summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authoravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-16 23:22:06 +0000
committeravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-16 23:22:06 +0000
commit5dd07869cdea6e7853f6f8dc513925670e66b364 (patch)
tree32cbc5773c13315127e23b2ac70b3fe3d076ae5a /webkit
parentae95538ad7b9812efb722eae25c72bb80ef67ac6 (diff)
downloadchromium_src-5dd07869cdea6e7853f6f8dc513925670e66b364.zip
chromium_src-5dd07869cdea6e7853f6f8dc513925670e66b364.tar.gz
chromium_src-5dd07869cdea6e7853f6f8dc513925670e66b364.tar.bz2
Fix Mac custom cursor color.
BUG=114598 TEST=as in bug Review URL: http://codereview.chromium.org/9419010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@122386 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/glue/webcursor.h5
-rw-r--r--webkit/glue/webcursor_mac.mm53
-rw-r--r--webkit/tools/test_shell/mac/test_webview_delegate.mm2
3 files changed, 43 insertions, 17 deletions
diff --git a/webkit/glue/webcursor.h b/webkit/glue/webcursor.h
index 78c6387..0461a3c 100644
--- a/webkit/glue/webcursor.h
+++ b/webkit/glue/webcursor.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -92,9 +92,6 @@ class WEBKIT_GLUE_EXPORT WebCursor {
// returns GDK_CURSOR_IS_PIXMAP.
GdkCursor* GetCustomCursor();
#elif defined(OS_MACOSX)
- // Gets an NSCursor* for this cursor.
- NSCursor* GetCursor() const;
-
// Initialize this from the given Carbon ThemeCursor.
void InitFromThemeCursor(ThemeCursor cursor);
diff --git a/webkit/glue/webcursor_mac.mm b/webkit/glue/webcursor_mac.mm
index 5ba6c00..fe65480 100644
--- a/webkit/glue/webcursor_mac.mm
+++ b/webkit/glue/webcursor_mac.mm
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -59,14 +59,17 @@ NSCursor* LoadCursor(const char* name, int x, int y) {
hotSpot:NSMakePoint(x, y)] autorelease];
}
+// TODO(avi): When Skia becomes default, fold this function into the remaining
+// caller, InitFromCursor().
CGImageRef CreateCGImageFromCustomData(const std::vector<char>& custom_data,
const gfx::Size& custom_size) {
- // This is safe since we're not going to draw into the context we're creating.
- // The settings here match SetCustomData() below; keep in sync.
// If the data is missing, leave the backing transparent.
void* data = NULL;
- if (!custom_data.empty())
+ if (!custom_data.empty()) {
+ // This is safe since we're not going to draw into the context we're
+ // creating.
data = const_cast<char*>(&custom_data[0]);
+ }
// If the size is empty, use a 1x1 transparent image.
gfx::Size size = custom_size;
@@ -77,6 +80,7 @@ CGImageRef CreateCGImageFromCustomData(const std::vector<char>& custom_data,
base::mac::ScopedCFTypeRef<CGColorSpaceRef> cg_color(
CGColorSpaceCreateDeviceRGB());
+ // The settings here match SetCustomData() below; keep in sync.
base::mac::ScopedCFTypeRef<CGContextRef> context(
CGBitmapContextCreate(data,
size.width(),
@@ -92,19 +96,46 @@ CGImageRef CreateCGImageFromCustomData(const std::vector<char>& custom_data,
NSCursor* CreateCustomCursor(const std::vector<char>& custom_data,
const gfx::Size& custom_size,
const gfx::Point& hotspot) {
+#if WEBKIT_USING_SKIA
+ // If the data is missing, leave the backing transparent.
+ void* data = NULL;
+ size_t data_size = 0;
+ if (!custom_data.empty()) {
+ // This is safe since we're not going to draw into the context we're
+ // creating.
+ data = const_cast<char*>(&custom_data[0]);
+ data_size = custom_data.size();
+ }
+
+ // If the size is empty, use a 1x1 transparent image.
+ gfx::Size size = custom_size;
+ if (size.IsEmpty()) {
+ size.SetSize(1, 1);
+ data = NULL;
+ }
+
+ SkBitmap bitmap;
+ bitmap.setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height());
+ bitmap.allocPixels();
+ if (data)
+ memcpy(bitmap.getAddr32(0, 0), data, data_size);
+ else
+ bitmap.eraseARGB(0, 0, 0, 0);
+ NSImage* cursor_image = gfx::SkBitmapToNSImage(bitmap);
+#else
base::mac::ScopedCFTypeRef<CGImageRef> cg_image(
CreateCGImageFromCustomData(custom_data, custom_size));
scoped_nsobject<NSBitmapImageRep> ns_bitmap(
[[NSBitmapImageRep alloc] initWithCGImage:cg_image.get()]);
- NSImage* cursor_image = [[NSImage alloc] init];
+ scoped_nsobject<NSImage> cursor_image([[NSImage alloc] init]);
DCHECK(cursor_image);
[cursor_image addRepresentation:ns_bitmap];
+#endif // WEBKIT_USING_SKIA
NSCursor* cursor = [[NSCursor alloc] initWithImage:cursor_image
hotSpot:NSMakePoint(hotspot.x(),
hotspot.y())];
- [cursor_image release];
return [cursor autorelease];
}
@@ -118,7 +149,7 @@ NSCursor* CreateCustomCursor(const std::vector<char>& custom_data,
// clear that accessing system cursors this way is enough of a gain to risk
// using SPIs. Until the benefits more clearly outweigh the risks, API is all
// that will be used.
-NSCursor* WebCursor::GetCursor() const {
+gfx::NativeCursor WebCursor::GetNativeCursor() {
switch (type_) {
case WebCursorInfo::TypePointer:
return [NSCursor arrowCursor];
@@ -223,10 +254,6 @@ NSCursor* WebCursor::GetCursor() const {
return nil;
}
-gfx::NativeCursor WebCursor::GetNativeCursor() {
- return GetCursor();
-}
-
void WebCursor::InitFromThemeCursor(ThemeCursor cursor) {
WebKit::WebCursorInfo cursor_info;
@@ -337,6 +364,8 @@ void WebCursor::InitFromCursor(const Cursor* cursor) {
cursor_info.type = WebCursorInfo::TypeCustom;
cursor_info.hotSpot = WebKit::WebPoint(cursor->hotSpot.h, cursor->hotSpot.v);
#if WEBKIT_USING_SKIA
+ // TODO(avi): build the cursor image in Skia directly rather than going via
+ // this roundabout path.
cursor_info.customImage = gfx::CGImageToSkBitmap(cg_image.get());
#else
cursor_info.customImage = cg_image.get();
@@ -454,7 +483,7 @@ void WebCursor::ImageFromCustomData(WebImage* image) const {
CreateCGImageFromCustomData(custom_data_, custom_size_));
*image = cg_image.get();
}
-#endif
+#endif // !WEBKIT_USING_SKIA
void WebCursor::InitPlatformData() {
return;
diff --git a/webkit/tools/test_shell/mac/test_webview_delegate.mm b/webkit/tools/test_shell/mac/test_webview_delegate.mm
index dce18b5..e0d3f38 100644
--- a/webkit/tools/test_shell/mac/test_webview_delegate.mm
+++ b/webkit/tools/test_shell/mac/test_webview_delegate.mm
@@ -103,7 +103,7 @@ void TestWebViewDelegate::closeWidgetSoon() {
}
void TestWebViewDelegate::didChangeCursor(const WebCursorInfo& cursor_info) {
- NSCursor* ns_cursor = WebCursor(cursor_info).GetCursor();
+ NSCursor* ns_cursor = WebCursor(cursor_info).GetNativeCursor();
[ns_cursor set];
}