Skip to main content

script/dom/webxr/
xrhittestsource.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use dom_struct::dom_struct;
6use js::context::JSContext;
7use script_bindings::reflector::{Reflector, reflect_dom_object_with_cx};
8use webxr_api::HitTestId;
9
10use crate::dom::bindings::codegen::Bindings::XRHitTestSourceBinding::XRHitTestSourceMethods;
11use crate::dom::bindings::root::{Dom, DomRoot};
12use crate::dom::window::Window;
13use crate::dom::xrsession::XRSession;
14
15#[dom_struct]
16pub(crate) struct XRHitTestSource {
17    reflector_: Reflector,
18    #[no_trace]
19    id: HitTestId,
20    session: Dom<XRSession>,
21}
22
23impl XRHitTestSource {
24    fn new_inherited(id: HitTestId, session: &XRSession) -> XRHitTestSource {
25        XRHitTestSource {
26            reflector_: Reflector::new(),
27            id,
28            session: Dom::from_ref(session),
29        }
30    }
31
32    pub(crate) fn new(
33        cx: &mut JSContext,
34        window: &Window,
35        id: HitTestId,
36        session: &XRSession,
37    ) -> DomRoot<XRHitTestSource> {
38        reflect_dom_object_with_cx(
39            Box::new(XRHitTestSource::new_inherited(id, session)),
40            window,
41            cx,
42        )
43    }
44
45    pub(crate) fn id(&self) -> HitTestId {
46        self.id
47    }
48}
49
50impl XRHitTestSourceMethods<crate::DomTypeHolder> for XRHitTestSource {
51    /// <https://immersive-web.github.io/hit-test/#dom-xrhittestsource-cancel>
52    fn Cancel(&self) {
53        self.session.with_session(|s| s.cancel_hit_test(self.id));
54    }
55}