2016-01-19 21:09:01 +01:00
|
|
|
// Copyright (c) 2016 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/browser/views/display_impl.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/browser/views/view_util.h"
|
2016-05-25 01:35:43 +02:00
|
|
|
#include "ui/display/screen.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefDisplay> CefDisplay::GetPrimaryDisplay() {
|
|
|
|
CEF_REQUIRE_UIT_RETURN(nullptr);
|
2016-05-25 01:35:43 +02:00
|
|
|
return new CefDisplayImpl(display::Screen::GetScreen()->GetPrimaryDisplay());
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefDisplay> CefDisplay::GetDisplayNearestPoint(
|
|
|
|
const CefPoint& point,
|
|
|
|
bool input_pixel_coords) {
|
|
|
|
CEF_REQUIRE_UIT_RETURN(nullptr);
|
|
|
|
return new CefDisplayImpl(view_util::GetDisplayNearestPoint(
|
|
|
|
gfx::Point(point.x, point.y), input_pixel_coords));
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefDisplay> CefDisplay::GetDisplayMatchingBounds(
|
|
|
|
const CefRect& bounds,
|
|
|
|
bool input_pixel_coords) {
|
|
|
|
CEF_REQUIRE_UIT_RETURN(nullptr);
|
|
|
|
return new CefDisplayImpl(view_util::GetDisplayMatchingBounds(
|
|
|
|
gfx::Rect(bounds.x, bounds.y, bounds.width, bounds.height),
|
|
|
|
input_pixel_coords));
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
size_t CefDisplay::GetDisplayCount() {
|
|
|
|
CEF_REQUIRE_UIT_RETURN(0U);
|
2016-05-25 01:35:43 +02:00
|
|
|
return static_cast<size_t>(display::Screen::GetScreen()->GetNumDisplays());
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2017-05-17 11:29:28 +02:00
|
|
|
void CefDisplay::GetAllDisplays(std::vector<CefRefPtr<CefDisplay>>& displays) {
|
2016-01-19 21:09:01 +01:00
|
|
|
CEF_REQUIRE_UIT_RETURN_VOID();
|
|
|
|
|
|
|
|
displays.clear();
|
|
|
|
|
2021-12-06 21:40:25 +01:00
|
|
|
using DisplayVector = std::vector<display::Display>;
|
2016-05-25 01:35:43 +02:00
|
|
|
DisplayVector vec = display::Screen::GetScreen()->GetAllDisplays();
|
2024-01-20 23:48:57 +01:00
|
|
|
for (const auto& i : vec) {
|
|
|
|
displays.push_back(new CefDisplayImpl(i));
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
2022-10-13 20:43:40 +02:00
|
|
|
// static
|
|
|
|
CefPoint CefDisplay::ConvertScreenPointToPixels(const CefPoint& point) {
|
|
|
|
CEF_REQUIRE_UIT_RETURN(CefPoint());
|
|
|
|
#if BUILDFLAG(IS_WIN)
|
|
|
|
const gfx::Point pix_point =
|
|
|
|
view_util::ConvertPointToPixels(gfx::Point(point.x, point.y));
|
|
|
|
return CefPoint(pix_point.x(), pix_point.y());
|
|
|
|
#else
|
|
|
|
return point;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefPoint CefDisplay::ConvertScreenPointFromPixels(const CefPoint& point) {
|
|
|
|
CEF_REQUIRE_UIT_RETURN(CefPoint());
|
|
|
|
#if BUILDFLAG(IS_WIN)
|
|
|
|
const gfx::Point dip_point =
|
|
|
|
view_util::ConvertPointFromPixels(gfx::Point(point.x, point.y));
|
|
|
|
return CefPoint(dip_point.x(), dip_point.y());
|
|
|
|
#else
|
|
|
|
return point;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-11-07 21:21:44 +01:00
|
|
|
// static
|
|
|
|
CefRect CefDisplay::ConvertScreenRectToPixels(const CefRect& rect) {
|
|
|
|
CEF_REQUIRE_UIT_RETURN(CefRect());
|
|
|
|
#if BUILDFLAG(IS_WIN)
|
|
|
|
const gfx::Rect pix_rect = view_util::ConvertRectToPixels(
|
|
|
|
gfx::Rect(rect.x, rect.y, rect.width, rect.height));
|
|
|
|
return CefRect(pix_rect.x(), pix_rect.y(), pix_rect.width(),
|
|
|
|
pix_rect.height());
|
|
|
|
#else
|
|
|
|
return rect;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRect CefDisplay::ConvertScreenRectFromPixels(const CefRect& rect) {
|
|
|
|
CEF_REQUIRE_UIT_RETURN(CefRect());
|
|
|
|
#if BUILDFLAG(IS_WIN)
|
|
|
|
const gfx::Rect dip_rect = view_util::ConvertRectFromPixels(
|
|
|
|
gfx::Rect(rect.x, rect.y, rect.width, rect.height));
|
|
|
|
return CefRect(dip_rect.x(), dip_rect.y(), dip_rect.width(),
|
|
|
|
dip_rect.height());
|
|
|
|
#else
|
|
|
|
return rect;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-05-25 01:35:43 +02:00
|
|
|
CefDisplayImpl::CefDisplayImpl(const display::Display& display)
|
2016-01-19 21:09:01 +01:00
|
|
|
: display_(display) {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
}
|
|
|
|
|
|
|
|
CefDisplayImpl::~CefDisplayImpl() {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
}
|
|
|
|
|
2023-06-01 16:06:15 +02:00
|
|
|
int64_t CefDisplayImpl::GetID() {
|
2016-01-19 21:09:01 +01:00
|
|
|
CEF_REQUIRE_UIT_RETURN(-1);
|
|
|
|
return display_.id();
|
|
|
|
}
|
|
|
|
|
|
|
|
float CefDisplayImpl::GetDeviceScaleFactor() {
|
|
|
|
CEF_REQUIRE_UIT_RETURN(0.0f);
|
|
|
|
return display_.device_scale_factor();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefDisplayImpl::ConvertPointToPixels(CefPoint& point) {
|
|
|
|
CEF_REQUIRE_UIT_RETURN_VOID();
|
|
|
|
gfx::Point gfx_point(point.x, point.y);
|
|
|
|
view_util::ConvertPointToPixels(&gfx_point, display_.device_scale_factor());
|
|
|
|
point = CefPoint(gfx_point.x(), gfx_point.y());
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefDisplayImpl::ConvertPointFromPixels(CefPoint& point) {
|
|
|
|
CEF_REQUIRE_UIT_RETURN_VOID();
|
|
|
|
gfx::Point gfx_point(point.x, point.y);
|
|
|
|
view_util::ConvertPointFromPixels(&gfx_point, display_.device_scale_factor());
|
|
|
|
point = CefPoint(gfx_point.x(), gfx_point.y());
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRect CefDisplayImpl::GetBounds() {
|
|
|
|
CEF_REQUIRE_UIT_RETURN(CefRect());
|
|
|
|
const gfx::Rect& gfx_rect = display_.bounds();
|
2017-05-17 11:29:28 +02:00
|
|
|
return CefRect(gfx_rect.x(), gfx_rect.y(), gfx_rect.width(),
|
|
|
|
gfx_rect.height());
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CefRect CefDisplayImpl::GetWorkArea() {
|
|
|
|
CEF_REQUIRE_UIT_RETURN(CefRect());
|
|
|
|
const gfx::Rect& gfx_rect = display_.work_area();
|
2017-05-17 11:29:28 +02:00
|
|
|
return CefRect(gfx_rect.x(), gfx_rect.y(), gfx_rect.width(),
|
|
|
|
gfx_rect.height());
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int CefDisplayImpl::GetRotation() {
|
|
|
|
CEF_REQUIRE_UIT_RETURN(0);
|
|
|
|
return display_.RotationAsDegree();
|
|
|
|
}
|