From e7f5b5a2f381e7677429edc8320d0257ef7fc1c7 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 16 Apr 2023 19:48:40 +0200 Subject: [PATCH] LibWeb: Fix multi-line flex column layouts with auto height on container When sizing a flex container with flex-direction:column under a max-content height constraint, we were incorrectly truncating the infinite available height to 0 when collecting flex items into lines. This caused us to put every flex item in its own flex line, which is the complete opposite of what we want during max-content intrinsic sizing, as the layout would grow wide but not tall. --- ...ine-column-container-with-automatic-height.txt | 7 +++++++ ...ne-column-container-with-automatic-height.html | 15 +++++++++++++++ .../LibWeb/Layout/FlexFormattingContext.cpp | 2 +- 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Layout/expected/flex/multi-line-column-container-with-automatic-height.txt create mode 100644 Tests/LibWeb/Layout/input/flex/multi-line-column-container-with-automatic-height.html diff --git a/Tests/LibWeb/Layout/expected/flex/multi-line-column-container-with-automatic-height.txt b/Tests/LibWeb/Layout/expected/flex/multi-line-column-container-with-automatic-height.txt new file mode 100644 index 00000000000..50b55e2e3c7 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/flex/multi-line-column-container-with-automatic-height.txt @@ -0,0 +1,7 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (1,1) content-size 798x176 children: not-inline + BlockContainer at (10,10) content-size 780x158 children: not-inline + Box at (11,11) content-size 200x156 flex-container(column) children: not-inline + BlockContainer
at (12,12) content-size 50x50 flex-item children: not-inline + BlockContainer
at (12,64) content-size 50x50 flex-item children: not-inline + BlockContainer
at (12,116) content-size 50x50 flex-item children: not-inline diff --git a/Tests/LibWeb/Layout/input/flex/multi-line-column-container-with-automatic-height.html b/Tests/LibWeb/Layout/input/flex/multi-line-column-container-with-automatic-height.html new file mode 100644 index 00000000000..2df2347fbe9 --- /dev/null +++ b/Tests/LibWeb/Layout/input/flex/multi-line-column-container-with-automatic-height.html @@ -0,0 +1,15 @@ +
\ No newline at end of file diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp index c18e2f781fe..803c62a8b11 100644 --- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp @@ -845,7 +845,7 @@ void FlexFormattingContext::collect_flex_items_into_flex_lines() CSSPixels line_main_size = 0; for (auto& item : m_flex_items) { auto const outer_hypothetical_main_size = item.outer_hypothetical_main_size(); - if (!line.items.is_empty() && (line_main_size + outer_hypothetical_main_size) > m_available_space_for_items->main.to_px_or_zero()) { + if (!line.items.is_empty() && (line_main_size + outer_hypothetical_main_size) > m_available_space_for_items->main.to_px()) { m_flex_lines.append(move(line)); line = {}; line_main_size = 0;