LibWeb: Skip layout update for disconnected elements querying metrics

Introduce Document::update_layout_if_needed_for_node() which only calls
update_layout() when the node is connected. Use it at all call sites
that query layout metrics (offsets, client dimensions, image size, SVG
bounding box, etc.) so disconnected elements no longer trigger an
unnecessary layout.
This commit is contained in:
Aliaksandr Kalenik 2026-03-05 12:47:32 +01:00 committed by Alexander Kalenik
parent 63113cf5c9
commit 8f7bb7dd2e
Notes: github-actions[bot] 2026-03-05 13:18:27 +00:00
7 changed files with 24 additions and 17 deletions

View file

@ -2352,7 +2352,7 @@ WebIDL::ExceptionOr<void> HTMLInputElement::set_size(WebIDL::UnsignedLong value)
// https://html.spec.whatwg.org/multipage/input.html#dom-input-height
WebIDL::UnsignedLong HTMLInputElement::height() const
{
const_cast<DOM::Document&>(document()).update_layout(DOM::UpdateLayoutReason::HTMLInputElementHeight);
const_cast<DOM::Document&>(document()).update_layout_if_needed_for_node(*this, DOM::UpdateLayoutReason::HTMLInputElementHeight);
// When the input element's type attribute is not in the Image Button state, then no image is available.
if (type_state() != TypeAttributeState::ImageButton)
@ -2387,7 +2387,7 @@ void HTMLInputElement::set_height(WebIDL::UnsignedLong value)
// https://html.spec.whatwg.org/multipage/input.html#dom-input-width
WebIDL::UnsignedLong HTMLInputElement::width() const
{
const_cast<DOM::Document&>(document()).update_layout(DOM::UpdateLayoutReason::HTMLInputElementWidth);
const_cast<DOM::Document&>(document()).update_layout_if_needed_for_node(*this, DOM::UpdateLayoutReason::HTMLInputElementWidth);
// When the input element's type attribute is not in the Image Button state, then no image is available.
if (type_state() != TypeAttributeState::ImageButton)