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

Side by Side Diff: ui/gfx/screen_mac.mm

Issue 11030017: Add context to gfx::Screen calls in support of simultaneous desktop+ash (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix other os's Created 8 years, 2 months 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 | Annotate | Revision Log
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 "base/logging.h" 10 #include "base/logging.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 } // namespace 78 } // namespace
79 79
80 namespace gfx { 80 namespace gfx {
81 81
82 // static 82 // static
83 bool Screen::IsDIPEnabled() { 83 bool Screen::IsDIPEnabled() {
84 return true; 84 return true;
85 } 85 }
86 86
87 // static 87 // static
88 gfx::Point Screen::GetCursorScreenPoint() { 88 gfx::Point Screen::GetCursorScreenPoint(gfx::NativeView context) {
89 NSPoint mouseLocation = [NSEvent mouseLocation]; 89 NSPoint mouseLocation = [NSEvent mouseLocation];
90 // Flip coordinates to gfx (0,0 in top-left corner) using primary screen. 90 // Flip coordinates to gfx (0,0 in top-left corner) using primary screen.
91 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; 91 NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
92 mouseLocation.y = NSMaxY([screen frame]) - mouseLocation.y; 92 mouseLocation.y = NSMaxY([screen frame]) - mouseLocation.y;
93 return gfx::Point(mouseLocation.x, mouseLocation.y); 93 return gfx::Point(mouseLocation.x, mouseLocation.y);
94 } 94 }
95 95
96 // static 96 // static
97 gfx::Display Screen::GetDisplayNearestWindow(gfx::NativeView view) { 97 gfx::Display Screen::GetDisplayNearestWindow(gfx::NativeView view) {
98 NSWindow* window = [view window]; 98 NSWindow* window = [view window];
99 if (!window) 99 if (!window)
100 return GetPrimaryDisplay(); 100 return GetPrimaryDisplay(view);
101 NSScreen* match_screen = [window screen]; 101 NSScreen* match_screen = [window screen];
102 return GetDisplayForScreen(match_screen, false /* may not be primary */); 102 return GetDisplayForScreen(match_screen, false /* may not be primary */);
103 } 103 }
104 104
105 // static 105 // static
106 gfx::Display Screen::GetDisplayMatching(const gfx::Rect& match_rect) { 106 gfx::Display Screen::GetDisplayMatching(
107 gfx::NativeView context, const gfx::Rect& match_rect) {
107 NSScreen* match_screen = GetMatchingScreen(match_rect); 108 NSScreen* match_screen = GetMatchingScreen(match_rect);
108 return GetDisplayForScreen(match_screen, false /* may not be primary */); 109 return GetDisplayForScreen(match_screen, false /* may not be primary */);
109 } 110 }
110 111
111 // static 112 // static
112 gfx::Display Screen::GetPrimaryDisplay() { 113 gfx::Display Screen::GetPrimaryDisplay(gfx::NativeView context) {
113 // Primary display is defined as the display with the menubar, 114 // Primary display is defined as the display with the menubar,
114 // which is always at index 0. 115 // which is always at index 0.
115 NSScreen* primary = [[NSScreen screens] objectAtIndex:0]; 116 NSScreen* primary = [[NSScreen screens] objectAtIndex:0];
116 gfx::Display display = GetDisplayForScreen(primary, true /* primary */); 117 gfx::Display display = GetDisplayForScreen(primary, true /* primary */);
117 return display; 118 return display;
118 } 119 }
119 120
120 // static 121 // static
121 int Screen::GetNumDisplays() { 122 int Screen::GetNumDisplays(gfx::NativeView context) {
122 // Don't just return the number of online displays. It includes displays 123 // Don't just return the number of online displays. It includes displays
123 // that mirror other displays, which are not desired in the count. It's 124 // that mirror other displays, which are not desired in the count. It's
124 // tempting to use the count returned by CGGetActiveDisplayList, but active 125 // tempting to use the count returned by CGGetActiveDisplayList, but active
125 // displays exclude sleeping displays, and those are desired in the count. 126 // displays exclude sleeping displays, and those are desired in the count.
126 127
127 // It would be ridiculous to have this many displays connected, but 128 // It would be ridiculous to have this many displays connected, but
128 // CGDirectDisplayID is just an integer, so supporting up to this many 129 // CGDirectDisplayID is just an integer, so supporting up to this many
129 // doesn't hurt. 130 // doesn't hurt.
130 CGDirectDisplayID online_displays[128]; 131 CGDirectDisplayID online_displays[128];
131 CGDisplayCount online_display_count = 0; 132 CGDisplayCount online_display_count = 0;
(...skipping 14 matching lines...) Expand all
146 // The primary display in a mirrored set will be counted, but those that 147 // The primary display in a mirrored set will be counted, but those that
147 // mirror it will not be. 148 // mirror it will not be.
148 ++display_count; 149 ++display_count;
149 } 150 }
150 } 151 }
151 152
152 return display_count; 153 return display_count;
153 } 154 }
154 155
155 // static 156 // static
156 gfx::Display Screen::GetDisplayNearestPoint(const gfx::Point& point) { 157 gfx::Display Screen::GetDisplayNearestPoint(
158 gfx::NativeView context, const gfx::Point& point) {
157 NSPoint ns_point = NSPointFromCGPoint(point.ToCGPoint()); 159 NSPoint ns_point = NSPointFromCGPoint(point.ToCGPoint());
158 160
159 NSArray* screens = [NSScreen screens]; 161 NSArray* screens = [NSScreen screens];
160 NSScreen* primary = [screens objectAtIndex:0]; 162 NSScreen* primary = [screens objectAtIndex:0];
161 for (NSScreen* screen in screens) { 163 for (NSScreen* screen in screens) {
162 if (NSMouseInRect(ns_point, [screen frame], NO)) 164 if (NSMouseInRect(ns_point, [screen frame], NO))
163 return GetDisplayForScreen(screen, screen == primary); 165 return GetDisplayForScreen(screen, screen == primary);
164 } 166 }
165 return GetPrimaryDisplay(); 167 return GetPrimaryDisplay();
166 } 168 }
167 169
168 } // namespace gfx 170 } // namespace gfx
OLDNEW
« ui/gfx/screen_aura.cc ('K') | « ui/gfx/screen_ios.mm ('k') | ui/gfx/screen_type_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698