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

Side by Side Diff: ui/gfx/screen_win.cc

Issue 9960042: Refactor screen/monitor so that gfx::Screen returns monitor object. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 8 years, 8 months 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
« no previous file with comments | « ui/gfx/screen_unittest.cc ('k') | ui/ui.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // TODO(oshima): Implement ID and Observer.
23 gfx::Monitor monitor(0, gfx::Rect(monitor_info.rcMonitor));
24 monitor.set_work_area(gfx::Rect(monitor_info.rcWork));
25 return monitor;
26 }
27
18 } // namespace 28 } // namespace
19 29
20 namespace gfx { 30 namespace gfx {
21 31
22 // static 32 // static
23 gfx::Point Screen::GetCursorScreenPoint() { 33 gfx::Point Screen::GetCursorScreenPoint() {
24 POINT pt; 34 POINT pt;
25 GetCursorPos(&pt); 35 GetCursorPos(&pt);
26 return gfx::Point(pt); 36 return gfx::Point(pt);
27 } 37 }
28 38
29 // static 39 // 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() { 40 gfx::NativeWindow Screen::GetWindowAtCursorScreenPoint() {
90 POINT location; 41 POINT location;
91 return GetCursorPos(&location) ? WindowFromPoint(location) : NULL; 42 return GetCursorPos(&location) ? WindowFromPoint(location) : NULL;
92 } 43 }
93 44
94 // static 45 // 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() { 46 int Screen::GetNumMonitors() {
102 return GetSystemMetrics(SM_CMONITORS); 47 return GetSystemMetrics(SM_CMONITORS);
103 } 48 }
104 49
50 // static
51 gfx::Monitor Screen::GetMonitorNearestWindow(gfx::NativeWindow window) {
52 MONITORINFO monitor_info;
53 monitor_info.cbSize = sizeof(monitor_info);
54 GetMonitorInfo(MonitorFromWindow(window, MONITOR_DEFAULTTONEAREST),
55 &monitor_info);
56 return GetMonitor(monitor_info);
57 }
58
59 // static
60 gfx::Monitor Screen::GetMonitorNearestPoint(const gfx::Point& point) {
61 POINT initial_loc = { point.x(), point.y() };
62 HMONITOR monitor = MonitorFromPoint(initial_loc, MONITOR_DEFAULTTONEAREST);
63 MONITORINFO mi = {0};
64 mi.cbSize = sizeof(mi);
65 if (monitor && GetMonitorInfo(monitor, &mi))
66 return GetMonitor(mi);
67 return gfx::Monitor();
68 }
69
70 // static
71 gfx::Monitor Screen::GetPrimaryMonitor() {
72 MONITORINFO mi = GetMonitorInfoForMonitor(
73 MonitorFromWindow(NULL, MONITOR_DEFAULTTOPRIMARY));
74 gfx::Monitor monitor = GetMonitor(mi);
75 DCHECK_EQ(GetSystemMetrics(SM_CXSCREEN), monitor.size().width());
76 DCHECK_EQ(GetSystemMetrics(SM_CYSCREEN), monitor.size().height());
77 return monitor;
78 }
79
80 // static
81 gfx::Monitor Screen::GetMonitorMatching(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 GetMonitor(monitor_info);
86 }
87
105 } // namespace gfx 88 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/screen_unittest.cc ('k') | ui/ui.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698