Quellcode durchsuchen

LibWeb/CSS: Clear CSSRule's cached layer name when it is moved

Through the CSSOM, rules can be moved around, and so anything cached
(for now just the qualified layer name) needs to be recalculated when
that happens. This method is virtual so that other rules will be able
to clear their cached data too.
Sam Atkins vor 9 Monaten
Ursprung
Commit
d935a00413

+ 7 - 0
Userland/Libraries/LibWeb/CSS/CSSRule.cpp

@@ -41,11 +41,18 @@ void CSSRule::set_css_text(StringView)
 void CSSRule::set_parent_rule(CSSRule* parent_rule)
 {
     m_parent_rule = parent_rule;
+    clear_caches();
 }
 
 void CSSRule::set_parent_style_sheet(CSSStyleSheet* parent_style_sheet)
 {
     m_parent_style_sheet = parent_style_sheet;
+    clear_caches();
+}
+
+void CSSRule::clear_caches()
+{
+    m_cached_layer_name.clear();
 }
 
 FlyString const& CSSRule::parent_layer_internal_qualified_name_slow_case() const

+ 2 - 0
Userland/Libraries/LibWeb/CSS/CSSRule.h

@@ -60,6 +60,8 @@ protected:
 
     virtual void visit_edges(Cell::Visitor&) override;
 
+    virtual void clear_caches();
+
     [[nodiscard]] FlyString const& parent_layer_internal_qualified_name() const
     {
         if (!m_cached_layer_name.has_value())