OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gfx/screen_win.h" | 5 #include "ui/gfx/screen_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "ui/gfx/display.h" | 10 #include "ui/gfx/display.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 HWND window_hwnd = GetCursorPos(&location) ? WindowFromPoint(location) : NULL; | 50 HWND window_hwnd = GetCursorPos(&location) ? WindowFromPoint(location) : NULL; |
51 return GetNativeWindowFromHWND(window_hwnd); | 51 return GetNativeWindowFromHWND(window_hwnd); |
52 } | 52 } |
53 | 53 |
54 int ScreenWin::GetNumDisplays() { | 54 int ScreenWin::GetNumDisplays() { |
55 return GetSystemMetrics(SM_CMONITORS); | 55 return GetSystemMetrics(SM_CMONITORS); |
56 } | 56 } |
57 | 57 |
58 gfx::Display ScreenWin::GetDisplayNearestWindow(gfx::NativeView window) const { | 58 gfx::Display ScreenWin::GetDisplayNearestWindow(gfx::NativeView window) const { |
59 HWND window_hwnd = GetHWNDFromNativeView(window); | 59 HWND window_hwnd = GetHWNDFromNativeView(window); |
| 60 if (!window_hwnd) { |
| 61 // When |window| isn't rooted to a display, we should just return the |
| 62 // default display so we get some correct display information like the |
| 63 // scaling factor. |
| 64 return GetPrimaryDisplay(); |
| 65 } |
| 66 |
60 MONITORINFO monitor_info; | 67 MONITORINFO monitor_info; |
61 monitor_info.cbSize = sizeof(monitor_info); | 68 monitor_info.cbSize = sizeof(monitor_info); |
62 GetMonitorInfo(MonitorFromWindow(window_hwnd, MONITOR_DEFAULTTONEAREST), | 69 GetMonitorInfo(MonitorFromWindow(window_hwnd, MONITOR_DEFAULTTONEAREST), |
63 &monitor_info); | 70 &monitor_info); |
64 return GetDisplay(monitor_info); | 71 return GetDisplay(monitor_info); |
65 } | 72 } |
66 | 73 |
67 gfx::Display ScreenWin::GetDisplayNearestPoint(const gfx::Point& point) const { | 74 gfx::Display ScreenWin::GetDisplayNearestPoint(const gfx::Point& point) const { |
68 POINT initial_loc = { point.x(), point.y() }; | 75 POINT initial_loc = { point.x(), point.y() }; |
69 HMONITOR monitor = MonitorFromPoint(initial_loc, MONITOR_DEFAULTTONEAREST); | 76 HMONITOR monitor = MonitorFromPoint(initial_loc, MONITOR_DEFAULTTONEAREST); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 #endif // USE_AURA | 123 #endif // USE_AURA |
117 } | 124 } |
118 | 125 |
119 #if !defined(USE_AURA) | 126 #if !defined(USE_AURA) |
120 Screen* CreateNativeScreen() { | 127 Screen* CreateNativeScreen() { |
121 return new ScreenWin; | 128 return new ScreenWin; |
122 } | 129 } |
123 #endif // !USE_AURA | 130 #endif // !USE_AURA |
124 | 131 |
125 } // namespace gfx | 132 } // namespace gfx |
OLD | NEW |