1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:57:44 +00:00

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.
This commit is contained in:
DerpyCrabs 2022-02-12 16:48:00 +03:00 committed by Andreas Kling
parent 2f828231c4
commit 58ce2dd088
3 changed files with 27 additions and 0 deletions

View file

@ -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())