script/dom/
touch.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use dom_struct::dom_struct;
6
7use crate::dom::bindings::codegen::Bindings::TouchBinding::TouchMethods;
8use crate::dom::bindings::num::Finite;
9use crate::dom::bindings::reflector::{Reflector, reflect_dom_object};
10use crate::dom::bindings::root::{DomRoot, MutDom};
11use crate::dom::eventtarget::EventTarget;
12use crate::dom::window::Window;
13use crate::script_runtime::CanGc;
14
15#[dom_struct]
16pub(crate) struct Touch {
17    reflector_: Reflector,
18    identifier: i32,
19    target: MutDom<EventTarget>,
20    screen_x: f64,
21    screen_y: f64,
22    client_x: f64,
23    client_y: f64,
24    page_x: f64,
25    page_y: f64,
26}
27
28impl Touch {
29    #[allow(clippy::too_many_arguments)]
30    fn new_inherited(
31        identifier: i32,
32        target: &EventTarget,
33        screen_x: Finite<f64>,
34        screen_y: Finite<f64>,
35        client_x: Finite<f64>,
36        client_y: Finite<f64>,
37        page_x: Finite<f64>,
38        page_y: Finite<f64>,
39    ) -> Touch {
40        Touch {
41            reflector_: Reflector::new(),
42            identifier,
43            target: MutDom::new(target),
44            screen_x: *screen_x,
45            screen_y: *screen_y,
46            client_x: *client_x,
47            client_y: *client_y,
48            page_x: *page_x,
49            page_y: *page_y,
50        }
51    }
52
53    #[allow(clippy::too_many_arguments)]
54    pub(crate) fn new(
55        window: &Window,
56        identifier: i32,
57        target: &EventTarget,
58        screen_x: Finite<f64>,
59        screen_y: Finite<f64>,
60        client_x: Finite<f64>,
61        client_y: Finite<f64>,
62        page_x: Finite<f64>,
63        page_y: Finite<f64>,
64        can_gc: CanGc,
65    ) -> DomRoot<Touch> {
66        reflect_dom_object(
67            Box::new(Touch::new_inherited(
68                identifier, target, screen_x, screen_y, client_x, client_y, page_x, page_y,
69            )),
70            window,
71            can_gc,
72        )
73    }
74}
75
76impl TouchMethods<crate::DomTypeHolder> for Touch {
77    /// <https://w3c.github.io/touch-events/#widl-Touch-identifier>
78    fn Identifier(&self) -> i32 {
79        self.identifier
80    }
81
82    /// <https://w3c.github.io/touch-events/#widl-Touch-target>
83    fn Target(&self) -> DomRoot<EventTarget> {
84        self.target.get()
85    }
86
87    /// <https://w3c.github.io/touch-events/#widl-Touch-screenX>
88    fn ScreenX(&self) -> Finite<f64> {
89        Finite::wrap(self.screen_x)
90    }
91
92    /// <https://w3c.github.io/touch-events/#widl-Touch-screenY>
93    fn ScreenY(&self) -> Finite<f64> {
94        Finite::wrap(self.screen_y)
95    }
96
97    /// <https://w3c.github.io/touch-events/#widl-Touch-clientX>
98    fn ClientX(&self) -> Finite<f64> {
99        Finite::wrap(self.client_x)
100    }
101
102    /// <https://w3c.github.io/touch-events/#widl-Touch-clientY>
103    fn ClientY(&self) -> Finite<f64> {
104        Finite::wrap(self.client_y)
105    }
106
107    /// <https://w3c.github.io/touch-events/#widl-Touch-clientX>
108    fn PageX(&self) -> Finite<f64> {
109        Finite::wrap(self.page_x)
110    }
111
112    /// <https://w3c.github.io/touch-events/#widl-Touch-clientY>
113    fn PageY(&self) -> Finite<f64> {
114        Finite::wrap(self.page_y)
115    }
116}