diff options
author | Manish Goregaokar <manishsmail@gmail.com> | 2019-03-15 10:11:05 -0700 |
---|---|---|
committer | Manish Goregaokar <manishsmail@gmail.com> | 2019-03-18 16:27:59 -0700 |
commit | 191fcf66cc59ef91eaf016b38188819d41b67259 (patch) | |
tree | bf8594262c8de289eccffdbcf0df56cf9c3eb5e9 | |
parent | f2a6164a52bfa789c123e0fe6b94285688804c29 (diff) | |
download | servo-191fcf66cc59ef91eaf016b38188819d41b67259.tar.gz servo-191fcf66cc59ef91eaf016b38188819d41b67259.zip |
Add requestReferenceSpace
-rw-r--r-- | components/script/dom/webidls/XRReferenceSpace.webidl | 10 | ||||
-rw-r--r-- | components/script/dom/webidls/XRSession.webidl | 15 | ||||
-rw-r--r-- | components/script/dom/webidls/XRStationaryReferenceSpace.webidl | 4 | ||||
-rw-r--r-- | components/script/dom/xrsession.rs | 41 | ||||
-rw-r--r-- | components/script/dom/xrstationaryreferencespace.rs | 12 |
5 files changed, 64 insertions, 18 deletions
diff --git a/components/script/dom/webidls/XRReferenceSpace.webidl b/components/script/dom/webidls/XRReferenceSpace.webidl index 378a4e520ee..43236ea338c 100644 --- a/components/script/dom/webidls/XRReferenceSpace.webidl +++ b/components/script/dom/webidls/XRReferenceSpace.webidl @@ -4,16 +4,6 @@ // https://immersive-web.github.io/webxr/#xrreferencespace-interface -enum XRReferenceSpaceType { - "stationary", - "bounded", - "unbounded" -}; - -dictionary XRReferenceSpaceOptions { - required XRReferenceSpaceType type; -}; - [SecureContext, Exposed=Window, Pref="dom.webxr.enabled"] interface XRReferenceSpace : XRSpace { attribute XRRigidTransform originOffset; diff --git a/components/script/dom/webidls/XRSession.webidl b/components/script/dom/webidls/XRSession.webidl index a07fa355e6e..fa8d13b7cb3 100644 --- a/components/script/dom/webidls/XRSession.webidl +++ b/components/script/dom/webidls/XRSession.webidl @@ -24,8 +24,7 @@ interface XRSession : EventTarget { attribute XRLayer? baseLayer; // // Methods - // Promise<XRReferenceSpace> requestReferenceSpace(XRReferenceSpaceType type, - // optional XRReferenceSpaceOptions options); + Promise<XRReferenceSpace> requestReferenceSpace(XRReferenceSpaceOptions options); // FrozenArray<XRInputSource> getInputSources(); @@ -43,3 +42,15 @@ interface XRSession : EventTarget { // attribute EventHandler onselectstart; // attribute EventHandler onselectend; }; + +enum XRReferenceSpaceType { + "identity", + "stationary", + "bounded", + "unbounded" +}; + +dictionary XRReferenceSpaceOptions { + required XRReferenceSpaceType type; + XRStationaryReferenceSpaceSubtype subtype; +}; diff --git a/components/script/dom/webidls/XRStationaryReferenceSpace.webidl b/components/script/dom/webidls/XRStationaryReferenceSpace.webidl index 3580ac94602..b04100dac6d 100644 --- a/components/script/dom/webidls/XRStationaryReferenceSpace.webidl +++ b/components/script/dom/webidls/XRStationaryReferenceSpace.webidl @@ -10,10 +10,6 @@ enum XRStationaryReferenceSpaceSubtype { "position-disabled" }; -dictionary XRStationaryReferenceSpaceOptions : XRReferenceSpaceOptions { - required XRStationaryReferenceSpaceSubtype subtype; -}; - [SecureContext, Exposed=Window, Pref="dom.webxr.enabled"] interface XRStationaryReferenceSpace: XRReferenceSpace { // readonly attribute XRStationaryReferenceSpaceSubtype subtype; diff --git a/components/script/dom/xrsession.rs b/components/script/dom/xrsession.rs index 997d88b34bf..4c8ac610a78 100644 --- a/components/script/dom/xrsession.rs +++ b/components/script/dom/xrsession.rs @@ -7,17 +7,23 @@ use crate::dom::bindings::codegen::Bindings::XRBinding::XRSessionMode; use crate::dom::bindings::codegen::Bindings::XRSessionBinding; use crate::dom::bindings::codegen::Bindings::XRSessionBinding::XREnvironmentBlendMode; use crate::dom::bindings::codegen::Bindings::XRSessionBinding::XRFrameRequestCallback; +use crate::dom::bindings::codegen::Bindings::XRSessionBinding::XRReferenceSpaceOptions; +use crate::dom::bindings::codegen::Bindings::XRSessionBinding::XRReferenceSpaceType; use crate::dom::bindings::codegen::Bindings::XRSessionBinding::XRSessionMethods; use crate::dom::bindings::codegen::Bindings::XRWebGLLayerBinding::XRWebGLLayerMethods; +use crate::dom::bindings::error::Error; use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::num::Finite; use crate::dom::bindings::reflector::reflect_dom_object; +use crate::dom::bindings::reflector::DomObject; use crate::dom::bindings::root::{Dom, DomRoot, MutNullableDom}; use crate::dom::eventtarget::EventTarget; use crate::dom::globalscope::GlobalScope; use crate::dom::promise::Promise; use crate::dom::vrdisplay::VRDisplay; use crate::dom::xrlayer::XRLayer; +use crate::dom::xrreferencespace::XRReferenceSpace; +use crate::dom::xrstationaryreferencespace::XRStationaryReferenceSpace; use crate::dom::xrwebgllayer::XRWebGLLayer; use dom_struct::dom_struct; use std::rc::Rc; @@ -111,4 +117,39 @@ impl XRSessionMethods for XRSession { fn EnvironmentBlendMode(&self) -> XREnvironmentBlendMode { self.blend_mode } + + /// https://immersive-web.github.io/webxr/#dom-xrsession-requestreferencespace + fn RequestReferenceSpace(&self, options: &XRReferenceSpaceOptions) -> Rc<Promise> { + let p = Promise::new(&self.global()); + + // https://immersive-web.github.io/webxr/#create-a-reference-space + + match options.type_ { + XRReferenceSpaceType::Identity => { + p.resolve_native(&XRReferenceSpace::identity( + &self.global().as_window(), + self, + )); + }, + XRReferenceSpaceType::Stationary => { + if let Some(subtype) = options.subtype { + p.resolve_native(&XRStationaryReferenceSpace::new( + &self.global().as_window(), + self, + subtype, + )); + } else { + p.reject_error(Error::Type(format!( + "stationary XRReferenceSpaces must specify a subtype" + ))) + } + }, + XRReferenceSpaceType::Bounded | XRReferenceSpaceType::Unbounded => { + // XXXManishearth eventually support these + p.reject_error(Error::NotSupported) + }, + } + + p + } } diff --git a/components/script/dom/xrstationaryreferencespace.rs b/components/script/dom/xrstationaryreferencespace.rs index 8ac897b5ad7..33d96f1488f 100644 --- a/components/script/dom/xrstationaryreferencespace.rs +++ b/components/script/dom/xrstationaryreferencespace.rs @@ -3,6 +3,7 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ use crate::dom::bindings::codegen::Bindings::XRStationaryReferenceSpaceBinding; +use crate::dom::bindings::codegen::Bindings::XRStationaryReferenceSpaceBinding::XRStationaryReferenceSpaceSubtype; use crate::dom::bindings::reflector::reflect_dom_object; use crate::dom::bindings::root::DomRoot; use crate::dom::window::Window; @@ -14,24 +15,31 @@ use dom_struct::dom_struct; #[dom_struct] pub struct XRStationaryReferenceSpace { xrreferencespace: XRReferenceSpace, + ty: XRStationaryReferenceSpaceSubtype, } #[allow(unused)] impl XRStationaryReferenceSpace { pub fn new_inherited( session: &XRSession, + ty: XRStationaryReferenceSpaceSubtype, transform: &XRRigidTransform, ) -> XRStationaryReferenceSpace { XRStationaryReferenceSpace { xrreferencespace: XRReferenceSpace::new_inherited(session, transform), + ty, } } - pub fn new(window: &Window, session: &XRSession) -> DomRoot<XRStationaryReferenceSpace> { + pub fn new( + window: &Window, + session: &XRSession, + ty: XRStationaryReferenceSpaceSubtype, + ) -> DomRoot<XRStationaryReferenceSpace> { let transform = XRRigidTransform::identity(window); reflect_dom_object( Box::new(XRStationaryReferenceSpace::new_inherited( - session, &transform, + session, ty, &transform, )), window, XRStationaryReferenceSpaceBinding::Wrap, |