Commit bb2388b6 authored by wangxianzhu's avatar wangxianzhu Committed by Commit bot

Don't always invalidate collapsed borders during table layout

Many layout changes e.g. resizing doesn't affect computed collapsed
borders so don't need to invalidate collapsed borders.

We need to invalidate collapsed borders when
1. Table sections are set need recalc (when table structure changes);
2. A cell is appended into a row (which could belong to 1 but we have an
   optimization not to recalc table sections if the added cell is the
   last cell of the table);
3. Border style changes;
4. border-collapse CSS property changes;

This CL will reduce frame time of PerformanceTests/Mutation/large-
table-row-height-change-with-collapsed-border.html (in
https://codereview.chromium.org/2842313002/) by about 35% by avoiding
unnecessary collapsed border recalculations.

BUG=626748

Review-Url: https://codereview.chromium.org/2840723005
Cr-Commit-Position: refs/heads/master@{#467694}
parent e79777a2
......@@ -101,8 +101,12 @@ void LayoutTable::StyleDidChange(StyleDifference diff,
if (!old_style)
return;
LayoutTableBoxComponent::InvalidateCollapsedBordersOnStyleChange(
*this, *this, diff, *old_style);
if (old_style->BorderCollapse() != StyleRef().BorderCollapse()) {
InvalidateCollapsedBorders();
} else {
LayoutTableBoxComponent::InvalidateCollapsedBordersOnStyleChange(
*this, *this, diff, *old_style);
}
if (LayoutTableBoxComponent::DoCellsHaveDirtyWidth(*this, *this, diff,
*old_style))
......@@ -755,9 +759,6 @@ void LayoutTable::UpdateLayout() {
UpdateLayerTransformAfterLayout();
// Layout was changed, so probably borders too.
InvalidateCollapsedBorders();
ComputeOverflow(ClientLogicalBottom());
UpdateAfterLayout();
......@@ -777,9 +778,6 @@ void LayoutTable::UpdateLayout() {
void LayoutTable::InvalidateCollapsedBorders() {
collapsed_borders_.clear();
if (!CollapseBorders())
return;
collapsed_borders_valid_ = false;
SetMayNeedPaintInvalidation();
}
......
......@@ -392,6 +392,10 @@ class CORE_EXPORT LayoutTable final : public LayoutBlock {
needs_section_recalc_ = true;
SetNeedsLayoutAndFullPaintInvalidation(
LayoutInvalidationReason::kTableChanged);
// Grid structure affects cell adjacence relationships which affect
// conflict resolution of collapsed borders.
InvalidateCollapsedBorders();
}
LayoutTableSection* SectionAbove(
......@@ -406,7 +410,11 @@ class CORE_EXPORT LayoutTable final : public LayoutBlock {
LayoutTableCell* CellBefore(const LayoutTableCell*) const;
LayoutTableCell* CellAfter(const LayoutTableCell*) const;
typedef Vector<CollapsedBorderValue> CollapsedBorderValues;
using CollapsedBorderValues = Vector<CollapsedBorderValue>;
const CollapsedBorderValues& CollapsedBorders() const {
DCHECK(collapsed_borders_valid_);
return collapsed_borders_;
}
void InvalidateCollapsedBorders();
bool HasSections() const { return Header() || Footer() || FirstBody(); }
......@@ -436,11 +444,6 @@ class CORE_EXPORT LayoutTable final : public LayoutBlock {
void PaintMask(const PaintInfo&, const LayoutPoint&) const final;
const CollapsedBorderValues& CollapsedBorders() const {
DCHECK(collapsed_borders_valid_);
return collapsed_borders_;
}
void SubtractCaptionRect(LayoutRect&) const;
bool IsLogicalWidthAuto() const;
......
......@@ -171,6 +171,7 @@ void LayoutTableRow::AddChild(LayoutObject* child, LayoutObject* before_child) {
// 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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment