diff --git a/components/script/dom/domrectlist.rs b/components/script/dom/domrectlist.rs new file mode 100644 index 00000000000..2762ddab232 --- /dev/null +++ b/components/script/dom/domrectlist.rs @@ -0,0 +1,66 @@ +/* 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 crate::dom::bindings::cell::DomRefCell; +use crate::dom::bindings::codegen::Bindings::DOMRectListBinding::DOMRectListMethods; +use crate::dom::bindings::reflector::{reflect_dom_object_with_proto, DomObject, Reflector}; +use crate::dom::bindings::root::{Dom, DomRoot}; +use crate::dom::domrect::DOMRect; +use crate::dom::window::Window; +use crate::script_runtime::CanGc; + +#[dom_struct] +pub struct DOMRectList { + reflector_: Reflector, + rects: DomRefCell>>, +} + +impl DOMRectList { + fn new_inherited(rects: Vec>) -> DOMRectList { + DOMRectList { + reflector_: Reflector::new(), + rects: DomRefCell::new( + rects + .into_iter() + .map(|dom_root| dom_root.as_traced()) + .collect(), + ), + } + } + + pub fn new( + window: &Window, + rects: Vec>, + can_gc: CanGc, + ) -> DomRoot { + reflect_dom_object_with_proto( + Box::new(DOMRectList::new_inherited(rects)), + &*window.global(), + None, + can_gc, + ) + } + + pub fn first(&self) -> Option> { + self.rects.borrow().first().map(Dom::as_rooted) + } +} + +impl DOMRectListMethods for DOMRectList { + /// + fn Item(&self, index: u32) -> Option> { + self.rects.borrow().get(index as usize).map(Dom::as_rooted) + } + + /// + fn IndexedGetter(&self, index: u32) -> Option> { + self.Item(index) + } + + /// + fn Length(&self) -> u32 { + self.rects.borrow().len() as u32 + } +} diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index bc09d5f8fb7..b26917c4028 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -103,6 +103,7 @@ use crate::dom::document::{ }; use crate::dom::documentfragment::DocumentFragment; use crate::dom::domrect::DOMRect; +use crate::dom::domrectlist::DOMRectList; use crate::dom::domtokenlist::DOMTokenList; use crate::dom::elementinternals::ElementInternals; use crate::dom::eventtarget::EventTarget; @@ -2431,10 +2432,10 @@ impl ElementMethods for Element { } // https://drafts.csswg.org/cssom-view/#dom-element-getclientrects - fn GetClientRects(&self, can_gc: CanGc) -> Vec> { + fn GetClientRects(&self, can_gc: CanGc) -> DomRoot { let win = window_from_node(self); let raw_rects = self.upcast::().content_boxes(can_gc); - raw_rects + let rects: Vec> = raw_rects .iter() .map(|rect| { DOMRect::new( @@ -2446,7 +2447,8 @@ impl ElementMethods for Element { can_gc, ) }) - .collect() + .collect(); + DOMRectList::new(&win, rects, can_gc) } // https://drafts.csswg.org/cssom-view/#dom-element-getboundingclientrect diff --git a/components/script/dom/mod.rs b/components/script/dom/mod.rs index ccb2970fd99..02e441476f6 100644 --- a/components/script/dom/mod.rs +++ b/components/script/dom/mod.rs @@ -294,6 +294,7 @@ pub mod dompoint; pub mod dompointreadonly; pub mod domquad; pub mod domrect; +pub mod domrectlist; pub mod domrectreadonly; pub mod domstringlist; pub mod domstringmap; diff --git a/components/script/dom/webidls/DOMRectList.webidl b/components/script/dom/webidls/DOMRectList.webidl new file mode 100644 index 00000000000..0d11c07e7fc --- /dev/null +++ b/components/script/dom/webidls/DOMRectList.webidl @@ -0,0 +1,11 @@ +/* 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://drafts.fxtf.org/geometry-1/#domrectlist + +[Exposed=Window] +interface DOMRectList { + readonly attribute unsigned long length; + getter DOMRect? item(unsigned long index); +}; diff --git a/components/script/dom/webidls/Element.webidl b/components/script/dom/webidls/Element.webidl index e5c503ef383..1a06f1394ca 100644 --- a/components/script/dom/webidls/Element.webidl +++ b/components/script/dom/webidls/Element.webidl @@ -88,7 +88,7 @@ interface Element : Node { // http://dev.w3.org/csswg/cssom-view/#extensions-to-the-element-interface partial interface Element { - sequence getClientRects(); + DOMRectList getClientRects(); [NewObject] DOMRect getBoundingClientRect(); diff --git a/tests/wpt/meta/css/cssom-view/DOMRectList.html.ini b/tests/wpt/meta/css/cssom-view/DOMRectList.html.ini index ddbb141c3f7..7994572555c 100644 --- a/tests/wpt/meta/css/cssom-view/DOMRectList.html.ini +++ b/tests/wpt/meta/css/cssom-view/DOMRectList.html.ini @@ -1,7 +1,3 @@ [DOMRectList.html] [Range getClientRects()] expected: FAIL - - [Element getClientRects()] - expected: FAIL - diff --git a/tests/wpt/meta/css/geometry/DOMRectList.html.ini b/tests/wpt/meta/css/geometry/DOMRectList.html.ini deleted file mode 100644 index d5365a060cf..00000000000 --- a/tests/wpt/meta/css/geometry/DOMRectList.html.ini +++ /dev/null @@ -1,9 +0,0 @@ -[DOMRectList.html] - [DOMRectList is exposed] - expected: FAIL - - [DOMRectList is not [LegacyArrayClass\]] - expected: FAIL - - [DOMRectList item()] - 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 d0c6cb5d66a..9a7d375f577 100644 --- a/tests/wpt/meta/css/geometry/idlharness.any.js.ini +++ b/tests/wpt/meta/css/geometry/idlharness.any.js.ini @@ -19,27 +19,12 @@ [DOMPointReadOnly interface: calling matrixTransform(optional DOMMatrixInit) on new DOMPoint() with too few arguments must throw TypeError] expected: FAIL - [DOMRectList interface: existence and properties of interface prototype object's "constructor" property] - expected: FAIL - - [DOMRectList interface: existence and properties of interface prototype object] - expected: FAIL - [DOMPointReadOnly interface: operation matrixTransform(optional DOMMatrixInit)] expected: FAIL [DOMRectList interface: [object DOMRect\] must inherit property "length" with the proper type] expected: FAIL - [DOMRectList interface: operation item(unsigned long)] - expected: FAIL - - [DOMRectList interface: existence and properties of interface object] - expected: FAIL - - [DOMRectList interface object name] - expected: FAIL - [DOMRectList interface: [object DOMRect\] must inherit property "item(unsigned long)" with the proper type] expected: FAIL @@ -52,9 +37,6 @@ [DOMPoint interface: legacy window alias] expected: FAIL - [DOMRectList interface object length] - expected: FAIL - [DOMMatrix interface: calling setMatrixValue(DOMString) on new DOMMatrix() with too few arguments must throw TypeError] expected: FAIL @@ -73,18 +55,12 @@ [DOMPointReadOnly interface: calling matrixTransform(optional DOMMatrixInit) on new DOMPointReadOnly() with too few arguments must throw TypeError] expected: FAIL - [DOMRectList interface: attribute length] - expected: FAIL - [DOMMatrix interface: legacy window alias] expected: FAIL [Stringification of [object DOMRect\]] expected: FAIL - [DOMRectList interface: existence and properties of interface prototype object's @@unscopables property] - expected: FAIL - [DOMRectList must be primary interface of ] expected: FAIL diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json index e9cd611ffe6..e85656e5aea 100644 --- a/tests/wpt/mozilla/meta/MANIFEST.json +++ b/tests/wpt/mozilla/meta/MANIFEST.json @@ -13495,7 +13495,7 @@ ] ], "interfaces.https.html": [ - "bfe16e7de02b6c95f3aaf274510633f029ad682a", + "24a5535b77ba9716e67056e1d81de837a3fecc7b", [ null, {} diff --git a/tests/wpt/mozilla/tests/mozilla/interfaces.https.html b/tests/wpt/mozilla/tests/mozilla/interfaces.https.html index bfe16e7de02..24a5535b77b 100644 --- a/tests/wpt/mozilla/tests/mozilla/interfaces.https.html +++ b/tests/wpt/mozilla/tests/mozilla/interfaces.https.html @@ -63,6 +63,7 @@ test_interfaces([ "DOMPointReadOnly", "DOMQuad", "DOMRect", + "DOMRectList", "DOMRectReadOnly", "Comment", "CustomElementRegistry",