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 <map> | 10 #include <map> |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 | 84 |
85 class ScreenMac : public gfx::Screen { | 85 class ScreenMac : public gfx::Screen { |
86 public: | 86 public: |
87 ScreenMac() { | 87 ScreenMac() { |
88 displays_ = BuildDisplaysFromQuartz(); | 88 displays_ = BuildDisplaysFromQuartz(); |
89 | 89 |
90 CGDisplayRegisterReconfigurationCallback( | 90 CGDisplayRegisterReconfigurationCallback( |
91 ScreenMac::DisplayReconfigurationCallBack, this); | 91 ScreenMac::DisplayReconfigurationCallBack, this); |
92 } | 92 } |
93 | 93 |
94 virtual bool IsDIPEnabled() OVERRIDE { | 94 virtual bool IsDIPEnabled() override { |
95 return true; | 95 return true; |
96 } | 96 } |
97 | 97 |
98 virtual gfx::Point GetCursorScreenPoint() OVERRIDE { | 98 virtual gfx::Point GetCursorScreenPoint() override { |
99 NSPoint mouseLocation = [NSEvent mouseLocation]; | 99 NSPoint mouseLocation = [NSEvent mouseLocation]; |
100 // Flip coordinates to gfx (0,0 in top-left corner) using primary screen. | 100 // Flip coordinates to gfx (0,0 in top-left corner) using primary screen. |
101 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; | 101 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; |
102 mouseLocation.y = NSMaxY([screen frame]) - mouseLocation.y; | 102 mouseLocation.y = NSMaxY([screen frame]) - mouseLocation.y; |
103 return gfx::Point(mouseLocation.x, mouseLocation.y); | 103 return gfx::Point(mouseLocation.x, mouseLocation.y); |
104 } | 104 } |
105 | 105 |
106 virtual gfx::NativeWindow GetWindowUnderCursor() OVERRIDE { | 106 virtual gfx::NativeWindow GetWindowUnderCursor() override { |
107 NOTIMPLEMENTED(); | 107 NOTIMPLEMENTED(); |
108 return gfx::NativeWindow(); | 108 return gfx::NativeWindow(); |
109 } | 109 } |
110 | 110 |
111 virtual gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) | 111 virtual gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) |
112 OVERRIDE { | 112 override { |
113 NOTIMPLEMENTED(); | 113 NOTIMPLEMENTED(); |
114 return gfx::NativeWindow(); | 114 return gfx::NativeWindow(); |
115 } | 115 } |
116 | 116 |
117 virtual int GetNumDisplays() const OVERRIDE { | 117 virtual int GetNumDisplays() const override { |
118 return GetAllDisplays().size(); | 118 return GetAllDisplays().size(); |
119 | 119 |
120 } | 120 } |
121 | 121 |
122 virtual std::vector<gfx::Display> GetAllDisplays() const OVERRIDE { | 122 virtual std::vector<gfx::Display> GetAllDisplays() const override { |
123 return displays_; | 123 return displays_; |
124 } | 124 } |
125 | 125 |
126 virtual gfx::Display GetDisplayNearestWindow( | 126 virtual gfx::Display GetDisplayNearestWindow( |
127 gfx::NativeView view) const OVERRIDE { | 127 gfx::NativeView view) const override { |
128 NSWindow* window = nil; | 128 NSWindow* window = nil; |
129 #if !defined(USE_AURA) | 129 #if !defined(USE_AURA) |
130 if (view) | 130 if (view) |
131 window = [view window]; | 131 window = [view window]; |
132 #endif | 132 #endif |
133 if (!window) | 133 if (!window) |
134 return GetPrimaryDisplay(); | 134 return GetPrimaryDisplay(); |
135 NSScreen* match_screen = [window screen]; | 135 NSScreen* match_screen = [window screen]; |
136 if (!match_screen) | 136 if (!match_screen) |
137 return GetPrimaryDisplay(); | 137 return GetPrimaryDisplay(); |
138 return GetDisplayForScreen(match_screen); | 138 return GetDisplayForScreen(match_screen); |
139 } | 139 } |
140 | 140 |
141 virtual gfx::Display GetDisplayNearestPoint( | 141 virtual gfx::Display GetDisplayNearestPoint( |
142 const gfx::Point& point) const OVERRIDE { | 142 const gfx::Point& point) const override { |
143 NSPoint ns_point = NSPointFromCGPoint(point.ToCGPoint()); | 143 NSPoint ns_point = NSPointFromCGPoint(point.ToCGPoint()); |
144 | 144 |
145 NSArray* screens = [NSScreen screens]; | 145 NSArray* screens = [NSScreen screens]; |
146 NSScreen* primary = [screens objectAtIndex:0]; | 146 NSScreen* primary = [screens objectAtIndex:0]; |
147 ns_point.y = NSMaxY([primary frame]) - ns_point.y; | 147 ns_point.y = NSMaxY([primary frame]) - ns_point.y; |
148 for (NSScreen* screen in screens) { | 148 for (NSScreen* screen in screens) { |
149 if (NSMouseInRect(ns_point, [screen frame], NO)) | 149 if (NSMouseInRect(ns_point, [screen frame], NO)) |
150 return GetDisplayForScreen(screen); | 150 return GetDisplayForScreen(screen); |
151 } | 151 } |
152 return GetPrimaryDisplay(); | 152 return GetPrimaryDisplay(); |
153 } | 153 } |
154 | 154 |
155 // Returns the display that most closely intersects the provided bounds. | 155 // Returns the display that most closely intersects the provided bounds. |
156 virtual gfx::Display GetDisplayMatching( | 156 virtual gfx::Display GetDisplayMatching( |
157 const gfx::Rect& match_rect) const OVERRIDE { | 157 const gfx::Rect& match_rect) const override { |
158 NSScreen* match_screen = GetMatchingScreen(match_rect); | 158 NSScreen* match_screen = GetMatchingScreen(match_rect); |
159 return GetDisplayForScreen(match_screen); | 159 return GetDisplayForScreen(match_screen); |
160 } | 160 } |
161 | 161 |
162 // Returns the primary display. | 162 // Returns the primary display. |
163 virtual gfx::Display GetPrimaryDisplay() const OVERRIDE { | 163 virtual gfx::Display GetPrimaryDisplay() const override { |
164 // Primary display is defined as the display with the menubar, | 164 // Primary display is defined as the display with the menubar, |
165 // which is always at index 0. | 165 // which is always at index 0. |
166 NSScreen* primary = [[NSScreen screens] objectAtIndex:0]; | 166 NSScreen* primary = [[NSScreen screens] objectAtIndex:0]; |
167 gfx::Display display = GetDisplayForScreen(primary); | 167 gfx::Display display = GetDisplayForScreen(primary); |
168 return display; | 168 return display; |
169 } | 169 } |
170 | 170 |
171 virtual void AddObserver(gfx::DisplayObserver* observer) OVERRIDE { | 171 virtual void AddObserver(gfx::DisplayObserver* observer) override { |
172 change_notifier_.AddObserver(observer); | 172 change_notifier_.AddObserver(observer); |
173 } | 173 } |
174 | 174 |
175 virtual void RemoveObserver(gfx::DisplayObserver* observer) OVERRIDE { | 175 virtual void RemoveObserver(gfx::DisplayObserver* observer) override { |
176 change_notifier_.RemoveObserver(observer); | 176 change_notifier_.RemoveObserver(observer); |
177 } | 177 } |
178 | 178 |
179 static void DisplayReconfigurationCallBack(CGDirectDisplayID display, | 179 static void DisplayReconfigurationCallBack(CGDirectDisplayID display, |
180 CGDisplayChangeSummaryFlags flags, | 180 CGDisplayChangeSummaryFlags flags, |
181 void* userInfo) { | 181 void* userInfo) { |
182 if (flags & kCGDisplayBeginConfigurationFlag) | 182 if (flags & kCGDisplayBeginConfigurationFlag) |
183 return; | 183 return; |
184 | 184 |
185 static_cast<ScreenMac*>(userInfo)->HandleDisplayReconfiguration(); | 185 static_cast<ScreenMac*>(userInfo)->HandleDisplayReconfiguration(); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 | 275 |
276 namespace gfx { | 276 namespace gfx { |
277 | 277 |
278 #if !defined(USE_AURA) | 278 #if !defined(USE_AURA) |
279 Screen* CreateNativeScreen() { | 279 Screen* CreateNativeScreen() { |
280 return new ScreenMac; | 280 return new ScreenMac; |
281 } | 281 } |
282 #endif | 282 #endif |
283 | 283 |
284 } | 284 } |
OLD | NEW |