Rewild Your Web
web
browser
dweb
1--- original
2+++ modified
3@@ -59,6 +59,17 @@
4 pub id: InputEventId,
5 }
6
7+impl InputEventAndId {
8+ /// Scale the event's point coordinates by the given factor (divides by scale).
9+ /// Used for converting coordinates to account for page zoom in embedded webviews.
10+ pub fn scale_point_by(self, scale: f32) -> Self {
11+ Self {
12+ event: self.event.scale_point_by(scale),
13+ id: self.id,
14+ }
15+ }
16+}
17+
18 impl From<InputEvent> for InputEventAndId {
19 fn from(event: InputEvent) -> Self {
20 Self {
21@@ -92,6 +103,31 @@
22 InputEvent::Scroll(..) => None,
23 }
24 }
25+
26+ /// Scale the point coordinates by the given factor (divides by scale).
27+ /// Used for converting coordinates to account for page zoom in embedded webviews.
28+ pub fn scale_point_by(self, scale: f32) -> Self {
29+ match self {
30+ InputEvent::MouseButton(mut event) => {
31+ event.point = event.point.scale_by(scale);
32+ InputEvent::MouseButton(event)
33+ },
34+ InputEvent::MouseMove(mut event) => {
35+ event.point = event.point.scale_by(scale);
36+ InputEvent::MouseMove(event)
37+ },
38+ InputEvent::Touch(mut event) => {
39+ event.point = event.point.scale_by(scale);
40+ InputEvent::Touch(event)
41+ },
42+ InputEvent::Wheel(mut event) => {
43+ event.point = event.point.scale_by(scale);
44+ InputEvent::Wheel(event)
45+ },
46+ // Events without coordinates pass through unchanged
47+ other => other,
48+ }
49+ }
50 }
51
52 #[derive(Clone, Debug, Default, Deserialize, Serialize)]
53@@ -226,7 +262,7 @@
54 }
55
56 /// The type of input represented by a multi-touch event.
57-#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
58+#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
59 pub enum TouchEventType {
60 /// A new touch point came in contact with the screen.
61 Down,