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 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <map> | 11 #include <map> |
12 | 12 |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/mac/sdk_forward_declarations.h" | 14 #include "base/mac/sdk_forward_declarations.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/timer/timer.h" | 16 #include "base/timer/timer.h" |
17 #include "ui/gfx/display.h" | 17 #include "ui/gfx/display.h" |
18 #include "ui/gfx/display_change_notifier.h" | 18 #include "ui/gfx/display_change_notifier.h" |
19 #include "ui/gfx/mac/coordinate_conversion.h" | |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 // The delay to handle the display configuration changes. | 23 // The delay to handle the display configuration changes. |
23 // See comments in ScreenMac::HandleDisplayReconfiguration. | 24 // See comments in ScreenMac::HandleDisplayReconfiguration. |
24 const int64_t kConfigureDelayMs = 500; | 25 const int64_t kConfigureDelayMs = 500; |
25 | 26 |
26 gfx::Rect ConvertCoordinateSystem(NSRect ns_rect) { | 27 gfx::Rect ConvertCoordinateSystem(NSRect ns_rect) { |
tapted
2016/03/01 08:11:58
this function isn't needed any more -- can just ca
| |
27 // Primary monitor is defined as the monitor with the menubar, | 28 return gfx::ScreenRectFromNSRect(ns_rect); |
28 // which is always at index 0. | |
29 NSScreen* primary_screen = [[NSScreen screens] firstObject]; | |
30 float primary_screen_height = [primary_screen frame].size.height; | |
31 gfx::Rect rect(NSRectToCGRect(ns_rect)); | |
32 rect.set_y(primary_screen_height - rect.y() - rect.height()); | |
33 return rect; | |
34 } | 29 } |
35 | 30 |
36 NSScreen* GetMatchingScreen(const gfx::Rect& match_rect) { | 31 NSScreen* GetMatchingScreen(const gfx::Rect& match_rect) { |
37 // Default to the monitor with the current keyboard focus, in case | 32 // Default to the monitor with the current keyboard focus, in case |
38 // |match_rect| is not on any screen at all. | 33 // |match_rect| is not on any screen at all. |
39 NSScreen* max_screen = [NSScreen mainScreen]; | 34 NSScreen* max_screen = [NSScreen mainScreen]; |
40 int max_area = 0; | 35 int max_area = 0; |
41 | 36 |
42 for (NSScreen* screen in [NSScreen screens]) { | 37 for (NSScreen* screen in [NSScreen screens]) { |
43 gfx::Rect monitor_area = ConvertCoordinateSystem([screen frame]); | 38 gfx::Rect monitor_area = ConvertCoordinateSystem([screen frame]); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 } | 93 } |
99 | 94 |
100 ~ScreenMac() override { | 95 ~ScreenMac() override { |
101 CGDisplayRemoveReconfigurationCallback( | 96 CGDisplayRemoveReconfigurationCallback( |
102 ScreenMac::DisplayReconfigurationCallBack, this); | 97 ScreenMac::DisplayReconfigurationCallBack, this); |
103 } | 98 } |
104 | 99 |
105 gfx::Point GetCursorScreenPoint() override { | 100 gfx::Point GetCursorScreenPoint() override { |
106 NSPoint mouseLocation = [NSEvent mouseLocation]; | 101 NSPoint mouseLocation = [NSEvent mouseLocation]; |
107 // Flip coordinates to gfx (0,0 in top-left corner) using primary screen. | 102 // Flip coordinates to gfx (0,0 in top-left corner) using primary screen. |
108 NSScreen* screen = [[NSScreen screens] firstObject]; | 103 return gfx::ScreenPointFromNSPoint(mouseLocation); |
tapted
2016/03/01 08:11:58
nit: can just pass [NSEvent mouseLocation]; in on
| |
109 mouseLocation.y = NSMaxY([screen frame]) - mouseLocation.y; | |
110 return gfx::Point(mouseLocation.x, mouseLocation.y); | |
111 } | 104 } |
112 | 105 |
113 gfx::NativeWindow GetWindowUnderCursor() override { | 106 gfx::NativeWindow GetWindowUnderCursor() override { |
114 NOTIMPLEMENTED(); | 107 NOTIMPLEMENTED(); |
115 return gfx::NativeWindow(); | 108 return gfx::NativeWindow(); |
116 } | 109 } |
117 | 110 |
118 gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override { | 111 gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override { |
119 NOTIMPLEMENTED(); | 112 NOTIMPLEMENTED(); |
120 return gfx::NativeWindow(); | 113 return gfx::NativeWindow(); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
275 | 268 |
276 namespace gfx { | 269 namespace gfx { |
277 | 270 |
278 #if !defined(USE_AURA) | 271 #if !defined(USE_AURA) |
279 Screen* CreateNativeScreen() { | 272 Screen* CreateNativeScreen() { |
280 return new ScreenMac; | 273 return new ScreenMac; |
281 } | 274 } |
282 #endif | 275 #endif |
283 | 276 |
284 } | 277 } |
OLD | NEW |