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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use std::cell::Cell;
use std::default::Default;
use std::f64::consts::PI;
use dom_struct::dom_struct;
use euclid::Point2D;
use js::rust::HandleObject;
use keyboard_types::Modifiers;
use script_bindings::codegen::GenericBindings::WindowBinding::WindowMethods;
use script_bindings::match_domstring_ascii;
use script_traits::ConstellationInputEvent;
use style::Atom;
use style_traits::CSSPixel;
use crate::dom::bindings::codegen::Bindings::EventBinding::Event_Binding::EventMethods;
use crate::dom::bindings::codegen::Bindings::MouseEventBinding;
use crate::dom::bindings::codegen::Bindings::MouseEventBinding::MouseEventMethods;
use crate::dom::bindings::codegen::Bindings::UIEventBinding::UIEventMethods;
use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::reflector::{DomGlobal, reflect_dom_object_with_proto};
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::document::FireMouseEventType;
use crate::dom::event::{Event, EventBubbles, EventCancelable};
use crate::dom::eventtarget::EventTarget;
use crate::dom::inputevent::HitTestResult;
use crate::dom::node::Node;
use crate::dom::pointerevent::{PointerEvent, PointerId};
use crate::dom::uievent::UIEvent;
use crate::dom::window::Window;
use crate::script_runtime::CanGc;
/// <https://w3c.github.io/uievents/#interface-mouseevent>
#[dom_struct]
pub(crate) struct MouseEvent {
uievent: UIEvent,
/// The point on the screen of where this [`MouseEvent`] was originally triggered,
/// to use during the dispatch phase.
///
/// See:
/// <https://w3c.github.io/uievents/#dom-mouseevent-screenx>
/// <https://w3c.github.io/uievents/#dom-mouseevent-screeny>
#[no_trace]
screen_point: Cell<Point2D<i32, CSSPixel>>,
/// The point in the viewport of where this [`MouseEvent`] was originally triggered,
/// to use during the dispatch phase.
///
/// See:
/// <https://w3c.github.io/uievents/#dom-mouseevent-clientx>
/// <https://w3c.github.io/uievents/#dom-mouseevent-clienty>
#[no_trace]
client_point: Cell<Point2D<i32, CSSPixel>>,
/// The point in the initial containing block of where this [`MouseEvent`] was
/// originally triggered to use during the dispatch phase.
///
/// See:
/// <https://w3c.github.io/uievents/#dom-mouseevent-pagex>
/// <https://w3c.github.io/uievents/#dom-mouseevent-pagey>
#[no_trace]
page_point: Cell<Point2D<i32, CSSPixel>>,
/// The keyboard modifiers that were active when this mouse event was triggered.
#[no_trace]
modifiers: Cell<Modifiers>,
/// <https://w3c.github.io/uievents/#dom-mouseevent-button>
button: Cell<i16>,
/// <https://w3c.github.io/uievents/#dom-mouseevent-buttons>
buttons: Cell<u16>,
#[no_trace]
point_in_target: Cell<Option<Point2D<f32, CSSPixel>>>,
}
impl MouseEvent {
pub(crate) fn new_inherited() -> MouseEvent {
MouseEvent {
uievent: UIEvent::new_inherited(),
screen_point: Cell::new(Default::default()),
client_point: Cell::new(Default::default()),
page_point: Cell::new(Default::default()),
modifiers: Cell::new(Modifiers::empty()),
button: Cell::new(0),
buttons: Cell::new(0),
point_in_target: Cell::new(None),
}
}
pub(crate) fn new_uninitialized(window: &Window, can_gc: CanGc) -> DomRoot<MouseEvent> {
Self::new_uninitialized_with_proto(window, None, can_gc)
}
fn new_uninitialized_with_proto(
window: &Window,
proto: Option<HandleObject>,
can_gc: CanGc,
) -> DomRoot<MouseEvent> {
reflect_dom_object_with_proto(Box::new(MouseEvent::new_inherited()), window, proto, can_gc)
}
#[allow(clippy::too_many_arguments)]
pub(crate) fn new(
window: &Window,
event_type: Atom,
can_bubble: EventBubbles,
cancelable: EventCancelable,
view: Option<&Window>,
detail: i32,
screen_point: Point2D<i32, CSSPixel>,
client_point: Point2D<i32, CSSPixel>,
page_point: Point2D<i32, CSSPixel>,
modifiers: Modifiers,
button: i16,
buttons: u16,
related_target: Option<&EventTarget>,
point_in_target: Option<Point2D<f32, CSSPixel>>,
can_gc: CanGc,
) -> DomRoot<MouseEvent> {
Self::new_with_proto(
window,
None,
event_type,
can_bubble,
cancelable,
view,
detail,
screen_point,
client_point,
page_point,
modifiers,
button,
buttons,
related_target,
point_in_target,
can_gc,
)
}
#[allow(clippy::too_many_arguments)]
fn new_with_proto(
window: &Window,
proto: Option<HandleObject>,
event_type: Atom,
can_bubble: EventBubbles,
cancelable: EventCancelable,
view: Option<&Window>,
detail: i32,
screen_point: Point2D<i32, CSSPixel>,
client_point: Point2D<i32, CSSPixel>,
page_point: Point2D<i32, CSSPixel>,
modifiers: Modifiers,
button: i16,
buttons: u16,
related_target: Option<&EventTarget>,
point_in_target: Option<Point2D<f32, CSSPixel>>,
can_gc: CanGc,
) -> DomRoot<MouseEvent> {
let ev = MouseEvent::new_uninitialized_with_proto(window, proto, can_gc);
ev.initialize_mouse_event(
event_type,
can_bubble,
cancelable,
view,
detail,
screen_point,
client_point,
page_point,
modifiers,
button,
buttons,
related_target,
point_in_target,
);
ev
}
/// <https://w3c.github.io/uievents/#initialize-a-mouseevent>
#[expect(clippy::too_many_arguments)]
pub(crate) fn initialize_mouse_event(
&self,
event_type: Atom,
can_bubble: EventBubbles,
cancelable: EventCancelable,
view: Option<&Window>,
detail: i32,
screen_point: Point2D<i32, CSSPixel>,
client_point: Point2D<i32, CSSPixel>,
page_point: Point2D<i32, CSSPixel>,
modifiers: Modifiers,
button: i16,
buttons: u16,
related_target: Option<&EventTarget>,
point_in_target: Option<Point2D<f32, CSSPixel>>,
) {
self.uievent.initialize_ui_event(
event_type,
view.map(|window| window.upcast::<EventTarget>()),
can_bubble,
cancelable,
);
self.uievent.set_detail(detail);
self.screen_point.set(screen_point);
self.client_point.set(client_point);
self.page_point.set(page_point);
self.modifiers.set(modifiers);
self.button.set(button);
self.buttons.set(buttons);
self.upcast::<Event>().set_related_target(related_target);
self.point_in_target.set(point_in_target);
// Legacy mapping per spec: left/middle/right => 1/2/3 (button + 1), else 0.
let w = if button >= 0 { (button as u32) + 1 } else { 0 };
self.uievent.set_which(w);
}
pub(crate) fn new_for_platform_motion_event(
window: &Window,
event_name: FireMouseEventType,
hit_test_result: &HitTestResult,
input_event: &ConstellationInputEvent,
can_gc: CanGc,
) -> DomRoot<Self> {
// These values come from the event tables in
// <https://w3c.github.io/uievents/#events-mouse-types>.
let (bubbles, cancelable, composed) = match event_name {
FireMouseEventType::Move | FireMouseEventType::Over | FireMouseEventType::Out => {
(EventBubbles::Bubbles, EventCancelable::Cancelable, true)
},
FireMouseEventType::Enter | FireMouseEventType::Leave => (
EventBubbles::DoesNotBubble,
EventCancelable::NotCancelable,
false,
),
};
let mouse_event = Self::new(
window,
Atom::from(event_name.as_str()),
bubbles,
cancelable,
Some(window),
0i32,
hit_test_result.point_in_frame.to_i32(),
hit_test_result.point_in_frame.to_i32(),
hit_test_result
.point_relative_to_initial_containing_block
.to_i32(),
input_event.active_keyboard_modifiers,
0i16,
input_event.pressed_mouse_buttons,
None,
None,
can_gc,
);
let event = mouse_event.upcast::<Event>();
event.set_composed(composed);
event.set_trusted(true);
mouse_event
}
/// Create a [MouseEvent] triggered by the embedder
/// <https://w3c.github.io/uievents/#create-a-cancelable-mouseevent-id>
#[expect(clippy::too_many_arguments)]
pub(crate) fn for_platform_button_event(
event_type: Atom,
event: embedder_traits::MouseButtonEvent,
pressed_mouse_buttons: u16,
window: &Window,
hit_test_result: &HitTestResult,
modifiers: Modifiers,
click_count: usize,
can_gc: CanGc,
) -> DomRoot<Self> {
let client_point = hit_test_result.point_in_frame.to_i32();
let page_point = hit_test_result
.point_relative_to_initial_containing_block
.to_i32();
let mouse_event = Self::new(
window,
event_type,
EventBubbles::Bubbles,
EventCancelable::Cancelable,
Some(window),
click_count as i32,
client_point, // TODO: Get real screen coordinates?
client_point,
page_point,
modifiers,
event.button.into(),
pressed_mouse_buttons,
None,
Some(hit_test_result.point_in_node),
can_gc,
);
mouse_event.upcast::<Event>().set_trusted(true);
mouse_event.upcast::<Event>().set_composed(true);
mouse_event
}
pub(crate) fn point_in_viewport(&self) -> Option<Point2D<f32, CSSPixel>> {
Some(self.client_point.get().to_f32())
}
/// Create a PointerEvent from this MouseEvent.
/// <https://w3c.github.io/pointerevents/#the-primary-pointer>
/// For mouse, the pointer ID is always -1, and is_primary is always true.
pub(crate) fn to_pointer_event(
&self,
event_type: Atom,
can_gc: CanGc,
) -> DomRoot<crate::dom::pointerevent::PointerEvent> {
// TODO: This function should almost certainly accept an enumn for the event type.
let is_pointer_down = &*event_type == "pointerdown";
let is_pointer_move = &*event_type == "pointermove";
let is_pointer_up = &*event_type == "pointerup";
// Pressure is 0.5 when button is down, 0.0 when up
let pressure = if is_pointer_down || (is_pointer_move && self.Buttons() != 0) {
0.5
} else {
0.0
};
let button = if is_pointer_down || is_pointer_up {
self.Button()
} else {
-1
};
let window = self.global();
let window = window.as_window();
PointerEvent::new(
window,
event_type,
EventBubbles::from(self.upcast::<Event>().Bubbles()),
EventCancelable::from(self.upcast::<Event>().Cancelable()),
self.uievent.GetView().as_deref(),
self.uievent.Detail(),
Point2D::new(self.ScreenX(), self.ScreenY()),
Point2D::new(self.ClientX(), self.ClientY()),
Point2D::new(self.PageX(), self.PageY()),
self.modifiers.get(),
button,
self.Buttons(),
self.GetRelatedTarget().as_deref(),
self.point_in_target.get(),
PointerId::Mouse as i32, // Mouse pointer ID is always -1
1, // width
1, // height
pressure,
0.0, // tangential_pressure
0, // tilt_x
0, // tilt_y
0, // twist
PI / 2.0, // altitude_angle (perpendicular to surface)
0.0, // azimuth_angle
DOMString::from("mouse"),
true, // is_primary (mouse is always primary)
vec![], // coalesced_events
vec![], // predicted_events
can_gc,
)
}
/// Create a PointerEvent for hover events (pointerover, pointerenter, pointerout, pointerleave).
/// <https://w3c.github.io/pointerevents/#the-primary-pointer>
/// For mouse, the pointer ID is always -1, and is_primary is always true.
pub(crate) fn to_pointer_hover_event(
&self,
event_type: &str,
can_gc: CanGc,
) -> DomRoot<crate::dom::pointerevent::PointerEvent> {
// Determine bubbles and cancelable based on event type
// pointerover/pointerout bubble and are cancelable
// pointerenter/pointerleave do not bubble and are not cancelable
let (bubbles, cancelable) = match event_type {
"pointerover" | "pointerout" => (EventBubbles::Bubbles, EventCancelable::Cancelable),
"pointerenter" | "pointerleave" => {
(EventBubbles::DoesNotBubble, EventCancelable::NotCancelable)
},
_ => (EventBubbles::Bubbles, EventCancelable::Cancelable),
};
let window = self.global();
let window = window.as_window();
let pointer_event = PointerEvent::new(
window,
event_type.into(),
bubbles,
cancelable,
self.uievent.GetView().as_deref(),
self.uievent.Detail(),
Point2D::new(self.ScreenX(), self.ScreenY()),
Point2D::new(self.ClientX(), self.ClientY()),
Point2D::new(self.PageX(), self.PageY()),
self.modifiers.get(),
-1, // button: -1 for hover events (no button pressed)
self.Buttons(),
self.GetRelatedTarget().as_deref(),
self.point_in_target.get(),
PointerId::Mouse as i32, // Mouse pointer ID is always -1
1, // width
1, // height
0.0, // pressure: 0.0 for hover events
0.0, // tangential_pressure
0, // tilt_x
0, // tilt_y
0, // twist
PI / 2.0, // altitude_angle (perpendicular to surface)
0.0, // azimuth_angle
DOMString::from("mouse"),
true, // is_primary (mouse is always primary)
vec![], // coalesced_events
vec![], // predicted_events
can_gc,
);
// Set trusted to match the source mouse event
pointer_event
.upcast::<Event>()
.set_trusted(self.IsTrusted());
pointer_event
}
}
impl MouseEventMethods<crate::DomTypeHolder> for MouseEvent {
/// <https://w3c.github.io/uievents/#dom-mouseevent-mouseevent>
fn Constructor(
window: &Window,
proto: Option<HandleObject>,
can_gc: CanGc,
event_type: DOMString,
init: &MouseEventBinding::MouseEventInit,
) -> Fallible<DomRoot<MouseEvent>> {
let bubbles = EventBubbles::from(init.parent.parent.parent.bubbles);
let cancelable = EventCancelable::from(init.parent.parent.parent.cancelable);
let scroll_offset = window.scroll_offset();
let page_point = Point2D::new(
scroll_offset.x as i32 + init.clientX,
scroll_offset.y as i32 + init.clientY,
);
let event = MouseEvent::new_with_proto(
window,
proto,
event_type.into(),
bubbles,
cancelable,
init.parent.parent.view.as_deref(),
init.parent.parent.detail,
Point2D::new(init.screenX, init.screenY),
Point2D::new(init.clientX, init.clientY),
page_point,
init.parent.modifiers(),
init.button,
init.buttons,
init.relatedTarget.as_deref(),
None,
can_gc,
);
event
.upcast::<Event>()
.set_composed(init.parent.parent.parent.composed);
Ok(event)
}
/// <https://w3c.github.io/uievents/#widl-MouseEvent-screenX>
fn ScreenX(&self) -> i32 {
self.screen_point.get().x
}
/// <https://w3c.github.io/uievents/#widl-MouseEvent-screenY>
fn ScreenY(&self) -> i32 {
self.screen_point.get().y
}
/// <https://w3c.github.io/uievents/#widl-MouseEvent-clientX>
fn ClientX(&self) -> i32 {
self.client_point.get().x
}
/// <https://w3c.github.io/uievents/#widl-MouseEvent-clientY>
fn ClientY(&self) -> i32 {
self.client_point.get().y
}
/// <https://drafts.csswg.org/cssom-view/#dom-mouseevent-pagex>
fn PageX(&self) -> i32 {
// The pageX attribute must follow these steps:
// > 1. If the event’s dispatch flag is set, return the horizontal coordinate of the
// > position where the event occurred relative to the origin of the initial containing
// > block and terminate these steps.
if self.upcast::<Event>().dispatching() {
return self.page_point.get().x;
}
// > 2. Let offset be the value of the scrollX attribute of the event’s associated
// > Window object, if there is one, or zero otherwise.
// > 3. Return the sum of offset and the value of the event’s clientX attribute.
self.global().as_window().ScrollX() + self.ClientX()
}
/// <https://drafts.csswg.org/cssom-view/#dom-mouseevent-pagey>
fn PageY(&self) -> i32 {
// The pageY attribute must follow these steps:
// > 1. If the event’s dispatch flag is set, return the vertical coordinate of the
// > position where the event occurred relative to the origin of the initial
// > containing block and terminate these steps.
if self.upcast::<Event>().dispatching() {
return self.page_point.get().y;
}
// > 2. Let offset be the value of the scrollY attribute of the event’s associated
// > Window object, if there is one, or zero otherwise.
// > 3. Return the sum of offset and the value of the event’s clientY attribute.
self.global().as_window().ScrollY() + self.ClientY()
}
/// <https://drafts.csswg.org/cssom-view/#dom-mouseevent-x>
fn X(&self) -> i32 {
self.ClientX()
}
/// <https://drafts.csswg.org/cssom-view/#dom-mouseevent-y>
fn Y(&self) -> i32 {
self.ClientY()
}
/// <https://drafts.csswg.org/cssom-view/#dom-mouseevent-offsetx>
fn OffsetX(&self) -> i32 {
// > The offsetX attribute must follow these steps:
// > 1. If the event’s dispatch flag is set, return the x-coordinate of the position
// > where the event occurred relative to the origin of the padding edge of the
// > target node, ignoring the transforms that apply to the element and its
// > ancestors, and terminate these steps.
let event = self.upcast::<Event>();
if event.dispatching() {
let Some(target) = event.GetTarget() else {
return 0;
};
let Some(node) = target.downcast::<Node>() else {
return 0;
};
return self.ClientX() - node.client_rect().origin.x;
}
// > 2. Return the value of the event’s pageX attribute.
self.PageX()
}
/// <https://drafts.csswg.org/cssom-view/#dom-mouseevent-offsety>
fn OffsetY(&self) -> i32 {
// > The offsetY attribute must follow these steps:
// > 1. If the event’s dispatch flag is set, return the y-coordinate of the
// > position where the event occurred relative to the origin of the padding edge of
// > the target node, ignoring the transforms that apply to the element and its
// > ancestors, and terminate these steps.
let event = self.upcast::<Event>();
if event.dispatching() {
let Some(target) = event.GetTarget() else {
return 0;
};
let Some(node) = target.downcast::<Node>() else {
return 0;
};
return self.ClientY() - node.client_rect().origin.y;
}
// 2. Return the value of the event’s pageY attribute.
self.PageY()
}
/// <https://w3c.github.io/uievents/#dom-mouseevent-ctrlkey>
fn CtrlKey(&self) -> bool {
self.modifiers.get().contains(Modifiers::CONTROL)
}
/// <https://w3c.github.io/uievents/#dom-mouseevent-shiftkey>
fn ShiftKey(&self) -> bool {
self.modifiers.get().contains(Modifiers::SHIFT)
}
/// <https://w3c.github.io/uievents/#dom-mouseevent-altkey>
fn AltKey(&self) -> bool {
self.modifiers.get().contains(Modifiers::ALT)
}
/// <https://w3c.github.io/uievents/#dom-mouseevent-metakey>
fn MetaKey(&self) -> bool {
self.modifiers.get().contains(Modifiers::META)
}
/// <https://w3c.github.io/uievents/#dom-mouseevent-button>
fn Button(&self) -> i16 {
self.button.get()
}
/// <https://w3c.github.io/uievents/#dom-mouseevent-buttons>
fn Buttons(&self) -> u16 {
self.buttons.get()
}
/// <https://w3c.github.io/uievents/#widl-MouseEvent-relatedTarget>
fn GetRelatedTarget(&self) -> Option<DomRoot<EventTarget>> {
self.upcast::<Event>().related_target()
}
/// <https://w3c.github.io/uievents/#widl-MouseEvent-initMouseEvent>
fn InitMouseEvent(
&self,
type_arg: DOMString,
can_bubble_arg: bool,
cancelable_arg: bool,
view_arg: Option<&Window>,
detail_arg: i32,
screen_x_arg: i32,
screen_y_arg: i32,
client_x_arg: i32,
client_y_arg: i32,
ctrl_key_arg: bool,
alt_key_arg: bool,
shift_key_arg: bool,
meta_key_arg: bool,
button_arg: i16,
related_target_arg: Option<&EventTarget>,
) {
if self.upcast::<Event>().dispatching() {
return;
}
self.upcast::<UIEvent>().InitUIEvent(
type_arg,
can_bubble_arg,
cancelable_arg,
view_arg,
detail_arg,
);
self.screen_point
.set(Point2D::new(screen_x_arg, screen_y_arg));
self.client_point
.set(Point2D::new(client_x_arg, client_y_arg));
let global = self.global();
let scroll_offset = global.as_window().scroll_offset();
self.page_point.set(Point2D::new(
scroll_offset.x as i32 + client_x_arg,
scroll_offset.y as i32 + client_y_arg,
));
let mut modifiers = Modifiers::empty();
if ctrl_key_arg {
modifiers.insert(Modifiers::CONTROL);
}
if alt_key_arg {
modifiers.insert(Modifiers::ALT);
}
if shift_key_arg {
modifiers.insert(Modifiers::SHIFT);
}
if meta_key_arg {
modifiers.insert(Modifiers::META);
}
self.modifiers.set(modifiers);
self.button.set(button_arg);
self.upcast::<Event>()
.set_related_target(related_target_arg);
// Keep UIEvent.which in sync for legacy init path too.
let w = if button_arg >= 0 {
(button_arg as u32) + 1
} else {
0
};
self.uievent.set_which(w);
}
/// <https://dom.spec.whatwg.org/#dom-event-istrusted>
fn IsTrusted(&self) -> bool {
self.uievent.IsTrusted()
}
/// <https://w3c.github.io/uievents/#dom-mouseevent-getmodifierstate>
fn GetModifierState(&self, key_arg: DOMString) -> bool {
self.modifiers
.get()
.contains(match_domstring_ascii!(key_arg,
"Alt" => Modifiers::ALT,
"AltGraph" => Modifiers::ALT_GRAPH,
"CapsLock" => Modifiers::CAPS_LOCK,
"Control" => Modifiers::CONTROL,
"Fn" => Modifiers::FN,
"FnLock" => Modifiers::FN_LOCK,
"Meta" => Modifiers::META,
"NumLock" => Modifiers::NUM_LOCK,
"ScrollLock" => Modifiers::SCROLL_LOCK,
"Shift" => Modifiers::SHIFT,
"Symbol" => Modifiers::SYMBOL,
"SymbolLock" => Modifiers::SYMBOL_LOCK,
_ => { return false; },
))
}
}