Bug 22998 - Setting the drag image during a drag operation does not work
Summary: Setting the drag image during a drag operation does not work
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Macintosh OS X 10.5
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-12-26 04:05 PST by Antoine Quint
Modified: 2013-07-22 07:28 PDT (History)
5 users (show)

See Also:


Attachments
Testcase (2.43 KB, text/html)
2008-12-26 04:06 PST, Antoine Quint
no flags Details
Another test case (2.33 KB, text/html)
2010-08-26 16:06 PDT, Mike Thole
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Antoine Quint 2008-12-26 04:05:49 PST
From my tests, calling event.dataTransfer.setDragImage() within a "dragenter" event handler in JS code is a no-op and .setDragImage() only does what's intended within a "dragstart" event handler. This might be a "feature" and not a bug, but I'm not sure why there would such a limitation to the use of .setDragImage().
Comment 1 Antoine Quint 2008-12-26 04:06:55 PST
Created attachment 26254 [details]
Testcase

This testcases shows that Clipboard::setDragImage() only works when called within a "dragstart" event handler. Indeed, when dragging the black square above, we set the drag image to be some element elsewhere in the DOM, and this works fine. As you initiate a drag from the black rectangle, you should see this message: This is a custom drag image. However, when you are dragging something else, say an image or URL shortcut from the Finder, over the black rectangle, attempting to set a custom drag image fails.
Comment 2 Simon Fraser (smfr) 2008-12-26 16:35:42 PST
It seems this is by design. The docs <http://developer.apple.com/documentation/AppleApplications/Conceptual/SafariJSProgTopics/Tasks/DragAndDrop.html#//apple_ref/doc/uid/30001233-177395> say "When a drag operation begins, you can use the setDragImage method of the dataTransfer object".

In terms of the implementation, DragController::tryDHTMLDrag() actually creates a new Clipboard object on every mouse drag, with a policy of ClipboardReadable or ClipboardTypesReadable. setDragImage() then bails on setting the image for this Clipboard because of that policy.

If it were possible to change the drag image after the start of the drag, I think there would have to be some 'same origin' policy to avoid pages changing the drag images of drags from other documents, or from outside the browser.
Comment 3 Antoine Quint 2008-12-27 02:40:29 PST
I think the current policy is too restrictive, I would prefer to have something like a same-domain policy so that I could have an element dragged from one of my webpages opened in one window dropped onto another webpages off my website in another window, and have the drop page be able to update the drag image to reflect the state of the element once dropped onto the current drop zone.
Comment 4 Mike Thole 2010-08-26 16:06:11 PDT
Created attachment 65639 [details]
Another test case

I was also surprised to find that the drag image can only be set during the "dragstart" event handler.  Attaching another test case that demonstrates the issue: RainbowDragging.html