Index: ui/gfx/screen_mac.mm |
diff --git a/ui/gfx/screen_mac.mm b/ui/gfx/screen_mac.mm |
index a3b7306d593f817f8b1976e28f0fbd77721866f0..3bf26798c1c5f94298ef5978bd93815410875cc4 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,26 @@ NSScreen* GetMatchingScreen(const gfx::Rect& match_rect) { |
return max_screen; |
} |
+gfx::Monitor* GetMonitorForScreen(NSScreen* screen, bool is_primary) { |
+ static gfx::SimpleMonitor* monitor = new gfx::SimpleMonitor(); |
dhollowa
2012/04/09 23:41:37
This will cause SimpleMonitor destructor to fire p
oshima
2012/04/10 00:09:08
This isn't uncommon for near POD objects such as F
|
+ |
+ NSRect frame = [screen frame]; |
+ monitor->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->set_work_area(work_area); |
+ } else { |
+ monitor->set_work_area(ConvertCoordinateSystem(visible_frame)); |
+ } |
+ return monitor; |
+} |
+ |
} // namespace |
namespace gfx { |
@@ -52,39 +75,24 @@ gfx::Point Screen::GetCursorScreenPoint() { |
} |
// static |
-gfx::Rect Screen::GetPrimaryMonitorWorkArea() { |
+const 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]; |
- |
- // 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; |
-} |
+ gfx::Monitor* monitor = GetMonitorForScreen(primary, true /* primary */); |
-// 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->GetSize().width()); |
+ CHECK_EQ(static_cast<const int>(CGDisplayPixelsHigh(main_display)), |
+ monitor->GetSize().height()); |
+ return monitor; |
} |
// static |
-gfx::Rect Screen::GetMonitorWorkAreaMatching(const gfx::Rect& match_rect) { |
+const 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 |