|
@@ -157,135 +157,147 @@ impl HtmlEventConverter for WebEventConverter {
|
|
|
|
|
|
/// A extension trait for web-sys events that provides a way to get the event as a web-sys event.
|
|
/// A extension trait for web-sys events that provides a way to get the event as a web-sys event.
|
|
pub trait WebEventExt<E> {
|
|
pub trait WebEventExt<E> {
|
|
- /// Get the event as a web-sys event.
|
|
|
|
- fn web_event(&self) -> &E;
|
|
|
|
|
|
+ /// Try to downcast this event as a `web-sys` event.
|
|
|
|
+ fn try_as_web_event(&self) -> Option<&E>;
|
|
|
|
+
|
|
|
|
+ /// Downcast this event as a `web-sys` event.
|
|
|
|
+ #[inline(always)]
|
|
|
|
+ fn as_web_event(&self) -> &E
|
|
|
|
+ where
|
|
|
|
+ E: 'static,
|
|
|
|
+ {
|
|
|
|
+ self.try_as_web_event().unwrap_or_else(|| {
|
|
|
|
+ panic!(
|
|
|
|
+ "Error downcasting to `web-sys`, event should be a {}.",
|
|
|
|
+ std::any::type_name::<E>()
|
|
|
|
+ )
|
|
|
|
+ })
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
impl WebEventExt<web_sys::AnimationEvent> for dioxus_html::AnimationData {
|
|
impl WebEventExt<web_sys::AnimationEvent> for dioxus_html::AnimationData {
|
|
- fn web_event(&self) -> &web_sys::AnimationEvent {
|
|
|
|
|
|
+ #[inline(always)]
|
|
|
|
+ fn try_as_web_event(&self) -> Option<&web_sys::AnimationEvent> {
|
|
self.downcast::<web_sys::AnimationEvent>()
|
|
self.downcast::<web_sys::AnimationEvent>()
|
|
- .expect("event should be a WebAnimationEvent")
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
impl WebEventExt<web_sys::Event> for dioxus_html::ClipboardData {
|
|
impl WebEventExt<web_sys::Event> for dioxus_html::ClipboardData {
|
|
- fn web_event(&self) -> &web_sys::Event {
|
|
|
|
|
|
+ #[inline(always)]
|
|
|
|
+ fn try_as_web_event(&self) -> Option<&web_sys::Event> {
|
|
self.downcast::<web_sys::Event>()
|
|
self.downcast::<web_sys::Event>()
|
|
- .expect("event should be a web_sys::Event")
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
impl WebEventExt<web_sys::CompositionEvent> for dioxus_html::CompositionData {
|
|
impl WebEventExt<web_sys::CompositionEvent> for dioxus_html::CompositionData {
|
|
- fn web_event(&self) -> &web_sys::CompositionEvent {
|
|
|
|
|
|
+ #[inline(always)]
|
|
|
|
+ fn try_as_web_event(&self) -> Option<&web_sys::CompositionEvent> {
|
|
self.downcast::<web_sys::CompositionEvent>()
|
|
self.downcast::<web_sys::CompositionEvent>()
|
|
- .expect("event should be a WebCompositionEvent")
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
impl WebEventExt<web_sys::MouseEvent> for dioxus_html::DragData {
|
|
impl WebEventExt<web_sys::MouseEvent> for dioxus_html::DragData {
|
|
- fn web_event(&self) -> &web_sys::MouseEvent {
|
|
|
|
- &self
|
|
|
|
- .downcast::<WebDragData>()
|
|
|
|
- .expect("event should be a WebMouseEvent")
|
|
|
|
- .raw
|
|
|
|
|
|
+ #[inline(always)]
|
|
|
|
+ fn try_as_web_event(&self) -> Option<&web_sys::MouseEvent> {
|
|
|
|
+ self.downcast::<WebDragData>().map(|data| &data.raw)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
impl WebEventExt<web_sys::FocusEvent> for dioxus_html::FocusData {
|
|
impl WebEventExt<web_sys::FocusEvent> for dioxus_html::FocusData {
|
|
- fn web_event(&self) -> &web_sys::FocusEvent {
|
|
|
|
|
|
+ #[inline(always)]
|
|
|
|
+ fn try_as_web_event(&self) -> Option<&web_sys::FocusEvent> {
|
|
self.downcast::<web_sys::FocusEvent>()
|
|
self.downcast::<web_sys::FocusEvent>()
|
|
- .expect("event should be a WebFocusEvent")
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
impl WebEventExt<web_sys::Event> for dioxus_html::FormData {
|
|
impl WebEventExt<web_sys::Event> for dioxus_html::FormData {
|
|
- fn web_event(&self) -> &web_sys::Event {
|
|
|
|
|
|
+ #[inline(always)]
|
|
|
|
+ fn try_as_web_event(&self) -> Option<&web_sys::Event> {
|
|
self.downcast::<web_sys::Event>()
|
|
self.downcast::<web_sys::Event>()
|
|
- .expect("event should be a WebFormData")
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
impl WebEventExt<WebImageEvent> for dioxus_html::ImageData {
|
|
impl WebEventExt<WebImageEvent> for dioxus_html::ImageData {
|
|
- fn web_event(&self) -> &WebImageEvent {
|
|
|
|
|
|
+ #[inline(always)]
|
|
|
|
+ fn try_as_web_event(&self) -> Option<&WebImageEvent> {
|
|
self.downcast::<WebImageEvent>()
|
|
self.downcast::<WebImageEvent>()
|
|
- .expect("event should be a WebImageEvent")
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
impl WebEventExt<web_sys::KeyboardEvent> for dioxus_html::KeyboardData {
|
|
impl WebEventExt<web_sys::KeyboardEvent> for dioxus_html::KeyboardData {
|
|
- fn web_event(&self) -> &web_sys::KeyboardEvent {
|
|
|
|
|
|
+ #[inline(always)]
|
|
|
|
+ fn try_as_web_event(&self) -> Option<&web_sys::KeyboardEvent> {
|
|
self.downcast::<web_sys::KeyboardEvent>()
|
|
self.downcast::<web_sys::KeyboardEvent>()
|
|
- .expect("event should be a WebKeyboardEvent")
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
impl WebEventExt<web_sys::Event> for dioxus_html::MediaData {
|
|
impl WebEventExt<web_sys::Event> for dioxus_html::MediaData {
|
|
- fn web_event(&self) -> &web_sys::Event {
|
|
|
|
|
|
+ #[inline(always)]
|
|
|
|
+ fn try_as_web_event(&self) -> Option<&web_sys::Event> {
|
|
self.downcast::<web_sys::Event>()
|
|
self.downcast::<web_sys::Event>()
|
|
- .expect("event should be a WebMediaEvent")
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
impl WebEventExt<web_sys::Element> for MountedData {
|
|
impl WebEventExt<web_sys::Element> for MountedData {
|
|
- fn web_event(&self) -> &web_sys::Element {
|
|
|
|
|
|
+ #[inline(always)]
|
|
|
|
+ fn try_as_web_event(&self) -> Option<&web_sys::Element> {
|
|
self.downcast::<web_sys::Element>()
|
|
self.downcast::<web_sys::Element>()
|
|
- .expect("event should be a web_sys::Element")
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
impl WebEventExt<web_sys::MouseEvent> for dioxus_html::MouseData {
|
|
impl WebEventExt<web_sys::MouseEvent> for dioxus_html::MouseData {
|
|
- fn web_event(&self) -> &web_sys::MouseEvent {
|
|
|
|
|
|
+ #[inline(always)]
|
|
|
|
+ fn try_as_web_event(&self) -> Option<&web_sys::MouseEvent> {
|
|
self.downcast::<web_sys::MouseEvent>()
|
|
self.downcast::<web_sys::MouseEvent>()
|
|
- .expect("event should be a WebMouseEvent")
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
impl WebEventExt<web_sys::PointerEvent> for dioxus_html::PointerData {
|
|
impl WebEventExt<web_sys::PointerEvent> for dioxus_html::PointerData {
|
|
- fn web_event(&self) -> &web_sys::PointerEvent {
|
|
|
|
|
|
+ #[inline(always)]
|
|
|
|
+ fn try_as_web_event(&self) -> Option<&web_sys::PointerEvent> {
|
|
self.downcast::<web_sys::PointerEvent>()
|
|
self.downcast::<web_sys::PointerEvent>()
|
|
- .expect("event should be a WebPointerEvent")
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
impl WebEventExt<web_sys::Event> for ScrollData {
|
|
impl WebEventExt<web_sys::Event> for ScrollData {
|
|
- fn web_event(&self) -> &web_sys::Event {
|
|
|
|
|
|
+ #[inline(always)]
|
|
|
|
+ fn try_as_web_event(&self) -> Option<&web_sys::Event> {
|
|
self.downcast::<web_sys::Event>()
|
|
self.downcast::<web_sys::Event>()
|
|
- .expect("event should be a WebScrollEvent")
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
impl WebEventExt<web_sys::Event> for dioxus_html::SelectionData {
|
|
impl WebEventExt<web_sys::Event> for dioxus_html::SelectionData {
|
|
- fn web_event(&self) -> &web_sys::Event {
|
|
|
|
|
|
+ #[inline(always)]
|
|
|
|
+ fn try_as_web_event(&self) -> Option<&web_sys::Event> {
|
|
self.downcast::<web_sys::Event>()
|
|
self.downcast::<web_sys::Event>()
|
|
- .expect("event should be a WebSelectionEvent")
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
impl WebEventExt<web_sys::Event> for dioxus_html::ToggleData {
|
|
impl WebEventExt<web_sys::Event> for dioxus_html::ToggleData {
|
|
- fn web_event(&self) -> &web_sys::Event {
|
|
|
|
|
|
+ #[inline(always)]
|
|
|
|
+ fn try_as_web_event(&self) -> Option<&web_sys::Event> {
|
|
self.downcast::<web_sys::Event>()
|
|
self.downcast::<web_sys::Event>()
|
|
- .expect("event should be a WebToggleEvent")
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
impl WebEventExt<web_sys::TouchEvent> for dioxus_html::TouchData {
|
|
impl WebEventExt<web_sys::TouchEvent> for dioxus_html::TouchData {
|
|
- fn web_event(&self) -> &web_sys::TouchEvent {
|
|
|
|
|
|
+ #[inline(always)]
|
|
|
|
+ fn try_as_web_event(&self) -> Option<&web_sys::TouchEvent> {
|
|
self.downcast::<web_sys::TouchEvent>()
|
|
self.downcast::<web_sys::TouchEvent>()
|
|
- .expect("event should be a WebTouchEvent")
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
impl WebEventExt<web_sys::TransitionEvent> for dioxus_html::TransitionData {
|
|
impl WebEventExt<web_sys::TransitionEvent> for dioxus_html::TransitionData {
|
|
- fn web_event(&self) -> &web_sys::TransitionEvent {
|
|
|
|
|
|
+ #[inline(always)]
|
|
|
|
+ fn try_as_web_event(&self) -> Option<&web_sys::TransitionEvent> {
|
|
self.downcast::<web_sys::TransitionEvent>()
|
|
self.downcast::<web_sys::TransitionEvent>()
|
|
- .expect("event should be a WebTransitionEvent")
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
impl WebEventExt<web_sys::WheelEvent> for dioxus_html::WheelData {
|
|
impl WebEventExt<web_sys::WheelEvent> for dioxus_html::WheelData {
|
|
- fn web_event(&self) -> &web_sys::WheelEvent {
|
|
|
|
|
|
+ #[inline(always)]
|
|
|
|
+ fn try_as_web_event(&self) -> Option<&web_sys::WheelEvent> {
|
|
self.downcast::<web_sys::WheelEvent>()
|
|
self.downcast::<web_sys::WheelEvent>()
|
|
- .expect("event should be a WebWheelEvent")
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|