From 244d4e19fa65434d3ffb334beb35a349d99b8ad7 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 7 Jan 2023 17:43:34 +0100 Subject: [PATCH] LibWeb: Run more of flex layout algorithm for intrinsic sizing We were trying to take a shortcut by avoiding much of the flex layout algorithm during intrinsic sizing. Unfortunately, this isn't good enough since we may end up needing some of the flex item metrics for intrinsic contribution calculations. This means we do a bit more work for flexboxes, but intrinsic sizes are correct in more cases. --- .../LibWeb/Layout/FlexFormattingContext.cpp | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp index bf4294ab1c..9456a444dc 100644 --- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp @@ -142,18 +142,13 @@ void FlexFormattingContext::run(Box const& run_box, LayoutMode, AvailableSpace c } if (available_width.is_intrinsic_sizing_constraint() || available_height.is_intrinsic_sizing_constraint()) { - // We're computing intrinsic size for the flex container. - determine_intrinsic_size_of_flex_container(); + // We're computing intrinsic size for the flex container. This happens at the end of run(). + } else { - // Our caller is only interested in the content-width and content-height results, - // which have now been set on m_flex_container_state, so there's no need to continue - // the main layout algorithm after this point. - return; + // 4. Determine the main size of the flex container + determine_main_size_of_flex_container(); } - // 4. Determine the main size of the flex container - determine_main_size_of_flex_container(); - // 5. Collect flex items into flex lines: // After this step no additional items are to be added to flex_lines or any of its items! collect_flex_items_into_flex_lines(); @@ -231,6 +226,15 @@ void FlexFormattingContext::run(Box const& run_box, LayoutMode, AvailableSpace c // part of the spec, and simply covering up the fact that our inside layout currently // mutates the height of BFC roots. copy_dimensions_from_flex_items_to_boxes(); + + if (available_width.is_intrinsic_sizing_constraint() || available_height.is_intrinsic_sizing_constraint()) { + // We're computing intrinsic size for the flex container. + determine_intrinsic_size_of_flex_container(); + + // Our caller is only interested in the content-width and content-height results, + // which have now been set on m_flex_container_state, so there's no need to continue + // the main layout algorithm after this point. + } } void FlexFormattingContext::parent_context_did_dimension_child_root_box()