From 58ce2dd08806fb998d8705868314d25753674f30 Mon Sep 17 00:00:00 2001 From: DerpyCrabs Date: Sat, 12 Feb 2022 16:48:00 +0300 Subject: [PATCH] LibWeb: Add stub implementation for Element's getClientRects getClientRects supposed to return a list of bounding DOMRect for each box fragment of Element's layout, but most elements have only one box fragment, so implementing it with getBoundingClientRect is useful. --- Userland/Libraries/LibWeb/DOM/Element.cpp | 25 +++++++++++++++++++++++ Userland/Libraries/LibWeb/DOM/Element.h | 1 + Userland/Libraries/LibWeb/DOM/Element.idl | 1 + 3 files changed, 27 insertions(+) diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index f21f5f4661..30e3fb3437 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -447,6 +448,30 @@ NonnullRefPtr Element::get_bounding_client_rect() const return Geometry::DOMRect::create(box.absolute_rect().translated(-viewport_offset.x(), -viewport_offset.y())); } +// https://drafts.csswg.org/cssom-view/#dom-element-getclientrects +NonnullRefPtr Element::get_client_rects() const +{ + NonnullRefPtrVector rects; + + // 1. If the element on which it was invoked does not have an associated layout box return an empty DOMRectList object and stop this algorithm. + if (!layout_node() || !layout_node()->is_box()) + return Geometry::DOMRectList::create(move(rects)); + + // FIXME: 2. If the element has an associated SVG layout box return a DOMRectList object containing a single DOMRect object that describes + // the bounding box of the element as defined by the SVG specification, applying the transforms that apply to the element and its ancestors. + + // FIXME: 3. Return a DOMRectList object containing DOMRect objects in content order, one for each box fragment, + // describing its border area (including those with a height or width of zero) with the following constraints: + // - Apply the transforms that apply to the element and its ancestors. + // - If the element on which the method was invoked has a computed value for the display property of table + // or inline-table include both the table box and the caption box, if any, but not the anonymous container box. + // - Replace each anonymous block box with its child box(es) and repeat this until no anonymous block boxes are left in the final list. + + auto bounding_rect = get_bounding_client_rect(); + rects.append(bounding_rect); + return Geometry::DOMRectList::create(move(rects)); +} + int Element::client_top() const { if (!layout_node() || !layout_node()->is_box()) diff --git a/Userland/Libraries/LibWeb/DOM/Element.h b/Userland/Libraries/LibWeb/DOM/Element.h index 4c1b1a6e04..4242c6d5eb 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.h +++ b/Userland/Libraries/LibWeb/DOM/Element.h @@ -125,6 +125,7 @@ public: bool serializes_as_void() const; NonnullRefPtr get_bounding_client_rect() const; + NonnullRefPtr get_client_rects() const; virtual RefPtr create_layout_node(NonnullRefPtr); diff --git a/Userland/Libraries/LibWeb/DOM/Element.idl b/Userland/Libraries/LibWeb/DOM/Element.idl index e11a33dcd6..3cf0b0f255 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.idl +++ b/Userland/Libraries/LibWeb/DOM/Element.idl @@ -49,6 +49,7 @@ interface Element : Node { [SameObject] readonly attribute HTMLCollection children; DOMRect getBoundingClientRect(); + DOMRectList getClientRects(); readonly attribute long clientTop; readonly attribute long clientLeft;