OLD | NEW |
---|---|
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 "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 return gfx::NativeWindow(); | 89 return gfx::NativeWindow(); |
90 } | 90 } |
91 | 91 |
92 virtual gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) | 92 virtual gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) |
93 OVERRIDE { | 93 OVERRIDE { |
94 NOTIMPLEMENTED(); | 94 NOTIMPLEMENTED(); |
95 return gfx::NativeWindow(); | 95 return gfx::NativeWindow(); |
96 } | 96 } |
97 | 97 |
98 virtual int GetNumDisplays() const OVERRIDE { | 98 virtual int GetNumDisplays() const OVERRIDE { |
99 // Don't just return the number of online displays. It includes displays | 99 return GetAllDisplays().size(); |
100 // that mirror other displays, which are not desired in the count. It's | 100 |
101 } | |
102 | |
103 virtual std::vector<gfx::Display> GetAllDisplays() const OVERRIDE { | |
104 // Don't just return all online displays. This would include displays | |
105 // that mirror other displays, which are not desired in this list. It's | |
101 // tempting to use the count returned by CGGetActiveDisplayList, but active | 106 // tempting to use the count returned by CGGetActiveDisplayList, but active |
102 // displays exclude sleeping displays, and those are desired in the count. | 107 // displays exclude sleeping displays, and those are desired. |
103 | 108 |
104 // It would be ridiculous to have this many displays connected, but | 109 // It would be ridiculous to have this many displays connected, but |
105 // CGDirectDisplayID is just an integer, so supporting up to this many | 110 // CGDirectDisplayID is just an integer, so supporting up to this many |
106 // doesn't hurt. | 111 // doesn't hurt. |
107 CGDirectDisplayID online_displays[128]; | 112 CGDirectDisplayID online_displays[128]; |
108 CGDisplayCount online_display_count = 0; | 113 CGDisplayCount online_display_count = 0; |
109 if (CGGetOnlineDisplayList(arraysize(online_displays), | 114 if (CGGetOnlineDisplayList(arraysize(online_displays), |
110 online_displays, | 115 online_displays, |
111 &online_display_count) != kCGErrorSuccess) { | 116 &online_display_count) != kCGErrorSuccess) { |
112 // 1 is a reasonable assumption. | 117 return std::vector<gfx::Display>(1, GetPrimaryDisplay()); |
113 return 1; | |
114 } | 118 } |
115 | 119 |
116 int display_count = 0; | 120 std::vector<gfx::Display> displays; |
117 for (CGDisplayCount online_display_index = 0; | 121 for (CGDisplayCount online_display_index = 0; |
118 online_display_index < online_display_count; | 122 online_display_index < online_display_count; |
119 ++online_display_index) { | 123 ++online_display_index) { |
120 CGDirectDisplayID online_display = online_displays[online_display_index]; | 124 CGDirectDisplayID online_display = online_displays[online_display_index]; |
121 if (CGDisplayMirrorsDisplay(online_display) == kCGNullDirectDisplay) { | 125 if (CGDisplayMirrorsDisplay(online_display) == kCGNullDirectDisplay) { |
122 // If this display doesn't mirror any other, include it in the count. | 126 // 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 | 127 // The primary display in a mirrored set will be counted, but those that |
124 // mirror it will not be. | 128 // mirror it will not be. |
125 ++display_count; | 129 // Search for the associated screen and add it to our list. |
130 for (NSScreen* screen in [NSScreen screens]) { | |
131 NSDictionary* screenDeviceDescription = [screen deviceDescription]; | |
Nico
2013/10/24 15:41:27
Can you build an id -> NSScreen map before this lo
| |
132 if (online_display == [[screenDeviceDescription | |
133 objectForKey:@"NSScreenNumber"] unsignedIntValue]) { | |
134 displays.push_back(GetDisplayForScreen(screen, false)); | |
135 } | |
136 } | |
126 } | 137 } |
127 } | 138 } |
128 | 139 |
129 return display_count; | 140 if (!displays.size()) |
130 } | 141 return std::vector<gfx::Display>(1, GetPrimaryDisplay()); |
131 | 142 |
132 virtual std::vector<gfx::Display> GetAllDisplays() const OVERRIDE { | 143 return displays; |
133 NOTIMPLEMENTED(); | |
134 return std::vector<gfx::Display>(1, GetPrimaryDisplay()); | |
135 } | 144 } |
136 | 145 |
137 virtual gfx::Display GetDisplayNearestWindow( | 146 virtual gfx::Display GetDisplayNearestWindow( |
138 gfx::NativeView view) const OVERRIDE { | 147 gfx::NativeView view) const OVERRIDE { |
139 NSWindow* window = [view window]; | 148 NSWindow* window = [view window]; |
140 if (!window) | 149 if (!window) |
141 return GetPrimaryDisplay(); | 150 return GetPrimaryDisplay(); |
142 NSScreen* match_screen = [window screen]; | 151 NSScreen* match_screen = [window screen]; |
143 return GetDisplayForScreen(match_screen, false /* may not be primary */); | 152 return GetDisplayForScreen(match_screen, false /* may not be primary */); |
144 } | 153 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 | 196 |
188 } // namespace | 197 } // namespace |
189 | 198 |
190 namespace gfx { | 199 namespace gfx { |
191 | 200 |
192 Screen* CreateNativeScreen() { | 201 Screen* CreateNativeScreen() { |
193 return new ScreenMac; | 202 return new ScreenMac; |
194 } | 203 } |
195 | 204 |
196 } | 205 } |
OLD | NEW |