LibWeb: Simplify standalone CSS math functions when used outside calc()

Math functions like abs(), clamp(), round(), etc, can be used by
themselves in property values, without wrapping them in calc().

Before this change, we were neglecting to run calc simplification on the
generated calculation node trees. By doing that manually after parsing a
standalone math function, we score at least a couple hundred WPT points.
This commit is contained in:
Andreas Kling
2025-04-24 17:33:52 +02:00
committed by Andreas Kling
parent 94ae63c436
commit 0553bcb35b
Notes: github-actions[bot] 2025-04-24 18:38:57 +00:00
10 changed files with 1298 additions and 2 deletions

View File

@@ -3515,8 +3515,11 @@ RefPtr<CalculationNode const> Parser::parse_a_calc_function_node(Function const&
if (function.name.equals_ignoring_ascii_case("calc"sv))
return parse_a_calculation(function.value, context);
if (auto maybe_function = parse_math_function(function, context))
return maybe_function;
if (auto maybe_function = parse_math_function(function, context)) {
// NOTE: We have to simplify manually here, since parse_math_function() is a helper for calc() parsing
// that doesn't do it directly by itself.
return simplify_a_calculation_tree(*maybe_function, context, CalculationResolutionContext {});
}
return nullptr;
}