Skip to content

Commit 4218b0e

Browse files
committed
feat: propagate implementation of cancel event
1 parent 24080f3 commit 4218b0e

File tree

4 files changed

+40
-5
lines changed

4 files changed

+40
-5
lines changed

packages/desktop/src/events.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ impl HtmlEventConverter for SerializedHtmlEventConverter {
1717
.into()
1818
}
1919

20+
fn convert_cancel_data(&self, event: &PlatformEventData) -> CancelData {
21+
event
22+
.downcast::<SerializedCancelData>()
23+
.cloned()
24+
.unwrap()
25+
.into()
26+
}
27+
2028
fn convert_clipboard_data(&self, event: &PlatformEventData) -> ClipboardData {
2129
event
2230
.downcast::<SerializedClipboardData>()

packages/html/src/transit.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ fn deserialize_raw(name: &str, data: &serde_json::Value) -> Result<EventData, se
6565
}
6666

6767
let data = match name {
68+
// Cancel
69+
"cancel" => Cancel(de(data)?),
70+
6871
// Mouse
6972
"click" | "contextmenu" | "dblclick" | "doubleclick" | "mousedown" | "mouseenter"
7073
| "mouseleave" | "mousemove" | "mouseout" | "mouseover" | "mouseup" => Mouse(de(data)?),
@@ -154,6 +157,7 @@ impl HtmlEvent {
154157
#[serde(untagged)]
155158
#[non_exhaustive]
156159
pub enum EventData {
160+
Cancel(SerializedCancelData),
157161
Mouse(SerializedMouseData),
158162
Clipboard(SerializedClipboardData),
159163
Composition(SerializedCompositionData),
@@ -179,6 +183,9 @@ pub enum EventData {
179183
impl EventData {
180184
pub fn into_any(self) -> Rc<dyn Any> {
181185
match self {
186+
EventData::Cancel(data) => {
187+
Rc::new(PlatformEventData::new(Box::new(data))) as Rc<dyn Any>
188+
}
182189
EventData::Mouse(data) => {
183190
Rc::new(PlatformEventData::new(Box::new(data))) as Rc<dyn Any>
184191
}
@@ -291,6 +298,14 @@ impl HtmlEventConverter for SerializedHtmlEventConverter {
291298
.into()
292299
}
293300

301+
fn convert_cancel_data(&self, event: &PlatformEventData) -> CancelData {
302+
event
303+
.downcast::<SerializedCancelData>()
304+
.cloned()
305+
.unwrap()
306+
.into()
307+
}
308+
294309
fn convert_clipboard_data(&self, event: &PlatformEventData) -> ClipboardData {
295310
event
296311
.downcast::<SerializedClipboardData>()

packages/liveview/src/events.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ impl HtmlEventConverter for SerializedHtmlEventConverter {
1515
.into()
1616
}
1717

18+
fn convert_cancel_data(&self, event: &PlatformEventData) -> CancelData {
19+
event
20+
.downcast::<SerializedCancelData>()
21+
.cloned()
22+
.unwrap()
23+
.into()
24+
}
25+
1826
fn convert_clipboard_data(&self, event: &PlatformEventData) -> ClipboardData {
1927
event
2028
.downcast::<SerializedClipboardData>()

packages/native-dom/src/events.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ use dioxus_html::{
55
point_interaction::{
66
InteractionElementOffset, InteractionLocation, ModifiersInteraction, PointerInteraction,
77
},
8-
AnimationData, ClipboardData, CompositionData, DragData, FocusData, FormData, FormValue,
9-
HasFileData, HasFocusData, HasFormData, HasKeyboardData, HasMouseData, HtmlEventConverter,
10-
ImageData, KeyboardData, MediaData, MountedData, MouseData, PlatformEventData, PointerData,
11-
ResizeData, ScrollData, SelectionData, ToggleData, TouchData, TransitionData, VisibleData,
12-
WheelData,
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,
1313
};
1414
use keyboard_types::{Code, Key, Location, Modifiers};
1515
use std::any::Any;
@@ -18,6 +18,10 @@ use std::collections::HashMap;
1818
pub struct NativeConverter {}
1919

2020
impl HtmlEventConverter for NativeConverter {
21+
fn convert_cancel_data(&self, _event: &PlatformEventData) -> CancelData {
22+
todo!("todo: convert_cancel_data in dioxus-native. requires support in blitz")
23+
}
24+
2125
fn convert_form_data(&self, event: &PlatformEventData) -> FormData {
2226
event.downcast::<NativeFormData>().unwrap().clone().into()
2327
}

0 commit comments

Comments
 (0)