Title: [211283] trunk/Source/WebCore
Revision
211283
Author
svil...@igalia.com
Date
2017-01-27 08:28:24 -0800 (Fri, 27 Jan 2017)

Log Message

[css-grid] Move Grid class out of RenderGrid
https://bugs.webkit.org/show_bug.cgi?id=167418

Reviewed by Antti Koivisto.

The RenderGrid should be able to use different implementations of
the Grid class. The latter is big enough to be in its own file. That
would help on the effort of moving the grid track sizing algorithm
out of RenderGrid too.

No new tests required as we're just moving code.

* CMakeLists.txt:
* rendering/Grid.cpp: Added.
(WebCore::Grid::Grid):
(WebCore::Grid::numTracks):
(WebCore::Grid::ensureGridSize):
(WebCore::Grid::insert):
(WebCore::Grid::setSmallestTracksStart):
(WebCore::Grid::smallestTrackStart):
(WebCore::Grid::gridItemArea):
(WebCore::Grid::setGridItemArea):
(WebCore::Grid::setAutoRepeatTracks):
(WebCore::Grid::autoRepeatTracks):
(WebCore::Grid::setAutoRepeatEmptyColumns):
(WebCore::Grid::setAutoRepeatEmptyRows):
(WebCore::Grid::hasAutoRepeatEmptyTracks):
(WebCore::Grid::isEmptyAutoRepeatTrack):
(WebCore::Grid::autoRepeatEmptyTracks):
(WebCore::Grid::gridItemSpan):
(WebCore::Grid::setNeedsItemsPlacement):
(WebCore::GridIterator::GridIterator):
(WebCore::GridIterator::nextGridItem):
(WebCore::GridIterator::isEmptyAreaEnough):
(WebCore::GridIterator::nextEmptyGridArea):
* rendering/Grid.h: Added.
* rendering/RenderGrid.cpp:
(WebCore::RenderGrid::computeEmptyTracksForAutoRepeat):
(WebCore::RenderGrid::Grid::numTracks): Deleted.
(WebCore::RenderGrid::Grid::ensureGridSize): Deleted.
(WebCore::RenderGrid::Grid::insert): Deleted.
(WebCore::RenderGrid::Grid::setSmallestTracksStart): Deleted.
(WebCore::RenderGrid::Grid::smallestTrackStart): Deleted.
(WebCore::RenderGrid::Grid::gridItemArea): Deleted.
(WebCore::RenderGrid::Grid::setGridItemArea): Deleted.
(WebCore::RenderGrid::Grid::setAutoRepeatTracks): Deleted.
(WebCore::RenderGrid::Grid::autoRepeatTracks): Deleted.
(WebCore::RenderGrid::Grid::setAutoRepeatEmptyColumns): Deleted.
(WebCore::RenderGrid::Grid::setAutoRepeatEmptyRows): Deleted.
(WebCore::RenderGrid::Grid::hasAutoRepeatEmptyTracks): Deleted.
(WebCore::RenderGrid::Grid::isEmptyAutoRepeatTrack): Deleted.
(WebCore::RenderGrid::Grid::autoRepeatEmptyTracks): Deleted.
(WebCore::RenderGrid::Grid::gridItemSpan): Deleted.
(WebCore::RenderGrid::Grid::setNeedsItemsPlacement): Deleted.
(WebCore::RenderGrid::GridIterator::GridIterator): Deleted.
(WebCore::RenderGrid::GridIterator::nextGridItem): Deleted.
(WebCore::RenderGrid::GridIterator::isEmptyAreaEnough): Deleted.
(WebCore::RenderGrid::GridIterator::nextEmptyGridArea): Deleted.
* rendering/RenderGrid.h:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/CMakeLists.txt (211282 => 211283)


--- trunk/Source/WebCore/CMakeLists.txt	2017-01-27 15:58:05 UTC (rev 211282)
+++ trunk/Source/WebCore/CMakeLists.txt	2017-01-27 16:28:24 UTC (rev 211283)
@@ -2362,6 +2362,7 @@
     rendering/FixedTableLayout.cpp
     rendering/FloatingObjects.cpp
     rendering/FlowThreadController.cpp
+    rendering/Grid.cpp
     rendering/HitTestLocation.cpp
     rendering/HitTestResult.cpp
     rendering/HitTestingTransformState.cpp

Modified: trunk/Source/WebCore/ChangeLog (211282 => 211283)


