From b7d8fbbd709ae5c44220d6dd916f6e6277a24025 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 9 Sep 2022 15:01:28 +0200 Subject: [PATCH] LibWeb: Update layout in Element.client{Left,Top} We have to flush any pending layout changes before getting metrics. --- Userland/Libraries/LibWeb/DOM/Element.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index d37e314f03..874494cc6d 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -603,6 +603,9 @@ JS::NonnullGCPtr 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()).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()).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;