| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/paint/GridPainter.h" | 5 #include "core/paint/GridPainter.h" |
| 6 | 6 |
| 7 #include "core/layout/LayoutGrid.h" | 7 #include "core/layout/LayoutGrid.h" |
| 8 #include "core/paint/BlockPainter.h" | 8 #include "core/paint/BlockPainter.h" |
| 9 #include "core/paint/PaintInfo.h" | 9 #include "core/paint/PaintInfo.h" |
| 10 #include <algorithm> | 10 #include <algorithm> |
| 11 | 11 |
| 12 namespace blink { | 12 namespace blink { |
| 13 | 13 |
| 14 static GridSpan dirtiedGridAreas(const Vector<LayoutUnit>& coordinates, | 14 static GridSpan dirtiedGridAreas(const Vector<LayoutUnit>& coordinates, |
| 15 LayoutUnit start, | 15 LayoutUnit start, |
| 16 LayoutUnit end) { | 16 LayoutUnit end) { |
| 17 // This function does a binary search over the coordinates. | 17 // This function does a binary search over the coordinates. |
| 18 // This doesn't work with grid items overflowing their grid areas, but that is
managed with m_gridItemsOverflowingGridArea. | 18 // This doesn't work with grid items overflowing their grid areas, but that is |
| 19 // managed with m_gridItemsOverflowingGridArea. |
| 19 | 20 |
| 20 size_t startGridAreaIndex = | 21 size_t startGridAreaIndex = |
| 21 std::upper_bound(coordinates.begin(), coordinates.end() - 1, start) - | 22 std::upper_bound(coordinates.begin(), coordinates.end() - 1, start) - |
| 22 coordinates.begin(); | 23 coordinates.begin(); |
| 23 if (startGridAreaIndex > 0) | 24 if (startGridAreaIndex > 0) |
| 24 --startGridAreaIndex; | 25 --startGridAreaIndex; |
| 25 | 26 |
| 26 size_t endGridAreaIndex = | 27 size_t endGridAreaIndex = |
| 27 std::upper_bound(coordinates.begin() + startGridAreaIndex, | 28 std::upper_bound(coordinates.begin() + startGridAreaIndex, |
| 28 coordinates.end() - 1, end) - | 29 coordinates.end() - 1, end) - |
| (...skipping 22 matching lines...) Expand all Loading... |
| 51 void GridPainter::paintChildren(const PaintInfo& paintInfo, | 52 void GridPainter::paintChildren(const PaintInfo& paintInfo, |
| 52 const LayoutPoint& paintOffset) { | 53 const LayoutPoint& paintOffset) { |
| 53 ASSERT(!m_layoutGrid.needsLayout()); | 54 ASSERT(!m_layoutGrid.needsLayout()); |
| 54 | 55 |
| 55 LayoutRect localPaintInvalidationRect = | 56 LayoutRect localPaintInvalidationRect = |
| 56 LayoutRect(paintInfo.cullRect().m_rect); | 57 LayoutRect(paintInfo.cullRect().m_rect); |
| 57 localPaintInvalidationRect.moveBy(-paintOffset); | 58 localPaintInvalidationRect.moveBy(-paintOffset); |
| 58 | 59 |
| 59 Vector<LayoutUnit> columnPositions = m_layoutGrid.columnPositions(); | 60 Vector<LayoutUnit> columnPositions = m_layoutGrid.columnPositions(); |
| 60 if (!m_layoutGrid.styleRef().isLeftToRightDirection()) { | 61 if (!m_layoutGrid.styleRef().isLeftToRightDirection()) { |
| 61 // Translate columnPositions in RTL as we need the physical coordinates of t
he columns in order to call dirtiedGridAreas(). | 62 // Translate columnPositions in RTL as we need the physical coordinates of |
| 63 // the columns in order to call dirtiedGridAreas(). |
| 62 for (size_t i = 0; i < columnPositions.size(); i++) | 64 for (size_t i = 0; i < columnPositions.size(); i++) |
| 63 columnPositions[i] = | 65 columnPositions[i] = |
| 64 m_layoutGrid.translateRTLCoordinate(columnPositions[i]); | 66 m_layoutGrid.translateRTLCoordinate(columnPositions[i]); |
| 65 // We change the order of tracks in columnPositions, as in RTL the leftmost
track will be the last one. | 67 // We change the order of tracks in columnPositions, as in RTL the leftmost |
| 68 // track will be the last one. |
| 66 std::sort(columnPositions.begin(), columnPositions.end()); | 69 std::sort(columnPositions.begin(), columnPositions.end()); |
| 67 } | 70 } |
| 68 | 71 |
| 69 GridSpan dirtiedColumns = | 72 GridSpan dirtiedColumns = |
| 70 dirtiedGridAreas(columnPositions, localPaintInvalidationRect.x(), | 73 dirtiedGridAreas(columnPositions, localPaintInvalidationRect.x(), |
| 71 localPaintInvalidationRect.maxX()); | 74 localPaintInvalidationRect.maxX()); |
| 72 GridSpan dirtiedRows = dirtiedGridAreas(m_layoutGrid.rowPositions(), | 75 GridSpan dirtiedRows = dirtiedGridAreas(m_layoutGrid.rowPositions(), |
| 73 localPaintInvalidationRect.y(), | 76 localPaintInvalidationRect.y(), |
| 74 localPaintInvalidationRect.maxY()); | 77 localPaintInvalidationRect.maxY()); |
| 75 | 78 |
| 76 if (!m_layoutGrid.styleRef().isLeftToRightDirection()) { | 79 if (!m_layoutGrid.styleRef().isLeftToRightDirection()) { |
| 77 // As we changed the order of tracks previously, we need to swap the dirtied
columns in RTL. | 80 // As we changed the order of tracks previously, we need to swap the dirtied |
| 81 // columns in RTL. |
| 78 size_t lastLine = columnPositions.size() - 1; | 82 size_t lastLine = columnPositions.size() - 1; |
| 79 dirtiedColumns = GridSpan::translatedDefiniteGridSpan( | 83 dirtiedColumns = GridSpan::translatedDefiniteGridSpan( |
| 80 lastLine - dirtiedColumns.endLine(), | 84 lastLine - dirtiedColumns.endLine(), |
| 81 lastLine - dirtiedColumns.startLine()); | 85 lastLine - dirtiedColumns.startLine()); |
| 82 } | 86 } |
| 83 | 87 |
| 84 Vector<std::pair<LayoutBox*, size_t>> gridItemsToBePainted; | 88 Vector<std::pair<LayoutBox*, size_t>> gridItemsToBePainted; |
| 85 | 89 |
| 86 for (const auto& row : dirtiedRows) { | 90 for (const auto& row : dirtiedRows) { |
| 87 for (const auto& column : dirtiedColumns) { | 91 for (const auto& column : dirtiedColumns) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 99 std::make_pair(item, m_layoutGrid.paintIndexForGridItem(item))); | 103 std::make_pair(item, m_layoutGrid.paintIndexForGridItem(item))); |
| 100 } | 104 } |
| 101 | 105 |
| 102 // Sort grid items following order-modified document order. | 106 // Sort grid items following order-modified document order. |
| 103 // See http://www.w3.org/TR/css-flexbox/#order-modified-document-order | 107 // See http://www.w3.org/TR/css-flexbox/#order-modified-document-order |
| 104 std::stable_sort(gridItemsToBePainted.begin(), gridItemsToBePainted.end(), | 108 std::stable_sort(gridItemsToBePainted.begin(), gridItemsToBePainted.end(), |
| 105 GridItemsSorter()); | 109 GridItemsSorter()); |
| 106 | 110 |
| 107 LayoutBox* previous = 0; | 111 LayoutBox* previous = 0; |
| 108 for (const auto& gridItemAndPaintIndex : gridItemsToBePainted) { | 112 for (const auto& gridItemAndPaintIndex : gridItemsToBePainted) { |
| 109 // We might have duplicates because of spanning children are included in all
cells they span. | 113 // We might have duplicates because of spanning children are included in all |
| 110 // Skip them here to avoid painting items several times. | 114 // cells they span. Skip them here to avoid painting items several times. |
| 111 LayoutBox* current = gridItemAndPaintIndex.first; | 115 LayoutBox* current = gridItemAndPaintIndex.first; |
| 112 if (current == previous) | 116 if (current == previous) |
| 113 continue; | 117 continue; |
| 114 | 118 |
| 115 BlockPainter(m_layoutGrid) | 119 BlockPainter(m_layoutGrid) |
| 116 .paintAllChildPhasesAtomically(*current, paintInfo, paintOffset); | 120 .paintAllChildPhasesAtomically(*current, paintInfo, paintOffset); |
| 117 previous = current; | 121 previous = current; |
| 118 } | 122 } |
| 119 } | 123 } |
| 120 | 124 |
| 121 } // namespace blink | 125 } // namespace blink |
| OLD | NEW |