Index: third_party/WebKit/Source/core/layout/LayoutTableRow.cpp |
diff --git a/third_party/WebKit/Source/core/layout/LayoutTableRow.cpp b/third_party/WebKit/Source/core/layout/LayoutTableRow.cpp |
index b18c797e6ed844e346b6d23b586ab4efcc5706b2..98063f238fce64a43f6f32a8f3df60f225abc7ec 100644 |
--- a/third_party/WebKit/Source/core/layout/LayoutTableRow.cpp |
+++ b/third_party/WebKit/Source/core/layout/LayoutTableRow.cpp |
@@ -71,11 +71,15 @@ void LayoutTableRow::StyleDidChange(StyleDifference diff, |
if (!table) |
return; |
- LayoutTableBoxComponent::InvalidateCollapsedBordersOnStyleChange( |
- *this, *table, diff, *old_style); |
+ if (LayoutTableBoxComponent::NeedsInvalidateCollapsedBordersOnStyleChange( |
+ *this, *table, diff, *old_style)) |
+ InvalidateCollapsedBordersOfAffectedCells(); |
if (LayoutTableBoxComponent::DoCellsHaveDirtyWidth(*this, *table, diff, |
*old_style)) { |
+ // TODO(wangxianzhu,dgrogan): The following seems incorrect the row's border |
+ // is used by cells not in this row. Could reuse some code in |
+ // InvalidateCollapsedBordersOfAffectedCells(). |
// If the border width changes on a row, we need to make sure the cells in |
// the row know to lay out again. |
// This only happens when borders are collapsed, since they end up affecting |
@@ -166,24 +170,31 @@ void LayoutTableRow::AddChild(LayoutObject* child, LayoutObject* before_child) { |
// Generated content can result in us having a null section so make sure to |
// null check our parent. |
- if (Parent()) { |
- Section()->AddCell(cell, this); |
- // When borders collapse, adding a cell can affect the the width of |
- // neighboring cells. |
- LayoutTable* enclosing_table = Table(); |
- if (enclosing_table && enclosing_table->CollapseBorders()) { |
- enclosing_table->InvalidateCollapsedBorders(); |
- if (LayoutTableCell* previous_cell = cell->PreviousCell()) |
- previous_cell->SetNeedsLayoutAndPrefWidthsRecalc( |
- LayoutInvalidationReason::kTableChanged); |
- if (LayoutTableCell* next_cell = cell->NextCell()) |
- next_cell->SetNeedsLayoutAndPrefWidthsRecalc( |
- LayoutInvalidationReason::kTableChanged); |
- } |
- } |
+ if (!Parent()) |
+ return; |
+ |
+ Section()->AddCell(cell, this); |
if (before_child || NextRow()) |
Section()->SetNeedsCellRecalc(); |
+ |
+ // When borders collapse, adding a cell can affect the the width of |
+ // neighboring cells. |
+ LayoutTable* enclosing_table = Table(); |
+ if (enclosing_table && enclosing_table->CollapseBorders()) { |
+ cell->InvalidateCollapsedBordersOfAffectedCells(); |
+ // TODO(wangxianzhu,dgrogan): The following seems incorrect if the cell has |
+ // adjacent cells other than PreviousCell() and NextCell(). Could reuse some |
+ // code in LayoutTableCell::InvalidateCollapsedBordersOfAffectedCells(). |
+ if (LayoutTableCell* previous_cell = cell->PreviousCell()) { |
+ previous_cell->SetNeedsLayoutAndPrefWidthsRecalc( |
+ LayoutInvalidationReason::kTableChanged); |
+ } |
+ if (LayoutTableCell* next_cell = cell->NextCell()) { |
+ next_cell->SetNeedsLayoutAndPrefWidthsRecalc( |
+ LayoutInvalidationReason::kTableChanged); |
+ } |
+ } |
} |
void LayoutTableRow::UpdateLayout() { |
@@ -333,4 +344,35 @@ bool LayoutTableRow::IsFirstRowInSectionAfterHeader() const { |
header->GetPaginationBreakability() != kAllowAnyBreaks; |
} |
+void LayoutTableRow::InvalidateCollapsedBordersOfAffectedCells() { |
+ auto* table = Table(); |
+ DCHECK(table->CollapseBorders()); |
+ if (table->NeedsInvalidateCollapsedBordersForAllCells()) |
+ return; |
+ |
+ table->RecalcSectionsIfNeeded(); |
+ table->InvalidateCollapsedBorders(); |
+ |
+ // Invalidate cells intersecting this row. |
+ auto* section = Section(); |
+ section->InvalidateCellCollapsedBordersIntersectingRow(RowIndex()); |
+ |
+ // Invalidate cells above this row. |
+ if (RowIndex()) { |
+ section->InvalidateCellCollapsedBordersIntersectingRow(RowIndex() - 1); |
+ } else if (auto* section_above = |
+ table->SectionAbove(section, kSkipEmptySections)) { |
+ section_above->InvalidateCellCollapsedBordersIntersectingRow( |
+ section_above->NumRows() - 1); |
+ } |
+ |
+ // Invalidate cells below this row. |
+ if (RowIndex() + 1 < section->NumRows()) { |
+ section->InvalidateCellCollapsedBordersIntersectingRow(RowIndex() + 1); |
+ } else if (auto* section_below = |
+ table->SectionBelow(section, kSkipEmptySections)) { |
+ section_below->InvalidateCellCollapsedBordersIntersectingRow(0); |
+ } |
+} |
+ |
} // namespace blink |