Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(459)

Side by Side Diff: Source/core/paint/GridPainter.cpp

Issue 594293002: Move painting code from RenderGrid to GridPainter. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix debug build. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/paint/GridPainter.h ('k') | Source/core/rendering/RenderGrid.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "core/paint/GridPainter.h"
7
8 #include "core/rendering/PaintInfo.h"
9 #include "core/rendering/RenderGrid.h"
10
11 namespace blink {
12
13 static GridSpan dirtiedGridAreas(const Vector<LayoutUnit>& coordinates, LayoutUn it start, LayoutUnit end)
14 {
15 // This function does a binary search over the coordinates.
16 // This doesn't work with grid items overflowing their grid areas, but that is managed with m_gridItemsOverflowingGridArea.
17
18 size_t startGridAreaIndex = std::upper_bound(coordinates.begin(), coordinate s.end() - 1, start) - coordinates.begin();
19 if (startGridAreaIndex > 0)
20 --startGridAreaIndex;
21
22 size_t endGridAreaIndex = std::upper_bound(coordinates.begin() + startGridAr eaIndex, coordinates.end() - 1, end) - coordinates.begin();
23 if (endGridAreaIndex > 0)
24 --endGridAreaIndex;
25
26 return GridSpan(startGridAreaIndex, endGridAreaIndex);
27 }
28
29 class GridItemsSorter {
30 public:
31 bool operator()(const std::pair<RenderBox*, size_t>& firstChild, const std:: pair<RenderBox*, size_t>& secondChild) const
32 {
33 if (firstChild.first->style()->order() != secondChild.first->style()->or der())
34 return firstChild.first->style()->order() < secondChild.first->style ()->order();
35
36 return firstChild.second < secondChild.second;
37 }
38 };
39
40 void GridPainter::paintChildren(PaintInfo& paintInfo, const LayoutPoint& paintOf fset)
41 {
42 ASSERT_WITH_SECURITY_IMPLICATION(!m_renderGrid.gridIsDirty());
43
44 LayoutRect localPaintInvalidationRect = paintInfo.rect;
45 localPaintInvalidationRect.moveBy(-paintOffset);
46
47 GridSpan dirtiedColumns = dirtiedGridAreas(m_renderGrid.columnPositions(), l ocalPaintInvalidationRect.x(), localPaintInvalidationRect.maxX());
48 GridSpan dirtiedRows = dirtiedGridAreas(m_renderGrid.rowPositions(), localPa intInvalidationRect.y(), localPaintInvalidationRect.maxY());
49
50 Vector<std::pair<RenderBox*, size_t> > gridItemsToBePainted;
51
52 for (GridSpan::iterator row = dirtiedRows.begin(); row != dirtiedRows.end(); ++row) {
53 for (GridSpan::iterator column = dirtiedColumns.begin(); column != dirti edColumns.end(); ++column) {
54 const Vector<RenderBox*, 1>& children = m_renderGrid.gridCell(row.to Int(), column.toInt());
55 for (size_t j = 0; j < children.size(); ++j)
56 gridItemsToBePainted.append(std::make_pair(children[j], m_render Grid.paintIndexForGridItem(children[j])));
57 }
58 }
59
60 for (Vector<RenderBox*>::const_iterator it = m_renderGrid.itemsOverflowingGr idArea().begin(); it != m_renderGrid.itemsOverflowingGridArea().end(); ++it) {
61 if ((*it)->frameRect().intersects(localPaintInvalidationRect))
62 gridItemsToBePainted.append(std::make_pair(*it, m_renderGrid.paintIn dexForGridItem(*it)));
63 }
64
65 // Sort grid items following order-modified document order.
66 // See http://www.w3.org/TR/css-flexbox/#order-modified-document-order
67 std::stable_sort(gridItemsToBePainted.begin(), gridItemsToBePainted.end(), G ridItemsSorter());
68
69 RenderBox* previous = 0;
70 for (Vector<std::pair<RenderBox*, size_t> >::const_iterator it = gridItemsTo BePainted.begin(); it != gridItemsToBePainted.end(); ++it) {
71 // We might have duplicates because of spanning children are included in all cells they span.
72 // Skip them here to avoid painting items several times.
73 RenderBox* current = it->first;
74 if (current == previous)
75 continue;
76
77 paintChild(current, paintInfo, paintOffset);
78 previous = current;
79 }
80 }
81
82 void GridPainter::paintChild(RenderBox* child, PaintInfo& paintInfo, const Layou tPoint& paintOffset)
83 {
84 LayoutPoint childPoint = m_renderGrid.flipForWritingModeForChild(child, pain tOffset);
85 if (!child->hasSelfPaintingLayer() && !child->isFloating())
86 child->paint(paintInfo, childPoint);
87 }
88
89 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/paint/GridPainter.h ('k') | Source/core/rendering/RenderGrid.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698