--- trunk/Source/WebCore/ChangeLog	2017-01-27 15:58:05 UTC (rev 211282)
+++ trunk/Source/WebCore/ChangeLog	2017-01-27 16:28:24 UTC (rev 211283)
@@ -1,3 +1,65 @@
+2017-01-25  Sergio Villar Senin  <svil...@igalia.com>
+
+        [css-grid] Move Grid class out of RenderGrid
+        https://bugs.webkit.org/show_bug.cgi?id=167418
+
+        Reviewed by Antti Koivisto.
+
+        The RenderGrid should be able to use different implementations of
+        the Grid class. The latter is big enough to be in its own file. That
+        would help on the effort of moving the grid track sizing algorithm
+        out of RenderGrid too.
+
+        No new tests required as we're just moving code.
+
+        * CMakeLists.txt:
+        * rendering/Grid.cpp: Added.
+        (WebCore::Grid::Grid):
+        (WebCore::Grid::numTracks):
+        (WebCore::Grid::ensureGridSize):
+        (WebCore::Grid::insert):
+        (WebCore::Grid::setSmallestTracksStart):
+        (WebCore::Grid::smallestTrackStart):
+        (WebCore::Grid::gridItemArea):
+        (WebCore::Grid::setGridItemArea):
+        (WebCore::Grid::setAutoRepeatTracks):
+        (WebCore::Grid::autoRepeatTracks):
+        (WebCore::Grid::setAutoRepeatEmptyColumns):
+        (WebCore::Grid::setAutoRepeatEmptyRows):
+        (WebCore::Grid::hasAutoRepeatEmptyTracks):
+        (WebCore::Grid::isEmptyAutoRepeatTrack):
+        (WebCore::Grid::autoRepeatEmptyTracks):
+        (WebCore::Grid::gridItemSpan):
+        (WebCore::Grid::setNeedsItemsPlacement):
+        (WebCore::GridIterator::GridIterator):
+        (WebCore::GridIterator::nextGridItem):
+        (WebCore::GridIterator::isEmptyAreaEnough):
+        (WebCore::GridIterator::nextEmptyGridArea):
+        * rendering/Grid.h: Added.
+        * rendering/RenderGrid.cpp:
+        (WebCore::RenderGrid::computeEmptyTracksForAutoRepeat):
+        (WebCore::RenderGrid::Grid::numTracks): Deleted.
+        (WebCore::RenderGrid::Grid::ensureGridSize): Deleted.
+        (WebCore::RenderGrid::Grid::insert): Deleted.
+        (WebCore::RenderGrid::Grid::setSmallestTracksStart): Deleted.
+        (WebCore::RenderGrid::Grid::smallestTrackStart): Deleted.
+        (WebCore::RenderGrid::Grid::gridItemArea): Deleted.
+        (WebCore::RenderGrid::Grid::setGridItemArea): Deleted.
+        (WebCore::RenderGrid::Grid::setAutoRepeatTracks): Deleted.
+        (WebCore::RenderGrid::Grid::autoRepeatTracks): Deleted.
+        (WebCore::RenderGrid::Grid::setAutoRepeatEmptyColumns): Deleted.
+        (WebCore::RenderGrid::Grid::setAutoRepeatEmptyRows): Deleted.
+        (WebCore::RenderGrid::Grid::hasAutoRepeatEmptyTracks): Deleted.
+        (WebCore::RenderGrid::Grid::isEmptyAutoRepeatTrack): Deleted.
+        (WebCore::RenderGrid::Grid::autoRepeatEmptyTracks): Deleted.
+        (WebCore::RenderGrid::Grid::gridItemSpan): Deleted.
+        (WebCore::RenderGrid::Grid::setNeedsItemsPlacement): Deleted.
+        (WebCore::RenderGrid::GridIterator::GridIterator): Deleted.
+        (WebCore::RenderGrid::GridIterator::nextGridItem): Deleted.
+        (WebCore::RenderGrid::GridIterator::isEmptyAreaEnough): Deleted.
+        (WebCore::RenderGrid::GridIterator::nextEmptyGridArea): Deleted.
+        * rendering/RenderGrid.h:
+
 2017-01-27  Yusuke Suzuki  <utatane....@gmail.com>
 
         Implement dynamic-import for WebCore

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (211282 => 211283)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-01-27 15:58:05 UTC (rev 211282)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-01-27 16:28:24 UTC (rev 211283)
@@ -6103,6 +6103,8 @@
 		E10B9B6D0B747599003ED890 /* NativeXPathNSResolver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E10B9B6B0B747599003ED890 /* NativeXPathNSResolver.cpp */; };
 		E11003301C9AC3DE00412DD0 /* CSSGridAutoRepeatValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E110032E1C9AC3DE00412DD0 /* CSSGridAutoRepeatValue.cpp */; };
 		E11003311C9AC3DE00412DD0 /* CSSGridAutoRepeatValue.h in Headers */ = {isa = PBXBuildFile; fileRef = E110032F1C9AC3DE00412DD0 /* CSSGridAutoRepeatValue.h */; };
+		E112F4711E3A861200D6CDFD /* Grid.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E112F4701E3A85F200D6CDFD /* Grid.cpp */; };
+		E112F4721E3A861600D6CDFD /* Grid.h in Headers */ = {isa = PBXBuildFile; fileRef = E112F46F1E3A85D800D6CDFD /* Grid.h */; };
 		E11AF15111B9A1A300805103 /* Cursor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E11AF15011B9A1A300805103 /* Cursor.cpp */; };
 		E11C9D9B0EB3681200E409DB /* ScriptExecutionContext.h in Headers */ = {isa = PBXBuildFile; fileRef = E11C9D9A0EB3681200E409DB /* ScriptExecutionContext.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		E11C9DB00EB3699500E409DB /* ScriptExecutionContext.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E11C9DAF0EB3699500E409DB /* ScriptExecutionContext.cpp */; };
