From 97154d9cf8a42564742eab9d0a8974766edd210f Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Tue, 26 Nov 2024 10:32:52 +1300 Subject: [PATCH] Avoid laying out grid items and generating fragments if only inline size is requested (#34352) * Layout: Short-circuit grid item layout if only inline size is requested Signed-off-by: Nico Burns * Layout: Avoid creating grid item fragments if only size is requested Signed-off-by: Nico Burns --------- Signed-off-by: Nico Burns --- components/layout_2020/taffy/layout.rs | 27 ++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/components/layout_2020/taffy/layout.rs b/components/layout_2020/taffy/layout.rs index e1d35380513..03c76b3bf85 100644 --- a/components/layout_2020/taffy/layout.rs +++ b/components/layout_2020/taffy/layout.rs @@ -10,7 +10,7 @@ use style::values::specified::align::AlignFlags; use style::values::specified::box_::DisplayInside; use style::Zero; use taffy::style_helpers::{TaffyMaxContent, TaffyMinContent}; -use taffy::{AvailableSpace, MaybeMath}; +use taffy::{AvailableSpace, MaybeMath, RequestedAxis, RunMode}; use super::{TaffyContainer, TaffyItemBox, TaffyItemBoxInner, TaffyStyloStyle}; use crate::cell::ArcRefCell; @@ -172,11 +172,15 @@ impl taffy::LayoutPartialTree for TaffyContainerContext<'_> { ) .to_physical_size(self.style.writing_mode); - child.child_fragments = replaced.contents.make_fragments( - &replaced.style, - containing_block, - content_box_size, - ); + // Create fragments if the RunMode if PerformLayout + // If the RunMode is ComputeSize then only the returned size will be used + if inputs.run_mode == RunMode::PerformLayout { + child.child_fragments = replaced.contents.make_fragments( + &replaced.style, + containing_block, + content_box_size, + ); + } let computed_size = taffy::Size { width: inputs.known_dimensions.width.unwrap_or_else(|| { @@ -236,6 +240,17 @@ impl taffy::LayoutPartialTree for TaffyContainerContext<'_> { resolve_content_size(adjusted_available_space, result.sizes) }); + // Return early if only inline content sizes are requested + if inputs.run_mode == RunMode::ComputeSize && + inputs.axis == RequestedAxis::Horizontal + { + return taffy::LayoutOutput::from_outer_size(taffy::Size { + width: inline_size + pbm.padding_border_sums.inline.to_f32_px(), + // If RequestedAxis is Horizontal then height will be ignored. + height: 0.0, + }); + } + let maybe_block_size = option_f32_to_lpa(content_box_known_dimensions.height); let content_box_size_override = ContainingBlock {