[CSS Grid Layout] Add GridSpan::iterator
authorrego@igalia.com <rego@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Jun 2014 08:28:59 +0000 (08:28 +0000)
committerrego@igalia.com <rego@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Jun 2014 08:28:59 +0000 (08:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=134058

Reviewed by Bem Jones-Bey.

Once that GridResolvedPosition has been introduced in r169934, this
patch adds a GridSpan::iterator which allows to simplify the loops over
GridResolvedPositions.
From now on we could use range-based for loops.

No new tests as it is already covered by current tests
(fast/css-grid-layout/).

* rendering/RenderGrid.cpp:
(WebCore::RenderGrid::computeNormalizedFractionBreadth): Change loop to
ranged-based for.
(WebCore::RenderGrid::insertItemIntoGrid): Ditto.
(WebCore::RenderGrid::gridAreaBreadthForChild): Ditto.
* rendering/style/GridCoordinate.h: Define GridSpan::iterator.
(WebCore::GridSpan::begin): Return resolved initial position.
(WebCore::GridSpan::end): Return next to resolved final position.
* rendering/style/GridResolvedPosition.h:
(WebCore::GridResolvedPosition::operator*): Add operator required by
range-based for loops.
(WebCore::GridResolvedPosition::operator!=): Add not equal operator.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@170182 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderGrid.cpp
Source/WebCore/rendering/style/GridCoordinate.h
Source/WebCore/rendering/style/GridResolvedPosition.h

index 9ad72a9..17f8cdd 100644 (file)
@@ -1,3 +1,31 @@
+2014-06-20  Manuel Rego Casasnovas  <rego@igalia.com>
+
+        [CSS Grid Layout] Add GridSpan::iterator
+        https://bugs.webkit.org/show_bug.cgi?id=134058
+
+        Reviewed by Bem Jones-Bey.
+
+        Once that GridResolvedPosition has been introduced in r169934, this
+        patch adds a GridSpan::iterator which allows to simplify the loops over
+        GridResolvedPositions.
+        From now on we could use range-based for loops.
+
+        No new tests as it is already covered by current tests
+        (fast/css-grid-layout/).
+
+        * rendering/RenderGrid.cpp:
+        (WebCore::RenderGrid::computeNormalizedFractionBreadth): Change loop to
+        ranged-based for.
+        (WebCore::RenderGrid::insertItemIntoGrid): Ditto.
+        (WebCore::RenderGrid::gridAreaBreadthForChild): Ditto.
+        * rendering/style/GridCoordinate.h: Define GridSpan::iterator.
+        (WebCore::GridSpan::begin): Return resolved initial position.
+        (WebCore::GridSpan::end): Return next to resolved final position.
+        * rendering/style/GridResolvedPosition.h:
+        (WebCore::GridResolvedPosition::operator*): Add operator required by
+        range-based for loops.
+        (WebCore::GridResolvedPosition::operator!=): Add not equal operator.
+
 2014-06-20  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         Unreviewed. Fix GTK+ debug build after r170174.
index 61cd26c..e6cd952 100644 (file)
@@ -401,7 +401,7 @@ double RenderGrid::computeNormalizedFractionBreadth(Vector<GridTrack>& tracks, c
     // |availableLogicalSpace| already accounts for the used breadths so no need to remove it here.
 
     Vector<GridTrackForNormalization> tracksForNormalization;
-    for (GridResolvedPosition position = tracksSpan.resolvedInitialPosition; position <= tracksSpan.resolvedFinalPosition; ++position) {
+    for (auto position : tracksSpan) {
         const GridTrackSize& trackSize = gridTrackSize(direction, position.toInt());
         if (!trackSize.maxTrackBreadth().isFlex())
             continue;
@@ -623,8 +623,8 @@ void RenderGrid::growGrid(GridTrackSizingDirection direction)
 
 void RenderGrid::insertItemIntoGrid(RenderBox* child, const GridCoordinate& coordinate)
 {
-    for (GridResolvedPosition row = coordinate.rows.resolvedInitialPosition; row <= coordinate.rows.resolvedFinalPosition; ++row) {
-        for (GridResolvedPosition column = coordinate.columns.resolvedInitialPosition; column <= coordinate.columns.resolvedFinalPosition; ++column)
+    for (auto row : coordinate.rows) {
+        for (auto column : coordinate.columns)
             m_grid[row.toInt()][column.toInt()].append(child);
     }
     m_gridItemCoordinate.set(child, coordinate);
@@ -837,7 +837,7 @@ LayoutUnit RenderGrid::gridAreaBreadthForChild(const RenderBox* child, GridTrack
     const GridCoordinate& coordinate = cachedGridCoordinate(child);
     const GridSpan& span = (direction == ForColumns) ? coordinate.columns : coordinate.rows;
     LayoutUnit gridAreaBreadth = 0;
-    for (GridResolvedPosition trackPosition = span.resolvedInitialPosition; trackPosition <= span.resolvedFinalPosition; ++trackPosition)
+    for (auto trackPosition : span)
         gridAreaBreadth += tracks[trackPosition.toInt()].m_usedBreadth;
     return gridAreaBreadth;
 }
index 908f367..39c4a3b 100644 (file)
@@ -59,6 +59,18 @@ public:
 
     GridResolvedPosition resolvedInitialPosition;
     GridResolvedPosition resolvedFinalPosition;
+
+    typedef GridResolvedPosition iterator;
+
+    iterator begin() const
+    {
+        return resolvedInitialPosition;
+    }
+
+    iterator end() const
+    {
+        return resolvedFinalPosition.next();
+    }
 };
 
 // This represents a grid area that spans in both rows' and columns' direction.
index 9016741..db3d21a 100644 (file)
@@ -95,6 +95,11 @@ public:
         m_integerPosition = adjustGridPositionForSide(integerPosition, side).m_integerPosition;
     }
 
+    GridResolvedPosition& operator*()
+    {
+        return *this;
+    }
+
     GridResolvedPosition& operator++()
     {
         m_integerPosition++;
@@ -106,6 +111,11 @@ public:
         return m_integerPosition == other.m_integerPosition;
     }
 
+    bool operator!=(const GridResolvedPosition& other) const
+    {
+        return m_integerPosition != other.m_integerPosition;
+    }
+
     bool operator<(const GridResolvedPosition& other) const
     {
         return m_integerPosition < other.m_integerPosition;