virtual_node/event/
event_handlers.rs1use crate::EventAttribFn;
2use std::cell::{Cell, RefCell};
3use std::fmt::{Debug, Formatter};
4use std::ops::Deref;
5use std::rc::Rc;
6
7#[derive(Clone)]
13pub enum EventHandler {
14 NoArgs(Rc<RefCell<dyn FnMut()>>),
16 MouseEvent(Rc<RefCell<dyn FnMut(MouseEvent)>>),
18 UnsupportedSignature(EventAttribFn),
21}
22
23#[derive(Clone)]
27pub struct MouseEvent {
28 event: web_sys::MouseEvent,
29 should_propagate: Rc<Cell<bool>>,
30}
31
32impl MouseEvent {
33 pub fn new(event: web_sys::MouseEvent) -> Self {
35 MouseEvent {
36 event,
37 should_propagate: Rc::new(Cell::new(true)),
38 }
39 }
40
41 pub fn stop_propagation(&self) {
43 self.should_propagate.set(false);
44 self.event.stop_propagation();
45 }
46
47 pub fn should_propagate(&self) -> &Rc<Cell<bool>> {
49 &self.should_propagate
50 }
51}
52
53impl Deref for MouseEvent {
54 type Target = web_sys::MouseEvent;
55
56 fn deref(&self) -> &Self::Target {
57 &self.event
58 }
59}
60
61impl PartialEq for EventHandler {
66 fn eq(&self, _other: &Self) -> bool {
67 true
68 }
69}
70
71impl Debug for EventHandler {
72 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
73 f.write_str("event handler")
74 }
75}