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 "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> | |
9 | 8 |
10 #include "base/logging.h" | 9 #include "base/logging.h" |
11 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
12 #include "base/mac/scoped_cftyperef.h" | 11 #include "base/mac/scoped_cftyperef.h" |
13 #include "base/memory/scoped_nsobject.h" | 12 #include "base/memory/scoped_nsobject.h" |
14 #include "grit/webkit_chromium_resources.h" | 13 #include "grit/webkit_chromium_resources.h" |
15 #include "skia/ext/skia_utils_mac.h" | 14 #include "skia/ext/skia_utils_mac.h" |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebImage.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebImage.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" |
19 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
20 | 19 |
21 | 20 |
22 #if defined(MAC_OS_X_VERSION_10_7) && \ | |
23 MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 | |
24 // The 10.7 SDK no longer has QuickDraw headers. | |
25 // http://developer.apple.com/legacy/mac/library/documentation/Carbon/reference/
QuickDraw_Ref/QuickDraw_Ref.pdf | |
26 typedef short Bits16[16]; | |
27 struct Cursor { | |
28 Bits16 data; | |
29 Bits16 mask; | |
30 Point hotSpot; | |
31 }; | |
32 #endif // 10.7+ SDK | |
33 | |
34 using WebKit::WebCursorInfo; | 21 using WebKit::WebCursorInfo; |
35 using WebKit::WebImage; | 22 using WebKit::WebImage; |
36 using WebKit::WebSize; | 23 using WebKit::WebSize; |
37 | 24 |
38 // Declare symbols that are part of the 10.7 SDK. | 25 // Declare symbols that are part of the 10.7 SDK. |
39 #if !defined(MAC_OS_X_VERSION_10_7) || \ | 26 #if !defined(MAC_OS_X_VERSION_10_7) || \ |
40 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 |
41 | 28 |
42 @interface NSCursor (LionSDKDeclarations) | 29 @interface NSCursor (LionSDKDeclarations) |
43 + (NSCursor*)IBeamCursorForVerticalLayout; | 30 + (NSCursor*)IBeamCursorForVerticalLayout; |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 return [NSCursor openHandCursor]; | 331 return [NSCursor openHandCursor]; |
345 case WebCursorInfo::TypeGrabbing: | 332 case WebCursorInfo::TypeGrabbing: |
346 return [NSCursor closedHandCursor]; | 333 return [NSCursor closedHandCursor]; |
347 case WebCursorInfo::TypeCustom: | 334 case WebCursorInfo::TypeCustom: |
348 return CreateCustomCursor(custom_data_, custom_size_, hotspot_); | 335 return CreateCustomCursor(custom_data_, custom_size_, hotspot_); |
349 } | 336 } |
350 NOTREACHED(); | 337 NOTREACHED(); |
351 return nil; | 338 return nil; |
352 } | 339 } |
353 | 340 |
354 void WebCursor::InitFromThemeCursor(ThemeCursor cursor) { | |
355 WebKit::WebCursorInfo cursor_info; | |
356 | |
357 switch (cursor) { | |
358 case kThemeArrowCursor: | |
359 cursor_info.type = WebCursorInfo::TypePointer; | |
360 break; | |
361 case kThemeCopyArrowCursor: | |
362 cursor_info.type = WebCursorInfo::TypeCopy; | |
363 break; | |
364 case kThemeAliasArrowCursor: | |
365 cursor_info.type = WebCursorInfo::TypeAlias; | |
366 break; | |
367 case kThemeContextualMenuArrowCursor: | |
368 cursor_info.type = WebCursorInfo::TypeContextMenu; | |
369 break; | |
370 case kThemeIBeamCursor: | |
371 cursor_info.type = WebCursorInfo::TypeIBeam; | |
372 break; | |
373 case kThemeCrossCursor: | |
374 case kThemePlusCursor: | |
375 cursor_info.type = WebCursorInfo::TypeCross; | |
376 break; | |
377 case kThemeWatchCursor: | |
378 case kThemeSpinningCursor: | |
379 cursor_info.type = WebCursorInfo::TypeWait; | |
380 break; | |
381 case kThemeClosedHandCursor: | |
382 cursor_info.type = WebCursorInfo::TypeGrabbing; | |
383 break; | |
384 case kThemeOpenHandCursor: | |
385 cursor_info.type = WebCursorInfo::TypeGrab; | |
386 break; | |
387 case kThemePointingHandCursor: | |
388 case kThemeCountingUpHandCursor: | |
389 case kThemeCountingDownHandCursor: | |
390 case kThemeCountingUpAndDownHandCursor: | |
391 cursor_info.type = WebCursorInfo::TypeHand; | |
392 break; | |
393 case kThemeResizeLeftCursor: | |
394 cursor_info.type = WebCursorInfo::TypeWestResize; | |
395 break; | |
396 case kThemeResizeRightCursor: | |
397 cursor_info.type = WebCursorInfo::TypeEastResize; | |
398 break; | |
399 case kThemeResizeLeftRightCursor: | |
400 cursor_info.type = WebCursorInfo::TypeEastWestResize; | |
401 break; | |
402 case kThemeNotAllowedCursor: | |
403 cursor_info.type = WebCursorInfo::TypeNotAllowed; | |
404 break; | |
405 case kThemeResizeUpCursor: | |
406 cursor_info.type = WebCursorInfo::TypeNorthResize; | |
407 break; | |
408 case kThemeResizeDownCursor: | |
409 cursor_info.type = WebCursorInfo::TypeSouthResize; | |
410 break; | |
411 case kThemeResizeUpDownCursor: | |
412 cursor_info.type = WebCursorInfo::TypeNorthSouthResize; | |
413 break; | |
414 case kThemePoofCursor: // *shrug* | |
415 default: | |
416 cursor_info.type = WebCursorInfo::TypePointer; | |
417 break; | |
418 } | |
419 | |
420 InitFromCursorInfo(cursor_info); | |
421 } | |
422 | |
423 void WebCursor::InitFromCursor(const Cursor* cursor) { | |
424 // This conversion isn't perfect (in particular, the inversion effect of | |
425 // data==1, mask==0 won't work). Not planning on fixing it. | |
426 | |
427 gfx::Size custom_size(16, 16); | |
428 std::vector<char> raw_data; | |
429 for (int row = 0; row < 16; ++row) { | |
430 unsigned short data = cursor->data[row]; | |
431 unsigned short mask = cursor->mask[row]; | |
432 | |
433 // The Core Endian flipper callback for 'CURS' doesn't flip Bits16 as if it | |
434 // were a short (which it is), so we flip it here. | |
435 data = ((data << 8) & 0xFF00) | ((data >> 8) & 0x00FF); | |
436 mask = ((mask << 8) & 0xFF00) | ((mask >> 8) & 0x00FF); | |
437 | |
438 for (int bit = 0; bit < 16; ++bit) { | |
439 if (data & 0x8000) { | |
440 raw_data.push_back(0x00); | |
441 raw_data.push_back(0x00); | |
442 raw_data.push_back(0x00); | |
443 } else { | |
444 raw_data.push_back(0xFF); | |
445 raw_data.push_back(0xFF); | |
446 raw_data.push_back(0xFF); | |
447 } | |
448 if (mask & 0x8000) | |
449 raw_data.push_back(0xFF); | |
450 else | |
451 raw_data.push_back(0x00); | |
452 data <<= 1; | |
453 mask <<= 1; | |
454 } | |
455 } | |
456 | |
457 base::mac::ScopedCFTypeRef<CGImageRef> cg_image( | |
458 CreateCGImageFromCustomData(raw_data, custom_size)); | |
459 | |
460 WebKit::WebCursorInfo cursor_info; | |
461 cursor_info.type = WebCursorInfo::TypeCustom; | |
462 cursor_info.hotSpot = WebKit::WebPoint(cursor->hotSpot.h, cursor->hotSpot.v); | |
463 // TODO(avi): build the cursor image in Skia directly rather than going via | |
464 // this roundabout path. | |
465 cursor_info.customImage = gfx::CGImageToSkBitmap(cg_image.get()); | |
466 | |
467 InitFromCursorInfo(cursor_info); | |
468 } | |
469 | |
470 void WebCursor::InitFromNSCursor(NSCursor* cursor) { | 341 void WebCursor::InitFromNSCursor(NSCursor* cursor) { |
471 WebKit::WebCursorInfo cursor_info; | 342 WebKit::WebCursorInfo cursor_info; |
472 | 343 |
473 if ([cursor isEqual:[NSCursor arrowCursor]]) { | 344 if ([cursor isEqual:[NSCursor arrowCursor]]) { |
474 cursor_info.type = WebCursorInfo::TypePointer; | 345 cursor_info.type = WebCursorInfo::TypePointer; |
475 } else if ([cursor isEqual:[NSCursor IBeamCursor]]) { | 346 } else if ([cursor isEqual:[NSCursor IBeamCursor]]) { |
476 cursor_info.type = WebCursorInfo::TypeIBeam; | 347 cursor_info.type = WebCursorInfo::TypeIBeam; |
477 } else if ([cursor isEqual:[NSCursor crosshairCursor]]) { | 348 } else if ([cursor isEqual:[NSCursor crosshairCursor]]) { |
478 cursor_info.type = WebCursorInfo::TypeCross; | 349 cursor_info.type = WebCursorInfo::TypeCross; |
479 } else if ([cursor isEqual:[NSCursor pointingHandCursor]]) { | 350 } else if ([cursor isEqual:[NSCursor pointingHandCursor]]) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 return true; | 418 return true; |
548 } | 419 } |
549 | 420 |
550 void WebCursor::CleanupPlatformData() { | 421 void WebCursor::CleanupPlatformData() { |
551 return; | 422 return; |
552 } | 423 } |
553 | 424 |
554 void WebCursor::CopyPlatformData(const WebCursor& other) { | 425 void WebCursor::CopyPlatformData(const WebCursor& other) { |
555 return; | 426 return; |
556 } | 427 } |
OLD | NEW |