dymokomi/luce-browser-engine
Source of release 0.6.0
0.6.0 / src / web / css / style_values / calculated_style_value_4.lucb
#==============================================================================================
#
# calculated_style_value_4 - CalculatedStyleValue: min(), max(), clamp(), abs(), sign(), sin()
#
# DESCRIPTION:
# Port of LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp (lines 1123-1638) and the inline
# members of CalculatedStyleValue.h they belong with: the Min, Max, Clamp, Abs, Sign and Sin
# nodes, run_min_or_max_operation_if_possible and run_sin_cos_or_tan_operation_if_possible.
#
# 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: MinCalculationNode ======================================================================
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1110 Web::CSS::MinCalculationNode::create.
pub func css_min_calculation_node_create(values: ak.Vector[CssCalculationNode*]) -> CssMinCalculationNode*:
# https://drafts.csswg.org/css-values-4/#determine-the-type-of-a-calculation
# The result of adding the types of its comma-separated calculations.
let numeric_type = css_add_the_types_vector(&values)
let this = &(new CssMinCalculationNode[1] --- else trap("out of memory"))[0]
css_min_calculation_node_construct(this, values, numeric_type)
return this
## css_min_calculation_node_create as a CssCreateFromChildren.
func css_min_calculation_node_create_node(values: ak.Vector[CssCalculationNode*]) -> CssCalculationNode*:
return css_min_calculation_node_create(values).css_calculation_node()
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1118 Web::CSS::MinCalculationNode::MinCalculationNode.
pub func css_min_calculation_node_construct(this: CssMinCalculationNode*, values: ak.Vector[CssCalculationNode*], numeric_type: CssNumericType?):
css_calculation_node_construct(this.css_calculation_node(), .min, numeric_type)
css_calculation_node_set_class(this.css_calculation_node(), (const CssCalculationNodeVTable*)&css_min_calculation_node_vtable, &css_min_calculation_node_class)
this.m_values = values
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1126 Web::CSS::MinCalculationNode::contains_percentage (override).
pub func css_min_calculation_node_contains_percentage_impl(base: CssCalculationNode*) -> bool:
let this = (CssMinCalculationNode*)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:1136 Web::CSS::MinCalculationNode::with_simplified_children (override).
pub func css_min_calculation_node_with_simplified_children_impl(base: CssCalculationNode*, context: CssCalculationContext, resolution_context: CssCalculationResolutionContext) -> CssCalculationNode*:
return css_simplify_children_vector(base, css_min_calculation_node_create_node, context, resolution_context)
## `CalculationResult { value, type }`.
pub func css_calculated_style_value_calculation_result_new(value: f64, type_: CssNumericType?) -> CssCalculatedStyleValueCalculationResult:
var result = CssCalculatedStyleValueCalculationResult(m_value = 0.0)
css_calculated_style_value_calculation_result_construct(&result, value, type_)
return result
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1146 Web::CSS::run_min_or_max_operation_if_possible.
func css_run_min_or_max_operation_if_possible(children: const ak.Vector[CssCalculationNode*]*, context: CssCalculationContext, resolution_context: CssCalculationResolutionContext, min_or_max: CssMinOrMax) -> CssCalculatedStyleValueCalculationResult?:
# The min() or max() functions contain one or more comma-separated calculations, and represent the smallest
# (most negative) or largest (most positive) of them, respectively.
var result: CssCalculatedStyleValueCalculationResult? = none
for child in ak.vector_span_const(children):
let child_value = css_try_get_value_with_canonical_unit(child, context, resolution_context) else return none
if let current = result:
let current_type = current.m_type else trap("VERIFY: has_value")
let consistent_type = css_numeric_type_consistent_type(¤t_type, child_value.m_type else trap("VERIFY: has_value")) else return none
# https://drafts.csswg.org/css-values-4/#calc-ieee
# Any operation with at least one NaN argument produces NaN.
if math.is_nan(child_value.m_value) or math.is_nan(current.m_value):
result = css_calculated_style_value_calculation_result_new(math.nan, consistent_type)
continue
if min_or_max == CssMinOrMax.min:
if child_value.m_value < current.m_value:
result = css_calculated_style_value_calculation_result_new(child_value.m_value, consistent_type)
else:
result = css_calculated_style_value_calculation_result_new(current.m_value, consistent_type)
else:
if child_value.m_value > current.m_value:
result = css_calculated_style_value_calculation_result_new(child_value.m_value, consistent_type)
else:
result = css_calculated_style_value_calculation_result_new(current.m_value, consistent_type)
else:
result = child_value
return result
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1189 Web::CSS::MinCalculationNode::run_operation_if_possible (override).
# https://drafts.csswg.org/css-values-4/#funcdef-min
pub func css_min_calculation_node_run_operation_if_possible_impl(base: CssCalculationNode*, context: CssCalculationContext, resolution_context: CssCalculationResolutionContext) -> CssCalculatedStyleValueCalculationResult?:
let this = (CssMinCalculationNode*)base
return css_run_min_or_max_operation_if_possible(&this.m_values, context, resolution_context, .min)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1194 Web::CSS::MinCalculationNode::dump (override).
pub func css_min_calculation_node_dump_impl(base: CssCalculationNode*, builder: ak.StringBuilder*, indent: i32):
let this = (CssMinCalculationNode*)base
css_appendff(builder, "{: >{}}MIN:\n", [ak.arg_str(""), ak.arg_i64((i64)indent)])
for value in ak.vector_span_const(&this.m_values):
css_calculation_node_dump(value, builder, indent + 2)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1201 Web::CSS::MinCalculationNode::equals (override).
pub func css_min_calculation_node_equals_impl(base: CssCalculationNode*, other: CssCalculationNode*) -> bool:
let this = (CssMinCalculationNode*)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, &((CssMinCalculationNode*)other).m_values)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1216 Web::CSS::MinCalculationNode::is_computationally_independent (override).
pub func css_min_calculation_node_is_computationally_independent_impl(base: CssCalculationNode*) -> bool:
let this = (CssMinCalculationNode*)base
return css_calculation_nodes_are_computationally_independent(&this.m_values)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1221 Web::CSS::MinCalculationNode::reify (override).
pub func css_min_calculation_node_reify_impl(base: CssCalculationNode*, realm: Realm*) -> CssNumericValue*?:
let this = (CssMinCalculationNode*)base
let reified_children = css_reify_children(realm, ak.vector_span_const(&this.m_values)) else return none
return css_math_min_create(realm, css_calculation_node_numeric_type(base) else trap("VERIFY: has_value"), reified_children)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.h:388 Web::CSS::MinCalculationNode::children (override).
pub func css_min_calculation_node_children_impl(base: CssCalculationNode*) -> ak.Vector[CssCalculationNode*]:
let this = (CssMinCalculationNode*)base
return this.m_values
# mark: MaxCalculationNode ======================================================================
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1229 Web::CSS::MaxCalculationNode::create.
pub func css_max_calculation_node_create(values: ak.Vector[CssCalculationNode*]) -> CssMaxCalculationNode*:
# https://drafts.csswg.org/css-values-4/#determine-the-type-of-a-calculation
# The result of adding the types of its comma-separated calculations.
let numeric_type = css_add_the_types_vector(&values)
let this = &(new CssMaxCalculationNode[1] --- else trap("out of memory"))[0]
css_max_calculation_node_construct(this, values, numeric_type)
return this
## css_max_calculation_node_create as a CssCreateFromChildren.
func css_max_calculation_node_create_node(values: ak.Vector[CssCalculationNode*]) -> CssCalculationNode*:
return css_max_calculation_node_create(values).css_calculation_node()
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1237 Web::CSS::MaxCalculationNode::MaxCalculationNode.
pub func css_max_calculation_node_construct(this: CssMaxCalculationNode*, values: ak.Vector[CssCalculationNode*], numeric_type: CssNumericType?):
css_calculation_node_construct(this.css_calculation_node(), .max, numeric_type)
css_calculation_node_set_class(this.css_calculation_node(), (const CssCalculationNodeVTable*)&css_max_calculation_node_vtable, &css_max_calculation_node_class)
this.m_values = values
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1245 Web::CSS::MaxCalculationNode::contains_percentage (override).
pub func css_max_calculation_node_contains_percentage_impl(base: CssCalculationNode*) -> bool:
let this = (CssMaxCalculationNode*)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:1255 Web::CSS::MaxCalculationNode::with_simplified_children (override).
pub func css_max_calculation_node_with_simplified_children_impl(base: CssCalculationNode*, context: CssCalculationContext, resolution_context: CssCalculationResolutionContext) -> CssCalculationNode*:
return css_simplify_children_vector(base, css_max_calculation_node_create_node, context, resolution_context)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1261 Web::CSS::MaxCalculationNode::run_operation_if_possible (override).
# https://drafts.csswg.org/css-values-4/#funcdef-max
pub func css_max_calculation_node_run_operation_if_possible_impl(base: CssCalculationNode*, context: CssCalculationContext, resolution_context: CssCalculationResolutionContext) -> CssCalculatedStyleValueCalculationResult?:
let this = (CssMaxCalculationNode*)base
return css_run_min_or_max_operation_if_possible(&this.m_values, context, resolution_context, .max)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1266 Web::CSS::MaxCalculationNode::dump (override).
pub func css_max_calculation_node_dump_impl(base: CssCalculationNode*, builder: ak.StringBuilder*, indent: i32):
let this = (CssMaxCalculationNode*)base
css_appendff(builder, "{: >{}}MAX:\n", [ak.arg_str(""), ak.arg_i64((i64)indent)])
for value in ak.vector_span_const(&this.m_values):
css_calculation_node_dump(value, builder, indent + 2)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1273 Web::CSS::MaxCalculationNode::equals (override).
pub func css_max_calculation_node_equals_impl(base: CssCalculationNode*, other: CssCalculationNode*) -> bool:
let this = (CssMaxCalculationNode*)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, &((CssMaxCalculationNode*)other).m_values)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1288 Web::CSS::MaxCalculationNode::is_computationally_independent (override).
pub func css_max_calculation_node_is_computationally_independent_impl(base: CssCalculationNode*) -> bool:
let this = (CssMaxCalculationNode*)base
return css_calculation_nodes_are_computationally_independent(&this.m_values)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1293 Web::CSS::MaxCalculationNode::reify (override).
pub func css_max_calculation_node_reify_impl(base: CssCalculationNode*, realm: Realm*) -> CssNumericValue*?:
let this = (CssMaxCalculationNode*)base
let reified_children = css_reify_children(realm, ak.vector_span_const(&this.m_values)) else return none
return css_math_max_create(realm, css_calculation_node_numeric_type(base) else trap("VERIFY: has_value"), reified_children)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.h:409 Web::CSS::MaxCalculationNode::children (override).
pub func css_max_calculation_node_children_impl(base: CssCalculationNode*) -> ak.Vector[CssCalculationNode*]:
let this = (CssMaxCalculationNode*)base
return this.m_values
# mark: ClampCalculationNode ====================================================================
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1301 Web::CSS::ClampCalculationNode::create.
pub func css_clamp_calculation_node_create(min: CssCalculationNode*, center: CssCalculationNode*, max: CssCalculationNode*) -> CssClampCalculationNode*:
# https://drafts.csswg.org/css-values-4/#determine-the-type-of-a-calculation
# The result of adding the types of its comma-separated calculations.
let numeric_type = css_add_the_types_css_calculation_node_css_calculation_node_css_calculation_node(min, center, max)
let this = &(new CssClampCalculationNode[1] --- else trap("out of memory"))[0]
css_clamp_calculation_node_construct(this, min, center, max, numeric_type)
return this
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1309 Web::CSS::ClampCalculationNode::ClampCalculationNode.
pub func css_clamp_calculation_node_construct(this: CssClampCalculationNode*, min: CssCalculationNode*, center: CssCalculationNode*, max: CssCalculationNode*, numeric_type: CssNumericType?):
css_calculation_node_construct(this.css_calculation_node(), .clamp, numeric_type)
css_calculation_node_set_class(this.css_calculation_node(), (const CssCalculationNodeVTable*)&css_clamp_calculation_node_vtable, &css_clamp_calculation_node_class)
this.m_min_value = min
this.m_center_value = center
this.m_max_value = max
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1319 Web::CSS::ClampCalculationNode::contains_percentage (override).
pub func css_clamp_calculation_node_contains_percentage_impl(base: CssCalculationNode*) -> bool:
let this = (CssClampCalculationNode*)base
return css_calculation_node_contains_percentage(this.m_min_value) or css_calculation_node_contains_percentage(this.m_center_value) or css_calculation_node_contains_percentage(this.m_max_value)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1324 Web::CSS::ClampCalculationNode::with_simplified_children (override).
pub func css_clamp_calculation_node_with_simplified_children_impl(base: CssCalculationNode*, context: CssCalculationContext, resolution_context: CssCalculationResolutionContext) -> CssCalculationNode*:
let this = (CssClampCalculationNode*)base
let simplified_min = css_simplify_a_calculation_tree(this.m_min_value, context, resolution_context)
let simplified_center = css_simplify_a_calculation_tree(this.m_center_value, context, resolution_context)
let simplified_max = css_simplify_a_calculation_tree(this.m_max_value, context, resolution_context)
if simplified_min != this.m_min_value or simplified_center != this.m_center_value or simplified_max != this.m_max_value:
return css_clamp_calculation_node_create(simplified_min, simplified_center, simplified_max).css_calculation_node()
return base
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1335 Web::CSS::ClampCalculationNode::run_operation_if_possible (override).
# https://drafts.csswg.org/css-values-4/#funcdef-clamp
pub func css_clamp_calculation_node_run_operation_if_possible_impl(base: CssCalculationNode*, context: CssCalculationContext, resolution_context: CssCalculationResolutionContext) -> CssCalculatedStyleValueCalculationResult?:
let this = (CssClampCalculationNode*)base
# The clamp() function takes three calculations — a minimum value, a central value, and a maximum value — and
# represents its central calculation, clamped according to its min and max calculations, favoring the min
# calculation if it conflicts with the max. (That is, given clamp(MIN, VAL, MAX), it represents exactly the
# same value as max(MIN, min(VAL, MAX))).
#
# Either the min or max calculations (or even both) can instead be the keyword none, which indicates the value
# is not clamped from that side. (That is, clamp(MIN, VAL, none) is equivalent to max(MIN, VAL), clamp(none,
# VAL, MAX) is equivalent to min(VAL, MAX), and clamp(none, VAL, none) is equivalent to just calc(VAL).)
#
# For all three functions, the argument calculations can resolve to any <number>, <dimension>, or <percentage>,
# but must have a consistent type or else the function is invalid; the result’s type will be the consistent type.
let min_result = css_try_get_value_with_canonical_unit(this.m_min_value, context, resolution_context) else return none
let center_result = css_try_get_value_with_canonical_unit(this.m_center_value, context, resolution_context) else return none
let max_result = css_try_get_value_with_canonical_unit(this.m_max_value, context, resolution_context) else return none
let min_type = min_result.m_type else trap("VERIFY: has_value")
let min_and_center_type = css_numeric_type_consistent_type(&min_type, center_result.m_type else trap("VERIFY: has_value")) else return none
let consistent_type = css_numeric_type_consistent_type(&min_and_center_type, max_result.m_type else trap("VERIFY: has_value")) else return none
# https://drafts.csswg.org/css-values-4/#calc-ieee
# Any operation with at least one NaN argument produces NaN.
if math.is_nan(min_result.m_value) or math.is_nan(center_result.m_value) or math.is_nan(max_result.m_value):
return css_calculated_style_value_calculation_result_new(math.nan, consistent_type)
let chosen_value = ak.max_f64(min_result.m_value, ak.min_f64(center_result.m_value, max_result.m_value))
return css_calculated_style_value_calculation_result_new(chosen_value, consistent_type)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1374 Web::CSS::ClampCalculationNode::dump (override).
pub func css_clamp_calculation_node_dump_impl(base: CssCalculationNode*, builder: ak.StringBuilder*, indent: i32):
let this = (CssClampCalculationNode*)base
css_appendff(builder, "{: >{}}CLAMP:\n", [ak.arg_str(""), ak.arg_i64((i64)indent)])
css_calculation_node_dump(this.m_min_value, builder, indent + 2)
css_calculation_node_dump(this.m_center_value, builder, indent + 2)
css_calculation_node_dump(this.m_max_value, builder, indent + 2)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1382 Web::CSS::ClampCalculationNode::equals (override).
pub func css_clamp_calculation_node_equals_impl(base: CssCalculationNode*, other: CssCalculationNode*) -> bool:
let this = (CssClampCalculationNode*)base
if base == other:
return true
if css_calculation_node_type(base) != css_calculation_node_type(other):
return false
let other_clamp = (CssClampCalculationNode*)other
return (css_calculation_node_equals(this.m_min_value, other_clamp.m_min_value) and css_calculation_node_equals(this.m_center_value, other_clamp.m_center_value) and css_calculation_node_equals(this.m_max_value, other_clamp.m_max_value))
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1393 Web::CSS::ClampCalculationNode::is_computationally_independent (override).
pub func css_clamp_calculation_node_is_computationally_independent_impl(base: CssCalculationNode*) -> bool:
let this = (CssClampCalculationNode*)base
return (css_calculation_node_is_computationally_independent(this.m_min_value) and css_calculation_node_is_computationally_independent(this.m_center_value) and css_calculation_node_is_computationally_independent(this.m_max_value))
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1400 Web::CSS::ClampCalculationNode::reify (override).
pub func css_clamp_calculation_node_reify_impl(base: CssCalculationNode*, realm: Realm*) -> CssNumericValue*?:
let this = (CssClampCalculationNode*)base
let lower = css_calculation_node_reify(this.m_min_value, realm)
let value = css_calculation_node_reify(this.m_center_value, realm)
let upper = css_calculation_node_reify(this.m_max_value, realm)
if lower == none or value == none or upper == none:
return none
return css_math_clamp_create(realm, css_calculation_node_numeric_type(base) else trap("VERIFY: has_value"), lower else trap("unreachable"), value else trap("unreachable"), upper else trap("unreachable"))
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.h:430 Web::CSS::ClampCalculationNode::children (override).
pub func css_clamp_calculation_node_children_impl(base: CssCalculationNode*) -> ak.Vector[CssCalculationNode*]:
let this = (CssClampCalculationNode*)base
var children = ak.Vector[CssCalculationNode*]()
ak.vector_append_t(&children, this.m_min_value)
ak.vector_append_t(&children, this.m_center_value)
ak.vector_append_t(&children, this.m_max_value)
return children
# mark: AbsCalculationNode ======================================================================
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1411 Web::CSS::AbsCalculationNode::create.
pub func css_abs_calculation_node_create(value: CssCalculationNode*) -> CssAbsCalculationNode*:
let this = &(new CssAbsCalculationNode[1] --- else trap("out of memory"))[0]
css_abs_calculation_node_construct(this, value)
return this
## css_abs_calculation_node_create as a CssCreateFromChild.
func css_abs_calculation_node_create_node(value: CssCalculationNode*) -> CssCalculationNode*:
return css_abs_calculation_node_create(value).css_calculation_node()
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1416 Web::CSS::AbsCalculationNode::AbsCalculationNode.
pub func css_abs_calculation_node_construct(this: CssAbsCalculationNode*, value: CssCalculationNode*):
# https://www.w3.org/TR/css-values-4/#determine-the-type-of-a-calculation
# The type of its contained calculation.
css_calculation_node_construct(this.css_calculation_node(), .abs, css_calculation_node_numeric_type(value))
css_calculation_node_set_class(this.css_calculation_node(), (const CssCalculationNodeVTable*)&css_abs_calculation_node_vtable, &css_abs_calculation_node_class)
this.m_value = value
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1426 Web::CSS::AbsCalculationNode::contains_percentage (override).
pub func css_abs_calculation_node_contains_percentage_impl(base: CssCalculationNode*) -> bool:
let this = (CssAbsCalculationNode*)base
return css_calculation_node_contains_percentage(this.m_value)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1431 Web::CSS::AbsCalculationNode::with_simplified_children (override).
pub func css_abs_calculation_node_with_simplified_children_impl(base: CssCalculationNode*, context: CssCalculationContext, resolution_context: CssCalculationResolutionContext) -> CssCalculationNode*:
let this = (CssAbsCalculationNode*)base
return css_simplify_child(base, css_abs_calculation_node_create_node, this.m_value, context, resolution_context)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1437 Web::CSS::AbsCalculationNode::run_operation_if_possible (override).
# https://drafts.csswg.org/css-values-4/#funcdef-abs
pub func css_abs_calculation_node_run_operation_if_possible_impl(base: CssCalculationNode*, context: CssCalculationContext, resolution_context: CssCalculationResolutionContext) -> CssCalculatedStyleValueCalculationResult?:
let this = (CssAbsCalculationNode*)base
# The abs(A) function contains one calculation A, and returns the absolute value of A, as the same type as the input:
# if A’s numeric value is positive or 0⁺, just A again; otherwise -1 * A.
let child_value = css_try_get_value_with_canonical_unit(this.m_value, context, resolution_context) else return none
return css_calculated_style_value_calculation_result_new(math.abs(child_value.m_value), child_value.m_type)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1447 Web::CSS::AbsCalculationNode::dump (override).
pub func css_abs_calculation_node_dump_impl(base: CssCalculationNode*, builder: ak.StringBuilder*, indent: i32):
let this = (CssAbsCalculationNode*)base
css_appendff(builder, "{: >{}}ABS:\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:1453 Web::CSS::AbsCalculationNode::equals (override).
pub func css_abs_calculation_node_equals_impl(base: CssCalculationNode*, other: CssCalculationNode*) -> bool:
let this = (CssAbsCalculationNode*)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, ((CssAbsCalculationNode*)other).m_value)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1462 Web::CSS::AbsCalculationNode::is_computationally_independent (override).
pub func css_abs_calculation_node_is_computationally_independent_impl(base: CssCalculationNode*) -> bool:
let this = (CssAbsCalculationNode*)base
return css_calculation_node_is_computationally_independent(this.m_value)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.h:453 Web::CSS::AbsCalculationNode::children (override).
pub func css_abs_calculation_node_children_impl(base: CssCalculationNode*) -> ak.Vector[CssCalculationNode*]:
let this = (CssAbsCalculationNode*)base
var children = ak.Vector[CssCalculationNode*]()
ak.vector_append_t(&children, this.m_value)
return children
# mark: SignCalculationNode =====================================================================
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1467 Web::CSS::SignCalculationNode::create.
pub func css_sign_calculation_node_create(value: CssCalculationNode*) -> CssSignCalculationNode*:
let this = &(new CssSignCalculationNode[1] --- else trap("out of memory"))[0]
css_sign_calculation_node_construct(this, value)
return this
## css_sign_calculation_node_create as a CssCreateFromChild.
func css_sign_calculation_node_create_node(value: CssCalculationNode*) -> CssCalculationNode*:
return css_sign_calculation_node_create(value).css_calculation_node()
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1472 Web::CSS::SignCalculationNode::SignCalculationNode.
pub func css_sign_calculation_node_construct(this: CssSignCalculationNode*, value: CssCalculationNode*):
# https://www.w3.org/TR/css-values-4/#determine-the-type-of-a-calculation
# «[ ]» (empty map).
css_calculation_node_construct(this.css_calculation_node(), .sign, CssNumericType())
css_calculation_node_set_class(this.css_calculation_node(), (const CssCalculationNodeVTable*)&css_sign_calculation_node_vtable, &css_sign_calculation_node_class)
this.m_value = value
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1482 Web::CSS::SignCalculationNode::contains_percentage (override).
pub func css_sign_calculation_node_contains_percentage_impl(base: CssCalculationNode*) -> bool:
let this = (CssSignCalculationNode*)base
return css_calculation_node_contains_percentage(this.m_value)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1487 Web::CSS::SignCalculationNode::with_simplified_children (override).
pub func css_sign_calculation_node_with_simplified_children_impl(base: CssCalculationNode*, context: CssCalculationContext, resolution_context: CssCalculationResolutionContext) -> CssCalculationNode*:
let this = (CssSignCalculationNode*)base
return css_simplify_child(base, css_sign_calculation_node_create_node, this.m_value, context, resolution_context)
## The raw value of a numeric node's value: the number, the percentage as a fraction, or the dimension's raw value.
func css_numeric_node_raw_value_or_fraction(numeric_child: CssNumericCalculationNode*) -> f64:
match numeric_child.m_value:
.number(number): return css_syntax.number_value(&number)
.css_percentage(percentage): return css_percentage_as_fraction(&percentage)
_: return css_numeric_value_dimension_raw_value(&numeric_child.m_value)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1493 Web::CSS::SignCalculationNode::run_operation_if_possible (override).
# https://drafts.csswg.org/css-values-4/#funcdef-sign
pub func css_sign_calculation_node_run_operation_if_possible_impl(base: CssCalculationNode*, arg0: CssCalculationContext, arg1: CssCalculationResolutionContext) -> CssCalculatedStyleValueCalculationResult?:
_ = arg0
_ = arg1
let this = (CssSignCalculationNode*)base
# The sign(A) function contains one calculation A, and returns -1 if A’s numeric value is negative,
# +1 if A’s numeric value is positive, 0⁺ if A’s numeric value is 0⁺, and 0⁻ if A’s numeric value is 0⁻.
# The return type is a <number>, made consistent with the input calculation’s type.
if css_calculation_node_type(this.m_value) != CssCalculationNodeType.numeric:
return none
let numeric_child = as_css_numeric_calculation_node(this.m_value)
let raw_value = css_numeric_node_raw_value_or_fraction(numeric_child)
let empty_type = CssNumericType()
let return_type = css_numeric_type_made_consistent_with(&empty_type, css_calculation_node_numeric_type(numeric_child.css_calculation_node()) else CssNumericType())
# https://drafts.csswg.org/css-values-4/#calc-ieee
# Any operation with at least one NaN argument produces NaN.
if math.is_nan(raw_value):
return css_calculated_style_value_calculation_result_new(math.nan, return_type)
var sign = 0.0
if raw_value < 0.0:
sign = -1.0
elif raw_value > 0.0:
sign = 1.0
else:
sign = -0.0 if math.signbit(raw_value) else 0.0
return css_calculated_style_value_calculation_result_new(sign, return_type)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1527 Web::CSS::SignCalculationNode::dump (override).
pub func css_sign_calculation_node_dump_impl(base: CssCalculationNode*, builder: ak.StringBuilder*, indent: i32):
let this = (CssSignCalculationNode*)base
css_appendff(builder, "{: >{}}SIGN:\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:1533 Web::CSS::SignCalculationNode::equals (override).
pub func css_sign_calculation_node_equals_impl(base: CssCalculationNode*, other: CssCalculationNode*) -> bool:
let this = (CssSignCalculationNode*)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, ((CssSignCalculationNode*)other).m_value)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1542 Web::CSS::SignCalculationNode::is_computationally_independent (override).
pub func css_sign_calculation_node_is_computationally_independent_impl(base: CssCalculationNode*) -> bool:
let this = (CssSignCalculationNode*)base
return css_calculation_node_is_computationally_independent(this.m_value)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.h:473 Web::CSS::SignCalculationNode::children (override).
pub func css_sign_calculation_node_children_impl(base: CssCalculationNode*) -> ak.Vector[CssCalculationNode*]:
let this = (CssSignCalculationNode*)base
var children = ak.Vector[CssCalculationNode*]()
ak.vector_append_t(&children, this.m_value)
return children
# mark: SinCalculationNode ======================================================================
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1547 Web::CSS::SinCalculationNode::create.
pub func css_sin_calculation_node_create(value: CssCalculationNode*) -> CssSinCalculationNode*:
let this = &(new CssSinCalculationNode[1] --- else trap("out of memory"))[0]
css_sin_calculation_node_construct(this, value)
return this
## css_sin_calculation_node_create as a CssCreateFromChild.
func css_sin_calculation_node_create_node(value: CssCalculationNode*) -> CssCalculationNode*:
return css_sin_calculation_node_create(value).css_calculation_node()
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1552 Web::CSS::SinCalculationNode::SinCalculationNode.
pub func css_sin_calculation_node_construct(this: CssSinCalculationNode*, value: CssCalculationNode*):
# «[ ]» (empty map).
css_calculation_node_construct(this.css_calculation_node(), .sin, CssNumericType())
css_calculation_node_set_class(this.css_calculation_node(), (const CssCalculationNodeVTable*)&css_sin_calculation_node_vtable, &css_sin_calculation_node_class)
this.m_value = value
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1561 Web::CSS::SinCalculationNode::contains_percentage (override).
pub func css_sin_calculation_node_contains_percentage_impl(base: CssCalculationNode*) -> bool:
let this = (CssSinCalculationNode*)base
return css_calculation_node_contains_percentage(this.m_value)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1566 Web::CSS::SinCalculationNode::with_simplified_children (override).
pub func css_sin_calculation_node_with_simplified_children_impl(base: CssCalculationNode*, context: CssCalculationContext, resolution_context: CssCalculationResolutionContext) -> CssCalculationNode*:
let this = (CssSinCalculationNode*)base
return css_simplify_child(base, css_sin_calculation_node_create_node, this.m_value, context, resolution_context)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1576 Web::CSS::run_sin_cos_or_tan_operation_if_possible.
func css_run_sin_cos_or_tan_operation_if_possible(child: CssCalculationNode*, trig_function: CssSinCosOrTan) -> CssCalculatedStyleValueCalculationResult?:
# The sin(A), cos(A), and tan(A) functions all contain a single calculation which must resolve to either a <number>
# or an <angle>, and compute their corresponding function by interpreting the result of their argument as radians.
# (That is, sin(45deg), sin(.125turn), and sin(3.14159 / 4) all represent the same value, approximately .707.) They
# all represent a <number>, with the return type made consistent with the input calculation’s type. sin() and cos()
# will always return a number between −1 and 1, while tan() can return any number between −∞ and +∞.
# (See § 10.9 Type Checking for details on how math functions handle ∞.)
if css_calculation_node_type(child) != CssCalculationNodeType.numeric:
return none
let numeric_child = as_css_numeric_calculation_node(child)
var radians = 0.0
match numeric_child.m_value:
.css_angle(angle): radians = css_angle_to_radians(&angle)
.number(number): radians = css_syntax.number_value(&number)
_: trap("VERIFY_NOT_REACHED")
var result = 0.0
match trig_function:
.sin: result = math.sin(radians)
.cos: result = math.cos(radians)
.tan: result = math.tan(radians)
_: _ = 0
let empty_type = CssNumericType()
return css_calculated_style_value_calculation_result_new(result, css_numeric_type_made_consistent_with(&empty_type, css_calculation_node_numeric_type(child) else trap("VERIFY: has_value")))
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1611 Web::CSS::SinCalculationNode::run_operation_if_possible (override).
# https://drafts.csswg.org/css-values-4/#funcdef-sin
pub func css_sin_calculation_node_run_operation_if_possible_impl(base: CssCalculationNode*, arg0: CssCalculationContext, arg1: CssCalculationResolutionContext) -> CssCalculatedStyleValueCalculationResult?:
_ = arg0
_ = arg1
let this = (CssSinCalculationNode*)base
return css_run_sin_cos_or_tan_operation_if_possible(this.m_value, .sin)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1616 Web::CSS::SinCalculationNode::dump (override).
pub func css_sin_calculation_node_dump_impl(base: CssCalculationNode*, builder: ak.StringBuilder*, indent: i32):
let this = (CssSinCalculationNode*)base
css_appendff(builder, "{: >{}}SIN:\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:1622 Web::CSS::SinCalculationNode::equals (override).
pub func css_sin_calculation_node_equals_impl(base: CssCalculationNode*, other: CssCalculationNode*) -> bool:
let this = (CssSinCalculationNode*)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, ((CssSinCalculationNode*)other).m_value)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp:1631 Web::CSS::SinCalculationNode::is_computationally_independent (override).
pub func css_sin_calculation_node_is_computationally_independent_impl(base: CssCalculationNode*) -> bool:
let this = (CssSinCalculationNode*)base
return css_calculation_node_is_computationally_independent(this.m_value)
## Ported from Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.h:493 Web::CSS::SinCalculationNode::children (override).
pub func css_sin_calculation_node_children_impl(base: CssCalculationNode*) -> ak.Vector[CssCalculationNode*]:
let this = (CssSinCalculationNode*)base
var children = ak.Vector[CssCalculationNode*]()
ak.vector_append_t(&children, this.m_value)
return children