diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index 9d62aad8c7a..606b7f7e424 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -2479,6 +2479,8 @@ NonnullOwnPtr StyleComputer::make_rule_cache_for_casca Optional pseudo_element; for (auto const& simple_selector : selector.compound_selectors().last().simple_selectors) { + if (!rule_cache->has_has_selectors && simple_selector.type == CSS::Selector::SimpleSelector::Type::PseudoClass && simple_selector.pseudo_class().type == CSS::PseudoClass::Has) + rule_cache->has_has_selectors = true; if (!matching_rule.contains_pseudo_element) { if (simple_selector.type == CSS::Selector::SimpleSelector::Type::PseudoElement) { matching_rule.contains_pseudo_element = true; @@ -2726,6 +2728,8 @@ void StyleComputer::build_rule_cache() m_author_rule_cache = make_rule_cache_for_cascade_origin(CascadeOrigin::Author); m_user_rule_cache = make_rule_cache_for_cascade_origin(CascadeOrigin::User); m_user_agent_rule_cache = make_rule_cache_for_cascade_origin(CascadeOrigin::UserAgent); + + m_has_has_selectors = m_author_rule_cache->has_has_selectors || m_user_rule_cache->has_has_selectors || m_user_agent_rule_cache->has_has_selectors; } void StyleComputer::invalidate_rule_cache() diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.h b/Userland/Libraries/LibWeb/CSS/StyleComputer.h index 9d854107343..66e1b4ee0ff 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.h +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.h @@ -156,6 +156,8 @@ public: }; void collect_animation_into(DOM::Element&, Optional, JS::NonnullGCPtr animation, StyleProperties& style_properties, AnimationRefresh = AnimationRefresh::No) const; + [[nodiscard]] bool has_has_selectors() const { return m_has_has_selectors; } + private: enum class ComputeStyleMode { Normal, @@ -221,12 +223,15 @@ private: Vector other_rules; HashMap> rules_by_animation_keyframes; + + bool has_has_selectors { false }; }; NonnullOwnPtr make_rule_cache_for_cascade_origin(CascadeOrigin); RuleCache const& rule_cache_for_cascade_origin(CascadeOrigin) const; + bool m_has_has_selectors { false }; OwnPtr m_author_rule_cache; OwnPtr m_user_rule_cache; OwnPtr m_user_agent_rule_cache;