Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.0

0.6.0 / src / web / css / computed_properties_1.lucb

#==============================================================================================
#
#   computed_properties_1 - ComputedProperties: the property store and its basic readers
#
#   DESCRIPTION:
#       Port of LibWeb/CSS/ComputedProperties.cpp (lines 1-422) and the inline members of
#       ComputedProperties.h: construction, the per-longhand value array and its important,
#       inherited and animation flags, the animated values, `property()`, and the first typed
#       readers (sizes, gaps, lengths, length boxes, colors, positions, coordinated value lists,
#       color-interpolation, color-scheme, the fallback font, line-height, z-index, opacity).
#
#       Copyright (c) 2018-2025, Andreas Kling <andreas@ladybird.org>
#       Copyright (c) 2021-2025, Sam Atkins <sam@ladybird.org>
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

# mark: Inline members of ComputedProperties.h ==================================================

## The callback of ComputedProperties::for_each_property: the C++ template takes any callable
## `callback(PropertyID, StyleValue const&)`; a Luce caller passes a pointer to a struct that
## conforms (Dump's cascaded-properties lambda is DumpTreeComputedProperty).
pub interface CssComputedPropertiesPropertyCallback:
    func call(property_id: css_data.PropertyId, value: CssStyleValue*)

## Ported from Libraries/LibWeb/CSS/ComputedProperties.h:53 Web::CSS::ComputedProperties::for_each_property.
pub func css_computed_properties_for_each_property[TCallback: CssComputedPropertiesPropertyCallback](this: CssComputedProperties*, callback: TCallback*):
    for i in 0..<css_data.number_of_longhand_properties:
        if let value = this.m_property_values[i]:
            callback.call((css_data.PropertyId)(i + (usize)css_data.first_longhand_property_id), value)

## Ported from Libraries/LibWeb/CSS/ComputedProperties.h:68 Web::CSS::ComputedProperties::animated_property_values.
pub func css_computed_properties_animated_property_values(this: CssComputedProperties*) -> ak.HashMap[css_data.PropertyId, CssStyleValue*, css_data.PropertyIdTraits]:
    return this.m_animated_property_values

## Ported from Libraries/LibWeb/CSS/ComputedProperties.h:250 Web::CSS::ComputedProperties::cached_computed_font_list.
pub func css_computed_properties_cached_computed_font_list(this: CssComputedProperties*) -> const web_fonts.FontCascadeList*?:
    return this.m_cached_computed_font_list

## Ported from Libraries/LibWeb/CSS/ComputedProperties.h:277 Web::CSS::ComputedProperties::has_attempted_match_against_pseudo_class.
pub func css_computed_properties_has_attempted_match_against_pseudo_class(this: CssComputedProperties*, pseudo_class: css_data.PseudoClass) -> bool:
    return css_pseudo_class_bitmap_get(&this.m_attempted_pseudo_class_matches, pseudo_class)

## Ported from Libraries/LibWeb/CSS/ComputedProperties.h:282 Web::CSS::ComputedProperties::set_attempted_pseudo_class_matches.
pub func css_computed_properties_set_attempted_pseudo_class_matches(this: CssComputedProperties*, results: CssPseudoClassBitmap):
    this.m_attempted_pseudo_class_matches = results

## Ported from Libraries/LibWeb/CSS/ComputedProperties.h:308 Web::CSS::ComputedProperties::clear_computed_font_list_cache.
pub func css_computed_properties_clear_computed_font_list_cache(this: CssComputedProperties*):
    this.m_cached_computed_font_list = none
    this.m_cached_first_available_computed_font = none

# mark: Construction and the property store =====================================================

## The index of `property_id` in the per-longhand arrays (C++ `to_underlying(id) -
## to_underlying(first_longhand_property_id)`), after the VERIFY that it is a longhand.
func css_computed_properties_longhand_index(property_id: css_data.PropertyId) -> usize:
    assert((usize)property_id >= (usize)css_data.first_longhand_property_id and (usize)property_id <= (usize)css_data.last_longhand_property_id)
    return (usize)property_id - (usize)css_data.first_longhand_property_id

