Index: third_party/WebKit/Source/core/layout/LayoutTable.cpp |
diff --git a/third_party/WebKit/Source/core/layout/LayoutTable.cpp b/third_party/WebKit/Source/core/layout/LayoutTable.cpp |
index c0bb217186c7c7920a379781fad95237bbd71264..e89e3838665c20bf8a72b020b9e78c2397f6ddd1 100644 |
--- a/third_party/WebKit/Source/core/layout/LayoutTable.cpp |
+++ b/third_party/WebKit/Source/core/layout/LayoutTable.cpp |
@@ -103,12 +103,12 @@ void LayoutTable::StyleDidChange(StyleDifference diff, |
if (!old_style) |
return; |
- if (old_style->BorderCollapse() != StyleRef().BorderCollapse()) { |
- InvalidateCollapsedBorders(); |
- } else { |
- LayoutTableBoxComponent::InvalidateCollapsedBordersOnStyleChange( |
- *this, *this, diff, *old_style); |
- } |
+ if (old_style->BorderCollapse() != StyleRef().BorderCollapse()) |
+ SetNeedsInvalidateCollapsedBordersForAllCells(); |
+ else if (LayoutTableBoxComponent:: |
+ NeedsInvalidateCollapsedBordersOnStyleChange(*this, *this, diff, |
+ *old_style)) |
+ InvalidateCollapsedBordersOfAffectedCells(); |
if (LayoutTableBoxComponent::DoCellsHaveDirtyWidth(*this, *this, diff, |
*old_style)) |
@@ -807,6 +807,40 @@ void LayoutTable::InvalidateCollapsedBordersForAllCellsIfNeeded() { |
} |
} |
+void LayoutTable::InvalidateCollapsedBordersOfAffectedCells() { |
+ DCHECK(CollapseBorders()); |
+ if (NeedsInvalidateCollapsedBordersForAllCells()) |
+ return; |
+ |
+ RecalcSectionsIfNeeded(); |
+ InvalidateCollapsedBorders(); |
+ |
+ auto* top_section = TopNonEmptySection(); |
+ if (!top_section) |
+ return; |
+ |
+ // Invalidate cells in the top row. |
+ top_section->InvalidateCellCollapsedBordersIntersectingRow(0); |
+ |
+ LayoutTableSection* bottom_section = nullptr; |
+ for (auto* section = top_section; section; |
+ section = SectionBelow(section, kSkipEmptySections)) { |
+ auto num_effective_columns = section->NumEffectiveColumns(); |
+ for (unsigned r = 0; r < section->NumRows(); ++r) { |
+ if (auto* cell = section->PrimaryCellAt(r, 0)) |
+ cell->InvalidateCollapsedBorderValues(); |
+ if (auto* cell = section->PrimaryCellAt(r, num_effective_columns - 1)) |
+ cell->InvalidateCollapsedBorderValues(); |
+ } |
+ bottom_section = section; |
+ } |
+ |
+ if (bottom_section != top_section || bottom_section->NumRows() > 1) { |
+ bottom_section->InvalidateCellCollapsedBordersIntersectingRow( |
+ bottom_section->NumRows() - 1); |
+ } |
+} |
+ |
// Collect all the unique border values that we want to paint in a sorted list. |
// During the collection, each cell saves its recalculated borders into the |
// cache of its containing section, and invalidates itself if any border |
@@ -1495,56 +1529,16 @@ LayoutTableSection* LayoutTable::BottomSection() const { |
LayoutTableCell* LayoutTable::CellAbove(const LayoutTableCell* cell) const { |
RecalcSectionsIfNeeded(); |
- |
- // Find the section and row to look in |
wkorman
2017/04/27 22:05:36
Is the simplified logic here and in CellBelow bene
|
- unsigned r = cell->RowIndex(); |
- LayoutTableSection* section = nullptr; |
- unsigned r_above = 0; |
- if (r > 0) { |
- // cell is not in the first row, so use the above row in its own section |
- section = cell->Section(); |
- r_above = r - 1; |
- } else { |
- section = SectionAbove(cell->Section(), kSkipEmptySections); |
- if (section) { |
- DCHECK(section->NumRows()); |
- r_above = section->NumRows() - 1; |
- } |
- } |
- |
- // Look up the cell in the section's grid, which requires effective col index |
- if (section) { |
- unsigned eff_col = |
- AbsoluteColumnToEffectiveColumn(cell->AbsoluteColumnIndex()); |
- return section->PrimaryCellAt(r_above, eff_col); |
- } |
- return nullptr; |
+ return cell->Section()->PrimaryCellAboveInTable( |
+ cell->RowIndex(), |
+ AbsoluteColumnToEffectiveColumn(cell->AbsoluteColumnIndex())); |
} |
LayoutTableCell* LayoutTable::CellBelow(const LayoutTableCell* cell) const { |
RecalcSectionsIfNeeded(); |
- |
- // Find the section and row to look in |
- unsigned r = cell->RowIndex() + cell->RowSpan() - 1; |
- LayoutTableSection* section = nullptr; |
- unsigned r_below = 0; |
- if (r < cell->Section()->NumRows() - 1) { |
- // The cell is not in the last row, so use the next row in the section. |
- section = cell->Section(); |
- r_below = r + 1; |
- } else { |
- section = SectionBelow(cell->Section(), kSkipEmptySections); |
- if (section) |
- r_below = 0; |
- } |
- |
- // Look up the cell in the section's grid, which requires effective col index |
- if (section) { |
- unsigned eff_col = |
- AbsoluteColumnToEffectiveColumn(cell->AbsoluteColumnIndex()); |
- return section->PrimaryCellAt(r_below, eff_col); |
- } |
- return nullptr; |
+ return cell->Section()->PrimaryCellBelowInTable( |
+ cell->RowIndex(), |
+ AbsoluteColumnToEffectiveColumn(cell->AbsoluteColumnIndex())); |
} |
LayoutTableCell* LayoutTable::CellBefore(const LayoutTableCell* cell) const { |