From ad8d65fd6e77b71f26738011d59a203e74a14e16 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 12 Mar 2022 19:36:04 +0100 Subject: [PATCH] LibWeb: Fix calculation of hypothetical cross size in column flex layout Simplify automatic cross sizing of items in flex-direction:column by using the fit-content width directly. There's obviously a lot more nuance to this, but for now this makes flex items with both width:auto and height:auto actually get some height in column flex layouts. --- .../LibWeb/Layout/FlexFormattingContext.cpp | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp index e0110627808..41a00072f07 100644 --- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp @@ -836,11 +836,16 @@ void FlexFormattingContext::determine_hypothetical_cross_size_of_item(FlexItem& } else { // Item has indefinite main size, layout with "fit-content" - float fit_content_main_size; - if (is_row_layout()) - fit_content_main_size = calculate_fit_content_width(item.box, m_available_space->main); - else - fit_content_main_size = calculate_fit_content_height(item.box, m_available_space->main); + // If we're in a column layout and looking for the width, just use the fit-content width. + if (!is_row_layout()) { + item.hypothetical_cross_size = calculate_fit_content_width(item.box, m_available_space->cross); + return; + } + + // We're in a row layout, looking for the height. Figure out the fit-content width, + // then layout with that and see what height comes out of it. + + float fit_content_main_size = calculate_fit_content_width(item.box, m_available_space->main); FormattingState throwaway_state(&m_state); auto& box_state = throwaway_state.get_mutable(item.box); @@ -850,18 +855,10 @@ void FlexFormattingContext::determine_hypothetical_cross_size_of_item(FlexItem& // NOTE: Flex items should always create an independent formatting context! VERIFY(independent_formatting_context); - if (is_row_layout()) { - box_state.content_width = fit_content_main_size; - } else { - box_state.content_height = fit_content_main_size; - } + box_state.content_width = fit_content_main_size; independent_formatting_context->run(item.box, LayoutMode::Default); - if (is_row_layout()) { - item.hypothetical_cross_size = BlockFormattingContext::compute_theoretical_height(throwaway_state, item.box); - } else { - item.hypothetical_cross_size = box_state.content_width; - } + item.hypothetical_cross_size = BlockFormattingContext::compute_theoretical_height(throwaway_state, item.box); } }