Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(283)

Unified Diff: ui/gfx/screen_mac.mm

Issue 40163002: Implement GetAllDisplays() for the Mac screen backend (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Implement GetAllDisplays() - variable naming Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/screen_mac.mm
diff --git a/ui/gfx/screen_mac.mm b/ui/gfx/screen_mac.mm
index f63bd306cd8bb19273def02b0ebbfe24ddf97b53..51c0b665b7e34274b98cf4c2d3386898af8c98f3 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 screen_ids_to_screens;
+ for (NSScreen* screen in [NSScreen screens]) {
+ NSDictionary* screen_device_description = [screen deviceDescription];
+ int64 screen_id = [[screen_device_description
+ objectForKey:@"NSScreenNumber"] unsignedIntValue];
+ screen_ids_to_screens[screen_id] = 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 =
+ screen_ids_to_screens.find(online_display);
+ if (foundScreen != screen_ids_to_screens.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(
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698