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 |