[go: nahoru, domu]

blob: 59dec1c71ec351a36b797f5a9c8eb2dc6f078a66 [file] [log] [blame]
scottmg@chromium.orgffabb1e2012-10-12 19:51:171// 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
oshimaa15deb02016-05-11 00:19:335#include "ui/display/screen.h"
robliaoa7f30842016-02-02 22:23:306
oshimaa15deb02016-05-11 00:19:337#include "ui/display/display.h"
robliaoa7f30842016-02-02 22:23:308#include "ui/gfx/geometry/rect.h"
scottmg@chromium.orgffabb1e2012-10-12 19:51:179
oshimaa15deb02016-05-11 00:19:3310namespace display {
scottmg@chromium.orgffabb1e2012-10-12 19:51:1711
12namespace {
13
scottmgfb33c342016-01-27 01:30:3614Screen* g_screen;
scottmg@chromium.orgffabb1e2012-10-12 19:51:1715
16} // namespace
17
oshimaa15deb02016-05-11 00:19:3318Screen::Screen() {}
scottmg@chromium.orgffabb1e2012-10-12 19:51:1719
oshimaa15deb02016-05-11 00:19:3320Screen::~Screen() {}
scottmg@chromium.orgffabb1e2012-10-12 19:51:1721
22// static
scottmgfb33c342016-01-27 01:30:3623Screen* Screen::GetScreen() {
timavfe53c2c62016-11-23 02:35:4624#if defined(OS_MACOSX)
scottmgfb33c342016-01-27 01:30:3625 // TODO(scottmg): https://crbug.com/558054
26 if (!g_screen)
27 g_screen = CreateNativeScreen();
28#endif
29 return g_screen;
scottmg@chromium.orgffabb1e2012-10-12 19:51:1730}
31
32// static
scottmgfb33c342016-01-27 01:30:3633void Screen::SetScreenInstance(Screen* instance) {
34 g_screen = instance;
scottmg@chromium.orgffabb1e2012-10-12 19:51:1735}
36
jinsukkim2dd85f32017-03-17 01:54:2837Display Screen::GetDisplayNearestView(gfx::NativeView view) const {
38 return GetDisplayNearestWindow(GetWindowForView(view));
39}
40
oshimaa15deb02016-05-11 00:19:3341gfx::Rect Screen::ScreenToDIPRectInWindow(gfx::NativeView view,
robliaoa7f30842016-02-02 22:23:3042 const gfx::Rect& screen_rect) const {
jinsukkim2dd85f32017-03-17 01:54:2843 float scale = GetDisplayNearestView(view).device_scale_factor();
robliaoa7f30842016-02-02 22:23:3044 return ScaleToEnclosingRect(screen_rect, 1.0f / scale);
45}
46
oshimaa15deb02016-05-11 00:19:3347gfx::Rect Screen::DIPToScreenRectInWindow(gfx::NativeView view,
robliaoa7f30842016-02-02 22:23:3048 const gfx::Rect& dip_rect) const {
jinsukkim2dd85f32017-03-17 01:54:2849 float scale = GetDisplayNearestView(view).device_scale_factor();
robliaoa7f30842016-02-02 22:23:3050 return ScaleToEnclosingRect(dip_rect, scale);
51}
52
riajiang29f6a422016-11-21 20:09:3153bool Screen::GetDisplayWithDisplayId(int64_t display_id,
kylechar7a067ec2017-01-07 01:16:2854 Display* display) const {
55 for (const Display& display_in_list : GetAllDisplays()) {
riajiang29f6a422016-11-21 20:09:3156 if (display_in_list.id() == display_id) {
57 *display = display_in_list;
58 return true;
59 }
60 }
61 return false;
62}
63
oshimaa15deb02016-05-11 00:19:3364} // namespace display