diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index ac4e6c7f71..dcdd9a2ed5 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -123,8 +123,7 @@ WebIDL::ExceptionOr Element::set_attribute(FlyString const& name, String c parse_attribute(attribute->local_name(), value); - // FIXME: Invalidate less. - document().invalidate_style(); + invalidate_style_after_attribute_change(name); return {}; } @@ -191,8 +190,7 @@ void Element::remove_attribute(FlyString const& name) did_remove_attribute(name); - // FIXME: Invalidate less. - document().invalidate_style(); + invalidate_style_after_attribute_change(name); } // https://dom.spec.whatwg.org/#dom-element-hasattribute @@ -225,8 +223,7 @@ WebIDL::ExceptionOr Element::toggle_attribute(FlyString const& name, Optio parse_attribute(new_attribute->local_name(), ""); - // FIXME: Invalidate less. - document().invalidate_style(); + invalidate_style_after_attribute_change(name); return true; } @@ -241,8 +238,7 @@ WebIDL::ExceptionOr Element::toggle_attribute(FlyString const& name, Optio did_remove_attribute(name); - // FIXME: Invalidate less. - document().invalidate_style(); + invalidate_style_after_attribute_change(name); } // 6. Return true. @@ -980,4 +976,13 @@ void Element::scroll_into_view(Optional> ar // FIXME: 8. Optionally perform some other action that brings the element to the user’s attention. } +void Element::invalidate_style_after_attribute_change(FlyString const& attribute_name) +{ + // FIXME: Only invalidate if the attribute can actually affect style. + (void)attribute_name; + + // FIXME: This will need to become smarter when we implement the :has() selector. + invalidate_style(); +} + } diff --git a/Userland/Libraries/LibWeb/DOM/Element.h b/Userland/Libraries/LibWeb/DOM/Element.h index 6265b1b80c..2af1e0e094 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.h +++ b/Userland/Libraries/LibWeb/DOM/Element.h @@ -173,6 +173,8 @@ protected: private: void make_html_uppercased_qualified_name(); + void invalidate_style_after_attribute_change(FlyString const& attribute_name); + WebIDL::ExceptionOr> insert_adjacent(String const& where, JS::NonnullGCPtr node); QualifiedName m_qualified_name;