LibWeb: Avoid early conversion to CSSPixels when simplifying calculation

Converting to CSSPixels caused us to lose precision and the sign of
signed zeroes.

The values we resolve against in Length::ResolutionContext are still
themselves rounded too early but this is in the right direction.
This commit is contained in:
Callum Law 2025-10-22 20:18:07 +13:00 committed by Sam Atkins
parent 43b06cbbdd
commit 0b45a68423
Notes: github-actions[bot] 2025-10-23 08:35:32 +00:00
6 changed files with 63 additions and 39 deletions

View file

@ -2531,7 +2531,7 @@ CalculatedStyleValue::CalculationResult CalculatedStyleValue::CalculationResult:
return AK::NaN<double>;
}
return length.to_px(context.length_resolution_context.value()).to_double();
return length.to_px_without_rounding(context.length_resolution_context.value());
},
[](Resolution const& resolution) { return resolution.to_dots_per_pixel(); },
[](Time const& time) { return time.to_seconds(); },
@ -2900,7 +2900,7 @@ NonnullRefPtr<CalculationNode const> simplify_a_calculation_tree(CalculationNode
if (length.is_absolute())
return NumericCalculationNode::create(Length::make_px(length.absolute_length_to_px()).percentage_of(*percentage), context);
if (resolution_context.length_resolution_context.has_value())
return NumericCalculationNode::create(Length::make_px(length.to_px(resolution_context.length_resolution_context.value())).percentage_of(*percentage), context);
return NumericCalculationNode::create(Length::make_px(length.to_px_without_rounding(resolution_context.length_resolution_context.value())).percentage_of(*percentage), context);
return nullptr;
},
[&](Time const& time) -> RefPtr<NumericCalculationNode const> {
@ -2938,9 +2938,9 @@ NonnullRefPtr<CalculationNode const> simplify_a_calculation_tree(CalculationNode
if (length.unit() == LengthUnit::Px)
return nullptr;
if (length.is_absolute())
return NumericCalculationNode::create(Length::make_px(length.absolute_length_to_px()), context);
return NumericCalculationNode::create(Length::make_px(length.absolute_length_to_px_without_rounding()), context);
if (resolution_context.length_resolution_context.has_value())
return NumericCalculationNode::create(Length::make_px(length.to_px(resolution_context.length_resolution_context.value())), context);
return NumericCalculationNode::create(Length::make_px(length.to_px_without_rounding(resolution_context.length_resolution_context.value())), context);
return nullptr;
},
[&](Number const&) -> RefPtr<CalculationNode const> {