LibWeb: Add opt-in tracing of update_layout() calls with reason

This commit is contained in:
Andreas Kling 2025-03-05 20:50:05 +01:00 committed by Alexander Kalenik
commit c333042e63
Notes: github-actions[bot] 2025-03-08 02:39:13 +00:00
21 changed files with 137 additions and 52 deletions

View file

@ -962,7 +962,7 @@ void CanvasRenderingContext2D::set_filter(String filter)
drawing_state().filters.grow_capacity(filter_value_list.size());
// Note: The layout must be updated to make sure the canvas's layout node isn't null.
canvas_element().document().update_layout();
canvas_element().document().update_layout(DOM::UpdateLayoutReason::CanvasRenderingContext2DSetFilter);
auto layout_node = canvas_element().layout_node();
// 4. Set this's current filter to the given value.

View file

@ -400,7 +400,7 @@ void EventLoop::update_the_rendering()
while (true) {
// 1. Recalculate styles and update layout for doc.
// NOTE: Recalculation of styles is handled by update_layout()
document->update_layout();
document->update_layout(DOM::UpdateLayoutReason::HTMLEventLoopRenderingUpdate);
// 2. Let hadInitialVisibleContentVisibilityDetermination be false.
bool had_initial_visible_content_visibility_determination = false;

View file

@ -368,7 +368,7 @@ static Vector<Variant<String, RequiredLineBreakCount>> rendered_text_collection_
String HTMLElement::get_the_text_steps()
{
// 1. If element is not being rendered or if the user agent is a non-CSS user agent, then return element's descendant text content.
document().update_layout();
document().update_layout(DOM::UpdateLayoutReason::HTMLElementGetTheTextSteps);
if (!layout_node())
return descendant_text_content();
@ -444,7 +444,7 @@ String HTMLElement::outer_text()
// https://www.w3.org/TR/cssom-view-1/#dom-htmlelement-offsetparent
GC::Ptr<DOM::Element> HTMLElement::offset_parent() const
{
const_cast<DOM::Document&>(document()).update_layout();
const_cast<DOM::Document&>(document()).update_layout(DOM::UpdateLayoutReason::HTMLElementOffsetParent);
// 1. If any of the following holds true return null and terminate this algorithm:
// - The element does not have an associated CSS layout box.
@ -491,7 +491,7 @@ int HTMLElement::offset_top() const
return 0;
// NOTE: Ensure that layout is up-to-date before looking at metrics.
const_cast<DOM::Document&>(document()).update_layout();
const_cast<DOM::Document&>(document()).update_layout(DOM::UpdateLayoutReason::HTMLElementOffsetTop);
if (!paintable_box())
return 0;
@ -533,7 +533,7 @@ int HTMLElement::offset_left() const
return 0;
// NOTE: Ensure that layout is up-to-date before looking at metrics.
const_cast<DOM::Document&>(document()).update_layout();
const_cast<DOM::Document&>(document()).update_layout(DOM::UpdateLayoutReason::HTMLElementOffsetLeft);
if (!paintable_box())
return 0;
@ -571,7 +571,7 @@ int HTMLElement::offset_left() const
int HTMLElement::offset_width() const
{
// NOTE: Ensure that layout is up-to-date before looking at metrics.
const_cast<DOM::Document&>(document()).update_layout();
const_cast<DOM::Document&>(document()).update_layout(DOM::UpdateLayoutReason::HTMLElementOffsetWidth);
// 1. If the element does not have any associated box return zero and terminate this algorithm.
auto const* box = paintable_box();
@ -590,7 +590,7 @@ int HTMLElement::offset_width() const
int HTMLElement::offset_height() const
{
// NOTE: Ensure that layout is up-to-date before looking at metrics.
const_cast<DOM::Document&>(document()).update_layout();
const_cast<DOM::Document&>(document()).update_layout(DOM::UpdateLayoutReason::HTMLElementOffsetHeight);
// 1. If the element does not have any associated box return zero and terminate this algorithm.
auto const* box = paintable_box();

View file

@ -204,7 +204,7 @@ void HTMLImageElement::set_visible_in_viewport(bool)
// https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-width
WebIDL::UnsignedLong HTMLImageElement::width() const
{
const_cast<DOM::Document&>(document()).update_layout();
const_cast<DOM::Document&>(document()).update_layout(DOM::UpdateLayoutReason::HTMLImageElementWidth);
// Return the rendered width of the image, in CSS pixels, if the image is being rendered.
if (auto* paintable_box = this->paintable_box())
@ -235,7 +235,7 @@ WebIDL::ExceptionOr<void> HTMLImageElement::set_width(WebIDL::UnsignedLong width
// https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-height
WebIDL::UnsignedLong HTMLImageElement::height() const
{
const_cast<DOM::Document&>(document()).update_layout();
const_cast<DOM::Document&>(document()).update_layout(DOM::UpdateLayoutReason::HTMLImageElementHeight);
// Return the rendered height of the image, in CSS pixels, if the image is being rendered.
if (auto* paintable_box = this->paintable_box())

View file

@ -2029,7 +2029,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();
const_cast<DOM::Document&>(document()).update_layout(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)
@ -2064,7 +2064,7 @@ WebIDL::ExceptionOr<void> HTMLInputElement::set_height(WebIDL::UnsignedLong valu
// https://html.spec.whatwg.org/multipage/input.html#dom-input-width
WebIDL::UnsignedLong HTMLInputElement::width() const
{
const_cast<DOM::Document&>(document()).update_layout();
const_cast<DOM::Document&>(document()).update_layout(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)

View file

@ -402,7 +402,7 @@ void SourceSet::normalize_source_densities(DOM::Element const& element)
// HACK: Flush any pending layouts here so we get an up-to-date length resolution context.
// FIXME: We should have a way to build a LengthResolutionContext for any DOM node without going through the layout tree.
const_cast<DOM::Document&>(element.document()).update_layout();
const_cast<DOM::Document&>(element.document()).update_layout(DOM::UpdateLayoutReason::SourceSetNormalizeSourceDensities);
if (element.layout_node()) {
CSS::CalculationResolutionContext context { .length_resolution_context = CSS::Length::ResolutionContext::for_layout_node(*element.layout_node()) };
return m_source_size.resolved(context).value_or(CSS::Length::make_auto());

View file

@ -1422,7 +1422,7 @@ void Window::scroll(ScrollToOptions const& options)
VERIFY(document);
// Make sure layout is up-to-date before looking at scrollable overflow metrics.
document->update_layout();
document->update_layout(DOM::UpdateLayoutReason::WindowScroll);
VERIFY(document->paintable_box());
auto scrolling_area = document->paintable_box()->scrollable_overflow_rect()->to_type<float>();