Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.0

0.6.0 / src / web / css / length.lucb

#==============================================================================================
#
#   length - Length and LengthOrAuto: <length> values, their units and conversion to pixels
#
#   DESCRIPTION:
#       Port of LibWeb/CSS/Length.cpp (lines 1-291) and the inline members of Length.h
#       (Length, Length::FontMetrics, Length::ResolutionContext and LengthOrAuto), in the
#       order of Length.cpp with each header member beside its declaration's neighbours.
#       C++'s operator== on Length is css_length_eq; FontMetrics, ResolutionContext and
#       LengthOrAuto compare with Luce's structural `==` (their C++ operator== is defaulted).
#
#       Copyright (c) 2018-2024, Andreas Kling <andreas@ladybird.org>
#       Copyright (c) 2021-2025, Sam Atkins <sam@ladybird.org>
#       Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

# mark: Construction ============================================================================

## Ported from Libraries/LibWeb/CSS/Length.cpp:25 Web::CSS::Length::FontMetrics::FontMetrics.
pub func css_length_font_metrics_construct(this: CssLengthFontMetrics*, font_size: gfx.CssPixels, pixel_metrics: web_fonts.FontPixelMetrics, line_height: gfx.CssPixels):
    this.font_size = font_size
    this.x_height = gfx.css_pixels_from_f32(pixel_metrics.x_height)
    # FIXME: This is only approximately the cap height. The spec suggests measuring the "O" glyph:
    #        https://www.w3.org/TR/css-values-4/#cap
    this.cap_height = gfx.css_pixels_from_f32(pixel_metrics.ascent)
    this.zero_advance = gfx.css_pixels_from_f32(pixel_metrics.advance_of_ascii_zero)
    this.line_height = line_height

## `FontMetrics { font_size, pixel_metrics, line_height }` as a value.
pub func css_length_font_metrics_new(font_size: gfx.CssPixels, pixel_metrics: web_fonts.FontPixelMetrics, line_height: gfx.CssPixels) -> CssLengthFontMetrics:
    var font_metrics: CssLengthFontMetrics = ---
    css_length_font_metrics_construct(&font_metrics, font_size, pixel_metrics, line_height)
    return font_metrics

## Ported from Libraries/LibWeb/CSS/Length.h:36 Web::CSS::Length::Length.
pub func css_length_construct(this: CssLength*, value: f64, unit_: css_data.LengthUnit):
    this.m_unit = unit_
    this.m_value = value

## `Length { value, unit }` as a value.
pub func css_length_new(value: f64, unit_: css_data.LengthUnit) -> CssLength:
    var length: CssLength = ---
    css_length_construct(&length, value, unit_)
    return length

## Ported from Libraries/LibWeb/CSS/Length.h:43 Web::CSS::Length::make_px.
pub func css_length_make_px_f64(value: f64) -> CssLength:
    return css_length_new(value, css_data.LengthUnit.px)

## Ported from Libraries/LibWeb/CSS/Length.h:44 Web::CSS::Length::make_px.
pub func css_length_make_px_css_pixels(value: gfx.CssPixels) -> CssLength:
    return css_length_make_px_f64(value.to_double())

## Ported from Libraries/LibWeb/CSS/Length.cpp:36 Web::CSS::Length::percentage_of.
pub func css_length_percentage_of(this: const CssLength*, percentage: CssPercentage) -> CssLength:
    return css_length_new(css_percentage_as_fraction(&percentage) * css_length_raw_value(this), this.m_unit)

# mark: Units ===================================================================================

## Ported from Libraries/LibWeb/CSS/Length.h:47 Web::CSS::Length::is_px.
pub func css_length_is_px(this: const CssLength*) -> bool:
    return this.m_unit == css_data.LengthUnit.px

## Ported from Libraries/LibWeb/CSS/Length.h:49 Web::CSS::Length::is_absolute.
pub func css_length_is_absolute(this: const CssLength*) -> bool:
    return css_data.is_absolute(this.m_unit)

