LibWeb/CSS: Add a Property -> CalculationContext factory method

We have this code duplicated in multiple places, and we'll want to
handle registered custom properties too at some point, so wrap it in a
reusable `CalculationContext::for_property()` method.

Noticed while doing this that ValueParsingContext will eventually need
to take a PropertyNameAndID, not a PropertyID, so I've added a FIXME.
This commit is contained in:
Sam Atkins 2025-10-10 16:04:51 +01:00
commit 0afa93e639
Notes: github-actions[bot] 2025-10-13 09:01:24 +00:00
6 changed files with 19 additions and 15 deletions

View file

@ -322,11 +322,7 @@ WebIDL::ExceptionOr<NonnullRefPtr<StyleValue const>> CSSUnitValue::create_an_int
}
auto wrap_in_math_sum = [this, &property](auto&& value) -> NonnullRefPtr<StyleValue const> {
CalculationContext context {
.percentages_resolve_as = property_resolves_percentages_relative_to(property.id()),
.resolve_numbers_as_integers = property_accepts_type(property.id(), ValueType::Integer),
.accepted_type_ranges = property_accepted_type_ranges(property.id()),
};
auto context = CalculationContext::for_property(property);
auto numeric_node = NumericCalculationNode::create(value, context);
auto math_sum_node = SumCalculationNode::create({ move(numeric_node) });
return CalculatedStyleValue::create(move(math_sum_node), NumericType::create_from_unit(m_unit).release_value(), context);