LibWeb: Round offsetWidth and offsetHeight

Blink, WebKit, and Gecko round the border-box geometry that feeds
offsetWidth and offsetHeight instead of truncating it. Do the same
in HTMLElement so these CSSOM View APIs match interop behavior for
fractional sizes.

This also updates the two local text expectations that changed
because they observe the rounded values.
This commit is contained in:
Andreas Kling 2026-04-03 10:10:12 +02:00 committed by Andreas Kling
parent 99dd13f7f7
commit 51c7afdf5f
3 changed files with 6 additions and 6 deletions

View file

@ -685,7 +685,7 @@ int HTMLElement::offset_width() const
//
// If the elements principal box is an inline-level box which was "split" by a block-level descendant, also
// include fragments generated by the block-level descendants, unless they are zero width or height.
return box->absolute_united_border_box_rect().width().to_int();
return round(box->absolute_united_border_box_rect().width()).to_int();
}
// https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetheight
@ -704,7 +704,7 @@ int HTMLElement::offset_height() const
//
// If the elements principal box is an inline-level box which was "split" by a block-level descendant, also
// include fragments generated by the block-level descendants, unless they are zero width or height.
return box->absolute_united_border_box_rect().height().to_int();
return round(box->absolute_united_border_box_rect().height()).to_int();
}
void HTMLElement::attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_)

View file

@ -4,7 +4,7 @@ After abspos content change: 210
PASS: true
=== Test 2: Content change in in-flow element DOES affect ancestor ===
Initial width: 94
Initial width: 95
After in-flow content change: 609
PASS: true
@ -34,7 +34,7 @@ After sibling content change: 598
PASS: true
=== Test 8: Abspos with fit-content updates its own size ===
Initial abspos width: 150
Initial abspos width: 151
After content change abspos width: 405
Container width (should be ~210): 210
PASS abspos grew: true

View file

@ -1,4 +1,4 @@
119
120
141
100
122
123