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

Side by Side Diff: webkit/glue/webcursor_mac.mm

Issue 7645026: Fix missing cursors. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 4 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
« 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "webkit/glue/webcursor.h" 5 #include "webkit/glue/webcursor.h"
6 6
7 #import <AppKit/AppKit.h> 7 #import <AppKit/AppKit.h>
8 #include <Carbon/Carbon.h> 8 #include <Carbon/Carbon.h>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/mac/mac_util.h"
11 #include "base/mac/scoped_cftyperef.h" 12 #include "base/mac/scoped_cftyperef.h"
12 #include "base/memory/scoped_nsobject.h" 13 #include "base/memory/scoped_nsobject.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebImage.h" 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebImage.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h"
16 #include "ui/gfx/mac/nsimage_cache.h" 17 #include "ui/gfx/mac/nsimage_cache.h"
17 18
18 #if WEBKIT_USING_SKIA 19 #if WEBKIT_USING_SKIA
19 #include "skia/ext/skia_utils_mac.h" 20 #include "skia/ext/skia_utils_mac.h"
20 #endif 21 #endif
21 22
22 using WebKit::WebCursorInfo; 23 using WebKit::WebCursorInfo;
23 using WebKit::WebImage; 24 using WebKit::WebImage;
24 using WebKit::WebSize; 25 using WebKit::WebSize;
25 26
27 // Forward-declare symbols that are part of the 10.6 SDK.
Mark Mentovai 2011/08/15 16:00:08 Nit: These are declarations, not really anything e
Avi (use Gerrit) 2011/08/15 16:09:34 Done.
28 #if !defined(MAC_OS_X_VERSION_10_6) || \
29 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6
30
31 @interface NSCursor (SnowLeopardSDKDeclarations)
32 + (NSCursor *)contextualMenuCursor;
Mark Mentovai 2011/08/15 16:00:08 Nit: This file uses NSCursor* style, no space.
Avi (use Gerrit) 2011/08/15 16:09:34 Done.
33 + (NSCursor *)dragCopyCursor;
34 + (NSCursor *)operationNotAllowedCursor;
35 @end
36
37 #endif // MAC_OS_X_VERSION_10_6
38
39 // Forward-declare symbols that are part of the 10.7 SDK.
40 #if !defined(MAC_OS_X_VERSION_10_7) || \
41 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7
42
43 @interface NSCursor (LionSDKDeclarations)
44 + (NSCursor *)IBeamCursorForVerticalLayout;
45 @end
46
47 #endif // MAC_OS_X_VERSION_10_7
48
26 namespace { 49 namespace {
27 50
28 // TODO: This image fetch can (and probably should) be serviced by the resource 51 // TODO: This image fetch can (and probably should) be serviced by the resource
29 // resource bundle instead of going through the image cache. 52 // resource bundle instead of going through the image cache.
30 NSCursor* LoadCursor(const char* name, int x, int y) { 53 NSCursor* LoadCursor(const char* name, int x, int y) {
31 NSString* file_name = [NSString stringWithUTF8String:name]; 54 NSString* file_name = [NSString stringWithUTF8String:name];
32 DCHECK(file_name); 55 DCHECK(file_name);
33 NSImage* cursor_image = gfx::GetCachedImageWithName(file_name); 56 NSImage* cursor_image = gfx::GetCachedImageWithName(file_name);
34 DCHECK(cursor_image); 57 DCHECK(cursor_image);
35 return [[[NSCursor alloc] initWithImage:cursor_image 58 return [[[NSCursor alloc] initWithImage:cursor_image
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 } 110 }
88 111
89 } // namespace 112 } // namespace
90 113
91 // We're matching Safari's cursor choices; see platform/mac/CursorMac.mm 114 // We're matching Safari's cursor choices; see platform/mac/CursorMac.mm
92 NSCursor* WebCursor::GetCursor() const { 115 NSCursor* WebCursor::GetCursor() const {
93 switch (type_) { 116 switch (type_) {
94 case WebCursorInfo::TypePointer: 117 case WebCursorInfo::TypePointer:
95 return [NSCursor arrowCursor]; 118 return [NSCursor arrowCursor];
96 case WebCursorInfo::TypeCross: 119 case WebCursorInfo::TypeCross:
97 return LoadCursor("crossHairCursor", 11, 11); 120 return [NSCursor crosshairCursor];
98 case WebCursorInfo::TypeHand: 121 case WebCursorInfo::TypeHand:
99 return LoadCursor("linkCursor", 6, 1); 122 // If >= 10.7, the pointingHandCursor has a shadow so use it. Otherwise
123 // use the custom one.
124 if (base::mac::IsOSLionOrLater())
125 return [NSCursor pointingHandCursor];
126 else
127 return LoadCursor("linkCursor", 6, 1);
100 case WebCursorInfo::TypeIBeam: 128 case WebCursorInfo::TypeIBeam:
101 return [NSCursor IBeamCursor]; 129 return [NSCursor IBeamCursor];
102 case WebCursorInfo::TypeWait: 130 case WebCursorInfo::TypeWait:
103 return LoadCursor("waitCursor", 7, 7); 131 return LoadCursor("waitCursor", 7, 7);
104 case WebCursorInfo::TypeHelp: 132 case WebCursorInfo::TypeHelp:
105 return LoadCursor("helpCursor", 8, 8); 133 return LoadCursor("helpCursor", 8, 8);
106 case WebCursorInfo::TypeEastResize: 134 case WebCursorInfo::TypeEastResize:
107 case WebCursorInfo::TypeEastPanning: 135 case WebCursorInfo::TypeEastPanning:
108 return LoadCursor("eastResizeCursor", 14, 7); 136 return LoadCursor("eastResizeCursor", 14, 7);
109 case WebCursorInfo::TypeNorthResize: 137 case WebCursorInfo::TypeNorthResize:
(...skipping 26 matching lines...) Expand all
136 case WebCursorInfo::TypeNorthWestSouthEastResize: 164 case WebCursorInfo::TypeNorthWestSouthEastResize:
137 return LoadCursor("northWestSouthEastResizeCursor", 7, 7); 165 return LoadCursor("northWestSouthEastResizeCursor", 7, 7);
138 case WebCursorInfo::TypeColumnResize: 166 case WebCursorInfo::TypeColumnResize:
139 return [NSCursor resizeLeftRightCursor]; 167 return [NSCursor resizeLeftRightCursor];
140 case WebCursorInfo::TypeRowResize: 168 case WebCursorInfo::TypeRowResize:
141 return [NSCursor resizeUpDownCursor]; 169 return [NSCursor resizeUpDownCursor];
142 case WebCursorInfo::TypeMiddlePanning: 170 case WebCursorInfo::TypeMiddlePanning:
143 case WebCursorInfo::TypeMove: 171 case WebCursorInfo::TypeMove:
144 return LoadCursor("moveCursor", 7, 7); 172 return LoadCursor("moveCursor", 7, 7);
145 case WebCursorInfo::TypeVerticalText: 173 case WebCursorInfo::TypeVerticalText:
146 return LoadCursor("verticalTextCursor", 7, 7); 174 // IBeamCursorForVerticalLayout is >= 10.7.
175 if ([NSCursor respondsToSelector:@selector(IBeamCursorForVerticalLayout)])
176 return [NSCursor IBeamCursorForVerticalLayout];
177 else
178 return LoadCursor("verticalTextCursor", 7, 7);
147 case WebCursorInfo::TypeCell: 179 case WebCursorInfo::TypeCell:
148 return LoadCursor("cellCursor", 7, 7); 180 return LoadCursor("cellCursor", 7, 7);
149 case WebCursorInfo::TypeContextMenu: 181 case WebCursorInfo::TypeContextMenu:
150 return LoadCursor("contextMenuCursor", 3, 2); 182 // contextualMenuCursor is >= 10.6.
183 if ([NSCursor respondsToSelector:@selector(contextualMenuCursor)])
184 return [NSCursor contextualMenuCursor];
185 else
186 return LoadCursor("contextMenuCursor", 3, 2);
151 case WebCursorInfo::TypeAlias: 187 case WebCursorInfo::TypeAlias:
152 return LoadCursor("aliasCursor", 11, 3); 188 return LoadCursor("aliasCursor", 11, 3);
153 case WebCursorInfo::TypeProgress: 189 case WebCursorInfo::TypeProgress:
154 return LoadCursor("progressCursor", 3, 2); 190 return LoadCursor("progressCursor", 3, 2);
155 case WebCursorInfo::TypeNoDrop: 191 case WebCursorInfo::TypeNoDrop:
156 return LoadCursor("noDropCursor", 3, 1); 192 return LoadCursor("noDropCursor", 3, 1);
157 case WebCursorInfo::TypeCopy: 193 case WebCursorInfo::TypeCopy:
158 return LoadCursor("copyCursor", 3, 2); 194 // dragCopyCursor is >= 10.6.
195 if ([NSCursor respondsToSelector:@selector(dragCopyCursor)])
196 return [NSCursor dragCopyCursor];
197 else
198 return LoadCursor("copyCursor", 3, 2);
159 case WebCursorInfo::TypeNone: 199 case WebCursorInfo::TypeNone:
160 return LoadCursor("noneCursor", 7, 7); 200 return LoadCursor("noneCursor", 7, 7);
161 case WebCursorInfo::TypeNotAllowed: 201 case WebCursorInfo::TypeNotAllowed:
162 return LoadCursor("notAllowedCursor", 11, 11); 202 // Docs say that operationNotAllowedCursor is >= 10.6, and it's not in the
203 // 10.5 SDK, but later SDKs note that it really is available on 10.5.
Mark Mentovai 2011/08/15 16:00:08 Just be sure you test this.
Avi (use Gerrit) 2011/08/15 16:09:34 Tested.
204 return [NSCursor operationNotAllowedCursor];
163 case WebCursorInfo::TypeZoomIn: 205 case WebCursorInfo::TypeZoomIn:
164 return LoadCursor("zoomInCursor", 7, 7); 206 return LoadCursor("zoomInCursor", 7, 7);
165 case WebCursorInfo::TypeZoomOut: 207 case WebCursorInfo::TypeZoomOut:
166 return LoadCursor("zoomOutCursor", 7, 7); 208 return LoadCursor("zoomOutCursor", 7, 7);
167 case WebCursorInfo::TypeGrab: 209 case WebCursorInfo::TypeGrab:
168 return [NSCursor openHandCursor]; 210 return [NSCursor openHandCursor];
169 case WebCursorInfo::TypeGrabbing: 211 case WebCursorInfo::TypeGrabbing:
170 return [NSCursor closedHandCursor]; 212 return [NSCursor closedHandCursor];
171 case WebCursorInfo::TypeCustom: 213 case WebCursorInfo::TypeCustom:
172 return CreateCustomCursor(custom_data_, custom_size_, hotspot_); 214 return CreateCustomCursor(custom_data_, custom_size_, hotspot_);
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 } else if ([cursor isEqual:[NSCursor resizeUpCursor]]) { 359 } else if ([cursor isEqual:[NSCursor resizeUpCursor]]) {
318 cursor_info.type = WebCursorInfo::TypeNorthResize; 360 cursor_info.type = WebCursorInfo::TypeNorthResize;
319 } else if ([cursor isEqual:[NSCursor resizeDownCursor]]) { 361 } else if ([cursor isEqual:[NSCursor resizeDownCursor]]) {
320 cursor_info.type = WebCursorInfo::TypeSouthResize; 362 cursor_info.type = WebCursorInfo::TypeSouthResize;
321 } else if ([cursor isEqual:[NSCursor resizeUpDownCursor]]) { 363 } else if ([cursor isEqual:[NSCursor resizeUpDownCursor]]) {
322 cursor_info.type = WebCursorInfo::TypeNorthSouthResize; 364 cursor_info.type = WebCursorInfo::TypeNorthSouthResize;
323 } else if ([cursor isEqual:[NSCursor openHandCursor]]) { 365 } else if ([cursor isEqual:[NSCursor openHandCursor]]) {
324 cursor_info.type = WebCursorInfo::TypeGrab; 366 cursor_info.type = WebCursorInfo::TypeGrab;
325 } else if ([cursor isEqual:[NSCursor closedHandCursor]]) { 367 } else if ([cursor isEqual:[NSCursor closedHandCursor]]) {
326 cursor_info.type = WebCursorInfo::TypeGrabbing; 368 cursor_info.type = WebCursorInfo::TypeGrabbing;
369 } else if ([cursor isEqual:[NSCursor operationNotAllowedCursor]]) {
370 cursor_info.type = WebCursorInfo::TypeNotAllowed;
371 } else if ([NSCursor respondsToSelector:@selector(dragCopyCursor)] &&
372 [cursor isEqual:[NSCursor dragCopyCursor]]) {
373 cursor_info.type = WebCursorInfo::TypeCopy;
374 } else if ([NSCursor respondsToSelector:@selector(contextualMenuCursor)] &&
375 [cursor isEqual:[NSCursor contextualMenuCursor]]) {
376 cursor_info.type = WebCursorInfo::TypeContextMenu;
377 } else if (
378 [NSCursor respondsToSelector:@selector(IBeamCursorForVerticalLayout)] &&
379 [cursor isEqual:[NSCursor IBeamCursorForVerticalLayout]]) {
380 cursor_info.type = WebCursorInfo::TypeVerticalText;
327 } else { 381 } else {
328 // Also handles the [NSCursor disappearingItemCursor] case. Quick-and-dirty 382 // Also handles the [NSCursor disappearingItemCursor] case. Quick-and-dirty
329 // image conversion; TODO(avi): do better. 383 // image conversion; TODO(avi): do better.
330 CGImageRef cg_image = nil; 384 CGImageRef cg_image = nil;
331 NSImage* image = [cursor image]; 385 NSImage* image = [cursor image];
332 for (id rep in [image representations]) { 386 for (id rep in [image representations]) {
333 if ([rep isKindOfClass:[NSBitmapImageRep class]]) { 387 if ([rep isKindOfClass:[NSBitmapImageRep class]]) {
334 cg_image = [rep CGImage]; 388 cg_image = [rep CGImage];
335 break; 389 break;
336 } 390 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 return true; 466 return true;
413 } 467 }
414 468
415 void WebCursor::CleanupPlatformData() { 469 void WebCursor::CleanupPlatformData() {
416 return; 470 return;
417 } 471 }
418 472
419 void WebCursor::CopyPlatformData(const WebCursor& other) { 473 void WebCursor::CopyPlatformData(const WebCursor& other) {
420 return; 474 return;
421 } 475 }
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