2024-10-15 15:59:31 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2024, Sam Atkins <sam@ladybird.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "CSSNestedDeclarations.h"
|
|
|
|
#include <LibWeb/Bindings/CSSNestedDeclarationsPrototype.h>
|
|
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
2024-11-06 17:43:30 +00:00
|
|
|
#include <LibWeb/CSS/CSSStyleRule.h>
|
2024-10-15 15:59:31 +01:00
|
|
|
|
|
|
|
namespace Web::CSS {
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DEFINE_ALLOCATOR(CSSNestedDeclarations);
|
2024-10-15 15:59:31 +01:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<CSSNestedDeclarations> CSSNestedDeclarations::create(JS::Realm& realm, PropertyOwningCSSStyleDeclaration& declaration)
|
2024-10-15 15:59:31 +01:00
|
|
|
{
|
2024-11-14 05:50:17 +13:00
|
|
|
return realm.create<CSSNestedDeclarations>(realm, declaration);
|
2024-10-15 15:59:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CSSNestedDeclarations::CSSNestedDeclarations(JS::Realm& realm, PropertyOwningCSSStyleDeclaration& declaration)
|
2024-10-28 20:16:28 +01:00
|
|
|
: CSSRule(realm, Type::NestedDeclarations)
|
2024-10-15 15:59:31 +01:00
|
|
|
, m_declaration(declaration)
|
|
|
|
{
|
|
|
|
m_declaration->set_parent_rule(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSSNestedDeclarations::initialize(JS::Realm& realm)
|
|
|
|
{
|
|
|
|
Base::initialize(realm);
|
|
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(CSSNestedDeclarations);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSSNestedDeclarations::visit_edges(Cell::Visitor& visitor)
|
|
|
|
{
|
|
|
|
Base::visit_edges(visitor);
|
|
|
|
visitor.visit(m_declaration);
|
2024-11-06 17:43:30 +00:00
|
|
|
visitor.visit(m_parent_style_rule);
|
2024-10-15 15:59:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CSSStyleDeclaration* CSSNestedDeclarations::style()
|
|
|
|
{
|
|
|
|
return m_declaration;
|
|
|
|
}
|
|
|
|
|
2024-11-06 17:43:30 +00:00
|
|
|
CSSStyleRule const& CSSNestedDeclarations::parent_style_rule() const
|
|
|
|
{
|
|
|
|
if (m_parent_style_rule)
|
|
|
|
return *m_parent_style_rule;
|
|
|
|
|
|
|
|
for (auto* parent = parent_rule(); parent; parent = parent->parent_rule()) {
|
|
|
|
if (is<CSSStyleRule>(parent)) {
|
|
|
|
m_parent_style_rule = static_cast<CSSStyleRule const*>(parent);
|
|
|
|
return *m_parent_style_rule;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dbgln("CSSNestedDeclarations has no parent style rule!");
|
|
|
|
VERIFY_NOT_REACHED();
|
|
|
|
}
|
|
|
|
|
2024-10-15 15:59:31 +01:00
|
|
|
String CSSNestedDeclarations::serialized() const
|
|
|
|
{
|
|
|
|
// NOTE: There's no proper spec for this yet, only this note:
|
|
|
|
// "The CSSNestedDeclarations rule serializes as if its declaration block had been serialized directly."
|
|
|
|
// - https://drafts.csswg.org/css-nesting-1/#ref-for-cssnesteddeclarations%E2%91%A1
|
|
|
|
// So, we'll do the simple thing and hope it's good.
|
|
|
|
return m_declaration->serialized();
|
|
|
|
}
|
|
|
|
|
2024-11-06 17:43:30 +00:00
|
|
|
void CSSNestedDeclarations::clear_caches()
|
|
|
|
{
|
|
|
|
Base::clear_caches();
|
|
|
|
m_parent_style_rule = nullptr;
|
|
|
|
}
|
|
|
|
|
2024-10-15 15:59:31 +01:00
|
|
|
}
|