diff --git a/components/script/dom/domrect.rs b/components/script/dom/domrect.rs index 0a169570867..5ab05b94ef4 100644 --- a/components/script/dom/domrect.rs +++ b/components/script/dom/domrect.rs @@ -6,11 +6,13 @@ use dom_struct::dom_struct; use js::rust::HandleObject; use crate::dom::bindings::codegen::Bindings::DOMRectBinding::DOMRectMethods; -use crate::dom::bindings::codegen::Bindings::DOMRectReadOnlyBinding::DOMRectReadOnlyMethods; +use crate::dom::bindings::codegen::Bindings::DOMRectReadOnlyBinding::{ + DOMRectInit, DOMRectReadOnlyMethods, +}; use crate::dom::bindings::error::Fallible; -use crate::dom::bindings::reflector::reflect_dom_object_with_proto; +use crate::dom::bindings::reflector::{reflect_dom_object, reflect_dom_object_with_proto}; use crate::dom::bindings::root::DomRoot; -use crate::dom::domrectreadonly::DOMRectReadOnly; +use crate::dom::domrectreadonly::{create_a_domrectreadonly_from_the_dictionary, DOMRectReadOnly}; use crate::dom::globalscope::GlobalScope; use crate::script_runtime::CanGc; @@ -71,6 +73,14 @@ impl DOMRectMethods for DOMRect { )) } + // https://drafts.fxtf.org/geometry/#dom-domrect-fromrect + #[allow(crown::unrooted_must_root)] + fn FromRect(global: &GlobalScope, other: &DOMRectInit) -> DomRoot { + let rect = create_a_domrectreadonly_from_the_dictionary(other); + + reflect_dom_object(Box::new(Self { rect }), global) + } + // https://drafts.fxtf.org/geometry/#dom-domrect-x fn X(&self) -> f64 { self.rect.X() diff --git a/components/script/dom/domrectreadonly.rs b/components/script/dom/domrectreadonly.rs index ddda17bb7c2..125122853af 100644 --- a/components/script/dom/domrectreadonly.rs +++ b/components/script/dom/domrectreadonly.rs @@ -7,9 +7,13 @@ use std::cell::Cell; use dom_struct::dom_struct; use js::rust::HandleObject; -use crate::dom::bindings::codegen::Bindings::DOMRectReadOnlyBinding::DOMRectReadOnlyMethods; +use crate::dom::bindings::codegen::Bindings::DOMRectReadOnlyBinding::{ + DOMRectInit, DOMRectReadOnlyMethods, +}; use crate::dom::bindings::error::Fallible; -use crate::dom::bindings::reflector::{reflect_dom_object_with_proto, Reflector}; +use crate::dom::bindings::reflector::{ + reflect_dom_object, reflect_dom_object_with_proto, Reflector, +}; use crate::dom::bindings::root::DomRoot; use crate::dom::globalscope::GlobalScope; use crate::script_runtime::CanGc; @@ -84,6 +88,14 @@ impl DOMRectReadOnlyMethods for DOMRectReadOnly { )) } + // https://drafts.fxtf.org/geometry/#dom-domrectreadonly-fromrect + #[allow(crown::unrooted_must_root)] + fn FromRect(global: &GlobalScope, other: &DOMRectInit) -> DomRoot { + let dom_rect = create_a_domrectreadonly_from_the_dictionary(other); + + reflect_dom_object(Box::new(dom_rect), global) + } + // https://drafts.fxtf.org/geometry/#dom-domrectreadonly-x fn X(&self) -> f64 { self.x.get() @@ -144,3 +156,25 @@ impl DOMRectReadOnlyMethods for DOMRectReadOnly { } } } + +/// +#[allow(crown::unrooted_must_root)] +pub(super) fn create_a_domrectreadonly_from_the_dictionary(other: &DOMRectInit) -> DOMRectReadOnly { + // NOTE: We trivially combine all three steps into one + + // Step 1. Let rect be a new DOMRectReadOnly or DOMRect as appropriate. + + // Step 2. Set rect’s variables x coordinate to other’s x dictionary member, y coordinate to other’s y + // dictionary member, width dimension to other’s width dictionary member and height dimension to + // other’s height dictionary member. + + // Step 3. Return rect. + + DOMRectReadOnly { + reflector_: Reflector::new(), + x: Cell::new(other.x), + y: Cell::new(other.y), + width: Cell::new(other.width), + height: Cell::new(other.height), + } +} diff --git a/components/script/dom/webidls/DOMRect.webidl b/components/script/dom/webidls/DOMRect.webidl index 0aabed6d93f..aee406502fc 100644 --- a/components/script/dom/webidls/DOMRect.webidl +++ b/components/script/dom/webidls/DOMRect.webidl @@ -2,11 +2,17 @@ * 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/. */ -[Exposed=(Window,Worker)] // https://drafts.fxtf.org/geometry/#domrect + +[Exposed=(Window,Worker), + Serializable, + LegacyWindowAlias=SVGRect] interface DOMRect : DOMRectReadOnly { [Throws] constructor(optional unrestricted double x = 0, optional unrestricted double y = 0, optional unrestricted double width = 0, optional unrestricted double height = 0); + + [NewObject] static DOMRect fromRect(optional DOMRectInit other = {}); + inherit attribute unrestricted double x; inherit attribute unrestricted double y; inherit attribute unrestricted double width; diff --git a/components/script/dom/webidls/DOMRectReadOnly.webidl b/components/script/dom/webidls/DOMRectReadOnly.webidl index 9885841c73a..b8bc3057675 100644 --- a/components/script/dom/webidls/DOMRectReadOnly.webidl +++ b/components/script/dom/webidls/DOMRectReadOnly.webidl @@ -2,12 +2,15 @@ * 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/. */ -[Exposed=(Window,Worker)] // https://drafts.fxtf.org/geometry/#domrect + +[Exposed=(Window,Worker), + Serializable] interface DOMRectReadOnly { [Throws] constructor(optional unrestricted double x = 0, optional unrestricted double y = 0, optional unrestricted double width = 0, optional unrestricted double height = 0); - // [NewObject] static DOMRectReadOnly fromRect(optional DOMRectInit other); + + [NewObject] static DOMRectReadOnly fromRect(optional DOMRectInit other = {}); readonly attribute unrestricted double x; readonly attribute unrestricted double y; diff --git a/tests/wpt/meta/css/geometry/DOMRect-002.html.ini b/tests/wpt/meta/css/geometry/DOMRect-002.html.ini deleted file mode 100644 index ddbfc5eeccf..00000000000 --- a/tests/wpt/meta/css/geometry/DOMRect-002.html.ini +++ /dev/null @@ -1,6 +0,0 @@ -[DOMRect-002.html] - [DOMRect.fromRect] - expected: FAIL - - [DOMRectReadOnly.fromRect] - expected: FAIL diff --git a/tests/wpt/meta/css/geometry/idlharness.any.js.ini b/tests/wpt/meta/css/geometry/idlharness.any.js.ini index 2c25f767d0e..d0c6cb5d66a 100644 --- a/tests/wpt/meta/css/geometry/idlharness.any.js.ini +++ b/tests/wpt/meta/css/geometry/idlharness.any.js.ini @@ -1,28 +1,13 @@ [idlharness.any.worker.html] - [DOMRectReadOnly interface: operation fromRect(optional DOMRectInit)] - expected: FAIL - [DOMPointReadOnly interface: calling matrixTransform(optional DOMMatrixInit) on new DOMPoint() with too few arguments must throw TypeError] expected: FAIL [DOMPointReadOnly interface: operation matrixTransform(optional DOMMatrixInit)] expected: FAIL - [DOMRect interface: operation fromRect(optional DOMRectInit)] - expected: FAIL - [DOMPointReadOnly interface: new DOMPoint() must inherit property "matrixTransform(optional DOMMatrixInit)" with the proper type] expected: FAIL - [DOMRectReadOnly interface: calling fromRect(optional DOMRectInit) on new DOMRect() with too few arguments must throw TypeError] - expected: FAIL - - [DOMRect interface: calling fromRect(optional DOMRectInit) on new DOMRect() with too few arguments must throw TypeError] - expected: FAIL - - [DOMRectReadOnly interface: calling fromRect(optional DOMRectInit) on new DOMRectReadOnly() with too few arguments must throw TypeError] - expected: FAIL - [DOMPointReadOnly interface: new DOMPointReadOnly() must inherit property "matrixTransform(optional DOMMatrixInit)" with the proper type] expected: FAIL @@ -31,9 +16,6 @@ [idlharness.any.html] - [DOMRectReadOnly interface: operation fromRect(optional DOMRectInit)] - expected: FAIL - [DOMPointReadOnly interface: calling matrixTransform(optional DOMMatrixInit) on new DOMPoint() with too few arguments must throw TypeError] expected: FAIL @@ -49,9 +31,6 @@ [DOMRectList interface: [object DOMRect\] must inherit property "length" with the proper type] expected: FAIL - [DOMRect interface: operation fromRect(optional DOMRectInit)] - expected: FAIL - [DOMRectList interface: operation item(unsigned long)] expected: FAIL @@ -70,18 +49,9 @@ [DOMMatrix interface: operation setMatrixValue(DOMString)] expected: FAIL - [DOMRectReadOnly interface: calling fromRect(optional DOMRectInit) on new DOMRect() with too few arguments must throw TypeError] - expected: FAIL - - [DOMRect interface: calling fromRect(optional DOMRectInit) on new DOMRect() with too few arguments must throw TypeError] - expected: FAIL - [DOMPoint interface: legacy window alias] expected: FAIL - [DOMRectReadOnly interface: calling fromRect(optional DOMRectInit) on new DOMRectReadOnly() with too few arguments must throw TypeError] - expected: FAIL - [DOMRectList interface object length] expected: FAIL @@ -91,9 +61,6 @@ [DOMPointReadOnly interface: new DOMPointReadOnly() must inherit property "matrixTransform(optional DOMMatrixInit)" with the proper type] expected: FAIL - [DOMRect interface: legacy window alias] - expected: FAIL - [DOMRectList interface: calling item(unsigned long) on [object DOMRect\] with too few arguments must throw TypeError] expected: FAIL diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json index 0334f0a9fe7..e9cd611ffe6 100644 --- a/tests/wpt/mozilla/meta/MANIFEST.json +++ b/tests/wpt/mozilla/meta/MANIFEST.json @@ -13495,7 +13495,7 @@ ] ], "interfaces.https.html": [ - "94f1102da478919d2948ebb96f81450f5d545635", + "bfe16e7de02b6c95f3aaf274510633f029ad682a", [ null, {} diff --git a/tests/wpt/mozilla/tests/mozilla/interfaces.https.html b/tests/wpt/mozilla/tests/mozilla/interfaces.https.html index 94f1102da47..bfe16e7de02 100644 --- a/tests/wpt/mozilla/tests/mozilla/interfaces.https.html +++ b/tests/wpt/mozilla/tests/mozilla/interfaces.https.html @@ -240,6 +240,7 @@ test_interfaces([ "StyleSheet", "StyleSheetList", "SubmitEvent", + "SVGRect", "Text", "TextTrack", "TextTrackCue",