@@ -14135,6 +14137,8 @@
 		E10B9B6B0B747599003ED890 /* NativeXPathNSResolver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NativeXPathNSResolver.cpp; sourceTree = "<group>"; };
 		E110032E1C9AC3DE00412DD0 /* CSSGridAutoRepeatValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSGridAutoRepeatValue.cpp; sourceTree = "<group>"; };
 		E110032F1C9AC3DE00412DD0 /* CSSGridAutoRepeatValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSGridAutoRepeatValue.h; sourceTree = "<group>"; };
+		E112F46F1E3A85D800D6CDFD /* Grid.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Grid.h; sourceTree = "<group>"; };
+		E112F4701E3A85F200D6CDFD /* Grid.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Grid.cpp; sourceTree = "<group>"; };
 		E11AF15011B9A1A300805103 /* Cursor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Cursor.cpp; sourceTree = "<group>"; };
 		E11C9D9A0EB3681200E409DB /* ScriptExecutionContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptExecutionContext.h; sourceTree = "<group>"; };
 		E11C9DAF0EB3699500E409DB /* ScriptExecutionContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScriptExecutionContext.cpp; sourceTree = "<group>"; };
@@ -23808,6 +23812,8 @@
 				D72F6D77153159A3001EE44E /* FlowThreadController.cpp */,
 				D72F6D78153159A3001EE44E /* FlowThreadController.h */,
 				935C477409AC4D8D00A6AAB4 /* GapRects.h */,
+				E112F4701E3A85F200D6CDFD /* Grid.cpp */,
+				E112F46F1E3A85D800D6CDFD /* Grid.h */,
 				4969B0F013D0B33F00DF3521 /* HitTestingTransformState.cpp */,
 				4969B0F113D0B33F00DF3521 /* HitTestingTransformState.h */,
 				2D8287F416E4A0380086BD00 /* HitTestLocation.cpp */,
@@ -25861,6 +25867,7 @@
 				CEC337AF1A46086D009B8523 /* GraphicsServicesSPI.h in Headers */,
 				B2A015AB0AF6CD53006BCE0E /* GraphicsTypes.h in Headers */,
 				77A17A7B12F2890B004E02F6 /* GraphicsTypes3D.h in Headers */,
+				E112F4721E3A861600D6CDFD /* Grid.h in Headers */,
 				CD3E251C18046B0600E27F56 /* GridArea.h in Headers */,
 				CDEF4FD717E85C8F00AEE24B /* GridLength.h in Headers */,
 				A12705C31656BD6500C2E27C /* GridPosition.h in Headers */,
@@ -29653,6 +29660,7 @@
 				499B3ED6128CD31400E726C2 /* GraphicsLayerCA.cpp in Sources */,
 				0FA24D79162DF91900A3F4C0 /* GraphicsLayerUpdater.cpp in Sources */,
 				B2A015AA0AF6CD53006BCE0E /* GraphicsTypes.cpp in Sources */,
+				E112F4711E3A861200D6CDFD /* Grid.cpp in Sources */,
 				CDF7483E18FEBCEC0006ECC0 /* GridPositionsResolver.cpp in Sources */,
 				F55B3DBF1251F12D003EF269 /* HiddenInputType.cpp in Sources */,
 				515BE19B1D54F6C100DD7C68 /* HIDGamepad.cpp in Sources */,

Added: trunk/Source/WebCore/rendering/Grid.cpp (0 => 211283)


