LibWeb/CSS: Update CalculatedOr API to use CalculationResolutionContext

To be properly compatible with calc(), the resolved() methods all need:
- A length resolution context
- To return an Optional, as the calculation might not be resolvable

A bonus of this is that we can get rid of the overloads of `resolved()`
as they now all behave the same way.

A downside is a scattering of `value_or()` wherever these are used. It
might be the case that all unresolvable calculations have been rejected
before this point, but I'm not confident, and so I'll leave it like
this for now.
This commit is contained in:
Sam Atkins 2025-01-22 15:00:13 +00:00 committed by Andreas Kling
commit 385c3d273a
Notes: github-actions[bot] 2025-01-30 18:33:51 +00:00
11 changed files with 98 additions and 100 deletions

View file

@ -306,7 +306,10 @@ Vector<float> SVGGraphicsElement::stroke_dasharray() const
dasharray.append(resolve_relative_to_viewport_size(length_percentage));
},
[&](CSS::NumberOrCalculated const& number_or_calculated) {
dasharray.append(number_or_calculated.resolved(*layout_node()));
CSS::CalculationResolutionContext calculation_context {
.length_resolution_context = CSS::Length::ResolutionContext::for_layout_node(*layout_node()),
};
dasharray.append(number_or_calculated.resolved(calculation_context).value_or(0));
});
}