summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorDerpyCrabs <derpycrabs@gmail.com>2022-02-12 16:48:00 +0300
committerAndreas Kling <kling@serenityos.org>2022-02-12 22:43:10 +0100
commit58ce2dd08806fb998d8705868314d25753674f30 (patch)
tree9e52e1e8a65bb39044da9518ba7785776d36ae87 /Userland
parent2f828231c40a4a78c0563824e204f5b112094c7d (diff)
downloadserenity-58ce2dd08806fb998d8705868314d25753674f30.zip
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.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/DOM/Element.cpp25
-rw-r--r--Userland/Libraries/LibWeb/DOM/Element.h1
-rw-r--r--Userland/Libraries/LibWeb/DOM/Element.idl1
3 files changed, 27 insertions, 0 deletions
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 <LibWeb/DOM/Text.h>
#include <LibWeb/DOMParsing/InnerHTML.h>
#include <LibWeb/Geometry/DOMRect.h>
+#include <LibWeb/Geometry/DOMRectList.h>
#include <LibWeb/HTML/BrowsingContext.h>
#include <LibWeb/HTML/EventLoop/EventLoop.h>
#include <LibWeb/HTML/Parser/HTMLParser.h>
@@ -447,6 +448,30 @@ NonnullRefPtr<Geometry::DOMRect> 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<Geometry::DOMRectList> Element::get_client_rects() const
+{
+ NonnullRefPtrVector<Geometry::DOMRect> 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<Geometry::DOMRect> get_bounding_client_rect() const;
+ NonnullRefPtr<Geometry::DOMRectList> get_client_rects() const;
virtual RefPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>);
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;