--- trunk/Source/WebCore/rendering/Grid.cpp	                        (rev 0)
+++ trunk/Source/WebCore/rendering/Grid.cpp	2017-01-27 16:28:24 UTC (rev 211283)
@@ -0,0 +1,242 @@
+/*
+ * Copyright (C) 2017 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "Grid.h"
+
+#if ENABLE(CSS_GRID_LAYOUT)
+
+#include "GridArea.h"
+#include "RenderGrid.h"
+
+namespace WebCore {
+
+Grid::Grid(RenderGrid& grid)
+    : m_orderIterator(grid)
+{
+}
+
+unsigned Grid::numTracks(GridTrackSizingDirection direction) const
+{
+    if (direction == ForRows)
+        return m_grid.size();
+    return m_grid.size() ? m_grid[0].size() : 0;
+}
+
+void Grid::ensureGridSize(unsigned maximumRowSize, unsigned maximumColumnSize)
+{
+    const size_t oldColumnSize = numTracks(ForColumns);
+    const size_t oldRowSize = numTracks(ForRows);
+    if (maximumRowSize > oldRowSize) {
+        m_grid.grow(maximumRowSize);
+        for (size_t row = oldRowSize; row < maximumRowSize; ++row)
+            m_grid[row].grow(oldColumnSize);
+    }
+
+    if (maximumColumnSize > oldColumnSize) {
+        for (size_t row = 0; row < numTracks(ForRows); ++row)
+            m_grid[row].grow(maximumColumnSize);
+    }
+}
+
+void Grid::insert(RenderBox& child, const GridArea& area)
+{
+    ASSERT(area.rows.isTranslatedDefinite() && area.columns.isTranslatedDefinite());
+    ensureGridSize(area.rows.endLine(), area.columns.endLine());
+
+    for (const auto& row : area.rows) {
+        for (const auto& column : area.columns)
+            m_grid[row][column].append(&child);
+    }
+
+    setGridItemArea(child, area);
+}
+
+void Grid::setSmallestTracksStart(int rowStart, int columnStart)
+{
+    m_smallestRowStart = rowStart;
+    m_smallestColumnStart = columnStart;
+}
+
+int Grid::smallestTrackStart(GridTrackSizingDirection direction) const
+{
+    return direction == ForRows ? m_smallestRowStart : m_smallestColumnStart;
+}
+
+GridArea Grid::gridItemArea(const RenderBox& item) const
+{
+    ASSERT(m_gridItemArea.contains(&item));
+    return m_gridItemArea.get(&item);
+}
+
+void Grid::setGridItemArea(const RenderBox& item, GridArea area)
+{
+    m_gridItemArea.set(&item, area);
+}
+
+void Grid::setAutoRepeatTracks(unsigned autoRepeatRows, unsigned autoRepeatColumns)
+{
+    m_autoRepeatRows = autoRepeatRows;
+    m_autoRepeatColumns =  autoRepeatColumns;
+}
+
+unsigned Grid::autoRepeatTracks(GridTrackSizingDirection direction) const
+{
+    return direction == ForRows ? m_autoRepeatRows : m_autoRepeatColumns;
+}
+
+void Grid::setAutoRepeatEmptyColumns(std::unique_ptr<OrderedTrackIndexSet> autoRepeatEmptyColumns)
+{
+    m_autoRepeatEmptyColumns = WTFMove(autoRepeatEmptyColumns);
+}
+
+void Grid::setAutoRepeatEmptyRows(std::unique_ptr<OrderedTrackIndexSet> autoRepeatEmptyRows)
+{
+    m_autoRepeatEmptyRows = WTFMove(autoRepeatEmptyRows);
+}
+
+bool Grid::hasAutoRepeatEmptyTracks(GridTrackSizingDirection direction) const
+{
+    return direction == ForColumns ? !!m_autoRepeatEmptyColumns : !!m_autoRepeatEmptyRows;
+}
+
+bool Grid::isEmptyAutoRepeatTrack(GridTrackSizingDirection direction, unsigned line) const
+{
+    ASSERT(hasAutoRepeatEmptyTracks(direction));
+    return autoRepeatEmptyTracks(direction)->contains(line);
+}
+
+OrderedTrackIndexSet* Grid::autoRepeatEmptyTracks(GridTrackSizingDirection direction) const
+{
+    ASSERT(hasAutoRepeatEmptyTracks(direction));
+    return direction == ForColumns ? m_autoRepeatEmptyColumns.get() : m_autoRepeatEmptyRows.get();
+}
+
+GridSpan Grid::gridItemSpan(const RenderBox& gridItem, GridTrackSizingDirection direction) const
+{
+    GridArea area = gridItemArea(gridItem);
+    return direction == ForColumns ? area.columns : area.rows;
+}
+
+void Grid::setNeedsItemsPlacement(bool needsItemsPlacement)
+{
+    m_needsItemsPlacement = needsItemsPlacement;
+
+    if (!needsItemsPlacement) {
+        m_grid.shrinkToFit();
+        return;
+    }
+
+    m_grid.resize(0);
+    m_gridItemArea.clear();
+    m_hasAnyOrthogonalGridItem = false;
+    m_smallestRowStart = 0;
+    m_smallestColumnStart = 0;
+    m_autoRepeatEmptyColumns = nullptr;
+    m_autoRepeatEmptyRows = nullptr;
+    m_autoRepeatColumns = 0;
+    m_autoRepeatRows = 0;
+}
+
+GridIterator::GridIterator(const Grid& grid, GridTrackSizingDirection direction, unsigned fixedTrackIndex, unsigned varyingTrackIndex)
+    : m_grid(grid.m_grid)
+    , m_direction(direction)
+    , m_rowIndex((direction == ForColumns) ? varyingTrackIndex : fixedTrackIndex)
+    , m_columnIndex((direction == ForColumns) ? fixedTrackIndex : varyingTrackIndex)
+    , m_childIndex(0)
+{
+    ASSERT(!m_grid.isEmpty());
+    ASSERT(!m_grid[0].isEmpty());
+    ASSERT(m_rowIndex < m_grid.size());
+    ASSERT(m_columnIndex < m_grid[0].size());
+}
+
+RenderBox* GridIterator::nextGridItem()
+{
+    ASSERT(!m_grid.isEmpty());
+    ASSERT(!m_grid[0].isEmpty());
+
+    unsigned& varyingTrackIndex = (m_direction == ForColumns) ? m_rowIndex : m_columnIndex;
+    const unsigned endOfVaryingTrackIndex = (m_direction == ForColumns) ? m_grid.size() : m_grid[0].size();
+    for (; varyingTrackIndex < endOfVaryingTrackIndex; ++varyingTrackIndex) {
+        const auto& children = m_grid[m_rowIndex][m_columnIndex];
+        if (m_childIndex < children.size())
+            return children[m_childIndex++];
+
+        m_childIndex = 0;
+    }
+    return 0;
+}
+
+bool GridIterator::isEmptyAreaEnough(unsigned rowSpan, unsigned columnSpan) const
+{
+    ASSERT(!m_grid.isEmpty());
+    ASSERT(!m_grid[0].isEmpty());
+
+    // Ignore cells outside current grid as we will grow it later if needed.
+    unsigned maxRows = std::min<unsigned>(m_rowIndex + rowSpan, m_grid.size());
+    unsigned maxColumns = std::min<unsigned>(m_columnIndex + columnSpan, m_grid[0].size());
+
+    // This adds a O(N^2) behavior that shouldn't be a big deal as we expect spanning areas to be small.
+    for (unsigned row = m_rowIndex; row < maxRows; ++row) {
+        for (unsigned column = m_columnIndex; column < maxColumns; ++column) {
+            auto& children = m_grid[row][column];
+            if (!children.isEmpty())
+                return false;
+        }
+    }
+
+    return true;
+}
+
+std::unique_ptr<GridArea> GridIterator::nextEmptyGridArea(unsigned fixedTrackSpan, unsigned varyingTrackSpan)
+{
+    ASSERT(!m_grid.isEmpty());
+    ASSERT(!m_grid[0].isEmpty());
+    ASSERT(fixedTrackSpan >= 1);
+    ASSERT(varyingTrackSpan >= 1);
+
+    if (m_grid.isEmpty())
+        return nullptr;
+
+    unsigned rowSpan = (m_direction == ForColumns) ? varyingTrackSpan : fixedTrackSpan;
+    unsigned columnSpan = (m_direction == ForColumns) ? fixedTrackSpan : varyingTrackSpan;
+
+    unsigned& varyingTrackIndex = (m_direction == ForColumns) ? m_rowIndex : m_columnIndex;
+    const unsigned endOfVaryingTrackIndex = (m_direction == ForColumns) ? m_grid.size() : m_grid[0].size();
+    for (; varyingTrackIndex < endOfVaryingTrackIndex; ++varyingTrackIndex) {
+        if (isEmptyAreaEnough(rowSpan, columnSpan)) {
+            std::unique_ptr<GridArea> result = std::make_unique<GridArea>(GridSpan::translatedDefiniteGridSpan(m_rowIndex, m_rowIndex + rowSpan), GridSpan::translatedDefiniteGridSpan(m_columnIndex, m_columnIndex + columnSpan));
+            // Advance the iterator to avoid an infinite loop where we would return the same grid area over and over.
+            ++varyingTrackIndex;
+            return result;
+        }
+    }
+    return nullptr;
+}
+
+} // namespace WebCore
+
+#endif  /* ENABLE(CSS_GRID_LAYOUT) */
Property changes on: trunk/Source/WebCore/rendering/Grid.cpp
___________________________________________________________________

