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/TableSectionPainter.h" | 5 #include "core/paint/TableSectionPainter.h" |
6 | 6 |
7 #include "core/layout/LayoutTableCell.h" | 7 #include "core/layout/LayoutTableCell.h" |
8 #include "core/layout/LayoutTableCol.h" | 8 #include "core/layout/LayoutTableCol.h" |
9 #include "core/layout/LayoutTableRow.h" | 9 #include "core/layout/LayoutTableRow.h" |
10 #include "core/layout/LayoutView.h" | |
10 #include "core/paint/BoxClipper.h" | 11 #include "core/paint/BoxClipper.h" |
11 #include "core/paint/ObjectPainter.h" | 12 #include "core/paint/ObjectPainter.h" |
12 #include "core/paint/PaintInfo.h" | 13 #include "core/paint/PaintInfo.h" |
14 #include "core/paint/PaintLayer.h" | |
13 #include "core/paint/TableCellPainter.h" | 15 #include "core/paint/TableCellPainter.h" |
14 #include "core/paint/TableRowPainter.h" | 16 #include "core/paint/TableRowPainter.h" |
15 #include <algorithm> | 17 #include <algorithm> |
16 | 18 |
17 namespace blink { | 19 namespace blink { |
18 | 20 |
19 inline const LayoutTableCell* TableSectionPainter::primaryCellToPaint(unsigned r ow, unsigned column, const CellSpan& dirtiedRows, const CellSpan& dirtiedColumns ) const | 21 inline const LayoutTableCell* TableSectionPainter::primaryCellToPaint(unsigned r ow, unsigned column, const CellSpan& dirtiedRows, const CellSpan& dirtiedColumns ) const |
20 { | 22 { |
21 DCHECK(row >= dirtiedRows.start() && row < dirtiedRows.end()); | 23 DCHECK(row >= dirtiedRows.start() && row < dirtiedRows.end()); |
22 DCHECK(column >= dirtiedColumns.start() && column < dirtiedColumns.end()); | 24 DCHECK(column >= dirtiedColumns.start() && column < dirtiedColumns.end()); |
23 | 25 |
24 const LayoutTableCell* cell = m_layoutTableSection.primaryCellAt(row, column ); | 26 const LayoutTableCell* cell = m_layoutTableSection.primaryCellAt(row, column ); |
25 if (!cell) | 27 if (!cell) |
26 return nullptr; | 28 return nullptr; |
27 // We have painted (row, column) when painting (row - 1, column). | 29 // We have painted (row, column) when painting (row - 1, column). |
28 if (row > dirtiedRows.start() && m_layoutTableSection.primaryCellAt(row - 1, column) == cell) | 30 if (row > dirtiedRows.start() && m_layoutTableSection.primaryCellAt(row - 1, column) == cell) |
29 return nullptr; | 31 return nullptr; |
30 // We have painted (row, column) when painting (row, column -1). | 32 // We have painted (row, column) when painting (row, column -1). |
31 if (column > dirtiedColumns.start() && m_layoutTableSection.primaryCellAt(ro w, column - 1) == cell) | 33 if (column > dirtiedColumns.start() && m_layoutTableSection.primaryCellAt(ro w, column - 1) == cell) |
32 return nullptr; | 34 return nullptr; |
33 return cell; | 35 return cell; |
34 } | 36 } |
35 | 37 |
38 void TableSectionPainter::paintRepeatingHeaderGroup(const PaintInfo& paintInfo, const LayoutPoint& paintOffset, const CollapsedBorderValue& currentBorderValue, ItemToPaint itemToPaint) | |
39 { | |
40 if (m_layoutTableSection.getPaginationBreakability() == LayoutBox::AllowAnyB reaks) | |
41 return; | |
42 // TODO(rhogan): We don't paint a header repeatedly if it's self-painting. | |
Xianzhu
2016/06/02 23:03:52
Nit: This sentence actually describes a bug, but g
| |
43 if (m_layoutTableSection.layer() && m_layoutTableSection.layer()->isSelfPain tingLayer()) | |
Xianzhu
2016/06/02 23:03:52
Use hasSelfPaintingLayer().
| |
44 return; | |
45 LayoutUnit printedPageLogicalHeight = m_layoutTableSection.view() ? m_layout TableSection.view()->pageLogicalHeight() : LayoutUnit(); | |
Xianzhu
2016/06/02 23:03:52
Nit: During painting, we can be sure that any layo
| |
46 LayoutTable* table = m_layoutTableSection.table(); | |
47 LayoutUnit pageHeight = std::max(printedPageLogicalHeight, table->flowThread ContainingBlock() ? table->pageLogicalHeightForOffset(LayoutUnit()) : LayoutUnit ()); | |
Xianzhu
2016/06/02 23:03:53
Can you try
LayoutUnit pageHeight = table->pageL
| |
48 if (!pageHeight) | |
49 return; | |
50 | |
51 int pages = static_cast<int>(ceilf(table->logicalHeight() / pageHeight)); | |
52 LayoutPoint paginationOffset = paintOffset; | |
53 paginationOffset += LayoutPoint(0, pageHeight - table->pageLogicalOffset()); | |
54 for (int i = 1; i < pages; i++) { | |
Xianzhu
2016/06/02 23:03:52
You can reduce number of iterations of the loop li
| |
55 if (paintInfo.cullRect().intersectsVerticalRange(paginationOffset.y(), p aginationOffset.y() + pageHeight)) { | |
56 if (itemToPaint == PaintCollapsedBorders) | |
57 paintCollapsedSectionBorders(paintInfo.forDescendants(), paginat ionOffset, currentBorderValue); | |
58 else | |
59 paintChild(paintInfo.forDescendants(), paginationOffset); | |
60 } | |
61 paginationOffset += LayoutPoint(0, pageHeight); | |
Xianzhu
2016/06/02 23:03:52
Nit: (optional) pageinationOffset.move(0, pageHeig
| |
62 } | |
63 } | |
64 | |
36 void TableSectionPainter::paint(const PaintInfo& paintInfo, const LayoutPoint& p aintOffset) | 65 void TableSectionPainter::paint(const PaintInfo& paintInfo, const LayoutPoint& p aintOffset) |
37 { | 66 { |
67 paintChild(paintInfo, paintOffset); | |
68 LayoutTable* table = m_layoutTableSection.table(); | |
69 if (table->header() == m_layoutTableSection) | |
70 paintRepeatingHeaderGroup(paintInfo, paintOffset, CollapsedBorderValue() , PaintChild); | |
71 } | |
72 | |
73 void TableSectionPainter::paintChild(const PaintInfo& paintInfo, const LayoutPoi nt& paintOffset) | |
Xianzhu
2016/06/02 23:03:52
The name looks not appropriate because it paints t
| |
74 { | |
38 DCHECK(!m_layoutTableSection.needsLayout()); | 75 DCHECK(!m_layoutTableSection.needsLayout()); |
39 // avoid crashing on bugs that cause us to paint with dirty layout | 76 // avoid crashing on bugs that cause us to paint with dirty layout |
40 if (m_layoutTableSection.needsLayout()) | 77 if (m_layoutTableSection.needsLayout()) |
41 return; | 78 return; |
42 | 79 |
43 unsigned totalRows = m_layoutTableSection.numRows(); | 80 unsigned totalRows = m_layoutTableSection.numRows(); |
44 unsigned totalCols = m_layoutTableSection.table()->numEffectiveColumns(); | 81 unsigned totalCols = m_layoutTableSection.table()->numEffectiveColumns(); |
45 | 82 |
46 if (!totalRows || !totalCols) | 83 if (!totalRows || !totalCols) |
47 return; | 84 return; |
(...skipping 21 matching lines...) Expand all Loading... | |
69 static inline bool compareCellPositionsWithOverflowingCells(LayoutTableCell* ele m1, LayoutTableCell* elem2) | 106 static inline bool compareCellPositionsWithOverflowingCells(LayoutTableCell* ele m1, LayoutTableCell* elem2) |
70 { | 107 { |
71 if (elem1->rowIndex() != elem2->rowIndex()) | 108 if (elem1->rowIndex() != elem2->rowIndex()) |
72 return elem1->rowIndex() < elem2->rowIndex(); | 109 return elem1->rowIndex() < elem2->rowIndex(); |
73 | 110 |
74 return elem1->absoluteColumnIndex() < elem2->absoluteColumnIndex(); | 111 return elem1->absoluteColumnIndex() < elem2->absoluteColumnIndex(); |
75 } | 112 } |
76 | 113 |
77 void TableSectionPainter::paintCollapsedBorders(const PaintInfo& paintInfo, cons t LayoutPoint& paintOffset, const CollapsedBorderValue& currentBorderValue) | 114 void TableSectionPainter::paintCollapsedBorders(const PaintInfo& paintInfo, cons t LayoutPoint& paintOffset, const CollapsedBorderValue& currentBorderValue) |
78 { | 115 { |
116 paintCollapsedSectionBorders(paintInfo, paintOffset, currentBorderValue); | |
117 LayoutTable* table = m_layoutTableSection.table(); | |
118 if (table->header() == m_layoutTableSection) | |
119 paintRepeatingHeaderGroup(paintInfo, paintOffset, currentBorderValue, Pa intCollapsedBorders); | |
120 } | |
121 | |
122 void TableSectionPainter::paintCollapsedSectionBorders(const PaintInfo& paintInf o, const LayoutPoint& paintOffset, const CollapsedBorderValue& currentBorderValu e) | |
123 { | |
79 if (!m_layoutTableSection.numRows() || !m_layoutTableSection.table()->effect iveColumns().size()) | 124 if (!m_layoutTableSection.numRows() || !m_layoutTableSection.table()->effect iveColumns().size()) |
80 return; | 125 return; |
81 | 126 |
82 LayoutPoint adjustedPaintOffset = paintOffset + m_layoutTableSection.locatio n(); | 127 LayoutPoint adjustedPaintOffset = paintOffset + m_layoutTableSection.locatio n(); |
83 BoxClipper boxClipper(m_layoutTableSection, paintInfo, adjustedPaintOffset, ForceContentsClip); | 128 BoxClipper boxClipper(m_layoutTableSection, paintInfo, adjustedPaintOffset, ForceContentsClip); |
84 | 129 |
85 LayoutRect localPaintInvalidationRect = LayoutRect(paintInfo.cullRect().m_re ct); | 130 LayoutRect localPaintInvalidationRect = LayoutRect(paintInfo.cullRect().m_re ct); |
86 localPaintInvalidationRect.moveBy(-adjustedPaintOffset); | 131 localPaintInvalidationRect.moveBy(-adjustedPaintOffset); |
87 | 132 |
88 LayoutRect tableAlignedRect = m_layoutTableSection.logicalRectForWritingMode AndDirection(localPaintInvalidationRect); | 133 LayoutRect tableAlignedRect = m_layoutTableSection.logicalRectForWritingMode AndDirection(localPaintInvalidationRect); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
231 | 276 |
232 void TableSectionPainter::paintCell(const LayoutTableCell& cell, const PaintInfo & paintInfoForCells, const LayoutPoint& paintOffset) | 277 void TableSectionPainter::paintCell(const LayoutTableCell& cell, const PaintInfo & paintInfoForCells, const LayoutPoint& paintOffset) |
233 { | 278 { |
234 if (!cell.hasSelfPaintingLayer() && !cell.row()->hasSelfPaintingLayer()) { | 279 if (!cell.hasSelfPaintingLayer() && !cell.row()->hasSelfPaintingLayer()) { |
235 LayoutPoint cellPoint = m_layoutTableSection.flipForWritingModeForChild( &cell, paintOffset); | 280 LayoutPoint cellPoint = m_layoutTableSection.flipForWritingModeForChild( &cell, paintOffset); |
236 cell.paint(paintInfoForCells, cellPoint); | 281 cell.paint(paintInfoForCells, cellPoint); |
237 } | 282 } |
238 } | 283 } |
239 | 284 |
240 } // namespace blink | 285 } // namespace blink |
OLD | NEW |