LibWeb/CSS: Implement "Create a sum value"

This commit is contained in:
Sam Atkins 2025-09-11 16:48:57 +01:00 committed by Jelle Raaijmakers
commit 80abffd2e8
Notes: github-actions[bot] 2025-09-12 11:46:44 +00:00
17 changed files with 320 additions and 1 deletions

View file

@ -129,4 +129,32 @@ bool CSSMathMax::is_equal_numeric_value(GC::Ref<CSSNumericValue> other) const
return m_values->is_equal_numeric_values(other_max->m_values);
}
// https://drafts.css-houdini.org/css-typed-om-1/#create-a-sum-value
Optional<SumValue> CSSMathMax::create_a_sum_value() const
{
// 1. Let args be the result of creating a sum value for each item in thiss values internal slot.
Vector<Optional<SumValue>> args;
args.ensure_capacity(m_values->length());
for (auto const& value : m_values->values()) {
args.unchecked_append(value->create_a_sum_value());
}
Optional<SumValue> item_with_largest_value = args.first();
for (auto const& item : args) {
// 2. If any item of args is failure, or has a length greater than one, return failure.
if (!item.has_value() || item->size() > 1)
return {};
// 3. If not all of the unit maps among the items of args are identical, return failure.
if (item->first().unit_map != item_with_largest_value->first().unit_map)
return {};
if (item->first().value > item_with_largest_value->first().value)
item_with_largest_value = item;
}
// 4. Return the item of args whose sole item has the largest value.
return item_with_largest_value;
}
}