mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:47:46 +00:00
LibWeb: Update layout in HTMLElement.offset{Width,Height}
If we don't do this, we may be returning stale values.
This commit is contained in:
parent
bb17f74fb1
commit
60ec006265
1 changed files with 22 additions and 6 deletions
|
@ -149,17 +149,33 @@ int HTMLElement::offset_left() const
|
||||||
// https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetwidth
|
// https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetwidth
|
||||||
int HTMLElement::offset_width() const
|
int HTMLElement::offset_width() const
|
||||||
{
|
{
|
||||||
if (auto* paint_box = this->paint_box())
|
// NOTE: Ensure that layout is up-to-date before looking at metrics.
|
||||||
return paint_box->border_box_width();
|
const_cast<DOM::Document&>(document()).update_layout();
|
||||||
return 0;
|
|
||||||
|
// 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
|
// https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetheight
|
||||||
int HTMLElement::offset_height() const
|
int HTMLElement::offset_height() const
|
||||||
{
|
{
|
||||||
if (auto* paint_box = this->paint_box())
|
// NOTE: Ensure that layout is up-to-date before looking at metrics.
|
||||||
return paint_box->border_box_height();
|
const_cast<DOM::Document&>(document()).update_layout();
|
||||||
return 0;
|
|
||||||
|
// 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
|
bool HTMLElement::cannot_navigate() const
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue