summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2021-09-15 10:12:08 +0100
committerAndreas Kling <kling@serenityos.org>2021-09-15 11:24:11 +0200
commit3f31f109b56730f71d6d61914429038501a8ed23 (patch)
tree3cc88370cc670a5252b4b7b775d4ca72a15758f1
parent344397557c7c26a275d4b83304d15a381d4f9d8e (diff)
downloadserenity-3f31f109b56730f71d6d61914429038501a8ed23.zip
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. :^)
-rw-r--r--Userland/Libraries/LibWeb/CSS/ComputedCSSStyleDeclaration.cpp2
-rw-r--r--Userland/Libraries/LibWeb/DOM/Document.cpp6
-rw-r--r--Userland/Libraries/LibWeb/DOM/Document.h1
3 files changed, 8 insertions, 1 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/ComputedCSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/ComputedCSSStyleDeclaration.cpp
index 3995c05d50..fb3b4ceaa6 100644
--- a/Userland/Libraries/LibWeb/CSS/ComputedCSSStyleDeclaration.cpp
+++ b/Userland/Libraries/LibWeb/CSS/ComputedCSSStyleDeclaration.cpp
@@ -381,7 +381,7 @@ static NonnullRefPtr<StyleValue> value_or_default(Optional<StyleProperty> proper
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()) {
auto style = m_element->document().style_resolver().resolve_style(const_cast<DOM::Element&>(*m_element));
diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp
index 2cfa9a55c2..d9e24f07d9 100644
--- a/Userland/Libraries/LibWeb/DOM/Document.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Document.cpp
@@ -400,6 +400,12 @@ void Document::force_layout()
update_layout();
}
+void Document::ensure_layout()
+{
+ if (!m_layout_root)
+ update_layout();
+}
+
void Document::update_layout()
{
if (!browsing_context())
diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h
index 099f199795..5ac4254e40 100644
--- a/Userland/Libraries/LibWeb/DOM/Document.h
+++ b/Userland/Libraries/LibWeb/DOM/Document.h
@@ -144,6 +144,7 @@ public:
void force_layout();
void invalidate_layout();
+ void ensure_layout();
void update_style();
void update_layout();