diff options
author | Linus Groh <mail@linusgroh.de> | 2020-12-14 21:31:10 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-12-14 23:38:08 +0100 |
commit | 5e7945e26f1c81816758046bd45f32a384824527 (patch) | |
tree | f743ad6dda5e5d6363a5a46f61f421002bfcca9a /Libraries/LibWeb/DOM | |
parent | 9a9d655abe88c156cb2eb3896512efe8f91d6d72 (diff) | |
download | serenity-5e7945e26f1c81816758046bd45f32a384824527.zip |
LibWeb: Add a simple StyleInvalidator class
This patch adds a simple, naive & inefficient class for document-wide
style invalidation, e.g. after element attribute updates. During
construction it collects a HashMap of a document's elements and their
matching rules, during destruction it does the same and then compares
the results; dirtying all elements that have a different number or order
of matching rules afterwards.
Much room for improvement, but it solves the problem of stale element
styling after attribute updates for now :^)
Fixes #4404.
Diffstat (limited to 'Libraries/LibWeb/DOM')
-rw-r--r-- | Libraries/LibWeb/DOM/Element.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cpp index d36e85f4f2..97691c2a6b 100644 --- a/Libraries/LibWeb/DOM/Element.cpp +++ b/Libraries/LibWeb/DOM/Element.cpp @@ -28,6 +28,7 @@ #include <LibWeb/CSS/Length.h> #include <LibWeb/CSS/Parser/CSSParser.h> #include <LibWeb/CSS/PropertyID.h> +#include <LibWeb/CSS/StyleInvalidator.h> #include <LibWeb/CSS/StyleResolver.h> #include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/DocumentFragment.h> @@ -83,6 +84,8 @@ String Element::attribute(const FlyString& name) const void Element::set_attribute(const FlyString& name, const String& value) { + CSS::StyleInvalidator style_invalidator(document()); + if (auto* attribute = find_attribute(name)) attribute->set_value(value); else @@ -93,11 +96,15 @@ void Element::set_attribute(const FlyString& name, const String& value) void Element::remove_attribute(const FlyString& name) { + CSS::StyleInvalidator style_invalidator(document()); + m_attributes.remove_first_matching([&](auto& attribute) { return attribute.name() == name; }); } void Element::set_attributes(Vector<Attribute>&& attributes) { + CSS::StyleInvalidator style_invalidator(document()); + m_attributes = move(attributes); for (auto& attribute : m_attributes) @@ -161,12 +168,9 @@ void Element::parse_attribute(const FlyString& name, const String& value) for (auto& new_class : new_classes) { m_classes.unchecked_append(new_class); } - set_needs_style_update(true); } else if (name == HTML::AttributeNames::style) { m_inline_style = parse_css_declaration(CSS::ParsingContext(document()), value); set_needs_style_update(true); - } else if (name == HTML::AttributeNames::id) { - set_needs_style_update(true); } } |