diff options
author | Andreas Kling <kling@serenityos.org> | 2023-03-27 14:12:05 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-03-27 23:28:07 +0200 |
commit | ca290b27eaadba2792585623ed8e24e2887d4485 (patch) | |
tree | d52cb33f6279c48b8e2efad4babc40a59c701580 /Userland/Libraries/LibWeb/Layout | |
parent | 7639eccd53327e93b2055433cdb2e3a7a49e463e (diff) | |
download | serenity-ca290b27eaadba2792585623ed8e24e2887d4485.zip |
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.
Diffstat (limited to 'Userland/Libraries/LibWeb/Layout')
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/FormattingContext.cpp | 10 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/LayoutState.cpp | 10 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/LayoutState.h | 3 |
3 files changed, 23 insertions, 0 deletions
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<FormattingContext*>(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<FormattingContext*>(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<FormattingContext*>(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<FormattingContext*>(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); |