## Bit `n` of a per-longhand flag array (`flags[n // 8] & (1 << (n % 8))`).
func css_computed_properties_flag(flags: const u8[], n: usize) -> bool:
    return (flags[n // 8] & ((u8)1 << (u8)(n % 8))) != 0

## Sets or clears bit `n` of a per-longhand flag array (`flags[n // 8] |= ...` / `&= ~...`).
func css_computed_properties_set_flag(flags: u8[], n: usize, value: bool):
    if value:
        flags[n // 8] |= (u8)1 << (u8)(n % 8)
    else:
        flags[n // 8] &= ~((u8)1 << (u8)(n % 8))

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:62 Web::CSS::ComputedProperties::ComputedProperties.
pub func css_computed_properties_construct(this: CssComputedProperties*):
    css_computed_properties_init_fields(this)

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:66 Web::CSS::ComputedProperties::visit_edges (override).
pub func css_computed_properties_visit_edges_impl(base: gc.Cell*, visitor: gc.CellVisitor*):
    gc.cell_visit_edges_impl(base, visitor)

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:71 Web::CSS::ComputedProperties::is_property_important.
pub func css_computed_properties_is_property_important(this: CssComputedProperties*, property_id: css_data.PropertyId) -> bool:
    let n = css_computed_properties_longhand_index(property_id)
    return css_computed_properties_flag(this.m_property_important, n)

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:79 Web::CSS::ComputedProperties::set_property_important.
pub func css_computed_properties_set_property_important(this: CssComputedProperties*, property_id: css_data.PropertyId, important: css_syntax.Important):
    let n = css_computed_properties_longhand_index(property_id)
    css_computed_properties_set_flag(this.m_property_important, n, important == css_syntax.Important.yes)

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:90 Web::CSS::ComputedProperties::is_property_inherited.
pub func css_computed_properties_is_property_inherited(this: CssComputedProperties*, property_id: css_data.PropertyId) -> bool:
    let n = css_computed_properties_longhand_index(property_id)
    return css_computed_properties_flag(this.m_property_inherited, n)

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:98 Web::CSS::ComputedProperties::is_animated_property_inherited.
pub func css_computed_properties_is_animated_property_inherited(this: CssComputedProperties*, property_id: css_data.PropertyId) -> bool:
    let n = css_computed_properties_longhand_index(property_id)
    return css_computed_properties_flag(this.m_animated_property_inherited, n)

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:106 Web::CSS::ComputedProperties::is_animated_property_result_of_transition.
pub func css_computed_properties_is_animated_property_result_of_transition(this: CssComputedProperties*, property_id: css_data.PropertyId) -> bool:
    let n = css_computed_properties_longhand_index(property_id)
    return css_computed_properties_flag(this.m_animated_property_result_of_transition, n)

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:114 Web::CSS::ComputedProperties::set_property_inherited.
pub func css_computed_properties_set_property_inherited(this: CssComputedProperties*, property_id: css_data.PropertyId, inherited: CssComputedPropertiesInherited):
    let n = css_computed_properties_longhand_index(property_id)
    css_computed_properties_set_flag(this.m_property_inherited, n, inherited == CssComputedPropertiesInherited.yes)

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:125 Web::CSS::ComputedProperties::set_animated_property_inherited.
pub func css_computed_properties_set_animated_property_inherited(this: CssComputedProperties*, property_id: css_data.PropertyId, inherited: CssComputedPropertiesInherited):
    let n = css_computed_properties_longhand_index(property_id)
    css_computed_properties_set_flag(this.m_animated_property_inherited, n, inherited == CssComputedPropertiesInherited.yes)

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:136 Web::CSS::ComputedProperties::set_animated_property_result_of_transition.
pub func css_computed_properties_set_animated_property_result_of_transition(this: CssComputedProperties*, property_id: css_data.PropertyId, animated_value_result_of_transition: CssAnimatedPropertyResultOfTransition):
    let n = css_computed_properties_longhand_index(property_id)
    css_computed_properties_set_flag(this.m_animated_property_result_of_transition, n, animated_value_result_of_transition == CssAnimatedPropertyResultOfTransition.yes)

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:147 Web::CSS::ComputedProperties::set_property.
pub func css_computed_properties_set_property(this: CssComputedProperties*, id: css_data.PropertyId, value: CssStyleValue*, inherited: CssComputedPropertiesInherited = CssComputedPropertiesInherited.no, important: css_syntax.Important = css_syntax.Important.no):
    assert((usize)id >= (usize)css_data.first_longhand_property_id and (usize)id <= (usize)css_data.last_longhand_property_id)

    css_computed_properties_set_property_without_modifying_flags(this, id, value)
    css_computed_properties_set_property_important(this, id, important)
    css_computed_properties_set_property_inherited(this, id, inherited)

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:156 Web::CSS::property_affects_computed_font_list.
func css_property_affects_computed_font_list(id: css_data.PropertyId) -> bool:
    match id:
        .font_family, .font_size, .font_style, .font_weight, .font_width, .font_variation_settings:
            return true
        _:
            return false

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:161 Web::CSS::ComputedProperties::set_property_without_modifying_flags.
pub func css_computed_properties_set_property_without_modifying_flags(this: CssComputedProperties*, id: css_data.PropertyId, value: CssStyleValue*):
    this.m_property_values[css_computed_properties_longhand_index(id)] = value

    if css_property_affects_computed_font_list(id):
        css_computed_properties_clear_computed_font_list_cache(this)

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:171 Web::CSS::ComputedProperties::revert_property.
pub func css_computed_properties_revert_property(this: CssComputedProperties*, id: css_data.PropertyId, style_for_revert: CssComputedProperties*):
    let n = css_computed_properties_longhand_index(id)

    this.m_property_values[n] = style_for_revert.m_property_values[n]
    css_computed_properties_set_property_important(this, id, css_syntax.Important.yes if css_computed_properties_is_property_important(style_for_revert, id) else css_syntax.Important.no)
    css_computed_properties_set_property_inherited(this, id, CssComputedPropertiesInherited.yes if css_computed_properties_is_property_inherited(style_for_revert, id) else CssComputedPropertiesInherited.no)

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:180 Web::CSS::ComputedProperties::display_before_box_type_transformation.
pub func css_computed_properties_display_before_box_type_transformation(this: CssComputedProperties*) -> CssDisplay:
    return this.m_display_before_box_type_transformation

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:185 Web::CSS::ComputedProperties::set_display_before_box_type_transformation.
pub func css_computed_properties_set_display_before_box_type_transformation(this: CssComputedProperties*, value: CssDisplay):
    this.m_display_before_box_type_transformation = value

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:190 Web::CSS::ComputedProperties::set_animated_property.
pub func css_computed_properties_set_animated_property(this: CssComputedProperties*, id: css_data.PropertyId, value: CssStyleValue*, animated_property_result_of_transition: CssAnimatedPropertyResultOfTransition, inherited: CssComputedPropertiesInherited = CssComputedPropertiesInherited.no):
    _ = ak.hash_map_set(&this.m_animated_property_values, id, value)
    css_computed_properties_set_animated_property_inherited(this, id, inherited)
    css_computed_properties_set_animated_property_result_of_transition(this, id, animated_property_result_of_transition)

    if css_property_affects_computed_font_list(id):
        css_computed_properties_clear_computed_font_list_cache(this)

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:200 Web::CSS::ComputedProperties::remove_animated_property.
pub func css_computed_properties_remove_animated_property(this: CssComputedProperties*, id: css_data.PropertyId):
    _ = ak.hash_map_remove_k(&this.m_animated_property_values, id)

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:205 Web::CSS::ComputedProperties::reset_non_inherited_animated_properties.
pub func css_computed_properties_reset_non_inherited_animated_properties(this: CssComputedProperties*):
    let keys = ak.hash_map_keys(&this.m_animated_property_values)
    for property_id in ak.vector_span_const(&keys):
        if not css_computed_properties_is_animated_property_inherited(this, property_id):
            _ = ak.hash_map_remove_k(&this.m_animated_property_values, property_id)

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:213 Web::CSS::ComputedProperties::property.
pub func css_computed_properties_property(this: CssComputedProperties*, property_id: css_data.PropertyId, return_animated_value: CssComputedPropertiesWithAnimationsApplied = CssComputedPropertiesWithAnimationsApplied.yes) -> CssStyleValue*:
    let n = css_computed_properties_longhand_index(property_id)

    # Important properties override animated but not transitioned properties
    if (not css_computed_properties_is_property_important(this, property_id) or css_computed_properties_is_animated_property_result_of_transition(this, property_id)) and return_animated_value == CssComputedPropertiesWithAnimationsApplied.yes:
        if let animated_value = ak.hash_map_get_k(&this.m_animated_property_values, property_id):
            return *animated_value

    # By the time we call this method, the property should have been assigned
    return this.m_property_values[n] else trap("VERIFY: ComputedProperties::property() of an unassigned property")

# mark: Typed readers ===========================================================================

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:227 Web::CSS::ComputedProperties::gap_value.
pub func css_computed_properties_gap_value(this: CssComputedProperties*, id: css_data.PropertyId) -> CssLengthPercentageOrCssNormalGap:
    let value = css_computed_properties_property(this, id)
    if css_style_value_is_keyword(value):
        assert(css_keyword_style_value_keyword(css_style_value_as_keyword(value)) == css_data.Keyword.normal)
        return CssLengthPercentageOrCssNormalGap.css_normal_gap(CssNormalGap())

    return CssLengthPercentageOrCssNormalGap.css_length_percentage(css_length_percentage_from_style_value(value))

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:238 Web::CSS::ComputedProperties::size_value.
pub func css_computed_properties_size_value(this: CssComputedProperties*, id: css_data.PropertyId) -> CssSize:
    return css_size_from_style_value(css_computed_properties_property(this, id))

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:243 Web::CSS::ComputedProperties::length.
pub func css_computed_properties_length(this: CssComputedProperties*, property_id: css_data.PropertyId) -> CssLength:
    return css_length_style_value_length(css_style_value_as_length(css_computed_properties_property(this, property_id)))

## The `length_box_side` lambda of ComputedProperties::length_box.
func css_computed_properties_length_box_side(this: CssComputedProperties*, id: css_data.PropertyId, default_value: CssLengthPercentageOrAuto) -> CssLengthPercentageOrAuto:
    let value = css_computed_properties_property(this, id)

    if css_style_value_is_calculated(value) or css_style_value_is_percentage(value) or css_style_value_is_length(value) or css_style_value_has_auto(value):
        return css_length_percentage_or_auto_from_style_value(value)

    # FIXME: Handle anchor sizes
    return default_value

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:248 Web::CSS::ComputedProperties::length_box.
pub func css_computed_properties_length_box(this: CssComputedProperties*, left_id: css_data.PropertyId, top_id: css_data.PropertyId, right_id: css_data.PropertyId, bottom_id: css_data.PropertyId, default_value: CssLengthPercentageOrAuto) -> CssLengthBox:
    let top = css_computed_properties_length_box_side(this, top_id, default_value)
    let right = css_computed_properties_length_box_side(this, right_id, default_value)
    let bottom = css_computed_properties_length_box_side(this, bottom_id, default_value)
    let left = css_computed_properties_length_box_side(this, left_id, default_value)
    var box: CssLengthBox = ---
    css_length_box_construct_css_length_percentage_or_auto(&box, top, right, bottom, left)
    return box

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:268 Web::CSS::ComputedProperties::for_each_anchor_name.
pub func css_computed_properties_for_each_anchor_name(this: CssComputedProperties*, callback: ak.Function1[const ak.FlyString*, unit]):
    let value = css_computed_properties_property(this, css_data.PropertyId.anchor_name)
    if css_style_value_is_custom_ident(value):
        let custom_ident = css_custom_ident_style_value_custom_ident(css_style_value_as_custom_ident(value))
        ak.function1_call(&callback, &custom_ident)
    elif css_style_value_is_value_list(value):
        let values = css_style_value_list_values(css_style_value_as_value_list(value))
        for item in ak.vector_span_const(&values):
            if css_style_value_is_custom_ident(item):
                let custom_ident = css_custom_ident_style_value_custom_ident(css_style_value_as_custom_ident(item))
                ak.function1_call(&callback, &custom_ident)

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:281 Web::CSS::ComputedProperties::color.
pub func css_computed_properties_color(this: CssComputedProperties*, id: css_data.PropertyId, color_resolution_context: CssColorResolutionContext) -> gfx.Color:
    return css_style_value_to_color(css_computed_properties_property(this, id), color_resolution_context) else trap("VERIFY: Optional::value() of to_color()")

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:286 Web::CSS::ComputedProperties::position_value.
pub func css_computed_properties_position_value(this: CssComputedProperties*, id: css_data.PropertyId) -> CssPosition:
    let position = css_style_value_as_position(css_computed_properties_property(this, id))
    let edge_x = css_style_value_as_edge(css_position_style_value_edge_x(position).css_style_value())
    let edge_y = css_style_value_as_edge(css_position_style_value_edge_y(position).css_style_value())

    # `{ .offset_x = ..., .offset_y = ... }`: the edges keep their defaults (left, top).
    var result = css_position_new()
    result.offset_x = css_length_percentage_from_style_value(css_edge_style_value_offset(edge_x))
    result.offset_y = css_length_percentage_from_style_value(css_edge_style_value_offset(edge_y))
    return result

## The predicate of `first_matching` in ComputedProperties::color_scheme: a scheme the user agent supports.
func css_computed_properties_is_supported_color_scheme(context: void*?, scheme: const ak.String*) -> bool:
    return css_preferred_color_scheme_from_string(ak.string_bytes_as_string_view(scheme)) != CssPreferredColorScheme.auto

## `Vector<String>::contains_slow(StringView)`, as ComputedProperties::color_scheme uses it.
func css_computed_properties_schemes_contain(schemes: const ak.Vector[ak.String]*, scheme: ak.StringView) -> bool:
    for item in ak.vector_span_const(schemes):
        if ak.string_eq_string_view(&item, scheme):
            return true
    return false

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:299 Web::CSS::ComputedProperties::assemble_coordinated_value_list.
# https://drafts.csswg.org/css-values-4/#linked-properties
pub func css_computed_properties_assemble_coordinated_value_list(this: CssComputedProperties*, base_property_id: css_data.PropertyId, property_ids: ak.Vector[css_data.PropertyId]) -> ak.HashMap[css_data.PropertyId, ak.Vector[CssStyleValue*], css_data.PropertyIdTraits]:
    # A coordinating list property group creates a coordinated value list, which has, for each entry, a value from each
    # property in the group; these are used together to define a single effect, such as a background image layer or an
    # animation. The coordinated value list is assembled as follows:
    # - The length of the coordinated value list is determined by the number of items specified in one particular
    #   coordinating list property, the coordinating list base property. (In the case of backgrounds, this is the
    #   background-image property.)
    # - The Nth value of the coordinated value list is constructed by collecting the Nth use value of each coordinating
    #   list property
    # - If a coordinating list property has too many values specified, excess values at the end of its list are not
    #   used.
    # - If a coordinating list property has too few values specified, its value list is repeated to add more used
    #   values.
    # - The computed values of the coordinating list properties are not affected by such truncation or repetition.
    var coordinated_value_list: ak.HashMap[css_data.PropertyId, ak.Vector[CssStyleValue*], css_data.PropertyIdTraits]

    let base_size = css_style_value_list_size(css_style_value_as_value_list(css_computed_properties_property(this, base_property_id)))
    for i in 0..<base_size:
        for property_id in ak.vector_span_const(&property_ids):
            let list = css_style_value_list_values(css_style_value_as_value_list(css_computed_properties_property(this, property_id)))

            ak.vector_append_t(ak.hash_map_ensure(&coordinated_value_list, property_id), *ak.vector_at_const(&list, i % ak.vector_size(&list)))

    return coordinated_value_list

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:327 Web::CSS::ComputedProperties::color_interpolation.
pub func css_computed_properties_color_interpolation(this: CssComputedProperties*) -> css_data.ColorInterpolation:
    let value = css_computed_properties_property(this, css_data.PropertyId.color_interpolation)
    return css_data.keyword_to_color_interpolation(css_style_value_to_keyword(value)) else css_data.ColorInterpolation.auto

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:334 Web::CSS::ComputedProperties::color_scheme.
# https://drafts.csswg.org/css-color-adjust-1/#determine-the-used-color-scheme
pub func css_computed_properties_color_scheme(this: CssComputedProperties*, preferred_scheme: CssPreferredColorScheme, document_supported_schemes: const ak.Vector[ak.String]*?) -> CssPreferredColorScheme:
    # To determine the used color scheme of an element:
    let scheme_value = css_style_value_as_color_scheme(css_computed_properties_property(this, css_data.PropertyId.color_scheme))
    let schemes = css_color_scheme_style_value_schemes(scheme_value)

    # 1. If the user’s preferred color scheme, as indicated by the prefers-color-scheme media feature,
    #    is present among the listed color schemes, and is supported by the user agent,
    #    that’s the element’s used color scheme.
    if preferred_scheme != CssPreferredColorScheme.auto and css_computed_properties_schemes_contain(&schemes, css_preferred_color_scheme_to_string(preferred_scheme)):
        return preferred_scheme

    # 2. Otherwise, if the user has indicated an overriding preference for their chosen color scheme,
    #    and the only keyword is not present in color-scheme for the element,
    #    the user agent must override the color scheme with the user’s preferred color scheme.
    #    See § 2.3 Overriding the Color Scheme.
    # FIXME: We don't currently support setting an "overriding preference" for color schemes.

    # 3. Otherwise, if the user agent supports at least one of the listed color schemes,
    #    the used color scheme is the first supported color scheme in the list.
    let is_supported = ak.Function1[const ak.String*, bool](call = css_computed_properties_is_supported_color_scheme, context = none)
    if let first_supported = ak.vector_first_matching_const(&schemes, is_supported):
        return css_preferred_color_scheme_from_string(ak.string_bytes_as_string_view(first_supported))

    # 4. Otherwise, the used color scheme is the browser default. (Same as normal.)
    # `normal` indicates that the element supports the page’s supported color schemes, if they are set
    if let document_schemes = document_supported_schemes:
        if preferred_scheme != CssPreferredColorScheme.auto and css_computed_properties_schemes_contain(document_schemes, css_preferred_color_scheme_to_string(preferred_scheme)):
            return preferred_scheme

        if let document_first_supported = ak.vector_first_matching_const(document_schemes, is_supported):
            return css_preferred_color_scheme_from_string(ak.string_bytes_as_string_view(document_first_supported))

    return CssPreferredColorScheme.light

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:371 Web::CSS::ComputedProperties::font_fallback.
pub func css_computed_properties_font_fallback(monospace: bool, bold: bool, point_size: f32) -> const web_fonts.Font*:
    if monospace and bold:
        return web_fonts.font_bold_variant(platform_font_plugin_default_fixed_width_font(platform_font_plugin_the()))

    if monospace:
        return platform_font_plugin_default_fixed_width_font(platform_font_plugin_the())

    if bold:
        return web_fonts.font_bold_variant(platform_font_plugin_default_font(platform_font_plugin_the(), point_size) else trap("VERIFY: RefPtr::operator->() on a null default font"))

    return platform_font_plugin_default_font(platform_font_plugin_the(), point_size) else trap("VERIFY: RefPtr::operator*() on a null default font")

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:385 Web::CSS::ComputedProperties::line_height.
pub func css_computed_properties_line_height(this: CssComputedProperties*) -> gfx.CssPixels:
    # https://drafts.csswg.org/css-inline-3/#line-height-property
    let line_height = css_computed_properties_property(this, css_data.PropertyId.line_height)

    # normal
    # Determine the preferred line height automatically based on font metrics.
    if css_style_value_is_keyword(line_height) and css_style_value_to_keyword(line_height) == css_data.Keyword.normal:
        return gfx.css_pixels_from_int((i64)ak.rounding_round_to_f64_i32(gfx.mul_css_pixels_f64(css_computed_properties_font_size(this), css_computed_properties_normal_line_height_scale)))

    # <length [0,∞]>
    # The specified length is used as the preferred line height. Negative values are illegal.
    if css_style_value_is_length(line_height):
        let length = css_length_style_value_length(css_style_value_as_length(line_height))
        return css_length_absolute_length_to_px(&length)

    # <number [0,∞]>
    # The preferred line height is this number multiplied by the element’s computed font-size.
    if css_style_value_is_number(line_height):
        return gfx.css_pixels_from_f64(gfx.mul_css_pixels_f64(css_computed_properties_font_size(this), css_number_style_value_number(css_style_value_as_number(line_height))))

    trap("VERIFY_NOT_REACHED")

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:408 Web::CSS::ComputedProperties::z_index.
pub func css_computed_properties_z_index(this: CssComputedProperties*) -> i32?:
    let value = css_computed_properties_property(this, css_data.PropertyId.z_index)
    if css_style_value_has_auto(value):
        return none

    return css_int_from_style_value(value)

## Ported from Libraries/LibWeb/CSS/ComputedProperties.cpp:417 Web::CSS::ComputedProperties::opacity.
pub func css_computed_properties_opacity(this: CssComputedProperties*) -> f32:
    return (f32)css_opacity_value_style_value_resolved(css_style_value_as_opacity_value(css_computed_properties_property(this, css_data.PropertyId.opacity)))