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

@ -251,7 +251,7 @@ RefPtr<CalculationNode> Parser::parse_math_function(Function const& function, Ca
// NOTE: We have exactly one default value in the data right now, and it's a `<calc-constant>`,
// so that's all we handle.
if (auto default_value = parameter.get_string("default"sv); default_value.has_value()) {
parameter_generator.set("parameter_default", MUST(String::formatted(" = ConstantCalculationNode::create(CalculationNode::constant_type_from_string(\"{}\"sv).value())", default_value.value())));
parameter_generator.set("parameter_default", MUST(String::formatted(" = NumericCalculationNode::from_keyword(Keyword::{}, context)", title_casify(default_value.value()))));
} else {
parameter_generator.set("parameter_default", ""_string);
}