scottmg@chromium.org | ffabb1e | 2012-10-12 19:51:17 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors. All rights reserved. |
2 | // Use of this source code is governed by a BSD-style license that can be | ||||
3 | // found in the LICENSE file. | ||||
4 | |||||
oshima | a15deb0 | 2016-05-11 00:19:33 | [diff] [blame] | 5 | #include "ui/display/screen.h" |
robliao | a7f3084 | 2016-02-02 22:23:30 | [diff] [blame] | 6 | |
oshima | a15deb0 | 2016-05-11 00:19:33 | [diff] [blame] | 7 | #include "ui/display/display.h" |
robliao | a7f3084 | 2016-02-02 22:23:30 | [diff] [blame] | 8 | #include "ui/gfx/geometry/rect.h" |
scottmg@chromium.org | ffabb1e | 2012-10-12 19:51:17 | [diff] [blame] | 9 | |
oshima | a15deb0 | 2016-05-11 00:19:33 | [diff] [blame] | 10 | namespace display { |
scottmg@chromium.org | ffabb1e | 2012-10-12 19:51:17 | [diff] [blame] | 11 | |
12 | namespace { | ||||
13 | |||||
scottmg | fb33c34 | 2016-01-27 01:30:36 | [diff] [blame] | 14 | Screen* g_screen; |
scottmg@chromium.org | ffabb1e | 2012-10-12 19:51:17 | [diff] [blame] | 15 | |
16 | } // namespace | ||||
17 | |||||
oshima | a15deb0 | 2016-05-11 00:19:33 | [diff] [blame] | 18 | Screen::Screen() {} |
scottmg@chromium.org | ffabb1e | 2012-10-12 19:51:17 | [diff] [blame] | 19 | |
oshima | a15deb0 | 2016-05-11 00:19:33 | [diff] [blame] | 20 | Screen::~Screen() {} |
scottmg@chromium.org | ffabb1e | 2012-10-12 19:51:17 | [diff] [blame] | 21 | |
22 | // static | ||||
scottmg | fb33c34 | 2016-01-27 01:30:36 | [diff] [blame] | 23 | Screen* Screen::GetScreen() { |
timav | fe53c2c6 | 2016-11-23 02:35:46 | [diff] [blame] | 24 | #if defined(OS_MACOSX) |
scottmg | fb33c34 | 2016-01-27 01:30:36 | [diff] [blame] | 25 | // TODO(scottmg): https://crbug.com/558054 |
26 | if (!g_screen) | ||||
27 | g_screen = CreateNativeScreen(); | ||||
28 | #endif | ||||
29 | return g_screen; | ||||
scottmg@chromium.org | ffabb1e | 2012-10-12 19:51:17 | [diff] [blame] | 30 | } |
31 | |||||
32 | // static | ||||
scottmg | fb33c34 | 2016-01-27 01:30:36 | [diff] [blame] | 33 | void Screen::SetScreenInstance(Screen* instance) { |
34 | g_screen = instance; | ||||
scottmg@chromium.org | ffabb1e | 2012-10-12 19:51:17 | [diff] [blame] | 35 | } |
36 | |||||
jinsukkim | 2dd85f3 | 2017-03-17 01:54:28 | [diff] [blame] | 37 | Display Screen::GetDisplayNearestView(gfx::NativeView view) const { |
38 | return GetDisplayNearestWindow(GetWindowForView(view)); | ||||
39 | } | ||||
40 | |||||
oshima | a15deb0 | 2016-05-11 00:19:33 | [diff] [blame] | 41 | gfx::Rect Screen::ScreenToDIPRectInWindow(gfx::NativeView view, |
robliao | a7f3084 | 2016-02-02 22:23:30 | [diff] [blame] | 42 | const gfx::Rect& screen_rect) const { |
jinsukkim | 2dd85f3 | 2017-03-17 01:54:28 | [diff] [blame] | 43 | float scale = GetDisplayNearestView(view).device_scale_factor(); |
robliao | a7f3084 | 2016-02-02 22:23:30 | [diff] [blame] | 44 | return ScaleToEnclosingRect(screen_rect, 1.0f / scale); |
45 | } | ||||
46 | |||||
oshima | a15deb0 | 2016-05-11 00:19:33 | [diff] [blame] | 47 | gfx::Rect Screen::DIPToScreenRectInWindow(gfx::NativeView view, |
robliao | a7f3084 | 2016-02-02 22:23:30 | [diff] [blame] | 48 | const gfx::Rect& dip_rect) const { |
jinsukkim | 2dd85f3 | 2017-03-17 01:54:28 | [diff] [blame] | 49 | float scale = GetDisplayNearestView(view).device_scale_factor(); |
robliao | a7f3084 | 2016-02-02 22:23:30 | [diff] [blame] | 50 | return ScaleToEnclosingRect(dip_rect, scale); |
51 | } | ||||
52 | |||||
riajiang | 29f6a42 | 2016-11-21 20:09:31 | [diff] [blame] | 53 | bool Screen::GetDisplayWithDisplayId(int64_t display_id, |
kylechar | 7a067ec | 2017-01-07 01:16:28 | [diff] [blame] | 54 | Display* display) const { |
55 | for (const Display& display_in_list : GetAllDisplays()) { | ||||
riajiang | 29f6a42 | 2016-11-21 20:09:31 | [diff] [blame] | 56 | if (display_in_list.id() == display_id) { |
57 | *display = display_in_list; | ||||
58 | return true; | ||||
59 | } | ||||
60 | } | ||||
61 | return false; | ||||
62 | } | ||||
63 | |||||
oshima | a15deb0 | 2016-05-11 00:19:33 | [diff] [blame] | 64 | } // namespace display |