mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
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:
parent
c553c43ba1
commit
376426a936
6 changed files with 55 additions and 42 deletions
|
@ -479,7 +479,6 @@ pub mod validation;
|
|||
pub mod validitystate;
|
||||
pub mod values;
|
||||
pub mod virtualmethods;
|
||||
pub mod vr;
|
||||
pub mod vrdisplay;
|
||||
pub mod vrdisplaycapabilities;
|
||||
pub mod vrdisplayevent;
|
||||
|
@ -518,3 +517,4 @@ pub mod xmldocument;
|
|||
pub mod xmlhttprequest;
|
||||
pub mod xmlhttprequesteventtarget;
|
||||
pub mod xmlhttprequestupload;
|
||||
pub mod xr;
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
use crate::dom::bindings::codegen::Bindings::NavigatorBinding;
|
||||
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::root::{DomRoot, MutNullableDom};
|
||||
use crate::dom::bindings::str::DOMString;
|
||||
|
@ -16,8 +15,8 @@ use crate::dom::permissions::Permissions;
|
|||
use crate::dom::pluginarray::PluginArray;
|
||||
use crate::dom::promise::Promise;
|
||||
use crate::dom::serviceworkercontainer::ServiceWorkerContainer;
|
||||
use crate::dom::vr::VR;
|
||||
use crate::dom::window::Window;
|
||||
use crate::dom::xr::XR;
|
||||
use dom_struct::dom_struct;
|
||||
use std::rc::Rc;
|
||||
|
||||
|
@ -28,7 +27,7 @@ pub struct Navigator {
|
|||
plugins: MutNullableDom<PluginArray>,
|
||||
mime_types: MutNullableDom<MimeTypeArray>,
|
||||
service_worker: MutNullableDom<ServiceWorkerContainer>,
|
||||
vr: MutNullableDom<VR>,
|
||||
xr: MutNullableDom<XR>,
|
||||
gamepads: MutNullableDom<GamepadList>,
|
||||
permissions: MutNullableDom<Permissions>,
|
||||
}
|
||||
|
@ -41,7 +40,7 @@ impl Navigator {
|
|||
plugins: Default::default(),
|
||||
mime_types: Default::default(),
|
||||
service_worker: Default::default(),
|
||||
vr: Default::default(),
|
||||
xr: Default::default(),
|
||||
gamepads: Default::default(),
|
||||
permissions: Default::default(),
|
||||
}
|
||||
|
@ -135,7 +134,7 @@ impl NavigatorMethods for Navigator {
|
|||
.gamepads
|
||||
.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);
|
||||
// TODO: Add not VR related gamepads
|
||||
root
|
||||
|
@ -149,12 +148,10 @@ impl NavigatorMethods for Navigator {
|
|||
// https://w3c.github.io/webvr/spec/1.1/#navigator-getvrdisplays-attribute
|
||||
#[allow(unrooted_must_root)]
|
||||
fn GetVRDisplays(&self) -> Rc<Promise> {
|
||||
self.Vr().GetDisplays()
|
||||
self.Xr().get_displays()
|
||||
}
|
||||
}
|
||||
|
||||
impl Navigator {
|
||||
pub fn Vr(&self) -> DomRoot<VR> {
|
||||
self.vr.or_init(|| VR::new(&self.global()))
|
||||
fn Xr(&self) -> DomRoot<XR> {
|
||||
self.xr.or_init(|| XR::new(&self.global()))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
30
components/script/dom/webidls/XR.webidl
Normal file
30
components/script/dom/webidls/XR.webidl
Normal 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;
|
||||
};
|
|
@ -3,12 +3,11 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use crate::dom::bindings::cell::DomRefCell;
|
||||
use crate::dom::bindings::codegen::Bindings::VRBinding;
|
||||
use crate::dom::bindings::codegen::Bindings::VRBinding::VRMethods;
|
||||
use crate::dom::bindings::codegen::Bindings::XRBinding;
|
||||
use crate::dom::bindings::codegen::Bindings::VRDisplayBinding::VRDisplayMethods;
|
||||
use crate::dom::bindings::error::Error;
|
||||
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::event::Event;
|
||||
use crate::dom::eventtarget::EventTarget;
|
||||
|
@ -26,38 +25,37 @@ use webvr_traits::{WebVRDisplayData, WebVRDisplayEvent, WebVREvent, WebVRMsg};
|
|||
use webvr_traits::{WebVRGamepadData, WebVRGamepadEvent, WebVRGamepadState};
|
||||
|
||||
#[dom_struct]
|
||||
pub struct VR {
|
||||
reflector_: Reflector,
|
||||
pub struct XR {
|
||||
eventtarget: EventTarget,
|
||||
displays: DomRefCell<Vec<Dom<VRDisplay>>>,
|
||||
gamepads: DomRefCell<Vec<Dom<Gamepad>>>,
|
||||
}
|
||||
|
||||
impl VR {
|
||||
fn new_inherited() -> VR {
|
||||
VR {
|
||||
reflector_: Reflector::new(),
|
||||
impl XR {
|
||||
fn new_inherited() -> XR {
|
||||
XR {
|
||||
eventtarget: EventTarget::new_inherited(),
|
||||
displays: DomRefCell::new(Vec::new()),
|
||||
gamepads: DomRefCell::new(Vec::new()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new(global: &GlobalScope) -> DomRoot<VR> {
|
||||
let root = reflect_dom_object(Box::new(VR::new_inherited()), global, VRBinding::Wrap);
|
||||
pub fn new(global: &GlobalScope) -> DomRoot<XR> {
|
||||
let root = reflect_dom_object(Box::new(XR::new_inherited()), global, XRBinding::Wrap);
|
||||
root.register();
|
||||
root
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for VR {
|
||||
impl Drop for XR {
|
||||
fn drop(&mut self) {
|
||||
self.unregister();
|
||||
}
|
||||
}
|
||||
|
||||
impl VRMethods for VR {
|
||||
impl XR {
|
||||
#[allow(unrooted_must_root)]
|
||||
// https://w3c.github.io/webvr/#interface-navigator
|
||||
fn GetDisplays(&self) -> Rc<Promise> {
|
||||
pub fn get_displays(&self) -> Rc<Promise> {
|
||||
let promise = Promise::new(&self.global());
|
||||
|
||||
if let Some(webvr_thread) = self.webvr_thread() {
|
||||
|
@ -93,9 +91,7 @@ impl VRMethods for VR {
|
|||
|
||||
promise
|
||||
}
|
||||
}
|
||||
|
||||
impl VR {
|
||||
fn webvr_thread(&self) -> Option<IpcSender<WebVRMsg>> {
|
||||
self.global().as_window().webvr_thread()
|
||||
}
|
||||
|
@ -209,7 +205,7 @@ impl VR {
|
|||
}
|
||||
|
||||
// Gamepad
|
||||
impl VR {
|
||||
impl XR {
|
||||
fn find_gamepad(&self, gamepad_id: u32) -> Option<DomRoot<Gamepad>> {
|
||||
self.gamepads
|
||||
.borrow()
|
|
@ -26,6 +26,7 @@ use crate::dom::bindings::codegen::Bindings::DocumentBinding::{
|
|||
DocumentMethods, DocumentReadyState,
|
||||
};
|
||||
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::WindowBinding::WindowMethods;
|
||||
use crate::dom::bindings::conversions::{
|
||||
|
@ -3278,8 +3279,8 @@ impl ScriptThread {
|
|||
fn handle_webvr_events(&self, pipeline_id: PipelineId, events: Vec<WebVREvent>) {
|
||||
let window = self.documents.borrow().find_window(pipeline_id);
|
||||
if let Some(window) = window {
|
||||
let vr = window.Navigator().Vr();
|
||||
vr.handle_webvr_events(events);
|
||||
let xr = window.Navigator().Xr();
|
||||
xr.handle_webvr_events(events);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue