Bug 1174553 part 5 - [css-grid] Replace the ambiguous Dimension with LogicalAxis. r=dholbert
authorMats Palmgren <mats@mozilla.com>
Fri, 04 Sep 2015 22:06:58 +0200
changeset 261124 56e29e6d877eab5f887cc93bfeff34a9a63144e9
parent 261123 bacad119cc26f53894d092bdd32f95a88ab70308
child 261125 37eb43b1d82ea3460d562a4ac4d0d9a2af20ae6c
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
bugs1174553
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 1174553 part 5 - [css-grid] Replace the ambiguous Dimension with LogicalAxis. r=dholbert
layout/generic/nsGridContainerFrame.cpp
layout/generic/nsGridContainerFrame.h
--- a/layout/generic/nsGridContainerFrame.cpp
+++ b/layout/generic/nsGridContainerFrame.cpp
@@ -223,17 +223,17 @@ struct MOZ_STACK_CLASS nsGridContainerFr
   uint32_t mExplicitGridOffset;
 };
 
 /**
  * State for the tracks in one dimension.
  */
 struct MOZ_STACK_CLASS nsGridContainerFrame::Tracks
 {
-  explicit Tracks(Dimension aDimension) : mDimension(aDimension) {}
+  explicit Tracks(LogicalAxis aAxis) : mAxis(aAxis) {}
 
   void Initialize(const TrackSizingFunctions& aFunctions,
                   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.
@@ -594,17 +594,17 @@ struct MOZ_STACK_CLASS nsGridContainerFr
       printf("  %d: ", i);
       mSizes[i].Dump();
       printf("\n");
     }
   }
 #endif
 
   nsAutoTArray<TrackSize, 32> mSizes;
