script/dom/webxr/
xrinputsourceevent.rs1use dom_struct::dom_struct;
6use js::rust::HandleObject;
7use stylo_atoms::Atom;
8
9use crate::dom::bindings::codegen::Bindings::EventBinding::Event_Binding::EventMethods;
10use crate::dom::bindings::codegen::Bindings::XRInputSourceEventBinding::{
11 self, XRInputSourceEventMethods,
12};
13use crate::dom::bindings::error::Fallible;
14use crate::dom::bindings::inheritance::Castable;
15use crate::dom::bindings::reflector::reflect_dom_object_with_proto;
16use crate::dom::bindings::root::{Dom, DomRoot};
17use crate::dom::bindings::str::DOMString;
18use crate::dom::event::Event;
19use crate::dom::window::Window;
20use crate::dom::xrframe::XRFrame;
21use crate::dom::xrinputsource::XRInputSource;
22use crate::script_runtime::CanGc;
23
24#[dom_struct]
25pub(crate) struct XRInputSourceEvent {
26 event: Event,
27 frame: Dom<XRFrame>,
28 source: Dom<XRInputSource>,
29}
30
31impl XRInputSourceEvent {
32 fn new_inherited(frame: &XRFrame, source: &XRInputSource) -> XRInputSourceEvent {
33 XRInputSourceEvent {
34 event: Event::new_inherited(),
35 frame: Dom::from_ref(frame),
36 source: Dom::from_ref(source),
37 }
38 }
39
40 pub(crate) fn new(
41 window: &Window,
42 type_: Atom,
43 bubbles: bool,
44 cancelable: bool,
45 frame: &XRFrame,
46 source: &XRInputSource,
47 can_gc: CanGc,
48 ) -> DomRoot<XRInputSourceEvent> {
49 Self::new_with_proto(
50 window, None, type_, bubbles, cancelable, frame, source, can_gc,
51 )
52 }
53
54 #[expect(clippy::too_many_arguments)]
55 fn new_with_proto(
56 window: &Window,
57 proto: Option<HandleObject>,
58 type_: Atom,
59 bubbles: bool,
60 cancelable: bool,
61 frame: &XRFrame,
62 source: &XRInputSource,
63 can_gc: CanGc,
64 ) -> DomRoot<XRInputSourceEvent> {
65 let trackevent = reflect_dom_object_with_proto(
66 Box::new(XRInputSourceEvent::new_inherited(frame, source)),
67 window,
68 proto,
69 can_gc,
70 );
71 {
72 let event = trackevent.upcast::<Event>();
73 event.init_event(type_, bubbles, cancelable);
74 }
75 trackevent
76 }
77}
78
79impl XRInputSourceEventMethods<crate::DomTypeHolder> for XRInputSourceEvent {
80 fn Constructor(
82 window: &Window,
83 proto: Option<HandleObject>,
84 can_gc: CanGc,
85 type_: DOMString,
86 init: &XRInputSourceEventBinding::XRInputSourceEventInit,
87 ) -> Fallible<DomRoot<XRInputSourceEvent>> {
88 Ok(XRInputSourceEvent::new_with_proto(
89 window,
90 proto,
91 Atom::from(type_),
92 init.parent.bubbles,
93 init.parent.cancelable,
94 &init.frame,
95 &init.inputSource,
96 can_gc,
97 ))
98 }
99
100 fn Frame(&self) -> DomRoot<XRFrame> {
102 DomRoot::from_ref(&*self.frame)
103 }
104
105 fn InputSource(&self) -> DomRoot<XRInputSource> {
107 DomRoot::from_ref(&*self.source)
108 }
109
110 fn IsTrusted(&self) -> bool {
112 self.event.IsTrusted()
113 }
114}