Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.0

0.6.0 / src / web / css / style_values / integer_style_value.lucb

#==============================================================================================
#
#   integer_style_value - IntegerStyleValue: an <integer>
#
#   DESCRIPTION:
#       Port of LibWeb/CSS/StyleValues/IntegerStyleValue.cpp (lines 1-48) and the inline members
#       of IntegerStyleValue.h.
#
#       Copyright (c) 2023-2025, Sam Atkins <sam@ladybird.org>
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

## Ported from Libraries/LibWeb/CSS/StyleValues/IntegerStyleValue.h:15 Web::CSS::IntegerStyleValue::create.
pub func css_integer_style_value_create(value: i32) -> CssIntegerStyleValue*:
    let this = &(new CssIntegerStyleValue[1] --- else trap("out of memory"))[0]
    css_integer_style_value_construct(this, value)
    return this

## Ported from Libraries/LibWeb/CSS/StyleValues/IntegerStyleValue.h:20 Web::CSS::IntegerStyleValue::integer.
pub func css_integer_style_value_integer(this: CssIntegerStyleValue*) -> i32:
    return this.m_value

## Ported from Libraries/LibWeb/CSS/StyleValues/IntegerStyleValue.cpp:14 Web::CSS::IntegerStyleValue::serialize (override).
pub func css_integer_style_value_serialize_impl(base: CssStyleValue*, builder: ak.StringBuilder*, arg1: css_syntax.SerializationMode):
    _ = arg1
    let this = (CssIntegerStyleValue*)base
    css_appendff(builder, "{}", [ak.arg_i64((i64)this.m_value)])

## Ported from Libraries/LibWeb/CSS/StyleValues/IntegerStyleValue.cpp:19 Web::CSS::IntegerStyleValue::tokenize (override).
pub func css_integer_style_value_tokenize_impl(base: CssStyleValue*) -> ak.Vector[css_syntax.ComponentValue]:
    let this = (CssIntegerStyleValue*)base
    var values = ak.Vector[css_syntax.ComponentValue]()
    ak.vector_append_t(&values, css_syntax.component_value_from_token(css_syntax.token_create_number(css_syntax.number_create(css_syntax.NumberType.integer, (f64)this.m_value), ak.String())))
    return values

# https://drafts.css-houdini.org/css-typed-om-1/#reify-a-numeric-value
## Ported from Libraries/LibWeb/CSS/StyleValues/IntegerStyleValue.cpp:25 Web::CSS::IntegerStyleValue::reify (override).
pub func css_integer_style_value_reify_impl(base: CssStyleValue*, realm: Realm*, associated_property: ak.FlyString) -> CssCssStyleValue*:
    let this = (CssIntegerStyleValue*)base
    # NB: Step 1 doesn't apply here.
    # 2. If num is the unitless value 0 and num is a <dimension>, return a new CSSUnitValue with its value internal
    #    slot set to 0, and its unit internal slot set to "px".
    if this.m_value == 0:
        # NB: Determine whether the associated property expects 0 to be a <length>.
        # FIXME: Do this for registered custom properties.
        if let property_id = css_data.property_id_from_string(ak.fly_string_bytes_as_string_view(&associated_property)):
            if property_id != css_data.PropertyId.custom and css_property_accepts_type(property_id, CssValueType.length):
                return (CssCssStyleValue*)css_unit_value_create(realm, 0.0, ak.fly_string_from_str("px"))
    # 3. Return a new CSSUnitValue with its value internal slot set to the numeric value of num, and its unit internal
    #    slot set to "number" if num is a <number>, "percent" if num is a <percentage>, and num’s unit if num is a
    #    <dimension>.
    #    If the value being reified is a computed value, the unit used must be the appropriate canonical unit for the
    #    value’s type, with the numeric value scaled accordingly.
    return (CssCssStyleValue*)css_unit_value_create(realm, (f64)this.m_value, ak.fly_string_from_str("number"))

## Ported from Libraries/LibWeb/CSS/StyleValues/IntegerStyleValue.h:26 Web::CSS::IntegerStyleValue::equals (override).
pub func css_integer_style_value_equals_impl(base: CssStyleValue*, other: CssStyleValue*) -> bool:
    let this = (CssIntegerStyleValue*)base
    if css_style_value_type(base) != css_style_value_type(other):
        return false
    let other_integer = css_style_value_as_integer(other)
    return this.m_value == other_integer.m_value

## Ported from Libraries/LibWeb/CSS/StyleValues/IntegerStyleValue.h:34 Web::CSS::IntegerStyleValue::is_computationally_independent (override).
pub func css_integer_style_value_is_computationally_independent_impl(base: CssStyleValue*) -> bool:
    _ = base
    return true

## Ported from Libraries/LibWeb/CSS/StyleValues/IntegerStyleValue.h:37 Web::CSS::IntegerStyleValue::IntegerStyleValue.
pub func css_integer_style_value_construct(this: CssIntegerStyleValue*, value: i32):
    css_style_value_construct(this.css_style_value(), CssStyleValueType.integer)
    css_style_value_set_class(this.css_style_value(), (const CssStyleValueVTable*)&css_integer_style_value_vtable, &css_integer_style_value_class)
    this.m_value = value