events.rs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. macro_rules! impl_event {
  2. (
  3. $data:ty;
  4. $(
  5. $( #[$attr:meta] )*
  6. $name:ident
  7. )*
  8. ) => {
  9. $(
  10. $( #[$attr] )*
  11. #[inline]
  12. pub fn $name<'a, E: crate::EventReturn<T>, T>(_cx: &'a ::dioxus_core::ScopeState, mut _f: impl FnMut(::dioxus_core::Event<$data>) -> E + 'a) -> ::dioxus_core::Attribute<'a> {
  13. ::dioxus_core::Attribute {
  14. name: stringify!($name),
  15. value: _cx.listener(move |e: ::dioxus_core::Event<$data>| {
  16. _f(e).spawn(_cx);
  17. }),
  18. namespace: None,
  19. mounted_element: Default::default(),
  20. volatile: false,
  21. }
  22. }
  23. )*
  24. };
  25. }
  26. mod animation;
  27. mod clipboard;
  28. mod composition;
  29. mod drag;
  30. mod focus;
  31. mod form;
  32. mod image;
  33. mod keyboard;
  34. mod media;
  35. mod mouse;
  36. mod pointer;
  37. mod scroll;
  38. mod selection;
  39. mod toggle;
  40. mod touch;
  41. mod transition;
  42. mod wheel;
  43. pub use animation::*;
  44. pub use clipboard::*;
  45. pub use composition::*;
  46. pub use drag::*;
  47. pub use focus::*;
  48. pub use form::*;
  49. pub use image::*;
  50. pub use keyboard::*;
  51. pub use media::*;
  52. pub use mouse::*;
  53. pub use pointer::*;
  54. pub use scroll::*;
  55. pub use selection::*;
  56. pub use toggle::*;
  57. pub use touch::*;
  58. pub use transition::*;
  59. pub use wheel::*;
  60. pub fn event_bubbles(evt: &str) -> bool {
  61. match evt {
  62. "copy" => true,
  63. "cut" => true,
  64. "paste" => true,
  65. "compositionend" => true,
  66. "compositionstart" => true,
  67. "compositionupdate" => true,
  68. "keydown" => true,
  69. "keypress" => true,
  70. "keyup" => true,
  71. "focus" => false,
  72. "focusout" => true,
  73. "focusin" => true,
  74. "blur" => false,
  75. "change" => true,
  76. "input" => true,
  77. "invalid" => true,
  78. "reset" => true,
  79. "submit" => true,
  80. "click" => true,
  81. "contextmenu" => true,
  82. "doubleclick" => true,
  83. "dblclick" => true,
  84. "drag" => true,
  85. "dragend" => true,
  86. "dragenter" => false,
  87. "dragexit" => false,
  88. "dragleave" => true,
  89. "dragover" => true,
  90. "dragstart" => true,
  91. "drop" => true,
  92. "mousedown" => true,
  93. "mouseenter" => false,
  94. "mouseleave" => false,
  95. "mousemove" => true,
  96. "mouseout" => true,
  97. "scroll" => false,
  98. "mouseover" => true,
  99. "mouseup" => true,
  100. "pointerdown" => true,
  101. "pointermove" => true,
  102. "pointerup" => true,
  103. "pointercancel" => true,
  104. "gotpointercapture" => true,
  105. "lostpointercapture" => true,
  106. "pointerenter" => false,
  107. "pointerleave" => false,
  108. "pointerover" => true,
  109. "pointerout" => true,
  110. "select" => true,
  111. "touchcancel" => true,
  112. "touchend" => true,
  113. "touchmove" => true,
  114. "touchstart" => true,
  115. "wheel" => true,
  116. "abort" => false,
  117. "canplay" => false,
  118. "canplaythrough" => false,
  119. "durationchange" => false,
  120. "emptied" => false,
  121. "encrypted" => true,
  122. "ended" => false,
  123. "error" => false,
  124. "loadeddata" => false,
  125. "loadedmetadata" => false,
  126. "loadstart" => false,
  127. "load" => false,
  128. "pause" => false,
  129. "play" => false,
  130. "playing" => false,
  131. "progress" => false,
  132. "ratechange" => false,
  133. "seeked" => false,
  134. "seeking" => false,
  135. "stalled" => false,
  136. "suspend" => false,
  137. "timeupdate" => false,
  138. "volumechange" => false,
  139. "waiting" => false,
  140. "animationstart" => true,
  141. "animationend" => true,
  142. "animationiteration" => true,
  143. "transitionend" => true,
  144. "toggle" => true,
  145. _ => true,
  146. }
  147. }
  148. use std::future::Future;
  149. #[doc(hidden)]
  150. pub trait EventReturn<P>: Sized {
  151. fn spawn(self, _cx: &dioxus_core::ScopeState) {}
  152. }
  153. impl EventReturn<()> for () {}
  154. #[doc(hidden)]
  155. pub struct AsyncMarker;
  156. impl<T> EventReturn<AsyncMarker> for T
  157. where
  158. T: Future<Output = ()> + 'static,
  159. {
  160. #[inline]
  161. fn spawn(self, cx: &dioxus_core::ScopeState) {
  162. cx.spawn(self);
  163. }
  164. }