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

@ -459,9 +459,15 @@ impl HoistedAbsolutelyPositionedBox {
IndependentFormattingContext::Replaced(replaced) => {
// https://drafts.csswg.org/css2/visudet.html#abs-replaced-width
// https://drafts.csswg.org/css2/visudet.html#abs-replaced-height
let content_box_sizes_and_pbm =
style.content_box_sizes_and_padding_border_margin(&containing_block.into());
let used_size = replaced
.contents
.used_size_as_if_inline_element(containing_block, &style, &pbm)
.used_size_as_if_inline_element(
containing_block,
&style,
&content_box_sizes_and_pbm.into(),
)
.map(|size| Size::Numeric(*size));
(used_size, Default::default(), Default::default())
},
@ -477,7 +483,7 @@ impl HoistedAbsolutelyPositionedBox {
.static_position_rect
.to_logical(containing_block);
let box_offset = style.box_offsets(containing_block);
let box_offset = style.box_offsets(containing_block.style.writing_mode);
// When the "static-position rect" doesn't come into play, we do not do any alignment
// in the inline axis.
@ -982,7 +988,7 @@ pub(crate) fn relative_adjustement(
let cbis = containing_block.inline_size;
let cbbs = containing_block.block_size;
let box_offsets = style
.box_offsets(containing_block)
.box_offsets(containing_block.style.writing_mode)
.map_inline_and_block_axes(
|value| value.map(|value| value.to_used_value(cbis)),
|value| match cbbs.non_auto() {