dioxus_native_dom/
events.rs1use blitz_traits::events::{BlitzKeyEvent, BlitzMouseButtonEvent, MouseEventButton};
2use dioxus_html::{
3 geometry::{ClientPoint, ElementPoint, PagePoint, ScreenPoint},
4 input_data::{MouseButton, MouseButtonSet},
5 point_interaction::{
6 InteractionElementOffset, InteractionLocation, ModifiersInteraction, PointerInteraction,
7 },
8 AnimationData, CancelData, ClipboardData, CompositionData, DragData, FocusData, FormData,
9 FormValue, HasFileData, HasFocusData, HasFormData, HasKeyboardData, HasMouseData,
10 HtmlEventConverter, ImageData, KeyboardData, MediaData, MountedData, MouseData,
11 PlatformEventData, PointerData, ResizeData, ScrollData, SelectionData, ToggleData, TouchData,
12 TransitionData, VisibleData, WheelData,
13};
14use keyboard_types::{Code, Key, Location, Modifiers};
15use std::any::Any;
16
17pub struct NativeConverter {}
18
19impl HtmlEventConverter for NativeConverter {
20 fn convert_cancel_data(&self, _event: &PlatformEventData) -> CancelData {
21 unimplemented!("todo: convert_cancel_data in dioxus-native. requires support in blitz")
22 }
23
24 fn convert_form_data(&self, event: &PlatformEventData) -> FormData {
25 event.downcast::<NativeFormData>().unwrap().clone().into()
26 }
27
28 fn convert_mouse_data(&self, event: &PlatformEventData) -> MouseData {
29 event.downcast::<NativeClickData>().unwrap().clone().into()
30 }
31
32 fn convert_keyboard_data(&self, event: &PlatformEventData) -> KeyboardData {
33 event
34 .downcast::<BlitzKeyboardData>()
35 .unwrap()
36 .clone()
37 .into()
38 }
39
40 fn convert_focus_data(&self, _event: &PlatformEventData) -> FocusData {
41 NativeFocusData {}.into()
42 }
43
44 fn convert_animation_data(&self, _event: &PlatformEventData) -> AnimationData {
45 unimplemented!("todo: convert_animation_data in dioxus-native. requires support in blitz")
46 }
47
48 fn convert_clipboard_data(&self, _event: &PlatformEventData) -> ClipboardData {
49 unimplemented!("todo: convert_clipboard_data in dioxus-native. requires support in blitz")
50 }
51
52 fn convert_composition_data(&self, _event: &PlatformEventData) -> CompositionData {
53 unimplemented!("todo: convert_composition_data in dioxus-native. requires support in blitz")
54 }
55
56 fn convert_drag_data(&self, _event: &PlatformEventData) -> DragData {
57 unimplemented!("todo: convert_drag_data in dioxus-native. requires support in blitz")
58 }
59
60 fn convert_image_data(&self, _event: &PlatformEventData) -> ImageData {
61 unimplemented!("todo: convert_image_data in dioxus-native. requires support in blitz")
62 }
63
64 fn convert_media_data(&self, _event: &PlatformEventData) -> MediaData {
65 unimplemented!("todo: convert_media_data in dioxus-native. requires support in blitz")
66 }
67
68 fn convert_mounted_data(&self, _event: &PlatformEventData) -> MountedData {
69 unimplemented!("todo: convert_mounted_data in dioxus-native. requires support in blitz")
70 }
71
72 fn convert_pointer_data(&self, _event: &PlatformEventData) -> PointerData {
73 unimplemented!("todo: convert_pointer_data in dioxus-native. requires support in blitz")
74 }
75
76 fn convert_scroll_data(&self, _event: &PlatformEventData) -> ScrollData {
77 unimplemented!("todo: convert_scroll_data in dioxus-native. requires support in blitz")
78 }
79
80 fn convert_selection_data(&self, _event: &PlatformEventData) -> SelectionData {
81 unimplemented!("todo: convert_selection_data in dioxus-native. requires support in blitz")
82 }
83
84 fn convert_toggle_data(&self, _event: &PlatformEventData) -> ToggleData {
85 unimplemented!("todo: convert_toggle_data in dioxus-native. requires support in blitz")
86 }
87
88 fn convert_touch_data(&self, _event: &PlatformEventData) -> TouchData {
89 unimplemented!("todo: convert_touch_data in dioxus-native. requires support in blitz")
90 }
91
92 fn convert_transition_data(&self, _event: &PlatformEventData) -> TransitionData {
93 unimplemented!("todo: convert_transition_data in dioxus-native. requires support in blitz")
94 }
95
96 fn convert_wheel_data(&self, _event: &PlatformEventData) -> WheelData {
97 unimplemented!("todo: convert_wheel_data in dioxus-native. requires support in blitz")
98 }
99
100 fn convert_resize_data(&self, _event: &PlatformEventData) -> ResizeData {
101 unimplemented!("todo: convert_resize_data in dioxus-native. requires support in blitz")
102 }
103
104 fn convert_visible_data(&self, _event: &PlatformEventData) -> VisibleData {
105 unimplemented!("todo: convert_visible_data in dioxus-native. requires support in blitz")
106 }
107}
108
109#[derive(Clone, Debug)]
110pub struct NativeFormData {
111 pub value: String,
112 pub values: Vec<(String, FormValue)>,
113}
114
115impl HasFormData for NativeFormData {
116 fn as_any(&self) -> &dyn std::any::Any {
117 self as &dyn std::any::Any
118 }
119
120 fn value(&self) -> String {
121 self.value.clone()
122 }
123
124 fn values(&self) -> Vec<(String, FormValue)> {
125 self.values.clone()
126 }
127 fn valid(&self) -> bool {
128 true
130 }
131}
132
133impl HasFileData for NativeFormData {
134 fn files(&self) -> Vec<dioxus_html::FileData> {
135 vec![]
136 }
137}
138
139#[derive(Clone, Debug)]
140pub(crate) struct BlitzKeyboardData(pub(crate) BlitzKeyEvent);
141
142impl ModifiersInteraction for BlitzKeyboardData {
143 fn modifiers(&self) -> Modifiers {
144 self.0.modifiers
145 }
146}
147
148impl HasKeyboardData for BlitzKeyboardData {
149 fn key(&self) -> Key {
150 self.0.key.clone()
151 }
152
153 fn code(&self) -> Code {
154 self.0.code
155 }
156
157 fn location(&self) -> Location {
158 self.0.location
159 }
160
161 fn is_auto_repeating(&self) -> bool {
162 self.0.is_auto_repeating
163 }
164
165 fn is_composing(&self) -> bool {
166 self.0.is_composing
167 }
168
169 fn as_any(&self) -> &dyn std::any::Any {
170 self as &dyn Any
171 }
172}
173
174#[derive(Clone)]
175pub struct NativeClickData(pub(crate) BlitzMouseButtonEvent);
176
177impl InteractionLocation for NativeClickData {
178 fn client_coordinates(&self) -> ClientPoint {
179 ClientPoint::new(self.0.x as _, self.0.y as _)
180 }
181
182 fn screen_coordinates(&self) -> ScreenPoint {
184 unimplemented!()
185 }
186
187 fn page_coordinates(&self) -> PagePoint {
188 unimplemented!()
189 }
190}
191
192impl InteractionElementOffset for NativeClickData {
193 fn element_coordinates(&self) -> ElementPoint {
194 unimplemented!()
195 }
196}
197
198impl ModifiersInteraction for NativeClickData {
199 fn modifiers(&self) -> Modifiers {
200 self.0.mods
201 }
202}
203
204impl PointerInteraction for NativeClickData {
205 fn trigger_button(&self) -> Option<MouseButton> {
206 Some(match self.0.button {
207 MouseEventButton::Main => MouseButton::Primary,
208 MouseEventButton::Auxiliary => MouseButton::Auxiliary,
209 MouseEventButton::Secondary => MouseButton::Secondary,
210 MouseEventButton::Fourth => MouseButton::Fourth,
211 MouseEventButton::Fifth => MouseButton::Fifth,
212 })
213 }
214
215 fn held_buttons(&self) -> MouseButtonSet {
216 dioxus_html::input_data::decode_mouse_button_set(self.0.buttons.bits() as u16)
217 }
218}
219impl HasMouseData for NativeClickData {
220 fn as_any(&self) -> &dyn std::any::Any {
221 self as &dyn std::any::Any
222 }
223}
224
225#[derive(Clone)]
226pub struct NativeFocusData {}
227impl HasFocusData for NativeFocusData {
228 fn as_any(&self) -> &dyn std::any::Any {
229 self as &dyn std::any::Any
230 }
231}