dymokomi/luce-browser-engine
Source of release 0.6.1
0.6.1 / src / web / css / css_style_properties_4.lucb
#==============================================================================================
#
# css_style_properties_4 - CSS::CSSStyleProperties: removeProperty(), serialization, cssText
#
# DESCRIPTION:
# Port of LibWeb/CSS/CSSStyleProperties.cpp (lines 1044-1526): removeProperty(),
# cssFloat, "serialize a CSS declaration block" (with shorthands rebuilt from their
# longhands), "serialize a CSS value", the cssText setter, owner invalidation and "set a
# CSS declaration".
#
# Copyright (c) 2018-2024, Andreas Kling <andreas@ladybird.org>
# Copyright (c) 2023-2025, Sam Atkins <sam@ladybird.org>
# SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================
# mark: removeProperty() ========================================================================
## Ported from Libraries/LibWeb/CSS/CSSStyleProperties.cpp:1046 Web::CSS::CSSStyleProperties::remove_property (override).
# https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-removeproperty
pub func css_style_properties_remove_property_impl(base: CssStyleDeclaration*, property_name: ak.FlyString) -> ak.String!:
return try css_style_properties_remove_property_internal((CssStyleProperties*)base, css_property_name_and_id_from_name(property_name))
## remove_property_internal's recursive remove_declaration lambda.
func css_style_properties_remove_declaration(this: CssStyleProperties*, property_to_remove: CssPropertyNameAndId) -> bool:
# 4. Let removed be false.
var removed = false
# 5. If property is a shorthand property, for each longhand property longhand that property maps to:
if css_data.property_is_shorthand(css_property_name_and_id_id(&property_to_remove)):
let longhands = css_data.longhands_for_shorthand(css_property_name_and_id_id(&property_to_remove))
for longhand_property_id in ak.vector_span_const(&longhands):
# 1. If longhand is not a property name of a CSS declaration in the declarations, continue.
# 2. Remove that CSS declaration and let removed be true.
let longhand_removed = css_style_properties_remove_declaration(this, css_property_name_and_id_from_id(longhand_property_id))
removed = removed or longhand_removed
else:
# 6. Otherwise, if property is a case-sensitive match for a property name of a CSS declaration in the declarations, remove that CSS declaration and let removed be true.
if css_property_name_and_id_is_custom_property(&property_to_remove):
removed = ak.ordered_hash_map_remove_k(&this.m_custom_properties, css_property_name_and_id_name(&property_to_remove))
elif let index = css_style_properties_index_of(&this.m_properties, css_property_name_and_id_id(&property_to_remove)):
ak.vector_remove(&this.m_properties, index)
removed = true
return removed
## Ported from Libraries/LibWeb/CSS/CSSStyleProperties.cpp:1052 Web::CSS::CSSStyleProperties::remove_property_internal.
# https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-removeproperty
func css_style_properties_remove_property_internal(this: CssStyleProperties*, property: CssPropertyNameAndId?) -> ak.String!:
# 1. If the readonly flag is set, then throw a NoModificationAllowedError exception.
if css_style_declaration_is_readonly(this.css_style_declaration()):
try idl_throw(.idl_dom_exception(idl_no_modification_allowed_error_create(bind_platform_object_realm(this.bind_platform_object()), ak.utf16_string_from_str("Cannot remove property: CSSStyleProperties is read-only."))))
# 2. If property is not a custom property, let property be property converted to ASCII lowercase.
# NB: Already done by creating a PropertyNameAndID.
# NB: The spec doesn't reject invalid property names, it just lets them pass through.
# Attempting to remove a non-existent property is a no-op, so we can just skip over this section.
var value = ak.string_from_str("")
if let property_to_remove = property:
# 3. Let value be the return value of invoking getPropertyValue() with property as argument.
# FIXME: Add an overload that takes PropertyNameAndID?
value = css_style_declaration_get_property_value(this.css_style_declaration(), css_property_name_and_id_name(&property_to_remove))
let removed = css_style_properties_remove_declaration(this, property_to_remove)
# 7. If removed is true, Update style attribute for the CSS declaration block.
if removed:
css_style_declaration_update_style_attribute(this.css_style_declaration())
# Non-standard: Invalidate style for the owners of our containing sheet, if any.
css_style_properties_invalidate_owners(this, DomStyleInvalidationReason.css_style_properties_remove_property)
# 8. Return value.
return value
## Ported from Libraries/LibWeb/CSS/CSSStyleProperties.cpp:1107 Web::CSS::CSSStyleProperties::remove_property.
pub func css_style_properties_remove_property_property_id(this: CssStyleProperties*, property_name: css_data.PropertyId) -> ak.String!:
return try css_style_properties_remove_property_internal(this, css_property_name_and_id_from_id(property_name))
## Ported from Libraries/LibWeb/CSS/CSSStyleProperties.cpp:1113 Web::CSS::CSSStyleProperties::css_float.
# https://drafts.csswg.org/cssom/#dom-cssstyleproperties-cssfloat
pub func css_style_properties_css_float(this: CssStyleProperties*) -> ak.String:
# The cssFloat attribute, on getting, must return the result of invoking getPropertyValue() with float as argument.
return css_style_declaration_get_property_value(this.css_style_declaration(), ak.fly_string_from_str("float"))
## Ported from Libraries/LibWeb/CSS/CSSStyleProperties.cpp:1119 Web::CSS::CSSStyleProperties::set_css_float.
pub func css_style_properties_set_css_float(this: CssStyleProperties*, value: ak.StringView) -> !:
# On setting, the attribute must invoke setProperty() with float as first argument, as second argument the given value,
# and no third argument. Any exceptions thrown must be re-thrown.
try css_style_declaration_set_property(this.css_style_declaration(), ak.fly_string_from_str("float"), value, ak.sv(""))
# mark: Serialization ===========================================================================
## serialized()'s recursive append_property_to_already_serialized lambda.
func css_append_property_to_already_serialized(already_serialized: ak.HashTable[css_data.PropertyId, css_data.PropertyIdTraits]*, property: css_data.PropertyId):
_ = ak.hash_table_set(already_serialized, property)
# AD-HOC: The spec assumes that we only store values against expanded longhands, there are however limited
# circumstances where we store against shorthands directly in addition to the expanded longhands. For
# example if the value of the shorthand is unresolved we store an UnresolvedStyleValue against the
# shorthand directly and a PendingSubstitutionStyleValue against each of the longhands. In the case we
# serialize a shorthand directly we should also mark it's longhands as serialized to avoid serializing
# them separately.
if css_data.property_is_shorthand(property):
let longhands = css_data.longhands_for_shorthand(property)
for longhand in ak.vector_span_const(&longhands):
css_append_property_to_already_serialized(already_serialized, longhand)
## Whether `shorthand` is one of the shorthands `property_id` maps to (`shorthands_for_longhand(...).contains_slow(shorthand)`).
func css_maps_to_shorthand(property_id: css_data.PropertyId, shorthand: css_data.PropertyId) -> bool:
let shorthands = css_data.shorthands_for_longhand(property_id)
return ak.vector_contains_slow[css_data.PropertyId, css_data.PropertyIdTraits](&shorthands, shorthand)
## Whether `declarations` has a declaration of `property_id` (the `any_of(..., property_id == ...)` of serialized()).
func css_declarations_contain(declarations: const ak.Vector[CssStyleProperty]*, property_id: css_data.PropertyId) -> bool:
for declaration in ak.vector_span_const(declarations):
if declaration.property_id == property_id:
return true
return false
## Ported from Libraries/LibWeb/CSS/CSSStyleProperties.cpp:1141 Web::CSS::CSSStyleProperties::serialized (override).
# https://www.w3.org/TR/cssom/#serialize-a-css-declaration-block
pub func css_style_properties_serialized_impl(base: CssStyleDeclaration*) -> ak.String:
let this = (CssStyleProperties*)base
# 1. Let list be an empty array.
var list: ak.Vector[ak.String]
# 2. Let already serialized be an empty array.
var already_serialized: ak.HashTable[css_data.PropertyId, css_data.PropertyIdTraits]
# NB: The spec treats custom properties the same as any other property, and expects the above loop to handle them.
# However, our implementation separates them from regular properties, so we need to handle them separately here.
# FIXME: Is the relative order of custom properties and regular properties supposed to be preserved?
for declaration in ak.ordered_hash_map_begin_const(&this.m_custom_properties):
# 1. Let property be declaration’s property name.
let property = declaration.key
# 2. If property is in already serialized, continue with the steps labeled declaration loop.
# NB: It is never in already serialized, as there are no shorthands for custom properties.
# 3. If property maps to one or more shorthand properties, let shorthands be an array of those shorthand properties, in preferred order.
# NB: There are no shorthands for custom properties.
# 4. Shorthand loop: For each shorthand in shorthands, follow these substeps: ...
# NB: There are no shorthands for custom properties.
# 5. Let value be the result of invoking serialize a CSS value of declaration.
let value = css_style_value_to_string(declaration.value.value, css_syntax.SerializationMode.normal)
# 6. Let serialized declaration be the result of invoking serialize a CSS declaration with property name property, value value,
# and the important flag set if declaration has its important flag set.
# NB: We have to inline this here as the actual implementation does not accept custom properties.
let serialized_declaration = css_serialize_a_css_declaration(ak.fly_string_bytes_as_string_view(&property), ak.string_bytes_as_string_view(&value), declaration.value.important)
# 7. Append serialized declaration to list.
ak.vector_append_t(&list, serialized_declaration)
# 8. Append property to already serialized.
# NB: We don't need to do this, as we don't have shorthands for custom properties.
# 3. Declaration loop: For each CSS declaration declaration in declaration block’s declarations, follow these substeps:
for declaration in ak.vector_span(&this.m_properties):
# 1. Let property be declaration’s property name.
let property = declaration.property_id
# 2. If property is in already serialized, continue with the steps labeled declaration loop.
if ak.hash_table_contains_t(&already_serialized, property):
continue
# 3. If property maps to one or more shorthand properties, let shorthands be an array of those shorthand properties, in preferred order.
if css_data.property_maps_to_shorthand(property):
let shorthands = css_data.shorthands_for_longhand(property)
# 4. Shorthand loop: For each shorthand in shorthands, follow these substeps:
for shorthand in ak.vector_span_const(&shorthands):
css_style_properties_serialize_shorthand(this, shorthand, &list, &already_serialized)
# FIXME: File spec issue that this should only be run if we haven't serialized this declaration in the above shorthand loop.
if not ak.hash_table_contains_t(&already_serialized, declaration.property_id):
# 5. Let value be the result of invoking serialize a CSS value of declaration.
let value = css_style_properties_serialize_a_css_value_css_style_property(this, declaration)
# 6. Let serialized declaration be the result of invoking serialize a CSS declaration with property name property, value value,
# and the important flag set if declaration has its important flag set.
let name = css_data.string_from_property_id(property)
let serialized_declaration = css_serialize_a_css_declaration(ak.fly_string_bytes_as_string_view(&name), ak.string_bytes_as_string_view(&value), declaration.important)
# 7. Append serialized declaration to list.
ak.vector_append_t(&list, serialized_declaration)
# 8. Append property to already serialized.
css_append_property_to_already_serialized(&already_serialized, declaration.property_id)
# 4. Return list joined with " " (U+0020).
var builder = ak.string_builder_new()
ak.string_builder_join_string(&builder, ak.sv(" "), ak.vector_span_const(&list))
return ak.string_builder_to_string(&builder) else trap("MUST: StringBuilder::to_string")
## One pass of serialized()'s shorthand loop (step 3.4) for `shorthand`.
func css_style_properties_serialize_shorthand(this: CssStyleProperties*, shorthand: css_data.PropertyId, list: ak.Vector[ak.String]*, already_serialized: ak.HashTable[css_data.PropertyId, css_data.PropertyIdTraits]*):
# 1. Let longhands be an array consisting of all CSS declarations in declaration block’s declarations
# that are not in already serialized and have a property name that maps to one of the shorthand
# properties in shorthands.
var longhands: ak.Vector[CssStyleProperty]
for longhand_declaration in ak.vector_span(&this.m_properties):
if not ak.hash_table_contains_t(already_serialized, longhand_declaration.property_id) and css_maps_to_shorthand(longhand_declaration.property_id, shorthand):
ak.vector_append_t(&longhands, longhand_declaration)
# 2. If not all properties that map to shorthand are present in longhands, continue with the steps labeled shorthand loop.
let expanded_longhands = css_data.expanded_longhands_for_shorthand(shorthand)
for longhand_id in ak.vector_span_const(&expanded_longhands):
if not css_declarations_contain(&longhands, longhand_id):
return
# 3. Let current longhands be an empty array.
var current_longhands: ak.Vector[CssStyleProperty]
# 4. Append all CSS declarations in longhands that have a property name that maps to shorthand to current longhands.
for longhand in ak.vector_span(&longhands):
if css_maps_to_shorthand(longhand.property_id, shorthand):
ak.vector_append_t(¤t_longhands, longhand)
# 5. If there are one or more CSS declarations in current longhands have their important flag set and
# one or more with it unset, continue with the steps labeled shorthand loop.
var all_declarations_have_same_important_flag = true
for i in 1..<ak.vector_size(¤t_longhands):
if ak.vector_at(¤t_longhands, i).important != ak.vector_at(¤t_longhands, 0).important:
all_declarations_have_same_important_flag = false
break
if not all_declarations_have_same_important_flag:
return
# 6. If there is any declaration in declaration block in between the first and the last longhand
# in current longhands which belongs to the same logical property group, but has a different
# mapping logic as any of the longhands in current longhands, and is not in current
# longhands, continue with the steps labeled shorthand loop.
let first_current_longhand_index = css_style_properties_index_of(&this.m_properties, ak.vector_at(¤t_longhands, 0).property_id) else trap("VERIFY: first_current_longhand_index")
let last_current_longhand_index = css_style_properties_index_of(&this.m_properties, ak.vector_at(¤t_longhands, ak.vector_size(¤t_longhands) - 1).property_id) else trap("VERIFY: last_current_longhand_index")
var should_continue = false
var current_declaration_index = first_current_longhand_index
while current_declaration_index <= last_current_longhand_index:
let current_property_id = ak.vector_at(&this.m_properties, current_declaration_index).property_id
current_declaration_index += 1
# NB: Declaration is in current longhands
if css_declarations_contain(¤t_longhands, current_property_id):
continue
let logical_property_group_for_current_declaration = css_data.logical_property_group_for_property(current_property_id)
if logical_property_group_for_current_declaration == none:
continue
let current_declaration_is_logical_alias = css_data.property_is_logical_alias(current_property_id)
# NB: Declaration has any counterpart in current longhands with same logical property group but different mapping logic
for current_longhand in ak.vector_span(¤t_longhands):
if css_data.logical_property_group_for_property(current_longhand.property_id) == logical_property_group_for_current_declaration and css_data.property_is_logical_alias(current_longhand.property_id) != current_declaration_is_logical_alias:
should_continue = true
break
if should_continue:
break
if should_continue:
return
# 7. Let value be the result of invoking serialize a CSS value with current longhands.
let value = css_style_properties_serialize_a_css_value_vector(this, ak.vector_clone(¤t_longhands))
# 8. If value is the empty string, continue with the steps labeled shorthand loop.
if ak.string_is_empty(&value):
return
# 9. Let serialized declaration be the result of invoking serialize a CSS declaration with property
# name shorthand, value value, and the important flag set if the CSS declarations in current
# longhands have their important flag set.
let name = css_data.string_from_property_id(shorthand)
let serialized_declaration = css_serialize_a_css_declaration(ak.fly_string_bytes_as_string_view(&name), ak.string_bytes_as_string_view(&value), ak.vector_first(¤t_longhands).important)
# 10. Append serialized declaration to list.
ak.vector_append_t(list, serialized_declaration)
# 11. Append the property names of all items of current longhands to already serialized.
for longhand in ak.vector_span(¤t_longhands):
css_append_property_to_already_serialized(already_serialized, longhand.property_id)
# 12. Continue with the steps labeled declaration loop.
## Ported from Libraries/LibWeb/CSS/CSSStyleProperties.cpp:1314 Web::CSS::CSSStyleProperties::serialize_a_css_value.
# https://www.w3.org/TR/cssom/#serialize-a-css-value
pub func css_style_properties_serialize_a_css_value_css_style_property(this: CssStyleProperties*, declaration: CssStyleProperty) -> ak.String:
_ = this
# 1. If If this algorithm is invoked with a list list:
# NOTE: This is handled in other other overload of this method
# 2. Represent the value of the declaration as a list of CSS component values components that, when parsed
# according to the property’s grammar, would represent that value. Additionally:
# - If certain component values can appear in any order without changing the meaning of the value (a pattern
# typically represented by a double bar || in the value syntax), reorder the component values to use the
# canonical order of component values as given in the property definition table.
# - If component values can be omitted or replaced with a shorter representation without changing the meaning
# of the value, omit/replace them.
# - If either of the above syntactic translations would be less backwards-compatible, do not perform them.
# Spec Note: The rules described here outlines the general principles of serialization. For legacy reasons, some
# properties serialize in a different manner, which is intentionally undefined here due to lack of
# resources. Please consult your local reverse-engineer for details.
# 3. Remove any <whitespace-token>s from components.
# 4. Replace each component value in components with the result of invoking serialize a CSS component value.
# 5. Join the items of components into a single string, inserting " " (U+0020 SPACE) between each pair of items
# unless the second item is a "," (U+002C COMMA) Return the result.
# AD-HOC: As the spec is vague we don't follow it exactly here.
return css_style_value_to_string(declaration.value, css_syntax.SerializationMode.normal)
## The make_shorthand_value lambda of serialize_a_css_value(list): a shorthand value of `shorthand_id`
## from the declarations of `list`, nested shorthands made recursively.
func css_make_shorthand_value(list: const ak.Vector[CssStyleProperty]*, shorthand_id: css_data.PropertyId) -> CssStyleValue*:
let longhand_ids = css_data.longhands_for_shorthand(shorthand_id)
var longhand_values: ak.Vector[CssStyleValue*]
for longhand_id in ak.vector_span_const(&longhand_ids):
if css_data.property_is_shorthand(longhand_id):
ak.vector_append_t(&longhand_values, css_make_shorthand_value(list, longhand_id))
else:
let index = css_style_properties_index_of(list, longhand_id) else trap("first_matching: no declaration")
ak.vector_append_t(&longhand_values, ak.vector_at_const(list, index).value)
return css_shorthand_style_value_create(shorthand_id, longhand_ids, longhand_values).css_style_value()
## Ported from Libraries/LibWeb/CSS/CSSStyleProperties.cpp:1342 Web::CSS::CSSStyleProperties::serialize_a_css_value.
# https://www.w3.org/TR/cssom/#serialize-a-css-value
pub func css_style_properties_serialize_a_css_value_vector(this: CssStyleProperties*, list: ak.Vector[CssStyleProperty]) -> ak.String:
_ = this
if ak.vector_is_empty(&list):
return ak.string_from_str("")
# 1. Let shorthand be the first shorthand property, in preferred order, that exactly maps to all of the longhand properties in list.
var shorthand: css_data.PropertyId? = none
let candidates = css_data.shorthands_for_longhand(ak.vector_first_const(&list).property_id)
for potential_shorthand in ak.vector_span_const(&candidates):
let longhands_for_potential_shorthand = css_data.expanded_longhands_for_shorthand(potential_shorthand)
# The potential shorthand exactly maps to all of the longhand properties in list if:
# a. The number of longhand properties in the list is equal to the number of longhand properties that the potential shorthand maps to.
if ak.vector_size(&longhands_for_potential_shorthand) != ak.vector_size(&list):
continue
# b. All longhand properties in the list are contained in the list of longhands for the potential shorthand.
var all_contained = true
for longhand in ak.vector_span_const(&longhands_for_potential_shorthand):
if not css_declarations_contain(&list, longhand):
all_contained = false
break
if all_contained:
shorthand = potential_shorthand
break
# 2. If there is no such shorthand or shorthand cannot exactly represent the values of all the properties in list, return the empty string.
let shorthand_id = shorthand else return ak.string_from_str("")
# 3. Otherwise, serialize a CSS value from a hypothetical declaration of the property shorthand with its value representing the combined values of the declarations in list.
return css_style_value_to_string(css_make_shorthand_value(&list, shorthand_id), css_syntax.SerializationMode.normal)
# mark: cssText and the declarations ============================================================
## Ported from Libraries/LibWeb/CSS/CSSStyleProperties.cpp:1383 Web::CSS::CSSStyleProperties::set_css_text (override).
# https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-csstext
pub func css_style_properties_set_css_text_impl(base: CssStyleDeclaration*, css_text: ak.StringView) -> !:
let this = (CssStyleProperties*)base
# 1. If the readonly flag is set, then throw a NoModificationAllowedError exception.
if css_style_declaration_is_readonly(base):
try idl_throw(.idl_dom_exception(idl_no_modification_allowed_error_create(bind_platform_object_realm(this.bind_platform_object()), ak.utf16_string_from_str("Cannot modify properties: CSSStyleProperties is read-only."))))
# 2. Empty the declarations.
# 3. Parse the given value and, if the return value is not the empty list, insert the items in the list into the declarations, in specified order.
css_style_properties_set_declarations_from_text(this, css_text)
# 4. Update style attribute for the CSS declaration block.
css_style_declaration_update_style_attribute(base)
# Non-standard: Invalidate style for the owners of our containing sheet, if any.
css_style_properties_invalidate_owners(this, DomStyleInvalidationReason.css_style_properties_text_change)
## Ported from Libraries/LibWeb/CSS/CSSStyleProperties.cpp:1403 Web::CSS::CSSStyleProperties::invalidate_owners.
func css_style_properties_invalidate_owners(this: CssStyleProperties*, reason: DomStyleInvalidationReason):
if let rule = css_style_declaration_parent_rule(this.css_style_declaration()):
if let sheet = css_rule_parent_style_sheet(rule):
if css_rule_type(rule) == CssRuleType.style or css_rule_type(rule) == CssRuleType.nested_declarations:
css_invalidate_style_for_style_sheet_owners(sheet, reason, CssShouldInvalidateRuleCache.no)
return
css_css_style_sheet_invalidate_owners(sheet, reason)
## Ported from Libraries/LibWeb/CSS/CSSStyleProperties.cpp:1418 Web::CSS::CSSStyleProperties::set_a_css_declaration.
# https://drafts.csswg.org/cssom/#set-a-css-declaration
func css_style_properties_set_a_css_declaration(this: CssStyleProperties*, property_id: css_data.PropertyId, value: CssStyleValue*, important: css_syntax.Important) -> bool:
assert(not css_style_declaration_is_computed(this.css_style_declaration()))
# NOTE: The below algorithm is only suggested rather than required by the spec
# https://drafts.csswg.org/cssom/#example-a40690cb
# 1. If property is a case-sensitive match for a property name of a CSS declaration in declarations, follow these substeps:
if let target_index = css_style_properties_index_of(&this.m_properties, property_id):
# 1. Let target declaration be such CSS declaration.
let target_declaration = *ak.vector_at(&this.m_properties, target_index)
# 2. Let needs append be false.
var needs_append = false
let logical_property_group_for_set_property = css_data.logical_property_group_for_property(property_id)
# NOTE: If the property of the declaration being set has no logical property group then it's not possible for
# one of the later declarations to share that logical property group so we can skip checking.
if logical_property_group_for_set_property != none:
let set_property_is_logical_alias = css_data.property_is_logical_alias(property_id)
# 3. For each declaration in declarations after target declaration:
for i in (target_index + 1)..<ak.vector_size(&this.m_properties):
let other_property_id = ak.vector_at(&this.m_properties, i).property_id
# 1. If declaration’s property name is not in the same logical property group as property, then continue.
if css_data.logical_property_group_for_property(other_property_id) != logical_property_group_for_set_property:
continue
# 2. If declaration’ property name has the same mapping logic as property, then continue.
if css_data.property_is_logical_alias(other_property_id) == set_property_is_logical_alias:
continue
# 3. Let needs append be true.
needs_append = true
# 4. Break.
break
# 4. If needs append is false, then:
if not needs_append:
# 1. Let needs update be false.
var needs_update = false
# 2. If target declaration’s value is not equal to component value list, then let needs update be true.
if not css_style_value_equals(target_declaration.value, value):
needs_update = true
# 3. If target declaration’s important flag is not equal to whether important flag is set, then let needs update be true.
if target_declaration.important != important:
needs_update = true
# 4. If needs update is false, then return false.
if not needs_update:
return false
# 5. Set target declaration’s value to component value list.
ak.vector_at(&this.m_properties, target_index).value = value
# 6. If important flag is set, then set target declaration’s important flag, otherwise unset it.
ak.vector_at(&this.m_properties, target_index).important = important
# 7. Return true.
return true
# 5. Otherwise, remove target declaration from declarations.
ak.vector_remove(&this.m_properties, target_index)
# 2. Append a new CSS declaration with property name property, value component value list, and important flag set
# if important flag is set to declarations.
ak.vector_append_t(&this.m_properties, CssStyleProperty(important = important, property_id = property_id, value = value))
# 3. Return true
return true
## Ported from Libraries/LibWeb/CSS/CSSStyleProperties.cpp:1502 Web::CSS::CSSStyleProperties::empty_the_declarations.
func css_style_properties_empty_the_declarations(this: CssStyleProperties*):
ak.vector_clear(&this.m_properties)
ak.ordered_hash_map_clear(&this.m_custom_properties)
## Ported from Libraries/LibWeb/CSS/CSSStyleProperties.cpp:1508 Web::CSS::CSSStyleProperties::set_the_declarations.
func css_style_properties_set_the_declarations(this: CssStyleProperties*, properties: ak.Vector[CssStyleProperty], custom_properties: ak.OrderedHashMap[ak.FlyString, CssStyleProperty, ak.FlyStringTraits]):
var declarations = ak.vector_clone(&properties) # by-value copy in C++
this.m_properties = css_style_properties_convert_declarations_to_specified_order(&declarations)
this.m_custom_properties = custom_properties
## Ported from Libraries/LibWeb/CSS/CSSStyleProperties.cpp:1514 Web::CSS::CSSStyleProperties::set_declarations_from_text.
pub func css_style_properties_set_declarations_from_text(this: CssStyleProperties*, css_text: ak.StringView):
css_style_properties_empty_the_declarations(this)
var parsing_params: CssParsingParams = ---
if let owner_node = css_style_declaration_owner_node(this.css_style_declaration()):
css_parsing_params_construct_dom_document(&parsing_params, dom_node_document(dom_abstract_element_element_const(&owner_node).dom_node()))
else:
css_parsing_params_construct_css_parsing_mode(&parsing_params)
ak.vector_append_t(&parsing_params.rule_context, CssRuleContext.style)
let style = parse_css_property_declaration_block(parsing_params, css_text)
css_style_properties_set_the_declarations(this, style.properties, style.custom_properties)