From b5b852be757b65bc72efb73bf8f10d698f5e009f Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Tue, 8 Oct 2019 14:51:05 -0700 Subject: [PATCH 1/5] Add empty XRInputSourceArray interface --- components/script/dom/mod.rs | 1 + .../dom/webidls/XRInputSourceArray.webidl | 12 ++++++++ components/script/dom/xrinputsourcearray.rs | 30 +++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 components/script/dom/webidls/XRInputSourceArray.webidl create mode 100644 components/script/dom/xrinputsourcearray.rs diff --git a/components/script/dom/mod.rs b/components/script/dom/mod.rs index 598832403e0..36adbbe4725 100644 --- a/components/script/dom/mod.rs +++ b/components/script/dom/mod.rs @@ -549,6 +549,7 @@ pub mod xmlserializer; pub mod xr; pub mod xrframe; pub mod xrinputsource; +pub mod xrinputsourcearray; pub mod xrinputsourceevent; pub mod xrpose; pub mod xrreferencespace; diff --git a/components/script/dom/webidls/XRInputSourceArray.webidl b/components/script/dom/webidls/XRInputSourceArray.webidl new file mode 100644 index 00000000000..939371bf417 --- /dev/null +++ b/components/script/dom/webidls/XRInputSourceArray.webidl @@ -0,0 +1,12 @@ +/* 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/#xrinputsourcearray-interface + +[SecureContext, Exposed=Window, Pref="dom.webxr.enabled"] +interface XRInputSourceArray { + // iterable; + // readonly attribute unsigned long length; + // getter XRInputSource(unsigned long index); +}; diff --git a/components/script/dom/xrinputsourcearray.rs b/components/script/dom/xrinputsourcearray.rs new file mode 100644 index 00000000000..d0d4a747052 --- /dev/null +++ b/components/script/dom/xrinputsourcearray.rs @@ -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/. */ + +use crate::dom::bindings::codegen::Bindings::XRInputSourceArrayBinding; +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; + +#[dom_struct] +pub struct XRInputSourceArray { + reflector_: Reflector, +} + +impl XRInputSourceArray { + fn new_inherited() -> XRInputSourceArray { + XRInputSourceArray { + reflector_: Reflector::new(), + } + } + + pub fn new(global: &GlobalScope) -> DomRoot { + reflect_dom_object( + Box::new(XRInputSourceArray::new_inherited()), + global, + XRInputSourceArrayBinding::Wrap, + ) + } +} From 0777233412359f49acd542916910e7ec6ed4dac2 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Tue, 8 Oct 2019 15:04:43 -0700 Subject: [PATCH 2/5] Store inputs array in XRInputSourceArray --- components/script/dom/xrinputsourcearray.rs | 22 +++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/components/script/dom/xrinputsourcearray.rs b/components/script/dom/xrinputsourcearray.rs index d0d4a747052..bf63e38e073 100644 --- a/components/script/dom/xrinputsourcearray.rs +++ b/components/script/dom/xrinputsourcearray.rs @@ -2,21 +2,26 @@ * 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::cell::DomRefCell; use crate::dom::bindings::codegen::Bindings::XRInputSourceArrayBinding; -use crate::dom::bindings::reflector::{reflect_dom_object, Reflector}; -use crate::dom::bindings::root::DomRoot; +use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector}; +use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::globalscope::GlobalScope; +use crate::dom::xrinputsource::XRInputSource; +use crate::dom::xrsession::XRSession; use dom_struct::dom_struct; #[dom_struct] pub struct XRInputSourceArray { reflector_: Reflector, + input_sources: DomRefCell>>, } impl XRInputSourceArray { fn new_inherited() -> XRInputSourceArray { XRInputSourceArray { reflector_: Reflector::new(), + input_sources: DomRefCell::new(vec![]), } } @@ -27,4 +32,17 @@ impl XRInputSourceArray { XRInputSourceArrayBinding::Wrap, ) } + + pub fn set_initial_inputs(&self, session: &XRSession) { + let mut input_sources = self.input_sources.borrow_mut(); + let global = self.global(); + session.with_session(|sess| { + for info in sess.initial_inputs() { + // XXXManishearth we should be able to listen for updates + // to the input sources + let input = XRInputSource::new(&global, &session, *info); + input_sources.push(Dom::from_ref(&input)); + } + }); + } } From 868e5cbd6220d39b08ceee2fa62521d4c51be596 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Tue, 8 Oct 2019 15:07:18 -0700 Subject: [PATCH 3/5] Add methods to XRInputSourceArray --- .../script/dom/webidls/XRInputSourceArray.webidl | 6 +++--- components/script/dom/xrinputsourcearray.rs | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/components/script/dom/webidls/XRInputSourceArray.webidl b/components/script/dom/webidls/XRInputSourceArray.webidl index 939371bf417..f8a0eb4308d 100644 --- a/components/script/dom/webidls/XRInputSourceArray.webidl +++ b/components/script/dom/webidls/XRInputSourceArray.webidl @@ -6,7 +6,7 @@ [SecureContext, Exposed=Window, Pref="dom.webxr.enabled"] interface XRInputSourceArray { - // iterable; - // readonly attribute unsigned long length; - // getter XRInputSource(unsigned long index); + iterable; + readonly attribute unsigned long length; + getter XRInputSource(unsigned long index); }; diff --git a/components/script/dom/xrinputsourcearray.rs b/components/script/dom/xrinputsourcearray.rs index bf63e38e073..b0565940373 100644 --- a/components/script/dom/xrinputsourcearray.rs +++ b/components/script/dom/xrinputsourcearray.rs @@ -4,6 +4,7 @@ use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::codegen::Bindings::XRInputSourceArrayBinding; +use crate::dom::bindings::codegen::Bindings::XRInputSourceArrayBinding::XRInputSourceArrayMethods; use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector}; use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::globalscope::GlobalScope; @@ -46,3 +47,18 @@ impl XRInputSourceArray { }); } } + +impl XRInputSourceArrayMethods for XRInputSourceArray { + /// https://immersive-web.github.io/webxr/#dom-xrinputsourcearray-length + fn Length(&self) -> u32 { + self.input_sources.borrow().len() as u32 + } + + /// https://immersive-web.github.io/webxr/#xrinputsourcearray + fn IndexedGetter(&self, n: u32) -> Option> { + self.input_sources + .borrow() + .get(n as usize) + .map(|x| DomRoot::from_ref(&**x)) + } +} From 8ae1c2e0ad8d03a09bf2f6e8bc67058acd910377 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Tue, 8 Oct 2019 15:34:04 -0700 Subject: [PATCH 4/5] Hook XRInputSourceArray into XRSession --- .../script/dom/webidls/XRSession.webidl | 15 ++---- components/script/dom/xrinputsourcearray.rs | 9 ++++ components/script/dom/xrsession.rs | 46 ++++++++----------- 3 files changed, 33 insertions(+), 37 deletions(-) diff --git a/components/script/dom/webidls/XRSession.webidl b/components/script/dom/webidls/XRSession.webidl index 820ef11dc70..82d3338858f 100644 --- a/components/script/dom/webidls/XRSession.webidl +++ b/components/script/dom/webidls/XRSession.webidl @@ -16,31 +16,26 @@ callback XRFrameRequestCallback = void (DOMHighResTimeStamp time, XRFrame frame) interface XRSession : EventTarget { // // Attributes readonly attribute XRSessionMode mode; - // readonly attribute XRPresentationContext outputContext; readonly attribute XREnvironmentBlendMode environmentBlendMode; - readonly attribute XRRenderState renderState; + // readonly attribute XRVisibilityState visibilityState; + [SameObject] readonly attribute XRRenderState renderState; + [SameObject] readonly attribute XRInputSourceArray inputSources; // // Methods + [Throws] void updateRenderState(optional XRRenderStateInit state = {}); Promise requestReferenceSpace(XRReferenceSpaceType type); - // workaround until we have FrozenArray - // see https://github.com/servo/servo/issues/10427#issuecomment-449593626 - // FrozenArray getInputSources(); - sequence getInputSources(); - - [Throws] void updateRenderState(optional XRRenderStateInit state = {}); long requestAnimationFrame(XRFrameRequestCallback callback); void cancelAnimationFrame(long handle); Promise end(); // // Events - // attribute EventHandler onblur; - // attribute EventHandler onfocus; attribute EventHandler onend; attribute EventHandler onselect; // attribute EventHandler oninputsourceschange; attribute EventHandler onselectstart; attribute EventHandler onselectend; + // attribute EventHandler onvisibilitychange; }; diff --git a/components/script/dom/xrinputsourcearray.rs b/components/script/dom/xrinputsourcearray.rs index b0565940373..48f84991db0 100644 --- a/components/script/dom/xrinputsourcearray.rs +++ b/components/script/dom/xrinputsourcearray.rs @@ -11,6 +11,7 @@ use crate::dom::globalscope::GlobalScope; use crate::dom::xrinputsource::XRInputSource; use crate::dom::xrsession::XRSession; use dom_struct::dom_struct; +use webxr_api::InputId; #[dom_struct] pub struct XRInputSourceArray { @@ -46,6 +47,14 @@ impl XRInputSourceArray { } }); } + + pub fn find(&self, id: InputId) -> Option> { + self.input_sources + .borrow() + .iter() + .find(|x| x.id() == id) + .map(|x| DomRoot::from_ref(&**x)) + } } impl XRInputSourceArrayMethods for XRInputSourceArray { diff --git a/components/script/dom/xrsession.rs b/components/script/dom/xrsession.rs index e7a3fab4677..d0511c6204d 100644 --- a/components/script/dom/xrsession.rs +++ b/components/script/dom/xrsession.rs @@ -32,7 +32,7 @@ use crate::dom::node::NodeDamage; use crate::dom::promise::Promise; use crate::dom::webglframebuffer::WebGLFramebufferAttachmentRoot; use crate::dom::xrframe::XRFrame; -use crate::dom::xrinputsource::XRInputSource; +use crate::dom::xrinputsourcearray::XRInputSourceArray; use crate::dom::xrinputsourceevent::XRInputSourceEvent; use crate::dom::xrreferencespace::XRReferenceSpace; use crate::dom::xrrenderstate::XRRenderState; @@ -68,7 +68,7 @@ pub struct XRSession { raf_callback_list: DomRefCell>)>>, #[ignore_malloc_size_of = "defined in ipc-channel"] raf_sender: DomRefCell>>, - input_sources: DomRefCell>>, + input_sources: Dom, // Any promises from calling end() #[ignore_malloc_size_of = "promises are hard"] end_promises: DomRefCell>>, @@ -77,7 +77,11 @@ pub struct XRSession { } impl XRSession { - fn new_inherited(session: Session, render_state: &XRRenderState) -> XRSession { + fn new_inherited( + session: Session, + render_state: &XRRenderState, + input_sources: &XRInputSourceArray, + ) -> XRSession { XRSession { eventtarget: EventTarget::new_inherited(), base_layer: Default::default(), @@ -92,7 +96,7 @@ impl XRSession { next_raf_id: Cell::new(0), raf_callback_list: DomRefCell::new(vec![]), raf_sender: DomRefCell::new(None), - input_sources: DomRefCell::new(vec![]), + input_sources: Dom::from_ref(input_sources), end_promises: DomRefCell::new(vec![]), ended: Cell::new(false), } @@ -100,20 +104,17 @@ impl XRSession { pub fn new(global: &GlobalScope, session: Session) -> DomRoot { let render_state = XRRenderState::new(global, 0.1, 1000.0, None); + let input_sources = XRInputSourceArray::new(global); let ret = reflect_dom_object( - Box::new(XRSession::new_inherited(session, &render_state)), + Box::new(XRSession::new_inherited( + session, + &render_state, + &input_sources, + )), global, XRSessionBinding::Wrap, ); - { - let mut input_sources = ret.input_sources.borrow_mut(); - for info in ret.session.borrow().initial_inputs() { - // XXXManishearth we should be able to listen for updates - // to the input sources - let input = XRInputSource::new(global, &ret, *info); - input_sources.push(Dom::from_ref(&input)); - } - } + input_sources.set_initial_inputs(&ret); ret.attach_event_handler(); ret } @@ -173,12 +174,7 @@ impl XRSession { }, XREvent::Select(input, kind, frame) => { // https://immersive-web.github.io/webxr/#primary-action - let source = self - .input_sources - .borrow_mut() - .iter() - .find(|s| s.id() == input) - .map(|x| DomRoot::from_ref(&**x)); + let source = self.input_sources.find(input); if let Some(source) = source { let frame = XRFrame::new(&self.global(), self, frame); frame.set_active(true); @@ -438,13 +434,9 @@ impl XRSessionMethods for XRSession { p } - /// https://immersive-web.github.io/webxr/#dom-xrsession-getinputsources - fn GetInputSources(&self) -> Vec> { - self.input_sources - .borrow() - .iter() - .map(|x| DomRoot::from_ref(&**x)) - .collect() + /// https://immersive-web.github.io/webxr/#dom-xrsession-inputsources + fn InputSources(&self) -> DomRoot { + DomRoot::from_ref(&*self.input_sources) } /// https://immersive-web.github.io/webxr/#dom-xrsession-end From c812fe0130031c01f0e1ee9151dc788b3ac24c41 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Tue, 8 Oct 2019 15:58:58 -0700 Subject: [PATCH 5/5] Update WPT --- .../webxr/idlharness.https.window.js.ini | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/tests/wpt/metadata/webxr/idlharness.https.window.js.ini b/tests/wpt/metadata/webxr/idlharness.https.window.js.ini index 1f341a6fe65..148617650d1 100644 --- a/tests/wpt/metadata/webxr/idlharness.https.window.js.ini +++ b/tests/wpt/metadata/webxr/idlharness.https.window.js.ini @@ -17,12 +17,6 @@ [XRSession interface: attribute onvisibilitychange] expected: FAIL - [XRInputSourceArray interface object name] - expected: FAIL - - [XRSession interface: attribute inputSources] - expected: FAIL - [XRInputSourcesChangeEvent interface object length] expected: FAIL @@ -41,9 +35,6 @@ [XRPose interface: attribute emulatedPosition] expected: FAIL - [XRInputSourceArray interface: attribute length] - expected: FAIL - [XRInputSource interface: attribute targetRayMode] expected: FAIL @@ -86,9 +77,6 @@ [XRRay interface object name] expected: FAIL - [XRInputSourceArray interface: existence and properties of interface prototype object's @@unscopables property] - expected: FAIL - [XRRay interface: existence and properties of interface prototype object's "constructor" property] expected: FAIL @@ -101,9 +89,6 @@ [XRInputSourcesChangeEvent interface: existence and properties of interface prototype object's "constructor" property] expected: FAIL - [XRInputSourceArray interface: existence and properties of interface prototype object] - expected: FAIL - [XRBoundedReferenceSpace interface: attribute boundsGeometry] expected: FAIL @@ -140,15 +125,9 @@ [XRRay interface: existence and properties of interface prototype object] expected: FAIL - [XRInputSourceArray interface object length] - expected: FAIL - [XRInputSource interface: attribute gripSpace] expected: FAIL - [XRInputSourceArray interface: existence and properties of interface object] - expected: FAIL - [XRReferenceSpaceEvent interface: existence and properties of interface prototype object's "constructor" property] expected: FAIL @@ -173,9 +152,6 @@ [XRWebGLLayer interface: attribute ignoreDepthValues] expected: FAIL - [XRInputSourceArray interface: existence and properties of interface prototype object's "constructor" property] - expected: FAIL - [XRSession interface: attribute oninputsourceschange] expected: FAIL