Chromium Code Reviews| Index: ui/gfx/screen_win.cc |
| diff --git a/ui/gfx/screen_win.cc b/ui/gfx/screen_win.cc |
| index 23dbc9d60fbb865a6124b32d57690bbb41d21ba2..67ce034c48d36c0fc45e4858ae334e7e0db20d49 100644 |
| --- a/ui/gfx/screen_win.cc |
| +++ b/ui/gfx/screen_win.cc |
| @@ -6,26 +6,35 @@ |
| #include <windows.h> |
| +#include "base/hash.h" |
| #include "base/logging.h" |
| +#include "base/strings/utf_string_conversions.h" |
| #include "base/win/win_util.h" |
| #include "ui/base/win/dpi.h" |
| #include "ui/gfx/display.h" |
| namespace { |
| -MONITORINFO GetMonitorInfoForMonitor(HMONITOR monitor) { |
| - MONITORINFO monitor_info = { 0 }; |
|
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
|
| +MONITORINFOEX GetMonitorInfoForMonitor(HMONITOR monitor) { |
| + MONITORINFOEX monitor_info; |
| + ZeroMemory(&monitor_info, sizeof(MONITORINFOEX)); |
| monitor_info.cbSize = sizeof(monitor_info); |
| base::win::GetMonitorInfoWrapper(monitor, &monitor_info); |
| return monitor_info; |
| } |
| -gfx::Display GetDisplay(MONITORINFO& monitor_info) { |
| - // TODO(oshima): Implement ID and Observer. |
| +gfx::Display GetDisplay(MONITORINFOEX& monitor_info) { |
| + // TODO(oshima): Implement Observer. |
| gfx::Rect bounds = gfx::Rect(monitor_info.rcMonitor); |
| gfx::Display display(0, bounds); |
| display.set_work_area(gfx::Rect(monitor_info.rcWork)); |
| display.SetScaleAndBounds(ui::win::GetDeviceScaleFactor(), bounds); |
| + DISPLAY_DEVICE device; |
| + device.cb = sizeof(device); |
| + if (EnumDisplayDevices(monitor_info.szDevice, 0, &device, 0)) { |
| + 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.
|
| + display.set_id(id); |
| + } |
| return display; |
| } |
| @@ -73,7 +82,7 @@ gfx::Display ScreenWin::GetDisplayNearestWindow(gfx::NativeView window) const { |
| return GetPrimaryDisplay(); |
| } |
| - MONITORINFO monitor_info; |
| + MONITORINFOEX monitor_info; |
| monitor_info.cbSize = sizeof(monitor_info); |
| base::win::GetMonitorInfoWrapper( |
| MonitorFromWindow(window_hwnd, MONITOR_DEFAULTTONEAREST), &monitor_info); |
| @@ -83,7 +92,8 @@ gfx::Display ScreenWin::GetDisplayNearestWindow(gfx::NativeView window) const { |
| gfx::Display ScreenWin::GetDisplayNearestPoint(const gfx::Point& point) const { |
| POINT initial_loc = { point.x(), point.y() }; |
| HMONITOR monitor = MonitorFromPoint(initial_loc, MONITOR_DEFAULTTONEAREST); |
| - MONITORINFO mi = {0}; |
| + MONITORINFOEX mi; |
| + ZeroMemory(&mi, sizeof(MONITORINFOEX)); |
| mi.cbSize = sizeof(mi); |
| if (monitor && base::win::GetMonitorInfoWrapper(monitor, &mi)) { |
| return GetDisplay(mi); |
| @@ -93,13 +103,13 @@ gfx::Display ScreenWin::GetDisplayNearestPoint(const gfx::Point& point) const { |
| gfx::Display ScreenWin::GetDisplayMatching(const gfx::Rect& match_rect) const { |
| RECT other_bounds_rect = match_rect.ToRECT(); |
| - MONITORINFO monitor_info = GetMonitorInfoForMonitor(MonitorFromRect( |
| + MONITORINFOEX monitor_info = GetMonitorInfoForMonitor(MonitorFromRect( |
| &other_bounds_rect, MONITOR_DEFAULTTONEAREST)); |
| return GetDisplay(monitor_info); |
| } |
| gfx::Display ScreenWin::GetPrimaryDisplay() const { |
| - MONITORINFO mi = GetMonitorInfoForMonitor( |
| + MONITORINFOEX mi = GetMonitorInfoForMonitor( |
| MonitorFromWindow(NULL, MONITOR_DEFAULTTOPRIMARY)); |
| gfx::Display display = GetDisplay(mi); |
| // TODO(kevers|girard): Test if these checks can be reintroduced for high-DIP |