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

Side by Side 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 - map for screen ids 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/screen.h" 5 #include "ui/gfx/screen.h"
6 6
7 #import <ApplicationServices/ApplicationServices.h> 7 #import <ApplicationServices/ApplicationServices.h>
8 #import <Cocoa/Cocoa.h> 8 #import <Cocoa/Cocoa.h>
9 9
10 #include <map>
11
10 #include "base/logging.h" 12 #include "base/logging.h"
11 #include "base/mac/sdk_forward_declarations.h" 13 #include "base/mac/sdk_forward_declarations.h"
12 #include "ui/gfx/display.h" 14 #include "ui/gfx/display.h"
13 15
14 namespace { 16 namespace {
15 17
16 gfx::Rect ConvertCoordinateSystem(NSRect ns_rect) { 18 gfx::Rect ConvertCoordinateSystem(NSRect ns_rect) {
17 // Primary monitor is defined as the monitor with the menubar, 19 // Primary monitor is defined as the monitor with the menubar,
18 // which is always at index 0. 20 // which is always at index 0.
19 NSScreen* primary_screen = [[NSScreen screens] objectAtIndex:0]; 21 NSScreen* primary_screen = [[NSScreen screens] objectAtIndex:0];
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 return gfx::NativeWindow(); 91 return gfx::NativeWindow();
90 } 92 }
91 93
92 virtual gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) 94 virtual gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point)
93 OVERRIDE { 95 OVERRIDE {
94 NOTIMPLEMENTED(); 96 NOTIMPLEMENTED();
95 return gfx::NativeWindow(); 97 return gfx::NativeWindow();
96 } 98 }
97 99
98 virtual int GetNumDisplays() const OVERRIDE { 100 virtual int GetNumDisplays() const OVERRIDE {
99 // Don't just return the number of online displays. It includes displays 101 return GetAllDisplays().size();
100 // that mirror other displays, which are not desired in the count. It's 102
103 }
104
105 virtual std::vector<gfx::Display> GetAllDisplays() const OVERRIDE {
106 // Don't just return all online displays. This would include displays
107 // that mirror other displays, which are not desired in this list. It's
101 // tempting to use the count returned by CGGetActiveDisplayList, but active 108 // tempting to use the count returned by CGGetActiveDisplayList, but active
102 // displays exclude sleeping displays, and those are desired in the count. 109 // displays exclude sleeping displays, and those are desired.
103 110
104 // It would be ridiculous to have this many displays connected, but 111 // It would be ridiculous to have this many displays connected, but
105 // CGDirectDisplayID is just an integer, so supporting up to this many 112 // CGDirectDisplayID is just an integer, so supporting up to this many
106 // doesn't hurt. 113 // doesn't hurt.
107 CGDirectDisplayID online_displays[128]; 114 CGDirectDisplayID online_displays[128];
108 CGDisplayCount online_display_count = 0; 115 CGDisplayCount online_display_count = 0;
109 if (CGGetOnlineDisplayList(arraysize(online_displays), 116 if (CGGetOnlineDisplayList(arraysize(online_displays),
110 online_displays, 117 online_displays,
111 &online_display_count) != kCGErrorSuccess) { 118 &online_display_count) != kCGErrorSuccess) {
112 // 1 is a reasonable assumption. 119 return std::vector<gfx::Display>(1, GetPrimaryDisplay());
113 return 1;
114 } 120 }
115 121
116 int display_count = 0; 122 typedef std::map<int64, NSScreen*> screenIdsToScreensMap;
Nico 2013/10/25 18:16:49 types start with capital letters in chromium style
123 screenIdsToScreensMap screenIdsToScreens;
124 for (NSScreen* screen in [NSScreen screens]) {
125 NSDictionary* screenDeviceDescription = [screen deviceDescription];
126 int64 screenId = [[screenDeviceDescription
127 objectForKey:@"NSScreenNumber"] unsignedIntValue];
128 screenIdsToScreens[screenId] = screen;
129 }
130
131 std::vector<gfx::Display> displays;
117 for (CGDisplayCount online_display_index = 0; 132 for (CGDisplayCount online_display_index = 0;
118 online_display_index < online_display_count; 133 online_display_index < online_display_count;
119 ++online_display_index) { 134 ++online_display_index) {
120 CGDirectDisplayID online_display = online_displays[online_display_index]; 135 CGDirectDisplayID online_display = online_displays[online_display_index];
121 if (CGDisplayMirrorsDisplay(online_display) == kCGNullDirectDisplay) { 136 if (CGDisplayMirrorsDisplay(online_display) == kCGNullDirectDisplay) {
122 // If this display doesn't mirror any other, include it in the count. 137 // If this display doesn't mirror any other, include it in the list.
123 // The primary display in a mirrored set will be counted, but those that 138 // The primary display in a mirrored set will be counted, but those that
124 // mirror it will not be. 139 // mirror it will not be.
125 ++display_count; 140 screenIdsToScreensMap::iterator foundScreen =
141 screenIdsToScreens.find(online_display);
142 if (!(foundScreen == screenIdsToScreens.end())) {
Nico 2013/10/25 18:16:49 You can write !(a == b) as a != b
143 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
144 }
126 } 145 }
127 } 146 }
128 147
129 return display_count; 148 if (!displays.size())
130 } 149 return std::vector<gfx::Display>(1, GetPrimaryDisplay());
131 150
132 virtual std::vector<gfx::Display> GetAllDisplays() const OVERRIDE { 151 return displays;
133 NOTIMPLEMENTED();
134 return std::vector<gfx::Display>(1, GetPrimaryDisplay());
135 } 152 }
136 153
137 virtual gfx::Display GetDisplayNearestWindow( 154 virtual gfx::Display GetDisplayNearestWindow(
138 gfx::NativeView view) const OVERRIDE { 155 gfx::NativeView view) const OVERRIDE {
139 NSWindow* window = [view window]; 156 NSWindow* window = [view window];
140 if (!window) 157 if (!window)
141 return GetPrimaryDisplay(); 158 return GetPrimaryDisplay();
142 NSScreen* match_screen = [window screen]; 159 NSScreen* match_screen = [window screen];
143 return GetDisplayForScreen(match_screen, false /* may not be primary */); 160 return GetDisplayForScreen(match_screen, false /* may not be primary */);
144 } 161 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 204
188 } // namespace 205 } // namespace
189 206
190 namespace gfx { 207 namespace gfx {
191 208
192 Screen* CreateNativeScreen() { 209 Screen* CreateNativeScreen() {
193 return new ScreenMac; 210 return new ScreenMac;
194 } 211 }
195 212
196 } 213 }
OLDNEW
« 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