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

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: . 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
Index: ui/gfx/screen_mac.mm
diff --git a/ui/gfx/screen_mac.mm b/ui/gfx/screen_mac.mm
index a3b7306d593f817f8b1976e28f0fbd77721866f0..c9b4494bf4fcfe283b75a9f39e55874ea59a065f 100644
--- a/ui/gfx/screen_mac.mm
+++ b/ui/gfx/screen_mac.mm
@@ -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;
}
+void GetMonitorForScreen(NSScreen* screen,
+ bool is_primary,
+ gfx::Monitor* monitor_out) {
+ NSRect frame = [screen frame];
+ monitor_out->set_bounds(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_out->set_work_area(work_area);
+ } else {
+ monitor_out->set_work_area(ConvertCoordinateSystem(visible_frame));
+ }
+}
+
} // namespace
namespace gfx {
@@ -52,39 +74,25 @@ gfx::Point Screen::GetCursorScreenPoint() {
}
// static
-gfx::Rect Screen::GetPrimaryMonitorWorkArea() {
+void Screen::GetPrimaryMonitor(gfx::Monitor* monitor_out) {
// 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];
+ GetMonitorForScreen(primary, true /* primary */, monitor_out);
- // 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_out->size().width());
+ CHECK_EQ(static_cast<const int>(CGDisplayPixelsHigh(main_display)),
+ monitor_out->size().height());
}
// static
-gfx::Rect Screen::GetMonitorWorkAreaMatching(const gfx::Rect& match_rect) {
+void Screen::GetMonitorMatching(const gfx::Rect& match_rect,
+ gfx::Monitor* monitor_out) {
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));
+ GetMonitorForScreen(
+ match_screen, false /* may not be primary */, monitor_out);
}
// static
« ui/gfx/screen_aura.cc ('K') | « 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