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 <nico@nicoburns.com>

* Layout: Avoid creating grid item fragments if only size is requested

Signed-off-by: Nico Burns <nico@nicoburns.com>

---------

Signed-off-by: Nico Burns <nico@nicoburns.com>
This commit is contained in:
Nico Burns 2024-11-26 10:32:52 +13:00 committed by GitHub
parent fdaf44bbc0
commit 97154d9cf8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -10,7 +10,7 @@ use style::values::specified::align::AlignFlags;
use style::values::specified::box_::DisplayInside; use style::values::specified::box_::DisplayInside;
use style::Zero; use style::Zero;
use taffy::style_helpers::{TaffyMaxContent, TaffyMinContent}; use taffy::style_helpers::{TaffyMaxContent, TaffyMinContent};
use taffy::{AvailableSpace, MaybeMath}; use taffy::{AvailableSpace, MaybeMath, RequestedAxis, RunMode};
use super::{TaffyContainer, TaffyItemBox, TaffyItemBoxInner, TaffyStyloStyle}; use super::{TaffyContainer, TaffyItemBox, TaffyItemBoxInner, TaffyStyloStyle};
use crate::cell::ArcRefCell; use crate::cell::ArcRefCell;
@ -172,11 +172,15 @@ impl taffy::LayoutPartialTree for TaffyContainerContext<'_> {
) )
.to_physical_size(self.style.writing_mode); .to_physical_size(self.style.writing_mode);
child.child_fragments = replaced.contents.make_fragments( // Create fragments if the RunMode if PerformLayout
&replaced.style, // If the RunMode is ComputeSize then only the returned size will be used
containing_block, if inputs.run_mode == RunMode::PerformLayout {
content_box_size, child.child_fragments = replaced.contents.make_fragments(
); &replaced.style,
containing_block,
content_box_size,
);
}
let computed_size = taffy::Size { let computed_size = taffy::Size {
width: inputs.known_dimensions.width.unwrap_or_else(|| { 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) 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 = let maybe_block_size =
option_f32_to_lpa(content_box_known_dimensions.height); option_f32_to_lpa(content_box_known_dimensions.height);
let content_box_size_override = ContainingBlock { let content_box_size_override = ContainingBlock {