diff options
10 files changed, 40 insertions, 17 deletions
diff --git a/components/script/dom/fakexrdevice.rs b/components/script/dom/fakexrdevice.rs index f43b0b1155b..dd599d4a3a4 100644 --- a/components/script/dom/fakexrdevice.rs +++ b/components/script/dom/fakexrdevice.rs @@ -205,13 +205,16 @@ impl FakeXRDeviceMethods for FakeXRDevice { None }; - // XXXManishearth deal with profiles, supportedButtons, selection* + let profiles = init.profiles.iter().cloned().map(String::from).collect(); + + // XXXManishearth deal with supportedButtons and selection* let source = InputSource { handedness, target_ray_mode, id, supports_grip: true, + profiles, }; let init = MockInputInit { diff --git a/components/script/dom/fakexrinputcontroller.rs b/components/script/dom/fakexrinputcontroller.rs index 7c145a3ed20..e93d328ff29 100644 --- a/components/script/dom/fakexrinputcontroller.rs +++ b/components/script/dom/fakexrinputcontroller.rs @@ -12,6 +12,7 @@ use crate::dom::bindings::codegen::Bindings::XRInputSourceBinding::{ use crate::dom::bindings::error::Fallible; use crate::dom::bindings::reflector::{reflect_dom_object, Reflector}; use crate::dom::bindings::root::DomRoot; +use crate::dom::bindings::str::DOMString; use crate::dom::fakexrdevice::get_origin; use crate::dom::globalscope::GlobalScope; use dom_struct::dom_struct; @@ -128,4 +129,10 @@ impl FakeXRInputControllerMethods for FakeXRInputController { }; let _ = self.send_message(MockInputMsg::SetTargetRayMode(t)); } + + /// https://immersive-web.github.io/webxr-test-api/#dom-fakexrinputcontroller-setprofiles + fn SetProfiles(&self, profiles: Vec<DOMString>) { + let t = profiles.into_iter().map(String::from).collect(); + let _ = self.send_message(MockInputMsg::SetProfiles(t)); + } } diff --git a/components/script/dom/webidls/FakeXRInputController.webidl b/components/script/dom/webidls/FakeXRInputController.webidl index 164012f3d83..b8faad1038a 100644 --- a/components/script/dom/webidls/FakeXRInputController.webidl +++ b/components/script/dom/webidls/FakeXRInputController.webidl @@ -8,7 +8,7 @@ interface FakeXRInputController { void setHandedness(XRHandedness handedness); void setTargetRayMode(XRTargetRayMode targetRayMode); - // void setProfiles(sequence<DOMString> profiles); + void setProfiles(sequence<DOMString> profiles); [Throws] void setGripOrigin(FakeXRRigidTransformInit gripOrigin, optional boolean emulatedPosition = false); void clearGripOrigin(); [Throws] void setPointerOrigin(FakeXRRigidTransformInit pointerOrigin, optional boolean emulatedPosition = false); diff --git a/components/script/dom/webidls/XRInputSource.webidl b/components/script/dom/webidls/XRInputSource.webidl index f07de183927..487c959859d 100644 --- a/components/script/dom/webidls/XRInputSource.webidl +++ b/components/script/dom/webidls/XRInputSource.webidl @@ -23,4 +23,5 @@ interface XRInputSource { [SameObject] readonly attribute XRSpace targetRaySpace; [SameObject] readonly attribute XRSpace? gripSpace; // [SameObject] readonly attribute Gamepad? gamepad; + /* [SameObject] */ readonly attribute /* FrozenArray<DOMString> */ any profiles; }; diff --git a/components/script/dom/xrinputsource.rs b/components/script/dom/xrinputsource.rs index fed76937d9c..e0da8bea550 100644 --- a/components/script/dom/xrinputsource.rs +++ b/components/script/dom/xrinputsource.rs @@ -2,6 +2,7 @@ * 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::compartments::enter_realm; use crate::dom::bindings::codegen::Bindings::XRInputSourceBinding; use crate::dom::bindings::codegen::Bindings::XRInputSourceBinding::{ XRHandedness, XRInputSourceMethods, XRTargetRayMode, @@ -11,7 +12,11 @@ use crate::dom::bindings::root::{Dom, DomRoot, MutNullableDom}; use crate::dom::globalscope::GlobalScope; use crate::dom::xrsession::XRSession; use crate::dom::xrspace::XRSpace; +use crate::script_runtime::JSContext; use dom_struct::dom_struct; +use js::conversions::ToJSValConvertible; +use js::jsapi::Heap; +use js::jsval::{JSVal, UndefinedValue}; use webxr_api::{Handedness, InputId, InputSource, TargetRayMode}; #[dom_struct] @@ -24,6 +29,8 @@ pub struct XRInputSource { target_ray_space: MutNullableDom<XRSpace>, #[ignore_malloc_size_of = "Defined in rust-webxr"] grip_space: MutNullableDom<XRSpace>, + #[ignore_malloc_size_of = "mozjs"] + profiles: Heap<JSVal>, } impl XRInputSource { @@ -34,19 +41,30 @@ impl XRInputSource { info, target_ray_space: Default::default(), grip_space: Default::default(), + profiles: Heap::default(), } } + #[allow(unsafe_code)] pub fn new( global: &GlobalScope, session: &XRSession, info: InputSource, ) -> DomRoot<XRInputSource> { - reflect_dom_object( + let source = reflect_dom_object( Box::new(XRInputSource::new_inherited(session, info)), global, XRInputSourceBinding::Wrap, - ) + ); + + let _ac = enter_realm(&*global); + let cx = global.get_cx(); + unsafe { + rooted!(in(*cx) let mut profiles = UndefinedValue()); + source.info.profiles.to_jsval(*cx, profiles.handle_mut()); + source.profiles.set(profiles.get()); + } + source } pub fn id(&self) -> InputId { @@ -92,4 +110,8 @@ impl XRInputSourceMethods for XRInputSource { None } } + // https://immersive-web.github.io/webxr/#dom-xrinputsource-profiles + fn Profiles(&self, _cx: JSContext) -> JSVal { + self.profiles.get() + } } diff --git a/components/script/dom/xrinputsourcearray.rs b/components/script/dom/xrinputsourcearray.rs index 66e4045e44a..86a107bcd27 100644 --- a/components/script/dom/xrinputsourcearray.rs +++ b/components/script/dom/xrinputsourcearray.rs @@ -45,7 +45,7 @@ impl XRInputSourceArray { 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); + let input = XRInputSource::new(&global, &session, info.clone()); input_sources.push(Dom::from_ref(&input)); } }); @@ -54,11 +54,11 @@ impl XRInputSourceArray { pub fn add_input_source(&self, session: &XRSession, info: InputSource) { let mut input_sources = self.input_sources.borrow_mut(); let global = self.global(); - let input = XRInputSource::new(&global, &session, info); debug_assert!( input_sources.iter().find(|i| i.id() == info.id).is_none(), "Should never add a duplicate input id!" ); + let input = XRInputSource::new(&global, &session, info); input_sources.push(Dom::from_ref(&input)); let added = [input]; diff --git a/tests/wpt/metadata/webxr/events_input_source_recreation.https.html.ini b/tests/wpt/metadata/webxr/events_input_source_recreation.https.html.ini deleted file mode 100644 index 976a3ad323d..00000000000 --- a/tests/wpt/metadata/webxr/events_input_source_recreation.https.html.ini +++ /dev/null @@ -1,4 +0,0 @@ -[events_input_source_recreation.https.html] - [Input sources are re-created when handedness or target ray mode changes] - expected: FAIL - diff --git a/tests/wpt/metadata/webxr/idlharness.https.window.js.ini b/tests/wpt/metadata/webxr/idlharness.https.window.js.ini index 1b47a7ad858..df4d0eabbcd 100644 --- a/tests/wpt/metadata/webxr/idlharness.https.window.js.ini +++ b/tests/wpt/metadata/webxr/idlharness.https.window.js.ini @@ -95,9 +95,6 @@ [XRReferenceSpaceEvent interface: existence and properties of interface prototype object's "constructor" property] expected: FAIL - [XRInputSource interface: attribute profiles] - expected: FAIL - [XR interface: operation requestSession(XRSessionMode, XRSessionInit)] expected: FAIL diff --git a/tests/wpt/metadata/webxr/xrInputSource_profiles.https.html.ini b/tests/wpt/metadata/webxr/xrInputSource_profiles.https.html.ini deleted file mode 100644 index 3e2806dfae7..00000000000 --- a/tests/wpt/metadata/webxr/xrInputSource_profiles.https.html.ini +++ /dev/null @@ -1,4 +0,0 @@ -[xrInputSource_profiles.https.html] - [WebXR InputSource's profiles list can be set] - expected: FAIL - diff --git a/tests/wpt/metadata/webxr/xrSession_input_events_end.https.html.ini b/tests/wpt/metadata/webxr/xrSession_input_events_end.https.html.ini index 739e7b4c112..1c2f8518d1a 100644 --- a/tests/wpt/metadata/webxr/xrSession_input_events_end.https.html.ini +++ b/tests/wpt/metadata/webxr/xrSession_input_events_end.https.html.ini @@ -1,4 +1,5 @@ [xrSession_input_events_end.https.html] + expected: TIMEOUT [Calling end during an input callback stops processing at the right time] expected: FAIL |