Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use DragEvent not MouseEvent for drag events #3137

Merged
merged 6 commits into from
Oct 31, 2024

Conversation

rogusdev
Copy link
Contributor

Resolves #3133 maybe?

@rogusdev rogusdev force-pushed the dragevent-not-mouseevent branch from 26dc8ea to 82a7e5c Compare October 28, 2024 23:44
@rogusdev
Copy link
Contributor Author

rogusdev commented Oct 28, 2024

Needs to convert the DragEvent into MouseEvent for some of the functions now

Resolved

@rogusdev rogusdev force-pushed the dragevent-not-mouseevent branch from 82a7e5c to 3b64b08 Compare October 29, 2024 04:57
@matthunz
Copy link
Contributor

Looks great! 👍 I just edited this to match the other web events that aren't using a wrapper struct (like WebDragData) and simplify because web_sys::DragEvent derefs to a web_sys::MouseEvent

@rogusdev rogusdev force-pushed the dragevent-not-mouseevent branch from cf49a51 to 6de77b0 Compare October 30, 2024 21:46
@rogusdev rogusdev force-pushed the dragevent-not-mouseevent branch from 6de77b0 to 6fa5c96 Compare October 30, 2024 21:48
@rogusdev
Copy link
Contributor Author

@matthunz sorry I did not see your changes before I force pushed my updates, because I found an issue. Please re-apply your updates you had done before, or just recommend them and I can add them.

@ealmloff your changes in cda8bb2#diff-517df2174967af5678c41e224b2d9a1f1e63e7fcdfe46bc4108c14bdf4defff2R25 broke downcast, I suspect for all event types. This is because self.raw is no longer a web_sys::*Event, instead they are all Synthetic<web_sys::*Event> and Synthetic is crate visibility only. So the as_any called by downcast needs to change to return the actual web_sys event, and not the Synthetic wrapper, otherwise outside code cannot access the wrapped web_sys events.

Given the last bit, I am not sure if this needs a larger set of changes to all the events, or if this is fine for now, or what. Please advise.

@ealmloff
Copy link
Member

@ealmloff your changes in cda8bb2#diff-517df2174967af5678c41e224b2d9a1f1e63e7fcdfe46bc4108c14bdf4defff2R25 broke downcast, I suspect for all event types. This is because self.raw is no longer a web_sys::*Event, instead they are all Synthetic<web_sys::*Event> and Synthetic is crate visibility only. So the as_any called by downcast needs to change to return the actual web_sys event, and not the Synthetic wrapper, otherwise outside code cannot access the wrapped web_sys events.

Given the last bit, I am not sure if this needs a larger set of changes to all the events, or if this is fine for now, or what. Please advise.

Yes, applying that change to all events would be great. Many people will be downcasting to the web-sys counterpart from previous releases, so if we can not change the type it downcasts to that is better

@matthunz
Copy link
Contributor

Oh my fault I didn't mean to get in the way @rogusdev I just re-applied those changes I hope that's all good.

I also added your fix for downcasting to all other events

@rogusdev
Copy link
Contributor Author

rogusdev commented Oct 30, 2024

@matthunz thanks! Your cleanup looks promising like a significant improvement! :) that said, I see a failing ci job now. Any idea what that is about?

@rogusdev
Copy link
Contributor Author

@matthunz I re-added the web_sys event reference for the drag.rs as_any-s because those got lost with the re-applying of the old commit

@rogusdev
Copy link
Contributor Author

rogusdev commented Oct 31, 2024

I also notice that web/events/mouse has these tidbits:

impl HasFileData for Synthetic<MouseEvent> {}

impl HasDragData for Synthetic<MouseEvent> {
    fn as_any(&self) -> &dyn std::any::Any {
        &self.event
    }
}

Perhaps these were just because of the old dragevent implementation and we can get rid of these now?...

I suspect they are vestigial now, and only added before for the slightly inaccurate previous structure of things, bc MDN does not mention files or drag anything for mouseevent: https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent

@matthunz
Copy link
Contributor

@matthunz I re-added the web_sys event reference for the drag.rs as_any-s because those got lost with the re-applying of the old commit

Ah man I totally missed that thanks!

@matthunz
Copy link
Contributor

@matthunz thanks! Your cleanup looks promising like a significant improvement! :) that said, I see a failing ci job now. Any idea what that is about?

Awesome! (: it looks like we might have a CI issue - looks like some links in various READMEs aren’t loading correctly for the runner

@rogusdev
Copy link
Contributor Author

Do you want to approve for me to merge as-is and you fix the readmes separately?

@ealmloff
Copy link
Member

Thanks, this looks much better. The readme links should be fixed automatically when the docsite is back to normal

@ealmloff ealmloff merged commit e5a1a62 into DioxusLabs:main Oct 31, 2024
16 of 17 checks passed
@ealmloff ealmloff added the web relating to the web renderer for dioxus label Oct 31, 2024
@rogusdev rogusdev deleted the dragevent-not-mouseevent branch October 31, 2024 14:56
@ealmloff ealmloff mentioned this pull request Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
web relating to the web renderer for dioxus
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Drag + drop events downcast to MouseEvent, when they should go to web_sys::DragEvent
3 participants