Index: chrome/browser/ui/monitor_info_provider_win.cc |
diff --git a/chrome/browser/ui/monitor_info_provider_win.cc b/chrome/browser/ui/monitor_info_provider_win.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3b38baa8432252c02bd55b70ad4a0be8b8b568d9 |
--- /dev/null |
+++ b/chrome/browser/ui/monitor_info_provider_win.cc |
@@ -0,0 +1,91 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/ui/monitor_info_provider.h" |
+ |
+#include <windows.h> |
+ |
+#include "base/compiler_specific.h" |
+ |
+namespace { |
+ |
+class MonitorInfoProviderWin : public MonitorInfoProvider { |
+ public: |
+ MonitorInfoProviderWin(); |
+ virtual ~MonitorInfoProviderWin(); |
+ |
+ // Overridden from MonitorInfoProvider: |
+ virtual gfx::Rect GetPrimaryMonitorWorkArea() const OVERRIDE; |
+ virtual gfx::Rect GetPrimaryMonitorBounds() const OVERRIDE; |
+ virtual gfx::Rect GetMonitorWorkAreaMatching( |
+ const gfx::Rect& match_rect) const OVERRIDE; |
+ virtual void UpdateWorkAreas() OVERRIDE; |
+ |
+ private: |
+ // A callback for EnumDisplayMonitors that records the work area of the |
+ // current monitor in the enumeration. |
+ static BOOL CALLBACK MonitorEnumProc(HMONITOR monitor, |
+ HDC monitor_dc, |
+ LPRECT monitor_rect, |
+ LPARAM data); |
+ |
+ static MONITORINFO GetMonitorInfoForMonitor(HMONITOR monitor); |
+ |
+ DISALLOW_COPY_AND_ASSIGN(MonitorInfoProviderWin); |
+}; |
+ |
+MonitorInfoProviderWin::MonitorInfoProviderWin() { |
+} |
+ |
+MonitorInfoProviderWin::~MonitorInfoProviderWin() { |
+} |
+ |
+gfx::Rect MonitorInfoProviderWin::GetPrimaryMonitorWorkArea() const { |
+ return gfx::Rect(GetMonitorInfoForMonitor(MonitorFromWindow(NULL, |
+ MONITOR_DEFAULTTOPRIMARY)).rcWork); |
+} |
+ |
+gfx::Rect MonitorInfoProviderWin::GetPrimaryMonitorBounds() const { |
+ return gfx::Rect(GetMonitorInfoForMonitor(MonitorFromWindow(NULL, |
+ MONITOR_DEFAULTTOPRIMARY)).rcMonitor); |
+} |
+ |
+gfx::Rect MonitorInfoProviderWin::GetMonitorWorkAreaMatching( |
+ const gfx::Rect& match_rect) const { |
+ RECT other_bounds_rect = match_rect.ToRECT(); |
+ MONITORINFO monitor_info = GetMonitorInfoForMonitor(MonitorFromRect( |
+ &other_bounds_rect, MONITOR_DEFAULTTONEAREST)); |
+ return gfx::Rect(monitor_info.rcWork); |
+} |
+ |
+void MonitorInfoProviderWin::UpdateWorkAreas() { |
+ work_areas_.clear(); |
+ EnumDisplayMonitors(NULL, NULL, &MonitorInfoProviderWin::MonitorEnumProc, |
+ reinterpret_cast<LPARAM>(&work_areas_)); |
+} |
+ |
+// static |
+BOOL CALLBACK MonitorInfoProviderWin::MonitorEnumProc(HMONITOR monitor, |
+ HDC monitor_dc, |
+ LPRECT monitor_rect, |
+ LPARAM data) { |
+ reinterpret_cast<std::vector<gfx::Rect>*>(data)->push_back( |
+ gfx::Rect(GetMonitorInfoForMonitor(monitor).rcWork)); |
+ return TRUE; |
+} |
+ |
+// static |
+MONITORINFO MonitorInfoProviderWin::GetMonitorInfoForMonitor(HMONITOR monitor) { |
+ MONITORINFO monitor_info = { 0 }; |
+ monitor_info.cbSize = sizeof(monitor_info); |
+ GetMonitorInfo(monitor, &monitor_info); |
+ return monitor_info; |
+} |
+ |
+} // namespace |
+ |
+// static |
+MonitorInfoProvider* MonitorInfoProvider::Create() { |
+ return new MonitorInfoProviderWin(); |
+} |