Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: chrome/browser/ui/monitor_info_provider_win.cc

Issue 8549008: Extract MonitorInfoProvider from WindowSizer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase 2 Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 "chrome/browser/ui/monitor_info_provider.h"
6
7 #include <windows.h>
8
9 #include "base/compiler_specific.h"
10
11 namespace {
12
13 class MonitorInfoProviderWin : public MonitorInfoProvider {
14 public:
15 MonitorInfoProviderWin();
16 virtual ~MonitorInfoProviderWin();
17
18 // Overridden from MonitorInfoProvider:
19 virtual gfx::Rect GetPrimaryMonitorWorkArea() const OVERRIDE;
20 virtual gfx::Rect GetPrimaryMonitorBounds() const OVERRIDE;
21 virtual gfx::Rect GetMonitorWorkAreaMatching(
22 const gfx::Rect& match_rect) const OVERRIDE;
23 virtual void UpdateWorkAreas() OVERRIDE;
24
25 private:
26 // A callback for EnumDisplayMonitors that records the work area of the
27 // current monitor in the enumeration.
28 static BOOL CALLBACK MonitorEnumProc(HMONITOR monitor,
29 HDC monitor_dc,
30 LPRECT monitor_rect,
31 LPARAM data);
32
33 static MONITORINFO GetMonitorInfoForMonitor(HMONITOR monitor);
34
35 DISALLOW_COPY_AND_ASSIGN(MonitorInfoProviderWin);
36 };
37
38 MonitorInfoProviderWin::MonitorInfoProviderWin() {
39 }
40
41 MonitorInfoProviderWin::~MonitorInfoProviderWin() {
42 }
43
44 gfx::Rect MonitorInfoProviderWin::GetPrimaryMonitorWorkArea() const {
45 return gfx::Rect(GetMonitorInfoForMonitor(MonitorFromWindow(NULL,
46 MONITOR_DEFAULTTOPRIMARY)).rcWork);
47 }
48
49 gfx::Rect MonitorInfoProviderWin::GetPrimaryMonitorBounds() const {
50 return gfx::Rect(GetMonitorInfoForMonitor(MonitorFromWindow(NULL,
51 MONITOR_DEFAULTTOPRIMARY)).rcMonitor);
52 }
53
54 gfx::Rect MonitorInfoProviderWin::GetMonitorWorkAreaMatching(
55 const gfx::Rect& match_rect) const {
56 RECT other_bounds_rect = match_rect.ToRECT();
57 MONITORINFO monitor_info = GetMonitorInfoForMonitor(MonitorFromRect(
58 &other_bounds_rect, MONITOR_DEFAULTTONEAREST));
59 return gfx::Rect(monitor_info.rcWork);
60 }
61
62 void MonitorInfoProviderWin::UpdateWorkAreas() {
63 work_areas_.clear();
64 EnumDisplayMonitors(NULL, NULL, &MonitorInfoProviderWin::MonitorEnumProc,
65 reinterpret_cast<LPARAM>(&work_areas_));
66 }
67
68 // static
69 BOOL CALLBACK MonitorInfoProviderWin::MonitorEnumProc(HMONITOR monitor,
70 HDC monitor_dc,
71 LPRECT monitor_rect,
72 LPARAM data) {
73 reinterpret_cast<std::vector<gfx::Rect>*>(data)->push_back(
74 gfx::Rect(GetMonitorInfoForMonitor(monitor).rcWork));
75 return TRUE;
76 }
77
78 // static
79 MONITORINFO MonitorInfoProviderWin::GetMonitorInfoForMonitor(HMONITOR monitor) {
80 MONITORINFO monitor_info = { 0 };
81 monitor_info.cbSize = sizeof(monitor_info);
82 GetMonitorInfo(monitor, &monitor_info);
83 return monitor_info;
84 }
85
86 } // namespace
87
88 // static
89 MonitorInfoProvider* MonitorInfoProvider::Create() {
90 return new MonitorInfoProviderWin();
91 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698