mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 01:35:08 +02:00
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.
75 lines
2.2 KiB
C++
75 lines
2.2 KiB
C++
/*
|
|
* Copyright (c) 2023, Jonah Shafran <jonahshafran@gmail.com>
|
|
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibGC/Heap.h>
|
|
#include <LibJS/Runtime/Realm.h>
|
|
#include <LibWeb/Bindings/CSSNamespaceRule.h>
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
|
#include <LibWeb/CSS/CSSNamespaceRule.h>
|
|
#include <LibWeb/CSS/Serialize.h>
|
|
#include <LibWeb/Dump.h>
|
|
#include <LibWeb/WebIDL/ExceptionOr.h>
|
|
|
|
namespace Web::CSS {
|
|
|
|
GC_DEFINE_ALLOCATOR(CSSNamespaceRule);
|
|
|
|
CSSNamespaceRule::CSSNamespaceRule(JS::Realm& realm, Optional<FlyString> prefix, FlyString namespace_uri)
|
|
: CSSRule(realm, Type::Namespace)
|
|
, m_namespace_uri(move(namespace_uri))
|
|
, m_prefix(prefix.value_or(""_fly_string))
|
|
{
|
|
}
|
|
|
|
GC::Ref<CSSNamespaceRule> CSSNamespaceRule::create(JS::Realm& realm, Optional<FlyString> prefix, FlyString namespace_uri)
|
|
{
|
|
return realm.create<CSSNamespaceRule>(realm, move(prefix), move(namespace_uri));
|
|
}
|
|
|
|
void CSSNamespaceRule::initialize(JS::Realm& realm)
|
|
{
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(CSSNamespaceRule);
|
|
Base::initialize(realm);
|
|
}
|
|
|
|
// https://www.w3.org/TR/cssom/#serialize-a-css-rule
|
|
String CSSNamespaceRule::serialized() const
|
|
{
|
|
StringBuilder builder;
|
|
// The literal string "@namespace", followed by a single SPACE (U+0020),
|
|
builder.append("@namespace "sv);
|
|
|
|
// followed by the serialization as an identifier of the prefix attribute (if any),
|
|
if (!m_prefix.is_empty()) {
|
|
serialize_an_identifier(builder, m_prefix);
|
|
// followed by a single SPACE (U+0020) if there is a prefix,
|
|
builder.append(" "sv);
|
|
}
|
|
|
|
// followed by the serialization as URL of the namespaceURI attribute,
|
|
serialize_a_url(builder, m_namespace_uri);
|
|
|
|
// followed the character ";" (U+003B).
|
|
builder.append(";"sv);
|
|
|
|
return MUST(builder.to_string());
|
|
}
|
|
|
|
void CSSNamespaceRule::dump(StringBuilder& builder, int indent_levels) const
|
|
{
|
|
Base::dump(builder, indent_levels);
|
|
|
|
dump_indent(builder, indent_levels + 1);
|
|
builder.appendff("Namespace: {}\n", namespace_uri());
|
|
if (!prefix().is_empty()) {
|
|
dump_indent(builder, indent_levels + 1);
|
|
builder.appendff("Prefix: {}\n", prefix());
|
|
}
|
|
}
|
|
|
|
}
|