This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 14633 - Drag source and drag destination can't coordinate behavior.
Summary: Drag source and drag destination can't coordinate behavior.
Status: RESOLVED LATER
Alias: None
Product: HTML.next
Classification: Unclassified
Component: default (show other bugs)
Version: unspecified
Hardware: All All
: P2 enhancement
Target Milestone: ---
Assignee: This bug has no owner yet - up for the taking
QA Contact: HTML WG Bugzilla archive list
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-31 18:43 UTC by bytecrafter
Modified: 2012-09-14 12:13 UTC (History)
7 users (show)

See Also:


Attachments

Description bytecrafter 2011-10-31 18:43:01 UTC
It seems that the HTML5 Drag and Drop API enforces a separation between the drag source and the drag destination (the two "sides" of the DnD operation). In general, this is a good thing. However, there are cases where one side of the DnD operation should definitely know about the other side.

In particular, I tried implementing drag-and-drop lists using HTML5 DnD. The list data is stored outside the DOM. When moving an item between lists, each side was responsible for updating its own data - the dragged element would remove itself from the source lists's data (during "dragend"), and the drag target would add the dragged item to the destination list's data (during "drop"). The problem, though, is that the move semantic has been lost. By decomposing a move into an insert followed by a delete, we may end up doing more work than we need to. Decomposing a move into an insert and a delete also breaks the atomicity that a move operation would suggest. Finally, the separate operations also imply the creation and destruction of data, which may introduce data inconsistencies. In my case, besides updating the Javascript data structures, the move operation eventually causes an asynchronous HTTP request to be sent. In this HTTP API, a move is very different from a insert/delete pair. 

In the case of a move, we want to update all the underlying data in one operation. That implies that we need only one side (either the source or the destination) to be responsible for updating all of the data. And this is where the HTML5 DnD spec falls short. As far as I can tell, there is no way for the source element to determine the drop target element, and there is no way for the drop target element to determine the source element. The only way that the two DnD sides can communicate is via the dataTransfer object. One thought would be to somehow put the source element into the dataTransfer object. However, since the dataTransfer object only supports files and strings, this won't work in the general case. Furthermore, this seems an abuse of the dataTransfer object, which seems like it should deal only with representations of the underlying data.

Although I don't have a lot of experience in this area, most desktop application libraries seem to include some provision in their drag-and-drop support to allow a drop destination to discover its paired drag source. For example, Cocoa sends the DnD source (often the NSView that initiated the DnD operation) along with all messages to the DnD destination. WinForms seems to include the drag source in the object that is sent to destination object events. In these libraries, the drag source is explicitly communicated alongside (not within) the DnD data store.

To address this gap, I would recommend using the relatedTarget property of the "dragEnd" and "drop" events. In the case of the "drop" event, relatedTarget should be set to the source element (i.e. the element to which the "dragEnd" event will be sent). In the case of the "dragEnd" event, relatedTarget should be set to the Current Drop Target (i.e. the element to which "drop" was sent). It might also make sense to set this property for the "dragover" event, but I haven't thought through that yet. In the current draft, relatedTarget is null for all DnD events, so I don't believe that this will cause any problems.
Comment 1 Ian 'Hixie' Hickson 2011-11-01 03:24:41 UTC
There is already a plan to fix this: in a future version (probably early next year) I plan to add the ability to pass a structured clone of data, including possibly a port, through which any such communication can occur.

In the meantime, you can just create a shared worker from which you get a unique transaction ID which is the data you add to the drag data store.


EDITOR'S RESPONSE: This is an Editor's Response to your comment. If you are satisfied with this response, please change the state of this bug to CLOSED. If you have additional information and would like the editor to reconsider, please reopen this bug. If you would like to escalate the issue to the full HTML Working Group, please add the TrackerRequest keyword to this bug, and suggest title and text for the tracker issue; or you may create a tracker issue yourself, if you are able to do so. For more details, see this document:
   http://dev.w3.org/html5/decision-policy/decision-policy.html

Status: Partially Accepted
Change Description: none yet
Rationale: Marking "LATER" for now; I don't want to add new drag-and-drop features until the browsers have mostly caught up with implementing the ones we've added already. However, please do not hesitate to reopen this if you notice that they have done so before I do.