Skip to content

Commit e06a462

Browse files
author
Mats Palmgren
committed
Bug 1427608 - [css-grid] Fix span=1 'auto' min-sizing for intrinsic sizing. r=dholbert
When sizing the container under a min- or max-content constraint, the item's min/max-content contribution needs to be clamped (when Automatic Minimum Size / clamping applies) if its size is 'auto'. That'll give the container the right intrinsic size. In Reflow, we'll size the track initially to the clamped min-content contribution again (in the Resolve Intrinsic Track Sizes step), but since the container now has a definite size we'll grow the track in the Maximize Tracks step up to its limit (i.e. the clamp size). For more details on the underlying issue, see: w3c/csswg-drafts#2303
1 parent 0a3df95 commit e06a462

File tree

2 files changed

+41
-47
lines changed

2 files changed

+41
-47
lines changed

layout/base/nsLayoutUtils.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5520,22 +5520,11 @@ nsLayoutUtils::IntrinsicForAxis(PhysicalAxis aAxis,
55205520
// For -moz-max-content and -moz-min-content, we handle them like
55215521
// specified widths, but ignore box-sizing.
55225522
boxSizing = StyleBoxSizing::Content;
5523-
if (aMarginBoxMinSizeClamp != NS_MAXSIZE &&
5524-
styleISize.GetIntValue() == NS_STYLE_WIDTH_MIN_CONTENT) {
5525-
// We need |result| to be the 'min-content size' for the clamping below.
5526-
result = aFrame->GetMinISize(aRenderingContext);
5527-
}
55285523
} else if (!styleISize.ConvertsToLength() &&
55295524
!(haveFixedMinISize && haveFixedMaxISize && maxISize <= minISize)) {
55305525
#ifdef DEBUG_INTRINSIC_WIDTH
55315526
++gNoiseIndent;
55325527
#endif
5533-
if (aType != MIN_ISIZE) {
5534-
// At this point, |styleISize| is auto/-moz-fit-content/-moz-available or
5535-
// has a percentage. The intrinisic size for those under a max-content
5536-
// constraint is the max-content contribution which we shouldn't clamp.
5537-
aMarginBoxMinSizeClamp = NS_MAXSIZE;
5538-
}
55395528
if (MOZ_UNLIKELY(!isInlineAxis)) {
55405529
IntrinsicSize intrinsicSize = aFrame->GetIntrinsicSize();
55415530
const nsStyleCoord intrinsicBCoord =

layout/generic/nsGridContainerFrame.cpp

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -614,22 +614,22 @@ struct nsGridContainerFrame::GridItemInfo
614614
LogicalAxis aContainerAxis,
615615
nscoord aPercentageBasis) const
616616
{
617-
const auto pos = mFrame->StylePosition();
617+
const auto* pos = mFrame->IsTableWrapperFrame() ?
618+
mFrame->PrincipalChildList().FirstChild()->StylePosition() :
619+
mFrame->StylePosition();
618620
const auto& size = aContainerAxis == eLogicalAxisInline ?
619621
pos->ISize(aContainerWM) : pos->BSize(aContainerWM);
620-
// NOTE: if we have a definite or 'max-content' size then our automatic
621-
// minimum size can't affect our size. Excluding these simplifies applying
622+
// NOTE: if we have a definite size then our automatic minimum size
623+
// can't affect our size. Excluding these simplifies applying
622624
// the clamping in the right cases later.
623-
if (size.GetUnit() == eStyleUnit_Auto ||
624-
::IsPercentOfIndefiniteSize(size, aPercentageBasis) || // same as 'auto'
625-
(size.GetUnit() == eStyleUnit_Enumerated &&
626-
size.GetIntValue() != NS_STYLE_WIDTH_MAX_CONTENT)) {
627-
const auto& minSize = aContainerAxis == eLogicalAxisInline ?
628-
pos->MinISize(aContainerWM) : pos->MinBSize(aContainerWM);
629-
return minSize.GetUnit() == eStyleUnit_Auto &&
630-
mFrame->StyleDisplay()->mOverflowX == NS_STYLE_OVERFLOW_VISIBLE;
625+
if (size.GetUnit() != eStyleUnit_Auto &&
626+
!::IsPercentOfIndefiniteSize(size, aPercentageBasis)) {
627+
return false;
631628
}
632-
return false;
629+
const auto& minSize = aContainerAxis == eLogicalAxisInline ?
630+
pos->MinISize(aContainerWM) : pos->MinBSize(aContainerWM);
631+
return minSize.GetUnit() == eStyleUnit_Auto &&
632+
mFrame->StyleDisplay()->mOverflowX == NS_STYLE_OVERFLOW_VISIBLE;
633633
}
634634

635635
#ifdef DEBUG
@@ -3779,33 +3779,25 @@ nsGridContainerFrame::Tracks::ResolveIntrinsicSizeStep1(
37793779
TrackSize& sz = mSizes[aRange.mStart];
37803780
WritingMode wm = aState.mWM;
37813781

3782-
// Check if we need to apply "Automatic Minimum Size" and cache it.
3783-
if ((sz.mState & TrackSize::eAutoMinSizing) &&
3784-
aGridItem.ShouldApplyAutoMinSize(wm, mAxis, aPercentageBasis)) {
3785-
aGridItem.mState[mAxis] |= ItemState::eApplyAutoMinSize;
3786-
}
3787-
3788-
// Calculate data for "Automatic Minimum Size" clamping, if needed.
3789-
bool needed = ((sz.mState & TrackSize::eIntrinsicMinSizing) ||
3790-
aConstraint == SizingConstraint::eNoConstraint) &&
3791-
(aGridItem.mState[mAxis] & ItemState::eApplyAutoMinSize);
3792-
if (needed && TrackSize::IsDefiniteMaxSizing(sz.mState)) {
3793-
if (sz.mState & TrackSize::eIntrinsicMinSizing) {
3794-
auto maxCoord = aFunctions.MaxSizingFor(aRange.mStart);
3795-
cache.mMinSizeClamp = maxCoord.ComputeCoordPercentCalc(aPercentageBasis);
3796-
}
3797-
aGridItem.mState[mAxis] |= ItemState::eClampMarginBoxMinSize;
3798-
}
37993782
// min sizing
38003783
gfxContext* rc = &aState.mRenderingContext;
38013784
if (sz.mState & TrackSize::eAutoMinSizing) {
38023785
nscoord s;
3803-
if (aConstraint == SizingConstraint::eMinContent) {
3804-
s = MinContentContribution(aGridItem, aState, rc, wm, mAxis, &cache);
3805-
} else if (aConstraint == SizingConstraint::eMaxContent) {
3806-
s = MaxContentContribution(aGridItem, aState, rc, wm, mAxis, &cache);
3786+
// Check if we need to apply "Automatic Minimum Size" and cache it.
3787+
if (aGridItem.ShouldApplyAutoMinSize(wm, mAxis, aPercentageBasis)) {
3788+
aGridItem.mState[mAxis] |= ItemState::eApplyAutoMinSize;
3789+
// Clamp it if it's spanning a definite track max-sizing function.
3790+
if (TrackSize::IsDefiniteMaxSizing(sz.mState)) {
3791+
auto maxCoord = aFunctions.MaxSizingFor(aRange.mStart);
3792+
cache.mMinSizeClamp = maxCoord.ComputeCoordPercentCalc(aPercentageBasis);
3793+
aGridItem.mState[mAxis] |= ItemState::eClampMarginBoxMinSize;
3794+
}
3795+
if (aConstraint != SizingConstraint::eMaxContent) {
3796+
s = MinContentContribution(aGridItem, aState, rc, wm, mAxis, &cache);
3797+
} else {
3798+
s = MaxContentContribution(aGridItem, aState, rc, wm, mAxis, &cache);
3799+
}
38073800
} else {
3808-
MOZ_ASSERT(aConstraint == SizingConstraint::eNoConstraint);
38093801
s = MinSize(aGridItem, aState, rc, wm, mAxis, &cache);
38103802
}
38113803
sz.mBase = std::max(sz.mBase, s);
@@ -5073,18 +5065,31 @@ nsGridContainerFrame::ReflowInFlowChild(nsIFrame* aChild,
50735065
// Setup the ClampMarginBoxMinSize reflow flags and property, if needed.
50745066
uint32_t flags = 0;
50755067
if (aGridItemInfo) {
5068+
// Clamp during reflow if we're stretching in that axis.
5069+
auto* pos = aChild->StylePosition();
5070+
auto j = pos->UsedJustifySelf(StyleContext());
5071+
auto a = pos->UsedAlignSelf(StyleContext());
5072+
bool stretch[2];
5073+
stretch[eLogicalAxisInline] = j == NS_STYLE_JUSTIFY_NORMAL ||
5074+
j == NS_STYLE_JUSTIFY_STRETCH;
5075+
stretch[eLogicalAxisBlock] = a == NS_STYLE_ALIGN_NORMAL ||
5076+
a == NS_STYLE_ALIGN_STRETCH;
50765077
auto childIAxis = isOrthogonal ? eLogicalAxisBlock : eLogicalAxisInline;
5077-
if (aGridItemInfo->mState[childIAxis] & ItemState::eClampMarginBoxMinSize) {
5078+
if (stretch[childIAxis] &&
5079+
aGridItemInfo->mState[childIAxis] & ItemState::eClampMarginBoxMinSize) {
50785080
flags |= ReflowInput::I_CLAMP_MARGIN_BOX_MIN_SIZE;
50795081
}
5082+
50805083
auto childBAxis = GetOrthogonalAxis(childIAxis);
5081-
if (aGridItemInfo->mState[childBAxis] & ItemState::eClampMarginBoxMinSize) {
5084+
if (stretch[childBAxis] &&
5085+
aGridItemInfo->mState[childBAxis] & ItemState::eClampMarginBoxMinSize) {
50825086
flags |= ReflowInput::B_CLAMP_MARGIN_BOX_MIN_SIZE;
50835087
aChild->SetProperty(BClampMarginBoxMinSizeProperty(),
50845088
childCBSize.BSize(childWM));
50855089
} else {
50865090
aChild->DeleteProperty(BClampMarginBoxMinSizeProperty());
50875091
}
5092+
50885093
if ((aGridItemInfo->mState[childIAxis] & ItemState::eApplyAutoMinSize)) {
50895094
flags |= ReflowInput::I_APPLY_AUTO_MIN_SIZE;
50905095
}

0 commit comments

Comments
 (0)