diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cpp index 3a21331c0de..b37b295a03b 100644 --- a/Libraries/LibWeb/DOM/Element.cpp +++ b/Libraries/LibWeb/DOM/Element.cpp @@ -1149,52 +1149,64 @@ bool Element::affected_by_hover() const return false; } -bool Element::affected_by_invalidation_property(CSS::InvalidationSet::Property const& property) const +bool Element::includes_properties_from_invalidation_set(CSS::InvalidationSet const& set) const { - switch (property.type) { - case CSS::InvalidationSet::Property::Type::Class: - return m_classes.contains_slow(property.name()); - case CSS::InvalidationSet::Property::Type::Id: - return m_id == property.name(); - case CSS::InvalidationSet::Property::Type::TagName: - return local_name() == property.name(); - case CSS::InvalidationSet::Property::Type::Attribute: { - if (property.name() == HTML::AttributeNames::id || property.name() == HTML::AttributeNames::class_) - return true; - return has_attribute(property.name()); - } - case CSS::InvalidationSet::Property::Type::PseudoClass: { - switch (property.value.get()) { - case CSS::PseudoClass::Enabled: { - return (is(*this) || is(*this) || is(*this) || is(*this) || is(*this) || is(*this) || is(*this)) - && !is_actually_disabled(); + auto includes_property = [&](CSS::InvalidationSet::Property const& property) { + switch (property.type) { + case CSS::InvalidationSet::Property::Type::Class: + return m_classes.contains_slow(property.name()); + case CSS::InvalidationSet::Property::Type::Id: + return m_id == property.name(); + case CSS::InvalidationSet::Property::Type::TagName: + return local_name() == property.name(); + case CSS::InvalidationSet::Property::Type::Attribute: { + if (property.name() == HTML::AttributeNames::id || property.name() == HTML::AttributeNames::class_) + return true; + return has_attribute(property.name()); } - case CSS::PseudoClass::Disabled: { - return is_actually_disabled(); - } - case CSS::PseudoClass::Checked: { - // FIXME: This could be narrowed down to return true only if element is actually checked. - return is(*this) || is(*this); - } - case CSS::PseudoClass::PlaceholderShown: { - if (is(*this) && has_attribute(HTML::AttributeNames::placeholder)) { - auto const& input_element = static_cast(*this); - return input_element.placeholder_element() && input_element.placeholder_value().has_value(); + case CSS::InvalidationSet::Property::Type::PseudoClass: { + switch (property.value.get()) { + case CSS::PseudoClass::Enabled: { + return (is(*this) || is(*this) || is(*this) || is(*this) || is(*this) || is(*this) || is(*this)) + && !is_actually_disabled(); + } + case CSS::PseudoClass::Disabled: { + return is_actually_disabled(); + } + case CSS::PseudoClass::Checked: { + // FIXME: This could be narrowed down to return true only if element is actually checked. + return is(*this) || is(*this); + } + case CSS::PseudoClass::PlaceholderShown: { + if (is(*this) && has_attribute(HTML::AttributeNames::placeholder)) { + auto const& input_element = static_cast(*this); + return input_element.placeholder_element() && input_element.placeholder_value().has_value(); + } + // - FIXME: textarea elements that have a placeholder attribute whose value is currently being presented to the user. + return false; + } + default: + VERIFY_NOT_REACHED(); } - // - FIXME: textarea elements that have a placeholder attribute whose value is currently being presented to the user. - return false; } + case CSS::InvalidationSet::Property::Type::InvalidateSelf: + return false; + case CSS::InvalidationSet::Property::Type::InvalidateWholeSubtree: + return true; default: VERIFY_NOT_REACHED(); } - } - case CSS::InvalidationSet::Property::Type::InvalidateSelf: - return false; - case CSS::InvalidationSet::Property::Type::InvalidateWholeSubtree: - return true; - default: - VERIFY_NOT_REACHED(); - } + }; + + bool includes_any = false; + set.for_each_property([&](auto const& property) { + if (includes_property(property)) { + includes_any = true; + return IterationDecision::Break; + } + return IterationDecision::Continue; + }); + return includes_any; } bool Element::has_pseudo_elements() const diff --git a/Libraries/LibWeb/DOM/Element.h b/Libraries/LibWeb/DOM/Element.h index 3c785a79924..130fec9aa73 100644 --- a/Libraries/LibWeb/DOM/Element.h +++ b/Libraries/LibWeb/DOM/Element.h @@ -266,7 +266,7 @@ public: static GC::Ptr create_layout_node_for_display_type(DOM::Document&, CSS::Display const&, GC::Ref, Element*); bool affected_by_hover() const; - bool affected_by_invalidation_property(CSS::InvalidationSet::Property const&) const; + bool includes_properties_from_invalidation_set(CSS::InvalidationSet const&) const; void set_pseudo_element_node(Badge, CSS::Selector::PseudoElement::Type, GC::Ptr); GC::Ptr get_pseudo_element_node(CSS::Selector::PseudoElement::Type) const; diff --git a/Libraries/LibWeb/DOM/Node.cpp b/Libraries/LibWeb/DOM/Node.cpp index ec8df229f3f..be1919c630a 100644 --- a/Libraries/LibWeb/DOM/Node.cpp +++ b/Libraries/LibWeb/DOM/Node.cpp @@ -486,18 +486,6 @@ void Node::invalidate_style(StyleInvalidationReason reason, Vector