Move VR interface to XR

The WebVR spec no longer has a navigator.vr, but there is a navigator.XR in the XR spec. Instead of duplicating work I've combined the two.
This commit is contained in:
Manish Goregaokar 2018-12-19 14:17:14 -08:00
parent c553c43ba1
commit 376426a936
6 changed files with 55 additions and 42 deletions

View file

@ -479,7 +479,6 @@ pub mod validation;
pub mod validitystate; pub mod validitystate;
pub mod values; pub mod values;
pub mod virtualmethods; pub mod virtualmethods;
pub mod vr;
pub mod vrdisplay; pub mod vrdisplay;
pub mod vrdisplaycapabilities; pub mod vrdisplaycapabilities;
pub mod vrdisplayevent; pub mod vrdisplayevent;
@ -518,3 +517,4 @@ pub mod xmldocument;
pub mod xmlhttprequest; pub mod xmlhttprequest;
pub mod xmlhttprequesteventtarget; pub mod xmlhttprequesteventtarget;
pub mod xmlhttprequestupload; pub mod xmlhttprequestupload;
pub mod xr;

View file

@ -4,7 +4,6 @@
use crate::dom::bindings::codegen::Bindings::NavigatorBinding; use crate::dom::bindings::codegen::Bindings::NavigatorBinding;
use crate::dom::bindings::codegen::Bindings::NavigatorBinding::NavigatorMethods; use crate::dom::bindings::codegen::Bindings::NavigatorBinding::NavigatorMethods;
use crate::dom::bindings::codegen::Bindings::VRBinding::VRBinding::VRMethods;
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector}; use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::{DomRoot, MutNullableDom}; use crate::dom::bindings::root::{DomRoot, MutNullableDom};
use crate::dom::bindings::str::DOMString; use crate::dom::bindings::str::DOMString;
@ -16,8 +15,8 @@ use crate::dom::permissions::Permissions;
use crate::dom::pluginarray::PluginArray; use crate::dom::pluginarray::PluginArray;
use crate::dom::promise::Promise; use crate::dom::promise::Promise;
use crate::dom::serviceworkercontainer::ServiceWorkerContainer; use crate::dom::serviceworkercontainer::ServiceWorkerContainer;
use crate::dom::vr::VR;
use crate::dom::window::Window; use crate::dom::window::Window;
use crate::dom::xr::XR;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use std::rc::Rc; use std::rc::Rc;
@ -28,7 +27,7 @@ pub struct Navigator {
plugins: MutNullableDom<PluginArray>, plugins: MutNullableDom<PluginArray>,
mime_types: MutNullableDom<MimeTypeArray>, mime_types: MutNullableDom<MimeTypeArray>,
service_worker: MutNullableDom<ServiceWorkerContainer>, service_worker: MutNullableDom<ServiceWorkerContainer>,
vr: MutNullableDom<VR>, xr: MutNullableDom<XR>,
gamepads: MutNullableDom<GamepadList>, gamepads: MutNullableDom<GamepadList>,
permissions: MutNullableDom<Permissions>, permissions: MutNullableDom<Permissions>,
} }
@ -41,7 +40,7 @@ impl Navigator {
plugins: Default::default(), plugins: Default::default(),
mime_types: Default::default(), mime_types: Default::default(),
service_worker: Default::default(), service_worker: Default::default(),
vr: Default::default(), xr: Default::default(),
gamepads: Default::default(), gamepads: Default::default(),
permissions: Default::default(), permissions: Default::default(),
} }
@ -135,7 +134,7 @@ impl NavigatorMethods for Navigator {
.gamepads .gamepads
.or_init(|| GamepadList::new(&self.global(), &[])); .or_init(|| GamepadList::new(&self.global(), &[]));
let vr_gamepads = self.Vr().get_gamepads(); let vr_gamepads = self.Xr().get_gamepads();
root.add_if_not_exists(&vr_gamepads); root.add_if_not_exists(&vr_gamepads);
// TODO: Add not VR related gamepads // TODO: Add not VR related gamepads
root root
@ -149,12 +148,10 @@ impl NavigatorMethods for Navigator {
// https://w3c.github.io/webvr/spec/1.1/#navigator-getvrdisplays-attribute // https://w3c.github.io/webvr/spec/1.1/#navigator-getvrdisplays-attribute
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
fn GetVRDisplays(&self) -> Rc<Promise> { fn GetVRDisplays(&self) -> Rc<Promise> {
self.Vr().GetDisplays() self.Xr().get_displays()
} }
}
impl Navigator { fn Xr(&self) -> DomRoot<XR> {
pub fn Vr(&self) -> DomRoot<VR> { self.xr.or_init(|| XR::new(&self.global()))
self.vr.or_init(|| VR::new(&self.global()))
} }
} }

View file

