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>
This commit is contained in:
Martin Robinson 2024-10-24 10:44:30 -07:00 committed by GitHub
parent 638b520186
commit 52db185568
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 490 additions and 257 deletions

View file

@ -117,7 +117,7 @@ pub(crate) enum FlexLevelBox {
pub(crate) struct FlexItemBox {
independent_formatting_context: IndependentFormattingContext,
#[serde(skip)]
cached_layout: ArcRefCell<Option<FlexItemLayoutCache>>,
block_content_size_cache: ArcRefCell<Option<CachedBlockSizeContribution>>,
}
impl std::fmt::Debug for FlexItemBox {
@ -136,19 +136,7 @@ impl FlexItemBox {
}
}
#[derive(Debug)]
struct FlexItemLayoutCacheDescriptor {
struct CachedBlockSizeContribution {
containing_block_inline_size: Au,
content_block_size: Au,
}
impl FlexItemLayoutCacheDescriptor {
fn compatible_with_size(&self, inline: Au) -> bool {
inline == self.containing_block_inline_size
}
}
/// A cache to avoid multiple layouts during flexbox layout.
struct FlexItemLayoutCache {
descriptor: FlexItemLayoutCacheDescriptor,
}