浏览代码

LibWeb: Add callback for when a CSSRuleList's rules change

Sam Atkins 2 年之前
父节点
当前提交
496db17c2d
共有 2 个文件被更改,包括 6 次插入0 次删除
  1. 4 0
      Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp
  2. 2 0
      Userland/Libraries/LibWeb/CSS/CSSRuleList.h

+ 4 - 0
Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp

@@ -93,6 +93,8 @@ WebIDL::ExceptionOr<unsigned> CSSRuleList::insert_a_css_rule(Variant<StringView,
     m_rules.insert(index, *new_rule);
 
     // 8. Return index.
+    if (on_change)
+        on_change();
     return index;
 }
 
@@ -118,6 +120,8 @@ WebIDL::ExceptionOr<void> CSSRuleList::remove_a_css_rule(u32 index)
     old_rule.set_parent_rule(nullptr);
     old_rule.set_parent_style_sheet(nullptr);
 
+    if (on_change)
+        on_change();
     return {};
 }
 

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

@@ -61,6 +61,8 @@ public:
     bool evaluate_media_queries(HTML::Window const&);
     void for_each_effective_keyframes_at_rule(Function<void(CSSKeyframesRule const&)> const& callback) const;
 
+    Function<void()> on_change;
+
 private:
     explicit CSSRuleList(JS::Realm&);