Files
ladybird/Libraries/LibWeb/CSS/CSSPropertyRule.cpp
Shannon Booth fd44da6829 LibWeb/Bindings: Emit one bindings header and cpp per IDL
Previously, the LibWeb bindings generator would output multiple per
interface files like Prototype/Constructor/Namespace/GlobalMixin
depending on the contents of that IDL file.

This complicates the build system as it means that it does not know
what files will be generated without knowledge of the contents of that
IDL file.

Instead, for each IDL file only generate a single Bindings/<IDLFile>.h
and Bindings/<IDLFile>.cpp.
2026-04-21 07:36:13 +02:00

119 lines
4.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* Copyright (c) 2024, Alex Ungurianu <alex@ungurianu.com>
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/CSSPropertyRule.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/CSS/CSSPropertyRule.h>
#include <LibWeb/CSS/Serialize.h>
#include <LibWeb/Dump.h>
namespace Web::CSS {
GC_DEFINE_ALLOCATOR(CSSPropertyRule);
GC::Ref<CSSPropertyRule> CSSPropertyRule::create(JS::Realm& realm, FlyString name, FlyString syntax, bool inherits, RefPtr<StyleValue const> initial_value)
{
return realm.create<CSSPropertyRule>(realm, move(name), move(syntax), inherits, move(initial_value));
}
CSSPropertyRule::CSSPropertyRule(JS::Realm& realm, FlyString name, FlyString syntax, bool inherits, RefPtr<StyleValue const> initial_value)
: CSSRule(realm, Type::Property)
, m_name(move(name))
, m_syntax(move(syntax))
, m_inherits(inherits)
, m_initial_value(move(initial_value))
{
}
Optional<String> CSSPropertyRule::initial_value() const
{
if (m_initial_value)
return m_initial_value->to_string(SerializationMode::Normal);
return {};
}
void CSSPropertyRule::initialize(JS::Realm& realm)
{
WEB_SET_PROTOTYPE_FOR_INTERFACE(CSSPropertyRule);
Base::initialize(realm);
}
CustomPropertyRegistration CSSPropertyRule::to_registration() const
{
return CustomPropertyRegistration {
.property_name = m_name,
.syntax = m_syntax.to_string(),
.inherit = m_inherits,
.initial_value = m_initial_value,
};
}
// https://www.w3.org/TR/cssom-1/#serialize-a-css-rule
String CSSPropertyRule::serialized() const
{
StringBuilder builder;
// Serialization algorithm is defined in the spec below
// https://drafts.css-houdini.org/css-properties-values-api/#the-css-property-rule-interface
// To serialize a CSSPropertyRule, return the concatenation of the following:
// 1. The string "@property" followed by a single SPACE (U+0020).
// 2. The result of performing serialize an identifier on the rules name, followed by a single SPACE (U+0020).
builder.appendff("@property {} ", serialize_an_identifier(name()));
// 3. The string "{ ", i.e., a single LEFT CURLY BRACKET (U+007B), followed by a SPACE (U+0020).
builder.append("{ "sv);
// 4. The string "syntax:", followed by a single SPACE (U+0020).
// 5. The result of performing serialize a string on the rules syntax, followed by a single SEMICOLON (U+003B), followed by a SPACE (U+0020).
builder.appendff("syntax: {}; ", serialize_a_string(syntax()));
// 6. The string "inherits:", followed by a single SPACE (U+0020).
// 7. For the rules inherits attribute, one of the following depending on the attributes value:
// true: The string "true" followed by a single SEMICOLON (U+003B), followed by a SPACE (U+0020).
// false: The string "false" followed by a single SEMICOLON (U+003B), followed by a SPACE (U+0020).
builder.appendff("inherits: {}; ", inherits());
// 8. If the rules initial-value is present, follow these substeps:
if (m_initial_value) {
// 1. The string "initial-value:".
// 2. The result of performing serialize a CSS value in the rules initial-value followed by a single SEMICOLON
// (U+003B), followed by a SPACE (U+0020).
builder.append("initial-value: "sv);
m_initial_value->serialize(builder, SerializationMode::Normal);
builder.append("; "sv);
}
// 9. A single RIGHT CURLY BRACKET (U+007D).
builder.append("}"sv);
return MUST(builder.to_string());
}
void CSSPropertyRule::dump(StringBuilder& builder, int indent_levels) const
{
Base::dump(builder, indent_levels);
dump_indent(builder, indent_levels + 1);
builder.appendff("Name: {}\n", name());
dump_indent(builder, indent_levels + 1);
builder.appendff("Syntax: {}\n", syntax());
dump_indent(builder, indent_levels + 1);
builder.appendff("Inherits: {}\n", inherits());
if (m_initial_value) {
dump_indent(builder, indent_levels + 1);
builder.append("Initial value: "sv);
m_initial_value->serialize(builder, SerializationMode::Normal);
builder.append('\n');
}
}
}