dymokomi/luce-browser-engine
Source of release 0.6.1
0.6.1 / src / web / css / css_property_rule.lucb
#==============================================================================================
#
# css_property_rule - CSS::CSSPropertyRule: an @property rule (a registered custom property)
#
# DESCRIPTION:
# Port of LibWeb/CSS/CSSPropertyRule.cpp (lines 1-118) and the inline members of
# CSSPropertyRule.h (lines 18-49).
#
# Copyright (c) 2024, Alex Ungurianu <alex@ungurianu.com>
# Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
# SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================
## Ported from Libraries/LibWeb/CSS/CSSPropertyRule.h:29 Web::CSS::CSSPropertyRule::name.
pub func css_property_rule_name(this: CssPropertyRule*) -> ak.FlyString:
return this.m_name
## Ported from Libraries/LibWeb/CSS/CSSPropertyRule.h:30 Web::CSS::CSSPropertyRule::syntax.
pub func css_property_rule_syntax(this: CssPropertyRule*) -> ak.FlyString:
return this.m_syntax
## Ported from Libraries/LibWeb/CSS/CSSPropertyRule.h:31 Web::CSS::CSSPropertyRule::inherits.
pub func css_property_rule_inherits(this: CssPropertyRule*) -> bool:
return this.m_inherits
## Ported from Libraries/LibWeb/CSS/CSSPropertyRule.h:33 Web::CSS::CSSPropertyRule::initial_style_value.
pub func css_property_rule_initial_style_value(this: CssPropertyRule*) -> CssStyleValue*?:
return this.m_initial_value
## Ported from Libraries/LibWeb/CSS/CSSPropertyRule.cpp:18 Web::CSS::CSSPropertyRule::create.
pub func css_property_rule_create(realm: Realm*, name: ak.FlyString, syntax: ak.FlyString, inherits: bool, initial_value: CssStyleValue*?) -> CssPropertyRule*:
return realm_create_css_property_rule(realm, realm, name, syntax, inherits, initial_value)
## Ported from Libraries/LibWeb/CSS/CSSPropertyRule.cpp:20 Web::CSS::CSSPropertyRule::CSSPropertyRule.
pub func css_property_rule_construct(this: CssPropertyRule*, realm: Realm*, name: ak.FlyString, syntax: ak.FlyString, inherits: bool, initial_value: CssStyleValue*?):
css_rule_construct(this.css_rule(), realm, CssRuleType.property)
this.m_name = name
this.m_syntax = syntax
this.m_inherits = inherits
this.m_initial_value = initial_value
## Ported from Libraries/LibWeb/CSS/CSSPropertyRule.cpp:32 Web::CSS::CSSPropertyRule::initial_value.
pub func css_property_rule_initial_value(this: CssPropertyRule*) -> ak.String?:
if let initial_value = this.m_initial_value:
return css_style_value_to_string(initial_value, css_syntax.SerializationMode.normal)
return none
## Ported from Libraries/LibWeb/CSS/CSSPropertyRule.cpp:39 Web::CSS::CSSPropertyRule::initialize (override).
pub func css_property_rule_initialize_impl(base: JsCell*, realm: Realm*):
web_set_prototype_for_interface(base, realm, BindInterfaceName.css_property_rule)
js_cell_initialize_impl(base, realm)
## Ported from Libraries/LibWeb/CSS/CSSPropertyRule.cpp:45 Web::CSS::CSSPropertyRule::to_registration.
pub func css_property_rule_to_registration(this: CssPropertyRule*) -> CssCustomPropertyRegistration:
return CssCustomPropertyRegistration(property_name = this.m_name, syntax = ak.fly_string_to_string_const(&this.m_syntax), inherit = this.m_inherits, initial_value = this.m_initial_value)
## Ported from Libraries/LibWeb/CSS/CSSPropertyRule.cpp:56 Web::CSS::CSSPropertyRule::serialized (override).
# https://www.w3.org/TR/cssom-1/#serialize-a-css-rule
pub func css_property_rule_serialized_impl(base: CssRule*) -> ak.String:
let this = (CssPropertyRule*)base
var builder = ak.string_builder_new()
# 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 rule’s name, followed by a single SPACE (U+0020).
let name = css_syntax.serialize_an_identifier_string_view(ak.fly_string_bytes_as_string_view(&this.m_name))
dump_appendff(&builder, "@property {} ", [css_arg_string(&name)])
# 3. The string "{ ", i.e., a single LEFT CURLY BRACKET (U+007B), followed by a SPACE (U+0020).
ak.string_builder_append(&builder, "{ ")
# 4. The string "syntax:", followed by a single SPACE (U+0020).
# 5. The result of performing serialize a string on the rule’s syntax, followed by a single SEMICOLON (U+003B), followed by a SPACE (U+0020).
let syntax = css_syntax.serialize_a_string_string_view(ak.fly_string_bytes_as_string_view(&this.m_syntax))
dump_appendff(&builder, "syntax: {}; ", [css_arg_string(&syntax)])
# 6. The string "inherits:", followed by a single SPACE (U+0020).
# 7. For the rule’s inherits attribute, one of the following depending on the attribute’s 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).
dump_appendff(&builder, "inherits: {}; ", [ak.arg_bool(this.m_inherits)])
# 8. If the rule’s initial-value is present, follow these substeps:
if let initial_value = this.m_initial_value:
# 1. The string "initial-value:".
# 2. The result of performing serialize a CSS value in the rule’s initial-value followed by a single SEMICOLON
# (U+003B), followed by a SPACE (U+0020).
ak.string_builder_append(&builder, "initial-value: ")
css_style_value_serialize(initial_value, &builder, css_syntax.SerializationMode.normal)
ak.string_builder_append(&builder, "; ")
# 9. A single RIGHT CURLY BRACKET (U+007D).
ak.string_builder_append(&builder, "}")
return ak.string_builder_to_string(&builder) else trap("MUST: StringBuilder::to_string")
## Ported from Libraries/LibWeb/CSS/CSSPropertyRule.cpp:96 Web::CSS::CSSPropertyRule::dump (override).
pub func css_property_rule_dump_impl(base: CssRule*, builder: ak.StringBuilder*, indent_levels: i32):
let this = (CssPropertyRule*)base
css_rule_dump_impl(base, builder, indent_levels)
dump_indent(builder, indent_levels + 1)
dump_appendff(builder, "Name: {}\n", [css_arg_fly_string(&this.m_name)])
dump_indent(builder, indent_levels + 1)
dump_appendff(builder, "Syntax: {}\n", [css_arg_fly_string(&this.m_syntax)])
dump_indent(builder, indent_levels + 1)
dump_appendff(builder, "Inherits: {}\n", [ak.arg_bool(this.m_inherits)])
if let initial_value = this.m_initial_value:
dump_indent(builder, indent_levels + 1)
ak.string_builder_append(builder, "Initial value: ")
css_style_value_serialize(initial_value, builder, css_syntax.SerializationMode.normal)
ak.string_builder_append_u8(builder, '\n')