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

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutTableCell.cpp

Issue 2805103003: Optimize collapsed border calculation (step 2) (Closed)
Patch Set: - Created 3 years, 7 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1997 Martin Jones (mjones@kde.org) 2 * Copyright (C) 1997 Martin Jones (mjones@kde.org)
3 * (C) 1997 Torben Weis (weis@kde.org) 3 * (C) 1997 Torben Weis (weis@kde.org)
4 * (C) 1998 Waldo Bastian (bastian@kde.org) 4 * (C) 1998 Waldo Bastian (bastian@kde.org)
5 * (C) 1999 Lars Knoll (knoll@kde.org) 5 * (C) 1999 Lars Knoll (knoll@kde.org)
6 * (C) 1999 Antti Koivisto (koivisto@kde.org) 6 * (C) 1999 Antti Koivisto (koivisto@kde.org)
7 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. 7 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc.
8 * All rights reserved. 8 * All rights reserved.
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 LayoutBlockFlow::WillBeRemovedFromTree(); 101 LayoutBlockFlow::WillBeRemovedFromTree();
102 102
103 Section()->SetNeedsCellRecalc(); 103 Section()->SetNeedsCellRecalc();
104 104
105 // When borders collapse, removing a cell can affect the the width of 105 // When borders collapse, removing a cell can affect the the width of
106 // neighboring cells. 106 // neighboring cells.
107 LayoutTable* enclosing_table = Table(); 107 LayoutTable* enclosing_table = Table();
108 DCHECK(enclosing_table); 108 DCHECK(enclosing_table);
109 if (!enclosing_table->CollapseBorders()) 109 if (!enclosing_table->CollapseBorders())
110 return; 110 return;
111 // TODO(wangxianzhu,dgrogan): The following seems incorrect if the cell has
112 // adjacent cells other than PreviousCell() and NextCell(). Could reuse some
113 // code in LayoutTableCell::InvalidateCollapsedBordersOfAffectedCells().
111 if (PreviousCell()) { 114 if (PreviousCell()) {
112 // TODO(dgrogan): Should this be setChildNeedsLayout or setNeedsLayout? 115 // TODO(dgrogan): Should this be setChildNeedsLayout or setNeedsLayout?
113 // remove-cell-with-border-box.html only passes with setNeedsLayout but 116 // remove-cell-with-border-box.html only passes with setNeedsLayout but
114 // other places use setChildNeedsLayout. 117 // other places use setChildNeedsLayout.
115 PreviousCell()->SetNeedsLayout(LayoutInvalidationReason::kTableChanged); 118 PreviousCell()->SetNeedsLayout(LayoutInvalidationReason::kTableChanged);
116 PreviousCell()->SetPreferredLogicalWidthsDirty(); 119 PreviousCell()->SetPreferredLogicalWidthsDirty();
117 } 120 }
118 if (NextCell()) { 121 if (NextCell()) {
119 // TODO(dgrogan): Same as above re: setChildNeedsLayout vs setNeedsLayout. 122 // TODO(dgrogan): Same as above re: setChildNeedsLayout vs setNeedsLayout.
120 NextCell()->SetNeedsLayout(LayoutInvalidationReason::kTableChanged); 123 NextCell()->SetNeedsLayout(LayoutInvalidationReason::kTableChanged);
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 // it from scratch. 493 // it from scratch.
491 if (Style()->VerticalAlign() != old_style->VerticalAlign()) 494 if (Style()->VerticalAlign() != old_style->VerticalAlign())
492 ClearIntrinsicPadding(); 495 ClearIntrinsicPadding();
493 496
494 if (!Parent()) 497 if (!Parent())
495 return; 498 return;
496 LayoutTable* table = Table(); 499 LayoutTable* table = Table();
497 if (!table) 500 if (!table)
498 return; 501 return;
499 502
500 LayoutTableBoxComponent::InvalidateCollapsedBordersOnStyleChange( 503 if (LayoutTableBoxComponent::NeedsInvalidateCollapsedBordersOnStyleChange(
501 *this, *table, diff, *old_style); 504 *this, *table, diff, *old_style))
505 InvalidateCollapsedBordersOfAffectedCells();
502 506
503 if (LayoutTableBoxComponent::DoCellsHaveDirtyWidth(*this, *table, diff, 507 if (LayoutTableBoxComponent::DoCellsHaveDirtyWidth(*this, *table, diff,
504 *old_style)) { 508 *old_style)) {
509 // TODO(wangxianzhu,dgrogan): The following seems incorrect if the cell has
dgrogan 2017/04/27 20:43:25 Could you expound on this a little? When can a cel
Xianzhu 2017/04/27 21:18:31 Actually I'm not very sure if the TODO is valid. I
510 // adjacent cells other than PreviousCell() and NextCell(). Could reuse some
511 // code in LayoutTableCell::InvalidateCollapsedBordersOfAffectedCells().
505 if (PreviousCell()) { 512 if (PreviousCell()) {
506 // TODO(dgrogan) Add a layout test showing that setChildNeedsLayout is 513 // TODO(dgrogan) Add a layout test showing that setChildNeedsLayout is
507 // needed instead of setNeedsLayout. 514 // needed instead of setNeedsLayout.
508 PreviousCell()->SetChildNeedsLayout(); 515 PreviousCell()->SetChildNeedsLayout();
509 PreviousCell()->SetPreferredLogicalWidthsDirty(kMarkOnlyThis); 516 PreviousCell()->SetPreferredLogicalWidthsDirty(kMarkOnlyThis);
510 } 517 }
511 if (NextCell()) { 518 if (NextCell()) {
512 // TODO(dgrogan) Add a layout test showing that setChildNeedsLayout is 519 // TODO(dgrogan) Add a layout test showing that setChildNeedsLayout is
513 // needed instead of setNeedsLayout. 520 // needed instead of setNeedsLayout.
514 NextCell()->SetChildNeedsLayout(); 521 NextCell()->SetChildNeedsLayout();
(...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after
1254 2); 1261 2);
1255 } 1262 }
1256 return LayoutUnit(); 1263 return LayoutUnit();
1257 } 1264 }
1258 1265
1259 void LayoutTableCell::Paint(const PaintInfo& paint_info, 1266 void LayoutTableCell::Paint(const PaintInfo& paint_info,
1260 const LayoutPoint& paint_offset) const { 1267 const LayoutPoint& paint_offset) const {
1261 TableCellPainter(*this).Paint(paint_info, paint_offset); 1268 TableCellPainter(*this).Paint(paint_info, paint_offset);
1262 } 1269 }
1263 1270
1271 void LayoutTableCell::InvalidateCollapsedBordersOfAffectedCells() {
1272 auto* table = this->Table();
1273 DCHECK(table && table->CollapseBorders());
1274 if (table->NeedsInvalidateCollapsedBordersForAllCells())
1275 return;
1276
1277 table->RecalcSectionsIfNeeded();
1278 table->InvalidateCollapsedBorders();
1279
1280 InvalidateCollapsedBorderValues();
1281
1282 auto col_span = this->ColSpan();
1283 auto row_span = this->RowSpan();
1284 auto row = RowIndex();
1285 auto effective_column =
1286 table->AbsoluteColumnToEffectiveColumn(AbsoluteColumnIndex());
1287 auto end_effective_column =
1288 table->AbsoluteColumnToEffectiveColumn(AbsoluteColumnIndex() + col_span);
1289 auto* section = this->Section();
1290
1291 // Invalidate cells above and below this cell.
1292 for (auto c = effective_column; c < end_effective_column; ++c) {
1293 if (auto* cell = section->PrimaryCellAboveInTable(row, c))
1294 cell->InvalidateCollapsedBorderValues();
1295 if (auto* cell = section->PrimaryCellBelowInTable(row, c))
1296 cell->InvalidateCollapsedBorderValues();
1297 }
1298 // Invalidate cells before and after this cell.
1299 for (unsigned i = 0; i < row_span; ++i) {
1300 if (effective_column > 0) {
1301 if (auto* cell = section->PrimaryCellAt(row + i, effective_column - 1))
1302 cell->InvalidateCollapsedBorderValues();
1303 }
1304 if (auto* cell = section->PrimaryCellAt(row + i, end_effective_column))
1305 cell->InvalidateCollapsedBorderValues();
1306 }
1307 }
1308
1264 void LayoutTableCell::RecalcCollapsedBorderValuesIfNeeded() const { 1309 void LayoutTableCell::RecalcCollapsedBorderValuesIfNeeded() const {
1265 Table()->InvalidateCollapsedBordersForAllCellsIfNeeded(); 1310 Table()->InvalidateCollapsedBordersForAllCellsIfNeeded();
1266 if (collapsed_border_values_valid_) 1311 if (collapsed_border_values_valid_)
1267 return; 1312 return;
1268 1313
1269 collapsed_border_values_valid_ = true; 1314 collapsed_border_values_valid_ = true;
1270 1315
1271 if (!Table()->CollapseBorders()) { 1316 if (!Table()->CollapseBorders()) {
1272 if (collapsed_border_values_) { 1317 if (collapsed_border_values_) {
1273 collapsed_borders_visually_changed_ = true; 1318 collapsed_borders_visually_changed_ = true;
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1472 } 1517 }
1473 1518
1474 bool LayoutTableCell::HasLineIfEmpty() const { 1519 bool LayoutTableCell::HasLineIfEmpty() const {
1475 if (GetNode() && HasEditableStyle(*GetNode())) 1520 if (GetNode() && HasEditableStyle(*GetNode()))
1476 return true; 1521 return true;
1477 1522
1478 return LayoutBlock::HasLineIfEmpty(); 1523 return LayoutBlock::HasLineIfEmpty();
1479 } 1524 }
1480 1525
1481 } // namespace blink 1526 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698