Title: [143941] trunk/Source/WebCore
Revision
143941
Author
[email protected]
Date
2013-02-25 10:08:50 -0800 (Mon, 25 Feb 2013)

Log Message

[CSS Grid Layout] Refactor RenderStyle's grid position storage in preparation to supporting spanning
https://bugs.webkit.org/show_bug.cgi?id=110651

Reviewed by Ojan Vafai.

The current code stores grid-{row|column} as a single GridPosition value. While this works well currently,
we want to be able to handle 2 GridPosition as this enables row / column spanning.

That's what this refactoring achieves: it replaces the internal storage by a GridPositions that contains a
single GridPosition for now. The rest is mechanical updates.

Refactoring covered by existing tests.

* css/CSSComputedStyleDeclaration.cpp:
(WebCore::valueForGridPositions):
(WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue):
Added the simple wrapper valueForGridPositions and updated the rest of the code.

* css/StyleResolver.cpp:
(WebCore::createGridPositions):
(WebCore::StyleResolver::applyProperty):
Ditto with createGridPositions.

* rendering/RenderGrid.cpp:
(WebCore::RenderGrid::maximumIndexInDirection):
(WebCore::RenderGrid::placeItemsOnGrid):
(WebCore::RenderGrid::placeSpecifiedMajorAxisItemsOnGrid):
(WebCore::RenderGrid::placeAutoMajorAxisItemsOnGrid):
(WebCore::RenderGrid::placeAutoMajorAxisItemOnGrid):
(WebCore::RenderGrid::autoPlacementMajorAxisPositionsForChild):
(WebCore::RenderGrid::autoPlacementMinorAxisPositionsForChild):
Updated the code after adding the indirection: s/GridPosition/GridPositions/ and
use the firstPosition helper.

* rendering/RenderGrid.h:
* rendering/style/GridPosition.h:
(WebCore::GridPositions::GridPositions):
(WebCore::GridPositions::firstPosition):
(WebCore::GridPositions::operator==):
Added this class to add the indirection. For now, it only wraps the single GridPosition.

* rendering/style/RenderStyle.h:
* rendering/style/StyleGridItemData.h:
Updated to store / take / return a GridPositions.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (143940 => 143941)


--- trunk/Source/WebCore/ChangeLog	2013-02-25 18:02:42 UTC (rev 143940)
+++ trunk/Source/WebCore/ChangeLog	2013-02-25 18:08:50 UTC (rev 143941)
@@ -1,3 +1,50 @@
+2013-02-25  Julien Chaffraix  <[email protected]>
+
+        [CSS Grid Layout] Refactor RenderStyle's grid position storage in preparation to supporting spanning
+        https://bugs.webkit.org/show_bug.cgi?id=110651
+
+        Reviewed by Ojan Vafai.
+
+        The current code stores grid-{row|column} as a single GridPosition value. While this works well currently,
+        we want to be able to handle 2 GridPosition as this enables row / column spanning.
+
+        That's what this refactoring achieves: it replaces the internal storage by a GridPositions that contains a 
+        single GridPosition for now. The rest is mechanical updates.
+
+        Refactoring covered by existing tests.
+
+        * css/CSSComputedStyleDeclaration.cpp:
+        (WebCore::valueForGridPositions):
+        (WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue):
+        Added the simple wrapper valueForGridPositions and updated the rest of the code.
+
+        * css/StyleResolver.cpp:
+        (WebCore::createGridPositions):
+        (WebCore::StyleResolver::applyProperty):
+        Ditto with createGridPositions.
+
+        * rendering/RenderGrid.cpp:
+        (WebCore::RenderGrid::maximumIndexInDirection):
+        (WebCore::RenderGrid::placeItemsOnGrid):
+        (WebCore::RenderGrid::placeSpecifiedMajorAxisItemsOnGrid):
+        (WebCore::RenderGrid::placeAutoMajorAxisItemsOnGrid):
+        (WebCore::RenderGrid::placeAutoMajorAxisItemOnGrid):
+        (WebCore::RenderGrid::autoPlacementMajorAxisPositionsForChild):
+        (WebCore::RenderGrid::autoPlacementMinorAxisPositionsForChild):
+        Updated the code after adding the indirection: s/GridPosition/GridPositions/ and
+        use the firstPosition helper.
+
+        * rendering/RenderGrid.h:
+        * rendering/style/GridPosition.h:
+        (WebCore::GridPositions::GridPositions):
+        (WebCore::GridPositions::firstPosition):
+        (WebCore::GridPositions::operator==):
+        Added this class to add the indirection. For now, it only wraps the single GridPosition.
+
+        * rendering/style/RenderStyle.h:
+        * rendering/style/StyleGridItemData.h:
+        Updated to store / take / return a GridPositions.
+
 2013-02-25  Dimitri Glazkov  <[email protected]>
 
         Revert r143840 because it caused flaky crashes.

Modified: trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp (143940 => 143941)


--- trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2013-02-25 18:02:42 UTC (rev 143940)
+++ trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2013-02-25 18:08:50 UTC (rev 143941)
@@ -1067,6 +1067,12 @@
 
     return cssValuePool().createValue(position.integerPosition(), CSSPrimitiveValue::CSS_NUMBER);
 }
+
+static PassRefPtr<CSSValue> valueForGridPositions(const GridPositions& positions)
+{
+    return valueForGridPosition(positions.firstPosition());
+}
+
 static PassRefPtr<CSSValue> createTransitionPropertyValue(const Animation* animation)
 {
     RefPtr<CSSValue> propertyValue;
@@ -1925,9 +1931,9 @@
             return valueForGridTrackList(style->gridRows(), style.get(), m_node->document()->renderView());
 
         case CSSPropertyWebkitGridColumn:
-            return valueForGridPosition(style->gridItemColumn());
+            return valueForGridPositions(style->gridItemColumn());
         case CSSPropertyWebkitGridRow:
-            return valueForGridPosition(style->gridItemRow());
+            return valueForGridPositions(style->gridItemRow());
 
         case CSSPropertyHeight:
             if (renderer) {

Modified: trunk/Source/WebCore/css/StyleResolver.cpp (143940 => 143941)


--- trunk/Source/WebCore/css/StyleResolver.cpp	2013-02-25 18:02:42 UTC (rev 143940)
+++ trunk/Source/WebCore/css/StyleResolver.cpp	2013-02-25 18:08:50 UTC (rev 143941)
@@ -2692,7 +2692,7 @@
 }
 
 
-static bool createGridPosition(CSSValue* value, GridPosition& position)
+static bool createGridPositions(CSSValue* value, GridPositions& position)
 {
     // For now, we only accept: <integer> | 'auto'
     if (!value->isPrimitiveValue())
@@ -2703,7 +2703,7 @@
         return true;
 
     ASSERT_WITH_SECURITY_IMPLICATION(primitiveValue->isNumber());
-    position.setIntegerPosition(primitiveValue->getIntValue());
+    position.firstPosition().setIntegerPosition(primitiveValue->getIntValue());
     return true;
 }
 
@@ -3563,15 +3563,15 @@
     }
 
     case CSSPropertyWebkitGridColumn: {
-        GridPosition column;
-        if (!createGridPosition(value, column))
+        GridPositions column;
+        if (!createGridPositions(value, column))
             return;
         state.style()->setGridItemColumn(column);
         return;
     }
     case CSSPropertyWebkitGridRow: {
-        GridPosition row;
-        if (!createGridPosition(value, row))
+        GridPositions row;
+        if (!createGridPositions(value, row))
             return;
         state.style()->setGridItemRow(row);
         return;

Modified: trunk/Source/WebCore/rendering/RenderGrid.cpp (143940 => 143941)


--- trunk/Source/WebCore/rendering/RenderGrid.cpp	2013-02-25 18:02:42 UTC (rev 143940)
+++ trunk/Source/WebCore/rendering/RenderGrid.cpp	2013-02-25 18:08:50 UTC (rev 143941)
@@ -334,14 +334,14 @@
     size_t maximumIndex = std::max<size_t>(1, trackStyles.size());
 
     for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBox()) {
-        const GridPosition& position = (direction == ForColumns) ? child->style()->gridItemColumn() : child->style()->gridItemRow();
+        const GridPositions& positions = (direction == ForColumns) ? child->style()->gridItemColumn() : child->style()->gridItemRow();
         // 'auto' items will need to be resolved in seperate phases anyway. Note that because maximumIndex is at least 1,
         // the grid-auto-flow == none case is automatically handled.
-        if (position.isAuto())
+        if (positions.firstPosition().isAuto())
             continue;
 
         // This function bypasses the cache (cachedGridCoordinate()) as it is used to build it.
-        maximumIndex = std::max(maximumIndex, resolveGridPositionFromStyle(position) + 1);
+        maximumIndex = std::max(maximumIndex, resolveGridPositionFromStyle(positions.firstPosition()) + 1);
     }
 
     return maximumIndex;
