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 <algorithm> |
7 #include "core/layout/LayoutTableCell.h" | 8 #include "core/layout/LayoutTableCell.h" |
8 #include "core/layout/LayoutTableCol.h" | 9 #include "core/layout/LayoutTableCol.h" |
9 #include "core/layout/LayoutTableRow.h" | 10 #include "core/layout/LayoutTableRow.h" |
10 #include "core/paint/BoxClipper.h" | 11 #include "core/paint/BoxClipper.h" |
11 #include "core/paint/BoxPainter.h" | 12 #include "core/paint/BoxPainter.h" |
12 #include "core/paint/LayoutObjectDrawingRecorder.h" | 13 #include "core/paint/LayoutObjectDrawingRecorder.h" |
13 #include "core/paint/ObjectPainter.h" | 14 #include "core/paint/ObjectPainter.h" |
14 #include "core/paint/PaintInfo.h" | 15 #include "core/paint/PaintInfo.h" |
15 #include "core/paint/TableCellPainter.h" | 16 #include "core/paint/TableCellPainter.h" |
| 17 #include "core/paint/TableCollapsedBorderPainter.h" |
16 #include "core/paint/TableRowPainter.h" | 18 #include "core/paint/TableRowPainter.h" |
17 #include <algorithm> | |
18 | 19 |
19 namespace blink { | 20 namespace blink { |
20 | 21 |
21 void TableSectionPainter::PaintRepeatingHeaderGroup( | 22 void TableSectionPainter::PaintRepeatingHeaderGroup( |
22 const PaintInfo& paint_info, | 23 const PaintInfo& paint_info, |
23 const LayoutPoint& paint_offset, | 24 const LayoutPoint& paint_offset, |
24 const CollapsedBorderValue& current_border_value, | 25 TableCollapsedBorderPainter& previous_painter, |
25 ItemToPaint item_to_paint) { | 26 ItemToPaint item_to_paint) { |
26 if (!layout_table_section_.IsRepeatingHeaderGroup()) | 27 if (!layout_table_section_.IsRepeatingHeaderGroup()) |
27 return; | 28 return; |
28 | 29 |
29 LayoutTable* table = layout_table_section_.Table(); | 30 LayoutTable* table = layout_table_section_.Table(); |
30 LayoutPoint pagination_offset = paint_offset; | 31 LayoutPoint pagination_offset = paint_offset; |
31 LayoutUnit page_height = table->PageLogicalHeightForOffset(LayoutUnit()); | 32 LayoutUnit page_height = table->PageLogicalHeightForOffset(LayoutUnit()); |
32 | 33 |
33 LayoutUnit header_group_offset = table->BlockOffsetToFirstRepeatableHeader(); | 34 LayoutUnit header_group_offset = table->BlockOffsetToFirstRepeatableHeader(); |
34 // The header may have a pagination strut before it so we need to account for | 35 // The header may have a pagination strut before it so we need to account for |
(...skipping 19 matching lines...) Expand all Loading... |
54 table->SubtractCaptionRect(sections_rect); | 55 table->SubtractCaptionRect(sections_rect); |
55 LayoutUnit total_height_of_rows = | 56 LayoutUnit total_height_of_rows = |
56 sections_rect.Height() - table->VBorderSpacing(); | 57 sections_rect.Height() - table->VBorderSpacing(); |
57 LayoutUnit bottom_bound = | 58 LayoutUnit bottom_bound = |
58 std::min(LayoutUnit(paint_info.GetCullRect().rect_.MaxY()), | 59 std::min(LayoutUnit(paint_info.GetCullRect().rect_.MaxY()), |
59 paint_offset.Y() + total_height_of_rows); | 60 paint_offset.Y() + total_height_of_rows); |
60 | 61 |
61 while (pagination_offset.Y() < bottom_bound) { | 62 while (pagination_offset.Y() < bottom_bound) { |
62 if (item_to_paint == kPaintCollapsedBorders) { | 63 if (item_to_paint == kPaintCollapsedBorders) { |
63 PaintCollapsedSectionBorders(paint_info, pagination_offset, | 64 PaintCollapsedSectionBorders(paint_info, pagination_offset, |
64 current_border_value); | 65 previous_painter); |
65 } else { | 66 } else { |
66 PaintSection(paint_info, pagination_offset); | 67 PaintSection(paint_info, pagination_offset); |
67 } | 68 } |
68 pagination_offset.Move(0, page_height.ToInt()); | 69 pagination_offset.Move(0, page_height.ToInt()); |
69 } | 70 } |
70 } | 71 } |
71 | 72 |
72 void TableSectionPainter::Paint(const PaintInfo& paint_info, | 73 void TableSectionPainter::Paint(const PaintInfo& paint_info, |
73 const LayoutPoint& paint_offset) { | 74 const LayoutPoint& paint_offset) { |
74 ObjectPainter(layout_table_section_) | 75 ObjectPainter(layout_table_section_) |
75 .CheckPaintOffset(paint_info, paint_offset); | 76 .CheckPaintOffset(paint_info, paint_offset); |
76 PaintSection(paint_info, paint_offset); | 77 PaintSection(paint_info, paint_offset); |
77 LayoutTable* table = layout_table_section_.Table(); | 78 LayoutTable* table = layout_table_section_.Table(); |
78 if (table->Header() == layout_table_section_) | 79 if (table->Header() == layout_table_section_) { |
79 PaintRepeatingHeaderGroup(paint_info, paint_offset, CollapsedBorderValue(), | 80 TableCollapsedBorderPainter old_painter; |
| 81 PaintRepeatingHeaderGroup(paint_info, paint_offset, old_painter, |
80 kPaintSection); | 82 kPaintSection); |
| 83 } |
81 } | 84 } |
82 | 85 |
83 void TableSectionPainter::PaintSection(const PaintInfo& paint_info, | 86 void TableSectionPainter::PaintSection(const PaintInfo& paint_info, |
84 const LayoutPoint& paint_offset) { | 87 const LayoutPoint& paint_offset) { |
85 DCHECK(!layout_table_section_.NeedsLayout()); | 88 DCHECK(!layout_table_section_.NeedsLayout()); |
86 // avoid crashing on bugs that cause us to paint with dirty layout | 89 // avoid crashing on bugs that cause us to paint with dirty layout |
87 if (layout_table_section_.NeedsLayout()) | 90 if (layout_table_section_.NeedsLayout()) |
88 return; | 91 return; |
89 | 92 |
90 unsigned total_rows = layout_table_section_.NumRows(); | 93 unsigned total_rows = layout_table_section_.NumRows(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 const LayoutTableCell* elem2) { | 125 const LayoutTableCell* elem2) { |
123 if (elem1->RowIndex() != elem2->RowIndex()) | 126 if (elem1->RowIndex() != elem2->RowIndex()) |
124 return elem1->RowIndex() < elem2->RowIndex(); | 127 return elem1->RowIndex() < elem2->RowIndex(); |
125 | 128 |
126 return elem1->AbsoluteColumnIndex() < elem2->AbsoluteColumnIndex(); | 129 return elem1->AbsoluteColumnIndex() < elem2->AbsoluteColumnIndex(); |
127 } | 130 } |
128 | 131 |
129 void TableSectionPainter::PaintCollapsedBorders( | 132 void TableSectionPainter::PaintCollapsedBorders( |
130 const PaintInfo& paint_info, | 133 const PaintInfo& paint_info, |
131 const LayoutPoint& paint_offset, | 134 const LayoutPoint& paint_offset, |
132 const CollapsedBorderValue& current_border_value) { | 135 TableCollapsedBorderPainter& previous_painter) { |
133 PaintCollapsedSectionBorders(paint_info, paint_offset, current_border_value); | 136 PaintCollapsedSectionBorders(paint_info, paint_offset, previous_painter); |
134 LayoutTable* table = layout_table_section_.Table(); | 137 LayoutTable* table = layout_table_section_.Table(); |
135 if (table->Header() == layout_table_section_) | 138 if (table->Header() == layout_table_section_) |
136 PaintRepeatingHeaderGroup(paint_info, paint_offset, current_border_value, | 139 PaintRepeatingHeaderGroup(paint_info, paint_offset, previous_painter, |
137 kPaintCollapsedBorders); | 140 kPaintCollapsedBorders); |
138 } | 141 } |
139 | 142 |
140 void TableSectionPainter::PaintCollapsedSectionBorders( | 143 void TableSectionPainter::PaintCollapsedSectionBorders( |
141 const PaintInfo& paint_info, | 144 const PaintInfo& paint_info, |
142 const LayoutPoint& paint_offset, | 145 const LayoutPoint& paint_offset, |
143 const CollapsedBorderValue& current_border_value) { | 146 TableCollapsedBorderPainter& previous_painter) { |
144 if (!layout_table_section_.NumRows() || | 147 if (!layout_table_section_.NumRows() || |
145 !layout_table_section_.Table()->EffectiveColumns().size()) | 148 !layout_table_section_.Table()->EffectiveColumns().size()) |
146 return; | 149 return; |
147 | |
148 LayoutPoint adjusted_paint_offset = | 150 LayoutPoint adjusted_paint_offset = |
149 paint_offset + layout_table_section_.Location(); | 151 paint_offset + layout_table_section_.Location(); |
150 BoxClipper box_clipper(layout_table_section_, paint_info, | 152 BoxClipper boxClipper(layout_table_section_, paint_info, |
151 adjusted_paint_offset, kForceContentsClip); | 153 adjusted_paint_offset, kForceContentsClip); |
152 | 154 LayoutRect local_paint_invalidation_rect = |
153 LayoutRect local_visual_rect = LayoutRect(paint_info.GetCullRect().rect_); | 155 LayoutRect(paint_info.GetCullRect().rect_); |
154 local_visual_rect.MoveBy(-adjusted_paint_offset); | 156 local_paint_invalidation_rect.MoveBy(-adjusted_paint_offset); |
155 | |
156 LayoutRect table_aligned_rect = | 157 LayoutRect table_aligned_rect = |
157 layout_table_section_.LogicalRectForWritingModeAndDirection( | 158 layout_table_section_.LogicalRectForWritingModeAndDirection( |
158 local_visual_rect); | 159 local_paint_invalidation_rect); |
159 | |
160 CellSpan dirtied_rows = layout_table_section_.DirtiedRows(table_aligned_rect); | 160 CellSpan dirtied_rows = layout_table_section_.DirtiedRows(table_aligned_rect); |
161 CellSpan dirtied_columns = | 161 CellSpan dirtied_eff_columns = |
162 layout_table_section_.DirtiedEffectiveColumns(table_aligned_rect); | 162 layout_table_section_.DirtiedEffectiveColumns(table_aligned_rect); |
163 | 163 |
164 if (dirtied_columns.Start() >= dirtied_columns.end()) | 164 TableCollapsedBorderPainter painter(&layout_table_section_); |
165 return; | 165 painter.PaintBorders(paint_info, paint_offset, dirtied_rows, |
166 | 166 dirtied_eff_columns, previous_painter); |
167 // Collapsed borders are painted from the bottom right to the top left so that | 167 previous_painter = painter; |
168 // precedence due to cell position is respected. | |
169 for (unsigned r = dirtied_rows.end(); r > dirtied_rows.Start(); r--) { | |
170 unsigned row = r - 1; | |
171 unsigned n_cols = layout_table_section_.NumCols(row); | |
172 for (unsigned c = std::min(dirtied_columns.end(), n_cols); | |
173 c > dirtied_columns.Start(); c--) { | |
174 unsigned col = c - 1; | |
175 if (const LayoutTableCell* cell = | |
176 layout_table_section_.OriginatingCellAt(row, col)) { | |
177 LayoutPoint cell_point = | |
178 layout_table_section_.FlipForWritingModeForChild( | |
179 cell, adjusted_paint_offset); | |
180 TableCellPainter(*cell).PaintCollapsedBorders(paint_info, cell_point, | |
181 current_border_value); | |
182 } | |
183 } | |
184 } | |
185 } | 168 } |
186 | 169 |
187 void TableSectionPainter::PaintObject(const PaintInfo& paint_info, | 170 void TableSectionPainter::PaintObject(const PaintInfo& paint_info, |
188 const LayoutPoint& paint_offset) { | 171 const LayoutPoint& paint_offset) { |
189 LayoutRect local_visual_rect = LayoutRect(paint_info.GetCullRect().rect_); | 172 LayoutRect local_visual_rect = LayoutRect(paint_info.GetCullRect().rect_); |
190 local_visual_rect.MoveBy(-paint_offset); | 173 local_visual_rect.MoveBy(-paint_offset); |
191 | 174 |
192 LayoutRect table_aligned_rect = | 175 LayoutRect table_aligned_rect = |
193 layout_table_section_.LogicalRectForWritingModeAndDirection( | 176 layout_table_section_.LogicalRectForWritingModeAndDirection( |
194 local_visual_rect); | 177 local_visual_rect); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 const PaintInfo& paint_info_for_cells, | 379 const PaintInfo& paint_info_for_cells, |
397 const LayoutPoint& paint_offset) { | 380 const LayoutPoint& paint_offset) { |
398 if (!cell.HasSelfPaintingLayer() && !cell.Row()->HasSelfPaintingLayer()) { | 381 if (!cell.HasSelfPaintingLayer() && !cell.Row()->HasSelfPaintingLayer()) { |
399 LayoutPoint cell_point = | 382 LayoutPoint cell_point = |
400 layout_table_section_.FlipForWritingModeForChild(&cell, paint_offset); | 383 layout_table_section_.FlipForWritingModeForChild(&cell, paint_offset); |
401 cell.Paint(paint_info_for_cells, cell_point); | 384 cell.Paint(paint_info_for_cells, cell_point); |
402 } | 385 } |
403 } | 386 } |
404 | 387 |
405 } // namespace blink | 388 } // namespace blink |
OLD | NEW |