Bug 1425599 part 4 - [css-grid] Factor out the starting base/limit size to a templated method (idempotent change). r=dholbert a=jcristau
authorMats Palmgren <mats@mozilla.com>
Thu, 15 Mar 2018 22:41:24 +0100
changeset 462718 a2d9cdb47e6257ac02696f6ce0a9432c6c485c39
parent 462717 2405110bef04d0ba709c8e96a2a6d890986a1293
child 462719 7a68f2b6d545736d3ac78a17dca935c227de6709
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert, jcristau
bugs1425599
milestone60.0
Bug 1425599 part 4 - [css-grid] Factor out the starting base/limit size to a templated method (idempotent change). r=dholbert a=jcristau
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<TrackSizingPhase phase> 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<TrackSize>& aPlan,
-                     const nsTArray<TrackSize>& aSizes) const
+  template<TrackSizingPhase phase>
+  void InitializePlan(nsTArray<TrackSize>& 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<phase>(sz);
+      plan.mState = sz.mState;
     }
   }
 
   void CopyPlanToBase(const nsTArray<TrackSize>& 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<uint32_t>& aTracks,
   nsTArray<TrackSize>& aPlan,
   nsTArray<TrackSize>& aItemPlan,
   TrackSize::StateBits aSelector,
   uint32_t aStartIndex,
   uint32_t aEndIndex)
 {
   bool updatedBase = false;
-  ResetBasePlan(aPlan, mSizes);
+  InitializePlan<phase>(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<TrackSize>& aPlan,
   nsTArray<TrackSize>& aItemPlan,
   TrackSize::StateBits aSelector,
   const TrackSizingFunctions& aFunctions,
   nscoord aPercentageBasis,
   uint32_t aStartIndex,
   uint32_t aEndIndex)
 {
-  ResetBasePlan(aPlan, aSizes);
+  InitializePlan<phase>(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;
     }