Chromium Code Reviews| Index: ui/gfx/screen_mac.mm |
| diff --git a/ui/gfx/screen_mac.mm b/ui/gfx/screen_mac.mm |
| index 28707ca7ea3a15ca95b127b2d6655fce60e624fa..9c5355ed22a28b366aea73c6bd11b9521e99a987 100644 |
| --- a/ui/gfx/screen_mac.mm |
| +++ b/ui/gfx/screen_mac.mm |
| @@ -7,6 +7,8 @@ |
| #import <ApplicationServices/ApplicationServices.h> |
| #import <Cocoa/Cocoa.h> |
| +#include <map> |
| + |
| #include "base/logging.h" |
| #include "base/mac/sdk_forward_declarations.h" |
| #include "ui/gfx/display.h" |
| @@ -96,10 +98,15 @@ class ScreenMac : public gfx::Screen { |
| } |
| virtual int GetNumDisplays() const OVERRIDE { |
| - // 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 |
| + return GetAllDisplays().size(); |
| + |
| + } |
| + |
| + virtual std::vector<gfx::Display> GetAllDisplays() const OVERRIDE { |
| + // Don't just return all online displays. This would include displays |
| + // that mirror other displays, which are not desired in this list. It's |
| // tempting to use the count returned by CGGetActiveDisplayList, but active |
| - // displays exclude sleeping displays, and those are desired in the count. |
| + // displays exclude sleeping displays, and those are desired. |
| // It would be ridiculous to have this many displays connected, but |
| // CGDirectDisplayID is just an integer, so supporting up to this many |
| @@ -109,29 +116,39 @@ class ScreenMac : public gfx::Screen { |
| if (CGGetOnlineDisplayList(arraysize(online_displays), |
| online_displays, |
| &online_display_count) != kCGErrorSuccess) { |
| - // 1 is a reasonable assumption. |
| - return 1; |
| + return std::vector<gfx::Display>(1, GetPrimaryDisplay()); |
| } |
| - int display_count = 0; |
| + typedef std::map<int64, NSScreen*> screenIdsToScreensMap; |
|
Nico
2013/10/25 18:16:49
types start with capital letters in chromium style
|
| + screenIdsToScreensMap screenIdsToScreens; |
| + for (NSScreen* screen in [NSScreen screens]) { |
| + NSDictionary* screenDeviceDescription = [screen deviceDescription]; |
| + int64 screenId = [[screenDeviceDescription |
| + objectForKey:@"NSScreenNumber"] unsignedIntValue]; |
| + screenIdsToScreens[screenId] = screen; |
| + } |
| + |
| + std::vector<gfx::Display> displays; |
| 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. |
| + // If this display doesn't mirror any other, include it in the list. |
| // The primary display in a mirrored set will be counted, but those that |
| // mirror it will not be. |
| - ++display_count; |
| + screenIdsToScreensMap::iterator foundScreen = |
| + screenIdsToScreens.find(online_display); |
| + if (!(foundScreen == screenIdsToScreens.end())) { |
|
Nico
2013/10/25 18:16:49
You can write !(a == b) as a != b
|
| + displays.push_back(GetDisplayForScreen(foundScreen->second, false)); |
|
Nico
2013/10/25 18:16:49
Won't one of these be the primary display? (see Ge
|
| + } |
| } |
| } |
| - return display_count; |
| - } |
| + if (!displays.size()) |
| + return std::vector<gfx::Display>(1, GetPrimaryDisplay()); |
| - virtual std::vector<gfx::Display> GetAllDisplays() const OVERRIDE { |
| - NOTIMPLEMENTED(); |
| - return std::vector<gfx::Display>(1, GetPrimaryDisplay()); |
| + return displays; |
| } |
| virtual gfx::Display GetDisplayNearestWindow( |