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)]
9pub enum EventHandler {
10 NoArgs(Rc<RefCell<dyn FnMut()>>),
12 MouseEvent(Rc<RefCell<dyn FnMut(MouseEvent)>>),
14 UnsupportedSignature(EventAttribFn),
17}
18
19#[derive(Clone)]
23pub struct MouseEvent {
24 event: web_sys::MouseEvent,
25 should_propagate: Rc<Cell<bool>>,
26}
27
28impl MouseEvent {
29 pub fn new(event: web_sys::MouseEvent) -> Self {
31 MouseEvent {
32 event,
33 should_propagate: Rc::new(Cell::new(true)),
34 }
35 }
36
37 pub fn stop_propagation(&self) {
39 self.should_propagate.set(false);
40 self.event.stop_propagation();
41 }
42
43 pub fn should_propagate(&self) -> &Rc<Cell<bool>> {
45 &self.should_propagate
46 }
47}
48
49impl Deref for MouseEvent {
50 type Target = web_sys::MouseEvent;
51
52 fn deref(&self) -> &Self::Target {
53 &self.event
54 }
55}
56
57impl PartialEq for EventHandler {
62 fn eq(&self, _other: &Self) -> bool {
63 true
64 }
65}
66
67impl Debug for EventHandler {
68 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
69 f.write_str("event handler")
70 }
71}