script/dom/webxr/
xrsessionevent.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::XRSessionEventBinding::{self, XRSessionEventMethods};
11use crate::dom::bindings::error::Fallible;
12use crate::dom::bindings::inheritance::Castable;
13use crate::dom::bindings::reflector::reflect_dom_object_with_proto;
14use crate::dom::bindings::root::{Dom, DomRoot};
15use crate::dom::bindings::str::DOMString;
16use crate::dom::event::Event;
17use crate::dom::window::Window;
18use crate::dom::xrsession::XRSession;
19use crate::script_runtime::CanGc;
20
21#[dom_struct]
22pub(crate) struct XRSessionEvent {
23 event: Event,
24 session: Dom<XRSession>,
25}
26
27impl XRSessionEvent {
28 #[cfg_attr(crown, allow(crown::unrooted_must_root))]
29 fn new_inherited(session: &XRSession) -> XRSessionEvent {
30 XRSessionEvent {
31 event: Event::new_inherited(),
32 session: Dom::from_ref(session),
33 }
34 }
35
36 pub(crate) fn new(
37 window: &Window,
38 type_: Atom,
39 bubbles: bool,
40 cancelable: bool,
41 session: &XRSession,
42 can_gc: CanGc,
43 ) -> DomRoot<XRSessionEvent> {
44 Self::new_with_proto(window, None, type_, bubbles, cancelable, session, can_gc)
45 }
46
47 fn new_with_proto(
48 window: &Window,
49 proto: Option<HandleObject>,
50 type_: Atom,
51 bubbles: bool,
52 cancelable: bool,
53 session: &XRSession,
54 can_gc: CanGc,
55 ) -> DomRoot<XRSessionEvent> {
56 let trackevent = reflect_dom_object_with_proto(
57 Box::new(XRSessionEvent::new_inherited(session)),
58 window,
59 proto,
60 can_gc,
61 );
62 {
63 let event = trackevent.upcast::<Event>();
64 event.init_event(type_, bubbles, cancelable);
65 }
66 trackevent
67 }
68}
69
70impl XRSessionEventMethods<crate::DomTypeHolder> for XRSessionEvent {
71 fn Constructor(
73 window: &Window,
74 proto: Option<HandleObject>,
75 can_gc: CanGc,
76 type_: DOMString,
77 init: &XRSessionEventBinding::XRSessionEventInit,
78 ) -> Fallible<DomRoot<XRSessionEvent>> {
79 Ok(XRSessionEvent::new_with_proto(
80 window,
81 proto,
82 Atom::from(type_),
83 init.parent.bubbles,
84 init.parent.cancelable,
85 &init.session,
86 can_gc,
87 ))
88 }
89
90 fn Session(&self) -> DomRoot<XRSession> {
92 DomRoot::from_ref(&*self.session)
93 }
94
95 fn IsTrusted(&self) -> bool {
97 self.event.IsTrusted()
98 }
99}