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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
use super::*;
/// The Event class.
/// [`Event`](https://developer.mozilla.org/en-US/docs/Web/API/Event)
#[derive(Clone, Debug, PartialEq, PartialOrd)]
#[repr(transparent)]
pub struct Event {
inner: Any,
}
impl FromVal for Event {
fn from_val(v: &Any) -> Self {
Event {
inner: Any::from_val(v),
}
}
fn take_ownership(v: AnyHandle) -> Self {
Self::from_val(&Any::take_ownership(v))
}
fn as_handle(&self) -> AnyHandle {
self.inner.as_handle()
}
}
impl core::ops::Deref for Event {
type Target = Any;
fn deref(&self) -> &Self::Target {
&self.inner
}
}
impl core::ops::DerefMut for Event {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.inner
}
}
impl AsRef<Any> for Event {
fn as_ref(&self) -> &Any {
&self.inner
}
}
impl AsMut<Any> for Event {
fn as_mut(&mut self) -> &mut Any {
&mut self.inner
}
}
impl From<Event> for Any {
fn from(s: Event) -> Any {
let handle = s.inner.as_handle();
core::mem::forget(s);
Any::take_ownership(handle)
}
}
impl From<&Event> for Any {
fn from(s: &Event) -> Any {
s.inner.clone().into()
}
}
jsbind::utils::impl_dyn_cast!(Event);
impl Event {
/// Getter of the `type` attribute.
/// [`Event.type`](https://developer.mozilla.org/en-US/docs/Web/API/Event/type)
pub fn type_(&self) -> JsString {
self.inner.get("type").as_::<JsString>()
}
}
impl Event {
/// Getter of the `target` attribute.
/// [`Event.target`](https://developer.mozilla.org/en-US/docs/Web/API/Event/target)
pub fn target(&self) -> EventTarget {
self.inner.get("target").as_::<EventTarget>()
}
}
impl Event {
/// Getter of the `srcElement` attribute.
/// [`Event.srcElement`](https://developer.mozilla.org/en-US/docs/Web/API/Event/srcElement)
pub fn src_element(&self) -> EventTarget {
self.inner.get("srcElement").as_::<EventTarget>()
}
}
impl Event {
/// Getter of the `currentTarget` attribute.
/// [`Event.currentTarget`](https://developer.mozilla.org/en-US/docs/Web/API/Event/currentTarget)
pub fn current_target(&self) -> EventTarget {
self.inner.get("currentTarget").as_::<EventTarget>()
}
}
impl Event {
/// Getter of the `eventPhase` attribute.
/// [`Event.eventPhase`](https://developer.mozilla.org/en-US/docs/Web/API/Event/eventPhase)
pub fn event_phase(&self) -> u16 {
self.inner.get("eventPhase").as_::<u16>()
}
}
impl Event {
/// Getter of the `cancelBubble` attribute.
/// [`Event.cancelBubble`](https://developer.mozilla.org/en-US/docs/Web/API/Event/cancelBubble)
pub fn cancel_bubble(&self) -> bool {
self.inner.get("cancelBubble").as_::<bool>()
}
/// Setter of the `cancelBubble` attribute.
/// [`Event.cancelBubble`](https://developer.mozilla.org/en-US/docs/Web/API/Event/cancelBubble)
pub fn set_cancel_bubble(&mut self, value: bool) {
self.inner.set("cancelBubble", value);
}
}
impl Event {
/// Getter of the `bubbles` attribute.
/// [`Event.bubbles`](https://developer.mozilla.org/en-US/docs/Web/API/Event/bubbles)
pub fn bubbles(&self) -> bool {
self.inner.get("bubbles").as_::<bool>()
}
}
impl Event {
/// Getter of the `cancelable` attribute.
/// [`Event.cancelable`](https://developer.mozilla.org/en-US/docs/Web/API/Event/cancelable)
pub fn cancelable(&self) -> bool {
self.inner.get("cancelable").as_::<bool>()
}
}
impl Event {
/// Getter of the `returnValue` attribute.
/// [`Event.returnValue`](https://developer.mozilla.org/en-US/docs/Web/API/Event/returnValue)
pub fn return_value(&self) -> bool {
self.inner.get("returnValue").as_::<bool>()
}
/// Setter of the `returnValue` attribute.
/// [`Event.returnValue`](https://developer.mozilla.org/en-US/docs/Web/API/Event/returnValue)
pub fn set_return_value(&mut self, value: bool) {
self.inner.set("returnValue", value);
}
}
impl Event {
/// Getter of the `defaultPrevented` attribute.
/// [`Event.defaultPrevented`](https://developer.mozilla.org/en-US/docs/Web/API/Event/defaultPrevented)
pub fn default_prevented(&self) -> bool {
self.inner.get("defaultPrevented").as_::<bool>()
}
}
impl Event {
/// Getter of the `composed` attribute.
/// [`Event.composed`](https://developer.mozilla.org/en-US/docs/Web/API/Event/composed)
pub fn composed(&self) -> bool {
self.inner.get("composed").as_::<bool>()
}
}
impl Event {
/// Getter of the `isTrusted` attribute.
/// [`Event.isTrusted`](https://developer.mozilla.org/en-US/docs/Web/API/Event/isTrusted)
pub fn is_trusted(&self) -> bool {
self.inner.get("isTrusted").as_::<bool>()
}
}
impl Event {
/// Getter of the `timeStamp` attribute.
/// [`Event.timeStamp`](https://developer.mozilla.org/en-US/docs/Web/API/Event/timeStamp)
pub fn time_stamp(&self) -> Any {
self.inner.get("timeStamp").as_::<Any>()
}
}
impl Event {
/// The `new Event(..)` constructor, creating a new Event instance
pub fn new(type_: &JsString) -> Event {
Self {
inner: Any::global("Event").new(&[type_.into()]).as_::<Any>(),
}
}
}
impl Event {
/// The `new Event(..)` constructor, creating a new Event instance
pub fn new_with_event_init_dict(type_: &JsString, event_init_dict: &EventInit) -> Event {
Self {
inner: Any::global("Event")
.new(&[type_.into(), event_init_dict.into()])
.as_::<Any>(),
}
}
}
impl Event {
/// The composedPath method.
/// [`Event.composedPath`](https://developer.mozilla.org/en-US/docs/Web/API/Event/composedPath)
pub fn composed_path(&self) -> TypedArray<EventTarget> {
self.inner
.call("composedPath", &[])
.as_::<TypedArray<EventTarget>>()
}
}
impl Event {
/// The stopPropagation method.
/// [`Event.stopPropagation`](https://developer.mozilla.org/en-US/docs/Web/API/Event/stopPropagation)
pub fn stop_propagation(&self) -> Undefined {
self.inner.call("stopPropagation", &[]).as_::<Undefined>()
}
}
impl Event {
/// The stopImmediatePropagation method.
/// [`Event.stopImmediatePropagation`](https://developer.mozilla.org/en-US/docs/Web/API/Event/stopImmediatePropagation)
pub fn stop_immediate_propagation(&self) -> Undefined {
self.inner
.call("stopImmediatePropagation", &[])
.as_::<Undefined>()
}
}
impl Event {
/// The preventDefault method.
/// [`Event.preventDefault`](https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
pub fn prevent_default(&self) -> Undefined {
self.inner.call("preventDefault", &[]).as_::<Undefined>()
}
}
impl Event {
/// The initEvent method.
/// [`Event.initEvent`](https://developer.mozilla.org/en-US/docs/Web/API/Event/initEvent)
pub fn init_event(&self, type_: &JsString) -> Undefined {
self.inner
.call("initEvent", &[type_.into()])
.as_::<Undefined>()
}
}
impl Event {
/// The initEvent method.
/// [`Event.initEvent`](https://developer.mozilla.org/en-US/docs/Web/API/Event/initEvent)
pub fn init_event_with_bubbles(&self, type_: &JsString, bubbles: bool) -> Undefined {
self.inner
.call("initEvent", &[type_.into(), bubbles.into()])
.as_::<Undefined>()
}
}
impl Event {
/// The initEvent method.
/// [`Event.initEvent`](https://developer.mozilla.org/en-US/docs/Web/API/Event/initEvent)
pub fn init_event_with_bubbles_and_cancelable(
&self,
type_: &JsString,
bubbles: bool,
cancelable: bool,
) -> Undefined {
self.inner
.call(
"initEvent",
&[type_.into(), bubbles.into(), cancelable.into()],
)
.as_::<Undefined>()
}
}