-  Dimension mDimension;
+  LogicalAxis mAxis;
 };
 
 struct MOZ_STACK_CLASS nsGridContainerFrame::GridReflowState
 {
   GridReflowState(nsGridContainerFrame*    aFrame,
                   const nsHTMLReflowState& aRS)
     : GridReflowState(aFrame, *aRS.rendContext, &aRS, aRS.mStylePosition,
                       aRS.GetWritingMode())
@@ -633,18 +633,18 @@ struct MOZ_STACK_CLASS nsGridContainerFr
 private:
   GridReflowState(nsGridContainerFrame*    aFrame,
                   nsRenderingContext&      aRenderingContext,
                   const nsHTMLReflowState* aReflowState,
                   const nsStylePosition*   aGridStyle,
                   const WritingMode&       aWM)
     : mIter(aFrame, kPrincipalList)
     , mGridStyle(aGridStyle)
-    , mCols(eColDimension)
-    , mRows(eRowDimension)
+    , mCols(eLogicalAxisInline)
+    , mRows(eLogicalAxisBlock)
     , mColFunctions({
         mGridStyle->mGridTemplateColumns.mMinTrackSizingFunctions,
         mGridStyle->mGridTemplateColumns.mMaxTrackSizingFunctions,
         mGridStyle->mGridAutoColumnsMin,
         mGridStyle->mGridAutoColumnsMax,
       })
     , mRowFunctions({
         mGridStyle->mGridTemplateRows.mMinTrackSizingFunctions,
@@ -1645,39 +1645,36 @@ nsGridContainerFrame::Tracks::Initialize
     mSizes[i].Initialize(percentageBasis,
                          aFunctions.mAutoMinSizing,
                          aFunctions.mAutoMaxSizing);
   }
 }
 
 static nscoord
 MinSize(nsIFrame* aChild, nsRenderingContext* aRC, WritingMode aCBWM,
-        nsGridContainerFrame::Dimension aDimension,
-        nsLayoutUtils::IntrinsicISizeType aConstraint)
+        LogicalAxis aAxis, nsLayoutUtils::IntrinsicISizeType aConstraint)
 {
-  PhysicalAxis axis(((aDimension == nsGridContainerFrame::eColDimension) ==
-                     aCBWM.IsVertical()) ? eAxisVertical : eAxisHorizontal);
+  PhysicalAxis axis(aCBWM.PhysicalAxis(aAxis));
   return nsLayoutUtils::MinSizeContributionForAxis(axis, aRC, aChild,
                                                    aConstraint);
 }
 
 /**
  * Return the [min|max]-content contribution of aChild to its parent (i.e.
- * the child's margin-box) in aDimension.
+ * the child's margin-box) in aAxis.
  */
 static nscoord
 ContentContribution(nsIFrame*                         aChild,
                     const nsHTMLReflowState*          aReflowState,
                     nsRenderingContext*               aRC,
                     WritingMode                       aCBWM,
-                    nsGridContainerFrame::Dimension   aDimension,
+                    LogicalAxis                       aAxis,
                     nsLayoutUtils::IntrinsicISizeType aConstraint)
 {
-  PhysicalAxis axis(((aDimension == nsGridContainerFrame::eColDimension) ==
-                     aCBWM.IsVertical()) ? eAxisVertical : eAxisHorizontal);
+  PhysicalAxis axis(aCBWM.PhysicalAxis(aAxis));
   nscoord size = nsLayoutUtils::IntrinsicForAxis(axis, aRC, aChild, aConstraint,
                    nsLayoutUtils::BAIL_IF_REFLOW_NEEDED);
   if (size == NS_INTRINSIC_WIDTH_UNKNOWN) {
     // We need to reflow the child to find its BSize contribution.
     WritingMode wm = aChild->GetWritingMode();
     nsContainerFrame* parent = aChild->GetParent();
     nsPresContext* pc = aChild->PresContext();
     Maybe<nsHTMLReflowState> dummyParentState;
@@ -1712,34 +1709,34 @@ ContentContribution(nsIFrame*           
 #ifdef DEBUG
     parent->Properties().Delete(nsContainerFrame::DebugReflowingWithInfiniteISize());
 #endif
   }
   return std::max(size, 0);
 }
 
 static nscoord
-MinContentContribution(nsIFrame*                       aChild,
-                       const nsHTMLReflowState*        aRS,
-                       nsRenderingContext*             aRC,
-                       WritingMode                     aCBWM,
-                       nsGridContainerFrame::Dimension aDimension)
+MinContentContribution(nsIFrame*                aChild,
+                       const nsHTMLReflowState* aRS,
+                       nsRenderingContext*      aRC,
+                       WritingMode              aCBWM,
+                       LogicalAxis              aAxis)
 {
-  return ContentContribution(aChild, aRS, aRC, aCBWM, aDimension,
+  return ContentContribution(aChild, aRS, aRC, aCBWM, aAxis,
                              nsLayoutUtils::MIN_ISIZE);
 }
 
 static nscoord
-MaxContentContribution(nsIFrame*                       aChild,
-                       const nsHTMLReflowState*        aRS,
-                       nsRenderingContext*             aRC,
-                       WritingMode                     aCBWM,
-                       nsGridContainerFrame::Dimension aDimension)
+MaxContentContribution(nsIFrame*                aChild,
+                       const nsHTMLReflowState* aRS,
+                       nsRenderingContext*      aRC,
+                       WritingMode              aCBWM,
+                       LogicalAxis              aAxis)
 {
-  return ContentContribution(aChild, aRS, aRC, aCBWM, aDimension,
+  return ContentContribution(aChild, aRS, aRC, aCBWM, aAxis,
                              nsLayoutUtils::PREF_ISIZE);
 }
 
 void
 nsGridContainerFrame::Tracks::CalculateSizes(
   GridReflowState&            aState,
   nsTArray<GridItemInfo>&     aGridItems,
   const TrackSizingFunctions& aFunctions,
@@ -1820,44 +1817,44 @@ nsGridContainerFrame::Tracks::ResolveInt
   Maybe<nscoord> minContentContribution;
   Maybe<nscoord> maxContentContribution;
   // min sizing
   TrackSize& sz = mSizes[aRange.mStart];
   WritingMode wm = aState.mWM;
   const nsHTMLReflowState* rs = aState.mReflowState;
   nsRenderingContext* rc = &aState.mRenderingContext;
   if (sz.mState & TrackSize::eAutoMinSizing) {
-    nscoord s = MinSize(aGridItem, rc, wm, mDimension, aConstraint);
+    nscoord s = MinSize(aGridItem, rc, wm, mAxis, aConstraint);
     sz.mBase = std::max(sz.mBase, s);
   } else if ((sz.mState & TrackSize::eMinContentMinSizing) ||
              (aConstraint == nsLayoutUtils::MIN_ISIZE &&
               (sz.mState & TrackSize::eFlexMinSizing))) {
-    nscoord s = MinContentContribution(aGridItem, rs, rc, wm, mDimension);
+    nscoord s = MinContentContribution(aGridItem, rs, rc, wm, mAxis);
     minContentContribution.emplace(s);
     sz.mBase = std::max(sz.mBase, minContentContribution.value());
   } else if (sz.mState & TrackSize::eMaxContentMinSizing) {
-    nscoord s = MaxContentContribution(aGridItem, rs, rc, wm, mDimension);
+    nscoord s = MaxContentContribution(aGridItem, rs, rc, wm, mAxis);
     maxContentContribution.emplace(s);
     sz.mBase = std::max(sz.mBase, maxContentContribution.value());
   }
   // max sizing
   if (sz.mState & TrackSize::eMinContentMaxSizing) {
     if (minContentContribution.isNothing()) {
-      nscoord s = MinContentContribution(aGridItem, rs, rc, wm, mDimension);
+      nscoord s = MinContentContribution(aGridItem, rs, rc, wm, mAxis);
       minContentContribution.emplace(s);
     }
     if (sz.mLimit == NS_UNCONSTRAINEDSIZE) {
       sz.mLimit = minContentContribution.value();
     } else {
       sz.mLimit = std::max(sz.mLimit, minContentContribution.value());
     }
   } else if (sz.mState & (TrackSize::eAutoMaxSizing |
                           TrackSize::eMaxContentMaxSizing)) {
     if (maxContentContribution.isNothing()) {
-      nscoord s = MaxContentContribution(aGridItem, rs, rc, wm, mDimension);
+      nscoord s = MaxContentContribution(aGridItem, rs, rc, wm, mAxis);
       maxContentContribution.emplace(s);
     }
     if (sz.mLimit == NS_UNCONSTRAINEDSIZE) {
       sz.mLimit = maxContentContribution.value();
     } else {
       sz.mLimit = std::max(sz.mLimit, maxContentContribution.value());
     }
   }
@@ -1907,17 +1904,17 @@ nsGridContainerFrame::Tracks::ResolveInt
                                             : TrackSize::StateBits(0);
   for (; !iter.AtEnd(); iter.Next()) {
     nsIFrame* child = *iter;
     const GridArea& area = aGridItems[iter.GridItemIndex()].mArea;
     const LineRange& lineRange = area.*aRange;
     uint32_t span = lineRange.Extent();
     if (span == 1) {
       // Step 1. Size tracks to fit non-spanning items.
-      aGridItems[iter.GridItemIndex()].mIsFlexing[mDimension] =
+      aGridItems[iter.GridItemIndex()].mIsFlexing[mAxis] =
         ResolveIntrinsicSizeStep1(aState, aFunctions, aPercentageBasis,
                                   aConstraint, lineRange, child);
     } else {
       TrackSize::StateBits state = TrackSize::StateBits(0);
       if (HasIntrinsicButNoFlexSizingInRange(lineRange, aConstraint, &state)) {
         // Collect data for Step 2.
         maxSpan = std::max(maxSpan, span);
         if (span >= stateBitsPerSpan.Length()) {
@@ -1925,35 +1922,35 @@ nsGridContainerFrame::Tracks::ResolveInt
           stateBitsPerSpan.SetCapacity(len);
           for (uint32_t i = stateBitsPerSpan.Length(); i < len; ++i) {
             stateBitsPerSpan.AppendElement(TrackSize::StateBits(0));
           }
         }
         stateBitsPerSpan[span] |= state;
         nscoord minSize = 0;
         if (state & (flexMin | TrackSize::eIntrinsicMinSizing)) { // for 2.1
-          minSize = MinSize(child, rc, wm, mDimension, aConstraint);
+          minSize = MinSize(child, rc, wm, mAxis, aConstraint);
         }
         nscoord minContent = 0;
         if (state & (flexMin | TrackSize::eMinOrMaxContentMinSizing | // for 2.2
                      TrackSize::eIntrinsicMaxSizing)) {               // for 2.5
           minContent = MinContentContribution(child, aState.mReflowState,
-                                              rc, wm, mDimension);
+                                              rc, wm, mAxis);
         }
         nscoord maxContent = 0;
         if (state & (TrackSize::eMaxContentMinSizing |         // for 2.3
                      TrackSize::eAutoOrMaxContentMaxSizing)) { // for 2.6
           maxContent = MaxContentContribution(child, aState.mReflowState,
-                                              rc, wm, mDimension);
+                                              rc, wm, mAxis);
         }
         step2Items.AppendElement(
           Step2ItemData({span, state, lineRange, minSize,
                          minContent, maxContent, child}));
       } else {
-        aGridItems[iter.GridItemIndex()].mIsFlexing[mDimension] =
+        aGridItems[iter.GridItemIndex()].mIsFlexing[mAxis] =
           !!(state & TrackSize::eFlexMaxSizing);
       }
     }
   }
 
   // Step 2.
   if (maxSpan) {
     // Sort the collected items on span length, shortest first.
@@ -2198,25 +2195,24 @@ nsGridContainerFrame::Tracks::FindUsedFl
   nsRenderingContext* rc = &aState.mRenderingContext;
   const nsHTMLReflowState* rs = aState.mReflowState;
   GridItemCSSOrderIterator& iter = aState.mIter;
   iter.Reset();
   // ... the result of 'finding the size of an fr' for each item that spans
   // a flex track with its max-content contribution as 'space to fill'
   for (; !iter.AtEnd(); iter.Next()) {
     const GridItemInfo& item = aGridItems[iter.GridItemIndex()];
-    if (item.mIsFlexing[mDimension]) {
-      nscoord spaceToFill = MaxContentContribution(*iter, rs, rc, wm,
-                                                   mDimension);
+    if (item.mIsFlexing[mAxis]) {
+      nscoord spaceToFill = MaxContentContribution(*iter, rs, rc, wm, mAxis);
       if (spaceToFill <= 0) {
         continue;
       }
       // ... and all its spanned tracks as input.
       const LineRange& range =
-        mDimension == eColDimension ? item.mArea.mCols : item.mArea.mRows;
+        mAxis == eLogicalAxisInline ? item.mArea.mCols : item.mArea.mRows;
       nsTArray<uint32_t> itemFlexTracks;
       for (uint32_t i = range.mStart, end = range.mEnd; i < end; ++i) {
         if (mSizes[i].mState & TrackSize::eFlexMaxSizing) {
           itemFlexTracks.AppendElement(i);
         }
       }
       float itemFr =
         FindFrUnitSize(range, itemFlexTracks, aFunctions, spaceToFill);
--- a/layout/generic/nsGridContainerFrame.h
+++ b/layout/generic/nsGridContainerFrame.h
@@ -80,21 +80,16 @@ public:
       eSkipGrowUnlimited = eSkipGrowUnlimited1 | eSkipGrowUnlimited2,
     };
 
     nscoord mBase;
     nscoord mLimit;
     StateBits mState;
   };
 
-  // @note when used in a function that measures a child's size, eColDimension
-  // means we're calculating the child's contribution to the column sizing.
-  // (i.e. the child's inline size if its 'writing-mode' is horizontal)
-  enum Dimension { eColDimension, eRowDimension };
-
   // @see nsAbsoluteContainingBlock::Reflow about this magic number
   static const nscoord VERY_LIKELY_A_GRID_CONTAINER = -123456789;
 
   NS_DECLARE_FRAME_PROPERTY(GridItemContainingBlockRect, DeleteValue<nsRect>)
 
 protected:
   static const uint32_t kAutoLine;
   // The maximum line number, in the zero-based translated grid.
@@ -289,17 +284,19 @@ protected:
     explicit GridItemInfo(const GridArea& aArea)
       : mArea(aArea)
     {
       mIsFlexing[0] = false;
       mIsFlexing[1] = false;
     }
 
     GridArea mArea;
-    bool mIsFlexing[2]; // does the item span a flex track? (index by Dimension)
+    bool mIsFlexing[2]; // does the item span a flex track? (LogicalAxis index)
+    static_assert(mozilla::eLogicalAxisBlock == 0, "unexpected index value");
+    static_assert(mozilla::eLogicalAxisInline == 1, "unexpected index value");
 #ifdef DEBUG
     nsIFrame* mFrame;
 #endif
   };
 
   enum LineRangeSide {
     eLineRangeSideStart, eLineRangeSideEnd
   };