mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-19 15:43:20 +00:00
LibWeb: Avoid premature creation of CSSPixels in calc simplification
Previously we were converting lengths to CSSPixels values when we didn't need to, this had a couple of effects in that: - We rounded to CSSPixel resolution prematurely (sometimes giving incorrect results) - We converted NaN to 0 when we shouldn't have. We now avoid prematurely converting lengths to CSSPixels values in two places: - `CalculationResult::from_value` - `CalculatedStyleValue::resolve_length_deprecated` (the new method already avoided rounding). Gains us 16 WPT tests.
This commit is contained in:
parent
3fa7bc1919
commit
a44e28fd56
Notes:
github-actions[bot]
2025-08-06 14:01:09 +00:00
Author: https://github.com/Calme1709
Commit: a44e28fd56
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5714
Reviewed-by: https://github.com/AtkinsSJ ✅
4 changed files with 74 additions and 17 deletions
|
@ -2600,7 +2600,7 @@ CalculatedStyleValue::CalculationResult CalculatedStyleValue::CalculationResult:
|
|||
return 0.0;
|
||||
|
||||
if (length.is_absolute())
|
||||
return length.absolute_length_to_px().to_double();
|
||||
return length.absolute_length_to_px_without_rounding();
|
||||
|
||||
// If we don't have a context, we cant resolve the length, so return NAN
|
||||
if (!context.length_resolution_context.has_value()) {
|
||||
|
@ -2751,7 +2751,7 @@ Optional<Length> CalculatedStyleValue::resolve_length_deprecated(CalculationReso
|
|||
{
|
||||
auto result = m_calculation->resolve(context);
|
||||
if (result.type().has_value() && result.type()->matches_length(m_context.percentages_resolve_as))
|
||||
return Length::make_px(CSSPixels { result.value() });
|
||||
return Length::make_px(result.value());
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue