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