summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-09-17 16:10:08 +0200
committerAndreas Kling <kling@serenityos.org>2022-09-17 18:53:26 +0200
commit23714469521be852f6e816091e05a3fd35485d79 (patch)
treedef4aa4cd39063b43557d54372ba794c8b94b2c9 /Userland/Libraries/LibWeb/HTML/HTMLElement.cpp
parent9e274d9501ab2fce6b95c05344d35f6b1148f5cb (diff)
downloadserenity-23714469521be852f6e816091e05a3fd35485d79.zip
LibWeb: Update layout in HTMLElement.offset{Top,Left}
We can't report layout-dependent metrics without first ensuring that layout is up-to-date.
Diffstat (limited to 'Userland/Libraries/LibWeb/HTML/HTMLElement.cpp')
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLElement.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp
index 097e16cda2..390e5728b2 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp
@@ -141,6 +141,9 @@ String HTMLElement::inner_text()
// // https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsettop
int HTMLElement::offset_top() const
{
+ // NOTE: Ensure that layout is up-to-date before looking at metrics.
+ const_cast<DOM::Document&>(document()).update_layout();
+
if (is<HTML::HTMLBodyElement>(this) || !layout_node() || !parent_element() || !parent_element()->layout_node())
return 0;
auto position = layout_node()->box_type_agnostic_position();
@@ -151,6 +154,9 @@ int HTMLElement::offset_top() const
// https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetleft
int HTMLElement::offset_left() const
{
+ // NOTE: Ensure that layout is up-to-date before looking at metrics.
+ const_cast<DOM::Document&>(document()).update_layout();
+
if (is<HTML::HTMLBodyElement>(this) || !layout_node() || !parent_element() || !parent_element()->layout_node())
return 0;
auto position = layout_node()->box_type_agnostic_position();