# HG changeset patch # User Mats Palmgren # Date 1521150084 -3600 # Thu Mar 15 22:41:24 2018 +0100 # Node ID a21fbd58159b85e2e2be7aa41b203c7df872c9a3 # Parent 035a8f610e64654ccfaa978cb40aacc6ceb695d9 Bug 1425599 part 4 - [css-grid] Factor out the starting base/limit size to a templated method (idempotent change). r=dholbert diff --git a/layout/generic/nsGridContainerFrame.cpp b/layout/generic/nsGridContainerFrame.cpp --- a/layout/generic/nsGridContainerFrame.cpp +++ b/layout/generic/nsGridContainerFrame.cpp @@ -1216,16 +1216,36 @@ struct nsGridContainerFrame::Tracks * max-sizing function, false otherwise. */ bool ResolveIntrinsicSizeStep1(GridReflowInput& aState, const TrackSizingFunctions& aFunctions, nscoord aPercentageBasis, SizingConstraint aConstraint, const LineRange& aRange, const GridItemInfo& aGridItem); + + // Helper method that returns the track size to use in ยง11.5.1.2 + // https://drafts.csswg.org/css-grid/#extra-space + template static + nscoord StartSizeInDistribution(const TrackSize& aSize) + { + switch (phase) { + case TrackSizingPhase::eIntrinsicMinimums: + case TrackSizingPhase::eContentBasedMinimums: + case TrackSizingPhase::eMaxContentMinimums: + return aSize.mBase; + case TrackSizingPhase::eIntrinsicMaximums: + case TrackSizingPhase::eMaxContentMaximums: + if (aSize.mLimit == NS_UNCONSTRAINEDSIZE) { + return aSize.mBase; + } + return aSize.mLimit; + } + } + /** * Collect the tracks which are growable (matching aSelector) into * aGrowableTracks, and return the amount of space that can be used * to grow those tracks. Specifically, we return aAvailableSpace minus * the sum of mBase's (and corresponding grid gaps) in aPlan (clamped to 0) * for the tracks in aRange, or zero when there are no growable tracks. * @note aPlan[*].mBase represents a planned new base or limit. */ @@ -1259,22 +1279,24 @@ struct nsGridContainerFrame::Tracks for (uint32_t track : aTracks) { auto& sz = aItemPlan[track]; sz.mBase = aSizes[track].mBase; sz.mLimit = aSizes[track].mLimit; sz.mState = aSizes[track].mState; } } - void ResetBasePlan(nsTArray& aPlan, - const nsTArray& aSizes) const + template + void InitializePlan(nsTArray& aPlan) const { - for (size_t i = 0, len = mSizes.Length(); i < len; ++i) { - aPlan[i].mBase = aSizes[i].mBase; - aPlan[i].mState = aSizes[i].mState; + for (size_t i = 0, len = aPlan.Length(); i < len; ++i) { + auto& plan = aPlan[i]; + const auto& sz = mSizes[i]; + plan.mBase = StartSizeInDistribution(sz); + plan.mState = sz.mState; } } void CopyPlanToBase(const nsTArray& aPlan) { for (size_t i = 0, len = mSizes.Length(); i < len; ++i) { mSizes[i].mBase = aPlan[i].mBase; } @@ -4230,17 +4252,17 @@ nsGridContainerFrame::Tracks::GrowBaseFo nsTArray& aTracks, nsTArray& aPlan, nsTArray& aItemPlan, TrackSize::StateBits aSelector, uint32_t aStartIndex, uint32_t aEndIndex) { bool updatedBase = false; - ResetBasePlan(aPlan, mSizes); + InitializePlan(aPlan); for (uint32_t i = aStartIndex; i < aEndIndex; ++i) { const Step2ItemData& item = aItemData[i]; if (!(item.mState & aSelector)) { continue; } nscoord space = item.SizeContributionForPhase(phase); if (space <= 0) { continue; @@ -4268,17 +4290,17 @@ nsGridContainerFrame::Tracks::GrowLimitF nsTArray& aPlan, nsTArray& aItemPlan, TrackSize::StateBits aSelector, const TrackSizingFunctions& aFunctions, nscoord aPercentageBasis, uint32_t aStartIndex, uint32_t aEndIndex) { - ResetBasePlan(aPlan, aSizes); + InitializePlan(aPlan); for (uint32_t i = aStartIndex; i < aEndIndex; ++i) { const Step2ItemData& item = aItemData[i]; if (!(item.mState & aSelector)) { continue; } for (auto j = item.mLineRange.mStart, end = item.mLineRange.mEnd; j < end; ++j) { aPlan[j].mState |= TrackSize::eModified; }