Chromium Code Reviews| 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; |
|
oshima
2013/08/30 18:15:13
Any reason to prefer ZeroMemory over standard init
Haojian Wu
2013/08/31 14:17:07
According to http://en.cppreference.com/w/cpp/lang
oshima
2013/09/03 18:04:44
but according to http://msdn.microsoft.com/en-us/l
| |
| 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. |
| 25 gfx::Rect bounds = gfx::Rect(monitor_info.rcMonitor); | 28 gfx::Rect bounds = gfx::Rect(monitor_info.rcMonitor); |
| 26 gfx::Display display(0, bounds); | 29 gfx::Display display(0, bounds); |
| 27 display.set_work_area(gfx::Rect(monitor_info.rcWork)); | 30 display.set_work_area(gfx::Rect(monitor_info.rcWork)); |
| 28 display.SetScaleAndBounds(ui::win::GetDeviceScaleFactor(), bounds); | 31 display.SetScaleAndBounds(ui::win::GetDeviceScaleFactor(), bounds); |
| 32 DISPLAY_DEVICE device; | |
| 33 device.cb = sizeof(device); | |
| 34 if (EnumDisplayDevices(monitor_info.szDevice, 0, &device, 0)) { | |
| 35 int64 id = static_cast<int64>(base::Hash(WideToUTF8(device.DeviceID))); | |
|
oshima
2013/08/30 18:15:13
Hmm, according to http://msdn.microsoft.com/en-us/
Haojian Wu
2013/08/31 14:17:07
Done.
| |
| 36 display.set_id(id); | |
| 37 } | |
| 29 return display; | 38 return display; |
| 30 } | 39 } |
| 31 | 40 |
| 32 } // namespace | 41 } // namespace |
| 33 | 42 |
| 34 namespace gfx { | 43 namespace gfx { |
| 35 | 44 |
| 36 ScreenWin::ScreenWin() { | 45 ScreenWin::ScreenWin() { |
| 37 } | 46 } |
| 38 | 47 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 66 | 75 |
| 67 gfx::Display ScreenWin::GetDisplayNearestWindow(gfx::NativeView window) const { | 76 gfx::Display ScreenWin::GetDisplayNearestWindow(gfx::NativeView window) const { |
| 68 HWND window_hwnd = GetHWNDFromNativeView(window); | 77 HWND window_hwnd = GetHWNDFromNativeView(window); |
| 69 if (!window_hwnd) { | 78 if (!window_hwnd) { |
| 70 // When |window| isn't rooted to a display, we should just return the | 79 // 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 | 80 // default display so we get some correct display information like the |
| 72 // scaling factor. | 81 // scaling factor. |
| 73 return GetPrimaryDisplay(); | 82 return GetPrimaryDisplay(); |
| 74 } | 83 } |
| 75 | 84 |
| 76 MONITORINFO monitor_info; | 85 MONITORINFOEX monitor_info; |
| 77 monitor_info.cbSize = sizeof(monitor_info); | 86 monitor_info.cbSize = sizeof(monitor_info); |
| 78 base::win::GetMonitorInfoWrapper( | 87 base::win::GetMonitorInfoWrapper( |
| 79 MonitorFromWindow(window_hwnd, MONITOR_DEFAULTTONEAREST), &monitor_info); | 88 MonitorFromWindow(window_hwnd, MONITOR_DEFAULTTONEAREST), &monitor_info); |
| 80 return GetDisplay(monitor_info); | 89 return GetDisplay(monitor_info); |
| 81 } | 90 } |
| 82 | 91 |
| 83 gfx::Display ScreenWin::GetDisplayNearestPoint(const gfx::Point& point) const { | 92 gfx::Display ScreenWin::GetDisplayNearestPoint(const gfx::Point& point) const { |
| 84 POINT initial_loc = { point.x(), point.y() }; | 93 POINT initial_loc = { point.x(), point.y() }; |
| 85 HMONITOR monitor = MonitorFromPoint(initial_loc, MONITOR_DEFAULTTONEAREST); | 94 HMONITOR monitor = MonitorFromPoint(initial_loc, MONITOR_DEFAULTTONEAREST); |
| 86 MONITORINFO mi = {0}; | 95 MONITORINFOEX mi; |
| 96 ZeroMemory(&mi, sizeof(MONITORINFOEX)); | |
| 87 mi.cbSize = sizeof(mi); | 97 mi.cbSize = sizeof(mi); |
| 88 if (monitor && base::win::GetMonitorInfoWrapper(monitor, &mi)) { | 98 if (monitor && base::win::GetMonitorInfoWrapper(monitor, &mi)) { |
| 89 return GetDisplay(mi); | 99 return GetDisplay(mi); |
| 90 } | 100 } |
| 91 return gfx::Display(); | 101 return gfx::Display(); |
| 92 } | 102 } |
| 93 | 103 |
| 94 gfx::Display ScreenWin::GetDisplayMatching(const gfx::Rect& match_rect) const { | 104 gfx::Display ScreenWin::GetDisplayMatching(const gfx::Rect& match_rect) const { |
| 95 RECT other_bounds_rect = match_rect.ToRECT(); | 105 RECT other_bounds_rect = match_rect.ToRECT(); |
| 96 MONITORINFO monitor_info = GetMonitorInfoForMonitor(MonitorFromRect( | 106 MONITORINFOEX monitor_info = GetMonitorInfoForMonitor(MonitorFromRect( |
| 97 &other_bounds_rect, MONITOR_DEFAULTTONEAREST)); | 107 &other_bounds_rect, MONITOR_DEFAULTTONEAREST)); |
| 98 return GetDisplay(monitor_info); | 108 return GetDisplay(monitor_info); |
| 99 } | 109 } |
| 100 | 110 |
| 101 gfx::Display ScreenWin::GetPrimaryDisplay() const { | 111 gfx::Display ScreenWin::GetPrimaryDisplay() const { |
| 102 MONITORINFO mi = GetMonitorInfoForMonitor( | 112 MONITORINFOEX mi = GetMonitorInfoForMonitor( |
| 103 MonitorFromWindow(NULL, MONITOR_DEFAULTTOPRIMARY)); | 113 MonitorFromWindow(NULL, MONITOR_DEFAULTTOPRIMARY)); |
| 104 gfx::Display display = GetDisplay(mi); | 114 gfx::Display display = GetDisplay(mi); |
| 105 // TODO(kevers|girard): Test if these checks can be reintroduced for high-DIP | 115 // TODO(kevers|girard): Test if these checks can be reintroduced for high-DIP |
| 106 // once more of the app is DIP-aware. | 116 // once more of the app is DIP-aware. |
| 107 if (!ui::IsInHighDPIMode()) { | 117 if (!ui::IsInHighDPIMode()) { |
| 108 DCHECK_EQ(GetSystemMetrics(SM_CXSCREEN), display.size().width()); | 118 DCHECK_EQ(GetSystemMetrics(SM_CXSCREEN), display.size().width()); |
| 109 DCHECK_EQ(GetSystemMetrics(SM_CYSCREEN), display.size().height()); | 119 DCHECK_EQ(GetSystemMetrics(SM_CYSCREEN), display.size().height()); |
| 110 } | 120 } |
| 111 return display; | 121 return display; |
| 112 } | 122 } |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 137 #endif // USE_AURA | 147 #endif // USE_AURA |
| 138 } | 148 } |
| 139 | 149 |
| 140 #if !defined(USE_AURA) | 150 #if !defined(USE_AURA) |
| 141 Screen* CreateNativeScreen() { | 151 Screen* CreateNativeScreen() { |
| 142 return new ScreenWin; | 152 return new ScreenWin; |
| 143 } | 153 } |
| 144 #endif // !USE_AURA | 154 #endif // !USE_AURA |
| 145 | 155 |
| 146 } // namespace gfx | 156 } // namespace gfx |
| OLD | NEW |