1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:37:35 +00:00

LibWeb: Speed up computed style calculation

Rather than destroying and rebuilding the entire document layout tree in
every call to `ComputedCSSStyleDeclaration::property()`, we now just
make sure that the layout tree exists.

This speeds up the DOM Inspector significantly, from taking several
seconds to select an element, to almost instant. :^)
This commit is contained in:
Sam Atkins 2021-09-15 10:12:08 +01:00 committed by Andreas Kling
parent 344397557c
commit 3f31f109b5
3 changed files with 8 additions and 1 deletions

View file

@ -381,7 +381,7 @@ static NonnullRefPtr<StyleValue> value_or_default(Optional<StyleProperty> proper
Optional<StyleProperty> ComputedCSSStyleDeclaration::property(PropertyID property_id) const Optional<StyleProperty> ComputedCSSStyleDeclaration::property(PropertyID property_id) const
{ {
const_cast<DOM::Document&>(m_element->document()).force_layout(); const_cast<DOM::Document&>(m_element->document()).ensure_layout();
if (!m_element->layout_node()) { if (!m_element->layout_node()) {
auto style = m_element->document().style_resolver().resolve_style(const_cast<DOM::Element&>(*m_element)); auto style = m_element->document().style_resolver().resolve_style(const_cast<DOM::Element&>(*m_element));

View file

@ -400,6 +400,12 @@ void Document::force_layout()
update_layout(); update_layout();
} }
void Document::ensure_layout()
{
if (!m_layout_root)
update_layout();
}
void Document::update_layout() void Document::update_layout()
{ {
if (!browsing_context()) if (!browsing_context())

View file

@ -144,6 +144,7 @@ public:
void force_layout(); void force_layout();
void invalidate_layout(); void invalidate_layout();
void ensure_layout();
void update_style(); void update_style();
void update_layout(); void update_layout();