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

@ -78,6 +78,18 @@ public:
return to_px_slow_case(node);
}
ALWAYS_INLINE double to_px_without_rounding(ResolutionContext const& context) const
{
if (is_absolute())
return absolute_length_to_px_without_rounding();
if (is_font_relative())
return font_relative_length_to_px_without_rounding(context.font_metrics, context.root_font_metrics);
if (is_viewport_relative())
return viewport_relative_length_to_px_without_rounding(context.viewport_rect);
VERIFY_NOT_REACHED();
}
ALWAYS_INLINE CSSPixels to_px(CSSPixelRect const& viewport_rect, FontMetrics const& font_metrics, FontMetrics const& root_font_metrics) const
{
if (is_absolute())
@ -108,7 +120,9 @@ public:
}
CSSPixels font_relative_length_to_px(FontMetrics const& font_metrics, FontMetrics const& root_font_metrics) const;
double font_relative_length_to_px_without_rounding(FontMetrics const& font_metrics, FontMetrics const& root_font_metrics) const;
CSSPixels viewport_relative_length_to_px(CSSPixelRect const& viewport_rect) const;
double viewport_relative_length_to_px_without_rounding(CSSPixelRect const& viewport_rect) const;
// Returns empty optional if it's already absolute.
Optional<Length> absolutize(CSSPixelRect const& viewport_rect, FontMetrics const& font_metrics, FontMetrics const& root_font_metrics) const;