diff options
author | Martin Robinson <mrobinson@igalia.com> | 2024-10-24 10:44:30 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-24 17:44:30 +0000 |
commit | 52db185568ca4dc49d28211f70b29aedecffaaf0 (patch) | |
tree | 4be1e80182425b3fa51e7d440a40dc6f59ca152d /components/layout_2020/flow/inline | |
parent | 638b520186f30d66fefa5a687799093dec071306 (diff) | |
download | servo-52db185568ca4dc49d28211f70b29aedecffaaf0.tar.gz servo-52db185568ca4dc49d28211f70b29aedecffaaf0.zip |
layout: Avoid layout sometimes when stretching (#33967)
This is the second flexbox caching change. It seeks to detect when a
relayout can be avoided in the case of a stretching flex item. This
heuristic can be combined, because currently we still do relayout
sometimes when we do not need to.
For instance currently we always relayout when a flex child is itself a
column flex. This only needs to happen when the grandchildren themselves
grow or shrink. That optimization is perhaps a lower priority as
`flex-grow: 0 / flex-shrink: 1` is the default behavior for flex.
Since this change means we more consistenly zero out the percentage part
of `calc` expressions when they have circular dependencies, this causes one
test to start failing (`/css/css-values/calc-min-height-block-1.html`).
This is related to w3c/csswg-drafts#10969, which is pending on further
discussion in the working group.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
Diffstat (limited to 'components/layout_2020/flow/inline')
-rw-r--r-- | components/layout_2020/flow/inline/mod.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/components/layout_2020/flow/inline/mod.rs b/components/layout_2020/flow/inline/mod.rs index 4bad4293e5a..73c678e0458 100644 --- a/components/layout_2020/flow/inline/mod.rs +++ b/components/layout_2020/flow/inline/mod.rs @@ -627,6 +627,10 @@ pub(super) struct InlineFormattingContextLayout<'layout_data> { /// Whether or not this InlineFormattingContext has processed any in flow content at all. had_inflow_content: bool, + /// Whether or not the layout of this InlineFormattingContext depends on the block size + /// of its container for the purposes of flexbox layout. + depends_on_block_constraints: bool, + /// The currently white-space-collapse setting of this line. This is stored on the /// [`InlineFormattingContextLayout`] because when a soft wrap opportunity is defined /// by the boundary between two characters, the white-space-collapse property of their @@ -701,6 +705,12 @@ impl<'layout_dta> InlineFormattingContextLayout<'layout_dta> { .map(|index| &self.ifc.font_metrics[index].metrics), ); + self.depends_on_block_constraints |= inline_box + .style + .depends_on_block_constraints_due_to_relative_positioning( + self.containing_block.style.writing_mode, + ); + // If we are starting a `<br>` element prepare to clear after its deferred linebreak has been // processed. Note that a `<br>` is composed of the element itself and the inner pseudo-element // with the actual linebreak. Both will have this `FragmentFlag`; that's why this code only @@ -1631,6 +1641,7 @@ impl InlineFormattingContext { deferred_br_clear: Clear::None, have_deferred_soft_wrap_opportunity: false, had_inflow_content: false, + depends_on_block_constraints: false, white_space_collapse: style_text.white_space_collapse, text_wrap_mode: style_text.text_wrap_mode, baselines: Baselines::default(), @@ -1692,6 +1703,7 @@ impl InlineFormattingContext { content_block_size, collapsible_margins_in_children, baselines: layout.baselines, + depends_on_block_constraints: layout.depends_on_block_constraints, } } @@ -1921,6 +1933,12 @@ impl IndependentFormattingContext { layout.containing_block, ); + // If this Fragment's layout depends on the block size of the containing block, + // then the entire layout of the inline formatting context does as well. + layout.depends_on_block_constraints |= fragment.base.flags.contains( + FragmentFlags::SIZE_DEPENDS_ON_BLOCK_CONSTRAINTS_AND_CAN_BE_CHILD_OF_FLEX_ITEM, + ); + // Offset the content rectangle by the physical offset of the padding, border, and margin. let container_writing_mode = layout.containing_block.style.writing_mode; let pbm_physical_offset = pbm_sums |