@@ -526,18 +526,18 @@
     Vector<RenderBox*> specifiedMajorAxisAutoGridItems;
     GridAutoFlow autoFlow = style()->gridAutoFlow();
     for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBox()) {
-        const GridPosition& columnPosition = child->style()->gridItemColumn();
-        const GridPosition& rowPosition = child->style()->gridItemRow();
-        if (autoFlow != AutoFlowNone && (columnPosition.isAuto() || rowPosition.isAuto())) {
-            const GridPosition& majorAxisPosition = autoPlacementMajorAxisPositionForChild(child);
-            if (majorAxisPosition.isAuto())
+        const GridPositions& columnPositions = child->style()->gridItemColumn();
+        const GridPositions& rowPositions = child->style()->gridItemRow();
+        if (autoFlow != AutoFlowNone && (columnPositions.firstPosition().isAuto() || rowPositions.firstPosition().isAuto())) {
+            const GridPositions& majorAxisPositions = autoPlacementMajorAxisPositionsForChild(child);
+            if (majorAxisPositions.firstPosition().isAuto())
                 autoMajorAxisAutoGridItems.append(child);
             else
                 specifiedMajorAxisAutoGridItems.append(child);
             continue;
         }
-        size_t columnTrack = resolveGridPositionFromStyle(columnPosition);
-        size_t rowTrack = resolveGridPositionFromStyle(rowPosition);
+        size_t columnTrack = resolveGridPositionFromStyle(columnPositions.firstPosition());
+        size_t rowTrack = resolveGridPositionFromStyle(rowPositions.firstPosition());
         insertItemIntoGrid(child, rowTrack, columnTrack);
     }
 
@@ -558,9 +558,9 @@
 void RenderGrid::placeSpecifiedMajorAxisItemsOnGrid(Vector<RenderBox*> autoGridItems)
 {
     for (size_t i = 0; i < autoGridItems.size(); ++i) {
-        const GridPosition& majorAxisPosition = autoPlacementMajorAxisPositionForChild(autoGridItems[i]);
-        ASSERT(!majorAxisPosition.isAuto());
-        GridIterator iterator(m_grid, autoPlacementMajorAxisDirection(), resolveGridPositionFromStyle(majorAxisPosition));
+        const GridPositions& majorAxisPositions = autoPlacementMajorAxisPositionsForChild(autoGridItems[i]);
+        ASSERT(!majorAxisPositions.firstPosition().isAuto());
+        GridIterator iterator(m_grid, autoPlacementMajorAxisDirection(), resolveGridPositionFromStyle(majorAxisPositions.firstPosition()));
         if (OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea()) {
             insertItemIntoGrid(autoGridItems[i], emptyGridArea->rowIndex, emptyGridArea->columnIndex);
             continue;
@@ -576,18 +576,18 @@
 void RenderGrid::placeAutoMajorAxisItemsOnGrid(Vector<RenderBox*> autoGridItems)
 {
     for (size_t i = 0; i < autoGridItems.size(); ++i) {
-        ASSERT(autoPlacementMajorAxisPositionForChild(autoGridItems[i]).isAuto());
+        ASSERT(autoPlacementMajorAxisPositionsForChild(autoGridItems[i]).firstPosition().isAuto());
         placeAutoMajorAxisItemOnGrid(autoGridItems[i]);
     }
 }
 
 void RenderGrid::placeAutoMajorAxisItemOnGrid(RenderBox* gridItem)
 {
-    ASSERT(autoPlacementMajorAxisPositionForChild(gridItem).isAuto());
-    const GridPosition& minorAxisPosition = autoPlacementMinorAxisPositionForChild(gridItem);
+    ASSERT(autoPlacementMajorAxisPositionsForChild(gridItem).firstPosition().isAuto());
+    const GridPositions& minorAxisPositions = autoPlacementMinorAxisPositionsForChild(gridItem);
     size_t minorAxisIndex = 0;
-    if (!minorAxisPosition.isAuto()) {
-        minorAxisIndex = resolveGridPositionFromStyle(minorAxisPosition);
+    if (!minorAxisPositions.firstPosition().isAuto()) {
+        minorAxisIndex = resolveGridPositionFromStyle(minorAxisPositions.firstPosition());
         GridIterator iterator(m_grid, autoPlacementMinorAxisDirection(), minorAxisIndex);
         if (OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea()) {
             insertItemIntoGrid(gridItem, emptyGridArea->rowIndex, emptyGridArea->columnIndex);
@@ -611,14 +611,14 @@
     insertItemIntoGrid(gridItem, rowIndex, columnIndex);
 }
 
-const GridPosition& RenderGrid::autoPlacementMajorAxisPositionForChild(const RenderBox* gridItem) const
+const GridPositions& RenderGrid::autoPlacementMajorAxisPositionsForChild(const RenderBox* gridItem) const
 {
     GridAutoFlow flow = style()->gridAutoFlow();
     ASSERT(flow != AutoFlowNone);
     return (flow == AutoFlowColumn) ? gridItem->style()->gridItemColumn() : gridItem->style()->gridItemRow();
 }
 
-const GridPosition& RenderGrid::autoPlacementMinorAxisPositionForChild(const RenderBox* gridItem) const
+const GridPositions& RenderGrid::autoPlacementMinorAxisPositionsForChild(const RenderBox* gridItem) const
 {
     GridAutoFlow flow = style()->gridAutoFlow();
     ASSERT(flow != AutoFlowNone);

Modified: trunk/Source/WebCore/rendering/RenderGrid.h (143940 => 143941)


--- trunk/Source/WebCore/rendering/RenderGrid.h	2013-02-25 18:02:42 UTC (rev 143940)
+++ trunk/Source/WebCore/rendering/RenderGrid.h	2013-02-25 18:08:50 UTC (rev 143941)
@@ -82,8 +82,8 @@
     void placeSpecifiedMajorAxisItemsOnGrid(Vector<RenderBox*>);
     void placeAutoMajorAxisItemsOnGrid(Vector<RenderBox*>);
     void placeAutoMajorAxisItemOnGrid(RenderBox*);
-    const GridPosition& autoPlacementMajorAxisPositionForChild(const RenderBox*) const;
-    const GridPosition& autoPlacementMinorAxisPositionForChild(const RenderBox*) const;
+    const GridPositions& autoPlacementMajorAxisPositionsForChild(const RenderBox*) const;
+    const GridPositions& autoPlacementMinorAxisPositionsForChild(const RenderBox*) const;
     TrackSizingDirection autoPlacementMajorAxisDirection() const;
     TrackSizingDirection autoPlacementMinorAxisDirection() const;
 

Modified: trunk/Source/WebCore/rendering/style/GridPosition.h (143940 => 143941)


--- trunk/Source/WebCore/rendering/style/GridPosition.h	2013-02-25 18:02:42 UTC (rev 143940)
+++ trunk/Source/WebCore/rendering/style/GridPosition.h	2013-02-25 18:08:50 UTC (rev 143941)
@@ -74,6 +74,24 @@
     int m_integerPosition;
 };
 
+class GridPositions {
+public:
+    GridPositions()
+    {
+    }
+
+    const GridPosition& firstPosition() const { return m_firstPosition; }
+    GridPosition& firstPosition() { return m_firstPosition; }
+
+    bool operator==(const GridPositions& other) const
+    {
+        return m_firstPosition == other.m_firstPosition;
+    }
+
+private:
+    GridPosition m_firstPosition;
+};
+
 } // namespace WebCore
 
 #endif // GridPosition_h

Modified: trunk/Source/WebCore/rendering/style/RenderStyle.h (143940 => 143941)


--- trunk/Source/WebCore/rendering/style/RenderStyle.h	2013-02-25 18:02:42 UTC (rev 143940)
+++ trunk/Source/WebCore/rendering/style/RenderStyle.h	2013-02-25 18:08:50 UTC (rev 143941)
@@ -765,8 +765,8 @@
     const Vector<GridTrackSize>& gridRows() const { return rareNonInheritedData->m_grid->m_gridRows; }
     GridAutoFlow gridAutoFlow() const { return rareNonInheritedData->m_grid->m_gridAutoFlow; }
 
-    const GridPosition& gridItemColumn() const { return rareNonInheritedData->m_gridItem->m_gridColumn; }
-    const GridPosition& gridItemRow() const { return rareNonInheritedData->m_gridItem->m_gridRow; }
+    const GridPositions& gridItemColumn() const { return rareNonInheritedData->m_gridItem->m_gridColumn; }
+    const GridPositions& gridItemRow() const { return rareNonInheritedData->m_gridItem->m_gridRow; }
 
     const ShadowData* boxShadow() const { return rareNonInheritedData->m_boxShadow.get(); }
     void getBoxShadowExtent(LayoutUnit& top, LayoutUnit& right, LayoutUnit& bottom, LayoutUnit& left) const { getShadowExtent(boxShadow(), top, right, bottom, left); }
@@ -1253,8 +1253,8 @@
     void setGridColumns(const Vector<GridTrackSize>& lengths) { SET_VAR(rareNonInheritedData.access()->m_grid, m_gridColumns, lengths); }
     void setGridRows(const Vector<GridTrackSize>& lengths) { SET_VAR(rareNonInheritedData.access()->m_grid, m_gridRows, lengths); }
     void setGridAutoFlow(GridAutoFlow flow) { SET_VAR(rareNonInheritedData.access()->m_grid, m_gridAutoFlow, flow); }
-    void setGridItemColumn(const GridPosition& columnPosition) { SET_VAR(rareNonInheritedData.access()->m_gridItem, m_gridColumn, columnPosition); }
-    void setGridItemRow(const GridPosition& rowPosition) { SET_VAR(rareNonInheritedData.access()->m_gridItem, m_gridRow, rowPosition); }
+    void setGridItemColumn(const GridPositions& columnPosition) { SET_VAR(rareNonInheritedData.access()->m_gridItem, m_gridColumn, columnPosition); }
+    void setGridItemRow(const GridPositions& rowPosition) { SET_VAR(rareNonInheritedData.access()->m_gridItem, m_gridRow, rowPosition); }
 
     void setMarqueeIncrement(const Length& f) { SET_VAR(rareNonInheritedData.access()->m_marquee, increment, f); }
     void setMarqueeSpeed(int f) { SET_VAR(rareNonInheritedData.access()->m_marquee, speed, f); }
@@ -1663,9 +1663,9 @@
 
     static GridAutoFlow initialGridAutoFlow() { return AutoFlowNone; }
 
-    // 'auto' is the default.
-    static GridPosition initialGridItemColumn() { return GridPosition(); }
-    static GridPosition initialGridItemRow() { return GridPosition(); }
+    // 'auto' / 'auto' is the default.
+    static GridPositions initialGridItemColumn() { return GridPositions(); }
+    static GridPositions initialGridItemRow() { return GridPositions(); }
 
     static unsigned initialTabSize() { return 8; }
 

Modified: trunk/Source/WebCore/rendering/style/StyleGridItemData.h (143940 => 143941)


--- trunk/Source/WebCore/rendering/style/StyleGridItemData.h	2013-02-25 18:02:42 UTC (rev 143940)
+++ trunk/Source/WebCore/rendering/style/StyleGridItemData.h	2013-02-25 18:08:50 UTC (rev 143941)
@@ -54,8 +54,8 @@
         return !(*this == o);
     }
 
-    GridPosition m_gridColumn;
-    GridPosition m_gridRow;
+    GridPositions m_gridColumn;
+    GridPositions m_gridRow;
 
 private:
     StyleGridItemData();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to