/* * Copyright (c) 2021-2022, Sam Atkins * Copyright (c) 2022, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include #include #include #include namespace Web::CSS { CSSGroupingRule::CSSGroupingRule(JS::Realm& realm, CSSRuleList& rules) : CSSRule(realm) , m_rules(rules) { for (auto& rule : *m_rules) rule->set_parent_rule(this); } JS::ThrowCompletionOr CSSGroupingRule::initialize(JS::Realm& realm) { MUST_OR_THROW_OOM(Base::initialize(realm)); set_prototype(&Bindings::ensure_web_prototype(realm, "CSSGroupingRule")); return {}; } void CSSGroupingRule::visit_edges(Cell::Visitor& visitor) { Base::visit_edges(visitor); visitor.visit(m_rules); } WebIDL::ExceptionOr CSSGroupingRule::insert_rule(StringView rule, u32 index) { TRY(m_rules->insert_a_css_rule(rule, index)); // NOTE: The spec doesn't say where to set the parent rule, so we'll do it here. m_rules->item(index)->set_parent_rule(this); return index; } WebIDL::ExceptionOr CSSGroupingRule::delete_rule(u32 index) { return m_rules->remove_a_css_rule(index); } void CSSGroupingRule::for_each_effective_style_rule(Function const& callback) const { m_rules->for_each_effective_style_rule(callback); } void CSSGroupingRule::set_parent_style_sheet(CSSStyleSheet* parent_style_sheet) { CSSRule::set_parent_style_sheet(parent_style_sheet); for (auto& rule : *m_rules) rule->set_parent_style_sheet(parent_style_sheet); } }