Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.1

0.6.1 / src / web / css / style_values / edge_style_value.lucb

#==============================================================================================
#
#   edge_style_value - EdgeStyleValue: one axis of a <position>: an edge keyword and an offset
#
#   DESCRIPTION:
#       Port of LibWeb/CSS/StyleValues/EdgeStyleValue.cpp (lines 1-77) and the inline members of
#       EdgeStyleValue.h.
#
#       Copyright (c) 2023, MacDue <macdue@dueutil.tech>
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

## Ported from Libraries/LibWeb/CSS/StyleValues/EdgeStyleValue.h:16 Web::CSS::EdgeStyleValue::create.
pub func css_edge_style_value_create(edge: css_data.PositionEdge?, offset: CssStyleValue*?) -> CssEdgeStyleValue*:
    let this = &(new CssEdgeStyleValue[1] --- else trap("out of memory"))[0]
    css_edge_style_value_construct(this, edge, offset)
    return this

# This is nonnull as it is only called after resolving keywords
## Ported from Libraries/LibWeb/CSS/StyleValues/EdgeStyleValue.h:23 Web::CSS::EdgeStyleValue::offset.
pub func css_edge_style_value_offset(this: CssEdgeStyleValue*) -> CssStyleValue*:
    return this.m_properties.offset else trap("VERIFY: an edge with an offset")

## Ported from Libraries/LibWeb/CSS/StyleValues/EdgeStyleValue.cpp:15 Web::CSS::EdgeStyleValue::is_center.
pub func css_edge_style_value_is_center(this: CssEdgeStyleValue*, mode: css_syntax.SerializationMode) -> bool:
    if this.m_properties.edge == css_data.PositionEdge.center:
        return true

    if let offset = this.m_properties.offset:
        let string = css_style_value_to_string(offset, mode)
        if ak.string_eq_string_view(&string, ak.sv("50%")):
            return true

    return false

## Ported from Libraries/LibWeb/CSS/StyleValues/EdgeStyleValue.cpp:26 Web::CSS::EdgeStyleValue::serialize (override).
pub func css_edge_style_value_serialize_impl(base: CssStyleValue*, builder: ak.StringBuilder*, mode: css_syntax.SerializationMode):
    let this = (CssEdgeStyleValue*)base
    if let edge = this.m_properties.edge:
        ak.string_builder_append_string_view(builder, css_data.to_string_position_edge(edge))

    if this.m_properties.edge != none and this.m_properties.offset != none:
        ak.string_builder_append_u8(builder, ' ')

    if let offset = this.m_properties.offset:
        css_style_value_serialize(offset, builder, mode)

## Ported from Libraries/LibWeb/CSS/StyleValues/EdgeStyleValue.cpp:38 Web::CSS::EdgeStyleValue::with_resolved_keywords.
pub func css_edge_style_value_with_resolved_keywords(this: CssEdgeStyleValue*) -> CssEdgeStyleValue*:
    if this.m_properties.edge == css_data.PositionEdge.center:
        return css_edge_style_value_create(none, css_percentage_style_value_create(css_percentage_new(50.0)).css_style_value())

    let calculation_context = CssCalculationContext(percentages_resolve_as = CssValueType.length)

    if this.m_properties.edge == css_data.PositionEdge.right or this.m_properties.edge == css_data.PositionEdge.bottom:
        let offset = this.m_properties.offset else return css_edge_style_value_create(none, css_percentage_style_value_create(css_percentage_new(100.0)).css_style_value())

        let negated_offset = css_negate_calculation_node_create(css_calculation_node_from_style_value(offset, calculation_context))

        var sum_values = ak.Vector[CssCalculationNode*]()
        ak.vector_append_t(&sum_values, (CssCalculationNode*)css_numeric_calculation_node_create(.css_percentage(css_percentage_new(100.0)), calculation_context))
        ak.vector_append_t(&sum_values, (CssCalculationNode*)negated_offset)
        let flipped_offset = css_simplify_a_calculation_tree((CssCalculationNode*)css_sum_calculation_node_create(sum_values), calculation_context, CssCalculationResolutionContext())

        var resolved_type: CssNumericType = ---
        css_numeric_type_construct(&resolved_type, CssNumericTypeBaseType.length, 1)
        let flipped_percentage_style_value = css_calculated_style_value_create(flipped_offset, resolved_type, calculation_context)

        return css_edge_style_value_create(none, flipped_percentage_style_value.css_style_value())

    let offset = this.m_properties.offset else return css_edge_style_value_create(none, css_percentage_style_value_create(css_percentage_new(0.0)).css_style_value())

    return css_edge_style_value_create(none, offset)

## Ported from Libraries/LibWeb/CSS/StyleValues/EdgeStyleValue.cpp:69 Web::CSS::EdgeStyleValue::absolutized (override).
pub func css_edge_style_value_absolutized_impl(base: CssStyleValue*, computation_context: CssComputationContext) -> CssStyleValue*:
    let this = (CssEdgeStyleValue*)base
    let absolutized_offset = css_style_value_absolutized(css_edge_style_value_offset(css_edge_style_value_with_resolved_keywords(this)), computation_context)
    if this.m_properties.edge == none and css_optional_style_values_equal(this.m_properties.offset, absolutized_offset):
        return base
    return css_edge_style_value_create(none, absolutized_offset).css_style_value()

## Ported from Libraries/LibWeb/CSS/StyleValues/EdgeStyleValue.h:31 Web::CSS::EdgeStyleValue::properties_equal.
pub func css_edge_style_value_properties_equal(this: CssEdgeStyleValue*, other: CssEdgeStyleValue*) -> bool:
    return this.m_properties.edge == other.m_properties.edge and css_optional_style_values_equal(this.m_properties.offset, other.m_properties.offset)

## Ported from Libraries/LibWeb/CSS/StyleValues/StyleValue.h:202 Web::CSS::StyleValueWithDefaultOperators::equals for Web::CSS::EdgeStyleValue (CRTP helper) (override).
pub func css_edge_style_value_equals_impl(base: CssStyleValue*, other: CssStyleValue*) -> bool:
    if css_style_value_type(base) != css_style_value_type(other):
        return false
    return css_edge_style_value_properties_equal((CssEdgeStyleValue*)base, (CssEdgeStyleValue*)other)

## Ported from Libraries/LibWeb/CSS/StyleValues/EdgeStyleValue.h:33 Web::CSS::EdgeStyleValue::is_computationally_independent (override).
pub func css_edge_style_value_is_computationally_independent_impl(base: CssStyleValue*) -> bool:
    let this = (CssEdgeStyleValue*)base
    return css_style_value_is_computationally_independent(this.m_properties.offset else trap("VERIFY: an edge with an offset"))

## Ported from Libraries/LibWeb/CSS/StyleValues/EdgeStyleValue.h:36 Web::CSS::EdgeStyleValue::EdgeStyleValue.
pub func css_edge_style_value_construct(this: CssEdgeStyleValue*, edge: css_data.PositionEdge?, offset: CssStyleValue*?):
    css_style_value_construct(this.css_style_value(), CssStyleValueType.edge)
    css_style_value_set_class(this.css_style_value(), (const CssStyleValueVTable*)&css_edge_style_value_vtable, &css_edge_style_value_class)
    this.m_properties = CssEdgeStyleValueProperties(edge = edge, offset = offset)