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 #[cfg_attr(crown, allow(crown::unrooted_must_root))]
33 fn new_inherited(frame: &XRFrame, source: &XRInputSource) -> XRInputSourceEvent {
34 XRInputSourceEvent {
35 event: Event::new_inherited(),
36 frame: Dom::from_ref(frame),
37 source: Dom::from_ref(source),
38 }
39 }
40
41 pub(crate) fn new(
42 window: &Window,
43 type_: Atom,
44 bubbles: bool,
45 cancelable: bool,
46 frame: &XRFrame,
47 source: &XRInputSource,
48 can_gc: CanGc,
49 ) -> DomRoot<XRInputSourceEvent> {
50 Self::new_with_proto(
51 window, None, type_, bubbles, cancelable, frame, source, can_gc,
52 )
53 }
54
55 #[allow(clippy::too_many_arguments)]
56 fn new_with_proto(
57 window: &Window,
58 proto: Option<HandleObject>,
59 type_: Atom,
60 bubbles: bool,
61 cancelable: bool,
62 frame: &XRFrame,
63 source: &XRInputSource,
64 can_gc: CanGc,
65 ) -> DomRoot<XRInputSourceEvent> {
66 let trackevent = reflect_dom_object_with_proto(
67 Box::new(XRInputSourceEvent::new_inherited(frame, source)),
68 window,
69 proto,
70 can_gc,
71 );
72 {
73 let event = trackevent.upcast::<Event>();
74 event.init_event(type_, bubbles, cancelable);
75 }
76 trackevent
77 }
78}
79
80impl XRInputSourceEventMethods<crate::DomTypeHolder> for XRInputSourceEvent {
81 fn Constructor(
83 window: &Window,
84 proto: Option<HandleObject>,
85 can_gc: CanGc,
86 type_: DOMString,
87 init: &XRInputSourceEventBinding::XRInputSourceEventInit,
88 ) -> Fallible<DomRoot<XRInputSourceEvent>> {
89 Ok(XRInputSourceEvent::new_with_proto(
90 window,
91 proto,
92 Atom::from(type_),
93 init.parent.bubbles,
94 init.parent.cancelable,
95 &init.frame,
96 &init.inputSource,
97 can_gc,
98 ))
99 }
100
101 fn Frame(&self) -> DomRoot<XRFrame> {
103 DomRoot::from_ref(&*self.frame)
104 }
105
106 fn InputSource(&self) -> DomRoot<XRInputSource> {
108 DomRoot::from_ref(&*self.source)
109 }
110
111 fn IsTrusted(&self) -> bool {
113 self.event.IsTrusted()
114 }
115}