@ -1,11 +0,0 @@
/* 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://w3c.github.io/webvr/#interface-navigator
[NoInterfaceObject]
interface VR {
[Pref="dom.webvr.enabled"]
Promise<sequence<VRDisplay>> getDisplays();
//readonly attribute FrozenArray<VRDisplay> activeVRDisplays;
};

View file

@ -0,0 +1,30 @@
/* 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/webxr/#xr-interface
[SecureContext, Exposed=Window]
interface XR: EventTarget {
// Methods
// Promise<void> supportsSessionMode(XRSessionMode mode);
// Promise<XRSession> requestSession(optional XRSessionCreationOptions parameters);
// Events
// attribute EventHandler ondevicechange;
};
[SecureContext]
partial interface Navigator {
[SameObject, Pref="dom.webvr.enabled"] readonly attribute XR xr;
};
enum XRSessionMode {
"inline",
"immersive-vr",
"immersive-ar"
};
dictionary XRSessionCreationOptions {
XRSessionMode mode = "inline";
// XRPresentationContext outputContext;
};

View file

@ -3,12 +3,11 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::VRBinding; use crate::dom::bindings::codegen::Bindings::XRBinding;
use crate::dom::bindings::codegen::Bindings::VRBinding::VRMethods;
use crate::dom::bindings::codegen::Bindings::VRDisplayBinding::VRDisplayMethods; use crate::dom::bindings::codegen::Bindings::VRDisplayBinding::VRDisplayMethods;
use crate::dom::bindings::error::Error; use crate::dom::bindings::error::Error;
use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector}; use crate::dom::bindings::reflector::{reflect_dom_object, DomObject};
use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::event::Event; use crate::dom::event::Event;
use crate::dom::eventtarget::EventTarget; use crate::dom::eventtarget::EventTarget;
@ -26,38 +25,37 @@ use webvr_traits::{WebVRDisplayData, WebVRDisplayEvent, WebVREvent, WebVRMsg};
use webvr_traits::{WebVRGamepadData, WebVRGamepadEvent, WebVRGamepadState}; use webvr_traits::{WebVRGamepadData, WebVRGamepadEvent, WebVRGamepadState};
#[dom_struct] #[dom_struct]
pub struct VR { pub struct XR {
reflector_: Reflector, eventtarget: EventTarget,
displays: DomRefCell<Vec<Dom<VRDisplay>>>, displays: DomRefCell<Vec<Dom<VRDisplay>>>,
gamepads: DomRefCell<Vec<Dom<Gamepad>>>, gamepads: DomRefCell<Vec<Dom<Gamepad>>>,
} }
impl VR { impl XR {
fn new_inherited() -> VR { fn new_inherited() -> XR {
VR { XR {
reflector_: Reflector::new(), eventtarget: EventTarget::new_inherited(),
displays: DomRefCell::new(Vec::new()), displays: DomRefCell::new(Vec::new()),
gamepads: DomRefCell::new(Vec::new()), gamepads: DomRefCell::new(Vec::new()),
} }
} }
pub fn new(global: &GlobalScope) -> DomRoot<VR> { pub fn new(global: &GlobalScope) -> DomRoot<XR> {
let root = reflect_dom_object(Box::new(VR::new_inherited()), global, VRBinding::Wrap); let root = reflect_dom_object(Box::new(XR::new_inherited()), global, XRBinding::Wrap);
root.register(); root.register();
root root
} }
} }
impl Drop for VR { impl Drop for XR {
fn drop(&mut self) { fn drop(&mut self) {
self.unregister(); self.unregister();
} }
} }
impl VRMethods for VR { impl XR {
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
// https://w3c.github.io/webvr/#interface-navigator pub fn get_displays(&self) -> Rc<Promise> {
fn GetDisplays(&self) -> Rc<Promise> {
let promise = Promise::new(&self.global()); let promise = Promise::new(&self.global());
if let Some(webvr_thread) = self.webvr_thread() { if let Some(webvr_thread) = self.webvr_thread() {
@ -93,9 +91,7 @@ impl VRMethods for VR {
promise promise
} }
}
impl VR {
fn webvr_thread(&self) -> Option<IpcSender<WebVRMsg>> { fn webvr_thread(&self) -> Option<IpcSender<WebVRMsg>> {
self.global().as_window().webvr_thread() self.global().as_window().webvr_thread()
} }
@ -209,7 +205,7 @@ impl VR {
} }
// Gamepad // Gamepad
impl VR { impl XR {
fn find_gamepad(&self, gamepad_id: u32) -> Option<DomRoot<Gamepad>> { fn find_gamepad(&self, gamepad_id: u32) -> Option<DomRoot<Gamepad>> {
self.gamepads self.gamepads
.borrow() .borrow()

View file

@ -26,6 +26,7 @@ use crate::dom::bindings::codegen::Bindings::DocumentBinding::{
DocumentMethods, DocumentReadyState, DocumentMethods, DocumentReadyState,
}; };
use crate::dom::bindings::codegen::Bindings::EventBinding::EventInit; use crate::dom::bindings::codegen::Bindings::EventBinding::EventInit;
use crate::dom::bindings::codegen::Bindings::NavigatorBinding::NavigatorMethods;
use crate::dom::bindings::codegen::Bindings::TransitionEventBinding::TransitionEventInit; use crate::dom::bindings::codegen::Bindings::TransitionEventBinding::TransitionEventInit;
use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
use crate::dom::bindings::conversions::{ use crate::dom::bindings::conversions::{
@ -3278,8 +3279,8 @@ impl ScriptThread {
fn handle_webvr_events(&self, pipeline_id: PipelineId, events: Vec<WebVREvent>) { fn handle_webvr_events(&self, pipeline_id: PipelineId, events: Vec<WebVREvent>) {
let window = self.documents.borrow().find_window(pipeline_id); let window = self.documents.borrow().find_window(pipeline_id);
if let Some(window) = window { if let Some(window) = window {
let vr = window.Navigator().Vr(); let xr = window.Navigator().Xr();
vr.handle_webvr_events(events); xr.handle_webvr_events(events);
} }
} }