diff options
author | Andreas Kling <kling@serenityos.org> | 2022-04-10 20:38:16 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-04-10 20:38:16 +0200 |
commit | 60ec00626572b256ca91a92bfbf29f84adc2aca0 (patch) | |
tree | 76e12ff7f4967f67e9eae6cb8902014a92307884 /Userland/Libraries/LibWeb/HTML/HTMLElement.cpp | |
parent | bb17f74fb1ec022eab216d902a9d2b26d4d5e6fc (diff) | |
download | serenity-60ec00626572b256ca91a92bfbf29f84adc2aca0.zip |
LibWeb: Update layout in HTMLElement.offset{Width,Height}
If we don't do this, we may be returning stale values.
Diffstat (limited to 'Userland/Libraries/LibWeb/HTML/HTMLElement.cpp')
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/HTMLElement.cpp | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp index 73de1cd369..ed1efe27c2 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp @@ -149,17 +149,33 @@ int HTMLElement::offset_left() const // https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetwidth int HTMLElement::offset_width() const { - if (auto* paint_box = this->paint_box()) - return paint_box->border_box_width(); - return 0; + // NOTE: Ensure that layout is up-to-date before looking at metrics. + const_cast<DOM::Document&>(document()).update_layout(); + + // 1. If the element does not have any associated CSS layout box return zero and terminate this algorithm. + if (!paint_box()) + return 0; + + // 2. Return the width of the axis-aligned bounding box of the border boxes of all fragments generated by the element’s principal box, + // ignoring any transforms that apply to the element and its ancestors. + // FIXME: Account for inline boxes. + return paint_box()->border_box_width(); } // https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetheight int HTMLElement::offset_height() const { - if (auto* paint_box = this->paint_box()) - return paint_box->border_box_height(); - return 0; + // NOTE: Ensure that layout is up-to-date before looking at metrics. + const_cast<DOM::Document&>(document()).update_layout(); + + // 1. If the element does not have any associated CSS layout box return zero and terminate this algorithm. + if (!paint_box()) + return 0; + + // 2. Return the height of the axis-aligned bounding box of the border boxes of all fragments generated by the element’s principal box, + // ignoring any transforms that apply to the element and its ancestors. + // FIXME: Account for inline boxes. + return paint_box()->border_box_height(); } bool HTMLElement::cannot_navigate() const |