diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs index cefc930af0a..02a668f08e0 100644 --- a/components/script/dom/bindings/trace.rs +++ b/components/script/dom/bindings/trace.rs @@ -158,6 +158,7 @@ use webgpu::{ }; use webrender_api::{DocumentId, ImageKey}; use webxr_api::SwapChainId as WebXRSwapChainId; +use webxr_api::Ray; unsafe_no_jsmanaged_fields!(Tm); @@ -750,6 +751,13 @@ unsafe impl JSTraceable for euclid::Rect { } } +unsafe impl JSTraceable for Ray { + #[inline] + unsafe fn trace(&self, _trc: *mut JSTracer) { + // Do nothing + } +} + unsafe impl JSTraceable for StyleLocked { unsafe fn trace(&self, _trc: *mut JSTracer) { // Do nothing. diff --git a/components/script/dom/mod.rs b/components/script/dom/mod.rs index 9ae4274a194..330f083397b 100644 --- a/components/script/dom/mod.rs +++ b/components/script/dom/mod.rs @@ -579,6 +579,7 @@ pub mod xrinputsourceschangeevent; pub mod xrlayer; pub mod xrmediabinding; pub mod xrpose; +pub mod xrray; pub mod xrreferencespace; pub mod xrrenderstate; pub mod xrrigidtransform; diff --git a/components/script/dom/webidls/XRRay.webidl b/components/script/dom/webidls/XRRay.webidl new file mode 100644 index 00000000000..74b45e5bab8 --- /dev/null +++ b/components/script/dom/webidls/XRRay.webidl @@ -0,0 +1,14 @@ +/* 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/. */ + +// https://immersive-web.github.io/hit-test/#xrray-interface + +[SecureContext, Exposed=Window, Pref="dom.webxr.enabled"] +interface XRRay { + // constructor(optional DOMPointInit origin, optional DOMPointInit direction); + // constructor(XRRigidTransform transform); + // [SameObject] readonly attribute DOMPointReadOnly origin; + // [SameObject] readonly attribute DOMPointReadOnly direction; + // [SameObject] readonly attribute Float32Array matrix; +}; diff --git a/components/script/dom/xrray.rs b/components/script/dom/xrray.rs new file mode 100644 index 00000000000..f850e00e906 --- /dev/null +++ b/components/script/dom/xrray.rs @@ -0,0 +1,29 @@ +/* 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 crate::dom::bindings::reflector::{reflect_dom_object, Reflector}; +use crate::dom::bindings::root::DomRoot; +use crate::dom::globalscope::GlobalScope; +use dom_struct::dom_struct; +use webxr_api::{ApiSpace, Ray}; + +#[dom_struct] +pub struct XRRay { + reflector_: Reflector, + #[ignore_malloc_size_of = "defined in webxr"] + ray: Ray, +} + +impl XRRay { + fn new_inherited(ray: Ray) -> XRRay { + XRRay { + reflector_: Reflector::new(), + ray, + } + } + + pub fn new(global: &GlobalScope, ray: Ray) -> DomRoot { + reflect_dom_object(Box::new(XRRay::new_inherited(ray)), global) + } +}