## Ported from Libraries/LibWeb/CSS/Length.h:50 Web::CSS::Length::is_font_relative.
pub func css_length_is_font_relative(this: const CssLength*) -> bool:
    return css_data.is_font_relative(this.m_unit)

## Ported from Libraries/LibWeb/CSS/Length.h:51 Web::CSS::Length::is_viewport_relative.
pub func css_length_is_viewport_relative(this: const CssLength*) -> bool:
    return css_data.is_viewport_relative(this.m_unit)

## Ported from Libraries/LibWeb/CSS/Length.h:52 Web::CSS::Length::is_relative.
pub func css_length_is_relative(this: const CssLength*) -> bool:
    return css_data.is_relative(this.m_unit)

## Ported from Libraries/LibWeb/CSS/Length.h:54 Web::CSS::Length::is_computationally_independent.
# FIXME: Mark container query units as not computationally independent once we support them
pub func css_length_is_computationally_independent(this: const CssLength*) -> bool:
    return not css_length_is_font_relative(this)

## Ported from Libraries/LibWeb/CSS/Length.h:56 Web::CSS::Length::raw_value.
pub func css_length_raw_value(this: const CssLength*) -> f64:
    return this.m_value

## Ported from Libraries/LibWeb/CSS/Length.h:57 Web::CSS::Length::unit.
pub func css_length_unit(this: const CssLength*) -> css_data.LengthUnit:
    return this.m_unit

## Ported from Libraries/LibWeb/CSS/Length.h:58 Web::CSS::Length::unit_name.
pub func css_length_unit_name(this: const CssLength*) -> ak.FlyString:
    return css_data.to_string_length_unit(this.m_unit)

# mark: Relative lengths ========================================================================

## Ported from Libraries/LibWeb/CSS/Length.cpp:41 Web::CSS::Length::font_relative_length_to_px.
pub func css_length_font_relative_length_to_px(this: const CssLength*, font_metrics: CssLengthFontMetrics, root_font_metrics: CssLengthFontMetrics) -> gfx.CssPixels:
    return gfx.css_pixels_nearest_value_for_f64(css_length_font_relative_length_to_px_without_rounding(this, font_metrics, root_font_metrics))

## Ported from Libraries/LibWeb/CSS/Length.cpp:46 Web::CSS::Length::font_relative_length_to_px_without_rounding.
pub func css_length_font_relative_length_to_px_without_rounding(this: const CssLength*, font_metrics: CssLengthFontMetrics, root_font_metrics: CssLengthFontMetrics) -> f64:
    match this.m_unit:
        .em: return this.m_value * font_metrics.font_size.to_double()
        .rem: return this.m_value * root_font_metrics.font_size.to_double()
        .ex: return this.m_value * font_metrics.x_height.to_double()
        .rex: return this.m_value * root_font_metrics.x_height.to_double()
        .cap: return this.m_value * font_metrics.cap_height.to_double()
        .rcap: return this.m_value * root_font_metrics.cap_height.to_double()
        .ch: return this.m_value * font_metrics.zero_advance.to_double()
        .rch: return this.m_value * root_font_metrics.zero_advance.to_double()
        .ic:
            # FIXME: Use the "advance measure of the “水” (CJK water ideograph, U+6C34) glyph"
            return this.m_value * font_metrics.font_size.to_double()
        .ric:
            # FIXME: Use the "advance measure of the “水” (CJK water ideograph, U+6C34) glyph"
            return this.m_value * root_font_metrics.font_size.to_double()
        .lh: return this.m_value * font_metrics.line_height.to_double()
        .rlh: return this.m_value * root_font_metrics.line_height.to_double()
        _: trap("VERIFY_NOT_REACHED")

## Ported from Libraries/LibWeb/CSS/Length.cpp:80 Web::CSS::Length::viewport_relative_length_to_px.
pub func css_length_viewport_relative_length_to_px(this: const CssLength*, viewport_rect: gfx.CssPixelRect) -> gfx.CssPixels:
    return gfx.css_pixels_nearest_value_for_f64(css_length_viewport_relative_length_to_px_without_rounding(this, viewport_rect))

## Ported from Libraries/LibWeb/CSS/Length.cpp:85 Web::CSS::Length::viewport_relative_length_to_px_without_rounding.
pub func css_length_viewport_relative_length_to_px_without_rounding(this: const CssLength*, viewport_rect: gfx.CssPixelRect) -> f64:
    let width = gfx.css_pixel_rect_width(&viewport_rect)
    let height = gfx.css_pixel_rect_height(&viewport_rect)
    match this.m_unit:
        .vw, .svw, .lvw, .dvw:
            return gfx.mul_css_pixels_f64(width, this.m_value) / 100.0
        .vh, .svh, .lvh, .dvh:
            return gfx.mul_css_pixels_f64(height, this.m_value) / 100.0
        .vi, .svi, .lvi, .dvi:
            # FIXME: Select the width or height based on which is the inline axis.
            return gfx.mul_css_pixels_f64(width, this.m_value) / 100.0
        .vb, .svb, .lvb, .dvb:
            # FIXME: Select the width or height based on which is the block axis.
            return gfx.mul_css_pixels_f64(height, this.m_value) / 100.0
        .vmin, .svmin, .lvmin, .dvmin:
            return gfx.mul_css_pixels_f64(ak.min(width, height), this.m_value) / 100.0
        .vmax, .svmax, .lvmax, .dvmax:
            return gfx.mul_css_pixels_f64(ak.max(width, height), this.m_value) / 100.0
        _: trap("VERIFY_NOT_REACHED")

# mark: Resolution contexts =====================================================================

## Ported from Libraries/LibWeb/CSS/Length.cpp:125 Web::CSS::Length::ResolutionContext::for_element.
pub func css_length_resolution_context_for_element(element: DomAbstractElement) -> CssLengthResolutionContext:
    var abstract_element = element
    let dom_element = dom_abstract_element_element(&abstract_element)
    let root_element = dom_document_document_element(dom_element_document(dom_element))
    let computed_properties = dom_abstract_element_computed_properties(&abstract_element) else trap("VERIFY: computed properties")
    let root = root_element else trap("VERIFY: a root element")
    let root_computed_properties = dom_element_computed_properties(root) else trap("VERIFY: the root's computed properties")
    let font_computer = dom_document_font_computer(dom_abstract_element_document(&abstract_element))
    let navigable = dom_node_navigable(dom_element.dom_node()) else trap("VERIFY: a navigable")
    return CssLengthResolutionContext(
        viewport_rect = html_navigable_viewport_rect(navigable),
        font_metrics = css_length_font_metrics_new(css_computed_properties_font_size(computed_properties), web_fonts.font_pixel_metrics(css_computed_properties_first_available_computed_font(computed_properties, font_computer)), css_computed_properties_line_height(computed_properties)),
        root_font_metrics = css_length_font_metrics_new(css_computed_properties_font_size(root_computed_properties), web_fonts.font_pixel_metrics(css_computed_properties_first_available_computed_font(root_computed_properties, font_computer)), css_computed_properties_line_height(computed_properties)),
    )

## Ported from Libraries/LibWeb/CSS/Length.cpp:140 Web::CSS::Length::ResolutionContext::for_document.
pub func css_length_resolution_context_for_document(document: DomDocument*) -> CssLengthResolutionContext:
    let initial_font = css_font_computer_initial_font(dom_document_font_computer(document))
    let initial_font_metrics = web_fonts.font_pixel_metrics(initial_font)
    let font_metrics = css_length_font_metrics_new(gfx.css_pixels_from_f32(web_fonts.font_pixel_size(initial_font)), initial_font_metrics, css_initial_values_line_height())
    var viewport_rect: gfx.CssPixelRect
    if let navigable = dom_document_navigable(document):
        viewport_rect = html_navigable_viewport_rect(navigable)

    return CssLengthResolutionContext(
        viewport_rect = viewport_rect,
        font_metrics = font_metrics,
        root_font_metrics = font_metrics,
    )

## Ported from Libraries/LibWeb/CSS/Length.cpp:157 Web::CSS::Length::ResolutionContext::for_layout_node.
pub func css_length_resolution_context_for_layout_node(node: LayoutNode*) -> CssLengthResolutionContext:
    var root_layout_node: LayoutNode* = node
    var is_document = false
    if let dom_node = layout_node_dom_node(node):
        is_document = is_dom_document(dom_node)
    if not is_document:
        let root_element = dom_document_document_element(layout_node_document(node)) else trap("VERIFY: a root element")
        # NB: Called during CSS length resolution, which may happen during style recalculation.
        let root_element_layout_node = dom_element_unsafe_layout_node(root_element) else trap("VERIFY: the root element's layout node")
        root_layout_node = root_element_layout_node.layout_node()

    let navigable = layout_node_navigable(node) else trap("VERIFY: a navigable")
    let computed_values = layout_node_computed_values(node)
    let root_computed_values = layout_node_computed_values(root_layout_node)
    let first_available_font = layout_node_first_available_font(node)
    let root_first_available_font = layout_node_first_available_font(root_layout_node)
    return CssLengthResolutionContext(
        viewport_rect = html_navigable_viewport_rect(navigable),
        font_metrics = css_length_font_metrics_new(css_computed_values_font_size(&computed_values.computed_values), web_fonts.font_pixel_metrics(first_available_font), css_computed_values_line_height(&computed_values.computed_values)),
        root_font_metrics = css_length_font_metrics_new(css_computed_values_font_size(&root_computed_values.computed_values), web_fonts.font_pixel_metrics(root_first_available_font), css_computed_values_line_height(&computed_values.computed_values)),
    )

# mark: Conversion to pixels ====================================================================

## Ported from Libraries/LibWeb/CSS/Length.cpp:178 Web::CSS::Length::to_px.
pub func css_length_to_px_css_length_resolution_context(this: const CssLength*, context: CssLengthResolutionContext) -> gfx.CssPixels:
    return css_length_to_px_css_pixel_rect(this, context.viewport_rect, context.font_metrics, context.root_font_metrics)

## Ported from Libraries/LibWeb/CSS/Length.h:74 Web::CSS::Length::to_px.
pub func css_length_to_px_layout_node(this: const CssLength*, node: LayoutNode*) -> gfx.CssPixels:
    if css_length_is_absolute(this):
        return css_length_absolute_length_to_px(this)
    return css_length_to_px_slow_case(this, node)

## Ported from Libraries/LibWeb/CSS/Length.h:81 Web::CSS::Length::to_px_without_rounding.
pub func css_length_to_px_without_rounding(this: const CssLength*, context: CssLengthResolutionContext) -> f64:
    if css_length_is_absolute(this):
        return css_length_absolute_length_to_px_without_rounding(this)
    if css_length_is_font_relative(this):
        return css_length_font_relative_length_to_px_without_rounding(this, context.font_metrics, context.root_font_metrics)
    if css_length_is_viewport_relative(this):
        return css_length_viewport_relative_length_to_px_without_rounding(this, context.viewport_rect)
    trap("VERIFY_NOT_REACHED")

## Ported from Libraries/LibWeb/CSS/Length.h:93 Web::CSS::Length::to_px.
pub func css_length_to_px_css_pixel_rect(this: const CssLength*, viewport_rect: gfx.CssPixelRect, font_metrics: CssLengthFontMetrics, root_font_metrics: CssLengthFontMetrics) -> gfx.CssPixels:
    if css_length_is_absolute(this):
        return css_length_absolute_length_to_px(this)
    if css_length_is_font_relative(this):
        return css_length_font_relative_length_to_px(this, font_metrics, root_font_metrics)
    if css_length_is_viewport_relative(this):
        return css_length_viewport_relative_length_to_px(this, viewport_rect)
    trap("VERIFY_NOT_REACHED")

## Ported from Libraries/LibWeb/CSS/Length.h:105 Web::CSS::Length::absolute_length_to_px.
pub func css_length_absolute_length_to_px(this: const CssLength*) -> gfx.CssPixels:
    return gfx.css_pixels_nearest_value_for_f64(css_length_absolute_length_to_px_without_rounding(this))

## Ported from Libraries/LibWeb/CSS/Length.h:110 Web::CSS::Length::absolute_length_to_px_without_rounding.
pub func css_length_absolute_length_to_px_without_rounding(this: const CssLength*) -> f64:
    return css_data.ratio_between_units_length_unit(this.m_unit, css_data.LengthUnit.px) * this.m_value

## Ported from Libraries/LibWeb/CSS/Length.cpp:183 Web::CSS::Length::to_px_slow_case.
pub func css_length_to_px_slow_case(this: const CssLength*, layout_node: LayoutNode*) -> gfx.CssPixels:
    let document = layout_node_document(layout_node)
    if dom_document_browsing_context(document) == none:
        return gfx.css_pixels_from_int(0)

    if css_length_is_font_relative(this):
        let root_element = dom_document_document_element(document)
        # NB: Called during CSS length resolution, which may happen during style recalculation.
        let root = root_element else return gfx.css_pixels_from_int(0)
        let root_layout_node = dom_element_unsafe_layout_node(root) else return gfx.css_pixels_from_int(0)

        let computed_values = layout_node_computed_values(layout_node)
        let first_available_font = layout_node_first_available_font(layout_node)
        let font_metrics = css_length_font_metrics_new(
            css_computed_values_font_size(&computed_values.computed_values),
            web_fonts.font_pixel_metrics(first_available_font),
            css_computed_values_line_height(&computed_values.computed_values),
        )
        let root_computed_values = layout_node_computed_values(root_layout_node.layout_node())
        let root_first_available_font = layout_node_first_available_font(root_layout_node.layout_node())
        let root_font_metrics = css_length_font_metrics_new(
            css_computed_values_font_size(&root_computed_values.computed_values),
            web_fonts.font_pixel_metrics(root_first_available_font),
            css_computed_values_line_height(&computed_values.computed_values),
        )
        return css_length_font_relative_length_to_px(this, font_metrics, root_font_metrics)

    assert(css_length_is_viewport_relative(this))
    let viewport_rect = dom_document_viewport_rect(document)
    return css_length_viewport_relative_length_to_px(this, viewport_rect)

# mark: Serialization, absolutization, style values =============================================

## Ported from Libraries/LibWeb/CSS/Length.cpp:213 Web::CSS::Length::serialize.
pub func css_length_serialize(this: const CssLength*, builder: ak.StringBuilder*, serialization_mode: css_syntax.SerializationMode = css_syntax.SerializationMode.normal):
    # https://drafts.csswg.org/cssom/#serialize-a-css-value
    # -> <length>
    # The <number> component serialized as per <number> followed by the unit in its canonical form as defined in its
    # respective specification.
    # FIXME: Manually skip this for px so we avoid rounding errors in absolute_length_to_px.
    #        Maybe provide alternative functions that don't produce CSSPixels?
    if serialization_mode == css_syntax.SerializationMode.resolved_value and css_length_is_absolute(this) and this.m_unit != css_data.LengthUnit.px:
        css_syntax.serialize_a_number_string_builder(builder, css_length_absolute_length_to_px(this).to_double())
        ak.string_builder_append(builder, "px")
        return
    css_syntax.serialize_a_number_string_builder(builder, this.m_value)
    let unit_name = css_length_unit_name(this)
    ak.string_builder_append_string_view(builder, ak.fly_string_bytes_as_string_view(&unit_name))

## Ported from Libraries/LibWeb/CSS/Length.cpp:231 Web::CSS::Length::to_string.
pub func css_length_to_string(this: const CssLength*, serialization_mode: css_syntax.SerializationMode = css_syntax.SerializationMode.normal) -> ak.String:
    var builder = ak.string_builder_new()
    css_length_serialize(this, &builder, serialization_mode)
    return ak.string_builder_to_string_without_validation(&builder)

## Ported from Libraries/LibWeb/CSS/Length.h:118 Web::CSS::Length::operator==.
pub func css_length_eq(this: const CssLength*, other: CssLength) -> bool:
    return this.m_unit == other.m_unit and this.m_value == other.m_value

## Ported from Libraries/LibWeb/CSS/Length.cpp:238 Web::CSS::Length::absolutize.
# Returns empty optional if it's already absolute.
pub func css_length_absolutize(this: const CssLength*, context: CssLengthResolutionContext) -> CssLength?:
    if css_length_is_px(this):
        return none
    return css_length_make_px_f64(css_length_to_px_without_rounding(this, context))

## Ported from Libraries/LibWeb/CSS/Length.cpp:246 Web::CSS::Length::from_style_value.
pub func css_length_from_style_value(style_value: CssStyleValue*, percentage_basis: CssLength?) -> CssLength:
    if css_style_value_is_length(style_value):
        return css_length_style_value_length(css_style_value_as_length(style_value))

    if css_style_value_is_calculated(style_value):
        var resolved_percentage_basis = CssCalculationResolutionContextPercentageBasis.empty

        if let basis = percentage_basis:
            resolved_percentage_basis = .css_length(basis)

        return css_calculated_style_value_resolve_length(css_style_value_as_calculated(style_value), CssCalculationResolutionContext(percentage_basis = resolved_percentage_basis)) else trap("VERIFY: a resolved length")

    if css_style_value_is_percentage(style_value):
        let basis = percentage_basis else trap("VERIFY: a percentage basis")

        return css_length_percentage_of(&basis, css_percentage_style_value_percentage(css_style_value_as_percentage(style_value)))

    trap("VERIFY_NOT_REACHED")

## Ported from Libraries/LibWeb/CSS/Length.cpp:270 Web::CSS::LengthOrAuto::from_style_value.
pub func css_length_or_auto_from_style_value(style_value: CssStyleValue*, percentage_basis: CssLength?) -> CssLengthOrAuto:
    if css_style_value_has_auto(style_value):
        return css_length_or_auto_make_auto()
    return css_length_or_auto_new(css_length_from_style_value(style_value, percentage_basis))

## Ported from Libraries/LibWeb/CSS/Length.cpp:277 Web::CSS::Length::resolve_calculated.
pub func css_length_resolve_calculated_css_length(calculated: CssCalculatedStyleValue*, layout_node: LayoutNode*, reference_value: CssLength) -> CssLength:
    let context = CssCalculationResolutionContext(
        percentage_basis = .css_length(reference_value),
        length_resolution_context = css_length_resolution_context_for_layout_node(layout_node),
    )
    return css_calculated_style_value_resolve_length(calculated, context) else trap("VERIFY: a resolved length")

## Ported from Libraries/LibWeb/CSS/Length.cpp:286 Web::CSS::Length::resolve_calculated.
pub func css_length_resolve_calculated_css_pixels(calculated: CssCalculatedStyleValue*, layout_node: LayoutNode*, reference_value: gfx.CssPixels) -> CssLength:
    return css_length_resolve_calculated_css_length(calculated, layout_node, css_length_make_px_css_pixels(reference_value))

# mark: LengthOrAuto ============================================================================