Added: svn:eol-style

+LF \ No newline at end of property

Added: trunk/Source/WebCore/rendering/Grid.h (0 => 211283)


--- trunk/Source/WebCore/rendering/Grid.h	                        (rev 0)
+++ trunk/Source/WebCore/rendering/Grid.h	2017-01-27 16:28:24 UTC (rev 211283)
@@ -0,0 +1,133 @@
+/*
+ * Copyright (C) 2017 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(CSS_GRID_LAYOUT)
+
+#include "GridPositionsResolver.h"
+#include "OrderIterator.h"
+#include <wtf/HashMap.h>
+#include <wtf/ListHashSet.h>
+
+namespace WebCore {
+
+typedef Vector<RenderBox*, 1> GridCell;
+typedef Vector<Vector<GridCell>> GridAsMatrix;
+typedef ListHashSet<size_t> OrderedTrackIndexSet;
+
+class GridArea;
+class GridPositionsResolver;
+class RenderGrid;
+
+class Grid final {
+public:
+    explicit Grid(RenderGrid&);
+
+    unsigned numTracks(GridTrackSizingDirection) const;
+
+    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);
+
+    GridSpan gridItemSpan(const RenderBox&, GridTrackSizingDirection) const;
+
+    const GridCell& cell(unsigned row, unsigned column) const { return m_grid[row][column]; }
+
+    int smallestTrackStart(GridTrackSizingDirection) const;
+    void setSmallestTracksStart(int rowStart, int columnStart);
+
+    unsigned autoRepeatTracks(GridTrackSizingDirection) const;
+    void setAutoRepeatTracks(unsigned autoRepeatRows, unsigned autoRepeatColumns);
+
+    void setAutoRepeatEmptyColumns(std::unique_ptr<OrderedTrackIndexSet>);
+    void setAutoRepeatEmptyRows(std::unique_ptr<OrderedTrackIndexSet>);
+
+    unsigned autoRepeatEmptyTracksCount(GridTrackSizingDirection) const;
+    bool hasAutoRepeatEmptyTracks(GridTrackSizingDirection) const;
+    bool isEmptyAutoRepeatTrack(GridTrackSizingDirection, unsigned) const;
+
+    OrderedTrackIndexSet* autoRepeatEmptyTracks(GridTrackSizingDirection) const;
+
+    OrderIterator& orderIterator() { return m_orderIterator; }
+
+    void setNeedsItemsPlacement(bool);
+    bool needsItemsPlacement() const { return m_needsItemsPlacement; };
+
+private:
+    friend class GridIterator;
+
+    OrderIterator m_orderIterator;
+
+    int m_smallestColumnStart { 0 };
+    int m_smallestRowStart { 0 };
+
+    unsigned m_autoRepeatColumns { 0 };
+    unsigned m_autoRepeatRows { 0 };
+
+    bool m_hasAnyOrthogonalGridItem { false };
+    bool m_needsItemsPlacement { true };
+
+    GridAsMatrix m_grid;
+
+    HashMap<const RenderBox*, GridArea> m_gridItemArea;
+    HashMap<const RenderBox*, size_t> m_gridItemsIndexesMap;
+
+    std::unique_ptr<OrderedTrackIndexSet> m_autoRepeatEmptyColumns;
+    std::unique_ptr<OrderedTrackIndexSet> m_autoRepeatEmptyRows;
+};
+
+class GridIterator {
+    WTF_MAKE_NONCOPYABLE(GridIterator);
+public:
+    // |direction| is the direction that is fixed to |fixedTrackIndex| so e.g
+    // GridIterator(m_grid, ForColumns, 1) will walk over the rows of the 2nd column.
+    GridIterator(const Grid&, GridTrackSizingDirection, unsigned fixedTrackIndex, unsigned varyingTrackIndex = 0);
+
+    RenderBox* nextGridItem();
+    bool isEmptyAreaEnough(unsigned rowSpan, unsigned columnSpan) const;
+    std::unique_ptr<GridArea> nextEmptyGridArea(unsigned fixedTrackSpan, unsigned varyingTrackSpan);
+
+private:
+    const GridAsMatrix& m_grid;
+    GridTrackSizingDirection m_direction;
+    unsigned m_rowIndex;
+    unsigned m_columnIndex;
+    unsigned m_childIndex;
+};
+
+} // namespace WebCore
+
+#endif  /* ENABLE(CSS_GRID_LAYOUT) */
Property changes on: trunk/Source/WebCore/rendering/Grid.h
___________________________________________________________________

