Bug 1174574 part 1 - [css-grid] Move the guts of nsGridContainerFrame::CalculateTrackSizes into a Tracks method. r=dholbert
authorMats Palmgren <mats@mozilla.com>
Fri, 04 Sep 2015 22:06:57 +0200
changeset 261122 cf5ad7ef6a431e1dac70e0e3b0fb302708e69b3b
parent 261121 71aea85370eb0e201273883b71755851e604751b
child 261123 bacad119cc26f53894d092bdd32f95a88ab70308
push id29336
push usercbook@mozilla.com
push dateMon, 07 Sep 2015 10:01:38 +0000
treeherdermozilla-central@5fe9ed3edd68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1174574
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1174574 part 1 - [css-grid] Move the guts of nsGridContainerFrame::CalculateTrackSizes into a Tracks method. r=dholbert
layout/generic/nsGridContainerFrame.cpp
--- a/layout/generic/nsGridContainerFrame.cpp
+++ b/layout/generic/nsGridContainerFrame.cpp
@@ -226,17 +226,18 @@ struct MOZ_STACK_CLASS nsGridContainerFr
 /**
  * State for the tracks in one dimension.
  */
 struct MOZ_STACK_CLASS nsGridContainerFrame::Tracks
 {
   explicit Tracks(Dimension aDimension) : mDimension(aDimension) {}
 
   void Initialize(const TrackSizingFunctions& aFunctions,
-                  nscoord                     aPercentageBasis);
+                  uint32_t                    aNumTracks,
+                  nscoord                     aContentBoxSize);
 
   /**
    * Return true if aRange spans at least one track with an intrinsic sizing
    * function and does not span any tracks with a <flex> max-sizing function.
    * @param aRange the span of tracks to check
    * @param aConstraint if MIN_ISIZE, treat a <flex> min-sizing as 'min-content'
    * @param aState will be set to the union of the state bits of all the spanned
    *               tracks, unless a flex track is found - then it only contains
@@ -569,16 +570,28 @@ struct MOZ_STACK_CLASS nsGridContainerFr
   /**
    * Implements "12.7. Stretch Flexible Tracks"
    * http://dev.w3.org/csswg/css-grid/#algo-flex-tracks
    */
   void StretchFlexibleTracks(GridReflowState&            aState,
                              nsTArray<GridItemInfo>&     aGridItems,
                              const TrackSizingFunctions& aFunctions,
                              nscoord                     aAvailableSize);
+
+  /**
+   * Implements "12.3. Track Sizing Algorithm"
+   * http://dev.w3.org/csswg/css-grid/#algo-track-sizing
+   */
+  void CalculateSizes(GridReflowState&            aState,
+                      nsTArray<GridItemInfo>&     aGridItems,
+                      const TrackSizingFunctions& aFunctions,
+                      nscoord                     aContentSize,
+                      LineRange GridArea::*       aRange,
+                      IntrinsicISizeType          aConstraint);
+
 #ifdef DEBUG
   void Dump() const
   {
     for (uint32_t i = 0, len = mSizes.Length(); i < len; ++i) {
       printf("  %d: ", i);
       mSizes[i].Dump();
       printf("\n");
     }
@@ -1593,39 +1606,48 @@ nsGridContainerFrame::TrackSize::Initial
       mLimit = nsRuleNode::ComputeCoordPercentCalc(aMaxCoord, aPercentageBasis);
       if (mLimit < mBase) {
         mLimit = mBase;
       }
   }
 }
 
 void
