dymokomi/luce-browser-engine
Source of release 0.6.1
0.6.1 / src / web / css / style_values / calculated_style_value_3.lucb
#==============================================================================================
#
# calculated_style_value_3 - CalculatedStyleValue: numeric leaves and the calc-operator nodes
#
# DESCRIPTION:
# Port of LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp (lines 645-1123) and the inline
# members of CalculatedStyleValue.h they belong with: the type of a numeric value,
# NumericCalculationNode (with try_get_value_with_canonical_unit and try_get_number, which
# sit between its members in the donor), and the Sum, Product, Negate and Invert nodes.
#
# Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
# Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
# Copyright (c) 2021-2025, Sam Atkins <sam@ladybird.org>
# Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech>
# SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================
# mark: The type of a numeric value =============================================================
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:635 Web::CSS::numeric_type_from_calculated_style_value.
func css_numeric_type_from_calculated_style_value(value: CssCalculationNodeNumericValue, context: CssCalculationContext) -> CssNumericType:
# https://drafts.csswg.org/css-values-4/#determine-the-type-of-a-calculation
# Anything else is a terminal value, whose type is determined based on its CSS type.
# (Unless otherwise specified, the type’s associated percent hint is null.)
match value:
.number(_):
# -> <number>
# -> <integer>
# the type is «[ ]» (empty map)
return CssNumericType()
.css_length(_):
# -> <length>
# the type is «[ "length" → 1 ]»
return css_numeric_type_new(.length, 1)
.css_angle(_):
# -> <angle>
# the type is «[ "angle" → 1 ]»
return css_numeric_type_new(.angle, 1)
.css_time(_):
# -> <time>
# the type is «[ "time" → 1 ]»
return css_numeric_type_new(.time, 1)
.css_frequency(_):
# -> <frequency>
# the type is «[ "frequency" → 1 ]»
return css_numeric_type_new(.frequency, 1)
.css_resolution(_):
# -> <resolution>
# the type is «[ "resolution" → 1 ]»
return css_numeric_type_new(.resolution, 1)
.css_flex(_):
# -> <flex>
# the type is «[ "flex" → 1 ]»
return css_numeric_type_new(.flex, 1)
# NOTE: <calc-constant> is a separate node type. (FIXME: Should it be?)
.css_percentage(_):
# -> <percentage>
# If, in the context in which the math function containing this calculation is placed,
# <percentage>s are resolved relative to another type of value (such as in width,
# where <percentage> is resolved against a <length>), and that other type is not <number>,
# the type is determined as the other type, but with a percent hint set to that other type.
if let resolve_as = context.percentages_resolve_as:
if resolve_as != CssValueType.number and resolve_as != CssValueType.percentage:
let base_type = css_numeric_type_base_type_from_value_type(resolve_as) else trap("VERIFY: base_type.has_value()")
var result = css_numeric_type_new(base_type, 1)
css_numeric_type_set_percent_hint(&result, base_type)
return result
# Otherwise, the type is «[ "percent" → 1 ]», with a percent hint of "percent".
let result = css_numeric_type_new(.percent, 1)
# FIXME: Setting the percent hint to "percent" causes us to fail tests.
# result.set_percent_hint(NumericType::BaseType::Percent);
return result
# mark: NumericCalculationNode ==================================================================
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:700 Web::CSS::NumericCalculationNode::create.
pub func css_numeric_calculation_node_create(value: CssCalculationNodeNumericValue, context: CssCalculationContext) -> CssNumericCalculationNode*:
let numeric_type = css_numeric_type_from_calculated_style_value(value, context)
let this = &(new CssNumericCalculationNode[1] --- else trap("out of memory"))[0]
css_numeric_calculation_node_construct(this, value, numeric_type)
return this
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:706 Web::CSS::NumericCalculationNode::from_keyword.
pub func css_numeric_calculation_node_from_keyword(keyword: css_data.Keyword, context: CssCalculationContext) -> CssNumericCalculationNode*?:
match keyword:
.e:
# https://drafts.csswg.org/css-values-4/#valdef-calc-e
return css_numeric_calculation_node_create(CssCalculationNodeNumericValue.number(css_syntax.number_create(css_syntax.NumberType.number, ak.e_f64)), context)
.pi:
# https://drafts.csswg.org/css-values-4/#valdef-calc-pi
return css_numeric_calculation_node_create(CssCalculationNodeNumericValue.number(css_syntax.number_create(css_syntax.NumberType.number, ak.pi_f64)), context)
.infinity:
# https://drafts.csswg.org/css-values-4/#valdef-calc-infinity
return css_numeric_calculation_node_create(CssCalculationNodeNumericValue.number(css_syntax.number_create(css_syntax.NumberType.number, math.infinity)), context)
.negative_infinity:
# https://drafts.csswg.org/css-values-4/#valdef-calc--infinity
return css_numeric_calculation_node_create(CssCalculationNodeNumericValue.number(css_syntax.number_create(css_syntax.NumberType.number, -math.infinity)), context)
.nan:
# https://drafts.csswg.org/css-values-4/#valdef-calc-nan
return css_numeric_calculation_node_create(CssCalculationNodeNumericValue.number(css_syntax.number_create(css_syntax.NumberType.number, math.nan)), context)
_:
return none
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:729 Web::CSS::NumericCalculationNode::NumericCalculationNode.
pub func css_numeric_calculation_node_construct(this: CssNumericCalculationNode*, value: CssCalculationNodeNumericValue, numeric_type: CssNumericType):
css_calculation_node_construct(this.css_calculation_node(), .numeric, numeric_type)
css_calculation_node_set_class(this.css_calculation_node(), (const CssCalculationNodeVTable*)&css_numeric_calculation_node_vtable, &css_numeric_calculation_node_class)
this.m_value = value
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:737 Web::CSS::NumericCalculationNode::serialize_value.
pub func css_numeric_calculation_node_serialize_value(this: CssNumericCalculationNode*, builder: ak.StringBuilder*):
css_numeric_value_serialize(&this.m_value, builder)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:742 Web::CSS::NumericCalculationNode::value_to_string.
pub func css_numeric_calculation_node_value_to_string(this: CssNumericCalculationNode*) -> ak.String:
var builder = ak.StringBuilder()
ak.string_builder_construct(&builder)
css_numeric_calculation_node_serialize_value(this, &builder)
return ak.string_builder_to_string_without_validation(&builder)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:749 Web::CSS::NumericCalculationNode::contains_percentage (override).
pub func css_numeric_calculation_node_contains_percentage_impl(base: CssCalculationNode*) -> bool:
let this = (CssNumericCalculationNode*)base
return css_numeric_value_is_percentage(&this.m_value)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:754 Web::CSS::NumericCalculationNode::is_in_canonical_unit.
pub func css_numeric_calculation_node_is_in_canonical_unit(this: CssNumericCalculationNode*) -> bool:
match this.m_value:
.css_angle(angle): return css_angle_unit(&angle) == css_data.AngleUnit.deg
.css_flex(flex): return css_flex_unit(&flex) == css_data.FlexUnit.fr
.css_frequency(frequency): return css_frequency_unit(&frequency) == css_data.FrequencyUnit.hz
.css_length(length): return css_length_unit(&length) == css_data.LengthUnit.px
.number(_): return true
.css_percentage(_): return true
.css_resolution(resolution): return css_resolution_unit(&resolution) == css_data.ResolutionUnit.dppx
.css_time(time): return css_time_unit(&time) == css_data.TimeUnit.s
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:767 Web::CSS::try_get_value_with_canonical_unit.
func css_try_get_value_with_canonical_unit(child: CssCalculationNode*, context: CssCalculationContext, resolution_context: CssCalculationResolutionContext) -> CssCalculatedStyleValueCalculationResult?:
if css_calculation_node_type(child) != CssCalculationNodeType.numeric:
return none
let numeric_child = as_css_numeric_calculation_node(child)
# Can't run with non-canonical units or unresolved percentages.
# We've already attempted to resolve both in with_simplified_children().
if (not css_numeric_calculation_node_is_in_canonical_unit(numeric_child) or (css_numeric_value_is_percentage(&numeric_child.m_value) and context.percentages_resolve_as != none)):
return none
# Can't run if a child has an invalid type.
if css_calculation_node_numeric_type(child) == none:
return none
return css_calculated_style_value_calculation_result_from_value(numeric_child.m_value, resolution_context, css_calculation_node_numeric_type(child))
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:786 Web::CSS::try_get_number.
func css_try_get_number(child: CssCalculationNode*) -> f64?:
if css_calculation_node_type(child) != CssCalculationNodeType.numeric:
return none
let maybe_number = css_numeric_value_number(&as_css_numeric_calculation_node(child).m_value) else return none
return css_syntax.number_value(&maybe_number)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:796 Web::CSS::NumericCalculationNode::infinite_or_nan_value.
pub func css_numeric_calculation_node_infinite_or_nan_value(this: CssNumericCalculationNode*) -> CssNonFiniteValue?:
var raw_value = 0.0
match this.m_value:
.number(number): raw_value = css_syntax.number_value(&number)
.css_percentage(percentage): raw_value = css_percentage_as_fraction(&percentage)
_: raw_value = css_numeric_value_dimension_raw_value(&this.m_value)
if math.is_nan(raw_value):
return CssNonFiniteValue.na_n
if not math.is_finite(raw_value):
if raw_value < 0.0:
return CssNonFiniteValue.negative_infinity
return CssNonFiniteValue.infinity
return none
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:814 Web::CSS::NumericCalculationNode::is_negative.
pub func css_numeric_calculation_node_is_negative(this: CssNumericCalculationNode*) -> bool:
match this.m_value:
.number(number): return css_syntax.number_value(&number) < 0.0
.css_percentage(percentage): return css_percentage_value(&percentage) < 0.0
_: return css_numeric_value_dimension_raw_value(&this.m_value) < 0.0
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:822 Web::CSS::NumericCalculationNode::negated.
pub func css_numeric_calculation_node_negated(this: CssNumericCalculationNode*, context: CssCalculationContext) -> CssNumericCalculationNode*:
match this.m_value:
.css_percentage(percentage):
return css_numeric_calculation_node_create(CssCalculationNodeNumericValue.css_percentage(css_percentage_new(-css_percentage_value(&percentage))), context)
.number(number):
return css_numeric_calculation_node_create(CssCalculationNodeNumericValue.number(css_syntax.number_create(css_syntax.number_type(&number), -css_syntax.number_value(&number))), context)
_:
return css_numeric_calculation_node_create(css_numeric_value_dimension_with_raw_value(&this.m_value, -css_numeric_value_dimension_raw_value(&this.m_value)), context)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:836 Web::CSS::NumericCalculationNode::dump (override).
pub func css_numeric_calculation_node_dump_impl(base: CssCalculationNode*, builder: ak.StringBuilder*, indent: i32):
let this = (CssNumericCalculationNode*)base
let value_string = css_numeric_value_to_string(&this.m_value)
css_appendff(builder, "{: >{}}NUMERIC({})\n", [ak.arg_str(""), ak.arg_i64((i64)indent), css_arg_string(&value_string)])
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:841 Web::CSS::NumericCalculationNode::equals (override).
pub func css_numeric_calculation_node_equals_impl(base: CssCalculationNode*, other: CssCalculationNode*) -> bool:
let this = (CssNumericCalculationNode*)base
if base == other:
return true
if css_calculation_node_type(base) != css_calculation_node_type(other):
return false
return css_numeric_values_equal(&this.m_value, &((CssNumericCalculationNode*)other).m_value)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:850 Web::CSS::NumericCalculationNode::is_computationally_independent (override).
pub func css_numeric_calculation_node_is_computationally_independent_impl(base: CssCalculationNode*) -> bool:
let this = (CssNumericCalculationNode*)base
match this.m_value:
.css_length(length): return css_length_is_computationally_independent(&length)
_: return true
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:857 Web::CSS::NumericCalculationNode::reify (override).
pub func css_numeric_calculation_node_reify_impl(base: CssCalculationNode*, realm: Realm*) -> CssNumericValue*?:
let this = (CssNumericCalculationNode*)base
match this.m_value:
.number(number):
return (CssNumericValue*)css_unit_value_create(realm, css_syntax.number_value(&number), ak.fly_string_from_str("number"))
.css_percentage(percentage):
return (CssNumericValue*)css_unit_value_create(realm, css_percentage_value(&percentage), ak.fly_string_from_str("percent"))
_:
return (CssNumericValue*)css_unit_value_create(realm, css_numeric_value_dimension_raw_value(&this.m_value), css_numeric_value_dimension_unit_name(&this.m_value))
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.h:276 Web::CSS::NumericCalculationNode::with_simplified_children (override).
pub func css_numeric_calculation_node_with_simplified_children_impl(base: CssCalculationNode*, arg0: CssCalculationContext, arg1: CssCalculationResolutionContext) -> CssCalculationNode*:
_ = arg0
_ = arg1
return base
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.h:278 Web::CSS::NumericCalculationNode::children (override).
pub func css_numeric_calculation_node_children_impl(base: CssCalculationNode*) -> ak.Vector[CssCalculationNode*]:
_ = base
return ak.Vector[CssCalculationNode*]()
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.h:279 Web::CSS::NumericCalculationNode::value.
pub func css_numeric_calculation_node_value(this: CssNumericCalculationNode*) -> CssCalculationNodeNumericValue:
return this.m_value
# mark: SumCalculationNode ======================================================================
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:865 Web::CSS::SumCalculationNode::create.
pub func css_sum_calculation_node_create(values: ak.Vector[CssCalculationNode*]) -> CssSumCalculationNode*:
# https://www.w3.org/TR/css-values-4/#determine-the-type-of-a-calculation
# At a + or - sub-expression, attempt to add the types of the left and right arguments.
# If this returns failure, the entire calculation’s type is failure.
# Otherwise, the sub-expression’s type is the returned type.
let numeric_type = css_add_the_types_vector(&values)
let this = &(new CssSumCalculationNode[1] --- else trap("out of memory"))[0]
css_sum_calculation_node_construct(this, values, numeric_type)
return this
## css_sum_calculation_node_create as a CssCreateFromChildren.
func css_sum_calculation_node_create_node(values: ak.Vector[CssCalculationNode*]) -> CssCalculationNode*:
return css_sum_calculation_node_create(values).css_calculation_node()
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:875 Web::CSS::SumCalculationNode::SumCalculationNode.
pub func css_sum_calculation_node_construct(this: CssSumCalculationNode*, values: ak.Vector[CssCalculationNode*], numeric_type: CssNumericType?):
css_calculation_node_construct(this.css_calculation_node(), .sum, numeric_type)
css_calculation_node_set_class(this.css_calculation_node(), (const CssCalculationNodeVTable*)&css_sum_calculation_node_vtable, &css_sum_calculation_node_class)
this.m_values = values
assert(not ak.vector_is_empty(&this.m_values))
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:884 Web::CSS::SumCalculationNode::contains_percentage (override).
pub func css_sum_calculation_node_contains_percentage_impl(base: CssCalculationNode*) -> bool:
let this = (CssSumCalculationNode*)base
for value in ak.vector_span_const(&this.m_values):
if css_calculation_node_contains_percentage(value):
return true
return false
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:893 Web::CSS::SumCalculationNode::with_simplified_children (override).
pub func css_sum_calculation_node_with_simplified_children_impl(base: CssCalculationNode*, context: CssCalculationContext, resolution_context: CssCalculationResolutionContext) -> CssCalculationNode*:
return css_simplify_children_vector(base, css_sum_calculation_node_create_node, context, resolution_context)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:898 Web::CSS::SumCalculationNode::dump (override).
pub func css_sum_calculation_node_dump_impl(base: CssCalculationNode*, builder: ak.StringBuilder*, indent: i32):
let this = (CssSumCalculationNode*)base
css_appendff(builder, "{: >{}}SUM:\n", [ak.arg_str(""), ak.arg_i64((i64)indent)])
for item in ak.vector_span_const(&this.m_values):
css_calculation_node_dump(item, builder, indent + 2)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:905 Web::CSS::SumCalculationNode::equals (override).
pub func css_sum_calculation_node_equals_impl(base: CssCalculationNode*, other: CssCalculationNode*) -> bool:
let this = (CssSumCalculationNode*)base
if base == other:
return true
if css_calculation_node_type(base) != css_calculation_node_type(other):
return false
return css_calculation_node_vectors_equal(&this.m_values, &((CssSumCalculationNode*)other).m_values)
## The element-wise `equals` of two lists of children, sizes first (Sum, Product, Min and Max nodes' `equals`).
func css_calculation_node_vectors_equal(a: const ak.Vector[CssCalculationNode*]*, b: const ak.Vector[CssCalculationNode*]*) -> bool:
if ak.vector_size(a) != ak.vector_size(b):
return false
for i in 0..<ak.vector_size(a):
if not css_calculation_node_equals(*ak.vector_at_const(a, i), *ak.vector_at_const(b, i)):
return false
return true
## `all_of(values, is_computationally_independent)`.
func css_calculation_nodes_are_computationally_independent(values: const ak.Vector[CssCalculationNode*]*) -> bool:
for value in ak.vector_span_const(values):
if not css_calculation_node_is_computationally_independent(value):
return false
return true
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:920 Web::CSS::SumCalculationNode::is_computationally_independent (override).
pub func css_sum_calculation_node_is_computationally_independent_impl(base: CssCalculationNode*) -> bool:
let this = (CssSumCalculationNode*)base
return css_calculation_nodes_are_computationally_independent(&this.m_values)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:925 Web::CSS::SumCalculationNode::reify (override).
pub func css_sum_calculation_node_reify_impl(base: CssCalculationNode*, realm: Realm*) -> CssNumericValue*?:
let this = (CssSumCalculationNode*)base
let reified_children = css_reify_children(realm, ak.vector_span_const(&this.m_values)) else return none
return css_math_sum_create(realm, css_calculation_node_numeric_type(base) else trap("VERIFY: has_value"), reified_children)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.h:305 Web::CSS::SumCalculationNode::children (override).
pub func css_sum_calculation_node_children_impl(base: CssCalculationNode*) -> ak.Vector[CssCalculationNode*]:
let this = (CssSumCalculationNode*)base
return this.m_values
# mark: ProductCalculationNode ==================================================================
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:933 Web::CSS::ProductCalculationNode::create.
pub func css_product_calculation_node_create(values: ak.Vector[CssCalculationNode*]) -> CssProductCalculationNode*:
# https://drafts.csswg.org/css-values-4/#determine-the-type-of-a-calculation
# At a * sub-expression, multiply the types of the left and right arguments.
# The sub-expression’s type is the returned result.
let numeric_type = css_multiply_the_types(&values)
let this = &(new CssProductCalculationNode[1] --- else trap("out of memory"))[0]
css_product_calculation_node_construct(this, values, numeric_type)
return this
## css_product_calculation_node_create as a CssCreateFromChildren.
func css_product_calculation_node_create_node(values: ak.Vector[CssCalculationNode*]) -> CssCalculationNode*:
return css_product_calculation_node_create(values).css_calculation_node()
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:942 Web::CSS::ProductCalculationNode::ProductCalculationNode.
pub func css_product_calculation_node_construct(this: CssProductCalculationNode*, values: ak.Vector[CssCalculationNode*], numeric_type: CssNumericType?):
css_calculation_node_construct(this.css_calculation_node(), .product, numeric_type)
css_calculation_node_set_class(this.css_calculation_node(), (const CssCalculationNodeVTable*)&css_product_calculation_node_vtable, &css_product_calculation_node_class)
this.m_values = values
assert(not ak.vector_is_empty(&this.m_values))
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:951 Web::CSS::ProductCalculationNode::contains_percentage (override).
pub func css_product_calculation_node_contains_percentage_impl(base: CssCalculationNode*) -> bool:
let this = (CssProductCalculationNode*)base
for value in ak.vector_span_const(&this.m_values):
if css_calculation_node_contains_percentage(value):
return true
return false
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:960 Web::CSS::ProductCalculationNode::with_simplified_children (override).
pub func css_product_calculation_node_with_simplified_children_impl(base: CssCalculationNode*, context: CssCalculationContext, resolution_context: CssCalculationResolutionContext) -> CssCalculationNode*:
return css_simplify_children_vector(base, css_product_calculation_node_create_node, context, resolution_context)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:965 Web::CSS::ProductCalculationNode::dump (override).
pub func css_product_calculation_node_dump_impl(base: CssCalculationNode*, builder: ak.StringBuilder*, indent: i32):
let this = (CssProductCalculationNode*)base
css_appendff(builder, "{: >{}}PRODUCT:\n", [ak.arg_str(""), ak.arg_i64((i64)indent)])
for item in ak.vector_span_const(&this.m_values):
css_calculation_node_dump(item, builder, indent + 2)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:972 Web::CSS::ProductCalculationNode::equals (override).
pub func css_product_calculation_node_equals_impl(base: CssCalculationNode*, other: CssCalculationNode*) -> bool:
let this = (CssProductCalculationNode*)base
if base == other:
return true
if css_calculation_node_type(base) != css_calculation_node_type(other):
return false
return css_calculation_node_vectors_equal(&this.m_values, &((CssProductCalculationNode*)other).m_values)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:987 Web::CSS::ProductCalculationNode::is_computationally_independent (override).
pub func css_product_calculation_node_is_computationally_independent_impl(base: CssCalculationNode*) -> bool:
let this = (CssProductCalculationNode*)base
return css_calculation_nodes_are_computationally_independent(&this.m_values)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:992 Web::CSS::ProductCalculationNode::reify (override).
pub func css_product_calculation_node_reify_impl(base: CssCalculationNode*, realm: Realm*) -> CssNumericValue*?:
let this = (CssProductCalculationNode*)base
let reified_children = css_reify_children(realm, ak.vector_span_const(&this.m_values)) else return none
return css_math_product_create(realm, css_calculation_node_numeric_type(base) else trap("VERIFY: has_value"), reified_children)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.h:325 Web::CSS::ProductCalculationNode::children (override).
pub func css_product_calculation_node_children_impl(base: CssCalculationNode*) -> ak.Vector[CssCalculationNode*]:
let this = (CssProductCalculationNode*)base
return this.m_values
# mark: NegateCalculationNode ===================================================================
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1000 Web::CSS::NegateCalculationNode::create.
pub func css_negate_calculation_node_create(value: CssCalculationNode*) -> CssNegateCalculationNode*:
let this = &(new CssNegateCalculationNode[1] --- else trap("out of memory"))[0]
css_negate_calculation_node_construct(this, value)
return this
## css_negate_calculation_node_create as a CssCreateFromChild.
func css_negate_calculation_node_create_node(value: CssCalculationNode*) -> CssCalculationNode*:
return css_negate_calculation_node_create(value).css_calculation_node()
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1005 Web::CSS::NegateCalculationNode::NegateCalculationNode.
pub func css_negate_calculation_node_construct(this: CssNegateCalculationNode*, value: CssCalculationNode*):
# NOTE: `- foo` doesn't change the type
css_calculation_node_construct(this.css_calculation_node(), .negate, css_calculation_node_numeric_type(value))
css_calculation_node_set_class(this.css_calculation_node(), (const CssCalculationNodeVTable*)&css_negate_calculation_node_vtable, &css_negate_calculation_node_class)
this.m_value = value
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1014 Web::CSS::NegateCalculationNode::contains_percentage (override).
pub func css_negate_calculation_node_contains_percentage_impl(base: CssCalculationNode*) -> bool:
let this = (CssNegateCalculationNode*)base
return css_calculation_node_contains_percentage(this.m_value)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1019 Web::CSS::NegateCalculationNode::with_simplified_children (override).
pub func css_negate_calculation_node_with_simplified_children_impl(base: CssCalculationNode*, context: CssCalculationContext, resolution_context: CssCalculationResolutionContext) -> CssCalculationNode*:
let this = (CssNegateCalculationNode*)base
return css_simplify_child(base, css_negate_calculation_node_create_node, this.m_value, context, resolution_context)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1024 Web::CSS::NegateCalculationNode::dump (override).
pub func css_negate_calculation_node_dump_impl(base: CssCalculationNode*, builder: ak.StringBuilder*, indent: i32):
let this = (CssNegateCalculationNode*)base
css_appendff(builder, "{: >{}}NEGATE:\n", [ak.arg_str(""), ak.arg_i64((i64)indent)])
css_calculation_node_dump(this.m_value, builder, indent + 2)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1030 Web::CSS::NegateCalculationNode::equals (override).
pub func css_negate_calculation_node_equals_impl(base: CssCalculationNode*, other: CssCalculationNode*) -> bool:
let this = (CssNegateCalculationNode*)base
if base == other:
return true
if css_calculation_node_type(base) != css_calculation_node_type(other):
return false
return css_calculation_node_equals(this.m_value, ((CssNegateCalculationNode*)other).m_value)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1039 Web::CSS::NegateCalculationNode::is_computationally_independent (override).
pub func css_negate_calculation_node_is_computationally_independent_impl(base: CssCalculationNode*) -> bool:
let this = (CssNegateCalculationNode*)base
return css_calculation_node_is_computationally_independent(this.m_value)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1044 Web::CSS::NegateCalculationNode::reify (override).
pub func css_negate_calculation_node_reify_impl(base: CssCalculationNode*, realm: Realm*) -> CssNumericValue*?:
let this = (CssNegateCalculationNode*)base
let reified_value = css_calculation_node_reify(this.m_value, realm) else return none
return css_math_negate_create(realm, css_calculation_node_numeric_type(base) else trap("VERIFY: has_value"), reified_value)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.h:345 Web::CSS::NegateCalculationNode::children (override).
pub func css_negate_calculation_node_children_impl(base: CssCalculationNode*) -> ak.Vector[CssCalculationNode*]:
let this = (CssNegateCalculationNode*)base
var children = ak.Vector[CssCalculationNode*]()
ak.vector_append_t(&children, this.m_value)
return children
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.h:346 Web::CSS::NegateCalculationNode::child.
pub func css_negate_calculation_node_child(this: CssNegateCalculationNode*) -> CssCalculationNode*:
return this.m_value
# mark: InvertCalculationNode ===================================================================
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1052 Web::CSS::InvertCalculationNode::create.
pub func css_invert_calculation_node_create(value: CssCalculationNode*) -> CssInvertCalculationNode*:
# https://drafts.csswg.org/css-values-4/#determine-the-type-of-a-calculation
# At a / sub-expression, let left type be the result of finding the types of its left argument,
# and right type be the result of finding the types of its right argument and then inverting it.
# The sub-expression’s type is the result of multiplying the left type and right type.
# NOTE: An InvertCalculationNode only represents the right argument here, and the multiplication
# is handled in the parent ProductCalculationNode.
var numeric_type: CssNumericType? = none
if let value_type = css_calculation_node_numeric_type(value):
numeric_type = css_numeric_type_inverted(&value_type)
let this = &(new CssInvertCalculationNode[1] --- else trap("out of memory"))[0]
css_invert_calculation_node_construct(this, value, numeric_type)
return this
## css_invert_calculation_node_create as a CssCreateFromChild.
func css_invert_calculation_node_create_node(value: CssCalculationNode*) -> CssCalculationNode*:
return css_invert_calculation_node_create(value).css_calculation_node()
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1064 Web::CSS::InvertCalculationNode::InvertCalculationNode.
pub func css_invert_calculation_node_construct(this: CssInvertCalculationNode*, value: CssCalculationNode*, numeric_type: CssNumericType?):
css_calculation_node_construct(this.css_calculation_node(), .invert, numeric_type)
css_calculation_node_set_class(this.css_calculation_node(), (const CssCalculationNodeVTable*)&css_invert_calculation_node_vtable, &css_invert_calculation_node_class)
this.m_value = value
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1072 Web::CSS::InvertCalculationNode::contains_percentage (override).
pub func css_invert_calculation_node_contains_percentage_impl(base: CssCalculationNode*) -> bool:
let this = (CssInvertCalculationNode*)base
return css_calculation_node_contains_percentage(this.m_value)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1077 Web::CSS::InvertCalculationNode::with_simplified_children (override).
pub func css_invert_calculation_node_with_simplified_children_impl(base: CssCalculationNode*, context: CssCalculationContext, resolution_context: CssCalculationResolutionContext) -> CssCalculationNode*:
let this = (CssInvertCalculationNode*)base
return css_simplify_child(base, css_invert_calculation_node_create_node, this.m_value, context, resolution_context)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1082 Web::CSS::InvertCalculationNode::dump (override).
pub func css_invert_calculation_node_dump_impl(base: CssCalculationNode*, builder: ak.StringBuilder*, indent: i32):
let this = (CssInvertCalculationNode*)base
css_appendff(builder, "{: >{}}INVERT:\n", [ak.arg_str(""), ak.arg_i64((i64)indent)])
css_calculation_node_dump(this.m_value, builder, indent + 2)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1088 Web::CSS::InvertCalculationNode::equals (override).
pub func css_invert_calculation_node_equals_impl(base: CssCalculationNode*, other: CssCalculationNode*) -> bool:
let this = (CssInvertCalculationNode*)base
if base == other:
return true
if css_calculation_node_type(base) != css_calculation_node_type(other):
return false
return css_calculation_node_equals(this.m_value, ((CssInvertCalculationNode*)other).m_value)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1097 Web::CSS::InvertCalculationNode::is_computationally_independent (override).
pub func css_invert_calculation_node_is_computationally_independent_impl(base: CssCalculationNode*) -> bool:
let this = (CssInvertCalculationNode*)base
return css_calculation_node_is_computationally_independent(this.m_value)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1102 Web::CSS::InvertCalculationNode::reify (override).
pub func css_invert_calculation_node_reify_impl(base: CssCalculationNode*, realm: Realm*) -> CssNumericValue*?:
let this = (CssInvertCalculationNode*)base
let reified_value = css_calculation_node_reify(this.m_value, realm) else return none
return css_math_invert_create(realm, css_calculation_node_numeric_type(base) else trap("VERIFY: has_value"), reified_value)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.h:366 Web::CSS::InvertCalculationNode::children (override).
pub func css_invert_calculation_node_children_impl(base: CssCalculationNode*) -> ak.Vector[CssCalculationNode*]:
let this = (CssInvertCalculationNode*)base
var children = ak.Vector[CssCalculationNode*]()
ak.vector_append_t(&children, this.m_value)
return children
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.h:367 Web::CSS::InvertCalculationNode::child.
pub func css_invert_calculation_node_child(this: CssInvertCalculationNode*) -> CssCalculationNode*:
return this.m_value