• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2016 The Chromium Embedded Framework Authors. All rights
2 // reserved. Use of this source code is governed by a BSD-style license that
3 // can be found in the LICENSE file.
4 
5 #include "libcef/browser/views/display_impl.h"
6 
7 #include "libcef/browser/views/view_util.h"
8 
9 #include "ui/display/screen.h"
10 
11 // static
GetPrimaryDisplay()12 CefRefPtr<CefDisplay> CefDisplay::GetPrimaryDisplay() {
13   CEF_REQUIRE_UIT_RETURN(nullptr);
14   return new CefDisplayImpl(display::Screen::GetScreen()->GetPrimaryDisplay());
15 }
16 
17 // static
GetDisplayNearestPoint(const CefPoint & point,bool input_pixel_coords)18 CefRefPtr<CefDisplay> CefDisplay::GetDisplayNearestPoint(
19     const CefPoint& point,
20     bool input_pixel_coords) {
21   CEF_REQUIRE_UIT_RETURN(nullptr);
22   return new CefDisplayImpl(view_util::GetDisplayNearestPoint(
23       gfx::Point(point.x, point.y), input_pixel_coords));
24 }
25 
26 // static
GetDisplayMatchingBounds(const CefRect & bounds,bool input_pixel_coords)27 CefRefPtr<CefDisplay> CefDisplay::GetDisplayMatchingBounds(
28     const CefRect& bounds,
29     bool input_pixel_coords) {
30   CEF_REQUIRE_UIT_RETURN(nullptr);
31   return new CefDisplayImpl(view_util::GetDisplayMatchingBounds(
32       gfx::Rect(bounds.x, bounds.y, bounds.width, bounds.height),
33       input_pixel_coords));
34 }
35 
36 // static
GetDisplayCount()37 size_t CefDisplay::GetDisplayCount() {
38   CEF_REQUIRE_UIT_RETURN(0U);
39   return static_cast<size_t>(display::Screen::GetScreen()->GetNumDisplays());
40 }
41 
42 // static
GetAllDisplays(std::vector<CefRefPtr<CefDisplay>> & displays)43 void CefDisplay::GetAllDisplays(std::vector<CefRefPtr<CefDisplay>>& displays) {
44   CEF_REQUIRE_UIT_RETURN_VOID();
45 
46   displays.clear();
47 
48   using DisplayVector = std::vector<display::Display>;
49   DisplayVector vec = display::Screen::GetScreen()->GetAllDisplays();
50   for (size_t i = 0; i < vec.size(); ++i)
51     displays.push_back(new CefDisplayImpl(vec[i]));
52 }
53 
CefDisplayImpl(const display::Display & display)54 CefDisplayImpl::CefDisplayImpl(const display::Display& display)
55     : display_(display) {
56   CEF_REQUIRE_UIT();
57 }
58 
~CefDisplayImpl()59 CefDisplayImpl::~CefDisplayImpl() {
60   CEF_REQUIRE_UIT();
61 }
62 
GetID()63 int64 CefDisplayImpl::GetID() {
64   CEF_REQUIRE_UIT_RETURN(-1);
65   return display_.id();
66 }
67 
GetDeviceScaleFactor()68 float CefDisplayImpl::GetDeviceScaleFactor() {
69   CEF_REQUIRE_UIT_RETURN(0.0f);
70   return display_.device_scale_factor();
71 }
72 
ConvertPointToPixels(CefPoint & point)73 void CefDisplayImpl::ConvertPointToPixels(CefPoint& point) {
74   CEF_REQUIRE_UIT_RETURN_VOID();
75   gfx::Point gfx_point(point.x, point.y);
76   view_util::ConvertPointToPixels(&gfx_point, display_.device_scale_factor());
77   point = CefPoint(gfx_point.x(), gfx_point.y());
78 }
79 
ConvertPointFromPixels(CefPoint & point)80 void CefDisplayImpl::ConvertPointFromPixels(CefPoint& point) {
81   CEF_REQUIRE_UIT_RETURN_VOID();
82   gfx::Point gfx_point(point.x, point.y);
83   view_util::ConvertPointFromPixels(&gfx_point, display_.device_scale_factor());
84   point = CefPoint(gfx_point.x(), gfx_point.y());
85 }
86 
GetBounds()87 CefRect CefDisplayImpl::GetBounds() {
88   CEF_REQUIRE_UIT_RETURN(CefRect());
89   const gfx::Rect& gfx_rect = display_.bounds();
90   return CefRect(gfx_rect.x(), gfx_rect.y(), gfx_rect.width(),
91                  gfx_rect.height());
92 }
93 
GetWorkArea()94 CefRect CefDisplayImpl::GetWorkArea() {
95   CEF_REQUIRE_UIT_RETURN(CefRect());
96   const gfx::Rect& gfx_rect = display_.work_area();
97   return CefRect(gfx_rect.x(), gfx_rect.y(), gfx_rect.width(),
98                  gfx_rect.height());
99 }
100 
GetRotation()101 int CefDisplayImpl::GetRotation() {
102   CEF_REQUIRE_UIT_RETURN(0);
103   return display_.RotationAsDegree();
104 }
105