| OLD | NEW |
| 1 // Copyright (c) 2011 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.h" | 5 #include "ui/gfx/screen.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 | 8 |
| 9 #include "base/logging.h" |
| 10 #include "ui/gfx/monitor.h" |
| 11 |
| 9 namespace { | 12 namespace { |
| 10 | 13 |
| 11 MONITORINFO GetMonitorInfoForMonitor(HMONITOR monitor) { | 14 MONITORINFO GetMonitorInfoForMonitor(HMONITOR monitor) { |
| 12 MONITORINFO monitor_info = { 0 }; | 15 MONITORINFO monitor_info = { 0 }; |
| 13 monitor_info.cbSize = sizeof(monitor_info); | 16 monitor_info.cbSize = sizeof(monitor_info); |
| 14 GetMonitorInfo(monitor, &monitor_info); | 17 GetMonitorInfo(monitor, &monitor_info); |
| 15 return monitor_info; | 18 return monitor_info; |
| 16 } | 19 } |
| 17 | 20 |
| 21 gfx::Monitor GetMonitor(MONITORINFO& monitor_info) { |
| 22 gfx::Monitor monitor(gfx::Rect(monitor_info.rcMonitor)); |
| 23 monitor.set_work_area(gfx::Rect(monitor_info.rcWork)); |
| 24 return monitor; |
| 25 } |
| 26 |
| 18 } // namespace | 27 } // namespace |
| 19 | 28 |
| 20 namespace gfx { | 29 namespace gfx { |
| 21 | 30 |
| 22 // static | 31 // static |
| 23 gfx::Point Screen::GetCursorScreenPoint() { | 32 gfx::Point Screen::GetCursorScreenPoint() { |
| 24 POINT pt; | 33 POINT pt; |
| 25 GetCursorPos(&pt); | 34 GetCursorPos(&pt); |
| 26 return gfx::Point(pt); | 35 return gfx::Point(pt); |
| 27 } | 36 } |
| 28 | 37 |
| 29 // static | 38 // static |
| 30 gfx::Rect Screen::GetMonitorWorkAreaNearestWindow(gfx::NativeWindow window) { | |
| 31 MONITORINFO monitor_info; | |
| 32 monitor_info.cbSize = sizeof(monitor_info); | |
| 33 GetMonitorInfo(MonitorFromWindow(window, MONITOR_DEFAULTTONEAREST), | |
| 34 &monitor_info); | |
| 35 return gfx::Rect(monitor_info.rcWork); | |
| 36 } | |
| 37 | |
| 38 // static | |
| 39 gfx::Rect Screen::GetMonitorAreaNearestWindow(gfx::NativeWindow window) { | |
| 40 MONITORINFO monitor_info; | |
| 41 monitor_info.cbSize = sizeof(monitor_info); | |
| 42 GetMonitorInfo(MonitorFromWindow(window, MONITOR_DEFAULTTONEAREST), | |
| 43 &monitor_info); | |
| 44 return gfx::Rect(monitor_info.rcMonitor); | |
| 45 } | |
| 46 | |
| 47 static gfx::Rect GetMonitorAreaOrWorkAreaNearestPoint(const gfx::Point& point, | |
| 48 bool work_area) { | |
| 49 POINT initial_loc = { point.x(), point.y() }; | |
| 50 HMONITOR monitor = MonitorFromPoint(initial_loc, MONITOR_DEFAULTTONEAREST); | |
| 51 MONITORINFO mi = {0}; | |
| 52 mi.cbSize = sizeof(mi); | |
| 53 if (monitor && GetMonitorInfo(monitor, &mi)) | |
| 54 return gfx::Rect(work_area ? mi.rcWork : mi.rcMonitor); | |
| 55 return gfx::Rect(); | |
| 56 } | |
| 57 | |
| 58 // static | |
| 59 gfx::Rect Screen::GetMonitorWorkAreaNearestPoint(const gfx::Point& point) { | |
| 60 return GetMonitorAreaOrWorkAreaNearestPoint(point, true); | |
| 61 } | |
| 62 | |
| 63 // static | |
| 64 gfx::Rect Screen::GetMonitorAreaNearestPoint(const gfx::Point& point) { | |
| 65 return GetMonitorAreaOrWorkAreaNearestPoint(point, false); | |
| 66 } | |
| 67 | |
| 68 // static | |
| 69 gfx::Rect Screen::GetPrimaryMonitorWorkArea() { | |
| 70 return gfx::Rect(GetMonitorInfoForMonitor(MonitorFromWindow(NULL, | |
| 71 MONITOR_DEFAULTTOPRIMARY)).rcWork); | |
| 72 } | |
| 73 | |
| 74 // static | |
| 75 gfx::Rect Screen::GetPrimaryMonitorBounds() { | |
| 76 return gfx::Rect(GetMonitorInfoForMonitor(MonitorFromWindow(NULL, | |
| 77 MONITOR_DEFAULTTOPRIMARY)).rcMonitor); | |
| 78 } | |
| 79 | |
| 80 // static | |
| 81 gfx::Rect Screen::GetMonitorWorkAreaMatching(const gfx::Rect& match_rect) { | |
| 82 RECT other_bounds_rect = match_rect.ToRECT(); | |
| 83 MONITORINFO monitor_info = GetMonitorInfoForMonitor(MonitorFromRect( | |
| 84 &other_bounds_rect, MONITOR_DEFAULTTONEAREST)); | |
| 85 return gfx::Rect(monitor_info.rcWork); | |
| 86 } | |
| 87 | |
| 88 // static | |
| 89 gfx::NativeWindow Screen::GetWindowAtCursorScreenPoint() { | 39 gfx::NativeWindow Screen::GetWindowAtCursorScreenPoint() { |
| 90 POINT location; | 40 POINT location; |
| 91 return GetCursorPos(&location) ? WindowFromPoint(location) : NULL; | 41 return GetCursorPos(&location) ? WindowFromPoint(location) : NULL; |
| 92 } | 42 } |
| 93 | 43 |
| 94 // static | 44 // static |
| 95 gfx::Size Screen::GetPrimaryMonitorSize() { | |
| 96 return gfx::Size(GetSystemMetrics(SM_CXSCREEN), | |
| 97 GetSystemMetrics(SM_CYSCREEN)); | |
| 98 } | |
| 99 | |
| 100 // static | |
| 101 int Screen::GetNumMonitors() { | 45 int Screen::GetNumMonitors() { |
| 102 return GetSystemMetrics(SM_CMONITORS); | 46 return GetSystemMetrics(SM_CMONITORS); |
| 103 } | 47 } |
| 104 | 48 |
| 49 // static |
| 50 gfx::Monitor Screen::GetMonitorNearestWindow(gfx::NativeWindow window) { |
| 51 MONITORINFO monitor_info; |
| 52 monitor_info.cbSize = sizeof(monitor_info); |
| 53 GetMonitorInfo(MonitorFromWindow(window, MONITOR_DEFAULTTONEAREST), |
| 54 &monitor_info); |
| 55 return GetMonitor(monitor_info); |
| 56 } |
| 57 |
| 58 // static |
| 59 gfx::Monitor Screen::GetMonitorNearestPoint(const gfx::Point& point) { |
| 60 POINT initial_loc = { point.x(), point.y() }; |
| 61 HMONITOR monitor = MonitorFromPoint(initial_loc, MONITOR_DEFAULTTONEAREST); |
| 62 MONITORINFO mi = {0}; |
| 63 mi.cbSize = sizeof(mi); |
| 64 if (monitor && GetMonitorInfo(monitor, &mi)) |
| 65 return GetMonitor(mi); |
| 66 return gfx::Monitor(); |
| 67 } |
| 68 |
| 69 // static |
| 70 gfx::Monitor Screen::GetPrimaryMonitor() { |
| 71 MONITORINFO mi = GetMonitorInfoForMonitor( |
| 72 MonitorFromWindow(NULL, MONITOR_DEFAULTTOPRIMARY)); |
| 73 gfx::Monitor monitor = GetMonitor(mi); |
| 74 DCHECK_EQ(GetSystemMetrics(SM_CXSCREEN), monitor.size().width()); |
| 75 DCHECK_EQ(GetSystemMetrics(SM_CYSCREEN), monitor.size().height()); |
| 76 return monitor; |
| 77 } |
| 78 |
| 79 // static |
| 80 gfx::Monitor Screen::GetMonitorMatching(const gfx::Rect& match_rect) { |
| 81 RECT other_bounds_rect = match_rect.ToRECT(); |
| 82 MONITORINFO monitor_info = GetMonitorInfoForMonitor(MonitorFromRect( |
| 83 &other_bounds_rect, MONITOR_DEFAULTTONEAREST)); |
| 84 return GetMonitor(monitor_info); |
| 85 } |
| 86 |
| 105 } // namespace gfx | 87 } // namespace gfx |
| OLD | NEW |