LibWeb/CSS: Simplify calculations after parsing them

If a calculation was simplified down to a single numeric node, then most
of the time we can instead return a regular StyleValue, for example
`calc(2px + 3px)` would be simplified down to a `5px` LengthStyleValue.
This means that parse_calculated_value() can't return a
CalculatedStyleValue directly, and its callers all have to handle
non-calculated values as well as calculated ones.

This simplification is reflected in the new test results. Serialization
is not yet correct in all cases but we're closer than we were. :^)
This commit is contained in:
Sam Atkins
2025-01-28 16:24:39 +00:00
committed by Andreas Kling
parent 39cefd7abf
commit ee712bd98f
15 changed files with 295 additions and 228 deletions

View File

@@ -268,6 +268,8 @@ public:
virtual CalculatedStyleValue::CalculationResult resolve(CalculationResolutionContext const&) const override;
virtual NonnullRefPtr<CalculationNode> with_simplified_children(CalculationContext const&, CalculationResolutionContext const&) const override { return *this; }
RefPtr<CSSStyleValue> to_style_value(CalculationContext const&) const;
NumericValue const& value() const { return m_value; }
virtual void dump(StringBuilder&, int indent) const override;