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> |
(...skipping 18 matching lines...) Expand all Loading... |
29 coordinates.end() - 1, end) - | 29 coordinates.end() - 1, end) - |
30 coordinates.begin(); | 30 coordinates.begin(); |
31 if (endGridAreaIndex > 0) | 31 if (endGridAreaIndex > 0) |
32 --endGridAreaIndex; | 32 --endGridAreaIndex; |
33 | 33 |
34 // GridSpan stores lines' indexes (not tracks' indexes). | 34 // GridSpan stores lines' indexes (not tracks' indexes). |
35 return GridSpan::translatedDefiniteGridSpan(startGridAreaIndex, | 35 return GridSpan::translatedDefiniteGridSpan(startGridAreaIndex, |
36 endGridAreaIndex + 1); | 36 endGridAreaIndex + 1); |
37 } | 37 } |
38 | 38 |
39 class GridItemsSorter { | 39 // Helper for the sorting of grid items following order-modified document order. |
40 public: | 40 // See http://www.w3.org/TR/css-flexbox/#order-modified-document-order |
41 bool operator()(const std::pair<LayoutBox*, size_t>& firstChild, | 41 static inline bool compareOrderModifiedDocumentOrder( |
42 const std::pair<LayoutBox*, size_t>& secondChild) const { | 42 const std::pair<LayoutBox*, size_t>& firstItem, |
43 if (firstChild.first->style()->order() != | 43 const std::pair<LayoutBox*, size_t>& secondItem) { |
44 secondChild.first->style()->order()) | 44 return firstItem.second < secondItem.second; |
45 return firstChild.first->style()->order() < | 45 } |
46 secondChild.first->style()->order(); | |
47 | |
48 return firstChild.second < secondChild.second; | |
49 } | |
50 }; | |
51 | 46 |
52 void GridPainter::paintChildren(const PaintInfo& paintInfo, | 47 void GridPainter::paintChildren(const PaintInfo& paintInfo, |
53 const LayoutPoint& paintOffset) { | 48 const LayoutPoint& paintOffset) { |
54 ASSERT(!m_layoutGrid.needsLayout()); | 49 ASSERT(!m_layoutGrid.needsLayout()); |
55 | 50 |
56 LayoutRect localPaintInvalidationRect = | 51 LayoutRect localPaintInvalidationRect = |
57 LayoutRect(paintInfo.cullRect().m_rect); | 52 LayoutRect(paintInfo.cullRect().m_rect); |
58 localPaintInvalidationRect.moveBy(-paintOffset); | 53 localPaintInvalidationRect.moveBy(-paintOffset); |
59 | 54 |
60 Vector<LayoutUnit> columnPositions = m_layoutGrid.columnPositions(); | 55 Vector<LayoutUnit> columnPositions = m_layoutGrid.columnPositions(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 std::make_pair(child, m_layoutGrid.paintIndexForGridItem(child))); | 91 std::make_pair(child, m_layoutGrid.paintIndexForGridItem(child))); |
97 } | 92 } |
98 } | 93 } |
99 | 94 |
100 for (auto* item : m_layoutGrid.itemsOverflowingGridArea()) { | 95 for (auto* item : m_layoutGrid.itemsOverflowingGridArea()) { |
101 if (item->frameRect().intersects(localPaintInvalidationRect)) | 96 if (item->frameRect().intersects(localPaintInvalidationRect)) |
102 gridItemsToBePainted.append( | 97 gridItemsToBePainted.append( |
103 std::make_pair(item, m_layoutGrid.paintIndexForGridItem(item))); | 98 std::make_pair(item, m_layoutGrid.paintIndexForGridItem(item))); |
104 } | 99 } |
105 | 100 |
106 // Sort grid items following order-modified document order. | |
107 // See http://www.w3.org/TR/css-flexbox/#order-modified-document-order | |
108 std::stable_sort(gridItemsToBePainted.begin(), gridItemsToBePainted.end(), | 101 std::stable_sort(gridItemsToBePainted.begin(), gridItemsToBePainted.end(), |
109 GridItemsSorter()); | 102 compareOrderModifiedDocumentOrder); |
110 | 103 |
111 LayoutBox* previous = 0; | 104 LayoutBox* previous = 0; |
112 for (const auto& gridItemAndPaintIndex : gridItemsToBePainted) { | 105 for (const auto& gridItemAndPaintIndex : gridItemsToBePainted) { |
113 // We might have duplicates because of spanning children are included in all | 106 // We might have duplicates because of spanning children are included in all |
114 // cells they span. Skip them here to avoid painting items several times. | 107 // cells they span. Skip them here to avoid painting items several times. |
115 LayoutBox* current = gridItemAndPaintIndex.first; | 108 LayoutBox* current = gridItemAndPaintIndex.first; |
116 if (current == previous) | 109 if (current == previous) |
117 continue; | 110 continue; |
118 | 111 |
119 BlockPainter(m_layoutGrid) | 112 BlockPainter(m_layoutGrid) |
120 .paintAllChildPhasesAtomically(*current, paintInfo, paintOffset); | 113 .paintAllChildPhasesAtomically(*current, paintInfo, paintOffset); |
121 previous = current; | 114 previous = current; |
122 } | 115 } |
123 } | 116 } |
124 | 117 |
125 } // namespace blink | 118 } // namespace blink |
OLD | NEW |