Index: ui/gfx/screen_mac.mm |
diff --git a/ui/gfx/screen_mac.mm b/ui/gfx/screen_mac.mm |
index 6bf0992896bccceb7295458bf39e3e42fe29416b..a3b7306d593f817f8b1976e28f0fbd77721866f0 100644 |
--- a/ui/gfx/screen_mac.mm |
+++ b/ui/gfx/screen_mac.mm |
@@ -7,6 +7,39 @@ |
#import <ApplicationServices/ApplicationServices.h> |
#import <Cocoa/Cocoa.h> |
+namespace { |
+ |
+gfx::Rect ConvertCoordinateSystem(NSRect ns_rect) { |
+ // Primary monitor is defined as the monitor with the menubar, |
+ // which is always at index 0. |
+ NSScreen* primary_screen = [[NSScreen screens] objectAtIndex:0]; |
+ float primary_screen_height = [primary_screen frame].size.height; |
+ gfx::Rect rect(NSRectToCGRect(ns_rect)); |
+ rect.set_y(primary_screen_height - rect.y() - rect.height()); |
+ return rect; |
+} |
+ |
+NSScreen* GetMatchingScreen(const gfx::Rect& match_rect) { |
+ // Default to the monitor with the current keyboard focus, in case |
+ // |match_rect| is not on any screen at all. |
+ NSScreen* max_screen = [NSScreen mainScreen]; |
+ int max_area = 0; |
+ |
+ for (NSScreen* screen in [NSScreen screens]) { |
+ gfx::Rect monitor_area = ConvertCoordinateSystem([screen frame]); |
+ gfx::Rect intersection = monitor_area.Intersect(match_rect); |
+ int area = intersection.width() * intersection.height(); |
+ if (area > max_area) { |
+ max_area = area; |
+ max_screen = screen; |
+ } |
+ } |
+ |
+ return max_screen; |
+} |
+ |
+} // namespace |
+ |
namespace gfx { |
// static |
@@ -19,6 +52,35 @@ gfx::Point Screen::GetCursorScreenPoint() { |
} |
// static |
+gfx::Rect Screen::GetPrimaryMonitorWorkArea() { |
+ // 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]; |
+ |
+ // 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])); |
+} |
+ |
+// static |
+gfx::Rect Screen::GetMonitorWorkAreaMatching(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), |