| 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 #include <stdint.h> | |
| 9 | 8 |
| 10 #include "base/bind.h" | 9 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 12 #include "base/hash.h" | 11 #include "base/hash.h" |
| 13 #include "base/logging.h" | 12 #include "base/logging.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/win/win_util.h" | 14 #include "base/win/win_util.h" |
| 16 #include "ui/gfx/display.h" | 15 #include "ui/gfx/display.h" |
| 17 #include "ui/gfx/win/dpi.h" | 16 #include "ui/gfx/win/dpi.h" |
| 18 | 17 |
| 19 namespace { | 18 namespace { |
| 20 | 19 |
| 21 MONITORINFOEX GetMonitorInfoForMonitor(HMONITOR monitor) { | 20 MONITORINFOEX GetMonitorInfoForMonitor(HMONITOR monitor) { |
| 22 MONITORINFOEX monitor_info; | 21 MONITORINFOEX monitor_info; |
| 23 ZeroMemory(&monitor_info, sizeof(MONITORINFOEX)); | 22 ZeroMemory(&monitor_info, sizeof(MONITORINFOEX)); |
| 24 monitor_info.cbSize = sizeof(monitor_info); | 23 monitor_info.cbSize = sizeof(monitor_info); |
| 25 GetMonitorInfo(monitor, &monitor_info); | 24 GetMonitorInfo(monitor, &monitor_info); |
| 26 return monitor_info; | 25 return monitor_info; |
| 27 } | 26 } |
| 28 | 27 |
| 29 gfx::Display GetDisplay(const MONITORINFOEX& monitor_info) { | 28 gfx::Display GetDisplay(const MONITORINFOEX& monitor_info) { |
| 30 int64_t id = | 29 int64_t id = gfx::ScreenWin::GenerateDisplayId(monitor_info.szDevice); |
| 31 static_cast<int64_t>(base::Hash(base::WideToUTF8(monitor_info.szDevice))); | |
| 32 gfx::Rect bounds = gfx::Rect(monitor_info.rcMonitor); | 30 gfx::Rect bounds = gfx::Rect(monitor_info.rcMonitor); |
| 33 gfx::Display display(id); | 31 gfx::Display display(id); |
| 34 display.set_bounds(gfx::win::ScreenToDIPRect(bounds)); | 32 display.set_bounds(gfx::win::ScreenToDIPRect(bounds)); |
| 35 display.set_work_area( | 33 display.set_work_area( |
| 36 gfx::win::ScreenToDIPRect(gfx::Rect(monitor_info.rcWork))); | 34 gfx::win::ScreenToDIPRect(gfx::Rect(monitor_info.rcWork))); |
| 37 display.SetScaleAndBounds(gfx::GetDPIScale(), bounds); | 35 display.SetScaleAndBounds(gfx::GetDPIScale(), bounds); |
| 38 | 36 |
| 39 DEVMODE mode; | 37 DEVMODE mode; |
| 40 memset(&mode, 0, sizeof(DEVMODE)); | 38 memset(&mode, 0, sizeof(DEVMODE)); |
| 41 mode.dmSize = sizeof(DEVMODE); | 39 mode.dmSize = sizeof(DEVMODE); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 HWND ScreenWin::GetHWNDFromNativeView(NativeView window) const { | 98 HWND ScreenWin::GetHWNDFromNativeView(NativeView window) const { |
| 101 NOTREACHED(); | 99 NOTREACHED(); |
| 102 return NULL; | 100 return NULL; |
| 103 } | 101 } |
| 104 | 102 |
| 105 NativeWindow ScreenWin::GetNativeWindowFromHWND(HWND hwnd) const { | 103 NativeWindow ScreenWin::GetNativeWindowFromHWND(HWND hwnd) const { |
| 106 NOTREACHED(); | 104 NOTREACHED(); |
| 107 return NULL; | 105 return NULL; |
| 108 } | 106 } |
| 109 | 107 |
| 108 // static |
| 109 int64_t ScreenWin::GenerateDisplayId(const std::wstring& str) { |
| 110 return static_cast<int64_t>(base::Hash(base::WideToUTF8(str))); |
| 111 } |
| 112 |
| 110 gfx::Point ScreenWin::GetCursorScreenPoint() { | 113 gfx::Point ScreenWin::GetCursorScreenPoint() { |
| 111 POINT pt; | 114 POINT pt; |
| 112 GetCursorPos(&pt); | 115 GetCursorPos(&pt); |
| 113 gfx::Point cursor_pos_pixels(pt); | 116 gfx::Point cursor_pos_pixels(pt); |
| 114 return gfx::win::ScreenToDIPPoint(cursor_pos_pixels); | 117 return gfx::win::ScreenToDIPPoint(cursor_pos_pixels); |
| 115 } | 118 } |
| 116 | 119 |
| 117 gfx::NativeWindow ScreenWin::GetWindowUnderCursor() { | 120 gfx::NativeWindow ScreenWin::GetWindowUnderCursor() { |
| 118 POINT cursor_loc; | 121 POINT cursor_loc; |
| 119 HWND hwnd = GetCursorPos(&cursor_loc) ? WindowFromPoint(cursor_loc) : NULL; | 122 HWND hwnd = GetCursorPos(&cursor_loc) ? WindowFromPoint(cursor_loc) : NULL; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 std::vector<gfx::Display> ScreenWin::GetDisplaysForMonitorInfos( | 210 std::vector<gfx::Display> ScreenWin::GetDisplaysForMonitorInfos( |
| 208 const std::vector<MONITORINFOEX>& monitor_infos) { | 211 const std::vector<MONITORINFOEX>& monitor_infos) { |
| 209 std::vector<gfx::Display> displays; | 212 std::vector<gfx::Display> displays; |
| 210 for (const MONITORINFOEX& monitor_info : monitor_infos) | 213 for (const MONITORINFOEX& monitor_info : monitor_infos) |
| 211 displays.push_back(GetDisplay(monitor_info)); | 214 displays.push_back(GetDisplay(monitor_info)); |
| 212 | 215 |
| 213 return displays; | 216 return displays; |
| 214 } | 217 } |
| 215 | 218 |
| 216 } // namespace gfx | 219 } // namespace gfx |
| OLD | NEW |