[css-grid] Refactor information stored related to column positions
authorrego@igalia.com <rego@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 May 2016 20:32:06 +0000 (20:32 +0000)
committerrego@igalia.com <rego@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 May 2016 20:32:06 +0000 (20:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=157342

Reviewed by Darin Adler.

In m_columnPositions we were storing position of each column
including the alignment offset, always from the logical left,
and the border and padding, depending on the direction.

This was really confusing as in the case of RTL direction
we were adding the offset from the left and
the right border and padding.

This patches changes it to store always the info from the left,
so even in RTL direction we use the left border and padding.

This allows us to simplify translateRTLCoordinate() as
it doesn't need to care about border and padding anymore.
And also to refactor offsetAndBreadthForPositionedChild()
which became really complex after adding RTL support.

No new tests, no change of behavior.

* rendering/RenderGrid.cpp:
(WebCore::RenderGrid::offsetAndBreadthForPositionedChild):
(WebCore::RenderGrid::populateGridPositions):
(WebCore::RenderGrid::translateRTLCoordinate):

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

Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderGrid.cpp

index 02d45a8..deaba9a 100644 (file)
@@ -1,3 +1,33 @@
+2016-05-04  Manuel Rego Casasnovas  <rego@igalia.com>
+
+        [css-grid] Refactor information stored related to column positions
+        https://bugs.webkit.org/show_bug.cgi?id=157342
+
+        Reviewed by Darin Adler.
+
+        In m_columnPositions we were storing position of each column
+        including the alignment offset, always from the logical left,
+        and the border and padding, depending on the direction.
+
+        This was really confusing as in the case of RTL direction
+        we were adding the offset from the left and
+        the right border and padding.
+
+        This patches changes it to store always the info from the left,
+        so even in RTL direction we use the left border and padding.
+
+        This allows us to simplify translateRTLCoordinate() as
+        it doesn't need to care about border and padding anymore.
+        And also to refactor offsetAndBreadthForPositionedChild()
+        which became really complex after adding RTL support.
+
+        No new tests, no change of behavior.
+
+        * rendering/RenderGrid.cpp:
+        (WebCore::RenderGrid::offsetAndBreadthForPositionedChild):
+        (WebCore::RenderGrid::populateGridPositions):
+        (WebCore::RenderGrid::translateRTLCoordinate):
+
 2016-05-04  Mark Lam  <mark.lam@apple.com>
 
         ES6 Function.name inferred from property names of literal objects can break some websites.
index 1913861..bbfbf6e 100644 (file)
@@ -1560,18 +1560,24 @@ void RenderGrid::offsetAndBreadthForPositionedChild(const RenderBox& child, Grid
     // We're normalizing the positions to avoid issues with RTL (as they're stored in the same order than LTR but adding an offset).
     LayoutUnit start;
     if (!startIsAuto) {
-        if (isRowAxis)
-            start = m_columnPositions[startLine] - m_columnPositions[0] + paddingStart();
-        else
-            start = m_rowPositions[startLine] - m_rowPositions[0] + paddingBefore();
+        if (isRowAxis) {
+            if (style().isLeftToRightDirection())
+                start = m_columnPositions[startLine] - borderLogicalLeft();
+            else
+                start = logicalWidth() - translateRTLCoordinate(m_columnPositions[startLine]) - borderLogicalRight();
+        } else
+            start = m_rowPositions[startLine] - borderBefore();
     }
 
     LayoutUnit end = isRowAxis ? clientLogicalWidth() : clientLogicalHeight();
     if (!endIsAuto) {
-        if (isRowAxis)
-            end = m_columnPositions[endLine] - m_columnPositions[0] + paddingStart();
-        else
-            end = m_rowPositions[endLine] - m_rowPositions[0] + paddingBefore();
+        if (isRowAxis) {
+            if (style().isLeftToRightDirection())
+                end = m_columnPositions[endLine] - borderLogicalLeft();
+            else
+                end = logicalWidth() - translateRTLCoordinate(m_columnPositions[endLine]) - borderLogicalRight();
+        } else
+            end = m_rowPositions[endLine] - borderBefore();
 
         // These vectors store line positions including gaps, but we shouldn't consider them for the edges of the grid.
         if (endLine > firstExplicitLine && endLine < lastExplicitLine) {
@@ -1580,15 +1586,6 @@ void RenderGrid::offsetAndBreadthForPositionedChild(const RenderBox& child, Grid
         }
     }
 
-    LayoutUnit alignmentOffset = isRowAxis ? m_columnPositions[0] - borderAndPaddingStart() : m_rowPositions[0] - borderAndPaddingBefore();
-    if (isRowAxis && !style().isLeftToRightDirection())
-        alignmentOffset = contentLogicalWidth() - (m_columnPositions[m_columnPositions.size() - 1] - borderAndPaddingStart());
-
-    if (!startIsAuto)
-        start += alignmentOffset;
-    if (!endIsAuto)
-        end += alignmentOffset;
-
     breadth = end - start;
     offset = start;
 
@@ -1672,7 +1669,7 @@ void RenderGrid::populateGridPositions(GridSizingData& sizingData)
     ContentAlignmentData offset = computeContentPositionAndDistributionOffset(ForColumns, sizingData.freeSpaceForDirection(ForColumns).value(), numberOfTracks);
     LayoutUnit trackGap = guttersSize(ForColumns, 2);
     m_columnPositions.resize(numberOfLines);
-    m_columnPositions[0] = borderAndPaddingStart() + offset.positionOffset;
+    m_columnPositions[0] = borderAndPaddingLogicalLeft() + 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();
@@ -2098,9 +2095,9 @@ LayoutUnit RenderGrid::translateRTLCoordinate(LayoutUnit coordinate) const
 {
     ASSERT(!style().isLeftToRightDirection());
 
-    LayoutUnit alignmentOffset = m_columnPositions[0] - borderAndPaddingStart();
+    LayoutUnit alignmentOffset = m_columnPositions[0];
     LayoutUnit rightGridEdgePosition = m_columnPositions[m_columnPositions.size() - 1];
-    return borderAndPaddingLogicalLeft() + rightGridEdgePosition + alignmentOffset - coordinate;
+    return rightGridEdgePosition + alignmentOffset - coordinate;
 }
 
 LayoutPoint RenderGrid::findChildLogicalPosition(const RenderBox& child) const