Title: [201379] trunk/Source/WebCore
Revision
201379
Author
[email protected]
Date
2016-05-25 04:32:30 -0700 (Wed, 25 May 2016)

Log Message

[css-grid] Refactor populateGridPositions()
https://bugs.webkit.org/show_bug.cgi?id=158065

Reviewed by Carlos Garcia Campos.

RenderGrid::populateGridPositions() was doing exactly the same thing for columns and rows
but using different data structures. That lead to a lot of duplicated code. It's easy to
refactor it in a new function that properly select the data structures to operate on based
on the direction.

No new tests as there is no change in behaviour.

* rendering/RenderGrid.cpp:
(WebCore::RenderGrid::layoutGridItems):
(WebCore::RenderGrid::populateGridPositionsForDirection): Refactored from
populateGridPositions().
(WebCore::RenderGrid::populateGridPositions): Deleted.
* rendering/RenderGrid.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (201378 => 201379)


--- trunk/Source/WebCore/ChangeLog	2016-05-25 11:17:38 UTC (rev 201378)
+++ trunk/Source/WebCore/ChangeLog	2016-05-25 11:32:30 UTC (rev 201379)
@@ -1,3 +1,24 @@
+2016-05-25  Sergio Villar Senin  <[email protected]>
+
+        [css-grid] Refactor populateGridPositions()
+        https://bugs.webkit.org/show_bug.cgi?id=158065
+
+        Reviewed by Carlos Garcia Campos.
+
+        RenderGrid::populateGridPositions() was doing exactly the same thing for columns and rows
+        but using different data structures. That lead to a lot of duplicated code. It's easy to
+        refactor it in a new function that properly select the data structures to operate on based
+        on the direction.
+
+        No new tests as there is no change in behaviour.
+
+        * rendering/RenderGrid.cpp:
+        (WebCore::RenderGrid::layoutGridItems):
+        (WebCore::RenderGrid::populateGridPositionsForDirection): Refactored from
+        populateGridPositions().
+        (WebCore::RenderGrid::populateGridPositions): Deleted.
+        * rendering/RenderGrid.h:
+
 2016-05-25  Commit Queue  <[email protected]>
 
         Unreviewed, rolling out r201373.

Modified: trunk/Source/WebCore/rendering/RenderGrid.cpp (201378 => 201379)


