From 5d27842b5dd18bf8c2b422dd30c39153afb61f5d Mon Sep 17 00:00:00 2001 From: Ting-Yu Lin Date: Tue, 5 Mar 2024 00:50:31 +0000 Subject: [PATCH] Bug 1881495 part 1: Add ShrinkWrap flag for grid items that are self-aligned (not stretched) in MeasuringReflow(). r=dholbert Bug 1350037 Part 3 [1] removed the code in ReflowInput that adds `ShrinkWrap` flag self-aligned grid items, to prevent the table-caption from getting aligned behavior, but it accidentally broke self-aligned behavior for other types of frames that are grid items. We actually already check if we need to add `ShrinkWrap` in grid item's final reflow [2], but we were missing the same logic in `MeasuringReflow()`. This patch adds that. [1] https://hg.mozilla.org/mozilla-central/rev/6e8085865f74 [2] https://searchfox.org/mozilla-central/rev/202c48686136360a23b73a49b611a19e64f3e1b8/layout/generic/nsGridContainerFrame.cpp#7651,7657 Differential Revision: https://phabricator.services.mozilla.com/D203514 --- layout/generic/nsGridContainerFrame.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/layout/generic/nsGridContainerFrame.cpp b/layout/generic/nsGridContainerFrame.cpp index 93685444cbb48..5eb9cde7da23a 100644 --- a/layout/generic/nsGridContainerFrame.cpp +++ b/layout/generic/nsGridContainerFrame.cpp @@ -5300,7 +5300,8 @@ static nscoord MeasuringReflow(nsIFrame* aChild, const LogicalSize& aCBSize, nscoord aIMinSizeClamp = NS_MAXSIZE, nscoord aBMinSizeClamp = NS_MAXSIZE) { - nsContainerFrame* parent = aChild->GetParent(); + MOZ_ASSERT(aChild->IsGridItem(), "aChild should be a grid item!"); + auto* parent = static_cast(aChild->GetParent()); nsPresContext* pc = aChild->PresContext(); Maybe dummyParentState; const ReflowInput* rs = aReflowInput; @@ -5319,6 +5320,11 @@ static nscoord MeasuringReflow(nsIFrame* aChild, #endif auto wm = aChild->GetWritingMode(); ComputeSizeFlags csFlags = ComputeSizeFlag::IsGridMeasuringReflow; + // Shrink-wrap grid items that will be aligned (rather than stretched) in + // their own inline axis. + if (!parent->GridItemShouldStretch(aChild, eLogicalAxisInline)) { + csFlags += ComputeSizeFlag::ShrinkWrap; + } if (aAvailableSize.ISize(wm) == INFINITE_ISIZE_COORD) { csFlags += ComputeSizeFlag::ShrinkWrap; }