@@ -10,11 +10,14 @@ use wasm_bindgen::{JsCast, JsValue};
10
10
use web_sys:: { HtmlCanvasElement , KeyboardEvent , MouseEvent , PointerEvent , WheelEvent } ;
11
11
12
12
bitflags ! {
13
+ // https://www.w3.org/TR/pointerevents3/#the-buttons-property
13
14
#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
14
15
pub struct ButtonsState : u16 {
15
- const LEFT = 0b001 ;
16
- const RIGHT = 0b010 ;
17
- const MIDDLE = 0b100 ;
16
+ const LEFT = 0b00001 ;
17
+ const RIGHT = 0b00010 ;
18
+ const MIDDLE = 0b00100 ;
19
+ const BACK = 0b01000 ;
20
+ const FORWARD = 0b10000 ;
18
21
}
19
22
}
20
23
@@ -24,6 +27,8 @@ impl From<ButtonsState> for MouseButton {
24
27
ButtonsState :: LEFT => MouseButton :: Left ,
25
28
ButtonsState :: RIGHT => MouseButton :: Right ,
26
29
ButtonsState :: MIDDLE => MouseButton :: Middle ,
30
+ ButtonsState :: BACK => MouseButton :: Back ,
31
+ ButtonsState :: FORWARD => MouseButton :: Forward ,
27
32
_ => MouseButton :: Other ( value. bits ( ) ) ,
28
33
}
29
34
}
@@ -35,6 +40,8 @@ impl From<MouseButton> for ButtonsState {
35
40
MouseButton :: Left => ButtonsState :: LEFT ,
36
41
MouseButton :: Right => ButtonsState :: RIGHT ,
37
42
MouseButton :: Middle => ButtonsState :: MIDDLE ,
43
+ MouseButton :: Back => ButtonsState :: BACK ,
44
+ MouseButton :: Forward => ButtonsState :: FORWARD ,
38
45
MouseButton :: Other ( value) => ButtonsState :: from_bits_retain ( value) ,
39
46
}
40
47
}
@@ -45,11 +52,14 @@ pub fn mouse_buttons(event: &MouseEvent) -> ButtonsState {
45
52
}
46
53
47
54
pub fn mouse_button ( event : & MouseEvent ) -> Option < MouseButton > {
55
+ // https://www.w3.org/TR/pointerevents3/#the-button-property
48
56
match event. button ( ) {
49
57
-1 => None ,
50
58
0 => Some ( MouseButton :: Left ) ,
51
59
1 => Some ( MouseButton :: Middle ) ,
52
60
2 => Some ( MouseButton :: Right ) ,
61
+ 3 => Some ( MouseButton :: Back ) ,
62
+ 4 => Some ( MouseButton :: Forward ) ,
53
63
i => Some ( MouseButton :: Other (
54
64
i. try_into ( )
55
65
. expect ( "unexpected negative mouse button value" ) ,
@@ -63,6 +73,8 @@ impl MouseButton {
63
73
MouseButton :: Left => 0 ,
64
74
MouseButton :: Right => 1 ,
65
75
MouseButton :: Middle => 2 ,
76
+ MouseButton :: Back => 3 ,
77
+ MouseButton :: Forward => 4 ,
66
78
MouseButton :: Other ( value) => value. into ( ) ,
67
79
}
68
80
}
0 commit comments