--- trunk/Source/WebCore/rendering/RenderGrid.cpp	2016-05-25 11:17:38 UTC (rev 201378)
+++ trunk/Source/WebCore/rendering/RenderGrid.cpp	2016-05-25 11:32:30 UTC (rev 201379)
@@ -1549,7 +1549,8 @@
 
 void RenderGrid::layoutGridItems(GridSizingData& sizingData)
 {
-    populateGridPositions(sizingData);
+    populateGridPositionsForDirection(sizingData, ForColumns);
+    populateGridPositionsForDirection(sizingData, ForRows);
 
     for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBox()) {
         if (child->isOutOfFlowPositioned()) {
@@ -1751,7 +1752,7 @@
     return finalTrackPosition - initialTrackPosition + tracks[span.endLine() - 1].baseSize();
 }
 
-void RenderGrid::populateGridPositions(GridSizingData& sizingData)
+void RenderGrid::populateGridPositionsForDirection(GridSizingData& sizingData, GridTrackSizingDirection direction)
 {
     // Since we add alignment offsets and track gutters, grid lines are not always adjacent. Hence we will have to
     // assume from now on that we just store positions of the initial grid lines of each track,
@@ -1760,31 +1761,23 @@
     // The grid container's frame elements (border, padding and <content-position> offset) are sensible to the
     // inline-axis flow direction. However, column lines positions are 'direction' unaware. This simplification
     // allows us to use the same indexes to identify the columns independently on the inline-axis direction.
-    unsigned numberOfTracks = sizingData.columnTracks.size();
+    bool isRowAxis = direction == ForColumns;
+    auto& tracks = isRowAxis ? sizingData.columnTracks : sizingData.rowTracks;
+    unsigned numberOfTracks = tracks.size();
     unsigned numberOfLines = numberOfTracks + 1;
     unsigned lastLine = numberOfLines - 1;
     unsigned nextToLastLine = numberOfLines - 2;
-    ContentAlignmentData offset = computeContentPositionAndDistributionOffset(ForColumns, sizingData.freeSpaceForDirection(ForColumns).value(), numberOfTracks);
-    LayoutUnit trackGap = guttersSize(ForColumns, 2);
-    m_columnPositions.resize(numberOfLines);
-    m_columnPositions[0] = borderAndPaddingLogicalLeft() + offset.positionOffset;
+    ContentAlignmentData offset = computeContentPositionAndDistributionOffset(direction, sizingData.freeSpaceForDirection(direction).value(), numberOfTracks);
+    LayoutUnit trackGap = guttersSize(direction, 2);
+    auto& positions = isRowAxis ? m_columnPositions : m_rowPositions;
+    positions.resize(numberOfLines);
+    auto borderAndPadding = isRowAxis ? borderAndPaddingLogicalLeft() : borderAndPaddingBefore();
+    positions[0] = borderAndPadding + offset.positionOffset;
     for (unsigned i = 0; i < nextToLastLine; ++i)
-        m_columnPositions[i + 1] = m_columnPositions[i] + offset.distributionOffset + sizingData.columnTracks[i].baseSize() + trackGap;
-    m_columnPositions[lastLine] = m_columnPositions[nextToLastLine] + sizingData.columnTracks[nextToLastLine].baseSize();
-    m_offsetBetweenColumns = offset.distributionOffset;
-
-    numberOfTracks = sizingData.rowTracks.size();
-    numberOfLines = numberOfTracks + 1;
-    lastLine = numberOfLines - 1;
-    nextToLastLine = numberOfLines - 2;
-    offset = computeContentPositionAndDistributionOffset(ForRows, sizingData.freeSpaceForDirection(ForRows).value(), numberOfTracks);
-    trackGap = guttersSize(ForRows, 2);
-    m_rowPositions.resize(numberOfLines);
-    m_rowPositions[0] = borderAndPaddingBefore() + offset.positionOffset;
-    for (unsigned i = 0; i < nextToLastLine; ++i)
-        m_rowPositions[i + 1] = m_rowPositions[i] + offset.distributionOffset + sizingData.rowTracks[i].baseSize() + trackGap;
-    m_rowPositions[lastLine] = m_rowPositions[nextToLastLine] + sizingData.rowTracks[nextToLastLine].baseSize();
-    m_offsetBetweenRows = offset.distributionOffset;
+        positions[i + 1] = positions[i] + offset.distributionOffset + tracks[i].baseSize() + trackGap;
+    positions[lastLine] = positions[nextToLastLine] + tracks[nextToLastLine].baseSize();
+    auto& offsetBetweenTracks = isRowAxis ? m_offsetBetweenColumns : m_offsetBetweenRows;
+    offsetBetweenTracks = offset.distributionOffset;
 }
 
 static inline LayoutUnit computeOverflowAlignmentOffset(OverflowAlignment overflow, LayoutUnit trackBreadth, LayoutUnit childBreadth)

Modified: trunk/Source/WebCore/rendering/RenderGrid.h (201378 => 201379)


--- trunk/Source/WebCore/rendering/RenderGrid.h	2016-05-25 11:17:38 UTC (rev 201378)
+++ trunk/Source/WebCore/rendering/RenderGrid.h	2016-05-25 11:32:30 UTC (rev 201379)
@@ -103,7 +103,7 @@
     void computeTrackSizesForDirection(GridTrackSizingDirection, GridSizingData&, LayoutUnit freeSpace);
 
     void layoutGridItems(GridSizingData&);
-    void populateGridPositions(GridSizingData&);
+    void populateGridPositionsForDirection(GridSizingData&, GridTrackSizingDirection);
     void clearGrid();
 
     enum TrackSizeRestriction {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to