From 6af55a234f434e96d91def302f8298c9cbc3e5a2 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 13 Dec 2020 15:19:42 +0100 Subject: [PATCH] LibWeb: Make DOM::Node::set_needs_style_update() schedule the update After you mark a node as needing new style, there's no situation in which we don't want a style update to happen, so just take care of scheduling it automatically. --- Libraries/LibWeb/DOM/Element.cpp | 1 - Libraries/LibWeb/DOM/Node.cpp | 10 +++++++++- Libraries/LibWeb/DOM/Node.h | 2 +- Libraries/LibWeb/HTML/HTMLElement.cpp | 1 - 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cpp index fd3776adda..816ec7e5a2 100644 --- a/Libraries/LibWeb/DOM/Element.cpp +++ b/Libraries/LibWeb/DOM/Element.cpp @@ -267,7 +267,6 @@ void Element::set_inner_html(StringView markup) } set_needs_style_update(true); - document().schedule_style_update(); document().invalidate_layout(); } diff --git a/Libraries/LibWeb/DOM/Node.cpp b/Libraries/LibWeb/DOM/Node.cpp index f87cc07ac9..00db6829e4 100644 --- a/Libraries/LibWeb/DOM/Node.cpp +++ b/Libraries/LibWeb/DOM/Node.cpp @@ -102,7 +102,6 @@ void Node::set_text_content(const String& content) } set_needs_style_update(true); - document().schedule_style_update(); document().invalidate_layout(); } @@ -250,4 +249,13 @@ EventTarget* Node::get_parent(const Event&) return parent(); } +void Node::set_needs_style_update(bool value) +{ + if (m_needs_style_update == value) + return; + m_needs_style_update = value; + if (m_needs_style_update) + document().schedule_style_update(); +} + } diff --git a/Libraries/LibWeb/DOM/Node.h b/Libraries/LibWeb/DOM/Node.h index 677d823d99..5409d05a66 100644 --- a/Libraries/LibWeb/DOM/Node.h +++ b/Libraries/LibWeb/DOM/Node.h @@ -138,7 +138,7 @@ public: virtual bool is_child_allowed(const Node&) const { return true; } bool needs_style_update() const { return m_needs_style_update; } - void set_needs_style_update(bool value) { m_needs_style_update = value; } + void set_needs_style_update(bool); void invalidate_style(); diff --git a/Libraries/LibWeb/HTML/HTMLElement.cpp b/Libraries/LibWeb/HTML/HTMLElement.cpp index 3ed31c7211..d0b590d541 100644 --- a/Libraries/LibWeb/HTML/HTMLElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLElement.cpp @@ -105,7 +105,6 @@ void HTMLElement::set_inner_text(StringView text) append_child(document().create_text_node(text)); set_needs_style_update(true); - document().schedule_style_update(); document().invalidate_layout(); }