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