Chromium Code Reviews| Index: ui/gfx/screen_mac.mm |
| diff --git a/ui/gfx/screen_mac.mm b/ui/gfx/screen_mac.mm |
| index f63bd306cd8bb19273def02b0ebbfe24ddf97b53..d4e0a0b88bb85387f0c6a773f9961d5916af66b7 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" |
| @@ -97,10 +99,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 |
| @@ -110,29 +117,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; |
| + ScreenIdsToScreensMap screenIdsToScreens; |
|
Nico
2013/11/01 21:45:47
name_variables_like_this_in_chromium_style in c++
|
| + for (NSScreen* screen in [NSScreen screens]) { |
| + NSDictionary* screenDeviceDescription = [screen deviceDescription]; |
|
Nico
2013/11/01 21:45:47
screen_device_description
|
| + int64 screenId = [[screenDeviceDescription |
|
Nico
2013/11/01 21:45:47
screen_id
|
| + 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()) { |
| + displays.push_back(GetDisplayForScreen(foundScreen->second)); |
| + } |
| } |
| } |
| - 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( |