dymokomi/luce-browser-engine
Source of release 0.6.0
0.6.0 / src / web / css / descriptor_name_and_id.lucb
#==============================================================================================
#
# descriptor_name_and_id - DescriptorNameAndID: a descriptor's name with its DescriptorID
#
# DESCRIPTION:
# Port of LibWeb/CSS/DescriptorNameAndID.h (lines 1-72), with the hash of
# AK::Traits<DescriptorNameAndID> (CssDescriptorNameAndIdTraits in
# generated/types_traits calls css_descriptor_name_and_id_hash and _eq).
#
# Copyright (c) 2026, Callum Law <callumlaw1709@outlook.com>
# SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================
## Ported from Libraries/LibWeb/CSS/DescriptorNameAndID.h:17 Web::CSS::DescriptorNameAndID::from_name.
pub func css_descriptor_name_and_id_from_name(at_rule_id: css_data.AtRuleId, name: ak.FlyString) -> CssDescriptorNameAndId?:
let name_view = ak.fly_string_bytes_as_string_view(&name)
if css_data.is_a_custom_property_name_string(name_view):
return css_descriptor_name_and_id_new(name, css_data.DescriptorId.custom)
if let descriptor_id = css_data.descriptor_id_from_string(at_rule_id, name_view):
# NB: We use the serialized ID as the name here instead of the input name to ensure that legacy alias
# mapping is reflected
return css_descriptor_name_and_id_new(css_data.to_string_descriptor_id(descriptor_id), descriptor_id)
return none
## Ported from Libraries/LibWeb/CSS/DescriptorNameAndID.h:31 Web::CSS::DescriptorNameAndID::from_id.
pub func css_descriptor_name_and_id_from_id(descriptor_id: css_data.DescriptorId) -> CssDescriptorNameAndId:
assert(descriptor_id != css_data.DescriptorId.custom)
return css_descriptor_name_and_id_new(css_data.to_string_descriptor_id(descriptor_id), descriptor_id)
## Ported from Libraries/LibWeb/CSS/DescriptorNameAndID.h:37 Web::CSS::DescriptorNameAndID::id.
pub func css_descriptor_name_and_id_id(this: const CssDescriptorNameAndId*) -> css_data.DescriptorId:
return this.m_id
## Ported from Libraries/LibWeb/CSS/DescriptorNameAndID.h:39 Web::CSS::DescriptorNameAndID::name.
pub func css_descriptor_name_and_id_name(this: const CssDescriptorNameAndId*) -> ak.FlyString:
return this.m_name
## Ported from Libraries/LibWeb/CSS/DescriptorNameAndID.h:44 Web::CSS::DescriptorNameAndID::operator==.
pub func css_descriptor_name_and_id_eq(this: const CssDescriptorNameAndId*, other: CssDescriptorNameAndId) -> bool:
return this.m_id == other.m_id and ak.fly_string_eq_fly_string(&this.m_name, &other.m_name)
## Ported from Libraries/LibWeb/CSS/DescriptorNameAndID.h:50 Web::CSS::DescriptorNameAndID::DescriptorNameAndID.
pub func css_descriptor_name_and_id_construct(this: CssDescriptorNameAndId*, name: ak.FlyString, id: css_data.DescriptorId):
this.m_name = name
this.m_id = id
## `DescriptorNameAndID(name, id)` as a value.
func css_descriptor_name_and_id_new(name: ak.FlyString, id: css_data.DescriptorId) -> CssDescriptorNameAndId:
var result: CssDescriptorNameAndId = ---
css_descriptor_name_and_id_construct(&result, name, id)
return result
## Ported from Libraries/LibWeb/CSS/DescriptorNameAndID.h:66 AK::Traits<Web::CSS::DescriptorNameAndID>::hash.
pub func css_descriptor_name_and_id_hash(descriptor_name_and_id: const CssDescriptorNameAndId*) -> u32:
return ak.pair_int_hash((u32)css_descriptor_name_and_id_id(descriptor_name_and_id), ak.fly_string_hash(&descriptor_name_and_id.m_name))