LibWeb: Properly clamp interpolated opacity values

Opacity values are unique in that the range which calculated and
interpolated values should be clamped to [0,1] is different from the
range of allowed values [-∞,∞].

This fixes 28 WPT tests that were regressed in #6112
This commit is contained in:
Callum Law 2025-09-09 22:03:23 +12:00 committed by Sam Atkins
commit 43dd0f2dda
Notes: github-actions[bot] 2025-09-24 11:02:58 +00:00
4 changed files with 251 additions and 21 deletions

View file

@ -3514,7 +3514,7 @@ NonnullRefPtr<StyleValue const> StyleComputer::compute_opacity(NonnullRefPtr<Sty
// NOTE: We also support calc()'d numbers
if (specified_value->is_calculated() && specified_value->as_calculated().resolves_to_number())
return NumberStyleValue::create(clamp(specified_value->as_calculated().resolve_number({ .length_resolution_context = computation_context.length_resolution_context }).value(), 0, 1));
return NumberStyleValue::create(specified_value->as_calculated().resolve_number({ .length_resolution_context = computation_context.length_resolution_context }).value());
// <percentage>
if (specified_value->is_percentage())
@ -3522,7 +3522,7 @@ NonnullRefPtr<StyleValue const> StyleComputer::compute_opacity(NonnullRefPtr<Sty
// NOTE: We also support calc()'d percentages
if (specified_value->is_calculated() && specified_value->as_calculated().resolves_to_percentage())
return NumberStyleValue::create(clamp(specified_value->as_calculated().resolve_percentage({ .length_resolution_context = computation_context.length_resolution_context })->as_fraction(), 0, 1));
return NumberStyleValue::create(specified_value->as_calculated().resolve_percentage({ .length_resolution_context = computation_context.length_resolution_context })->as_fraction());
VERIFY_NOT_REACHED();
}