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

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

Issue 10817031: mac: Move cursor images from the bundle into the resource pak file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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 | webkit/glue/webkit_resources.grd » ('j') | webkit/glue/webkit_resources.grd » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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/mac_util.h"
12 #include "base/mac/scoped_cftyperef.h" 12 #include "base/mac/scoped_cftyperef.h"
13 #include "base/memory/scoped_nsobject.h" 13 #include "base/memory/scoped_nsobject.h"
14 #include "grit/webkit_resources.h"
14 #include "skia/ext/skia_utils_mac.h" 15 #include "skia/ext/skia_utils_mac.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebImage.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebImage.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" 18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
18 #include "ui/gfx/mac/nsimage_cache.h" 19 #include "ui/base/resource/resource_bundle.h"
19 20
20 using WebKit::WebCursorInfo; 21 using WebKit::WebCursorInfo;
21 using WebKit::WebImage; 22 using WebKit::WebImage;
22 using WebKit::WebSize; 23 using WebKit::WebSize;
23 24
24 // Declare symbols that are part of the 10.7 SDK. 25 // Declare symbols that are part of the 10.7 SDK.
25 #if !defined(MAC_OS_X_VERSION_10_7) || \ 26 #if !defined(MAC_OS_X_VERSION_10_7) || \
26 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 27 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7
27 28
28 @interface NSCursor (LionSDKDeclarations) 29 @interface NSCursor (LionSDKDeclarations)
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 } 108 }
108 109
109 - (CrCoreCursorType)_coreCursorType { 110 - (CrCoreCursorType)_coreCursorType {
110 return type_; 111 return type_;
111 } 112 }
112 113
113 @end 114 @end
114 115
115 namespace { 116 namespace {
116 117
117 // Loads a cursor from the image cache. 118 NSCursor* LoadCursor(int resource_id, int hotspot_x, int hotspot_y) {
118 NSCursor* LoadCursor(const char* name, int hotspot_x, int hotspot_y) { 119 NSImage* cursor_image =
119 NSString* file_name = [NSString stringWithUTF8String:name]; 120 ResourceBundle::GetSharedInstance().GetNativeImageNamed(resource_id);
120 DCHECK(file_name);
121 // TODO: This image fetch can (and probably should) be serviced by the
122 // resource resource bundle instead of going through the image cache.
123 NSImage* cursor_image = gfx::GetCachedImageWithName(file_name);
124 DCHECK(cursor_image); 121 DCHECK(cursor_image);
125 return [[[NSCursor alloc] initWithImage:cursor_image 122 return [[[NSCursor alloc] initWithImage:cursor_image
126 hotSpot:NSMakePoint(hotspot_x, 123 hotSpot:NSMakePoint(hotspot_x,
127 hotspot_y)] autorelease]; 124 hotspot_y)] autorelease];
128 } 125 }
129 126
130 // Gets a specified cursor from CoreCursor, falling back to loading it from the 127 // Gets a specified cursor from CoreCursor, falling back to loading it from the
131 // image cache if CoreCursor cannot provide it. 128 // image cache if CoreCursor cannot provide it.
132 NSCursor* GetCoreCursorWithFallback(CrCoreCursorType type, 129 NSCursor* GetCoreCursorWithFallback(CrCoreCursorType type,
133 const char* name, 130 int resource_id,
134 int hotspot_x, 131 int hotspot_x,
135 int hotspot_y) { 132 int hotspot_y) {
136 if (base::mac::IsOSLionOrLater()) { 133 if (base::mac::IsOSLionOrLater()) {
137 NSCursor* cursor = [CrCoreCursor cursorWithType:type]; 134 NSCursor* cursor = [CrCoreCursor cursorWithType:type];
138 if (cursor) 135 if (cursor)
139 return cursor; 136 return cursor;
140 } 137 }
141 138
142 return LoadCursor(name, hotspot_x, hotspot_y); 139 return LoadCursor(resource_id, hotspot_x, hotspot_y);
143 } 140 }
144 141
145 // TODO(avi): When Skia becomes default, fold this function into the remaining 142 // TODO(avi): When Skia becomes default, fold this function into the remaining
146 // caller, InitFromCursor(). 143 // caller, InitFromCursor().
147 CGImageRef CreateCGImageFromCustomData(const std::vector<char>& custom_data, 144 CGImageRef CreateCGImageFromCustomData(const std::vector<char>& custom_data,
148 const gfx::Size& custom_size) { 145 const gfx::Size& custom_size) {
149 // If the data is missing, leave the backing transparent. 146 // If the data is missing, leave the backing transparent.
150 void* data = NULL; 147 void* data = NULL;
151 if (!custom_data.empty()) { 148 if (!custom_data.empty()) {
152 // This is safe since we're not going to draw into the context we're 149 // This is safe since we're not going to draw into the context we're
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 case WebCursorInfo::TypePointer: 217 case WebCursorInfo::TypePointer:
221 return [NSCursor arrowCursor]; 218 return [NSCursor arrowCursor];
222 case WebCursorInfo::TypeCross: 219 case WebCursorInfo::TypeCross:
223 return [NSCursor crosshairCursor]; 220 return [NSCursor crosshairCursor];
224 case WebCursorInfo::TypeHand: 221 case WebCursorInfo::TypeHand:
225 // If >= 10.7, the pointingHandCursor has a shadow so use it. Otherwise 222 // If >= 10.7, the pointingHandCursor has a shadow so use it. Otherwise
226 // use the custom one. 223 // use the custom one.
227 if (base::mac::IsOSLionOrLater()) 224 if (base::mac::IsOSLionOrLater())
228 return [NSCursor pointingHandCursor]; 225 return [NSCursor pointingHandCursor];
229 else 226 else
230 return LoadCursor("linkCursor", 6, 1); 227 return LoadCursor(IDR_LINK_CURSOR, 6, 1);
231 case WebCursorInfo::TypeIBeam: 228 case WebCursorInfo::TypeIBeam:
232 return [NSCursor IBeamCursor]; 229 return [NSCursor IBeamCursor];
233 case WebCursorInfo::TypeWait: 230 case WebCursorInfo::TypeWait:
234 return GetCoreCursorWithFallback(kBusyButClickableCursor, 231 return GetCoreCursorWithFallback(kBusyButClickableCursor,
235 "waitCursor", 7, 7); 232 IDR_WAIT_CURSOR, 7, 7);
236 case WebCursorInfo::TypeHelp: 233 case WebCursorInfo::TypeHelp:
237 return GetCoreCursorWithFallback(kHelpCursor, 234 return GetCoreCursorWithFallback(kHelpCursor,
238 "helpCursor", 8, 8); 235 IDR_HELP_CURSOR, 8, 8);
239 case WebCursorInfo::TypeEastResize: 236 case WebCursorInfo::TypeEastResize:
240 case WebCursorInfo::TypeEastPanning: 237 case WebCursorInfo::TypeEastPanning:
241 return GetCoreCursorWithFallback(kResizeEastCursor, 238 return GetCoreCursorWithFallback(kResizeEastCursor,
242 "eastResizeCursor", 14, 7); 239 IDR_EAST_RESIZE_CURSOR, 14, 7);
243 case WebCursorInfo::TypeNorthResize: 240 case WebCursorInfo::TypeNorthResize:
244 case WebCursorInfo::TypeNorthPanning: 241 case WebCursorInfo::TypeNorthPanning:
245 return GetCoreCursorWithFallback(kResizeNorthCursor, 242 return GetCoreCursorWithFallback(kResizeNorthCursor,
246 "northResizeCursor", 7, 1); 243 IDR_NORTH_RESIZE_CURSOR, 7, 1);
247 case WebCursorInfo::TypeNorthEastResize: 244 case WebCursorInfo::TypeNorthEastResize:
248 case WebCursorInfo::TypeNorthEastPanning: 245 case WebCursorInfo::TypeNorthEastPanning:
249 return GetCoreCursorWithFallback(kResizeNortheastCursor, 246 return GetCoreCursorWithFallback(kResizeNortheastCursor,
250 "northEastResizeCursor", 14, 1); 247 IDR_NORTHEAST_RESIZE_CURSOR, 14, 1);
251 case WebCursorInfo::TypeNorthWestResize: 248 case WebCursorInfo::TypeNorthWestResize:
252 case WebCursorInfo::TypeNorthWestPanning: 249 case WebCursorInfo::TypeNorthWestPanning:
253 return GetCoreCursorWithFallback(kResizeNorthwestCursor, 250 return GetCoreCursorWithFallback(kResizeNorthwestCursor,
254 "northWestResizeCursor", 0, 0); 251 IDR_NORTHWEST_RESIZE_CURSOR, 0, 0);
255 case WebCursorInfo::TypeSouthResize: 252 case WebCursorInfo::TypeSouthResize:
256 case WebCursorInfo::TypeSouthPanning: 253 case WebCursorInfo::TypeSouthPanning:
257 return GetCoreCursorWithFallback(kResizeSouthCursor, 254 return GetCoreCursorWithFallback(kResizeSouthCursor,
258 "southResizeCursor", 7, 14); 255 IDR_SOUTH_RESIZE_CURSOR, 7, 14);
259 case WebCursorInfo::TypeSouthEastResize: 256 case WebCursorInfo::TypeSouthEastResize:
260 case WebCursorInfo::TypeSouthEastPanning: 257 case WebCursorInfo::TypeSouthEastPanning:
261 return GetCoreCursorWithFallback(kResizeSoutheastCursor, 258 return GetCoreCursorWithFallback(kResizeSoutheastCursor,
262 "southEastResizeCursor", 14, 14); 259 IDR_SOUTHEAST_RESIZE_CURSOR, 14, 14);
263 case WebCursorInfo::TypeSouthWestResize: 260 case WebCursorInfo::TypeSouthWestResize:
264 case WebCursorInfo::TypeSouthWestPanning: 261 case WebCursorInfo::TypeSouthWestPanning:
265 return GetCoreCursorWithFallback(kResizeSouthwestCursor, 262 return GetCoreCursorWithFallback(kResizeSouthwestCursor,
266 "southWestResizeCursor", 1, 14); 263 IDR_SOUTHWEST_RESIZE_CURSOR, 1, 14);
267 case WebCursorInfo::TypeWestResize: 264 case WebCursorInfo::TypeWestResize:
268 case WebCursorInfo::TypeWestPanning: 265 case WebCursorInfo::TypeWestPanning:
269 return GetCoreCursorWithFallback(kResizeWestCursor, 266 return GetCoreCursorWithFallback(kResizeWestCursor,
270 "westResizeCursor", 1, 7); 267 IDR_WEST_RESIZE_CURSOR, 1, 7);
271 case WebCursorInfo::TypeNorthSouthResize: 268 case WebCursorInfo::TypeNorthSouthResize:
272 return GetCoreCursorWithFallback(kResizeNorthSouthCursor, 269 return GetCoreCursorWithFallback(kResizeNorthSouthCursor,
273 "northSouthResizeCursor", 7, 7); 270 IDR_NORTHSOUTH_RESIZE_CURSOR, 7, 7);
274 case WebCursorInfo::TypeEastWestResize: 271 case WebCursorInfo::TypeEastWestResize:
275 return GetCoreCursorWithFallback(kResizeEastWestCursor, 272 return GetCoreCursorWithFallback(kResizeEastWestCursor,
276 "eastWestResizeCursor", 7, 7); 273 IDR_EASTWEST_RESIZE_CURSOR, 7, 7);
277 case WebCursorInfo::TypeNorthEastSouthWestResize: 274 case WebCursorInfo::TypeNorthEastSouthWestResize:
278 return GetCoreCursorWithFallback(kResizeNortheastSouthwestCursor, 275 return GetCoreCursorWithFallback(kResizeNortheastSouthwestCursor,
279 "northEastSouthWestResizeCursor", 7, 7); 276 IDR_NORTHEASTSOUTHWEST_RESIZE_CURSOR,
277 7, 7);
280 case WebCursorInfo::TypeNorthWestSouthEastResize: 278 case WebCursorInfo::TypeNorthWestSouthEastResize:
281 return GetCoreCursorWithFallback(kResizeNorthwestSoutheastCursor, 279 return GetCoreCursorWithFallback(kResizeNorthwestSoutheastCursor,
282 "northWestSouthEastResizeCursor", 7, 7); 280 IDR_NORTHWESTSOUTHEAST_RESIZE_CURSOR,
281 7, 7);
283 case WebCursorInfo::TypeColumnResize: 282 case WebCursorInfo::TypeColumnResize:
284 return [NSCursor resizeLeftRightCursor]; 283 return [NSCursor resizeLeftRightCursor];
285 case WebCursorInfo::TypeRowResize: 284 case WebCursorInfo::TypeRowResize:
286 return [NSCursor resizeUpDownCursor]; 285 return [NSCursor resizeUpDownCursor];
287 case WebCursorInfo::TypeMiddlePanning: 286 case WebCursorInfo::TypeMiddlePanning:
288 case WebCursorInfo::TypeMove: 287 case WebCursorInfo::TypeMove:
289 return GetCoreCursorWithFallback(kMoveCursor, 288 return GetCoreCursorWithFallback(kMoveCursor,
290 "moveCursor", 7, 7); 289 IDR_MOVE_CURSOR, 7, 7);
291 case WebCursorInfo::TypeVerticalText: 290 case WebCursorInfo::TypeVerticalText:
292 // IBeamCursorForVerticalLayout is >= 10.7. 291 // IBeamCursorForVerticalLayout is >= 10.7.
293 if ([NSCursor respondsToSelector:@selector(IBeamCursorForVerticalLayout)]) 292 if ([NSCursor respondsToSelector:@selector(IBeamCursorForVerticalLayout)])
294 return [NSCursor IBeamCursorForVerticalLayout]; 293 return [NSCursor IBeamCursorForVerticalLayout];
295 else 294 else
296 return LoadCursor("verticalTextCursor", 7, 7); 295 return LoadCursor(IDR_VERTICALTEXT_CURSOR, 7, 7);
297 case WebCursorInfo::TypeCell: 296 case WebCursorInfo::TypeCell:
298 return GetCoreCursorWithFallback(kCellCursor, 297 return GetCoreCursorWithFallback(kCellCursor,
299 "cellCursor", 7, 7); 298 IDR_CELL_CURSOR, 7, 7);
300 case WebCursorInfo::TypeContextMenu: 299 case WebCursorInfo::TypeContextMenu:
301 // contextualMenuCursor is >= 10.6. 300 // contextualMenuCursor is >= 10.6.
302 if ([NSCursor respondsToSelector:@selector(contextualMenuCursor)]) 301 if ([NSCursor respondsToSelector:@selector(contextualMenuCursor)])
303 return [NSCursor contextualMenuCursor]; 302 return [NSCursor contextualMenuCursor];
304 else 303 else
305 return LoadCursor("contextMenuCursor", 3, 2); 304 return LoadCursor(IDR_CONTEXTMENU_CURSOR, 3, 2);
306 case WebCursorInfo::TypeAlias: 305 case WebCursorInfo::TypeAlias:
307 return GetCoreCursorWithFallback(kMakeAliasCursor, 306 return GetCoreCursorWithFallback(kMakeAliasCursor,
308 "aliasCursor", 11, 3); 307 IDR_ALIAS_CURSOR, 11, 3);
309 case WebCursorInfo::TypeProgress: 308 case WebCursorInfo::TypeProgress:
310 return GetCoreCursorWithFallback(kBusyButClickableCursor, 309 return GetCoreCursorWithFallback(kBusyButClickableCursor,
311 "progressCursor", 3, 2); 310 IDR_PROGRESS_CURSOR, 3, 2);
312 case WebCursorInfo::TypeNoDrop: 311 case WebCursorInfo::TypeNoDrop:
313 case WebCursorInfo::TypeNotAllowed: 312 case WebCursorInfo::TypeNotAllowed:
314 // Docs say that operationNotAllowedCursor is >= 10.6, and it's not in the 313 // Docs say that operationNotAllowedCursor is >= 10.6, and it's not in the
315 // 10.5 SDK, but later SDKs note that it really is available on 10.5. 314 // 10.5 SDK, but later SDKs note that it really is available on 10.5.
316 return [NSCursor operationNotAllowedCursor]; 315 return [NSCursor operationNotAllowedCursor];
317 case WebCursorInfo::TypeCopy: 316 case WebCursorInfo::TypeCopy:
318 // dragCopyCursor is >= 10.6. 317 // dragCopyCursor is >= 10.6.
319 if ([NSCursor respondsToSelector:@selector(dragCopyCursor)]) 318 if ([NSCursor respondsToSelector:@selector(dragCopyCursor)])
320 return [NSCursor dragCopyCursor]; 319 return [NSCursor dragCopyCursor];
321 else 320 else
322 return LoadCursor("copyCursor", 3, 2); 321 return LoadCursor(IDR_COPY_CURSOR, 3, 2);
323 case WebCursorInfo::TypeNone: 322 case WebCursorInfo::TypeNone:
324 return LoadCursor("noneCursor", 7, 7); 323 return LoadCursor(IDR_NONE_CURSOR, 7, 7);
325 case WebCursorInfo::TypeZoomIn: 324 case WebCursorInfo::TypeZoomIn:
326 return GetCoreCursorWithFallback(kZoomInCursor, 325 return GetCoreCursorWithFallback(kZoomInCursor,
327 "zoomInCursor", 7, 7); 326 IDR_ZOOMIN_CURSOR, 7, 7);
328 case WebCursorInfo::TypeZoomOut: 327 case WebCursorInfo::TypeZoomOut:
329 return GetCoreCursorWithFallback(kZoomOutCursor, 328 return GetCoreCursorWithFallback(kZoomOutCursor,
330 "zoomOutCursor", 7, 7); 329 IDR_ZOOMOUT_CURSOR, 7, 7);
331 case WebCursorInfo::TypeGrab: 330 case WebCursorInfo::TypeGrab:
332 return [NSCursor openHandCursor]; 331 return [NSCursor openHandCursor];
333 case WebCursorInfo::TypeGrabbing: 332 case WebCursorInfo::TypeGrabbing:
334 return [NSCursor closedHandCursor]; 333 return [NSCursor closedHandCursor];
335 case WebCursorInfo::TypeCustom: 334 case WebCursorInfo::TypeCustom:
336 return CreateCustomCursor(custom_data_, custom_size_, hotspot_); 335 return CreateCustomCursor(custom_data_, custom_size_, hotspot_);
337 } 336 }
338 NOTREACHED(); 337 NOTREACHED();
339 return nil; 338 return nil;
340 } 339 }
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 return true; 534 return true;
536 } 535 }
537 536
538 void WebCursor::CleanupPlatformData() { 537 void WebCursor::CleanupPlatformData() {
539 return; 538 return;
540 } 539 }
541 540
542 void WebCursor::CopyPlatformData(const WebCursor& other) { 541 void WebCursor::CopyPlatformData(const WebCursor& other) {
543 return; 542 return;
544 } 543 }
OLDNEW
« no previous file with comments | « no previous file | webkit/glue/webkit_resources.grd » ('j') | webkit/glue/webkit_resources.grd » ('J')

Powered by Google App Engine
This is Rietveld 408576698