Bug 1147423 part 1 - [css-grid] Use a signed integer type for some line variables in preparation for negative implicit lines. r=dholbert
authorMats Palmgren <mats@mozilla.com>
Thu, 30 Apr 2015 18:42:50 +0000
changeset 273263 fa682ace73660c86a62b3928dbc2f7eb878b781d
parent 273262 605d1ea1ff14b2f37a873ba0693e1891a8785a89
child 273264 9a7c7a133dd60195cf5292510fe913beaa94d69d
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1147423
milestone40.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 1147423 part 1 - [css-grid] Use a signed integer type for some line variables in preparation for negative implicit lines. r=dholbert
layout/generic/nsGridContainerFrame.cpp
layout/generic/nsGridContainerFrame.h
--- a/layout/generic/nsGridContainerFrame.cpp
+++ b/layout/generic/nsGridContainerFrame.cpp
@@ -369,30 +369,30 @@ nsGridContainerFrame::InitImplicitNamedA
   }
   AddImplicitNamedAreas(aStyle->mGridTemplateColumns.mLineNameLists);
   AddImplicitNamedAreas(aStyle->mGridTemplateRows.mLineNameLists);
   if (areas && areas->Count() == 0) {
     Properties().Delete(ImplicitNamedAreasProperty());
   }
 }
 
