2021-09-28 16:20:32 +01:00
|
|
|
/*
|
2024-09-03 11:43:20 +01:00
|
|
|
* Copyright (c) 2021-2024, Sam Atkins <sam@ladybird.org>
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2022, Andreas Kling <andreas@ladybird.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 {
|
|
|
|
|
2024-10-28 20:16:28 +01:00
|
|
|
CSSGroupingRule::CSSGroupingRule(JS::Realm& realm, CSSRuleList& rules, Type type)
|
|
|
|
: CSSRule(realm, type)
|
2022-08-07 15:46:44 +02:00
|
|
|
, m_rules(rules)
|
2021-09-28 16:20:32 +01:00
|
|
|
{
|
2025-04-14 17:27:00 +01:00
|
|
|
m_rules->set_owner_rule(*this);
|
2023-02-26 16:09:02 -07:00
|
|
|
for (auto& rule : *m_rules)
|
|
|
|
rule->set_parent_rule(this);
|
2021-09-28 16:20:32 +01:00
|
|
|
}
|
|
|
|
|
2023-08-07 08:41:28 +02:00
|
|
|
void CSSGroupingRule::initialize(JS::Realm& realm)
|
2023-01-10 06:28:20 -05:00
|
|
|
{
|
2024-03-16 13:13:08 +01:00
|
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(CSSGroupingRule);
|
2025-04-20 16:22:57 +02:00
|
|
|
Base::initialize(realm);
|
2023-01-10 06:28:20 -05:00
|
|
|
}
|
|
|
|
|
2022-08-07 15:46:44 +02:00
|
|
|
void CSSGroupingRule::visit_edges(Cell::Visitor& visitor)
|
|
|
|
{
|
|
|
|
Base::visit_edges(visitor);
|
2023-02-26 16:09:02 -07:00
|
|
|
visitor.visit(m_rules);
|
2022-08-07 15:46:44 +02:00
|
|
|
}
|
|
|
|
|
2024-11-04 17:13:51 +00:00
|
|
|
void CSSGroupingRule::clear_caches()
|
|
|
|
{
|
|
|
|
Base::clear_caches();
|
|
|
|
for (auto& rule : *m_rules)
|
|
|
|
rule->clear_caches();
|
|
|
|
}
|
|
|
|
|
2025-04-14 15:36:42 +01:00
|
|
|
// https://drafts.csswg.org/cssom/#dom-cssgroupingrule-insertrule
|
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
|
|
|
{
|
2025-04-14 15:36:42 +01:00
|
|
|
// The insertRule(rule, index) method must return the result of invoking insert a CSS rule rule into the child CSS
|
|
|
|
// rules at index, with the nested flag set.
|
2025-06-23 22:40:37 +12:00
|
|
|
TRY(m_rules->insert_a_css_rule(rule, index, CSSRuleList::Nested::Yes, m_parent_style_sheet->declared_namespaces()));
|
2025-04-14 15:36:42 +01:00
|
|
|
|
|
|
|
// AD-HOC: The spec doesn't say where to set the parent rule, so we'll do it here.
|
2023-02-26 16:09:02 -07: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
|
|
|
{
|
2023-02-26 16:09:02 -07:00
|
|
|
return m_rules->remove_a_css_rule(index);
|
2021-09-28 16:20:32 +01:00
|
|
|
}
|
|
|
|
|
2024-09-03 11:43:20 +01:00
|
|
|
void CSSGroupingRule::for_each_effective_rule(TraversalOrder order, Function<void(Web::CSS::CSSRule const&)> const& callback) const
|
2021-10-08 17:02:47 +01:00
|
|
|
{
|
2024-09-03 11:43:20 +01:00
|
|
|
m_rules->for_each_effective_rule(order, callback);
|
2023-05-26 23:30:54 +03:30
|
|
|
}
|
|
|
|
|
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);
|
2023-02-26 16:09:02 -07:00
|
|
|
for (auto& rule : *m_rules)
|
|
|
|
rule->set_parent_style_sheet(parent_style_sheet);
|
2022-04-22 19:56:22 +01:00
|
|
|
}
|
|
|
|
|
2021-09-28 16:20:32 +01:00
|
|
|
}
|