/src/serenity/Userland/Libraries/LibWeb/CSS/CSSGroupingRule.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2021-2024, Sam Atkins <sam@ladybird.org> |
3 | | * Copyright (c) 2022, Andreas Kling <kling@serenityos.org> |
4 | | * |
5 | | * SPDX-License-Identifier: BSD-2-Clause |
6 | | */ |
7 | | |
8 | | #include <LibWeb/Bindings/CSSGroupingRulePrototype.h> |
9 | | #include <LibWeb/Bindings/Intrinsics.h> |
10 | | #include <LibWeb/Bindings/MainThreadVM.h> |
11 | | #include <LibWeb/CSS/CSSGroupingRule.h> |
12 | | #include <LibWeb/CSS/CSSRuleList.h> |
13 | | #include <LibWeb/HTML/Window.h> |
14 | | |
15 | | namespace Web::CSS { |
16 | | |
17 | | CSSGroupingRule::CSSGroupingRule(JS::Realm& realm, CSSRuleList& rules) |
18 | 0 | : CSSRule(realm) |
19 | 0 | , m_rules(rules) |
20 | 0 | { |
21 | 0 | for (auto& rule : *m_rules) |
22 | 0 | rule->set_parent_rule(this); |
23 | 0 | } |
24 | | |
25 | | void CSSGroupingRule::initialize(JS::Realm& realm) |
26 | 0 | { |
27 | 0 | Base::initialize(realm); |
28 | 0 | WEB_SET_PROTOTYPE_FOR_INTERFACE(CSSGroupingRule); |
29 | 0 | } |
30 | | |
31 | | void CSSGroupingRule::visit_edges(Cell::Visitor& visitor) |
32 | 0 | { |
33 | 0 | Base::visit_edges(visitor); |
34 | 0 | visitor.visit(m_rules); |
35 | 0 | } |
36 | | |
37 | | WebIDL::ExceptionOr<u32> CSSGroupingRule::insert_rule(StringView rule, u32 index) |
38 | 0 | { |
39 | 0 | TRY(m_rules->insert_a_css_rule(rule, index)); |
40 | | // NOTE: The spec doesn't say where to set the parent rule, so we'll do it here. |
41 | 0 | m_rules->item(index)->set_parent_rule(this); |
42 | 0 | return index; |
43 | 0 | } |
44 | | |
45 | | WebIDL::ExceptionOr<void> CSSGroupingRule::delete_rule(u32 index) |
46 | 0 | { |
47 | 0 | return m_rules->remove_a_css_rule(index); |
48 | 0 | } |
49 | | |
50 | | void CSSGroupingRule::for_each_effective_rule(TraversalOrder order, Function<void(Web::CSS::CSSRule const&)> const& callback) const |
51 | 0 | { |
52 | 0 | m_rules->for_each_effective_rule(order, callback); |
53 | 0 | } |
54 | | |
55 | | void CSSGroupingRule::set_parent_style_sheet(CSSStyleSheet* parent_style_sheet) |
56 | 0 | { |
57 | 0 | CSSRule::set_parent_style_sheet(parent_style_sheet); |
58 | 0 | for (auto& rule : *m_rules) |
59 | 0 | rule->set_parent_style_sheet(parent_style_sheet); |
60 | 0 | } |
61 | | |
62 | | } |