LibWeb: Improve precision when computing size of replaced elements

Change associativity in computing of replaced element size to improve
precision of division.

Fixes vertically squashed image from Mozilla splash page MDN example.
This commit is contained in:
Andi Gallo 2023-08-04 10:37:44 +00:00 committed by Alexander Kalenik
commit 3e70c1b6a3
Notes: sideshowbarker 2024-07-17 07:09:53 +09:00
3 changed files with 18 additions and 18 deletions

View file

@ -283,21 +283,21 @@ CSSPixelSize FormattingContext::solve_replaced_size_constraint(CSSPixels input_w
auto& h = size.height;
if (w > max_width)
size = { max_width, max(max_width * (h / w), min_height) };
size = { max_width, max(max_width * h / w, min_height) };
if (w < min_width)
size = { min_width, min(min_width * (h / w), max_height) };
size = { min_width, min(min_width * h / w, max_height) };
if (h > max_height)
size = { max(max_height * (w / h), min_width), max_height };
size = { max(max_height * w / h, min_width), max_height };
if (h < min_height)
size = { min(min_height * (w / h), max_width), min_height };
size = { min(min_height * w / h, max_width), min_height };
if ((w > max_width && h > max_height) && (max_width / w <= max_height / h))
size = { max_width, max(min_height, max_width * (h / w)) };
size = { max_width, max(min_height, max_width * h / w) };
if ((w > max_width && h > max_height) && (max_width / w > max_height / h))
size = { max(min_width, max_height * (w / h)), max_height };
size = { max(min_width, max_height * w / h), max_height };
if ((w < min_width && h < min_height) && (min_width / w <= min_height / h))
size = { min(max_width, min_height * (w / h)), min_height };
size = { min(max_width, min_height * w / h), min_height };
if ((w < min_width && h < min_height) && (min_width / w > min_height / h))
size = { min_width, min(max_height, min_width * (h / w)) };
size = { min_width, min(max_height, min_width * h / w) };
if (w < min_width && h > max_height)
size = { min_width, max_height };
if (w > max_width && h < min_height)