Skip to main content

euv_core/event/name/
impl.rs

1use crate::*;
2
3/// Maps each `NativeEventName` variant to its corresponding DOM event string.
4impl NativeEventName {
5    /// Returns the string representation of this event name for DOM binding.
6    ///
7    /// Static variants return `Cow::Borrowed` (zero allocation), while
8    /// `Other` variants return `Cow::Owned` (heap allocation).
9    ///
10    /// # Returns
11    ///
12    /// - `Cow<'static, str>` - The event name as a static or owned string.
13    pub fn as_str(&self) -> Cow<'static, str> {
14        match self {
15            NativeEventName::Click => Cow::Borrowed("click"),
16            NativeEventName::DblClick => Cow::Borrowed("dblclick"),
17            NativeEventName::MouseDown => Cow::Borrowed("mousedown"),
18            NativeEventName::MouseUp => Cow::Borrowed("mouseup"),
19            NativeEventName::MouseMove => Cow::Borrowed("mousemove"),
20            NativeEventName::MouseEnter => Cow::Borrowed("mouseenter"),
21            NativeEventName::MouseLeave => Cow::Borrowed("mouseleave"),
22            NativeEventName::MouseOver => Cow::Borrowed("mouseover"),
23            NativeEventName::MouseOut => Cow::Borrowed("mouseout"),
24            NativeEventName::ContextMenu => Cow::Borrowed("contextmenu"),
25            NativeEventName::Input => Cow::Borrowed("input"),
26            NativeEventName::KeyDown => Cow::Borrowed("keydown"),
27            NativeEventName::KeyUp => Cow::Borrowed("keyup"),
28            NativeEventName::KeyPress => Cow::Borrowed("keypress"),
29            NativeEventName::Focus => Cow::Borrowed("focus"),
30            NativeEventName::Blur => Cow::Borrowed("blur"),
31            NativeEventName::FocusIn => Cow::Borrowed("focusin"),
32            NativeEventName::FocusOut => Cow::Borrowed("focusout"),
33            NativeEventName::Submit => Cow::Borrowed("submit"),
34            NativeEventName::Change => Cow::Borrowed("change"),
35            NativeEventName::Drag => Cow::Borrowed("drag"),
36            NativeEventName::DragStart => Cow::Borrowed("dragstart"),
37            NativeEventName::DragEnd => Cow::Borrowed("dragend"),
38            NativeEventName::DragOver => Cow::Borrowed("dragover"),
39            NativeEventName::DragEnter => Cow::Borrowed("dragenter"),
40            NativeEventName::DragLeave => Cow::Borrowed("dragleave"),
41            NativeEventName::Drop => Cow::Borrowed("drop"),
42            NativeEventName::TouchStart => Cow::Borrowed("touchstart"),
43            NativeEventName::TouchEnd => Cow::Borrowed("touchend"),
44            NativeEventName::TouchMove => Cow::Borrowed("touchmove"),
45            NativeEventName::TouchCancel => Cow::Borrowed("touchcancel"),
46            NativeEventName::Wheel => Cow::Borrowed("wheel"),
47            NativeEventName::Copy => Cow::Borrowed("copy"),
48            NativeEventName::Cut => Cow::Borrowed("cut"),
49            NativeEventName::Paste => Cow::Borrowed("paste"),
50            NativeEventName::Play => Cow::Borrowed("play"),
51            NativeEventName::Pause => Cow::Borrowed("pause"),
52            NativeEventName::Ended => Cow::Borrowed("ended"),
53            NativeEventName::LoadedData => Cow::Borrowed("loadeddata"),
54            NativeEventName::CanPlay => Cow::Borrowed("canplay"),
55            NativeEventName::VolumeChange => Cow::Borrowed("volumechange"),
56            NativeEventName::TimeUpdate => Cow::Borrowed("timeupdate"),
57            NativeEventName::HashChange => Cow::Borrowed("hashchange"),
58            NativeEventName::Resize => Cow::Borrowed("resize"),
59            NativeEventName::Scroll => Cow::Borrowed("scroll"),
60            NativeEventName::Load => Cow::Borrowed("load"),
61            NativeEventName::Unload => Cow::Borrowed("unload"),
62            NativeEventName::BeforeUnload => Cow::Borrowed("beforeunload"),
63            NativeEventName::Error => Cow::Borrowed("error"),
64            NativeEventName::Online => Cow::Borrowed("online"),
65            NativeEventName::Offline => Cow::Borrowed("offline"),
66            NativeEventName::VisibilityChange => Cow::Borrowed("visibilitychange"),
67            NativeEventName::AnimationStart => Cow::Borrowed("animationstart"),
68            NativeEventName::AnimationEnd => Cow::Borrowed("animationend"),
69            NativeEventName::AnimationIteration => Cow::Borrowed("animationiteration"),
70            NativeEventName::TransitionStart => Cow::Borrowed("transitionstart"),
71            NativeEventName::TransitionEnd => Cow::Borrowed("transitionend"),
72            NativeEventName::TransitionRun => Cow::Borrowed("transitionrun"),
73            NativeEventName::EuvSignalUpdate => Cow::Borrowed("__euv_signal_update__"),
74            NativeEventName::Other(name) => Cow::Owned(name.clone()),
75        }
76    }
77}
78
79/// Implements `Display` for `NativeEventName` by delegating to `as_str`.
80impl std::fmt::Display for NativeEventName {
81    /// Formats this event name as a string.
82    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
83        write!(f, "{}", self.as_str())
84    }
85}