| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/aura/desktop/desktop_screen_win.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "ui/aura/desktop/desktop_screen.h" |
| 9 #include "ui/aura/root_window.h" |
| 10 #include "ui/aura/root_window_host.h" |
| 11 #include "ui/gfx/monitor.h" |
| 12 |
| 13 namespace { |
| 14 |
| 15 MONITORINFO GetMonitorInfoForMonitor(HMONITOR monitor) { |
| 16 MONITORINFO monitor_info = { 0 }; |
| 17 monitor_info.cbSize = sizeof(monitor_info); |
| 18 GetMonitorInfo(monitor, &monitor_info); |
| 19 return monitor_info; |
| 20 } |
| 21 |
| 22 gfx::Monitor GetMonitor(MONITORINFO& monitor_info) { |
| 23 // TODO(oshima): Implement ID and Observer. |
| 24 gfx::Monitor monitor(0, gfx::Rect(monitor_info.rcMonitor)); |
| 25 monitor.set_work_area(gfx::Rect(monitor_info.rcWork)); |
| 26 return monitor; |
| 27 } |
| 28 |
| 29 } // namespace |
| 30 |
| 31 namespace aura { |
| 32 |
| 33 //////////////////////////////////////////////////////////////////////////////// |
| 34 // DesktopScreenWin, public: |
| 35 |
| 36 DesktopScreenWin::DesktopScreenWin() { |
| 37 } |
| 38 |
| 39 DesktopScreenWin::~DesktopScreenWin() { |
| 40 } |
| 41 |
| 42 //////////////////////////////////////////////////////////////////////////////// |
| 43 // DesktopScreenWin, gfx::ScreenImpl implementation: |
| 44 |
| 45 gfx::Point DesktopScreenWin::GetCursorScreenPoint() { |
| 46 POINT pt; |
| 47 GetCursorPos(&pt); |
| 48 return gfx::Point(pt); |
| 49 } |
| 50 |
| 51 gfx::NativeWindow DesktopScreenWin::GetWindowAtCursorScreenPoint() { |
| 52 POINT location; |
| 53 gfx::AcceleratedWidget accelerated_widget = |
| 54 GetCursorPos(&location) ? WindowFromPoint(location) : NULL; |
| 55 RootWindowHost* host = NULL; |
| 56 if (::IsWindow(accelerated_widget)) |
| 57 host = RootWindowHost::GetForAcceleratedWidget(accelerated_widget); |
| 58 return host ? host->GetRootWindow() : NULL; |
| 59 } |
| 60 |
| 61 int DesktopScreenWin::GetNumMonitors() { |
| 62 return GetSystemMetrics(SM_CMONITORS); |
| 63 } |
| 64 |
| 65 gfx::Monitor DesktopScreenWin::GetMonitorNearestWindow( |
| 66 gfx::NativeView window) const { |
| 67 gfx::AcceleratedWidget accelerated_window = |
| 68 window->GetRootWindow()->GetAcceleratedWidget(); |
| 69 MONITORINFO monitor_info; |
| 70 monitor_info.cbSize = sizeof(monitor_info); |
| 71 GetMonitorInfo(MonitorFromWindow(accelerated_window, |
| 72 MONITOR_DEFAULTTONEAREST), |
| 73 &monitor_info); |
| 74 return GetMonitor(monitor_info); |
| 75 } |
| 76 |
| 77 gfx::Monitor DesktopScreenWin::GetMonitorNearestPoint( |
| 78 const gfx::Point& point) const { |
| 79 POINT initial_loc = { point.x(), point.y() }; |
| 80 HMONITOR monitor = MonitorFromPoint(initial_loc, MONITOR_DEFAULTTONEAREST); |
| 81 MONITORINFO mi = {0}; |
| 82 mi.cbSize = sizeof(mi); |
| 83 if (monitor && GetMonitorInfo(monitor, &mi)) |
| 84 return GetMonitor(mi); |
| 85 return gfx::Monitor(); |
| 86 } |
| 87 |
| 88 gfx::Monitor DesktopScreenWin::GetPrimaryMonitor() const { |
| 89 MONITORINFO mi = GetMonitorInfoForMonitor( |
| 90 MonitorFromWindow(NULL, MONITOR_DEFAULTTOPRIMARY)); |
| 91 gfx::Monitor monitor = GetMonitor(mi); |
| 92 DCHECK_EQ(GetSystemMetrics(SM_CXSCREEN), monitor.size().width()); |
| 93 DCHECK_EQ(GetSystemMetrics(SM_CYSCREEN), monitor.size().height()); |
| 94 return monitor; |
| 95 } |
| 96 |
| 97 //////////////////////////////////////////////////////////////////////////////// |
| 98 |
| 99 gfx::ScreenImpl* CreateDesktopScreen() { |
| 100 return new DesktopScreenWin; |
| 101 } |
| 102 |
| 103 } // namespace aura |
| OLD | NEW |