Jelajahi Sumber

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.
Andreas Kling 2 tahun lalu
induk
melakukan
299775345d
1 mengubah file dengan 12 tambahan dan 4 penghapusan
  1. 12 4
      Userland/Libraries/LibWeb/Layout/FormattingContext.cpp

+ 12 - 4
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<FormattingContext*>(this)->create_independent_formatting_context_if_needed(throwaway_state, box);
-    VERIFY(context);
+    if (!context) {
+        context = make<BlockFormattingContext>(throwaway_state, verify_cast<BlockContainer>(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<FormattingContext*>(this)->create_independent_formatting_context_if_needed(throwaway_state, box);
-    VERIFY(context);
+    if (!context) {
+        context = make<BlockFormattingContext>(throwaway_state, verify_cast<BlockContainer>(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<FormattingContext*>(this)->create_independent_formatting_context_if_needed(throwaway_state, box);
-    VERIFY(context);
+    if (!context) {
+        context = make<BlockFormattingContext>(throwaway_state, verify_cast<BlockContainer>(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<FormattingContext*>(this)->create_independent_formatting_context_if_needed(throwaway_state, box);
-    VERIFY(context);
+    if (!context) {
+        context = make<BlockFormattingContext>(throwaway_state, verify_cast<BlockContainer>(box), nullptr);
+    }
 
     context->run(box, LayoutMode::IntrinsicSizing, AvailableSpace(available_width, AvailableSize::make_max_content()));