mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:17:44 +00:00
LibWeb: Make CSSRule and all its subclasses GC-allocated
This commit is contained in:
parent
5d6cb9cbdb
commit
12042f0757
39 changed files with 338 additions and 236 deletions
|
@ -1,45 +1,55 @@
|
|||
/*
|
||||
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
|
||||
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/Bindings/CSSGroupingRulePrototype.h>
|
||||
#include <LibWeb/Bindings/MainThreadVM.h>
|
||||
#include <LibWeb/Bindings/WindowObject.h>
|
||||
#include <LibWeb/CSS/CSSGroupingRule.h>
|
||||
#include <LibWeb/CSS/CSSRuleList.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
CSSGroupingRule::CSSGroupingRule(NonnullRefPtrVector<CSSRule>&& rules)
|
||||
// FIXME: Use the same window object for the rule list.
|
||||
: m_rules(JS::make_handle(CSSRuleList::create(Bindings::main_thread_internal_window_object(), move(rules))))
|
||||
CSSGroupingRule::CSSGroupingRule(Bindings::WindowObject& window_object, CSSRuleList& rules)
|
||||
: CSSRule(window_object)
|
||||
, m_rules(rules)
|
||||
{
|
||||
for (auto& rule : *m_rules)
|
||||
set_prototype(&window_object.ensure_web_prototype<Bindings::CSSGroupingRulePrototype>("CSSGroupingRule"));
|
||||
for (auto& rule : m_rules)
|
||||
rule.set_parent_rule(this);
|
||||
}
|
||||
|
||||
void CSSGroupingRule::visit_edges(Cell::Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
visitor.visit(&m_rules);
|
||||
}
|
||||
|
||||
DOM::ExceptionOr<u32> CSSGroupingRule::insert_rule(StringView rule, u32 index)
|
||||
{
|
||||
TRY(m_rules->insert_a_css_rule(rule, 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);
|
||||
m_rules.item(index)->set_parent_rule(this);
|
||||
return index;
|
||||
}
|
||||
|
||||
DOM::ExceptionOr<void> CSSGroupingRule::delete_rule(u32 index)
|
||||
{
|
||||
return m_rules->remove_a_css_rule(index);
|
||||
return m_rules.remove_a_css_rule(index);
|
||||
}
|
||||
|
||||
void CSSGroupingRule::for_each_effective_style_rule(Function<void(CSSStyleRule const&)> const& callback) const
|
||||
{
|
||||
m_rules->for_each_effective_style_rule(callback);
|
||||
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)
|
||||
for (auto& rule : m_rules)
|
||||
rule.set_parent_style_sheet(parent_style_sheet);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue