Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.0

0.6.0 / src / web / css / css_style_properties_3.lucb

#==============================================================================================
#
#   css_style_properties_3 - CSS::CSSStyleProperties: the resolved value of a property
#
#   DESCRIPTION:
#       Port of LibWeb/CSS/CSSStyleProperties.cpp (lines 646-1043):
#       style_value_for_computed_property, the "resolved value" getComputedStyle() reports for a
#       property of an element with a layout node: used values of sizes, margins, paddings and
#       insets, colors, shadows, the transform matrix, the grid track lists, and shorthands
#       assembled from their longhands. Its lambdas are the private functions above it.
#
#       Copyright (c) 2018-2024, Andreas Kling <andreas@ladybird.org>
#       Copyright (c) 2023-2025, Sam Atkins <sam@ladybird.org>
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

## AK/Debug.h's LIBWEB_CSS_DEBUG (0 in the reference build).
let css_libweb_css_debug: bool = false

# mark: The lambdas =============================================================================

## A getter of a used value from a paintable box (the lambdas passed to used_value_for_property).
type CssUsedValueGetter = func(PaintPaintableBox*) -> gfx.CssPixels

## The used_value_for_property lambda: the used value from the layout node's paintable box, if it
## has one and is displayed.
func css_style_properties_used_value_for_property(layout_node: LayoutNodeWithStyle*, property_id: css_data.PropertyId, used_value_getter: CssUsedValueGetter) -> gfx.CssPixels?:
    let computed_values = layout_node_with_style_computed_values(layout_node)
    let display = css_computed_values_display(&computed_values.computed_values)
    if not css_display_is_none(&display) and not css_display_is_contents(&display):
        if let first_paintable = layout_node_first_paintable(layout_node.layout_node()):
            if let paintable_box = as_if_paint_paintable_box(first_paintable):
                return used_value_getter(paintable_box)
            let name = css_data.string_from_property_id(property_id)
            let description = layout_node_debug_description(layout_node.layout_node())
            ak.dbgln(f"FIXME: Support getting used value for property `{ak.string_view_text(ak.fly_string_bytes_as_string_view(&name))}` on {ak.string_view_text(ak.string_bytes_as_string_view(&description))}")
    return none

## The used_size_for_property lambda: the content-box or the border-box getter, by box-sizing.
func css_style_properties_used_size_for_property(layout_node: LayoutNodeWithStyle*, property_id: css_data.PropertyId, content_box_getter: CssUsedValueGetter, border_box_getter: CssUsedValueGetter) -> gfx.CssPixels?:
    let computed_values = layout_node_with_style_computed_values(layout_node)
    if css_computed_values_box_sizing(&computed_values.computed_values) == css_data.BoxSizing.border_box:
        return css_style_properties_used_value_for_property(layout_node, property_id, border_box_getter)
    return css_style_properties_used_value_for_property(layout_node, property_id, content_box_getter)

## The used_value_for_inset lambda.
func css_style_properties_used_value_for_inset(layout_node: LayoutNodeWithStyle*, property_id: css_data.PropertyId, start_side: const CssLengthPercentageOrAuto*, end_side: const CssLengthPercentageOrAuto*, used_value_getter: CssUsedValueGetter) -> gfx.CssPixels?:
    if not layout_node_is_positioned(layout_node.layout_node()):
        return none

    # FIXME: Support getting the used value when position is sticky.
    if layout_node_is_sticky_position(layout_node.layout_node()):
        return none

    if not css_length_percentage_or_auto_is_percentage(start_side) and not css_length_percentage_or_auto_is_calculated(start_side) and not css_length_percentage_or_auto_is_auto(start_side) and not css_length_percentage_or_auto_is_auto(end_side):
        return none

    return css_style_properties_used_value_for_property(layout_node, property_id, used_value_getter)

## The get_computed_value lambda: the element's computed value of `property_id`.
func css_style_properties_get_computed_value(element: DomElement*, pseudo_element: css_data.PseudoElement?, property_id: css_data.PropertyId) -> CssStyleValue*:
    let computed_properties = dom_element_computed_properties(element, pseudo_element) else trap("null computed properties")
    return css_computed_properties_property(computed_properties, property_id)

## `paintable_box.content_height()`.
func css_used_content_height(paintable_box: PaintPaintableBox*) -> gfx.CssPixels:
    return paint_paintable_box_content_height(paintable_box)

## `paintable_box.absolute_border_box_rect().height()`.
func css_used_border_box_height(paintable_box: PaintPaintableBox*) -> gfx.CssPixels:
    let rect = paint_paintable_box_absolute_border_box_rect(paintable_box)
    return gfx.css_pixel_rect_height(&rect)

## `paintable_box.content_width()`.
func css_used_content_width(paintable_box: PaintPaintableBox*) -> gfx.CssPixels:
    return paint_paintable_box_content_width(paintable_box)

## `paintable_box.absolute_border_box_rect().width()`.
func css_used_border_box_width(paintable_box: PaintPaintableBox*) -> gfx.CssPixels:
    let rect = paint_paintable_box_absolute_border_box_rect(paintable_box)
    return gfx.css_pixel_rect_width(&rect)

## `paintable_box.box_model().margin.top` and the other sides of the margin, padding and inset.
func css_used_margin_top(paintable_box: PaintPaintableBox*) -> gfx.CssPixels:
    return paint_paintable_box_box_model(paintable_box).margin.top

## The used bottom margin.
func css_used_margin_bottom(paintable_box: PaintPaintableBox*) -> gfx.CssPixels:
    return paint_paintable_box_box_model(paintable_box).margin.bottom

## The used left margin.
func css_used_margin_left(paintable_box: PaintPaintableBox*) -> gfx.CssPixels:
    return paint_paintable_box_box_model(paintable_box).margin.left

## The used right margin.
func css_used_margin_right(paintable_box: PaintPaintableBox*) -> gfx.CssPixels:
    return paint_paintable_box_box_model(paintable_box).margin.right

## The used top padding.
func css_used_padding_top(paintable_box: PaintPaintableBox*) -> gfx.CssPixels:
    return paint_paintable_box_box_model(paintable_box).padding.top

## The used bottom padding.
func css_used_padding_bottom(paintable_box: PaintPaintableBox*) -> gfx.CssPixels:
    return paint_paintable_box_box_model(paintable_box).padding.bottom

## The used left padding.
func css_used_padding_left(paintable_box: PaintPaintableBox*) -> gfx.CssPixels:
    return paint_paintable_box_box_model(paintable_box).padding.left

## The used right padding.
func css_used_padding_right(paintable_box: PaintPaintableBox*) -> gfx.CssPixels:
    return paint_paintable_box_box_model(paintable_box).padding.right

## The used top inset.
func css_used_inset_top(paintable_box: PaintPaintableBox*) -> gfx.CssPixels:
    return paint_paintable_box_box_model(paintable_box).inset.top

## The used bottom inset.
func css_used_inset_bottom(paintable_box: PaintPaintableBox*) -> gfx.CssPixels:
    return paint_paintable_box_box_model(paintable_box).inset.bottom

## The used left inset.
func css_used_inset_left(paintable_box: PaintPaintableBox*) -> gfx.CssPixels:
    return paint_paintable_box_box_model(paintable_box).inset.left

## The used right inset.
func css_used_inset_right(paintable_box: PaintPaintableBox*) -> gfx.CssPixels:
    return paint_paintable_box_box_model(paintable_box).inset.right

## A used length as a style value: `LengthStyleValue::create(Length::make_px(value))`.
func css_used_length_style_value(value: gfx.CssPixels) -> CssStyleValue*:
    return css_length_style_value_create(css_length_make_px_css_pixels(value)).css_style_value()

## The is_2d_matrix lambda.
# https://drafts.csswg.org/css-transforms-1/#2d-matrix
func css_is_2d_matrix(matrix: const gfx.FloatMatrix4X4*) -> bool:
    # A 3x2 transformation matrix,
    # or a 4x4 matrix where the items m31, m32, m13, m23, m43, m14, m24, m34 are equal to 0
    # and m33, m44 are equal to 1.
    # NB: We only care about 4x4 matrices here.
    # NB: Our elements are 0-indexed not 1-indexed, and in the opposite order.
    # NB: We use epsilon comparisons here to account for inaccuracies when doing trigonometric calculations.
    let epsilon = ak.f32_epsilon
    if (css_abs_f32(gfx.float_matrix4_x4_at_const(matrix, 0, 2)) > epsilon or css_abs_f32(gfx.float_matrix4_x4_at_const(matrix, 1, 2)) > epsilon or css_abs_f32(gfx.float_matrix4_x4_at_const(matrix, 2, 0)) > epsilon or css_abs_f32(gfx.float_matrix4_x4_at_const(matrix, 2, 1)) > epsilon or css_abs_f32(gfx.float_matrix4_x4_at_const(matrix, 2, 3)) > epsilon or css_abs_f32(gfx.float_matrix4_x4_at_const(matrix, 3, 0)) > epsilon or css_abs_f32(gfx.float_matrix4_x4_at_const(matrix, 3, 1)) > epsilon or css_abs_f32(gfx.float_matrix4_x4_at_const(matrix, 3, 2)) > epsilon):  # m31
        # m32
        # m13
        # m23
        # m43
        # m14
        # m24
        # m34
        return false

    if (css_abs_f32(gfx.float_matrix4_x4_at_const(matrix, 2, 2)) - 1.0 > epsilon or css_abs_f32(gfx.float_matrix4_x4_at_const(matrix, 3, 3)) - 1.0 > epsilon):  # m33
        # m44
        return false

    return true

## `abs(float)`.
func css_abs_f32(value: f32) -> f32:
    return -value if value < 0.0 else value

## NumberStyleValue::create of a matrix element (the float is widened to double, as in C++).
func css_matrix_number(matrix: const gfx.FloatMatrix4X4*, row: usize, column: usize) -> CssStyleValue*:
    return css_number_style_value_create((f64)gfx.float_matrix4_x4_at_const(matrix, row, column)).css_style_value()

# mark: style_value_for_computed_property =======================================================

## Ported from Libraries/LibWeb/CSS/CSSStyleProperties.cpp:647 Web::CSS::CSSStyleProperties::style_value_for_computed_property.
func css_style_properties_style_value_for_computed_property(this: CssStyleProperties*, layout_node: LayoutNodeWithStyle*, property_id: css_data.PropertyId) -> CssStyleValue*?:
    if css_style_declaration_owner_node(this.css_style_declaration()) == none:
        if css_libweb_css_debug:
            ak.dbgln("Computed style for CSSStyleProperties without owner node was requested")
        return none
    var owner_node = css_style_declaration_owner_node(this.css_style_declaration()) else trap("unreachable")

    let element = dom_abstract_element_element(&owner_node)
    let pseudo_element = dom_abstract_element_pseudo_element(&owner_node)
    let computed_values = layout_node_with_style_computed_values(layout_node)
    let values = &computed_values.computed_values

    if css_data.property_is_logical_alias(property_id):
        let computed_properties = dom_element_computed_properties(element, pseudo_element) else trap("null computed properties")
        let context = css_data.LogicalAliasMappingContext(writing_mode = css_computed_properties_writing_mode(computed_properties), direction = css_computed_properties_direction(computed_properties))
        return css_style_properties_style_value_for_computed_property(this, layout_node, css_data.map_logical_alias_to_physical_property(property_id, context))

    # A limited number of properties have special rules for producing their "resolved value".
    # We also have to manually construct shorthands from their longhands here.
    # Everything else uses the computed value.
    # https://drafts.csswg.org/cssom/#resolved-values

    # AD-HOC: We don't resolve logical properties here as we have already handled above
    # The resolved value for a given longhand property can be determined as follows:
    match property_id:
        # -> background-color
        # -> border-block-end-color
        # -> border-block-start-color
        # -> border-bottom-color
        # -> border-inline-end-color
        # -> border-inline-start-color
        # -> border-left-color
        # -> border-right-color
        # -> border-top-color
        # -> box-shadow
        # -> caret-color
        # -> color
        # -> outline-color
        # -> A resolved value special case property like color defined in another specification
        #    The resolved value is the used value.
        .background_color:
            return css_resolve_color_style_value(css_style_properties_get_computed_value(element, pseudo_element, property_id), css_computed_values_background_color(values))
        .border_bottom_color:
            return css_resolve_color_style_value(css_style_properties_get_computed_value(element, pseudo_element, property_id), css_computed_values_border_bottom(values).color)
        .border_left_color:
            return css_resolve_color_style_value(css_style_properties_get_computed_value(element, pseudo_element, property_id), css_computed_values_border_left(values).color)
        .border_right_color:
            return css_resolve_color_style_value(css_style_properties_get_computed_value(element, pseudo_element, property_id), css_computed_values_border_right(values).color)
        .border_top_color:
            return css_resolve_color_style_value(css_style_properties_get_computed_value(element, pseudo_element, property_id), css_computed_values_border_top(values).color)
        .box_shadow:
            return css_style_value_for_shadow(CssShadowStyleValueShadowType.normal, css_computed_values_box_shadow(values))
        .caret_color:
            return css_resolve_color_style_value(css_style_properties_get_computed_value(element, pseudo_element, property_id), css_computed_values_caret_color(values))
        .color:
            return css_resolve_color_style_value(css_style_properties_get_computed_value(element, pseudo_element, property_id), css_computed_values_color(values))
        .outline_color:
            return css_resolve_color_style_value(css_style_properties_get_computed_value(element, pseudo_element, property_id), css_computed_values_outline_color(values))
        .text_decoration_color:
            return css_resolve_color_style_value(css_style_properties_get_computed_value(element, pseudo_element, property_id), css_computed_values_text_decoration_color(values))
        # NB: text-shadow isn't listed, but is computed the same as box-shadow.
        .text_shadow:
            return css_style_value_for_shadow(CssShadowStyleValueShadowType.text, css_computed_values_text_shadow(values))

        # -> line-height
        #    The resolved value is normal if the computed value is normal, or the used value otherwise.
        .line_height:
            let line_height = css_style_properties_get_computed_value(element, pseudo_element, property_id)
            if css_style_value_is_keyword(line_height) and css_style_value_to_keyword(line_height) == css_data.Keyword.normal:
                return line_height
            return css_used_length_style_value(css_computed_values_line_height(values))

        # -> block-size
        # -> height
        # -> inline-size
        # -> margin-block-end
        # -> margin-block-start
        # -> margin-bottom
        # -> margin-inline-end
        # -> margin-inline-start
        # -> margin-left
        # -> margin-right
        # -> margin-top
        # -> padding-block-end
        # -> padding-block-start
        # -> padding-bottom
        # -> padding-inline-end
        # -> padding-inline-start
        # -> padding-left
        # -> padding-right
        # -> padding-top
        # -> width
        # If the property applies to the element or pseudo-element and the resolved value of the
        # display property is not none or contents, then the resolved value is the used value.
        # Otherwise the resolved value is the computed value.
        .height:
            if let used_height = css_style_properties_used_size_for_property(layout_node, property_id, css_used_content_height, css_used_border_box_height):
                return css_style_value_for_size(css_size_make_px(used_height))
            return css_style_value_for_size(css_computed_values_height(values))
        .margin_bottom:
            if let used_value = css_style_properties_used_value_for_property(layout_node, property_id, css_used_margin_bottom):
                return css_used_length_style_value(used_value)
            var margin = css_computed_values_margin(values)
            return css_style_value_for_length_percentage_or_auto(*css_length_box_bottom(&margin))
        .margin_left:
            if let used_value = css_style_properties_used_value_for_property(layout_node, property_id, css_used_margin_left):
                return css_used_length_style_value(used_value)
            var margin = css_computed_values_margin(values)
            return css_style_value_for_length_percentage_or_auto(*css_length_box_left(&margin))
        .margin_right:
            if let used_value = css_style_properties_used_value_for_property(layout_node, property_id, css_used_margin_right):
                return css_used_length_style_value(used_value)
            var margin = css_computed_values_margin(values)
            return css_style_value_for_length_percentage_or_auto(*css_length_box_right(&margin))
        .margin_top:
            if let used_value = css_style_properties_used_value_for_property(layout_node, property_id, css_used_margin_top):
                return css_used_length_style_value(used_value)
            var margin = css_computed_values_margin(values)
            return css_style_value_for_length_percentage_or_auto(*css_length_box_top(&margin))
        .padding_bottom:
            if let used_value = css_style_properties_used_value_for_property(layout_node, property_id, css_used_padding_bottom):
                return css_used_length_style_value(used_value)
            var padding = css_computed_values_padding(values)
            return css_style_value_for_length_percentage_or_auto(*css_length_box_bottom(&padding))
        .padding_left:
            if let used_value = css_style_properties_used_value_for_property(layout_node, property_id, css_used_padding_left):
                return css_used_length_style_value(used_value)
            var padding = css_computed_values_padding(values)
            return css_style_value_for_length_percentage_or_auto(*css_length_box_left(&padding))
        .padding_right:
            if let used_value = css_style_properties_used_value_for_property(layout_node, property_id, css_used_padding_right):
                return css_used_length_style_value(used_value)
            var padding = css_computed_values_padding(values)
            return css_style_value_for_length_percentage_or_auto(*css_length_box_right(&padding))
        .padding_top:
            if let used_value = css_style_properties_used_value_for_property(layout_node, property_id, css_used_padding_top):
                return css_used_length_style_value(used_value)
            var padding = css_computed_values_padding(values)
            return css_style_value_for_length_percentage_or_auto(*css_length_box_top(&padding))
        .width:
            if let used_width = css_style_properties_used_size_for_property(layout_node, property_id, css_used_content_width, css_used_border_box_width):
                return css_style_value_for_size(css_size_make_px(used_width))
            return css_style_value_for_size(css_computed_values_width(values))

        # -> bottom
        # -> left
        # -> inset-block-end
        # -> inset-block-start
        # -> inset-inline-end
        # -> inset-inline-start
        # -> right
        # -> top
        # -> A resolved value special case property like top defined in another specification
        #    If the property applies to a positioned element and the resolved value of the display property is not
        #    none or contents, and the property is not over-constrained, then the resolved value is the used value.
        #    Otherwise the resolved value is the computed value.
        .bottom:
            var inset = css_computed_values_inset(values)
            if let used_value = css_style_properties_used_value_for_inset(layout_node, property_id, css_length_box_bottom(&inset), css_length_box_top(&inset), css_used_inset_bottom):
                return css_used_length_style_value(used_value)

            return css_style_value_for_length_percentage_or_auto(*css_length_box_bottom(&inset))
        .left:
            var inset = css_computed_values_inset(values)
            if let used_value = css_style_properties_used_value_for_inset(layout_node, property_id, css_length_box_left(&inset), css_length_box_right(&inset), css_used_inset_left):
                return css_used_length_style_value(used_value)
            return css_style_value_for_length_percentage_or_auto(*css_length_box_left(&inset))
        .right:
            var inset = css_computed_values_inset(values)
            if let used_value = css_style_properties_used_value_for_inset(layout_node, property_id, css_length_box_right(&inset), css_length_box_left(&inset), css_used_inset_right):
                return css_used_length_style_value(used_value)

            return css_style_value_for_length_percentage_or_auto(*css_length_box_right(&inset))
        .top:
            var inset = css_computed_values_inset(values)
            if let used_value = css_style_properties_used_value_for_inset(layout_node, property_id, css_length_box_top(&inset), css_length_box_bottom(&inset), css_used_inset_top):
                return css_used_length_style_value(used_value)

            return css_style_value_for_length_percentage_or_auto(*css_length_box_top(&inset))

        # -> A resolved value special case property defined in another specification
        #    As defined in the relevant specification.
        .transform:
            return css_style_properties_resolved_transform(layout_node, values)
        .animation_duration:
            # https://drafts.csswg.org/css-animations-2/#animation-duration
            # For backwards-compatibility with Level 1, when the computed value of animation-timeline is auto (i.e. only
            # one list value, and that value being auto), the resolved value of auto for animation-duration is 0s whenever
            # its used value would also be 0s.
            let animation_timeline_computed_value = css_style_properties_get_computed_value(element, pseudo_element, css_data.PropertyId.animation_timeline)
            let animation_duration_computed_value = css_style_properties_get_computed_value(element, pseudo_element, css_data.PropertyId.animation_duration)

            let timeline_list = css_style_value_as_value_list(animation_timeline_computed_value)
            let timeline_values = css_style_value_list_values(timeline_list)
            if css_style_value_list_size(timeline_list) == 1 and css_style_value_to_keyword(*ak.vector_at_const(&timeline_values, 0)) == css_data.Keyword.auto:
                var resolved_durations: ak.Vector[CssStyleValue*]

                let durations = css_style_value_list_values(css_style_value_as_value_list(animation_duration_computed_value))
                for duration in ak.vector_span_const(&durations):
                    if css_style_value_to_keyword(duration) == css_data.Keyword.auto:
                        ak.vector_append_t(&resolved_durations, css_time_style_value_create(css_time_make_seconds(0.0)).css_style_value())
                    else:
                        ak.vector_append_t(&resolved_durations, duration)

                return css_style_value_list_create(resolved_durations, CssStyleValueListSeparator.comma).css_style_value()

            return animation_duration_computed_value
        # If the border-style corresponding to a given border-width is none or hidden, then the used width is 0.
        # https://drafts.csswg.org/css-backgrounds/#border-width
        # NB: We do this adjustment when assigning to ComputedValues, so read from there.
        .border_bottom_width:
            return css_style_value_for_size(css_size_make_px(css_computed_values_border_bottom(values).width))
        .border_left_width:
            return css_style_value_for_size(css_size_make_px(css_computed_values_border_left(values).width))
        .border_right_width:
            return css_style_value_for_size(css_size_make_px(css_computed_values_border_right(values).width))
        .border_top_width:
            return css_style_value_for_size(css_size_make_px(css_computed_values_border_top(values).width))

        # -> Any other property
        #    The resolved value is the computed value.
        .contain:
            let contain = css_computed_values_contain(values)
            if contain.layout_containment and contain.style_containment and contain.paint_containment:
                if contain.size_containment:
                    return css_keyword_style_value_create(css_data.Keyword.strict).css_style_value()
                if not contain.inline_size_containment:
                    return css_keyword_style_value_create(css_data.Keyword.content).css_style_value()

            return css_style_properties_get_computed_value(element, pseudo_element, property_id)
        .webkit_text_fill_color:
            return css_resolve_color_style_value(css_style_properties_get_computed_value(element, pseudo_element, property_id), css_computed_values_webkit_text_fill_color(values))
        .letter_spacing:
            # https://drafts.csswg.org/css-text-4/#letter-spacing-property
            # For legacy reasons, a computed letter-spacing of zero yields a resolved value (getComputedStyle() return value) of normal.
            if css_computed_values_letter_spacing(values) == gfx.css_pixels_from_int(0):
                return css_keyword_style_value_create(css_data.Keyword.normal).css_style_value()
            return css_style_properties_get_computed_value(element, pseudo_element, property_id)
        .custom:
            if css_libweb_css_debug:
                ak.dbgln("Computed style for custom properties was requested (?)")
            return none
        _:
            return css_style_properties_resolved_value_otherwise(this, layout_node, element, pseudo_element, property_id)

