Drag & drop - #492
Conversation
|
Will take a proper look but:
Just wanted to say that this seems like a very sensible choice. I'm anticipating that we'll probably get a new Winit beta once the DnD PR lands. |
|
No need to rush, I've only tested the incoming dnd events and not everything is implemented yet, but it's a great start. |
nicoburns
left a comment
There was a problem hiding this comment.
I took a look because I was curious and have a left a couple of notes.
And a general comment that:
Drag and Drop actually has three distinct use cases: dragging elements within a page, dragging data out of a page, and dragging data into a page. They have subtly different requirements and implementations.
(https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API)
And this only currently only implements "dragging data into a page". We don't necessarily need an implementation of all 3 at once, but it's at least worth thinking about when designing the API (and I'd personally be kinda tempted to try to handle "dragging elements within a page" too, as I think that might end up changing the design somewhat).
|
I think that the enter/over/leave/drop are now handled correctly (needs #496 to be fixed for bubbling) I think that the structure can support "dragging elements within a page" but I haven't come to that part yet, also dragable=true needs to handle the event data automagically so yea fun stuff |
|
So I tried implementing dragstart/drag/dragend, but for whatever reason ondragstart is not even getting triggered... am I missing something somewhere? it gets to self.handler.handle_event in the driver, but not to the actual event, I don't think the implementation is correct yet, especially drag/dragend so thats still wip |
|
@Klemen2 You need to detect and send EDIT: well that's for dragging DOM elements with |
|
I did some changes and now you can d&d text within the app, haven't implemented the outgoing drags yet, but ondragstart is still not triggering on draggable (implementation is inside
as far as I can tell, dragstart only fires on elements with draggable=true / draggable types (text, images, link) from where the drag started, and doesn't fire at all for external drags |
|
I think that this is mostly ready, (todo: cursor icon, dragging images, inputs, links) |
|
Testing this on macOS I'm getting two files when dropping a single file onto the drop zone |
Interesting, I'm not experiencing this on windows |
dc2795b to
9aadb39
Compare
|
let mut event_kind_idx = event.data.discriminant() as usize;
match event.data {
DomEventData::DragStart(_) => event_kind_idx += 1,
_ => {}
}
Fixed it |
30910f7 to
b863f8d
Compare
- dragenter/dragover/drageave/drop - dragstart/drag/dragend - outgoing drags - drop effect (not fully implemented) - internal drags (not fully implemented) - shell set_datatransfer (I don't think that get_datatransfer is necessary as drop will always be an ui event so custom widgets can use that)
Stacked on top of: #614
This PR adds the following
Drag events:
dragentereventdragovereventdragleaveeventdropeventdragstarteventdrageventdragendeventExternal drags:
Internal drags
Shell
set_datatransferNot included in this pr: dragging text (html), dragging images, dragging links, dragging input/textbox text, dropping to input/textbox, cursor icon, drop effect based on target
WPT results
10 newly passing, 0 newly failing (net +10).
Full diff (10 changed tests)
Generated by the WPT workflow.