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/hash.h" |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/strings/utf_string_conversions.h" |
10 #include "base/win/win_util.h" | 12 #include "base/win/win_util.h" |
11 #include "ui/base/win/dpi.h" | 13 #include "ui/base/win/dpi.h" |
12 #include "ui/gfx/display.h" | 14 #include "ui/gfx/display.h" |
13 | 15 |
14 namespace { | 16 namespace { |
15 | 17 |
16 MONITORINFO GetMonitorInfoForMonitor(HMONITOR monitor) { | 18 MONITORINFOEX GetMonitorInfoForMonitor(HMONITOR monitor) { |
17 MONITORINFO monitor_info = { 0 }; | 19 MONITORINFOEX monitor_info; |
| 20 ZeroMemory(&monitor_info, sizeof(MONITORINFOEX)); |
18 monitor_info.cbSize = sizeof(monitor_info); | 21 monitor_info.cbSize = sizeof(monitor_info); |
19 base::win::GetMonitorInfoWrapper(monitor, &monitor_info); | 22 base::win::GetMonitorInfoWrapper(monitor, &monitor_info); |
20 return monitor_info; | 23 return monitor_info; |
21 } | 24 } |
22 | 25 |
23 gfx::Display GetDisplay(MONITORINFO& monitor_info) { | 26 gfx::Display GetDisplay(MONITORINFOEX& monitor_info) { |
24 // TODO(oshima): Implement ID and Observer. | 27 // TODO(oshima): Implement Observer. |
| 28 int64 id = static_cast<int64>(base::Hash(WideToUTF8(monitor_info.szDevice))); |
25 gfx::Rect bounds = gfx::Rect(monitor_info.rcMonitor); | 29 gfx::Rect bounds = gfx::Rect(monitor_info.rcMonitor); |
26 gfx::Display display(0, bounds); | 30 gfx::Display display(id, bounds); |
27 display.set_work_area(gfx::Rect(monitor_info.rcWork)); | 31 display.set_work_area(gfx::Rect(monitor_info.rcWork)); |
28 display.SetScaleAndBounds(ui::win::GetDeviceScaleFactor(), bounds); | 32 display.SetScaleAndBounds(ui::win::GetDeviceScaleFactor(), bounds); |
29 return display; | 33 return display; |
30 } | 34 } |
31 | 35 |
32 } // namespace | 36 } // namespace |
33 | 37 |
34 namespace gfx { | 38 namespace gfx { |
35 | 39 |
36 ScreenWin::ScreenWin() { | 40 ScreenWin::ScreenWin() { |
(...skipping 29 matching lines...) Expand all Loading... |
66 | 70 |
67 gfx::Display ScreenWin::GetDisplayNearestWindow(gfx::NativeView window) const { | 71 gfx::Display ScreenWin::GetDisplayNearestWindow(gfx::NativeView window) const { |
68 HWND window_hwnd = GetHWNDFromNativeView(window); | 72 HWND window_hwnd = GetHWNDFromNativeView(window); |
69 if (!window_hwnd) { | 73 if (!window_hwnd) { |
70 // When |window| isn't rooted to a display, we should just return the | 74 // When |window| isn't rooted to a display, we should just return the |
71 // default display so we get some correct display information like the | 75 // default display so we get some correct display information like the |
72 // scaling factor. | 76 // scaling factor. |
73 return GetPrimaryDisplay(); | 77 return GetPrimaryDisplay(); |
74 } | 78 } |
75 | 79 |
76 MONITORINFO monitor_info; | 80 MONITORINFOEX monitor_info; |
77 monitor_info.cbSize = sizeof(monitor_info); | 81 monitor_info.cbSize = sizeof(monitor_info); |
78 base::win::GetMonitorInfoWrapper( | 82 base::win::GetMonitorInfoWrapper( |
79 MonitorFromWindow(window_hwnd, MONITOR_DEFAULTTONEAREST), &monitor_info); | 83 MonitorFromWindow(window_hwnd, MONITOR_DEFAULTTONEAREST), &monitor_info); |
80 return GetDisplay(monitor_info); | 84 return GetDisplay(monitor_info); |
81 } | 85 } |
82 | 86 |
83 gfx::Display ScreenWin::GetDisplayNearestPoint(const gfx::Point& point) const { | 87 gfx::Display ScreenWin::GetDisplayNearestPoint(const gfx::Point& point) const { |
84 POINT initial_loc = { point.x(), point.y() }; | 88 POINT initial_loc = { point.x(), point.y() }; |
85 HMONITOR monitor = MonitorFromPoint(initial_loc, MONITOR_DEFAULTTONEAREST); | 89 HMONITOR monitor = MonitorFromPoint(initial_loc, MONITOR_DEFAULTTONEAREST); |
86 MONITORINFO mi = {0}; | 90 MONITORINFOEX mi; |
| 91 ZeroMemory(&mi, sizeof(MONITORINFOEX)); |
87 mi.cbSize = sizeof(mi); | 92 mi.cbSize = sizeof(mi); |
88 if (monitor && base::win::GetMonitorInfoWrapper(monitor, &mi)) { | 93 if (monitor && base::win::GetMonitorInfoWrapper(monitor, &mi)) { |
89 return GetDisplay(mi); | 94 return GetDisplay(mi); |
90 } | 95 } |
91 return gfx::Display(); | 96 return gfx::Display(); |
92 } | 97 } |
93 | 98 |
94 gfx::Display ScreenWin::GetDisplayMatching(const gfx::Rect& match_rect) const { | 99 gfx::Display ScreenWin::GetDisplayMatching(const gfx::Rect& match_rect) const { |
95 RECT other_bounds_rect = match_rect.ToRECT(); | 100 RECT other_bounds_rect = match_rect.ToRECT(); |
96 MONITORINFO monitor_info = GetMonitorInfoForMonitor(MonitorFromRect( | 101 MONITORINFOEX monitor_info = GetMonitorInfoForMonitor(MonitorFromRect( |
97 &other_bounds_rect, MONITOR_DEFAULTTONEAREST)); | 102 &other_bounds_rect, MONITOR_DEFAULTTONEAREST)); |
98 return GetDisplay(monitor_info); | 103 return GetDisplay(monitor_info); |
99 } | 104 } |
100 | 105 |
101 gfx::Display ScreenWin::GetPrimaryDisplay() const { | 106 gfx::Display ScreenWin::GetPrimaryDisplay() const { |
102 MONITORINFO mi = GetMonitorInfoForMonitor( | 107 MONITORINFOEX mi = GetMonitorInfoForMonitor( |
103 MonitorFromWindow(NULL, MONITOR_DEFAULTTOPRIMARY)); | 108 MonitorFromWindow(NULL, MONITOR_DEFAULTTOPRIMARY)); |
104 gfx::Display display = GetDisplay(mi); | 109 gfx::Display display = GetDisplay(mi); |
105 // TODO(kevers|girard): Test if these checks can be reintroduced for high-DIP | 110 // TODO(kevers|girard): Test if these checks can be reintroduced for high-DIP |
106 // once more of the app is DIP-aware. | 111 // once more of the app is DIP-aware. |
107 if (!ui::IsInHighDPIMode()) { | 112 if (!ui::IsInHighDPIMode()) { |
108 DCHECK_EQ(GetSystemMetrics(SM_CXSCREEN), display.size().width()); | 113 DCHECK_EQ(GetSystemMetrics(SM_CXSCREEN), display.size().width()); |
109 DCHECK_EQ(GetSystemMetrics(SM_CYSCREEN), display.size().height()); | 114 DCHECK_EQ(GetSystemMetrics(SM_CYSCREEN), display.size().height()); |
110 } | 115 } |
111 return display; | 116 return display; |
112 } | 117 } |
(...skipping 24 matching lines...) Expand all Loading... |
137 #endif // USE_AURA | 142 #endif // USE_AURA |
138 } | 143 } |
139 | 144 |
140 #if !defined(USE_AURA) | 145 #if !defined(USE_AURA) |
141 Screen* CreateNativeScreen() { | 146 Screen* CreateNativeScreen() { |
142 return new ScreenWin; | 147 return new ScreenWin; |
143 } | 148 } |
144 #endif // !USE_AURA | 149 #endif // !USE_AURA |
145 | 150 |
146 } // namespace gfx | 151 } // namespace gfx |
OLD | NEW |