summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-09-29 20:28:32 +0200
committerAndreas Kling <kling@serenityos.org>2021-09-29 21:21:57 +0200
commit30d710a0a230fd6f3473a9667ac08c46a84192d7 (patch)
tree4d0341f01b195dda311900f01fe1438dfc2a04e5 /Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp
parent3a4565beec10f2898844884c19dc3aacf1922d37 (diff)
downloadserenity-30d710a0a230fd6f3473a9667ac08c46a84192d7.zip
LibWeb: Add CSSStyleSheet.{insert,delete,remove}Rule() APIs
Note that insertRule() is really just a big TODO right now.
Diffstat (limited to 'Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp')
-rw-r--r--Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp b/Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp
index d33eb145d4..75e03e388c 100644
--- a/Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp
+++ b/Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp
@@ -5,6 +5,7 @@
*/
#include <LibWeb/CSS/CSSRuleList.h>
+#include <LibWeb/DOM/ExceptionOr.h>
namespace Web::CSS {
@@ -24,4 +25,28 @@ bool CSSRuleList::is_supported_property_index(u32 index) const
return index < m_rules.size();
}
+// https://drafts.csswg.org/cssom/#remove-a-css-rule
+DOM::ExceptionOr<void> CSSRuleList::remove_a_css_rule(u32 index)
+{
+ // 1. Set length to the number of items in list.
+ auto length = m_rules.size();
+
+ // 2. If index is greater than or equal to length, then throw an IndexSizeError exception.
+ if (index >= length)
+ return DOM::IndexSizeError::create("CSS rule index out of bounds.");
+
+ // 3. Set old rule to the indexth item in list.
+ auto& old_rule = m_rules[index];
+
+ // FIXME: 4. If old rule is an @namespace at-rule, and list contains anything other than @import at-rules, and @namespace at-rules, throw an InvalidStateError exception.
+ (void)old_rule;
+
+ // 5. Remove rule old rule from list at the zero-indexed position index.
+ m_rules.remove(index);
+
+ // FIXME: 6. Set old ruleโ€™s parent CSS rule and parent CSS style sheet to null.
+
+ return {};
+}
+
}