From ca290b27eaadba2792585623ed8e24e2887d4485 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 27 Mar 2023 14:12:05 +0200 Subject: [PATCH] LibWeb: Make box content sizes indefinite before intrinsic sizing When calculating the intrinsic width of a box, we now make its content width & height indefinite before entering the intrinsic sizing layout. This ensures that any geometry assigned to the box by its parent formatting context is ignored. For intrinsic heights, we only make the content height indefinite. This is because used content width is a valid (but optional) input to intrinsic height calculation. --- Userland/Libraries/LibWeb/Layout/FormattingContext.cpp | 10 ++++++++++ Userland/Libraries/LibWeb/Layout/LayoutState.cpp | 10 ++++++++++ Userland/Libraries/LibWeb/Layout/LayoutState.h | 3 +++ 3 files changed, 23 insertions(+) diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp index 1c8bd84ecc..803b051940 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -1093,6 +1093,8 @@ 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, box); VERIFY(context); @@ -1127,6 +1129,8 @@ 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, box); VERIFY(context); @@ -1177,6 +1181,9 @@ CSSPixels FormattingContext::calculate_min_content_height(Layout::Box const& box auto& box_state = throwaway_state.get_mutable(box); box_state.height_constraint = SizeConstraint::MinContent; + box_state.set_indefinite_content_height(); + if (available_width.is_definite()) + 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); @@ -1222,6 +1229,9 @@ CSSPixels FormattingContext::calculate_max_content_height(Layout::Box const& box auto& box_state = throwaway_state.get_mutable(box); box_state.height_constraint = SizeConstraint::MaxContent; + box_state.set_indefinite_content_height(); + if (available_width.is_definite()) + 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); diff --git a/Userland/Libraries/LibWeb/Layout/LayoutState.cpp b/Userland/Libraries/LibWeb/Layout/LayoutState.cpp index 192fc16d15..fea8b5e26b 100644 --- a/Userland/Libraries/LibWeb/Layout/LayoutState.cpp +++ b/Userland/Libraries/LibWeb/Layout/LayoutState.cpp @@ -416,4 +416,14 @@ void LayoutState::UsedValues::set_content_y(CSSPixels y) offset.set_y(y); } +void LayoutState::UsedValues::set_indefinite_content_width() +{ + m_has_definite_width = false; +} + +void LayoutState::UsedValues::set_indefinite_content_height() +{ + m_has_definite_height = false; +} + } diff --git a/Userland/Libraries/LibWeb/Layout/LayoutState.h b/Userland/Libraries/LibWeb/Layout/LayoutState.h index 25d8257867..3d0e5e6c31 100644 --- a/Userland/Libraries/LibWeb/Layout/LayoutState.h +++ b/Userland/Libraries/LibWeb/Layout/LayoutState.h @@ -53,6 +53,9 @@ struct LayoutState { void set_content_width(CSSPixels); void set_content_height(CSSPixels); + void set_indefinite_content_width(); + void set_indefinite_content_height(); + // NOTE: These are used by FlexFormattingContext to assign a temporary main size to items // early on, so that descendants have something to resolve percentages against. void set_temporary_content_width(CSSPixels);