LibWeb: Update layout in Element.client{Left,Top}

We have to flush any pending layout changes before getting metrics.
This commit is contained in:
Andreas Kling 2022-09-09 15:01:28 +02:00
parent 67b3af8025
commit b7d8fbbd70
Notes: sideshowbarker 2024-07-17 07:19:16 +09:00

View File

@ -603,6 +603,9 @@ JS::NonnullGCPtr<Geometry::DOMRectList> Element::get_client_rects() const
int Element::client_top() const
{
// NOTE: Ensure that layout is up-to-date before looking at metrics.
const_cast<Document&>(document()).update_layout();
// 1. If the element has no associated CSS layout box or if the CSS layout box is inline, return zero.
if (!layout_node() || !layout_node()->is_box())
return 0;
@ -616,6 +619,9 @@ int Element::client_top() const
// https://drafts.csswg.org/cssom-view/#dom-element-clientleft
int Element::client_left() const
{
// NOTE: Ensure that layout is up-to-date before looking at metrics.
const_cast<Document&>(document()).update_layout();
// 1. If the element has no associated CSS layout box or if the CSS layout box is inline, return zero.
if (!layout_node() || !layout_node()->is_box())
return 0;