diff options
author | shess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-03 18:06:52 +0000 |
---|---|---|
committer | shess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-03 18:06:52 +0000 |
commit | b1b8a9f6449027349606ca2393ffe884107faa8f (patch) | |
tree | 7f1b33945be65f70d3570918c94d121afe87e10e | |
parent | 9e0f7b623f298795a2b9c949926ca4183a37d999 (diff) | |
download | chromium_src-b1b8a9f6449027349606ca2393ffe884107faa8f.zip chromium_src-b1b8a9f6449027349606ca2393ffe884107faa8f.tar.gz chromium_src-b1b8a9f6449027349606ca2393ffe884107faa8f.tar.bz2 |
[Mac] Create transparent cursor when given empty custom data.
Based on webcursor_win.cc's implementation of GetCursor().
BUG=73356
TEST=Watch crash server.
Review URL: http://codereview.chromium.org/7273056
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91452 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/renderer_host/render_widget_host_view_mac.mm | 13 | ||||
-rw-r--r-- | webkit/glue/webcursor.h | 3 | ||||
-rw-r--r-- | webkit/glue/webcursor_mac.mm | 33 |
3 files changed, 20 insertions, 29 deletions
diff --git a/chrome/browser/renderer_host/render_widget_host_view_mac.mm b/chrome/browser/renderer_host/render_widget_host_view_mac.mm index 8b12cf0..6174c29 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_mac.mm +++ b/chrome/browser/renderer_host/render_widget_host_view_mac.mm @@ -15,7 +15,6 @@ #include "base/string_util.h" #include "base/sys_info.h" #include "base/sys_string_conversions.h" -#import "chrome/app/breakpad_mac.h" #include "chrome/browser/browser_trial.h" #import "chrome/browser/renderer_host/accelerated_plugin_view_mac.h" #import "chrome/browser/renderer_host/text_input_client_mac.h" @@ -43,7 +42,6 @@ #import "third_party/mozilla/ComplexTextInputPanel.h" #include "third_party/skia/include/core/SkColor.h" #include "third_party/WebKit/Source/WebKit/chromium/public/mac/WebInputEventFactory.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" #include "ui/gfx/point.h" #include "ui/gfx/surface/io_surface_support_mac.h" @@ -481,17 +479,6 @@ void RenderWidgetHostViewMac::UpdateCursorIfNecessary() { if ([event window] != [cocoa_view_ window]) return; - // TODO(shess): Store additional information in breakpad dumps for - // debugging http://crbug.com/73356 . - scoped_ptr<ScopedCrashKey> key; - if (current_cursor_.IsCustom()) { - NSString* kCrashKey = @"custom-cursor-size"; - const gfx::Size size = current_cursor_.custom_size(); - NSString* crashValue = - [NSString stringWithFormat:@"{%d, %d}", size.width(), size.height()]; - key.reset(new ScopedCrashKey(kCrashKey, crashValue)); - } - NSCursor* ns_cursor = current_cursor_.GetCursor(); [ns_cursor set]; } diff --git a/webkit/glue/webcursor.h b/webkit/glue/webcursor.h index 9b2b420..9c1a9e1 100644 --- a/webkit/glue/webcursor.h +++ b/webkit/glue/webcursor.h @@ -102,9 +102,6 @@ class WebCursor { // Initialize this from the given Cocoa NSCursor. void InitFromNSCursor(NSCursor* cursor); - - // TODO(shess): Temporary accessor for debugging http://crbug.com/73356 . - const gfx::Size& custom_size() const { return custom_size_; } #endif private: diff --git a/webkit/glue/webcursor_mac.mm b/webkit/glue/webcursor_mac.mm index 8c72da2..908f10c 100644 --- a/webkit/glue/webcursor_mac.mm +++ b/webkit/glue/webcursor_mac.mm @@ -9,6 +9,7 @@ #include "base/logging.h" #include "base/mac/scoped_cftyperef.h" +#include "base/memory/scoped_nsobject.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebImage.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h" @@ -37,17 +38,28 @@ NSCursor* LoadCursor(const char* name, int x, int y) { CGImageRef CreateCGImageFromCustomData(const std::vector<char>& custom_data, const gfx::Size& custom_size) { - base::mac::ScopedCFTypeRef<CGColorSpaceRef> cg_color( - CGColorSpaceCreateDeviceRGB()); // This is safe since we're not going to draw into the context we're creating. - void* data = const_cast<char*>(&custom_data[0]); // 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()) + data = const_cast<char*>(&custom_data[0]); + + // If the size is empty, use a 1x1 transparent image. + gfx::Size size = custom_size; + if (size.IsEmpty()) { + size.SetSize(1, 1); + data = NULL; + } + + base::mac::ScopedCFTypeRef<CGColorSpaceRef> cg_color( + CGColorSpaceCreateDeviceRGB()); base::mac::ScopedCFTypeRef<CGContextRef> context( CGBitmapContextCreate(data, - custom_size.width(), - custom_size.height(), + size.width(), + size.height(), 8, - custom_size.width()*4, + size.width()*4, cg_color.get(), kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big)); @@ -57,19 +69,14 @@ 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) { - // CG throws a cocoa exception if we try to create an empty image, which - // results in an infinite loop. This CHECK ensures that we crash instead. - CHECK(!custom_data.empty()); - base::mac::ScopedCFTypeRef<CGImageRef> cg_image( CreateCGImageFromCustomData(custom_data, custom_size)); - NSBitmapImageRep* ns_bitmap = - [[NSBitmapImageRep alloc] initWithCGImage:cg_image.get()]; + scoped_nsobject<NSBitmapImageRep> ns_bitmap( + [[NSBitmapImageRep alloc] initWithCGImage:cg_image.get()]); NSImage* cursor_image = [[NSImage alloc] init]; DCHECK(cursor_image); [cursor_image addRepresentation:ns_bitmap]; - [ns_bitmap release]; NSCursor* cursor = [[NSCursor alloc] initWithImage:cursor_image hotSpot:NSMakePoint(hotspot.x(), |