LibWeb/CSS: Use NumericCalculationNode for constants

Having multiple kinds of node that hold numeric values made things more
complicated than they needed to be, and we were already converting
ConstantCalculationNodes to NumericCalculationNodes in the first
simplification pass that happens at parse-time, so they didn't exist
after that.

As noted, the spec allows for other contexts to introduce their own
numeric keywords, which might be resolved later than parse-time. We'll
need a different mechanism to support those, but
ConstantCalculationNode could not have done so anyway.
This commit is contained in:
Sam Atkins 2025-02-25 16:37:10 +00:00 committed by Andreas Kling
commit f97ac33cb3
Notes: github-actions[bot] 2025-02-27 20:43:53 +00:00
6 changed files with 45 additions and 140 deletions

View file

@ -3340,10 +3340,10 @@ RefPtr<CalculationNode> Parser::convert_to_calculation_node(CalcParsing::Node co
// AD-HOC: We also need to convert tokens into their numeric types.
if (component_value->is(Token::Type::Ident)) {
auto maybe_constant = CalculationNode::constant_type_from_string(component_value->token().ident());
if (!maybe_constant.has_value())
auto maybe_keyword = keyword_from_string(component_value->token().ident());
if (!maybe_keyword.has_value())
return nullptr;
return ConstantCalculationNode::create(*maybe_constant);
return NumericCalculationNode::from_keyword(*maybe_keyword, context);
}
if (component_value->is(Token::Type::Number))