Commit 91f1e343 authored by wangxianzhu's avatar wangxianzhu Committed by Commit bot

Invalidate row/section for backgrounds when cell's geometry changes

https://codereview.chromium.org/2786463004/ caused the regression.
Now we paint cell's container backgrounds as display item of row/section
instead of cell, so when cell's geometry changes we need to invalidate
the container's backgrounds.

BUG=713050
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2

Review-Url: https://codereview.chromium.org/2851553002
Cr-Commit-Position: refs/heads/master@{#468056}
parent ff3fa0df
<!DOCTYPE html>
<style>
tr { height: 30px }
</style>
Should repaint the backgrounds of column (yellow), section (blue) and row (green) when cells resize.
<table id="table" style="width: 300px">
<colgroup>
<col style="background: yellow">
</colgroup>
<thead style="background: blue">
<tr>
<td>A</td><td style="width: 200px">B</td><td>C</td>
</tr>
</thead>
<tbody>
<tr style="background: green">
<td>A</td><td>B</td><td>C</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>A</td><td>B</td><td>C</td>
</tr>
</tfoot>
</table>
<!DOCTYPE html>
<style>
tr { height: 30px }
</style>
Should repaint the backgrounds of column (yellow), section (blue) and row (green) when cells resize.
<table style="width: 300px">
<colgroup>
<col style="background: yellow">
</colgroup>
<thead style="background: blue">
<tr>
<td>A</td><td id="cell" style="width: 100px">B</td><td>C</td>
</tr>
</thead>
<tbody>
<tr style="background: green">
<td>A</td><td>B</td><td>C</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>A</td><td>B</td><td>C</td>
</tr>
</tfoot>
</table>
<script src="../../../resources/run-after-layout-and-paint.js"></script>
<script>
runAfterLayoutAndPaint(function() {
cell.style.width = '200px';
}, true);
</script>
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "core/layout/SubtreeLayoutScope.h" #include "core/layout/SubtreeLayoutScope.h"
#include "core/paint/ObjectPaintInvalidator.h" #include "core/paint/ObjectPaintInvalidator.h"
#include "core/paint/PaintLayer.h" #include "core/paint/PaintLayer.h"
#include "core/paint/TableCellPaintInvalidator.h"
#include "core/paint/TableCellPainter.h" #include "core/paint/TableCellPainter.h"
#include "platform/geometry/FloatQuad.h" #include "platform/geometry/FloatQuad.h"
#include "platform/geometry/TransformState.h" #include "platform/geometry/TransformState.h"
...@@ -1491,4 +1492,14 @@ bool LayoutTableCell::HasLineIfEmpty() const { ...@@ -1491,4 +1492,14 @@ bool LayoutTableCell::HasLineIfEmpty() const {
return LayoutBlock::HasLineIfEmpty(); return LayoutBlock::HasLineIfEmpty();
} }
PaintInvalidationReason LayoutTableCell::InvalidatePaint(
const PaintInvalidatorContext& context) const {
return TableCellPaintInvalidator(*this, context).InvalidatePaint();
}
PaintInvalidationReason LayoutTableCell::InvalidatePaint(
const PaintInvalidationState& state) {
return LayoutBlockFlow::InvalidatePaint(state);
}
} // namespace blink } // namespace blink
...@@ -348,6 +348,11 @@ class CORE_EXPORT LayoutTableCell final : public LayoutBlockFlow { ...@@ -348,6 +348,11 @@ class CORE_EXPORT LayoutTableCell final : public LayoutBlockFlow {
const LayoutPoint& layer_offset, const LayoutPoint& layer_offset,
const LayoutRect& container_rect) const override; const LayoutRect& container_rect) const override;
PaintInvalidationReason InvalidatePaint(
const PaintInvalidatorContext&) const override;
PaintInvalidationReason InvalidatePaint(
const PaintInvalidationState&) override;
private: private:
friend class LayoutTableCellTest; friend class LayoutTableCellTest;
......
...@@ -172,6 +172,8 @@ blink_core_sources("paint") { ...@@ -172,6 +172,8 @@ blink_core_sources("paint") {
"ScrollbarManager.h", "ScrollbarManager.h",
"ScrollbarPainter.cpp", "ScrollbarPainter.cpp",
"ScrollbarPainter.h", "ScrollbarPainter.h",
"TableCellPaintInvalidator.cpp",
"TableCellPaintInvalidator.h",
"TableCellPainter.cpp", "TableCellPainter.cpp",
"TableCellPainter.h", "TableCellPainter.h",
"TablePaintInvalidator.cpp", "TablePaintInvalidator.cpp",
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "core/paint/TableCellPaintInvalidator.h"
#include "core/layout/LayoutTable.h"
#include "core/layout/LayoutTableCell.h"
#include "core/layout/LayoutTableCol.h"
#include "core/layout/LayoutTableRow.h"
#include "core/layout/LayoutTableSection.h"
#include "core/paint/BlockPaintInvalidator.h"
#include "core/paint/ObjectPaintInvalidator.h"
#include "core/paint/PaintInvalidator.h"
#include "core/paint/PaintLayer.h"
namespace blink {
PaintInvalidationReason TableCellPaintInvalidator::InvalidatePaint() {
// The cell's containing row and section paint backgrounds behind the cell.
// If the cell's geometry changed, invalidate the background display items.
if (context_.old_location != context_.new_location ||
cell_.Size() != cell_.PreviousSize()) {
const auto& row = *cell_.Row();
if (row.GetPaintInvalidationReason() == kPaintInvalidationNone &&
row.StyleRef().HasBackground()) {
if (RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled())
context_.parent_context->painting_layer->SetNeedsRepaint();
else
ObjectPaintInvalidator(row).SlowSetPaintingLayerNeedsRepaint();
row.InvalidateDisplayItemClients(kPaintInvalidationForcedByLayout);
}
const auto& section = *row.Section();
if (section.GetPaintInvalidationReason() == kPaintInvalidationNone) {
bool section_paints_background = section.StyleRef().HasBackground();
if (!section_paints_background) {
auto col_and_colgroup = section.Table()->ColElementAtAbsoluteColumn(
cell_.AbsoluteColumnIndex());
if ((col_and_colgroup.col &&
col_and_colgroup.col->StyleRef().HasBackground()) ||
(col_and_colgroup.colgroup &&
col_and_colgroup.colgroup->StyleRef().HasBackground()))
section_paints_background = true;
}
if (section_paints_background) {
if (RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled()) {
context_.parent_context->parent_context->painting_layer
->SetNeedsRepaint();
} else {
ObjectPaintInvalidator(section).SlowSetPaintingLayerNeedsRepaint();
}
section.InvalidateDisplayItemClients(kPaintInvalidationForcedByLayout);
}
}
}
return BlockPaintInvalidator(cell_).InvalidatePaint(context_);
}
} // namespace blink
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef TableCellPaintInvalidator_h
#define TableCellPaintInvalidator_h
#include "platform/graphics/PaintInvalidationReason.h"
#include "platform/wtf/Allocator.h"
namespace blink {
class LayoutTableCell;
struct PaintInvalidatorContext;
class TableCellPaintInvalidator {
STACK_ALLOCATED();
public:
TableCellPaintInvalidator(const LayoutTableCell& cell,
const PaintInvalidatorContext& context)
: cell_(cell), context_(context) {}
PaintInvalidationReason InvalidatePaint();
private:
const LayoutTableCell& cell_;
const PaintInvalidatorContext& context_;
};
} // namespace blink
#endif
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