summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/web_drag_source.mm
diff options
context:
space:
mode:
authorthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-05 18:45:33 +0000
committerthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-05 18:45:33 +0000
commit78043bddf1744180a28682f8cdf3359a9bfdef4b (patch)
tree55a8fb8cf8a99a039cb0e3bf2de96c6232782b93 /chrome/browser/cocoa/web_drag_source.mm
parent0a6d4ce8805679d6350dd4ce596d53dcd25837f4 (diff)
downloadchromium_src-78043bddf1744180a28682f8cdf3359a9bfdef4b.zip
chromium_src-78043bddf1744180a28682f8cdf3359a9bfdef4b.tar.gz
chromium_src-78043bddf1744180a28682f8cdf3359a9bfdef4b.tar.bz2
Mac: Make image dragging 162.4% more awesome.
Also needs a webkit patch to do anything ( https://bugs.webkit.org/show_bug.cgi?id=37069 ), but can be landed independently. BUG=11457,18992 TEST=(all require the webkit patch, so this won't work yet) http://html5demos.com/drag and http://ljouanneau.com/lab/html5/demodragdrop.html Dragging should show image http://www.google.com/ Dragging google image should show image http://www.travelvivi.com/wp-content/uploads/2009/09/Eiffel_Tower.jpg Dragging image should work, drag image should be smaller than image itself Random website Mark some text, drag it. Should show drag cursor and no image Review URL: http://codereview.chromium.org/1539018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43631 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/web_drag_source.mm')
-rw-r--r--chrome/browser/cocoa/web_drag_source.mm28
1 files changed, 17 insertions, 11 deletions
diff --git a/chrome/browser/cocoa/web_drag_source.mm b/chrome/browser/cocoa/web_drag_source.mm
index 8f5efe7..62733bc 100644
--- a/chrome/browser/cocoa/web_drag_source.mm
+++ b/chrome/browser/cocoa/web_drag_source.mm
@@ -35,16 +35,6 @@ namespace {
// |NSURLPboardType|.
NSString* const kNSURLTitlePboardType = @"public.url-name";
-// Make a drag image from the drop data.
-// TODO(viettrungluu): Move this somewhere more sensible.
-NSImage* MakeDragImage(const WebDropData* drop_data) {
- // TODO(viettrungluu): Just a stub for now. Make it do something (see, e.g.,
- // WebKit/WebKit/mac/Misc/WebNSViewExtras.m: |-_web_DragImageForElement:...|).
-
- // Default to returning a generic image.
- return nsimage_cache::ImageNamed(@"nav.pdf");
-}
-
// Returns a filename appropriate for the drop data
// TODO(viettrungluu): Refactor to make it common across platforms,
// and move it somewhere sensible.
@@ -122,6 +112,8 @@ void PromiseWriterTask::Run() {
- (id)initWithContentsView:(TabContentsViewCocoa*)contentsView
dropData:(const WebDropData*)dropData
+ image:(NSImage*)image
+ offset:(NSPoint)offset
pasteboard:(NSPasteboard*)pboard
dragOperationMask:(NSDragOperation)dragOperationMask {
if ((self = [super init])) {
@@ -131,6 +123,9 @@ void PromiseWriterTask::Run() {
dropData_.reset(new WebDropData(*dropData));
DCHECK(dropData_.get());
+ dragImage_.reset([image retain]);
+ imageOffset_ = offset;
+
pasteboard_.reset([pboard retain]);
DCHECK(pasteboard_.get());
@@ -225,6 +220,13 @@ void PromiseWriterTask::Run() {
clickCount:1
pressure:1.0];
+ if (dragImage_) {
+ position.x -= imageOffset_.x;
+ // Deal with Cocoa's flipped coordinate system.
+ position.y -= [dragImage_.get() size].height - imageOffset_.y;
+ }
+ // Per kwebster, offset arg is ignored, see -_web_DragImageForElement: in
+ // third_party/WebKit/WebKit/mac/Misc/WebNSViewExtras.m.
[window dragImage:[self dragImage]
at:position
offset:NSZeroSize
@@ -386,7 +388,11 @@ void PromiseWriterTask::Run() {
}
- (NSImage*)dragImage {
- return MakeDragImage(dropData_.get());
+ if (dragImage_)
+ return dragImage_;
+
+ // Default to returning a generic image.
+ return nsimage_cache::ImageNamed(@"nav.pdf");
}
@end // @implementation WebDragSource (Private)