Added: svn:eol-style

+LF \ No newline at end of property

Modified: trunk/Source/WebCore/rendering/RenderGrid.cpp (211282 => 211283)


--- trunk/Source/WebCore/rendering/RenderGrid.cpp	2017-01-27 15:58:05 UTC (rev 211282)
+++ trunk/Source/WebCore/rendering/RenderGrid.cpp	2017-01-27 16:28:24 UTC (rev 211283)
@@ -46,128 +46,6 @@
     ForbidInfinity,
 };
 
-unsigned RenderGrid::Grid::numTracks(GridTrackSizingDirection direction) const
-{
-    if (direction == ForRows)
-        return m_grid.size();
-    return m_grid.size() ? m_grid[0].size() : 0;
-}
-
-void RenderGrid::Grid::ensureGridSize(unsigned maximumRowSize, unsigned maximumColumnSize)
-{
-    const size_t oldColumnSize = numTracks(ForColumns);
-    const size_t oldRowSize = numTracks(ForRows);
-    if (maximumRowSize > oldRowSize) {
-        m_grid.grow(maximumRowSize);
-        for (size_t row = oldRowSize; row < maximumRowSize; ++row)
-            m_grid[row].grow(oldColumnSize);
-    }
-
-    if (maximumColumnSize > oldColumnSize) {
-        for (size_t row = 0; row < numTracks(ForRows); ++row)
-            m_grid[row].grow(maximumColumnSize);
-    }
-}
-
-void RenderGrid::Grid::insert(RenderBox& child, const GridArea& area)
-{
-    ASSERT(area.rows.isTranslatedDefinite() && area.columns.isTranslatedDefinite());
-    ensureGridSize(area.rows.endLine(), area.columns.endLine());
-
-    for (const auto& row : area.rows) {
-        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::setAutoRepeatTracks(unsigned autoRepeatRows, unsigned autoRepeatColumns)
-{
-    m_autoRepeatRows = autoRepeatRows;
-    m_autoRepeatColumns =  autoRepeatColumns;
-}
-
-unsigned RenderGrid::Grid::autoRepeatTracks(GridTrackSizingDirection direction) const
-{
-    return direction == ForRows ? m_autoRepeatRows : m_autoRepeatColumns;
-}
-
-void RenderGrid::Grid::setAutoRepeatEmptyColumns(std::unique_ptr<OrderedTrackIndexSet> autoRepeatEmptyColumns)
-{
-    m_autoRepeatEmptyColumns = WTFMove(autoRepeatEmptyColumns);
-}
-
-void RenderGrid::Grid::setAutoRepeatEmptyRows(std::unique_ptr<OrderedTrackIndexSet> autoRepeatEmptyRows)
-{
-    m_autoRepeatEmptyRows = WTFMove(autoRepeatEmptyRows);
-}
-
-bool RenderGrid::Grid::hasAutoRepeatEmptyTracks(GridTrackSizingDirection direction) const
-{
-    return direction == ForColumns ? !!m_autoRepeatEmptyColumns : !!m_autoRepeatEmptyRows;
-}
-
-bool RenderGrid::Grid::isEmptyAutoRepeatTrack(GridTrackSizingDirection direction, unsigned line) const
-{
-    ASSERT(hasAutoRepeatEmptyTracks(direction));
-    return autoRepeatEmptyTracks(direction)->contains(line);
-}
-
-RenderGrid::OrderedTrackIndexSet* RenderGrid::Grid::autoRepeatEmptyTracks(GridTrackSizingDirection direction) const
-{
-    ASSERT(hasAutoRepeatEmptyTracks(direction));
-    return direction == ForColumns ? m_autoRepeatEmptyColumns.get() : m_autoRepeatEmptyRows.get();
-}
-
-GridSpan RenderGrid::Grid::gridItemSpan(const RenderBox& gridItem, GridTrackSizingDirection direction) const
-{
-    GridArea area = gridItemArea(gridItem);
-    return direction == ForColumns ? area.columns : area.rows;
-}
-
-void RenderGrid::Grid::setNeedsItemsPlacement(bool needsItemsPlacement)
-{
-    m_needsItemsPlacement = needsItemsPlacement;
-
-    if (!needsItemsPlacement) {
-        m_grid.shrinkToFit();
-        return;
-    }
-
-    m_grid.resize(0);
-    m_gridItemArea.clear();
-    m_hasAnyOrthogonalGridItem = false;
-    m_smallestRowStart = 0;
-    m_smallestColumnStart = 0;
-    m_autoRepeatEmptyColumns = nullptr;
-    m_autoRepeatEmptyRows = nullptr;
-    m_autoRepeatColumns = 0;
-    m_autoRepeatRows = 0;
-}
-
 class GridTrack {
 public:
     GridTrack() {}
@@ -266,96 +144,6 @@
     LayoutUnit distributionOffset;
 };
 
-class RenderGrid::GridIterator {
-    WTF_MAKE_NONCOPYABLE(GridIterator);
-public:
-    // |direction| is the direction that is fixed to |fixedTrackIndex| so e.g
-    // GridIterator(m_grid, ForColumns, 1) will walk over the rows of the 2nd column.
-    GridIterator(const Grid& grid, GridTrackSizingDirection direction, unsigned fixedTrackIndex, unsigned varyingTrackIndex = 0)
-        : m_grid(grid.m_grid)
-        , m_direction(direction)
-        , m_rowIndex((direction == ForColumns) ? varyingTrackIndex : fixedTrackIndex)
-        , m_columnIndex((direction == ForColumns) ? fixedTrackIndex : varyingTrackIndex)
-        , m_childIndex(0)
-    {
-        ASSERT(!m_grid.isEmpty());
-        ASSERT(!m_grid[0].isEmpty());
-        ASSERT(m_rowIndex < m_grid.size());
-        ASSERT(m_columnIndex < m_grid[0].size());
-    }
-
-    RenderBox* nextGridItem()
-    {
-        ASSERT(!m_grid.isEmpty());
-        ASSERT(!m_grid[0].isEmpty());
-
-        unsigned& varyingTrackIndex = (m_direction == ForColumns) ? m_rowIndex : m_columnIndex;
-        const unsigned endOfVaryingTrackIndex = (m_direction == ForColumns) ? m_grid.size() : m_grid[0].size();
-        for (; varyingTrackIndex < endOfVaryingTrackIndex; ++varyingTrackIndex) {
-            const auto& children = m_grid[m_rowIndex][m_columnIndex];
-            if (m_childIndex < children.size())
-                return children[m_childIndex++];
-
-            m_childIndex = 0;
-        }
-        return 0;
-    }
-
-    bool isEmptyAreaEnough(unsigned rowSpan, unsigned columnSpan) const
-    {
-        ASSERT(!m_grid.isEmpty());
-        ASSERT(!m_grid[0].isEmpty());
-
-        // Ignore cells outside current grid as we will grow it later if needed.
-        unsigned maxRows = std::min<unsigned>(m_rowIndex + rowSpan, m_grid.size());
-        unsigned maxColumns = std::min<unsigned>(m_columnIndex + columnSpan, m_grid[0].size());
-
-        // This adds a O(N^2) behavior that shouldn't be a big deal as we expect spanning areas to be small.
-        for (unsigned row = m_rowIndex; row < maxRows; ++row) {
-            for (unsigned column = m_columnIndex; column < maxColumns; ++column) {
-                auto& children = m_grid[row][column];
-                if (!children.isEmpty())
-                    return false;
-            }
-        }
-
-        return true;
-    }
-
-    std::unique_ptr<GridArea> nextEmptyGridArea(unsigned fixedTrackSpan, unsigned varyingTrackSpan)
-    {
-        ASSERT(!m_grid.isEmpty());
-        ASSERT(!m_grid[0].isEmpty());
-        ASSERT(fixedTrackSpan >= 1);
-        ASSERT(varyingTrackSpan >= 1);
-
-        if (m_grid.isEmpty())
-            return nullptr;
-
-        unsigned rowSpan = (m_direction == ForColumns) ? varyingTrackSpan : fixedTrackSpan;
-        unsigned columnSpan = (m_direction == ForColumns) ? fixedTrackSpan : varyingTrackSpan;
-
-        unsigned& varyingTrackIndex = (m_direction == ForColumns) ? m_rowIndex : m_columnIndex;
-        const unsigned endOfVaryingTrackIndex = (m_direction == ForColumns) ? m_grid.size() : m_grid[0].size();
-        for (; varyingTrackIndex < endOfVaryingTrackIndex; ++varyingTrackIndex) {
-            if (isEmptyAreaEnough(rowSpan, columnSpan)) {
-                std::unique_ptr<GridArea> result = std::make_unique<GridArea>(GridSpan::translatedDefiniteGridSpan(m_rowIndex, m_rowIndex + rowSpan), GridSpan::translatedDefiniteGridSpan(m_columnIndex, m_columnIndex + columnSpan));
-                // Advance the iterator to avoid an infinite loop where we would return the same grid area over and over.
-                ++varyingTrackIndex;
-                return result;
-            }
-        }
-        return nullptr;
-    }
-
-private:
-    const GridAsMatrix& m_grid;
-    GridTrackSizingDirection m_direction;
-    unsigned m_rowIndex;
-    unsigned m_columnIndex;
-    unsigned m_childIndex;
-};
-
 class RenderGrid::GridSizingData {
     WTF_MAKE_NONCOPYABLE(GridSizingData);
 public:
@@ -1725,7 +1513,7 @@
 }
 
 
-std::unique_ptr<RenderGrid::OrderedTrackIndexSet> RenderGrid::computeEmptyTracksForAutoRepeat(Grid& grid, GridTrackSizingDirection direction) const
+std::unique_ptr<OrderedTrackIndexSet> RenderGrid::computeEmptyTracksForAutoRepeat(Grid& grid, GridTrackSizingDirection direction) const
 {
     bool isRowAxis = direction == ForColumns;
     if ((isRowAxis && style().gridAutoRepeatColumnsType() != AutoFit)

Modified: trunk/Source/WebCore/rendering/RenderGrid.h (211282 => 211283)


--- trunk/Source/WebCore/rendering/RenderGrid.h	2017-01-27 15:58:05 UTC (rev 211282)
+++ trunk/Source/WebCore/rendering/RenderGrid.h	2017-01-27 16:28:24 UTC (rev 211283)
@@ -28,8 +28,7 @@
 
 #if ENABLE(CSS_GRID_LAYOUT)
 
-#include "GridPositionsResolver.h"
-#include "OrderIterator.h"
+#include "Grid.h"
 #include "RenderBlock.h"
 
 namespace WebCore {
@@ -86,8 +85,6 @@
 
     std::optional<LayoutUnit> computeIntrinsicLogicalContentHeightUsing(Length logicalHeightLength, std::optional<LayoutUnit> intrinsicContentHeight, LayoutUnit borderAndPadding) const override;
 
-    class Grid;
-    class GridIterator;
     class GridSizingData;
     enum SizingOperation { TrackSizing, IntrinsicSizeComputation };
     void computeUsedBreadthOfGridTracks(GridTrackSizingDirection, GridSizingData&, LayoutUnit& baseSizesWithoutMaximization, LayoutUnit& growthLimitsWithoutMaximization) const;
@@ -98,7 +95,6 @@
 
     unsigned computeAutoRepeatTracksCount(GridTrackSizingDirection, SizingOperation) const;
 
-    typedef ListHashSet<size_t> OrderedTrackIndexSet;
     std::unique_ptr<OrderedTrackIndexSet> computeEmptyTracksForAutoRepeat(Grid&, GridTrackSizingDirection) const;
 
     void placeItemsOnGrid(Grid&, SizingOperation) const;
@@ -203,74 +199,6 @@
     bool isOrthogonalChild(const RenderBox&) const;
     GridTrackSizingDirection flowAwareDirectionForChild(const RenderBox&, GridTrackSizingDirection) const;
 
-    typedef Vector<RenderBox*, 1> GridCell;
-    typedef Vector<Vector<GridCell>> GridAsMatrix;
-    class Grid final {
-    public:
-        Grid(RenderGrid& grid) : m_orderIterator(grid) { }
-
-        unsigned numTracks(GridTrackSizingDirection) const;
-
-        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);
-
-        GridSpan gridItemSpan(const RenderBox&, GridTrackSizingDirection) const;
-
-        const GridCell& cell(unsigned row, unsigned column) const { return m_grid[row][column]; }
-
-        int smallestTrackStart(GridTrackSizingDirection) const;
-        void setSmallestTracksStart(int rowStart, int columnStart);
-
-        unsigned autoRepeatTracks(GridTrackSizingDirection) const;
-        void setAutoRepeatTracks(unsigned autoRepeatRows, unsigned autoRepeatColumns);
-
-        void setAutoRepeatEmptyColumns(std::unique_ptr<OrderedTrackIndexSet>);
-        void setAutoRepeatEmptyRows(std::unique_ptr<OrderedTrackIndexSet>);
-
-        unsigned autoRepeatEmptyTracksCount(GridTrackSizingDirection) const;
-        bool hasAutoRepeatEmptyTracks(GridTrackSizingDirection) const;
-        bool isEmptyAutoRepeatTrack(GridTrackSizingDirection, unsigned) const;
-
-        OrderedTrackIndexSet* autoRepeatEmptyTracks(GridTrackSizingDirection) const;
-
-        OrderIterator& orderIterator() { return m_orderIterator; }
-
-        void setNeedsItemsPlacement(bool);
-        bool needsItemsPlacement() const { return m_needsItemsPlacement; };
-
-    private:
-        friend class GridIterator;
-
-        OrderIterator m_orderIterator;
-
-        int m_smallestColumnStart { 0 };
-        int m_smallestRowStart { 0 };
-
-        unsigned m_autoRepeatColumns { 0 };
-        unsigned m_autoRepeatRows { 0 };
-
-        bool m_hasAnyOrthogonalGridItem { false };
-        bool m_needsItemsPlacement { true };
-
-        GridAsMatrix m_grid;
-
-        HashMap<const RenderBox*, GridArea> m_gridItemArea;
-        HashMap<const RenderBox*, size_t> m_gridItemsIndexesMap;
-
-        std::unique_ptr<OrderedTrackIndexSet> m_autoRepeatEmptyColumns;
-        std::unique_ptr<OrderedTrackIndexSet> m_autoRepeatEmptyRows;
-    };
     Grid m_grid;
 
     Vector<LayoutUnit> m_columnPositions;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to