diff options
author | derat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-25 00:39:35 +0000 |
---|---|---|
committer | derat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-25 00:39:35 +0000 |
commit | 6b7d954ff37811b45fac57e34418ff1c169b6ef8 (patch) | |
tree | f9b48972f6343d85508e1277bc9c524d7cb222a2 /ui/gfx/screen_mac.mm | |
parent | ed5c8219cf7da9a89d3da219c09f777ac3998ba9 (diff) | |
download | chromium_src-6b7d954ff37811b45fac57e34418ff1c169b6ef8.zip chromium_src-6b7d954ff37811b45fac57e34418ff1c169b6ef8.tar.gz chromium_src-6b7d954ff37811b45fac57e34418ff1c169b6ef8.tar.bz2 |
Move DisplayUtils methods into gfx::Screen.
These methods are currently just used by metrics. I moved
them from base into the browser a while back, but I think it
makes the most sense for them to live in gfx::Screen. I'm
also relocating the tests to ui_unittest and making them work
on Aura.
BUG=99711,100341
TEST=ran ui_unittest
Review URL: http://codereview.chromium.org/8382019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107027 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/screen_mac.mm')
-rw-r--r-- | ui/gfx/screen_mac.mm | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/ui/gfx/screen_mac.mm b/ui/gfx/screen_mac.mm index b38344a..6bf0992 100644 --- a/ui/gfx/screen_mac.mm +++ b/ui/gfx/screen_mac.mm @@ -4,6 +4,7 @@ #include "ui/gfx/screen.h" +#import <ApplicationServices/ApplicationServices.h> #import <Cocoa/Cocoa.h> namespace gfx { @@ -17,4 +18,46 @@ gfx::Point Screen::GetCursorScreenPoint() { return gfx::Point(mouseLocation.x, mouseLocation.y); } +// static +gfx::Size Screen::GetPrimaryMonitorSize() { + CGDirectDisplayID main_display = CGMainDisplayID(); + return gfx::Size(CGDisplayPixelsWide(main_display), + CGDisplayPixelsHigh(main_display)); +} + +// static +int Screen::GetNumMonitors() { + // Don't just return the number of online displays. It includes displays + // that mirror other displays, which are not desired in the count. It's + // tempting to use the count returned by CGGetActiveDisplayList, but active + // displays exclude sleeping displays, and those are desired in the count. + + // It would be ridiculous to have this many displays connected, but + // CGDirectDisplayID is just an integer, so supporting up to this many + // doesn't hurt. + CGDirectDisplayID online_displays[128]; + CGDisplayCount online_display_count = 0; + if (CGGetOnlineDisplayList(arraysize(online_displays), + online_displays, + &online_display_count) != kCGErrorSuccess) { + // 1 is a reasonable assumption. + return 1; + } + + int display_count = 0; + for (CGDisplayCount online_display_index = 0; + online_display_index < online_display_count; + ++online_display_index) { + CGDirectDisplayID online_display = online_displays[online_display_index]; + if (CGDisplayMirrorsDisplay(online_display) == kCGNullDirectDisplay) { + // If this display doesn't mirror any other, include it in the count. + // The primary display in a mirrored set will be counted, but those that + // mirror it will not be. + ++display_count; + } + } + + return display_count; +} + } // namespace gfx |