-uint32_t
+int32_t
 nsGridContainerFrame::ResolveLine(
   const nsStyleGridLine& aLine,
   int32_t aNth,
   uint32_t aFromIndex,
   const nsTArray<nsTArray<nsString>>& aLineNameList,
   uint32_t GridNamedArea::* aAreaStart,
   uint32_t GridNamedArea::* aAreaEnd,
   uint32_t aExplicitGridEnd,
   LineRangeSide aSide,
   const nsStylePosition* aStyle)
 {
   MOZ_ASSERT(!aLine.IsAuto());
-  uint32_t line = 0;
+  int32_t line = 0;
   if (aLine.mLineName.IsEmpty()) {
     MOZ_ASSERT(aNth != 0, "css-grid 9.2: <integer> must not be zero.");
     line = std::max(int32_t(aFromIndex) + aNth, 1);
   } else {
     if (aNth == 0) {
       // <integer> was omitted; treat it as 1.
       aNth = 1;
     }
@@ -496,17 +496,17 @@ nsGridContainerFrame::ResolveLineRangeHe
     int32_t span = aStart.mInteger == 0 ? 1 : aStart.mInteger;
     auto start = ResolveLine(aStart, -span, end, aLineNameList, aAreaStart,
                              aAreaEnd, aExplicitGridEnd, eLineRangeSideStart,
                              aStyle);
     MOZ_ASSERT(start > 0, "A start span can never resolve to 'auto'");
     return LinePair(start, end);
   }
 
-  uint32_t start = 0;
+  int32_t start = 0;
   if (!aStart.IsAuto()) {
     start = ResolveLine(aStart, aStart.mInteger, 0, aLineNameList, aAreaStart,
                         aAreaEnd, aExplicitGridEnd, eLineRangeSideStart,
                         aStyle);
   }
   if (aEnd.IsAuto()) {
     // * (except span) / auto
     return LinePair(start, 1); // XXX subgrid explicit size instead of 1?
@@ -525,17 +525,17 @@ nsGridContainerFrame::ResolveLineRangeHe
   uint32_t from = aEnd.mHasSpan ? start : 0;
   auto end = ResolveLine(aEnd, aEnd.mInteger, from, aLineNameList, aAreaStart,
                          aAreaEnd, aExplicitGridEnd, eLineRangeSideEnd, aStyle);
   if (end == 0) {
     // * (except span) / not found <custom-ident>
     end = 1; // XXX subgrid explicit size instead of 1?
   } else if (start == 0) {
     // auto (or not found <custom-ident>) / definite line
-    start = std::max(1U, end - 1);
+    start = std::max(1, end - 1);
   }
   return LinePair(start, end);
 }
 
 nsGridContainerFrame::LineRange
 nsGridContainerFrame::ResolveLineRange(
   const nsStyleGridLine& aStart,
   const nsStyleGridLine& aEnd,
@@ -582,44 +582,44 @@ nsGridContainerFrame::ResolveAbsPosLineR
   uint32_t aExplicitGridEnd,
   uint32_t aGridEnd,
   const nsStylePosition* aStyle)
 {
   if (aStart.IsAuto()) {
     if (aEnd.IsAuto()) {
       return LineRange(0, 0);
     }
-    uint32_t end = ResolveLine(aEnd, aEnd.mInteger, 0, aLineNameList, aAreaStart,
-                               aAreaEnd, aExplicitGridEnd, eLineRangeSideEnd,
-                               aStyle);
+    int32_t end = ResolveLine(aEnd, aEnd.mInteger, 0, aLineNameList, aAreaStart,
+                              aAreaEnd, aExplicitGridEnd, eLineRangeSideEnd,
+                              aStyle);
     MOZ_ASSERT(end != 0, "resolving non-auto line shouldn't result in auto");
     if (aEnd.mHasSpan) {
       ++end;
     }
-    return LineRange(0, clamped(end, 1U, aGridEnd));
+    return LineRange(0, clamped(end, 1, int32_t(aGridEnd)));
   }
 
   if (aEnd.IsAuto()) {
-    uint32_t start =
+    int32_t start =
       ResolveLine(aStart, aStart.mInteger, 0, aLineNameList, aAreaStart,
                   aAreaEnd, aExplicitGridEnd, eLineRangeSideStart, aStyle);
     MOZ_ASSERT(start != 0, "resolving non-auto line shouldn't result in auto");
     if (aStart.mHasSpan) {
-      start = std::max(int32_t(aGridEnd) - int32_t(start), 1);
+      start = std::max(int32_t(aGridEnd) - start, 1);
     }
-    return LineRange(clamped(start, 1U, aGridEnd), 0);
+    return LineRange(clamped(start, 1, int32_t(aGridEnd)), 0);
   }
 
   LineRange r = ResolveLineRange(aStart, aEnd, aLineNameList, aAreaStart,
                                  aAreaEnd, aExplicitGridEnd, aStyle);
   MOZ_ASSERT(!r.IsAuto(), "resolving definite lines shouldn't result in auto");
   // Clamp definite lines to be within the implicit grid.
   // Note that this implies mStart may be equal to mEnd.
-  r.mStart = clamped(r.mStart, 1U, aGridEnd);
-  r.mEnd = clamped(r.mEnd, 1U, aGridEnd);
+  r.mStart = clamped(r.mStart, 1, int32_t(aGridEnd));
+  r.mEnd = clamped(r.mEnd, 1, int32_t(aGridEnd));
   MOZ_ASSERT(r.mStart <= r.mEnd);
   return r;
 }
 
 uint32_t
 nsGridContainerFrame::FindAutoCol(uint32_t aStartCol, uint32_t aLockedRow,
                                   const GridArea* aArea) const
 {
@@ -870,17 +870,17 @@ nsGridContainerFrame::PlaceGridItems(Gri
     nsIFrame* child = *aIter;
     GridArea* area = GetGridAreaForChild(child);
     LineRange& major = isRowOrder ? area->mRows : area->mCols;
     LineRange& minor = isRowOrder ? area->mCols : area->mRows;
     if (major.IsAuto()) {
       if (minor.IsDefinite()) {
         // Items with 'auto' in the major dimension only.
         if (isSparse) {
-          if (minor.mStart < cursorMinor) {
+          if (minor.mStart < int32_t(cursorMinor)) {
             ++cursorMajor;
           }
           cursorMinor = minor.mStart;
         }
         (this->*placeAutoMajorFunc)(cursorMajor, area);
         if (isSparse) {
           cursorMajor = major.mStart;
         }
--- a/layout/generic/nsGridContainerFrame.h
+++ b/layout/generic/nsGridContainerFrame.h
@@ -78,30 +78,30 @@ protected:
    * In both states the invariant mEnd > mStart holds (for normal flow items).
    *
    * For abs.pos. grid items, mStart and mEnd may both be zero, meaning
    * "attach this side to the grid container containing block edge".
    * Additionally, mEnd >= mStart holds when both are definite (non-zero),
    * i.e. the invariant is slightly relaxed compared to normal flow items.
    */
   struct LineRange {
-   LineRange(uint32_t aStart, uint32_t aEnd)
+   LineRange(int32_t aStart, int32_t aEnd)
       : mStart(aStart), mEnd(aEnd) {}
     bool IsAuto() const { return mStart == 0; }
     bool IsDefinite() const { return mStart != 0; }
     uint32_t Extent() const { return mEnd - mStart; }
     /**
      * Resolve this auto range to start at aStart, making it definite.
      * Precondition: this range IsAuto()
      */
-    void ResolveAutoPosition(uint32_t aStart)
+    void ResolveAutoPosition(int32_t aStart)
     {
       MOZ_ASSERT(IsAuto(), "Why call me?");
       MOZ_ASSERT(aStart > 0, "expected a 1-based line number");
-      MOZ_ASSERT(Extent() == mEnd, "'auto' representation changed?");
+      MOZ_ASSERT(int32_t(Extent()) == mEnd, "'auto' representation changed?");
       mStart = aStart;
       mEnd += aStart;
     }
     /**
      * Return the contribution of this line range for step 2 in
      * http://dev.w3.org/csswg/css-grid/#auto-placement-algo
      */
     uint32_t HypotheticalEnd() const { return IsAuto() ? mEnd + 1 : mEnd; }
@@ -116,18 +116,18 @@ protected:
      * abs.pos. containing block along an axis given by aPos and aLength.
      * aPos and aLength should already be initialized to the grid container
      * containing block for this axis before calling this method.
      */
     void ToPositionAndLengthForAbsPos(const nsTArray<TrackSize>& aTrackSizes,
                                       nscoord aGridOrigin,
                                       nscoord* aPos, nscoord* aLength) const;
 
-    uint32_t mStart;  // the start line, or zero for 'auto'
-    uint32_t mEnd;    // the end line, or the span length for 'auto'
+    int32_t mStart;  // the start line, or zero for 'auto'
+    int32_t mEnd;    // the end line, or the span length for 'auto'
   };
 
   /**
    * A GridArea is the area in the grid for a grid item.
    * The area is represented by two LineRanges, both of which can be auto
    * (@see LineRange) in intermediate steps while the item is being placed.
    * @see PlaceGridItems
    */
@@ -176,25 +176,25 @@ protected:
    * @param aAreaStart a pointer to GridNamedArea::mColumnStart/mRowStart
    * @param aAreaEnd a pointer to GridNamedArea::mColumnEnd/mRowEnd
    * @param aExplicitGridEnd the last line in the explicit grid
    * @param aEdge indicates whether we are resolving a start or end line
    * @param aStyle the StylePosition() for the grid container
    * @return a definite line number, or zero in case aLine is a <custom-ident>
    * that can't be found.
    */
-  uint32_t ResolveLine(const nsStyleGridLine& aLine,
-                       int32_t aNth,
-                       uint32_t aFromIndex,
-                       const nsTArray<nsTArray<nsString>>& aLineNameList,
-                       uint32_t GridNamedArea::* aAreaStart,
-                       uint32_t GridNamedArea::* aAreaEnd,
-                       uint32_t aExplicitGridEnd,
-                       LineRangeSide aEdge,
-                       const nsStylePosition* aStyle);
+  int32_t ResolveLine(const nsStyleGridLine& aLine,
+                      int32_t aNth,
+                      uint32_t aFromIndex,
+                      const nsTArray<nsTArray<nsString>>& aLineNameList,
+                      uint32_t GridNamedArea::* aAreaStart,
+                      uint32_t GridNamedArea::* aAreaEnd,
+                      uint32_t aExplicitGridEnd,
+                      LineRangeSide aEdge,
+                      const nsStylePosition* aStyle);
   /**
    * Return a LineRange based on the given style data. Non-auto lines
    * are resolved to a definite line number per:
    * http://dev.w3.org/csswg/css-grid/#line-placement
    * with placement errors corrected per:
    * http://dev.w3.org/csswg/css-grid/#grid-placement-errors
    * @param aStyle the StylePosition() for the grid container
    * @param aStart style data for the start line
@@ -337,17 +337,17 @@ protected:
                            nsTArray<TrackSize>&        aColSizes,
                            nsTArray<TrackSize>&        aRowSizes);
 
   /**
    * Helper method for ResolveLineRange.
    * @see ResolveLineRange
    * @return a pair (start,end) of lines
    */
-  typedef std::pair<uint32_t, uint32_t> LinePair;
+  typedef std::pair<int32_t, int32_t> LinePair;
   LinePair ResolveLineRangeHelper(const nsStyleGridLine& aStart,
                                   const nsStyleGridLine& aEnd,
                                   const nsTArray<nsTArray<nsString>>& aLineNameList,
                                   uint32_t GridNamedArea::* aAreaStart,
                                   uint32_t GridNamedArea::* aAreaEnd,
                                   uint32_t aExplicitGridEnd,
                                   const nsStylePosition* aStyle);