-nsGridContainerFrame::Tracks::Initialize(const TrackSizingFunctions& aFunctions,
-                                         nscoord            aPercentageBasis)
+nsGridContainerFrame::Tracks::Initialize(
+  const TrackSizingFunctions& aFunctions,
+  uint32_t                    aNumTracks,
+  nscoord                     aContentBoxSize)
 {
+  mSizes.SetLength(aNumTracks);
+  PodZero(mSizes.Elements(), mSizes.Length());
+  nscoord percentageBasis = aContentBoxSize;
+  if (percentageBasis == NS_UNCONSTRAINEDSIZE) {
+    percentageBasis = 0;
+  }
+
   const uint32_t explicitGridOffset = aFunctions.mExplicitGridOffset;
   MOZ_ASSERT(mSizes.Length() >=
                explicitGridOffset + aFunctions.mMinSizingFunctions.Length());
   MOZ_ASSERT(aFunctions.mMinSizingFunctions.Length() ==
                aFunctions.mMaxSizingFunctions.Length());
   uint32_t i = 0;
   for (; i < explicitGridOffset; ++i) {
-    mSizes[i].Initialize(aPercentageBasis,
+    mSizes[i].Initialize(percentageBasis,
                          aFunctions.mAutoMinSizing,
                          aFunctions.mAutoMaxSizing);
   }
   uint32_t j = 0;
   for (uint32_t len = aFunctions.mMinSizingFunctions.Length(); j < len; ++j) {
-    mSizes[i + j].Initialize(aPercentageBasis,
+    mSizes[i + j].Initialize(percentageBasis,
                              aFunctions.mMinSizingFunctions[j],
                              aFunctions.mMaxSizingFunctions[j]);
   }
   i += j;
   for (; i < mSizes.Length(); ++i) {
-    mSizes[i].Initialize(aPercentageBasis,
+    mSizes[i].Initialize(percentageBasis,
                          aFunctions.mAutoMinSizing,
                          aFunctions.mAutoMaxSizing);
   }
 }
 
 static nscoord
 MinSize(nsIFrame* aChild, nsRenderingContext* aRC, WritingMode aCBWM,
         nsGridContainerFrame::Dimension aDimension,
@@ -1712,52 +1734,55 @@ MaxContentContribution(nsIFrame*        
                        WritingMode                     aCBWM,
                        nsGridContainerFrame::Dimension aDimension)
 {
   return ContentContribution(aChild, aRS, aRC, aCBWM, aDimension,
                              nsLayoutUtils::PREF_ISIZE);
 }
 
 void
+nsGridContainerFrame::Tracks::CalculateSizes(
+  GridReflowState&            aState,
+  nsTArray<GridItemInfo>&     aGridItems,
+  const TrackSizingFunctions& aFunctions,
+  nscoord                     aContentBoxSize,
+  LineRange GridArea::*       aRange,
+  IntrinsicISizeType          aConstraint)
+{
+  nscoord percentageBasis = aContentBoxSize;
+  if (percentageBasis == NS_UNCONSTRAINEDSIZE) {
+    percentageBasis = 0;
+  }
+  ResolveIntrinsicSize(aState, aGridItems, aFunctions, aRange, percentageBasis,
+                       aConstraint);
+  if (aConstraint != nsLayoutUtils::MIN_ISIZE) {
+    DistributeFreeSpace(aContentBoxSize);
+    StretchFlexibleTracks(aState, aGridItems, aFunctions, aContentBoxSize);
+  }
+}
+
+void
 nsGridContainerFrame::CalculateTrackSizes(GridReflowState&   aState,
                                           const LogicalSize& aContentBox,
                                           IntrinsicISizeType aConstraint)
 {
-  aState.mCols.mSizes.SetLength(mGridColEnd);
-  PodZero(aState.mCols.mSizes.Elements(), aState.mCols.mSizes.Length());
   const WritingMode& wm = aState.mWM;
-  nscoord colPercentageBasis = aContentBox.ISize(wm);
-  auto& colFunctions = aState.mColFunctions;
-  aState.mCols.Initialize(colFunctions, colPercentageBasis);
-  aState.mCols.ResolveIntrinsicSize(aState, mGridItems, colFunctions,
-                                    &GridArea::mCols, colPercentageBasis,
-                                    aConstraint);
-  if (aConstraint != nsLayoutUtils::MIN_ISIZE) {
-    nscoord size = aContentBox.ISize(wm);
-    aState.mCols.DistributeFreeSpace(size);
-    aState.mCols.StretchFlexibleTracks(aState, mGridItems, colFunctions, size);
-  }
+  aState.mCols.Initialize(aState.mColFunctions, mGridColEnd,
+                          aContentBox.ISize(wm));
+  aState.mRows.Initialize(aState.mRowFunctions, mGridRowEnd,
+                          aContentBox.BSize(wm));
 
-  aState.mRows.mSizes.SetLength(mGridRowEnd);
-  PodZero(aState.mRows.mSizes.Elements(), aState.mRows.mSizes.Length());
-  nscoord rowPercentageBasis = aContentBox.BSize(wm);
-  if (rowPercentageBasis == NS_AUTOHEIGHT) {
-    rowPercentageBasis = 0;
-  }
-  auto& rowFunctions = aState.mRowFunctions;
-  aState.mRows.Initialize(rowFunctions, rowPercentageBasis);
+  aState.mCols.CalculateSizes(aState, mGridItems, aState.mColFunctions,
+                              aContentBox.ISize(wm), &GridArea::mCols,
+                              aConstraint);
+
   aState.mIter.Reset(); // XXX cleanup this Reset mess!
-  aState.mRows.ResolveIntrinsicSize(aState, mGridItems, rowFunctions,
-                                    &GridArea::mRows, rowPercentageBasis,
-                                    aConstraint);
-  if (aConstraint != nsLayoutUtils::MIN_ISIZE) {
-    nscoord size = aContentBox.BSize(wm);
-    aState.mRows.DistributeFreeSpace(size);
-    aState.mRows.StretchFlexibleTracks(aState, mGridItems, rowFunctions, size);
-  }
+  aState.mRows.CalculateSizes(aState, mGridItems, aState.mRowFunctions,
+                              aContentBox.BSize(wm), &GridArea::mRows,
+                              aConstraint);
 }
 
 bool
 nsGridContainerFrame::Tracks::HasIntrinsicButNoFlexSizingInRange(
   const LineRange&      aRange,
   IntrinsicISizeType    aConstraint,
   TrackSize::StateBits* aState) const
 {