web_event/mouse_event/mouse_down/
mod.rs

1use std::fmt::{Debug, Formatter};
2use wasm_bindgen::JsCast;
3use web_sys::{Event, EventTarget, MouseEvent};
4
5/// - Bubbles: Yes
6/// - Cancelable: Yes
7/// - Event type: MouseEvent
8/// - Supported HTML tags: All HTML elements, EXCEPT: `<base>`, `<bdo>`, `<br>`, `<head>`, `<html>`,
9///   `<iframe>`, `<meta>`, `<param>`, `<script>`, `<style>`, and `<title>`.
10#[derive(Clone)]
11pub struct OnMouseDown {
12    inner: MouseEvent,
13}
14
15impl Debug for OnMouseDown {
16    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
17        f.write_str("OnMouseDown")
18    }
19}
20
21impl From<Event> for OnMouseDown {
22    fn from(e: Event) -> Self {
23        let event: MouseEvent = e.unchecked_into();
24        Self { inner: event }
25    }
26}
27
28impl OnMouseDown {
29    /// Getter for the `screenX` field of this object.
30    ///
31    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/screenX)
32    #[inline]
33    pub fn screen_x(&self) -> i32 {
34        self.inner.screen_x()
35    }
36
37    /// Getter for the `screenY` field of this object.
38    ///
39    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/screenY)
40    #[inline]
41    pub fn screen_y(&self) -> i32 {
42        self.inner.screen_y()
43    }
44    /// Getter for the `clientX` field of this object.
45    ///
46    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/clientX)
47    #[inline]
48    pub fn client_x(&self) -> i32 {
49        self.inner.client_x()
50    }
51
52    /// Getter for the `clientY` field of this object.
53    ///
54    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/clientY)
55    #[inline]
56    pub fn client_y(&self) -> i32 {
57        self.inner.client_y()
58    }
59    /// Getter for the `x` field of this object.
60    ///
61    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/x)
62    #[inline]
63    pub fn x(&self) -> i32 {
64        self.inner.x()
65    }
66
67    /// Getter for the `y` field of this object.
68    ///
69    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/y)
70    #[inline]
71    pub fn y(&self) -> i32 {
72        self.inner.y()
73    }
74
75    /// Getter for the `offsetX` field of this object.
76    ///
77    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/offsetX)
78    #[inline]
79    pub fn offset_x(&self) -> i32 {
80        self.inner.offset_x()
81    }
82
83    /// Getter for the `offsetY` field of this object.
84    ///
85    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/offsetY)
86    #[inline]
87    pub fn offset_y(&self) -> i32 {
88        self.inner.offset_y()
89    }
90
91    /// Getter for the `ctrlKey` field of this object.
92    ///
93    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/ctrlKey)
94    #[inline]
95    pub fn ctrl_key(&self) -> bool {
96        self.inner.ctrl_key()
97    }
98
99    /// Getter for the `shiftKey` field of this object.
100    ///
101    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/shiftKey)
102    #[inline]
103    pub fn shift_key(&self) -> bool {
104        self.inner.shift_key()
105    }
106
107    /// Getter for the `altKey` field of this object.
108    ///
109    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/altKey)
110    pub fn alt_key(&self) -> bool {
111        self.inner.alt_key()
112    }
113
114    /// Getter for the `metaKey` field of this object.
115    ///
116    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/metaKey)
117    #[inline]
118    pub fn meta_key(&self) -> bool {
119        self.inner.meta_key()
120    }
121
122    /// Getter for the `button` field of this object.
123    ///
124    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button)
125    #[inline]
126    pub fn button(&self) -> i16 {
127        self.inner.button()
128    }
129
130    /// Getter for the `buttons` field of this object.
131    ///
132    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons)
133    #[inline]
134    pub fn buttons(&self) -> u16 {
135        self.inner.buttons()
136    }
137    /// Getter for the `relatedTarget` field of this object.
138    ///
139    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/relatedTarget)
140    #[inline]
141    pub fn related_target(&self) -> Option<EventTarget> {
142        self.inner.related_target()
143    }
144
145    /// Getter for the `region` field of this object.
146    ///
147    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/region)
148    #[inline]
149    pub fn region(&self) -> Option<String> {
150        self.inner.region()
151    }
152
153    /// Getter for the `movementX` field of this object.
154    ///
155    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/movementX)
156    #[inline]
157    pub fn movement_x(&self) -> i32 {
158        self.inner.movement_x()
159    }
160
161    /// Getter for the `movementY` field of this object.
162    ///
163    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/movementY)
164    #[inline]
165    pub fn movement_y(&self) -> i32 {
166        self.inner.movement_y()
167    }
168}