[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
This commit is contained in:
@ -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];
|
||||
}
|
||||
|
@ -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:
|
||||
|
@ -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) {
|
||||
// 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())
|
||||
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());
|
||||
// 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.
|
||||
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(),
|
||||
|
Reference in New Issue
Block a user