2021-09-28 12:20:32 -03:00
|
|
|
/*
|
2022-04-22 15:56:22 -03:00
|
|
|
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
|
2022-08-07 10:46:44 -03:00
|
|
|
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
2021-09-28 12:20:32 -03:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
2022-09-24 19:34:04 -03:00
|
|
|
#include <LibWeb/Bindings/CSSGroupingRulePrototype.h>
|
|
|
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
2022-08-07 08:51:40 -03:00
|
|
|
#include <LibWeb/Bindings/MainThreadVM.h>
|
2021-09-28 12:20:32 -03:00
|
|
|
#include <LibWeb/CSS/CSSGroupingRule.h>
|
|
|
|
|
#include <LibWeb/CSS/CSSRuleList.h>
|
2022-08-28 08:42:07 -03:00
|
|
|
#include <LibWeb/HTML/Window.h>
|
2021-09-28 12:20:32 -03:00
|
|
|
|
|
|
|
|
namespace Web::CSS {
|
|
|
|
|
|
2022-09-24 19:34:04 -03:00
|
|
|
CSSGroupingRule::CSSGroupingRule(JS::Realm& realm, CSSRuleList& rules)
|
|
|
|
|
: CSSRule(realm)
|
2022-08-07 10:46:44 -03:00
|
|
|
, m_rules(rules)
|
2021-09-28 12:20:32 -03:00
|
|
|
{
|
2023-02-26 20:09:02 -03:00
|
|
|
for (auto& rule : *m_rules)
|
|
|
|
|
rule->set_parent_rule(this);
|
2021-09-28 12:20:32 -03:00
|
|
|
}
|
|
|
|
|
|
2023-08-07 03:41:28 -03:00
|
|
|
void CSSGroupingRule::initialize(JS::Realm& realm)
|
2023-01-10 08:28:20 -03:00
|
|
|
{
|
2023-08-07 03:41:28 -03:00
|
|
|
Base::initialize(realm);
|
2024-03-16 09:13:08 -03:00
|
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(CSSGroupingRule);
|
2023-01-10 08:28:20 -03:00
|
|
|
}
|
|
|
|
|
|
2022-08-07 10:46:44 -03:00
|
|
|
void CSSGroupingRule::visit_edges(Cell::Visitor& visitor)
|
|
|
|
|
{
|
|
|
|
|
Base::visit_edges(visitor);
|
2023-02-26 20:09:02 -03:00
|
|
|
visitor.visit(m_rules);
|
2022-08-07 10:46:44 -03:00
|
|
|
}
|
|
|
|
|
|
2022-09-25 13:03:42 -03:00
|
|
|
WebIDL::ExceptionOr<u32> CSSGroupingRule::insert_rule(StringView rule, u32 index)
|
2021-09-28 12:20:32 -03:00
|
|
|
{
|
2023-02-26 20:09:02 -03:00
|
|
|
TRY(m_rules->insert_a_css_rule(rule, index));
|
2022-04-22 15:56:22 -03:00
|
|
|
// NOTE: The spec doesn't say where to set the parent rule, so we'll do it here.
|
2023-02-26 20:09:02 -03:00
|
|
|
m_rules->item(index)->set_parent_rule(this);
|
2022-04-22 15:56:22 -03:00
|
|
|
return index;
|
2021-09-28 12:20:32 -03:00
|
|
|
}
|
|
|
|
|
|
2022-09-25 13:03:42 -03:00
|
|
|
WebIDL::ExceptionOr<void> CSSGroupingRule::delete_rule(u32 index)
|
2021-09-28 12:20:32 -03:00
|
|
|
{
|
2023-02-26 20:09:02 -03:00
|
|
|
return m_rules->remove_a_css_rule(index);
|
2021-09-28 12:20:32 -03:00
|
|
|
}
|
|
|
|
|
|
2021-10-08 13:02:47 -03:00
|
|
|
void CSSGroupingRule::for_each_effective_style_rule(Function<void(CSSStyleRule const&)> const& callback) const
|
|
|
|
|
{
|
2023-02-26 20:09:02 -03:00
|
|
|
m_rules->for_each_effective_style_rule(callback);
|
2021-10-08 13:02:47 -03:00
|
|
|
}
|
|
|
|
|
|
2023-05-26 17:00:54 -03:00
|
|
|
void CSSGroupingRule::for_each_effective_keyframes_at_rule(Function<void(CSSKeyframesRule const&)> const& callback) const
|
|
|
|
|
{
|
|
|
|
|
m_rules->for_each_effective_keyframes_at_rule(callback);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-22 15:56:22 -03:00
|
|
|
void CSSGroupingRule::set_parent_style_sheet(CSSStyleSheet* parent_style_sheet)
|
|
|
|
|
{
|
|
|
|
|
CSSRule::set_parent_style_sheet(parent_style_sheet);
|
2023-02-26 20:09:02 -03:00
|
|
|
for (auto& rule : *m_rules)
|
|
|
|
|
rule->set_parent_style_sheet(parent_style_sheet);
|
2022-04-22 15:56:22 -03:00
|
|
|
}
|
|
|
|
|
|
2021-09-28 12:20:32 -03:00
|
|
|
}
|