|
@@ -1,84 +1,84 @@
|
|
|
+use super::{Synthetic, WebEventExt};
|
|
|
use dioxus_html::{
|
|
|
+ geometry::{ClientPoint, ElementPoint, PagePoint, ScreenPoint},
|
|
|
+ input_data::{decode_mouse_button_set, MouseButton},
|
|
|
prelude::{
|
|
|
- InteractionElementOffset, InteractionLocation, ModifiersInteraction, PointerInteraction,
|
|
|
+ InteractionElementOffset, InteractionLocation, Modifiers, ModifiersInteraction,
|
|
|
+ PointerInteraction,
|
|
|
},
|
|
|
HasDragData, HasFileData, HasMouseData,
|
|
|
};
|
|
|
-use web_sys::MouseEvent;
|
|
|
-
|
|
|
-use super::{Synthetic, WebEventExt};
|
|
|
+use web_sys::DragEvent;
|
|
|
|
|
|
-pub(crate) struct WebDragData {
|
|
|
- raw: Synthetic<MouseEvent>,
|
|
|
-}
|
|
|
+impl InteractionLocation for Synthetic<DragEvent> {
|
|
|
+ fn client_coordinates(&self) -> ClientPoint {
|
|
|
+ ClientPoint::new(self.event.client_x().into(), self.event.client_y().into())
|
|
|
+ }
|
|
|
|
|
|
-impl WebDragData {
|
|
|
- pub fn new(raw: MouseEvent) -> Self {
|
|
|
- Self {
|
|
|
- raw: Synthetic::new(raw),
|
|
|
- }
|
|
|
+ fn page_coordinates(&self) -> PagePoint {
|
|
|
+ PagePoint::new(self.event.page_x().into(), self.event.page_y().into())
|
|
|
}
|
|
|
-}
|
|
|
|
|
|
-impl HasDragData for WebDragData {
|
|
|
- fn as_any(&self) -> &dyn std::any::Any {
|
|
|
- &self.raw as &dyn std::any::Any
|
|
|
+ fn screen_coordinates(&self) -> ScreenPoint {
|
|
|
+ ScreenPoint::new(self.event.screen_x().into(), self.event.screen_y().into())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-impl HasMouseData for WebDragData {
|
|
|
- fn as_any(&self) -> &dyn std::any::Any {
|
|
|
- &self.raw as &dyn std::any::Any
|
|
|
+impl InteractionElementOffset for Synthetic<DragEvent> {
|
|
|
+ fn element_coordinates(&self) -> ElementPoint {
|
|
|
+ ElementPoint::new(self.event.offset_x().into(), self.event.offset_y().into())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-impl PointerInteraction for WebDragData {
|
|
|
- fn trigger_button(&self) -> Option<dioxus_html::input_data::MouseButton> {
|
|
|
- self.raw.trigger_button()
|
|
|
- }
|
|
|
+impl ModifiersInteraction for Synthetic<DragEvent> {
|
|
|
+ fn modifiers(&self) -> Modifiers {
|
|
|
+ let mut modifiers = Modifiers::empty();
|
|
|
|
|
|
- fn held_buttons(&self) -> dioxus_html::input_data::MouseButtonSet {
|
|
|
- self.raw.held_buttons()
|
|
|
- }
|
|
|
-}
|
|
|
+ if self.event.alt_key() {
|
|
|
+ modifiers.insert(Modifiers::ALT);
|
|
|
+ }
|
|
|
+ if self.event.ctrl_key() {
|
|
|
+ modifiers.insert(Modifiers::CONTROL);
|
|
|
+ }
|
|
|
+ if self.event.meta_key() {
|
|
|
+ modifiers.insert(Modifiers::META);
|
|
|
+ }
|
|
|
+ if self.event.shift_key() {
|
|
|
+ modifiers.insert(Modifiers::SHIFT);
|
|
|
+ }
|
|
|
|
|
|
-impl ModifiersInteraction for WebDragData {
|
|
|
- fn modifiers(&self) -> dioxus_html::prelude::Modifiers {
|
|
|
- self.raw.modifiers()
|
|
|
+ modifiers
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-impl InteractionElementOffset for WebDragData {
|
|
|
- fn coordinates(&self) -> dioxus_html::geometry::Coordinates {
|
|
|
- self.raw.coordinates()
|
|
|
+impl PointerInteraction for Synthetic<DragEvent> {
|
|
|
+ fn held_buttons(&self) -> dioxus_html::input_data::MouseButtonSet {
|
|
|
+ decode_mouse_button_set(self.event.buttons())
|
|
|
}
|
|
|
|
|
|
- fn element_coordinates(&self) -> dioxus_html::geometry::ElementPoint {
|
|
|
- self.raw.element_coordinates()
|
|
|
+ fn trigger_button(&self) -> Option<MouseButton> {
|
|
|
+ Some(MouseButton::from_web_code(self.event.button()))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-impl InteractionLocation for WebDragData {
|
|
|
- fn client_coordinates(&self) -> dioxus_html::geometry::ClientPoint {
|
|
|
- self.raw.client_coordinates()
|
|
|
- }
|
|
|
-
|
|
|
- fn screen_coordinates(&self) -> dioxus_html::geometry::ScreenPoint {
|
|
|
- self.raw.screen_coordinates()
|
|
|
+impl HasMouseData for Synthetic<DragEvent> {
|
|
|
+ fn as_any(&self) -> &dyn std::any::Any {
|
|
|
+ &self.event
|
|
|
}
|
|
|
+}
|
|
|
|
|
|
- fn page_coordinates(&self) -> dioxus_html::geometry::PagePoint {
|
|
|
- self.raw.page_coordinates()
|
|
|
+impl HasDragData for Synthetic<DragEvent> {
|
|
|
+ fn as_any(&self) -> &dyn std::any::Any {
|
|
|
+ &self.event
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-impl HasFileData for WebDragData {
|
|
|
+impl HasFileData for Synthetic<DragEvent> {
|
|
|
#[cfg(feature = "file_engine")]
|
|
|
fn files(&self) -> Option<std::sync::Arc<dyn dioxus_html::FileEngine>> {
|
|
|
use wasm_bindgen::JsCast;
|
|
|
|
|
|
let files = self
|
|
|
- .raw
|
|
|
.event
|
|
|
.dyn_ref::<web_sys::DragEvent>()
|
|
|
.and_then(|drag_event| {
|
|
@@ -97,12 +97,11 @@ impl HasFileData for WebDragData {
|
|
|
}
|
|
|
|
|
|
impl WebEventExt for dioxus_html::DragData {
|
|
|
- type WebEvent = web_sys::MouseEvent;
|
|
|
+ type WebEvent = web_sys::DragEvent;
|
|
|
|
|
|
#[inline(always)]
|
|
|
- fn try_as_web_event(&self) -> Option<web_sys::MouseEvent> {
|
|
|
- self.downcast::<WebDragData>()
|
|
|
- .map(|data| &data.raw.event)
|
|
|
- .cloned()
|
|
|
+ fn try_as_web_event(&self) -> Option<web_sys::DragEvent> {
|
|
|
+ self.downcast::<Synthetic<DragEvent>>()
|
|
|
+ .map(|data| data.event.clone())
|
|
|
}
|
|
|
}
|