[whatwg] Proposal for public data in drag events
ian at hixie.ch
Thu Aug 30 10:27:58 PDT 2012
On Thu, 21 Jun 2012, Trevor Burnham wrote:
> I've been using HTML drag-and-drop
> in a project, but I've run into one limitation that seems severe to me:
> There is no direct way to determine what the source node is from a
> dragenter, dragover, or dragleave event. This makes it difficult to
> support use cases where elements react to those events differently
> depending on what is being dragged over them.
This is intentional, because that source node could be from a Web page in
another origin, another browser, or indeed, an app that isn't even a
browser. So there's no real sane way to do it.
> I understand that the reason for this is cross-document drags: In
> addition to security implications, obtaining a reference to a DOM node
> in another document simply wouldn't make sense. Therefore, the
> dataTransfer object only allows serialized data. Unfortunately,
> dataTransfer is only appropriate for carrying data to the drop target.
> There is no mechanism for providing data to intermediate drag event
> receivers, except for the "types" attributes on the dataTransfer object.
> "types" can be used to carry data that you want to make public
> (http://stackoverflow.com/a/11089592/66226), but this is clearly a hack
> and it carries some limitations. Most notably, the spec requires that
> data type strings be converted to ASCII lowercase.
> Therefore, I'd like to propose the addition of a "publicData" object on
> all drag events. It would have the same interface and behavior as the
> dataTransfer object, with the sole exception that it would be read-only
> in all events where dataTransfer is protected. That is, publicData would
> be read/write in dragStart, and read-only in all other drag-and-drop
That's an interesting idea. I suppose we could expose it using a custom
type in cross-app OS dnd situations, too.
Could you elaborate on your use case? Are there cross-window use cases for
this? (For in-window cases, you could instead just use a global.)
Ian Hickson U+1047E )\._.,--....,'``. fL
http://ln.hixie.ch/ U+263A /, _.. \ _\ ;`._ ,.
Things that are impossible just take longer. `._.-(,_..'--(,_..'`-.;.'
More information about the whatwg