Title: [208995] trunk/Source/WebCore
Revision
208995
Author
[email protected]
Date
2016-11-28 03:28:41 -0800 (Mon, 28 Nov 2016)

Log Message

[css-grid] Move attributes from RenderGrid to the new Grid class
https://bugs.webkit.org/show_bug.cgi?id=165065

Reviewed by Darin Adler.

A new class called Grid was added in 208973. This is the first of a couple of patches moving
private attributes from RenderGrid to Grid.

Apart from that this is adding a couple of new helper functions that will decouple the
existence of in-flow items from the actual data structures storing that information.

Last but not least, the Grid::insert() method does not only insert the item in the m_grid
data structure, but also stores the GridArea associated to that item, so there is no need to
do it in two different calls.

No new tests required as this is a refactoring.

* rendering/RenderGrid.cpp:
(WebCore::RenderGrid::Grid::insert): Added a new parameter.
(WebCore::RenderGrid::Grid::setSmallestTracksStart):
(WebCore::RenderGrid::Grid::smallestTrackStart):
(WebCore::RenderGrid::Grid::gridItemArea):
(WebCore::RenderGrid::Grid::setGridItemArea):
(WebCore::RenderGrid::Grid::clear): Clear the newly added attributes.
(WebCore::RenderGrid::repeatTracksSizingIfNeeded):
(WebCore::RenderGrid::computeUsedBreadthOfGridTracks):
(WebCore::RenderGrid::rawGridTrackSize):
(WebCore::RenderGrid::resolveContentBasedTrackSizingFunctions):
(WebCore::RenderGrid::computeEmptyTracksForAutoRepeat):
(WebCore::RenderGrid::placeItemsOnGrid):
(WebCore::RenderGrid::populateExplicitGridAndOrderIterator):
(WebCore::RenderGrid::placeSpecifiedMajorAxisItemsOnGrid):
(WebCore::RenderGrid::placeAutoMajorAxisItemOnGrid):
(WebCore::RenderGrid::clearGrid):
(WebCore::RenderGrid::offsetAndBreadthForPositionedChild):
(WebCore::RenderGrid::cachedGridSpan):
(WebCore::RenderGrid::cachedGridArea): Deleted.
* rendering/RenderGrid.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (208994 => 208995)


--- trunk/Source/WebCore/ChangeLog	2016-11-28 04:30:44 UTC (rev 208994)
+++ trunk/Source/WebCore/ChangeLog	2016-11-28 11:28:41 UTC (rev 208995)
@@ -1,3 +1,44 @@
+2016-11-24  Sergio Villar Senin  <[email protected]>
+
+        [css-grid] Move attributes from RenderGrid to the new Grid class
+        https://bugs.webkit.org/show_bug.cgi?id=165065
+
+        Reviewed by Darin Adler.
+
+        A new class called Grid was added in 208973. This is the first of a couple of patches moving
+        private attributes from RenderGrid to Grid.
+
+        Apart from that this is adding a couple of new helper functions that will decouple the
+        existence of in-flow items from the actual data structures storing that information.
+
+        Last but not least, the Grid::insert() method does not only insert the item in the m_grid
+        data structure, but also stores the GridArea associated to that item, so there is no need to
+        do it in two different calls.
+
+        No new tests required as this is a refactoring.
+
+        * rendering/RenderGrid.cpp:
+        (WebCore::RenderGrid::Grid::insert): Added a new parameter.
+        (WebCore::RenderGrid::Grid::setSmallestTracksStart):
+        (WebCore::RenderGrid::Grid::smallestTrackStart):
+        (WebCore::RenderGrid::Grid::gridItemArea):
+        (WebCore::RenderGrid::Grid::setGridItemArea):
+        (WebCore::RenderGrid::Grid::clear): Clear the newly added attributes.
+        (WebCore::RenderGrid::repeatTracksSizingIfNeeded):
+        (WebCore::RenderGrid::computeUsedBreadthOfGridTracks):
+        (WebCore::RenderGrid::rawGridTrackSize):
+        (WebCore::RenderGrid::resolveContentBasedTrackSizingFunctions):
+        (WebCore::RenderGrid::computeEmptyTracksForAutoRepeat):
+        (WebCore::RenderGrid::placeItemsOnGrid):
+        (WebCore::RenderGrid::populateExplicitGridAndOrderIterator):
+        (WebCore::RenderGrid::placeSpecifiedMajorAxisItemsOnGrid):
+        (WebCore::RenderGrid::placeAutoMajorAxisItemOnGrid):
+        (WebCore::RenderGrid::clearGrid):
+        (WebCore::RenderGrid::offsetAndBreadthForPositionedChild):
+        (WebCore::RenderGrid::cachedGridSpan):
+        (WebCore::RenderGrid::cachedGridArea): Deleted.
+        * rendering/RenderGrid.h:
+
 2016-11-27  Sam Weinig  <[email protected]>
 
         Remove unused DOMRequestState

