From 077bc68a4cbf2d8c97abc818515a22471da42c99 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 5 Oct 2024 18:47:47 +0200 Subject: [PATCH] LibWeb: Allow intrinsic width layout to see definite heights We were already allowing intrinsic height layout to see definite widths, and I can't think of a reason *not* to allow it the other way around. More importantly, this fixes an issue where things with an aspect ratio didn't have a height to resolve against before. Makes the logo show up on https://basecamp.com/ :^) --- ...efinite-height-and-item-that-has-aspect-ratio.txt | 11 +++++++++++ ...finite-height-and-item-that-has-aspect-ratio.html | 8 ++++++++ .../Libraries/LibWeb/Layout/FormattingContext.cpp | 12 ++++++++---- 3 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 Tests/LibWeb/Layout/expected/flex-container-max-content-width-with-definite-height-and-item-that-has-aspect-ratio.txt create mode 100644 Tests/LibWeb/Layout/input/flex-container-max-content-width-with-definite-height-and-item-that-has-aspect-ratio.html diff --git a/Tests/LibWeb/Layout/expected/flex-container-max-content-width-with-definite-height-and-item-that-has-aspect-ratio.txt b/Tests/LibWeb/Layout/expected/flex-container-max-content-width-with-definite-height-and-item-that-has-aspect-ratio.txt new file mode 100644 index 00000000000..58662bc1119 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/flex-container-max-content-width-with-definite-height-and-item-that-has-aspect-ratio.txt @@ -0,0 +1,11 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x116 [BFC] children: not-inline + Box at (8,8) content-size 100x100 flex-container(row) [FFC] children: not-inline + SVGSVGBox at (8,8) content-size 100x100 flex-item [SVG] children: not-inline + SVGGeometryBox at (8,8) content-size 100x100 children: not-inline + +ViewportPaintable (Viewport<#document>) [0,0 800x600] + PaintableWithLines (BlockContainer) [0,0 800x116] + PaintableBox (Box) [8,8 100x100] + SVGSVGPaintable (SVGSVGBox) [8,8 100x100] + SVGPathPaintable (SVGGeometryBox) [8,8 100x100] diff --git a/Tests/LibWeb/Layout/input/flex-container-max-content-width-with-definite-height-and-item-that-has-aspect-ratio.html b/Tests/LibWeb/Layout/input/flex-container-max-content-width-with-definite-height-and-item-that-has-aspect-ratio.html new file mode 100644 index 00000000000..5f105114016 --- /dev/null +++ b/Tests/LibWeb/Layout/input/flex-container-max-content-width-with-definite-height-and-item-that-has-aspect-ratio.html @@ -0,0 +1,8 @@ + \ No newline at end of file diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp index a2cdb4cccf6..65eee891d26 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -1465,7 +1465,6 @@ CSSPixels FormattingContext::calculate_min_content_width(Layout::Box const& box) auto& box_state = throwaway_state.get_mutable(box); box_state.width_constraint = SizeConstraint::MinContent; box_state.set_indefinite_content_width(); - box_state.set_indefinite_content_height(); auto context = const_cast(this)->create_independent_formatting_context_if_needed(throwaway_state, LayoutMode::IntrinsicSizing, box); if (!context) { @@ -1473,7 +1472,10 @@ CSSPixels FormattingContext::calculate_min_content_width(Layout::Box const& box) } auto available_width = AvailableSize::make_min_content(); - auto available_height = AvailableSize::make_indefinite(); + auto available_height = box_state.has_definite_height() + ? AvailableSize::make_definite(box_state.content_height()) + : AvailableSize::make_indefinite(); + context->run(AvailableSpace(available_width, available_height)); cache.min_content_width = context->automatic_content_width(); @@ -1503,7 +1505,6 @@ CSSPixels FormattingContext::calculate_max_content_width(Layout::Box const& box) auto& box_state = throwaway_state.get_mutable(box); box_state.width_constraint = SizeConstraint::MaxContent; box_state.set_indefinite_content_width(); - box_state.set_indefinite_content_height(); auto context = const_cast(this)->create_independent_formatting_context_if_needed(throwaway_state, LayoutMode::IntrinsicSizing, box); if (!context) { @@ -1511,7 +1512,10 @@ CSSPixels FormattingContext::calculate_max_content_width(Layout::Box const& box) } auto available_width = AvailableSize::make_max_content(); - auto available_height = AvailableSize::make_indefinite(); + auto available_height = box_state.has_definite_height() + ? AvailableSize::make_definite(box_state.content_height()) + : AvailableSize::make_indefinite(); + context->run(AvailableSpace(available_width, available_height)); cache.max_content_width = context->automatic_content_width();