## Ported from Libraries/LibWeb/CSS/Length.h:145 Web::CSS::LengthOrAuto::LengthOrAuto.
pub func css_length_or_auto_construct_css_length(this: CssLengthOrAuto*, length: CssLength):
    this.m_length = length

## `LengthOrAuto { length }` (the implicit conversion from a Length) as a value.
pub func css_length_or_auto_new(length: CssLength) -> CssLengthOrAuto:
    var length_or_auto: CssLengthOrAuto = ---
    css_length_or_auto_construct_css_length(&length_or_auto, length)
    return length_or_auto

## Ported from Libraries/LibWeb/CSS/Length.h:150 Web::CSS::LengthOrAuto::make_auto.
pub func css_length_or_auto_make_auto() -> CssLengthOrAuto:
    var length_or_auto: CssLengthOrAuto = ---
    css_length_or_auto_construct_optional_css_length(&length_or_auto, none)
    return length_or_auto

## Ported from Libraries/LibWeb/CSS/Length.h:153 Web::CSS::LengthOrAuto::is_length.
pub func css_length_or_auto_is_length(this: const CssLengthOrAuto*) -> bool:
    return this.m_length != none

## Ported from Libraries/LibWeb/CSS/Length.h:154 Web::CSS::LengthOrAuto::is_auto.
pub func css_length_or_auto_is_auto(this: const CssLengthOrAuto*) -> bool:
    return this.m_length == none

## Ported from Libraries/LibWeb/CSS/Length.h:156 Web::CSS::LengthOrAuto::length.
pub func css_length_or_auto_length(this: const CssLengthOrAuto*) -> CssLength:
    return this.m_length else trap("VERIFY: a length")

## Ported from Libraries/LibWeb/CSS/Length.h:158 Web::CSS::LengthOrAuto::serialize.
pub func css_length_or_auto_serialize(this: const CssLengthOrAuto*, builder: ak.StringBuilder*, mode: css_syntax.SerializationMode = css_syntax.SerializationMode.normal):
    if let length = this.m_length:
        css_length_serialize(&length, builder, mode)
    else:
        ak.string_builder_append(builder, "auto")

## Ported from Libraries/LibWeb/CSS/Length.h:166 Web::CSS::LengthOrAuto::to_string.
pub func css_length_or_auto_to_string(this: const CssLengthOrAuto*, mode: css_syntax.SerializationMode = css_syntax.SerializationMode.normal) -> ak.String:
    var builder = ak.string_builder_new()
    css_length_or_auto_serialize(this, &builder, mode)
    return ak.string_builder_to_string_without_validation(&builder)

## Ported from Libraries/LibWeb/CSS/Length.h:173 Web::CSS::LengthOrAuto::to_px_or_zero.
pub func css_length_or_auto_to_px_or_zero(this: const CssLengthOrAuto*, node: LayoutNode*) -> gfx.CssPixels:
    let length = this.m_length else return gfx.css_pixels_from_int(0)
    return css_length_to_px_layout_node(&length, node)

## Ported from Libraries/LibWeb/CSS/Length.h:180 Web::CSS::LengthOrAuto::is_font_relative.
pub func css_length_or_auto_is_font_relative(this: const CssLengthOrAuto*) -> bool:
    if let length = this.m_length:
        return css_length_is_font_relative(&length)
    return false

## Ported from Libraries/LibWeb/CSS/Length.h:181 Web::CSS::LengthOrAuto::is_computationally_independent.
pub func css_length_or_auto_is_computationally_independent(this: const CssLengthOrAuto*) -> bool:
    if let length = this.m_length:
        return css_length_is_computationally_independent(&length)
    return true

## Ported from Libraries/LibWeb/CSS/Length.h:186 Web::CSS::LengthOrAuto::LengthOrAuto.
pub func css_length_or_auto_construct_optional_css_length(this: CssLengthOrAuto*, maybe_length: CssLength?):
    this.m_length = maybe_length