## The `default:` case of style_value_for_computed_property's switch.
func css_style_properties_resolved_value_otherwise(this: CssStyleProperties*, layout_node: LayoutNodeWithStyle*, element: DomElement*, pseudo_element: css_data.PseudoElement?, property_id: css_data.PropertyId) -> CssStyleValue*?:
    # For grid-template-columns and grid-template-rows the resolved value is the used value.
    # https://www.w3.org/TR/css-grid-2/#resolved-track-list-standalone
    if property_id == css_data.PropertyId.grid_template_columns:
        if let first_paintable = layout_node_first_paintable(layout_node.layout_node()):
            if paint_paintable_is_paintable_box(first_paintable):
                let paintable_box = as_paint_paintable_box(first_paintable)
                if let used_values_for_grid_template_columns = paint_paintable_box_used_values_for_grid_template_columns(paintable_box):
                    return used_values_for_grid_template_columns.css_style_value()
    elif property_id == css_data.PropertyId.grid_template_rows:
        if let first_paintable = layout_node_first_paintable(layout_node.layout_node()):
            if paint_paintable_is_paintable_box(first_paintable):
                let paintable_box = as_paint_paintable_box(first_paintable)
                if let used_values_for_grid_template_rows = paint_paintable_box_used_values_for_grid_template_rows(paintable_box):
                    return used_values_for_grid_template_rows.css_style_value()

    if not css_data.property_is_shorthand(property_id):
        return css_style_properties_get_computed_value(element, pseudo_element, property_id)

    # Handle shorthands in a generic way
    let longhand_ids = css_data.longhands_for_shorthand(property_id)
    var longhand_values: ak.Vector[CssStyleValue*]
    ak.vector_ensure_capacity(&longhand_values, ak.vector_size(&longhand_ids))
    for longhand_id in ak.vector_span_const(&longhand_ids):
        ak.vector_append_t(&longhand_values, css_style_properties_style_value_for_computed_property(this, layout_node, longhand_id) else trap("release_nonnull: a null style value"))
    return css_shorthand_style_value_create(property_id, longhand_ids, longhand_values).css_style_value()

