| 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( |
| 31 static_cast<int64_t>(base::Hash(base::WideToUTF8(monitor_info.szDevice))); | 30 base::WideToUTF8(monitor_info.szDevice)); |
| 32 gfx::Rect bounds = gfx::Rect(monitor_info.rcMonitor); | 31 gfx::Rect bounds = gfx::Rect(monitor_info.rcMonitor); |
| 33 gfx::Display display(id); | 32 gfx::Display display(id); |
| 34 display.set_bounds(gfx::win::ScreenToDIPRect(bounds)); | 33 display.set_bounds(gfx::win::ScreenToDIPRect(bounds)); |
| 35 display.set_work_area( | 34 display.set_work_area( |
| 36 gfx::win::ScreenToDIPRect(gfx::Rect(monitor_info.rcWork))); | 35 gfx::win::ScreenToDIPRect(gfx::Rect(monitor_info.rcWork))); |
| 37 display.SetScaleAndBounds(gfx::GetDPIScale(), bounds); | 36 display.SetScaleAndBounds(gfx::GetDPIScale(), bounds); |
| 38 | 37 |
| 39 DEVMODE mode; | 38 DEVMODE mode; |
| 40 memset(&mode, 0, sizeof(DEVMODE)); | 39 memset(&mode, 0, sizeof(DEVMODE)); |
| 41 mode.dmSize = sizeof(DEVMODE); | 40 mode.dmSize = sizeof(DEVMODE); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 HWND ScreenWin::GetHWNDFromNativeView(NativeView window) const { | 99 HWND ScreenWin::GetHWNDFromNativeView(NativeView window) const { |
| 101 NOTREACHED(); | 100 NOTREACHED(); |
| 102 return NULL; | 101 return NULL; |
| 103 } | 102 } |
| 104 | 103 |
| 105 NativeWindow ScreenWin::GetNativeWindowFromHWND(HWND hwnd) const { | 104 NativeWindow ScreenWin::GetNativeWindowFromHWND(HWND hwnd) const { |
| 106 NOTREACHED(); | 105 NOTREACHED(); |
| 107 return NULL; | 106 return NULL; |
| 108 } | 107 } |
| 109 | 108 |
| 109 // static |
| 110 int64_t ScreenWin::GenerateDisplayId(const std::string& str) { |
| 111 return static_cast<int64_t>(base::Hash(str)); |
| 112 } |
| 113 |
| 110 gfx::Point ScreenWin::GetCursorScreenPoint() { | 114 gfx::Point ScreenWin::GetCursorScreenPoint() { |
| 111 POINT pt; | 115 POINT pt; |
| 112 GetCursorPos(&pt); | 116 GetCursorPos(&pt); |
| 113 gfx::Point cursor_pos_pixels(pt); | 117 gfx::Point cursor_pos_pixels(pt); |
| 114 return gfx::win::ScreenToDIPPoint(cursor_pos_pixels); | 118 return gfx::win::ScreenToDIPPoint(cursor_pos_pixels); |
| 115 } | 119 } |
| 116 | 120 |
| 117 gfx::NativeWindow ScreenWin::GetWindowUnderCursor() { | 121 gfx::NativeWindow ScreenWin::GetWindowUnderCursor() { |
| 118 POINT cursor_loc; | 122 POINT cursor_loc; |
| 119 HWND hwnd = GetCursorPos(&cursor_loc) ? WindowFromPoint(cursor_loc) : NULL; | 123 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( | 211 std::vector<gfx::Display> ScreenWin::GetDisplaysForMonitorInfos( |
| 208 const std::vector<MONITORINFOEX>& monitor_infos) { | 212 const std::vector<MONITORINFOEX>& monitor_infos) { |
| 209 std::vector<gfx::Display> displays; | 213 std::vector<gfx::Display> displays; |
| 210 for (const MONITORINFOEX& monitor_info : monitor_infos) | 214 for (const MONITORINFOEX& monitor_info : monitor_infos) |
| 211 displays.push_back(GetDisplay(monitor_info)); | 215 displays.push_back(GetDisplay(monitor_info)); |
| 212 | 216 |
| 213 return displays; | 217 return displays; |
| 214 } | 218 } |
| 215 | 219 |
| 216 } // namespace gfx | 220 } // namespace gfx |
| OLD | NEW |