1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:17:45 +00:00

LibWeb: Clamp justification space between flex items to 0

Before this change, it was possible for flex lines with negative
remaining space (due to overflowing items) to put a negative amount
of space between items for some values of `justify-content`.

This makes https://polar.sh/SerenityOS look much better :^)
This commit is contained in:
Andreas Kling 2024-01-25 12:51:33 +01:00
parent e668cdcf22
commit 1583e6ce07
3 changed files with 51 additions and 3 deletions

View file

@ -1230,11 +1230,11 @@ void FlexFormattingContext::distribute_any_remaining_free_space()
initial_offset = 0;
}
if (flex_line.remaining_free_space.has_value() && number_of_items > 1)
space_between_items = flex_line.remaining_free_space.value() / (number_of_items - 1);
space_between_items = max(CSSPixels(0), flex_line.remaining_free_space.value() / (number_of_items - 1));
break;
case CSS::JustifyContent::SpaceAround:
if (flex_line.remaining_free_space.has_value())
space_between_items = flex_line.remaining_free_space.value() / number_of_items;
space_between_items = max(CSSPixels(0), flex_line.remaining_free_space.value() / number_of_items);
if (is_direction_reverse()) {
initial_offset = inner_main_size(m_flex_container_state) - space_between_items / 2;
} else {
@ -1243,7 +1243,7 @@ void FlexFormattingContext::distribute_any_remaining_free_space()
break;
case CSS::JustifyContent::SpaceEvenly:
if (flex_line.remaining_free_space.has_value())
space_between_items = flex_line.remaining_free_space.value() / (number_of_items + 1);
space_between_items = max(CSSPixels(0), flex_line.remaining_free_space.value() / (number_of_items + 1));
if (is_direction_reverse()) {
initial_offset = inner_main_size(m_flex_container_state) - space_between_items;
} else {