Skip to content

Commit

Permalink
Add requestReferenceSpace
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Mar 18, 2019
1 parent f2a6164 commit 191fcf6
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 18 deletions.
10 changes: 0 additions & 10 deletions components/script/dom/webidls/XRReferenceSpace.webidl
Expand Up @@ -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;
Expand Down
15 changes: 13 additions & 2 deletions components/script/dom/webidls/XRSession.webidl
Expand Up @@ -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();

Expand All @@ -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;
};
Expand Up @@ -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;
Expand Down
41 changes: 41 additions & 0 deletions components/script/dom/xrsession.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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
}
}
12 changes: 10 additions & 2 deletions components/script/dom/xrstationaryreferencespace.rs
Expand Up @@ -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;
Expand All @@ -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,
Expand Down

0 comments on commit 191fcf6

Please sign in to comment.