aboutsummaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorNico Burns <nico@nicoburns.com>2024-11-26 10:32:52 +1300
committerGitHub <noreply@github.com>2024-11-25 21:32:52 +0000
commit97154d9cf8a42564742eab9d0a8974766edd210f (patch)
treec056c7c9079b2d5e6cd2b54a61b42357f22dd41f /components
parentfdaf44bbc0e12703490ff4f621ca983b14859418 (diff)
downloadservo-97154d9cf8a42564742eab9d0a8974766edd210f.tar.gz
servo-97154d9cf8a42564742eab9d0a8974766edd210f.zip
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>
Diffstat (limited to 'components')
-rw-r--r--components/layout_2020/taffy/layout.rs27
1 files 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 {