aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/bindings/conversions.rs5
-rw-r--r--components/script/dom/bindings/root.rs14
-rw-r--r--components/script/dom/dommatrix.rs49
-rw-r--r--components/script/dom/dommatrixreadonly.rs76
-rw-r--r--components/script/dom/fakexrdevice.rs121
-rw-r--r--components/script/dom/fakexrdevicecontroller.rs104
-rw-r--r--components/script/dom/mod.rs2
-rw-r--r--components/script/dom/webidls/DOMMatrix.webidl4
-rw-r--r--components/script/dom/webidls/DOMMatrixReadOnly.webidl4
-rw-r--r--components/script/dom/webidls/FakeXRDevice.webidl57
-rw-r--r--components/script/dom/webidls/FakeXRDeviceController.webidl49
-rw-r--r--components/script/dom/webidls/XRTest.webidl20
-rw-r--r--components/script/dom/window.rs5
-rw-r--r--components/script/dom/xrtest.rs34
14 files changed, 340 insertions, 204 deletions
diff --git a/components/script/dom/bindings/conversions.rs b/components/script/dom/bindings/conversions.rs
index 161354479b6..442648fb9c8 100644
--- a/components/script/dom/bindings/conversions.rs
+++ b/components/script/dom/bindings/conversions.rs
@@ -69,10 +69,7 @@ pub trait IDLInterface {
}
/// A trait to mark an IDL interface as deriving from another one.
-#[cfg_attr(
- feature = "unstable",
- rustc_on_unimplemented(message = "The IDL interface `{Self}` is not derived from `{T}`.")
-)]
+#[rustc_on_unimplemented(message = "The IDL interface `{Self}` is not derived from `{T}`.")]
pub trait DerivedFrom<T: Castable>: Castable {}
impl<T: Float + ToJSValConvertible> ToJSValConvertible for Finite<T> {
diff --git a/components/script/dom/bindings/root.rs b/components/script/dom/bindings/root.rs
index 228015b1275..c87c83a2469 100644
--- a/components/script/dom/bindings/root.rs
+++ b/components/script/dom/bindings/root.rs
@@ -330,13 +330,13 @@ impl<T: DomObject> Deref for Dom<T> {
unsafe impl<T: DomObject> JSTraceable for Dom<T> {
unsafe fn trace(&self, trc: *mut JSTracer) {
- #[cfg(all(feature = "unstable", debug_assertions))]
- let trace_str = format!("for {} on heap", ::std::intrinsics::type_name::<T>());
- #[cfg(all(feature = "unstable", debug_assertions))]
- let trace_info = &trace_str[..];
- #[cfg(not(all(feature = "unstable", debug_assertions)))]
- let trace_info = "for DOM object on heap";
-
+ let trace_string;
+ let trace_info = if cfg!(debug_assertions) {
+ trace_string = format!("for {} on heap", ::std::intrinsics::type_name::<T>());
+ &trace_string[..]
+ } else {
+ "for DOM object on heap"
+ };
trace_reflector(trc, trace_info, (*self.ptr.as_ptr()).reflector());
}
}
diff --git a/components/script/dom/dommatrix.rs b/components/script/dom/dommatrix.rs
index bc57feb14fa..03e152a2f2c 100644
--- a/components/script/dom/dommatrix.rs
+++ b/components/script/dom/dommatrix.rs
@@ -6,14 +6,17 @@ use crate::dom::bindings::codegen::Bindings::DOMMatrixBinding::{
DOMMatrixInit, DOMMatrixMethods, Wrap,
};
use crate::dom::bindings::codegen::Bindings::DOMMatrixReadOnlyBinding::DOMMatrixReadOnlyMethods;
+use crate::dom::bindings::codegen::UnionTypes::StringOrUnrestrictedDoubleSequence;
+use crate::dom::bindings::error;
use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::reflector::reflect_dom_object;
use crate::dom::bindings::root::DomRoot;
use crate::dom::dommatrixreadonly::{
- dommatrixinit_to_matrix, entries_to_matrix, DOMMatrixReadOnly,
+ dommatrixinit_to_matrix, entries_to_matrix, transform_to_matrix, DOMMatrixReadOnly,
};
use crate::dom::globalscope::GlobalScope;
+use crate::dom::window::Window;
use dom_struct::dom_struct;
use euclid::Transform3D;
use js::rust::CustomAutoRooterGuard;
@@ -37,14 +40,32 @@ impl DOMMatrix {
}
}
- // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-dommatrix
- pub fn Constructor(global: &GlobalScope) -> Fallible<DomRoot<Self>> {
- Self::Constructor_(global, vec![1.0, 0.0, 0.0, 1.0, 0.0, 0.0])
- }
-
- // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-dommatrix-numbersequence
- pub fn Constructor_(global: &GlobalScope, entries: Vec<f64>) -> Fallible<DomRoot<Self>> {
- entries_to_matrix(&entries[..]).map(|(is2D, matrix)| Self::new(global, is2D, matrix))
+ // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-dommatrixreadonly
+ pub fn Constructor(
+ global: &GlobalScope,
+ init: Option<StringOrUnrestrictedDoubleSequence>,
+ ) -> Fallible<DomRoot<Self>> {
+ if init.is_none() {
+ return Ok(Self::new(global, true, Transform3D::identity()));
+ }
+ match init.unwrap() {
+ StringOrUnrestrictedDoubleSequence::String(ref s) => {
+ if global.downcast::<Window>().is_none() {
+ return Err(error::Error::Type(
+ "String constructor is only supported in the main thread.".to_owned(),
+ ));
+ }
+ if s.is_empty() {
+ return Ok(Self::new(global, true, Transform3D::identity()));
+ }
+ transform_to_matrix(s.to_string())
+ .map(|(is2D, matrix)| Self::new(global, is2D, matrix))
+ },
+ StringOrUnrestrictedDoubleSequence::UnrestrictedDoubleSequence(ref entries) => {
+ entries_to_matrix(&entries[..])
+ .map(|(is2D, matrix)| Self::new(global, is2D, matrix))
+ },
+ }
}
// https://drafts.fxtf.org/geometry-1/#dom-dommatrix-frommatrix
@@ -62,7 +83,10 @@ impl DOMMatrix {
array: CustomAutoRooterGuard<Float32Array>,
) -> Fallible<DomRoot<DOMMatrix>> {
let vec: Vec<f64> = array.to_vec().iter().map(|&x| x as f64).collect();
- DOMMatrix::Constructor_(global, vec)
+ DOMMatrix::Constructor(
+ global,
+ Some(StringOrUnrestrictedDoubleSequence::UnrestrictedDoubleSequence(vec)),
+ )
}
// https://drafts.fxtf.org/geometry-1/#dom-dommatrix-fromfloat64array
@@ -71,7 +95,10 @@ impl DOMMatrix {
array: CustomAutoRooterGuard<Float64Array>,
) -> Fallible<DomRoot<DOMMatrix>> {
let vec: Vec<f64> = array.to_vec();
- DOMMatrix::Constructor_(global, vec)
+ DOMMatrix::Constructor(
+ global,
+ Some(StringOrUnrestrictedDoubleSequence::UnrestrictedDoubleSequence(vec)),
+ )
}
}
diff --git a/components/script/dom/dommatrixreadonly.rs b/components/script/dom/dommatrixreadonly.rs
index 010f823e78c..fae6afe1649 100644
--- a/components/script/dom/dommatrixreadonly.rs
+++ b/components/script/dom/dommatrixreadonly.rs
@@ -8,13 +8,17 @@ use crate::dom::bindings::codegen::Bindings::DOMMatrixReadOnlyBinding::{
DOMMatrixReadOnlyMethods, Wrap,
};
use crate::dom::bindings::codegen::Bindings::DOMPointBinding::DOMPointInit;
+use crate::dom::bindings::codegen::UnionTypes::StringOrUnrestrictedDoubleSequence;
use crate::dom::bindings::error;
use crate::dom::bindings::error::Fallible;
+use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::DomRoot;
use crate::dom::dommatrix::DOMMatrix;
use crate::dom::dompoint::DOMPoint;
use crate::dom::globalscope::GlobalScope;
+use crate::dom::window::Window;
+use cssparser::{Parser, ParserInput};
use dom_struct::dom_struct;
use euclid::{Angle, Transform3D};
use js::jsapi::{JSContext, JSObject};
@@ -25,6 +29,7 @@ use std::cell::{Cell, Ref};
use std::f64;
use std::ptr;
use std::ptr::NonNull;
+use style::parser::ParserContext;
#[dom_struct]
pub struct DOMMatrixReadOnly {
@@ -49,13 +54,31 @@ impl DOMMatrixReadOnly {
}
// https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-dommatrixreadonly
- pub fn Constructor(global: &GlobalScope) -> Fallible<DomRoot<Self>> {
- Ok(Self::new(global, true, Transform3D::identity()))
- }
-
- // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-dommatrixreadonly-numbersequence
- pub fn Constructor_(global: &GlobalScope, entries: Vec<f64>) -> Fallible<DomRoot<Self>> {
- entries_to_matrix(&entries[..]).map(|(is2D, matrix)| Self::new(global, is2D, matrix))
+ pub fn Constructor(
+ global: &GlobalScope,
+ init: Option<StringOrUnrestrictedDoubleSequence>,
+ ) -> Fallible<DomRoot<Self>> {
+ if init.is_none() {
+ return Ok(Self::new(global, true, Transform3D::identity()));
+ }
+ match init.unwrap() {
+ StringOrUnrestrictedDoubleSequence::String(ref s) => {
+ if global.downcast::<Window>().is_none() {
+ return Err(error::Error::Type(
+ "String constructor is only supported in the main thread.".to_owned(),
+ ));
+ }
+ if s.is_empty() {
+ return Ok(Self::new(global, true, Transform3D::identity()));
+ }
+ transform_to_matrix(s.to_string())
+ .map(|(is2D, matrix)| Self::new(global, is2D, matrix))
+ },
+ StringOrUnrestrictedDoubleSequence::UnrestrictedDoubleSequence(ref entries) => {
+ entries_to_matrix(&entries[..])
+ .map(|(is2D, matrix)| Self::new(global, is2D, matrix))
+ },
+ }
}
// https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-frommatrix
@@ -372,7 +395,10 @@ impl DOMMatrixReadOnly {
array: CustomAutoRooterGuard<Float32Array>,
) -> Fallible<DomRoot<DOMMatrixReadOnly>> {
let vec: Vec<f64> = array.to_vec().iter().map(|&x| x as f64).collect();
- DOMMatrixReadOnly::Constructor_(global, vec)
+ DOMMatrixReadOnly::Constructor(
+ global,
+ Some(StringOrUnrestrictedDoubleSequence::UnrestrictedDoubleSequence(vec)),
+ )
}
// https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-fromfloat64array
@@ -382,7 +408,10 @@ impl DOMMatrixReadOnly {
array: CustomAutoRooterGuard<Float64Array>,
) -> Fallible<DomRoot<DOMMatrixReadOnly>> {
let vec: Vec<f64> = array.to_vec();
- DOMMatrixReadOnly::Constructor_(global, vec)
+ DOMMatrixReadOnly::Constructor(
+ global,
+ Some(StringOrUnrestrictedDoubleSequence::UnrestrictedDoubleSequence(vec)),
+ )
}
}
@@ -759,3 +788,32 @@ fn normalize_point(x: f64, y: f64, z: f64) -> (f64, f64, f64) {
(x / len, y / len, z / len)
}
}
+
+pub fn transform_to_matrix(value: String) -> Fallible<(bool, Transform3D<f64>)> {
+ use style::properties::longhands::transform;
+
+ let mut input = ParserInput::new(&value);
+ let mut parser = Parser::new(&mut input);
+ let url = ::servo_url::ServoUrl::parse("about:blank").unwrap();
+ let context = ParserContext::new(
+ ::style::stylesheets::Origin::Author,
+ &url,
+ Some(::style::stylesheets::CssRuleType::Style),
+ ::style_traits::ParsingMode::DEFAULT,
+ ::style::context::QuirksMode::NoQuirks,
+ None,
+ None,
+ );
+
+ let transform = match parser.parse_entirely(|t| transform::parse(&context, t)) {
+ Ok(result) => result,
+ Err(..) => return Err(error::Error::Syntax),
+ };
+
+ let (m, is_3d) = match transform.to_transform_3d_matrix_f64(None) {
+ Ok(result) => result,
+ Err(..) => return Err(error::Error::Syntax),
+ };
+
+ Ok((!is_3d, m))
+}
diff --git a/components/script/dom/fakexrdevice.rs b/components/script/dom/fakexrdevice.rs
new file mode 100644
index 00000000000..070ba5fa89c
--- /dev/null
+++ b/components/script/dom/fakexrdevice.rs
@@ -0,0 +1,121 @@
+/* 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::FakeXRDeviceBinding::{
+ self, FakeXRDeviceMethods, FakeXRRigidTransformInit, FakeXRViewInit,
+};
+use crate::dom::bindings::codegen::Bindings::XRViewBinding::XREye;
+use crate::dom::bindings::error::{Error, Fallible};
+use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
+use crate::dom::bindings::root::DomRoot;
+use crate::dom::globalscope::GlobalScope;
+use dom_struct::dom_struct;
+use webvr_traits::{MockVRControlMsg, MockVRView, WebVRMsg};
+
+#[dom_struct]
+pub struct FakeXRDevice {
+ reflector: Reflector,
+}
+
+impl FakeXRDevice {
+ pub fn new_inherited() -> FakeXRDevice {
+ FakeXRDevice {
+ reflector: Reflector::new(),
+ }
+ }
+
+ pub fn new(global: &GlobalScope) -> DomRoot<FakeXRDevice> {
+ reflect_dom_object(
+ Box::new(FakeXRDevice::new_inherited()),
+ global,
+ FakeXRDeviceBinding::Wrap,
+ )
+ }
+
+ fn send_msg(&self, msg: MockVRControlMsg) {
+ self.global()
+ .as_window()
+ .webvr_thread()
+ .unwrap()
+ .send(WebVRMsg::MessageMockDisplay(msg))
+ .unwrap();
+ }
+}
+
+pub fn get_views(views: &[FakeXRViewInit]) -> Fallible<(MockVRView, MockVRView)> {
+ if views.len() != 2 {
+ return Err(Error::NotSupported);
+ }
+
+ let (left, right) = match (views[0].eye, views[1].eye) {
+ (XREye::Left, XREye::Right) => (&views[0], &views[1]),
+ (XREye::Right, XREye::Left) => (&views[1], &views[0]),
+ _ => return Err(Error::NotSupported),
+ };
+
+ if left.projectionMatrix.len() != 16 ||
+ right.projectionMatrix.len() != 16 ||
+ left.viewOffset.position.len() != 3 ||
+ right.viewOffset.position.len() != 3
+ {
+ return Err(Error::Type("Incorrectly sized array".into()));
+ }
+
+ let mut proj_l = [0.; 16];
+ let mut proj_r = [0.; 16];
+ let v: Vec<_> = left.projectionMatrix.iter().map(|x| **x).collect();
+ proj_l.copy_from_slice(&v);
+ let v: Vec<_> = right.projectionMatrix.iter().map(|x| **x).collect();
+ proj_r.copy_from_slice(&v);
+
+ let mut offset_l = [0.; 3];
+ let mut offset_r = [0.; 3];
+ let v: Vec<_> = left.viewOffset.position.iter().map(|x| **x).collect();
+ offset_l.copy_from_slice(&v);
+ let v: Vec<_> = right.viewOffset.position.iter().map(|x| **x).collect();
+ offset_r.copy_from_slice(&v);
+ let left = MockVRView {
+ projection: proj_l,
+ offset: offset_l,
+ };
+ let right = MockVRView {
+ projection: proj_r,
+ offset: offset_r,
+ };
+ Ok((left, right))
+}
+
+pub fn get_origin(origin: &FakeXRRigidTransformInit) -> Fallible<([f32; 3], [f32; 4])> {
+ if origin.position.len() != 3 || origin.orientation.len() != 4 {
+ return Err(Error::Type("Incorrectly sized array".into()));
+ }
+ let mut p = [0.; 3];
+ let mut o = [0.; 4];
+ let v: Vec<_> = origin.position.iter().map(|x| **x).collect();
+ p.copy_from_slice(&v[0..3]);
+ let v: Vec<_> = origin.orientation.iter().map(|x| **x).collect();
+ o.copy_from_slice(&v);
+
+ Ok((p, o))
+}
+
+impl FakeXRDeviceMethods for FakeXRDevice {
+ /// https://github.com/immersive-web/webxr-test-api/blob/master/explainer.md
+ fn SetViews(&self, views: Vec<FakeXRViewInit>) -> Fallible<()> {
+ let (left, right) = get_views(&views)?;
+ self.send_msg(MockVRControlMsg::SetViews(left, right));
+ Ok(())
+ }
+
+ /// https://github.com/immersive-web/webxr-test-api/blob/master/explainer.md
+ fn SetViewerOrigin(
+ &self,
+ origin: &FakeXRRigidTransformInit,
+ _emulated_position: bool,
+ ) -> Fallible<()> {
+ let (position, orientation) = get_origin(origin)?;
+ self.send_msg(MockVRControlMsg::SetViewerPose(position, orientation));
+ Ok(())
+ }
+}
diff --git a/components/script/dom/fakexrdevicecontroller.rs b/components/script/dom/fakexrdevicecontroller.rs
deleted file mode 100644
index a7ed2833716..00000000000
--- a/components/script/dom/fakexrdevicecontroller.rs
+++ /dev/null
@@ -1,104 +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/. */
-
-/* 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::FakeXRDeviceControllerBinding::{
- self, FakeXRDeviceControllerMethods, FakeXRRigidTransform, FakeXRViewInit,
-};
-use crate::dom::bindings::codegen::Bindings::XRViewBinding::XREye;
-use crate::dom::bindings::error::{Error, Fallible};
-use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
-use crate::dom::bindings::root::DomRoot;
-use crate::dom::globalscope::GlobalScope;
-use dom_struct::dom_struct;
-use webvr_traits::{MockVRControlMsg, WebVREyeParameters, WebVRMsg};
-
-#[dom_struct]
-pub struct FakeXRDeviceController {
- reflector: Reflector,
-}
-
-impl FakeXRDeviceController {
- pub fn new_inherited() -> FakeXRDeviceController {
- FakeXRDeviceController {
- reflector: Reflector::new(),
- }
- }
-
- pub fn new(global: &GlobalScope) -> DomRoot<FakeXRDeviceController> {
- reflect_dom_object(
- Box::new(FakeXRDeviceController::new_inherited()),
- global,
- FakeXRDeviceControllerBinding::Wrap,
- )
- }
-
- pub fn send_msg(&self, msg: MockVRControlMsg) {
- self.global()
- .as_window()
- .webvr_thread()
- .unwrap()
- .send(WebVRMsg::MessageMockDisplay(msg))
- .unwrap();
- }
-}
-
-impl FakeXRDeviceControllerMethods for FakeXRDeviceController {
- /// https://github.com/immersive-web/webxr-test-api/blob/master/explainer.md
- fn SetViews(&self, views: Vec<FakeXRViewInit>) -> Fallible<()> {
- if views.len() != 2 {
- return Err(Error::NotSupported);
- }
-
- let (left, right) = match (views[0].eye, views[1].eye) {
- (XREye::Left, XREye::Right) => (&views[0], &views[1]),
- (XREye::Right, XREye::Left) => (&views[1], &views[0]),
- _ => return Err(Error::NotSupported),
- };
-
- if left.projectionMatrix.len() != 16 ||
- right.projectionMatrix.len() != 16 ||
- left.viewOffset.position.len() != 3 ||
- right.viewOffset.position.len() != 3
- {
- return Err(Error::Type("Incorrectly sized array".into()));
- }
-
- let mut proj_l = [0.; 16];
- let mut proj_r = [0.; 16];
- let v: Vec<_> = left.projectionMatrix.iter().map(|x| **x).collect();
- proj_l.copy_from_slice(&v);
- let v: Vec<_> = right.projectionMatrix.iter().map(|x| **x).collect();
- proj_r.copy_from_slice(&v);
-
- let mut params_l = WebVREyeParameters::default();
- let mut params_r = WebVREyeParameters::default();
- let v: Vec<_> = left.viewOffset.position.iter().map(|x| **x).collect();
- params_l.offset.copy_from_slice(&v);
- let v: Vec<_> = right.viewOffset.position.iter().map(|x| **x).collect();
- params_r.offset.copy_from_slice(&v);
-
- self.send_msg(MockVRControlMsg::SetProjectionMatrices(proj_l, proj_r));
- self.send_msg(MockVRControlMsg::SetEyeParameters(params_l, params_r));
- Ok(())
- }
-
- /// https://github.com/immersive-web/webxr-test-api/blob/master/explainer.md
- fn SetViewerOrigin(&self, origin: &FakeXRRigidTransform) -> Fallible<()> {
- if origin.position.len() != 4 || origin.orientation.len() != 4 {
- return Err(Error::Type("Incorrectly sized array".into()));
- }
- let mut position = [0.; 3];
- let mut orientation = [0.; 4];
- let v: Vec<_> = origin.position.iter().map(|x| **x).collect();
- position.copy_from_slice(&v[0..3]);
- let v: Vec<_> = origin.orientation.iter().map(|x| **x).collect();
- orientation.copy_from_slice(&v);
- self.send_msg(MockVRControlMsg::SetViewerPose(position, orientation));
- Ok(())
- }
-}
diff --git a/components/script/dom/mod.rs b/components/script/dom/mod.rs
index 77729567558..d20b68c92b7 100644
--- a/components/script/dom/mod.rs
+++ b/components/script/dom/mod.rs
@@ -301,7 +301,7 @@ pub mod eventsource;
pub mod eventtarget;
pub mod extendableevent;
pub mod extendablemessageevent;
-pub mod fakexrdevicecontroller;
+pub mod fakexrdevice;
pub mod file;
pub mod filelist;
pub mod filereader;
diff --git a/components/script/dom/webidls/DOMMatrix.webidl b/components/script/dom/webidls/DOMMatrix.webidl
index 6facefec056..d617f20af99 100644
--- a/components/script/dom/webidls/DOMMatrix.webidl
+++ b/components/script/dom/webidls/DOMMatrix.webidl
@@ -10,9 +10,7 @@
* related or neighboring rights to this work.
*/
-[Constructor,
- // Constructor(DOMString transformList),
- Constructor(sequence<unrestricted double> numberSequence),
+[Constructor(optional (DOMString or sequence<unrestricted double>) init),
Exposed=(Window,Worker)]
interface DOMMatrix : DOMMatrixReadOnly {
diff --git a/components/script/dom/webidls/DOMMatrixReadOnly.webidl b/components/script/dom/webidls/DOMMatrixReadOnly.webidl
index 2382275e249..dcd9229b3d7 100644
--- a/components/script/dom/webidls/DOMMatrixReadOnly.webidl
+++ b/components/script/dom/webidls/DOMMatrixReadOnly.webidl
@@ -10,9 +10,7 @@
* related or neighboring rights to this work.
*/
-[Constructor,
- // Constructor(DOMString transformList)
- Constructor(sequence<unrestricted double> numberSequence),
+[Constructor(optional (DOMString or sequence<unrestricted double>) init),
Exposed=(Window,Worker)]
interface DOMMatrixReadOnly {
diff --git a/components/script/dom/webidls/FakeXRDevice.webidl b/components/script/dom/webidls/FakeXRDevice.webidl
new file mode 100644
index 00000000000..5e310c4d75f
--- /dev/null
+++ b/components/script/dom/webidls/FakeXRDevice.webidl
@@ -0,0 +1,57 @@
+/* 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://github.com/immersive-web/webxr-test-api/
+
+[Exposed=Window, Pref="dom.webxr.test"]
+interface FakeXRDevice {
+ // Sets the values to be used for subsequent
+ // requestAnimationFrame() callbacks.
+ [Throws] void setViews(sequence<FakeXRViewInit> views);
+
+ // // behaves as if device was disconnected
+ // Promise<void> disconnect();
+
+ // Sets the origin of the viewer
+ [Throws] void setViewerOrigin(FakeXRRigidTransformInit origin, optional boolean emulatedPosition = false);
+
+ // // Simulates devices focusing and blurring sessions.
+ // void simulateVisibilityChange(XRVisibilityState);
+
+ // void setBoundsGeometry(sequence<FakeXRBoundsPoint> boundsCoodinates);
+ // // Sets eye level used for calculating floor-level spaces
+ // void setEyeLevel(float eyeLevel);
+
+
+ // Promise<FakeXRInputController>
+ // simulateInputSourceConnection(FakeXRInputSourceInit);
+};
+
+// https://immersive-web.github.io/webxr/#dom-xrwebgllayer-getviewport
+dictionary FakeXRViewInit {
+ required XREye eye;
+ // https://immersive-web.github.io/webxr/#view-projection-matrix
+ required sequence<float> projectionMatrix;
+ // https://immersive-web.github.io/webxr/#view-offset
+ required FakeXRRigidTransformInit viewOffset;
+ // https://immersive-web.github.io/webxr/#dom-xrwebgllayer-getviewport
+ required FakeXRViewportInit viewport;
+};
+
+// https://immersive-web.github.io/webxr/#xrviewport
+dictionary FakeXRViewportInit {
+ required long x;
+ required long y;
+ required long width;
+ required long height;
+};
+
+dictionary FakeXRBoundsPoint {
+ double x; double z;
+};
+
+dictionary FakeXRRigidTransformInit {
+ required sequence<float> position;
+ required sequence<float> orientation;
+};
diff --git a/components/script/dom/webidls/FakeXRDeviceController.webidl b/components/script/dom/webidls/FakeXRDeviceController.webidl
deleted file mode 100644
index cacdb2f9819..00000000000
--- a/components/script/dom/webidls/FakeXRDeviceController.webidl
+++ /dev/null
@@ -1,49 +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://github.com/immersive-web/webxr-test-api/
-
-[Exposed=Window, Pref="dom.webxr.test"]
-interface FakeXRDeviceController {
- // Creates and attaches a XRFrameOfReference of the type specified to the device.
- // void setFrameOfReference(XRFrameOfReferenceType, FakeXRFrameOfReferenceInit);
-
- // // Sets the values to be used for subsequent
- // // requestAnimationFrame() callbacks.
- [Throws] void setViews(sequence<FakeXRViewInit> views);
-
- [Throws] void setViewerOrigin(FakeXRRigidTransform origin);
-
- // Simulates the user activating the reset pose on a device.
- // void simulateResetPose();
-
- // Simulates the platform ending the sessions.
- // void simulateForcedEndSessions();
-
- // Simulates devices focusing and blurring sessions.
- // void simulateBlurSession(XRSession);
- // void simulateFocusSession(XRSession);
-
- // void setBoundsGeometry(Array<FakeXRBoundsPoint> boundsCoodinates)l
-
- // Promise<FakeXRInputSourceController>
- // simulateInputSourceConnection(FakeXRInputSourceInit);
-};
-
-dictionary FakeXRViewInit {
- required XREye eye;
- // https://immersive-web.github.io/webxr/#view-projection-matrix
- required sequence<float> projectionMatrix;
- // https://immersive-web.github.io/webxr/#view-offset
- required FakeXRRigidTransform viewOffset;
-};
-
-dictionary FakeXRBoundsPoint {
- double x; double z;
-};
-
-dictionary FakeXRRigidTransform {
- required sequence<float> position;
- required sequence<float> orientation;
-};
diff --git a/components/script/dom/webidls/XRTest.webidl b/components/script/dom/webidls/XRTest.webidl
index 30c485321d4..f74b9b82331 100644
--- a/components/script/dom/webidls/XRTest.webidl
+++ b/components/script/dom/webidls/XRTest.webidl
@@ -8,18 +8,28 @@
interface XRTest {
// Simulates connecting a device to the system.
// Used to instantiate a fake device for use in tests.
- Promise<FakeXRDeviceController> simulateDeviceConnection(FakeXRDeviceInit init);
-
- // // Simulates a device being disconnected from the system.
- // Promise<void> simulateDeviceDisconnection(XRDevice);
+ Promise<FakeXRDevice> simulateDeviceConnection(FakeXRDeviceInit init);
// // Simulates a user activation (aka user gesture) for the current scope.
// // The activation is only guaranteed to be valid in the provided function and only applies to WebXR
// // Device API methods.
// void simulateUserActivation(Function);
+
+ // // Disconnect all fake devices
+ // Promise<void> disconnectAllDevices();
};
dictionary FakeXRDeviceInit {
- // TODO: Subject to change to match spec changes.
required boolean supportsImmersive;
+ required sequence<FakeXRViewInit> views;
+
+ boolean supportsUnbounded = false;
+ // Whether the space supports tracking in inline sessions
+ boolean supportsTrackingInInline = true;
+ // The bounds coordinates. If null, bounded reference spaces are not supported.
+ sequence<FakeXRBoundsPoint> boundsCoodinates;
+ // Eye level used for calculating floor-level spaces
+ float eyeLevel = 1.5;
+ FakeXRRigidTransformInit viewerOrigin;
};
+
diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs
index a1afdc34a82..596fd711599 100644
--- a/components/script/dom/window.rs
+++ b/components/script/dom/window.rs
@@ -938,10 +938,7 @@ impl WindowMethods for Window {
#[allow(unsafe_code)]
fn Trap(&self) {
- #[cfg(feature = "unstable")]
- unsafe {
- ::std::intrinsics::breakpoint()
- }
+ unsafe { ::std::intrinsics::breakpoint() }
}
#[allow(unsafe_code)]
diff --git a/components/script/dom/xrtest.rs b/components/script/dom/xrtest.rs
index 07fac9d6a89..6808ce262cd 100644
--- a/components/script/dom/xrtest.rs
+++ b/components/script/dom/xrtest.rs
@@ -11,13 +11,13 @@ use crate::dom::bindings::codegen::Bindings::XRTestBinding::{
};
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::DomRoot;
-use crate::dom::fakexrdevicecontroller::FakeXRDeviceController;
+use crate::dom::fakexrdevice::{get_origin, get_views, FakeXRDevice};
use crate::dom::globalscope::GlobalScope;
use crate::dom::promise::Promise;
use dom_struct::dom_struct;
use std::cell::Cell;
use std::rc::Rc;
-use webvr_traits::WebVRMsg;
+use webvr_traits::{MockVRInit, WebVRMsg};
#[dom_struct]
pub struct XRTest {
@@ -52,14 +52,40 @@ impl XRTestMethods for XRTest {
return p;
}
+ let origin = if let Some(ref o) = init.viewerOrigin {
+ match get_origin(&o) {
+ Ok(origin) => origin,
+ Err(e) => {
+ p.reject_error(e);
+ return p;
+ },
+ }
+ } else {
+ Default::default()
+ };
+
+ let views = match get_views(&init.views) {
+ Ok(views) => views,
+ Err(e) => {
+ p.reject_error(e);
+ return p;
+ },
+ };
+
+ let init = MockVRInit {
+ viewer_origin: Some(origin),
+ views: Some(views),
+ eye_level: None,
+ };
+
self.session_started.set(true);
self.global()
.as_window()
.webvr_thread()
.unwrap()
- .send(WebVRMsg::CreateMockDisplay)
+ .send(WebVRMsg::CreateMockDisplay(init))
.unwrap();
- p.resolve_native(&FakeXRDeviceController::new(&self.global()));
+ p.resolve_native(&FakeXRDevice::new(&self.global()));
p
}