## The `case PropertyID::Transform:` of style_value_for_computed_property.
func css_style_properties_resolved_transform(layout_node: LayoutNodeWithStyle*, values: const CssComputedValues*) -> CssStyleValue*?:
    let transformations = css_computed_values_transformations(values)
    if ak.vector_is_empty(&transformations):
        return css_keyword_style_value_create(css_data.Keyword.none_).css_style_value()

    # https://drafts.csswg.org/css-transforms-2/#serialization-of-the-computed-value
    # The transform property is a resolved value special case property. [CSSOM]
    # When the computed value is a <transform-list>, the resolved value is one <matrix()> function or one <matrix3d()> function computed by the following algorithm:
    # 1. Let transform be a 4x4 matrix initialized to the identity matrix.
    #    The elements m11, m22, m33 and m44 of transform must be set to 1; all other elements of transform must be set to 0.
    var transform = gfx.float_matrix4_x4_identity()

    # 2. Post-multiply all <transform-function>s in <transform-list> to transform.
    let first_paintable = layout_node_first_paintable(layout_node.layout_node()) else trap("VERIFY: first_paintable()")
    let paintable_box = as_paint_paintable_box(first_paintable)
    for transformation in ak.vector_span_const(&transformations):
        let matrix = css_transformation_style_value_to_matrix(transformation, paintable_box) else trap("release_value: to_matrix failed")
        transform = gfx.float_matrix4_x4_mul(&transform, matrix)

    # 3. Chose between <matrix()> or <matrix3d()> serialization:
    # -> If transform is a 2D matrix
    #        Serialize transform to a <matrix()> function.
    if css_is_2d_matrix(&transform):
        var parameters: ak.Vector[CssStyleValue*]
        ak.vector_append_t(&parameters, css_matrix_number(&transform, 0, 0))
        ak.vector_append_t(&parameters, css_matrix_number(&transform, 1, 0))
        ak.vector_append_t(&parameters, css_matrix_number(&transform, 0, 1))
        ak.vector_append_t(&parameters, css_matrix_number(&transform, 1, 1))
        ak.vector_append_t(&parameters, css_matrix_number(&transform, 0, 3))
        ak.vector_append_t(&parameters, css_matrix_number(&transform, 1, 3))
        return css_transformation_style_value_create(css_data.PropertyId.transform, css_data.TransformFunction.matrix, parameters).css_style_value()
    # -> Otherwise
    #        Serialize transform to a <matrix3d()> function.
    var parameters: ak.Vector[CssStyleValue*]
    for column: usize in 0..<4:
        for row: usize in 0..<4:
            ak.vector_append_t(&parameters, css_matrix_number(&transform, row, column))
    return css_transformation_style_value_create(css_data.PropertyId.transform, css_data.TransformFunction.matrix3_d, parameters).css_style_value()