[whatwg] How to tell when a drag and drop was successful?

2013-08-13 Thread Daniel Trebbien
Reading through the spec, I am not seeing how an application can determine 
whether a drop into a different window was successful.

Example use case:  An app wants to take advantage of multiple screens, and so 
it opens two different windows which can be placed on different screens.  The 
user can move items/tasks/events/objects/etc. from one window to another by 
dragging and dropping an item.  The app sets effectAllowed to move in the 
source window and the dropEffect to move in the destination window on 
dragging over the area where the item is supposed to be dropped.  The drag data 
are the essential details of the item that allow the destination window to know 
what was moved.  The source window needs to know whether the drop was 
successful in order to decide whether to remove the item from the display in 
the source window.

I have been experimenting with the attached HTML page in Chrome 28.0.1500.95 
and Firefox 23.0 on Mac.  I see no difference between the 'dragend' event 
object of a successful versus non-successful drop.

The spec gives an example of removing the dragged element from the display:
http://www.whatwg.org/specs/web-apps/current-work/multipage/dnd.html#introduction-8
.. but this has the problem that the element is removed regardless of whether 
the drop was successful, right?

One approach to removing the dragged element (as demonstrated by 
http://html5demos.com/drag ) is to do the cleanup on 'drop', but in a 
cross-window dragging scenario, the source window does not receive a 'drop' 
event.

Daniel


Re: [whatwg] How to tell when a drag and drop was successful?

2013-08-13 Thread Ian Hickson
On Tue, 13 Aug 2013, Daniel Trebbien wrote:

 Reading through the spec, I am not seeing how an application can 
 determine whether a drop into a different window was successful.

This was an error in the spec. Good catch.

I've updated the spec. The trick is to check event.dataTransfer.dropEffect 
in the dragend event; if it's none then the drag was canceled.

This works already in Chrome and Firefox for same-page drags; it also 
works in Chrome for cross-app drags, but in Firefox for some reason you 
always get none for cross-app drags currently. It does work for 
cross-page (all within Firefox) drags in Firefox. (Tested on Mac.)


 The spec gives an example of removing the dragged element from the 
 display: 
 http://www.whatwg.org/specs/web-apps/current-work/multipage/dnd.html#introduction-8
  
 .. but this has the problem that the element is removed regardless of 
 whether the drop was successful, right?

Good point. Fixed. Thanks!

-- 
Ian Hickson   U+1047E)\._.,--,'``.fL
http://ln.hixie.ch/   U+263A/,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'