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

Unified Diff: ui/gfx/screen_mac.mm

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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/screen_impl.h ('k') | ui/gfx/screen_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/screen_mac.mm
diff --git a/ui/gfx/screen_mac.mm b/ui/gfx/screen_mac.mm
index a3b7306d593f817f8b1976e28f0fbd77721866f0..64dbf860260d3b81eac2656c2a737a02d97c3740 100644
--- a/ui/gfx/screen_mac.mm
+++ b/ui/gfx/screen_mac.mm
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -7,6 +7,9 @@
#import <ApplicationServices/ApplicationServices.h>
#import <Cocoa/Cocoa.h>
+#include "base/logging.h"
+#include "ui/gfx/monitor.h"
+
namespace {
gfx::Rect ConvertCoordinateSystem(NSRect ns_rect) {
@@ -38,6 +41,25 @@ NSScreen* GetMatchingScreen(const gfx::Rect& match_rect) {
return max_screen;
}
+gfx::Monitor GetMonitorForScreen(NSScreen* screen, bool is_primary) {
+ NSRect frame = [screen frame];
+ // TODO(oshima): Implement ID and Observer.
+ gfx::Monitor monitor(0, gfx::Rect(NSRectToCGRect(frame)));
+
+ NSRect visible_frame = [screen visibleFrame];
+
+ // Convert work area's coordinate systems.
+ if (is_primary) {
+ gfx::Rect work_area = gfx::Rect(NSRectToCGRect(visible_frame));
+ work_area.set_y(frame.size.height - visible_frame.origin.y -
+ visible_frame.size.height);
+ monitor.set_work_area(work_area);
+ } else {
+ monitor.set_work_area(ConvertCoordinateSystem(visible_frame));
+ }
+ return monitor;
+}
+
} // namespace
namespace gfx {
@@ -52,39 +74,24 @@ gfx::Point Screen::GetCursorScreenPoint() {
}
// static
-gfx::Rect Screen::GetPrimaryMonitorWorkArea() {
+gfx::Monitor Screen::GetPrimaryMonitor() {
// Primary monitor is defined as the monitor with the menubar,
// which is always at index 0.
NSScreen* primary = [[NSScreen screens] objectAtIndex:0];
- NSRect frame = [primary frame];
- NSRect visible_frame = [primary visibleFrame];
+ gfx::Monitor monitor = GetMonitorForScreen(primary, true /* primary */);
- // Convert coordinate systems.
- gfx::Rect rect = gfx::Rect(NSRectToCGRect(visible_frame));
- rect.set_y(frame.size.height - visible_frame.origin.y -
- visible_frame.size.height);
- return rect;
-}
-
-// static
-gfx::Rect Screen::GetPrimaryMonitorBounds() {
- // Primary monitor is defined as the monitor with the menubar,
- // which is always at index 0.
- NSScreen* primary = [[NSScreen screens] objectAtIndex:0];
- return gfx::Rect(NSRectToCGRect([primary frame]));
+ CGDirectDisplayID main_display = CGMainDisplayID();
+ CHECK_EQ(static_cast<const int>(CGDisplayPixelsWide(main_display)),
+ monitor.size().width());
+ CHECK_EQ(static_cast<const int>(CGDisplayPixelsHigh(main_display)),
+ monitor.size().height());
+ return monitor;
}
// static
-gfx::Rect Screen::GetMonitorWorkAreaMatching(const gfx::Rect& match_rect) {
+gfx::Monitor Screen::GetMonitorMatching(const gfx::Rect& match_rect) {
NSScreen* match_screen = GetMatchingScreen(match_rect);
- return ConvertCoordinateSystem([match_screen visibleFrame]);
-}
-
-// static
-gfx::Size Screen::GetPrimaryMonitorSize() {
- CGDirectDisplayID main_display = CGMainDisplayID();
- return gfx::Size(CGDisplayPixelsWide(main_display),
- CGDisplayPixelsHigh(main_display));
+ return GetMonitorForScreen(match_screen, false /* may not be primary */);
}
// static
« no previous file with comments | « ui/gfx/screen_impl.h ('k') | ui/gfx/screen_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698