From 33887917e4ea5958c29947852a7ca9fbc4ff7175 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 6 Apr 2022 11:52:13 +0200 Subject: [PATCH] LibWeb: Determine intrinsic flex container size from content-size When running the min-content and max-content sizing algorithms and the target box creates a flex formatting context, we don't need to measure its children. FFC has already assigned the content_width and content_height values, so we just need to pick those up from the container's formatting state. --- .../LibWeb/Layout/FormattingContext.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp index 603aa176eb..73cf46ab30 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -816,8 +816,14 @@ FormattingState::IntrinsicSizes FormattingContext::calculate_intrinsic_sizes(Lay VERIFY(independent_formatting_context); independent_formatting_context->run(box, LayoutMode::MaxContent); - cached_box_sizes.max_content_size.set_width(independent_formatting_context->greatest_child_width(box)); - cached_box_sizes.max_content_size.set_height(compute_intrinsic_height(throwaway_state, box)); + + if (independent_formatting_context->type() == FormattingContext::Type::Flex) { + auto const& box_state = throwaway_state.get(box); + cached_box_sizes.max_content_size = { box_state.content_width, box_state.content_height }; + } else { + cached_box_sizes.max_content_size.set_width(independent_formatting_context->greatest_child_width(box)); + cached_box_sizes.max_content_size.set_height(compute_intrinsic_height(throwaway_state, box)); + } } { @@ -828,8 +834,13 @@ FormattingState::IntrinsicSizes FormattingContext::calculate_intrinsic_sizes(Lay auto independent_formatting_context = const_cast(this)->create_independent_formatting_context_if_needed(throwaway_state, box); VERIFY(independent_formatting_context); independent_formatting_context->run(box, LayoutMode::MinContent); - cached_box_sizes.min_content_size.set_width(independent_formatting_context->greatest_child_width(box)); - cached_box_sizes.min_content_size.set_height(compute_intrinsic_height(throwaway_state, box)); + if (independent_formatting_context->type() == FormattingContext::Type::Flex) { + auto const& box_state = throwaway_state.get(box); + cached_box_sizes.min_content_size = { box_state.content_width, box_state.content_height }; + } else { + cached_box_sizes.min_content_size.set_width(independent_formatting_context->greatest_child_width(box)); + cached_box_sizes.min_content_size.set_height(compute_intrinsic_height(throwaway_state, box)); + } } if (cached_box_sizes.min_content_size.width() > cached_box_sizes.max_content_size.width()) {