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.
This commit is contained in:
Andreas Kling 2022-03-12 19:36:04 +01:00
parent 2f3d7a7c36
commit ad8d65fd6e
Notes: sideshowbarker 2024-07-17 17:31:07 +09:00

View File

@ -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);
}
}