1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 04:37:44 +00:00

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.
This commit is contained in:
Andreas Kling 2023-05-26 18:58:33 +02:00
parent 09eb3ef405
commit 299775345d

View file

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