Modified: trunk/Source/WebCore/rendering/RenderGrid.cpp (208994 => 208995)


--- trunk/Source/WebCore/rendering/RenderGrid.cpp	2016-11-28 04:30:44 UTC (rev 208994)
+++ trunk/Source/WebCore/rendering/RenderGrid.cpp	2016-11-28 11:28:41 UTC (rev 208995)
@@ -71,11 +71,39 @@
         for (const auto& column : area.columns)
             m_grid[row][column].append(&child);
     }
+
+    setGridItemArea(child, area);
 }
 
+void RenderGrid::Grid::setSmallestTracksStart(int rowStart, int columnStart)
+{
+    m_smallestRowStart = rowStart;
+    m_smallestColumnStart = columnStart;
+}
+
+int RenderGrid::Grid::smallestTrackStart(GridTrackSizingDirection direction) const
+{
+    return direction == ForRows ? m_smallestRowStart : m_smallestColumnStart;
+}
+
+GridArea RenderGrid::Grid::gridItemArea(const RenderBox& item) const
+{
+    ASSERT(m_gridItemArea.contains(&item));
+    return m_gridItemArea.get(&item);
+}
+
+void RenderGrid::Grid::setGridItemArea(const RenderBox& item, GridArea area)
+{
+    m_gridItemArea.set(&item, area);
+}
+
 void RenderGrid::Grid::clear()
 {
     m_grid.resize(0);
+    m_gridItemArea.clear();
+    m_hasAnyOrthogonalGridItem = false;
+    m_smallestRowStart = 0;
+    m_smallestColumnStart = 0;
 }
 
 class GridTrack {
@@ -467,7 +495,7 @@
     // a new cycle of the sizing algorithm; there may be more. In addition, not all the
     // cases with orthogonal flows require this extra cycle; we need a more specific
     // condition to detect whether child's min-content contribution has changed or not.
-    if (m_hasAnyOrthogonalChild) {
+    if (m_grid.hasAnyOrthogonalGridItem()) {
         computeTrackSizesForDirection(ForColumns, sizingData, availableSpaceForColumns);
         computeTrackSizesForDirection(ForRows, sizingData, availableSpaceForRows);
     }
@@ -821,7 +849,7 @@
         for (const auto& trackIndex : flexibleSizedTracksIndex)
             flexFraction = std::max(flexFraction, normalizedFlexFraction(tracks[trackIndex], gridTrackSize(direction, trackIndex, sizingData.sizingOperation).maxTrackBreadth().flex()));
 
-        if (!m_gridItemArea.isEmpty()) {
+        if (m_grid.hasGridItems()) {
             for (unsigned i = 0; i < flexibleSizedTracksIndex.size(); ++i) {
                 GridIterator iterator(m_grid, direction, flexibleSizedTracksIndex[i]);
                 while (auto* gridItem = iterator.nextGridItem()) {
@@ -1007,7 +1035,7 @@
     // grid-template-areas is specified for example).
     unsigned explicitTracksCount = trackStyles.size() + autoRepeatTracksCount;
 
-    int untranslatedIndexAsInt = translatedIndex + (isRowAxis ? m_smallestColumnStart : m_smallestRowStart);
+    int untranslatedIndexAsInt = translatedIndex + m_grid.smallestTrackStart(direction);
     unsigned autoTrackStylesSize = autoTrackStyles.size();
     if (untranslatedIndexAsInt < 0) {
         int index = untranslatedIndexAsInt % static_cast<int>(autoTrackStylesSize);
@@ -1220,7 +1248,7 @@
 {
     sizingData.itemsSortedByIncreasingSpan.shrink(0);
     HashSet<RenderBox*> itemsSet;
-    if (!m_gridItemArea.isEmpty()) {
+    if (m_grid.hasGridItems()) {
         for (auto trackIndex : sizingData.contentSizedTracksIndex) {
             GridIterator iterator(m_grid, direction, trackIndex);
             GridTrack& track = (direction == ForColumns) ? sizingData.columnTracks[trackIndex] : sizingData.rowTracks[trackIndex];
@@ -1629,10 +1657,10 @@
 
     std::unique_ptr<OrderedTrackIndexSet> emptyTrackIndexes;
     unsigned insertionPoint = isRowAxis ? style().gridAutoRepeatColumnsInsertionPoint() : style().gridAutoRepeatRowsInsertionPoint();
-    unsigned firstAutoRepeatTrack = insertionPoint + std::abs(isRowAxis ? m_smallestColumnStart : m_smallestRowStart);
+    unsigned firstAutoRepeatTrack = insertionPoint + std::abs(m_grid.smallestTrackStart(direction));
     unsigned lastAutoRepeatTrack = firstAutoRepeatTrack + autoRepeatCountForDirection(direction);
 
-    if (m_gridItemArea.isEmpty()) {
+    if (!m_grid.hasGridItems()) {
         emptyTrackIndexes = std::make_unique<OrderedTrackIndexSet>();
         for (unsigned trackIndex = firstAutoRepeatTrack; trackIndex < lastAutoRepeatTrack; ++trackIndex)
             emptyTrackIndexes->add(trackIndex);
@@ -1652,7 +1680,7 @@
 void RenderGrid::placeItemsOnGrid(SizingOperation sizingOperation)
 {
     ASSERT(m_gridIsDirty);
-    ASSERT(m_gridItemArea.isEmpty());
+    ASSERT(!m_grid.hasGridItems());
 
     m_autoRepeatColumns = computeAutoRepeatTracksCount(ForColumns, sizingOperation);
     m_autoRepeatRows = computeAutoRepeatTracksCount(ForRows, sizingOperation);
@@ -1659,24 +1687,24 @@
 
     populateExplicitGridAndOrderIterator();
     m_gridIsDirty = false;
+    bool hasAnyOrthogonalGridItem = false;
 
     Vector<RenderBox*> autoMajorAxisAutoGridItems;
     Vector<RenderBox*> specifiedMajorAxisAutoGridItems;
-    m_hasAnyOrthogonalChild = false;
     for (RenderBox* child = m_orderIterator.first(); child; child = m_orderIterator.next()) {
         if (child->isOutOfFlowPositioned())
             continue;
 
-        m_hasAnyOrthogonalChild = m_hasAnyOrthogonalChild || isOrthogonalChild(*child);
+        hasAnyOrthogonalGridItem = hasAnyOrthogonalGridItem || isOrthogonalChild(*child);
 
-        GridArea area = cachedGridArea(*child);
+        GridArea area = m_grid.gridItemArea(*child);
         if (!area.rows.isIndefinite())
-            area.rows.translate(std::abs(m_smallestRowStart));
+            area.rows.translate(std::abs(m_grid.smallestTrackStart(ForRows)));
         if (!area.columns.isIndefinite())
-            area.columns.translate(std::abs(m_smallestColumnStart));
-        m_gridItemArea.set(child, area);
+            area.columns.translate(std::abs(m_grid.smallestTrackStart(ForColumns)));
 
         if (area.rows.isIndefinite() || area.columns.isIndefinite()) {
+            m_grid.setGridItemArea(*child, area);
             bool majorAxisDirectionIsForColumns = autoPlacementMajorAxisDirection() == ForColumns;
             if ((majorAxisDirectionIsForColumns && area.columns.isIndefinite())
                 || (!majorAxisDirectionIsForColumns && area.rows.isIndefinite()))
@@ -1687,9 +1715,10 @@
         }
         m_grid.insert(*child, { area.rows, area.columns });
     }
+    m_grid.setHasAnyOrthogonalGridItem(hasAnyOrthogonalGridItem);
 
 #if ENABLE(ASSERT)
-    if (!m_gridItemArea.isEmpty()) {
+    if (m_grid.hasGridItems()) {
         ASSERT(gridRowCount() >= GridPositionsResolver::explicitGridRowCount(style(), m_autoRepeatRows));
         ASSERT(gridColumnCount() >= GridPositionsResolver::explicitGridColumnCount(style(), m_autoRepeatColumns));
     }
@@ -1707,7 +1736,7 @@
         if (child->isOutOfFlowPositioned())
             continue;
 
-        GridArea area = cachedGridArea(*child);
+        GridArea area = m_grid.gridItemArea(*child);
         ASSERT(area.rows.isTranslatedDefinite() && area.columns.isTranslatedDefinite());
     }
 #endif
@@ -1716,7 +1745,8 @@
 void RenderGrid::populateExplicitGridAndOrderIterator()
 {
     OrderIteratorPopulator populator(m_orderIterator);
-    m_smallestRowStart = m_smallestColumnStart = 0;
+    int smallestRowStart = 0;
+    int smallestColumnStart = 0;
     unsigned maximumRowIndex = GridPositionsResolver::explicitGridRowCount(style(), m_autoRepeatRows);
     unsigned maximumColumnIndex = GridPositionsResolver::explicitGridColumnCount(style(), m_autoRepeatColumns);
 
@@ -1728,7 +1758,7 @@
 
         GridSpan rowPositions = GridPositionsResolver::resolveGridPositionsFromStyle(style(), *child, ForRows, m_autoRepeatRows);
         if (!rowPositions.isIndefinite()) {
-            m_smallestRowStart = std::min(m_smallestRowStart, rowPositions.untranslatedStartLine());
+            smallestRowStart = std::min(smallestRowStart, rowPositions.untranslatedStartLine());
             maximumRowIndex = std::max<int>(maximumRowIndex, rowPositions.untranslatedEndLine());
         } else {
             // Grow the grid for items with a definite row span, getting the largest such span.
@@ -1738,7 +1768,7 @@
 
         GridSpan columnPositions = GridPositionsResolver::resolveGridPositionsFromStyle(style(), *child, ForColumns, m_autoRepeatColumns);
         if (!columnPositions.isIndefinite()) {
-            m_smallestColumnStart = std::min(m_smallestColumnStart, columnPositions.untranslatedStartLine());
+            smallestColumnStart = std::min(smallestColumnStart, columnPositions.untranslatedStartLine());
             maximumColumnIndex = std::max<int>(maximumColumnIndex, columnPositions.untranslatedEndLine());
         } else {
             // Grow the grid for items with a definite column span, getting the largest such span.
@@ -1746,10 +1776,11 @@
             maximumColumnIndex = std::max(maximumColumnIndex, spanSize);
         }
 
-        m_gridItemArea.set(child, GridArea(rowPositions, columnPositions));
+        m_grid.setGridItemArea(*child, { rowPositions, columnPositions });
     }
 
-    m_grid.ensureGridSize(maximumRowIndex + std::abs(m_smallestRowStart), maximumColumnIndex + std::abs(m_smallestColumnStart));
+    m_grid.setSmallestTracksStart(smallestRowStart, smallestColumnStart);
+    m_grid.ensureGridSize(maximumRowIndex + std::abs(smallestRowStart), maximumColumnIndex + std::abs(smallestColumnStart));
 }
 
 std::unique_ptr<GridArea> RenderGrid::createEmptyGridAreaAtSpecifiedPositionsOutsideGrid(const RenderBox& gridItem, GridTrackSizingDirection specifiedDirection, const GridSpan& specifiedPositions) const
@@ -1783,7 +1814,6 @@
         if (!emptyGridArea)
             emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid(*autoGridItem, autoPlacementMajorAxisDirection(), majorAxisPositions);
 
-        m_gridItemArea.set(autoGridItem, *emptyGridArea);
         m_grid.insert(*autoGridItem, *emptyGridArea);
 
         if (!isGridAutoFlowDense)
@@ -1856,7 +1886,6 @@
             emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid(gridItem, autoPlacementMinorAxisDirection(), GridSpan::translatedDefiniteGridSpan(0, minorAxisSpanSize));
     }
 
-    m_gridItemArea.set(&gridItem, *emptyGridArea);
     m_grid.insert(gridItem, *emptyGridArea);
     autoPlacementCursor.first = emptyGridArea->rows.startLine();
     autoPlacementCursor.second = emptyGridArea->columns.startLine();
@@ -1875,7 +1904,6 @@
 void RenderGrid::clearGrid()
 {
     m_grid.clear();
-    m_gridItemArea.clear();
     m_gridIsDirty = true;
 }
 
@@ -2054,7 +2082,7 @@
     }
 
     // For positioned items we cannot use GridSpan::translate() because we could end up with negative values, as the positioned items do not create implicit tracks per spec.
-    int smallestStart = std::abs(isRowAxis ? m_smallestColumnStart : m_smallestRowStart);
+    int smallestStart = std::abs(m_grid.smallestTrackStart(direction));
     int startLine = positions.untranslatedStartLine() + smallestStart;
     int endLine = positions.untranslatedEndLine() + smallestStart;
 
@@ -2119,15 +2147,9 @@
     }
 }
 
-GridArea RenderGrid::cachedGridArea(const RenderBox& gridItem) const
-{
-    ASSERT(m_gridItemArea.contains(&gridItem));
-    return m_gridItemArea.get(&gridItem);
-}
-
 GridSpan RenderGrid::cachedGridSpan(const RenderBox& gridItem, GridTrackSizingDirection direction) const
 {
-    GridArea area = cachedGridArea(gridItem);
+    GridArea area = m_grid.gridItemArea(gridItem);
     return direction == ForColumns ? area.columns : area.rows;
 }
 

Modified: trunk/Source/WebCore/rendering/RenderGrid.h (208994 => 208995)


--- trunk/Source/WebCore/rendering/RenderGrid.h	2016-11-28 04:30:44 UTC (rev 208994)
+++ trunk/Source/WebCore/rendering/RenderGrid.h	2016-11-28 11:28:41 UTC (rev 208995)
@@ -209,8 +209,21 @@
         void ensureGridSize(unsigned maximumRowSize, unsigned maximumColumnSize);
         void insert(RenderBox&, const GridArea&);
 
+        // Note that each in flow child of a grid container becomes a grid item. This means that
+        // this method will return false for a grid container with only out of flow children.
+        bool hasGridItems() const { return !m_gridItemArea.isEmpty(); }
+
+        // FIXME: move this to SizingData once placeItemsOnGrid() takes it as argument.
+        bool hasAnyOrthogonalGridItem() const { return m_hasAnyOrthogonalGridItem; }
+        void setHasAnyOrthogonalGridItem(bool hasAnyOrthogonalGridItem) { m_hasAnyOrthogonalGridItem = hasAnyOrthogonalGridItem; }
+
+        GridArea gridItemArea(const RenderBox& item) const;
+        void setGridItemArea(const RenderBox& item, GridArea);
+
         const GridCell& cell(unsigned row, unsigned column) const { return m_grid[row][column]; }
 
+        int smallestTrackStart(GridTrackSizingDirection) const;
+        void setSmallestTracksStart(int rowStart, int columnStart);
         void shrinkToFit() { m_grid.shrinkToFit(); }
 
         void clear();
@@ -217,7 +230,16 @@
 
     private:
         friend class GridIterator;
+
+        int m_smallestColumnStart { 0 };
+        int m_smallestRowStart { 0 };
+
+        bool m_hasAnyOrthogonalGridItem { false };
+
         GridAsMatrix m_grid;
+
+        HashMap<const RenderBox*, GridArea> m_gridItemArea;
+        HashMap<const RenderBox*, size_t> m_gridItemsIndexesMap;
     };
     Grid m_grid;
 
@@ -225,20 +247,14 @@
     Vector<LayoutUnit> m_rowPositions;
     LayoutUnit m_offsetBetweenColumns;
     LayoutUnit m_offsetBetweenRows;
-    HashMap<const RenderBox*, GridArea> m_gridItemArea;
     OrderIterator m_orderIterator;
 
     std::optional<LayoutUnit> m_minContentHeight;
     std::optional<LayoutUnit> m_maxContentHeight;
 
-    int m_smallestColumnStart;
-    int m_smallestRowStart;
-
     unsigned m_autoRepeatColumns { 0 };
     unsigned m_autoRepeatRows { 0 };
 
-    bool m_hasAnyOrthogonalChild;
-
     bool m_gridIsDirty { true };
 
     std::unique_ptr<OrderedTrackIndexSet> m_autoRepeatEmptyColumns { nullptr };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to