Commit bb707101 authored by rego's avatar rego Committed by Commit bot

[css-grid] Use order-modified document order for m_gridItemsIndexesMap

We were storing the index in the DOM for the grid items
in m_gridItemsIndexesMap. However, we can already store the index
following the order-modified document order.

This allows us to simplify the sorter in painting,
as we don't need to check the order property now,
just simply use the stored index.

No new tests, as it's already covered by current tests.

CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2

Review-Url: https://chromiumcodereview.appspot.com/2438253003
Cr-Commit-Position: refs/heads/master@{#426989}
parent eb5a1b92
...@@ -1928,7 +1928,6 @@ void LayoutGrid::placeItemsOnGrid() { ...@@ -1928,7 +1928,6 @@ void LayoutGrid::placeItemsOnGrid() {
return; return;
DCHECK(m_gridItemArea.isEmpty()); DCHECK(m_gridItemArea.isEmpty());
DCHECK(m_gridItemsIndexesMap.isEmpty());
populateExplicitGridAndOrderIterator(); populateExplicitGridAndOrderIterator();
...@@ -1937,12 +1936,16 @@ void LayoutGrid::placeItemsOnGrid() { ...@@ -1937,12 +1936,16 @@ void LayoutGrid::placeItemsOnGrid() {
Vector<LayoutBox*> autoMajorAxisAutoGridItems; Vector<LayoutBox*> autoMajorAxisAutoGridItems;
Vector<LayoutBox*> specifiedMajorAxisAutoGridItems; Vector<LayoutBox*> specifiedMajorAxisAutoGridItems;
DCHECK(m_gridItemsIndexesMap.isEmpty());
size_t childIndex = 0;
m_hasAnyOrthogonalChildren = false; m_hasAnyOrthogonalChildren = false;
for (LayoutBox* child = m_orderIterator.first(); child; for (LayoutBox* child = m_orderIterator.first(); child;
child = m_orderIterator.next()) { child = m_orderIterator.next()) {
if (child->isOutOfFlowPositioned()) if (child->isOutOfFlowPositioned())
continue; continue;
m_gridItemsIndexesMap.set(child, childIndex++);
m_hasAnyOrthogonalChildren = m_hasAnyOrthogonalChildren =
m_hasAnyOrthogonalChildren || isOrthogonalChild(*child); m_hasAnyOrthogonalChildren || isOrthogonalChild(*child);
...@@ -2003,12 +2006,9 @@ void LayoutGrid::populateExplicitGridAndOrderIterator() { ...@@ -2003,12 +2006,9 @@ void LayoutGrid::populateExplicitGridAndOrderIterator() {
size_t maximumColumnIndex = GridPositionsResolver::explicitGridColumnCount( size_t maximumColumnIndex = GridPositionsResolver::explicitGridColumnCount(
*style(), m_autoRepeatColumns); *style(), m_autoRepeatColumns);
ASSERT(m_gridItemsIndexesMap.isEmpty());
size_t childIndex = 0;
for (LayoutBox* child = firstInFlowChildBox(); child; for (LayoutBox* child = firstInFlowChildBox(); child;
child = child->nextInFlowSiblingBox()) { child = child->nextInFlowSiblingBox()) {
populator.collectChild(child); populator.collectChild(child);
m_gridItemsIndexesMap.set(child, childIndex++);
// This function bypasses the cache (cachedGridArea()) as it is used to // This function bypasses the cache (cachedGridArea()) as it is used to
// build it. // build it.
......
...@@ -36,18 +36,13 @@ static GridSpan dirtiedGridAreas(const Vector<LayoutUnit>& coordinates, ...@@ -36,18 +36,13 @@ static GridSpan dirtiedGridAreas(const Vector<LayoutUnit>& coordinates,
endGridAreaIndex + 1); endGridAreaIndex + 1);
} }
class GridItemsSorter { // Helper for the sorting of grid items following order-modified document order.
public: // See http://www.w3.org/TR/css-flexbox/#order-modified-document-order
bool operator()(const std::pair<LayoutBox*, size_t>& firstChild, static inline bool compareOrderModifiedDocumentOrder(
const std::pair<LayoutBox*, size_t>& secondChild) const { const std::pair<LayoutBox*, size_t>& firstItem,
if (firstChild.first->style()->order() != const std::pair<LayoutBox*, size_t>& secondItem) {
secondChild.first->style()->order()) return firstItem.second < secondItem.second;
return firstChild.first->style()->order() < }
secondChild.first->style()->order();
return firstChild.second < secondChild.second;
}
};
void GridPainter::paintChildren(const PaintInfo& paintInfo, void GridPainter::paintChildren(const PaintInfo& paintInfo,
const LayoutPoint& paintOffset) { const LayoutPoint& paintOffset) {
...@@ -103,10 +98,8 @@ void GridPainter::paintChildren(const PaintInfo& paintInfo, ...@@ -103,10 +98,8 @@ void GridPainter::paintChildren(const PaintInfo& paintInfo,
std::make_pair(item, m_layoutGrid.paintIndexForGridItem(item))); std::make_pair(item, m_layoutGrid.paintIndexForGridItem(item)));
} }
// Sort grid items following order-modified document order.
// See http://www.w3.org/TR/css-flexbox/#order-modified-document-order
std::stable_sort(gridItemsToBePainted.begin(), gridItemsToBePainted.end(), std::stable_sort(gridItemsToBePainted.begin(), gridItemsToBePainted.end(),
GridItemsSorter()); compareOrderModifiedDocumentOrder);
LayoutBox* previous = 0; LayoutBox* previous = 0;
for (const auto& gridItemAndPaintIndex : gridItemsToBePainted) { for (const auto& gridItemAndPaintIndex : gridItemsToBePainted) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment