LibWeb: Don't resolve calc'd opacity percentages at parse time

This behaviour should only apply to literal percentages as clarified
here: 4ee8429

We were also doing this wrong by converting the numeric type of the calc
to Length which was causing values to be defaulted to 1 instead (hence
the new passing tests for computed values as well)
This commit is contained in:
Callum Law 2025-09-07 23:32:06 +12:00 committed by Tim Ledbetter
commit 246a1c41ff
Notes: github-actions[bot] 2025-09-08 10:07:16 +00:00
6 changed files with 29 additions and 42 deletions

View file

@ -3844,15 +3844,6 @@ RefPtr<StyleValue const> Parser::parse_opacity_value(PropertyID property_id, Tok
// Percentages map to the range [0,1] for opacity values
if (value->is_percentage())
value = NumberStyleValue::create(value->as_percentage().percentage().as_fraction());
if (value->is_calculated() && value->as_calculated().resolves_to_percentage()) {
auto maybe_percentage = value->as_calculated().resolve_percentage_deprecated({});
if (maybe_percentage.has_value()) {
auto resolved_percentage = maybe_percentage->as_fraction();
CalculationContext context {};
auto calc_node = NumericCalculationNode::create(Number { Number::Type::Number, resolved_percentage }, context);
value = CalculatedStyleValue::create(move(calc_node), NumericType { NumericType::BaseType::Length, 1 }, context);
}
}
return value;
}