diff --git a/Cargo.lock b/Cargo.lock index b71add99236..2d3fe920384 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7960,7 +7960,7 @@ dependencies = [ [[package]] name = "webxr" version = "0.0.1" -source = "git+https://github.com/servo/webxr#5587c9236bac0a8b7b87b3a95b22882400461b46" +source = "git+https://github.com/servo/webxr#845ae9c22c3eeb7b2ac3fcf9ed791879628256b3" dependencies = [ "crossbeam-channel", "euclid", @@ -7977,7 +7977,7 @@ dependencies = [ [[package]] name = "webxr-api" version = "0.0.1" -source = "git+https://github.com/servo/webxr#5587c9236bac0a8b7b87b3a95b22882400461b46" +source = "git+https://github.com/servo/webxr#845ae9c22c3eeb7b2ac3fcf9ed791879628256b3" dependencies = [ "euclid", "ipc-channel", diff --git a/components/script/dom/fakexrdevice.rs b/components/script/dom/fakexrdevice.rs index 397f6032c94..73af6c33724 100644 --- a/components/script/dom/fakexrdevice.rs +++ b/components/script/dom/fakexrdevice.rs @@ -337,6 +337,11 @@ impl FakeXRDeviceMethods for FakeXRDevice { let _ = self.sender.send(MockDeviceMsg::SetBoundsGeometry(coords)); Ok(()) } + + /// + fn SimulateResetPose(&self) { + let _ = self.sender.send(MockDeviceMsg::SimulateResetPose); + } } impl From for Handedness { diff --git a/components/script/dom/mod.rs b/components/script/dom/mod.rs index ae275631e95..cc5a60c7ef9 100644 --- a/components/script/dom/mod.rs +++ b/components/script/dom/mod.rs @@ -646,6 +646,7 @@ pub mod xrprojectionlayer; pub mod xrquadlayer; pub mod xrray; pub mod xrreferencespace; +pub mod xrreferencespaceevent; pub mod xrrenderstate; pub mod xrrigidtransform; pub mod xrsession; diff --git a/components/script/dom/webidls/FakeXRDevice.webidl b/components/script/dom/webidls/FakeXRDevice.webidl index 00665ceadbd..66027d8627c 100644 --- a/components/script/dom/webidls/FakeXRDevice.webidl +++ b/components/script/dom/webidls/FakeXRDevice.webidl @@ -17,7 +17,7 @@ interface FakeXRDevice { [Throws] undefined setFloorOrigin(FakeXRRigidTransformInit origin); undefined clearFloorOrigin(); [Throws] undefined setBoundsGeometry(sequence boundsCoodinates); - // undefined simulateResetPose(); + undefined simulateResetPose(); // Simulates devices focusing and blurring sessions. undefined simulateVisibilityChange(XRVisibilityState state); diff --git a/components/script/dom/webidls/XRReferenceSpace.webidl b/components/script/dom/webidls/XRReferenceSpace.webidl index f8a1638ef8d..21814883e18 100644 --- a/components/script/dom/webidls/XRReferenceSpace.webidl +++ b/components/script/dom/webidls/XRReferenceSpace.webidl @@ -16,5 +16,5 @@ enum XRReferenceSpaceType { interface XRReferenceSpace : XRSpace { [NewObject] XRReferenceSpace getOffsetReferenceSpace(XRRigidTransform originOffset); - // attribute EventHandler onreset; + attribute EventHandler onreset; }; diff --git a/components/script/dom/webidls/XRReferenceSpaceEvent.webidl b/components/script/dom/webidls/XRReferenceSpaceEvent.webidl new file mode 100644 index 00000000000..af3a646ec1a --- /dev/null +++ b/components/script/dom/webidls/XRReferenceSpaceEvent.webidl @@ -0,0 +1,17 @@ +/* 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/#xrreferencespaceevent-interface + +[SecureContext, Exposed=Window, Pref="dom.webxr.enabled"] +interface XRReferenceSpaceEvent : Event { + [Throws] constructor(DOMString type, XRReferenceSpaceEventInit eventInitDict); + [SameObject] readonly attribute XRReferenceSpace referenceSpace; + [SameObject] readonly attribute XRRigidTransform? transform; +}; + +dictionary XRReferenceSpaceEventInit : EventInit { + required XRReferenceSpace referenceSpace; + XRRigidTransform? transform = null; +}; diff --git a/components/script/dom/xrboundedreferencespace.rs b/components/script/dom/xrboundedreferencespace.rs index 591e3fad124..db890922944 100644 --- a/components/script/dom/xrboundedreferencespace.rs +++ b/components/script/dom/xrboundedreferencespace.rs @@ -19,7 +19,7 @@ use crate::script_runtime::JSContext; #[dom_struct] pub struct XRBoundedReferenceSpace { - xrspace: XRReferenceSpace, + reference_space: XRReferenceSpace, offset: Dom, } @@ -29,7 +29,7 @@ impl XRBoundedReferenceSpace { offset: &XRRigidTransform, ) -> XRBoundedReferenceSpace { XRBoundedReferenceSpace { - xrspace: XRReferenceSpace::new_inherited( + reference_space: XRReferenceSpace::new_inherited( session, offset, XRReferenceSpaceType::Bounded_floor, @@ -55,12 +55,16 @@ impl XRBoundedReferenceSpace { global, ) } + + pub fn reference_space(&self) -> &XRReferenceSpace { + &self.reference_space + } } impl XRBoundedReferenceSpaceMethods for XRBoundedReferenceSpace { /// fn BoundsGeometry(&self, cx: JSContext) -> JSVal { - if let Some(bounds) = self.xrspace.get_bounds() { + if let Some(bounds) = self.reference_space.get_bounds() { let points: Vec> = bounds .into_iter() .map(|point| { diff --git a/components/script/dom/xrreferencespace.rs b/components/script/dom/xrreferencespace.rs index 20f299292e8..62ac8abfddf 100644 --- a/components/script/dom/xrreferencespace.rs +++ b/components/script/dom/xrreferencespace.rs @@ -71,6 +71,10 @@ impl XRReferenceSpace { let offset = self.offset.transform(); Space { base, offset } } + + pub fn ty(&self) -> XRReferenceSpaceType { + self.ty + } } impl XRReferenceSpaceMethods for XRReferenceSpace { @@ -85,6 +89,9 @@ impl XRReferenceSpaceMethods for XRReferenceSpace { &offset, ) } + + // https://www.w3.org/TR/webxr/#dom-xrreferencespace-onreset + event_handler!(reset, GetOnreset, SetOnreset); } impl XRReferenceSpace { diff --git a/components/script/dom/xrreferencespaceevent.rs b/components/script/dom/xrreferencespaceevent.rs new file mode 100644 index 00000000000..075186d91c9 --- /dev/null +++ b/components/script/dom/xrreferencespaceevent.rs @@ -0,0 +1,128 @@ +/* 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 dom_struct::dom_struct; +use js::rust::HandleObject; +use servo_atoms::Atom; + +use crate::dom::bindings::codegen::Bindings::EventBinding::Event_Binding::EventMethods; +use crate::dom::bindings::codegen::Bindings::XRReferenceSpaceEventBinding::{ + XRReferenceSpaceEventInit, XRReferenceSpaceEventMethods, +}; +use crate::dom::bindings::error::Fallible; +use crate::dom::bindings::inheritance::Castable; +use crate::dom::bindings::reflector::{reflect_dom_object_with_proto, DomObject}; +use crate::dom::bindings::root::{Dom, DomRoot}; +use crate::dom::bindings::str::DOMString; +use crate::dom::event::Event; +use crate::dom::globalscope::GlobalScope; +use crate::dom::window::Window; +use crate::dom::xrreferencespace::XRReferenceSpace; +use crate::dom::xrrigidtransform::XRRigidTransform; +use crate::script_runtime::CanGc; + +#[dom_struct] +pub struct XRReferenceSpaceEvent { + event: Event, + space: Dom, + transform: Option>, +} + +impl XRReferenceSpaceEvent { + #[allow(crown::unrooted_must_root)] + fn new_inherited( + space: &XRReferenceSpace, + transform: Option<&XRRigidTransform>, + ) -> XRReferenceSpaceEvent { + XRReferenceSpaceEvent { + event: Event::new_inherited(), + space: Dom::from_ref(space), + transform: transform.map(Dom::from_ref), + } + } + + pub fn new( + global: &GlobalScope, + type_: Atom, + bubbles: bool, + cancelable: bool, + space: &XRReferenceSpace, + transform: Option<&XRRigidTransform>, + ) -> DomRoot { + Self::new_with_proto( + global, + None, + type_, + bubbles, + cancelable, + space, + transform, + CanGc::note(), + ) + } + + fn new_with_proto( + global: &GlobalScope, + proto: Option, + type_: Atom, + bubbles: bool, + cancelable: bool, + space: &XRReferenceSpace, + transform: Option<&XRRigidTransform>, + can_gc: CanGc, + ) -> DomRoot { + let trackevent = reflect_dom_object_with_proto( + Box::new(XRReferenceSpaceEvent::new_inherited(space, transform)), + global, + proto, + can_gc, + ); + { + let event = trackevent.upcast::(); + event.init_event(type_, bubbles, cancelable); + } + trackevent + } + + #[allow(non_snake_case)] + pub fn Constructor( + window: &Window, + proto: Option, + can_gc: CanGc, + type_: DOMString, + init: &XRReferenceSpaceEventInit, + ) -> Fallible> { + Ok(XRReferenceSpaceEvent::new_with_proto( + &window.global(), + proto, + Atom::from(type_), + init.parent.bubbles, + init.parent.cancelable, + &init.referenceSpace, + init.transform.as_deref(), + can_gc, + )) + } +} + +impl XRReferenceSpaceEventMethods for XRReferenceSpaceEvent { + /// + fn ReferenceSpace(&self) -> DomRoot { + DomRoot::from_ref(&*self.space) + } + + /// + fn GetTransform(&self) -> Option> { + if let Some(ref transform) = self.transform { + Some(DomRoot::from_ref(&**transform)) + } else { + None + } + } + + /// + fn IsTrusted(&self) -> bool { + self.event.IsTrusted() + } +} diff --git a/components/script/dom/xrsession.rs b/components/script/dom/xrsession.rs index 9c81013d3a3..43ed08df3d8 100644 --- a/components/script/dom/xrsession.rs +++ b/components/script/dom/xrsession.rs @@ -60,7 +60,9 @@ use crate::dom::xrhittestsource::XRHitTestSource; use crate::dom::xrinputsourcearray::XRInputSourceArray; use crate::dom::xrinputsourceevent::XRInputSourceEvent; use crate::dom::xrreferencespace::XRReferenceSpace; +use crate::dom::xrreferencespaceevent::XRReferenceSpaceEvent; use crate::dom::xrrenderstate::XRRenderState; +use crate::dom::xrrigidtransform::XRRigidTransform; use crate::dom::xrsessionevent::XRSessionEvent; use crate::dom::xrspace::XRSpace; use crate::realms::InRealm; @@ -109,6 +111,7 @@ pub struct XRSession { framerate: Cell, #[ignore_malloc_size_of = "promises are hard"] update_framerate_promise: DomRefCell>>, + reference_spaces: DomRefCell>>, } impl XRSession { @@ -142,6 +145,7 @@ impl XRSession { input_frames: DomRefCell::new(HashMap::new()), framerate: Cell::new(0.0), update_framerate_promise: DomRefCell::new(None), + reference_spaces: DomRefCell::new(Vec::new()), } } @@ -373,6 +377,35 @@ impl XRSession { XREvent::InputChanged(id, frame) => { self.input_frames.borrow_mut().insert(id, frame); }, + XREvent::ReferenceSpaceChanged(base_space, transform) => { + self.reference_spaces + .borrow() + .iter() + .filter(|space| { + let base = match space.ty() { + XRReferenceSpaceType::Local => webxr_api::BaseSpace::Local, + XRReferenceSpaceType::Viewer => webxr_api::BaseSpace::Viewer, + XRReferenceSpaceType::Local_floor => webxr_api::BaseSpace::Floor, + XRReferenceSpaceType::Bounded_floor => { + webxr_api::BaseSpace::BoundedFloor + }, + _ => panic!("unsupported reference space found"), + }; + base == base_space + }) + .for_each(|space| { + let offset = XRRigidTransform::new(&self.global(), transform); + let event = XRReferenceSpaceEvent::new( + &self.global(), + atom!("reset"), + false, + false, + space, + Some(&*offset), + ); + event.upcast::().fire(space.upcast()); + }); + }, } } @@ -829,9 +862,15 @@ impl XRSessionMethods for XRSession { } if ty == XRReferenceSpaceType::Bounded_floor { let space = XRBoundedReferenceSpace::new(&self.global(), self); + self.reference_spaces + .borrow_mut() + .push(Dom::from_ref(space.reference_space())); p.resolve_native(&space); } else { let space = XRReferenceSpace::new(&self.global(), self, ty); + self.reference_spaces + .borrow_mut() + .push(Dom::from_ref(&*space)); p.resolve_native(&space); } }, diff --git a/tests/wpt/meta-legacy-layout/webxr/events_referenceSpace_reset_immersive.https.html.ini b/tests/wpt/meta-legacy-layout/webxr/events_referenceSpace_reset_immersive.https.html.ini deleted file mode 100644 index 7919292fc78..00000000000 --- a/tests/wpt/meta-legacy-layout/webxr/events_referenceSpace_reset_immersive.https.html.ini +++ /dev/null @@ -1,7 +0,0 @@ -[events_referenceSpace_reset_immersive.https.html] - [XRSession resetpose from a device properly fires off the right events for immersive sessions - webgl2] - expected: FAIL - - [XRSession resetpose from a device properly fires off the right events for immersive sessions - webgl] - expected: FAIL - diff --git a/tests/wpt/meta-legacy-layout/webxr/events_referenceSpace_reset_inline.https.html.ini b/tests/wpt/meta-legacy-layout/webxr/events_referenceSpace_reset_inline.https.html.ini deleted file mode 100644 index 192d8334c45..00000000000 --- a/tests/wpt/meta-legacy-layout/webxr/events_referenceSpace_reset_inline.https.html.ini +++ /dev/null @@ -1,7 +0,0 @@ -[events_referenceSpace_reset_inline.https.html] - [XRSession resetpose from a device properly fires off the right events for non-immersive sessions - webgl2] - expected: FAIL - - [XRSession resetpose from a device properly fires off the right events for non-immersive sessions - webgl] - expected: FAIL - diff --git a/tests/wpt/meta-legacy-layout/webxr/idlharness.https.window.js.ini b/tests/wpt/meta-legacy-layout/webxr/idlharness.https.window.js.ini index 167b94c38ff..0e12c8ca0d7 100644 --- a/tests/wpt/meta-legacy-layout/webxr/idlharness.https.window.js.ini +++ b/tests/wpt/meta-legacy-layout/webxr/idlharness.https.window.js.ini @@ -5,30 +5,15 @@ [XR interface: calling supportsSession(XRSessionMode) on navigator.xr with too few arguments must throw TypeError] expected: FAIL - [XRReferenceSpaceEvent interface: attribute referenceSpace] - expected: FAIL - [XR interface: navigator.xr must inherit property "ondevicechange" with the proper type] expected: FAIL - [XRReferenceSpaceEvent interface: existence and properties of interface prototype object] - expected: FAIL - [XRRay interface object length] expected: FAIL [XRRay interface: attribute matrix] expected: FAIL - [XRReferenceSpaceEvent interface object length] - expected: FAIL - - [XRReferenceSpaceEvent interface: existence and properties of interface object] - expected: FAIL - - [XRReferenceSpaceEvent interface: attribute transform] - expected: FAIL - [XRRay interface: attribute direction] expected: FAIL @@ -41,18 +26,9 @@ [XRRay interface: existence and properties of interface object] expected: FAIL - [XRReferenceSpaceEvent interface object name] - expected: FAIL - - [XRReferenceSpaceEvent interface: existence and properties of interface prototype object's @@unscopables property] - expected: FAIL - [XRInputSource interface: attribute gamepad] expected: FAIL - [XRReferenceSpace interface: attribute onreset] - expected: FAIL - [XRRay interface: attribute origin] expected: FAIL @@ -62,9 +38,6 @@ [XRRay interface: existence and properties of interface prototype object] expected: FAIL - [XRReferenceSpaceEvent interface: existence and properties of interface prototype object's "constructor" property] - expected: FAIL - [XR interface: operation requestSession(XRSessionMode, XRSessionInit)] expected: FAIL diff --git a/tests/wpt/meta/webxr/events_referenceSpace_reset_immersive.https.html.ini b/tests/wpt/meta/webxr/events_referenceSpace_reset_immersive.https.html.ini deleted file mode 100644 index 7919292fc78..00000000000 --- a/tests/wpt/meta/webxr/events_referenceSpace_reset_immersive.https.html.ini +++ /dev/null @@ -1,7 +0,0 @@ -[events_referenceSpace_reset_immersive.https.html] - [XRSession resetpose from a device properly fires off the right events for immersive sessions - webgl2] - expected: FAIL - - [XRSession resetpose from a device properly fires off the right events for immersive sessions - webgl] - expected: FAIL - diff --git a/tests/wpt/meta/webxr/events_referenceSpace_reset_inline.https.html.ini b/tests/wpt/meta/webxr/events_referenceSpace_reset_inline.https.html.ini deleted file mode 100644 index 192d8334c45..00000000000 --- a/tests/wpt/meta/webxr/events_referenceSpace_reset_inline.https.html.ini +++ /dev/null @@ -1,7 +0,0 @@ -[events_referenceSpace_reset_inline.https.html] - [XRSession resetpose from a device properly fires off the right events for non-immersive sessions - webgl2] - expected: FAIL - - [XRSession resetpose from a device properly fires off the right events for non-immersive sessions - webgl] - expected: FAIL - diff --git a/tests/wpt/meta/webxr/idlharness.https.window.js.ini b/tests/wpt/meta/webxr/idlharness.https.window.js.ini index 21af20bb1f0..d39170c7376 100644 --- a/tests/wpt/meta/webxr/idlharness.https.window.js.ini +++ b/tests/wpt/meta/webxr/idlharness.https.window.js.ini @@ -5,9 +5,6 @@ [XRSession interface: calling requestReferenceSpace(XRReferenceSpaceType) on xrSession with too few arguments must throw TypeError] expected: FAIL - [XRReferenceSpaceEvent interface: existence and properties of interface prototype object's @@unscopables property] - expected: FAIL - [XRSession interface: xrSession must inherit property "visibilityState" with the proper type] expected: FAIL @@ -20,15 +17,9 @@ [XRWebGLLayer interface: calling getNativeFramebufferScaleFactor(XRSession) on xrWebGLLayer with too few arguments must throw TypeError] expected: FAIL - [XRReferenceSpaceEvent interface: attribute referenceSpace] - expected: FAIL - [XRWebGLLayer interface: xrWebGLLayer must inherit property "antialias" with the proper type] expected: FAIL - [XRReferenceSpaceEvent interface: existence and properties of interface prototype object] - expected: FAIL - [XRSession interface: xrSession must inherit property "requestAnimationFrame(XRFrameRequestCallback)" with the proper type] expected: FAIL @@ -62,12 +53,6 @@ [WebGLRenderingContext includes WebGLRenderingContextOverloads: member names are unique] expected: FAIL - [XRReferenceSpaceEvent interface object name] - expected: FAIL - - [XRReferenceSpaceEvent interface object length] - expected: FAIL - [XRRenderState must be primary interface of xrRenderState] expected: FAIL @@ -86,9 +71,6 @@ [XRReferenceSpace must be primary interface of xrReferenceSpace] expected: FAIL - [XRReferenceSpaceEvent interface: existence and properties of interface object] - expected: FAIL - [XRPermissionStatus interface: attribute granted] expected: FAIL @@ -110,9 +92,6 @@ [idl_test setup] expected: FAIL - [XRReferenceSpaceEvent interface: attribute transform] - expected: FAIL - [XRInputSourcesChangeEvent interface: xrInputSourcesChangeEvent must inherit property "added" with the proper type] expected: FAIL @@ -176,9 +155,6 @@ [XRInputSourcesChangeEvent interface: xrInputSourcesChangeEvent must inherit property "removed" with the proper type] expected: FAIL - [XRReferenceSpace interface: attribute onreset] - expected: FAIL - [XRSession interface: xrSession must inherit property "onsqueeze" with the proper type] expected: FAIL @@ -194,9 +170,6 @@ [Stringification of xrWebGLLayer] expected: FAIL - [XRReferenceSpaceEvent interface: existence and properties of interface prototype object's "constructor" property] - expected: FAIL - [Stringification of xrRenderState] expected: FAIL diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json index d3859f7b1d8..3b385c48413 100644 --- a/tests/wpt/mozilla/meta/MANIFEST.json +++ b/tests/wpt/mozilla/meta/MANIFEST.json @@ -13495,7 +13495,7 @@ ] ], "interfaces.html": [ - "dd0f564f708a2a0e8cf1ed571bd2bd45977fa469", + "086bc095b078efdcac4f51ef314f7851793dbb53", [ null, {} diff --git a/tests/wpt/mozilla/tests/mozilla/interfaces.html b/tests/wpt/mozilla/tests/mozilla/interfaces.html index dd0f564f708..086bc095b07 100644 --- a/tests/wpt/mozilla/tests/mozilla/interfaces.html +++ b/tests/wpt/mozilla/tests/mozilla/interfaces.html @@ -291,6 +291,7 @@ test_interfaces([ "XRLayer", "XRPose", "XRReferenceSpace", + "XRReferenceSpaceEvent", "XRRay", "XRRenderState", "XRRigidTransform",