From 299775345d24633fc4b7bcea27ce6751df5f80ed Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 26 May 2023 18:58:33 +0200 Subject: [PATCH] LibWeb: Allow calculating intrinsic sizes of non-FC-roots In order to support intrinsic size keywords (such as fit-content), we need to be able to calculate the intrinsic sizes of any element, not just those that form their own formatting context. When a non-FC-root element is passed to calculate_some_intrinsic_size(), we now create a synthetic BFC to handle sizing of them. --- .../LibWeb/Layout/FormattingContext.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp index f05884f469..638300eb23 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -1169,7 +1169,9 @@ CSSPixels FormattingContext::calculate_min_content_width(Layout::Box const& box) box_state.set_indefinite_content_height(); auto context = const_cast(this)->create_independent_formatting_context_if_needed(throwaway_state, box); - VERIFY(context); + if (!context) { + context = make(throwaway_state, verify_cast(box), nullptr); + } auto available_width = AvailableSize::make_min_content(); auto available_height = AvailableSize::make_indefinite(); @@ -1205,7 +1207,9 @@ CSSPixels FormattingContext::calculate_max_content_width(Layout::Box const& box) box_state.set_indefinite_content_height(); auto context = const_cast(this)->create_independent_formatting_context_if_needed(throwaway_state, box); - VERIFY(context); + if (!context) { + context = make(throwaway_state, verify_cast(box), nullptr); + } auto available_width = AvailableSize::make_max_content(); auto available_height = AvailableSize::make_indefinite(); @@ -1260,7 +1264,9 @@ CSSPixels FormattingContext::calculate_min_content_height(Layout::Box const& box box_state.set_content_width(available_width.to_px()); auto context = const_cast(this)->create_independent_formatting_context_if_needed(throwaway_state, box); - VERIFY(context); + if (!context) { + context = make(throwaway_state, verify_cast(box), nullptr); + } context->run(box, LayoutMode::IntrinsicSizing, AvailableSpace(available_width, AvailableSize::make_min_content())); @@ -1313,7 +1319,9 @@ CSSPixels FormattingContext::calculate_max_content_height(Layout::Box const& box box_state.set_content_width(available_width.to_px()); auto context = const_cast(this)->create_independent_formatting_context_if_needed(throwaway_state, box); - VERIFY(context); + if (!context) { + context = make(throwaway_state, verify_cast(box), nullptr); + } context->run(box, LayoutMode::IntrinsicSizing, AvailableSpace(available_width, AvailableSize::make_max_content()));