Commit 3e0db462 authored by Philip Rogers's avatar Philip Rogers Committed by Commit Bot

[SPV175] Update visual rects when printing

Printing can change layout and we should update visual rects when this occurs.
After [1], visual rects are used for clipping which exposed a bug where painting
occurred with stale visual rects (the skia rtree is not used when printing which
would have exposed this in SPV1). This patch fully enables the paint
invalidation step to reduce special-cases in the document lifecycle, even though
only the visual rect update is strictly needed.

[1] https://chromium.googlesource.com/chromium/src/+/b7e8c6eb13e6eb297747b9e394854408b3f29195

Bug: 824031
Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2
Change-Id: I0b9b358b078fa15b4aa1c26b494c213d62e571c4
Reviewed-on: https://chromium-review.googlesource.com/993700Reviewed-by: default avatarXianzhu Wang <wangxianzhu@chromium.org>
Commit-Queue: Philip Rogers <pdr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547881}
parent 39c77c86
...@@ -303,6 +303,45 @@ TEST_P(PaintInvalidationTest, SVGHiddenContainer) { ...@@ -303,6 +303,45 @@ TEST_P(PaintInvalidationTest, SVGHiddenContainer) {
GetDocument().View()->SetTracksPaintInvalidations(false); GetDocument().View()->SetTracksPaintInvalidations(false);
} }
TEST_P(PaintInvalidationTest, UpdateVisualRectWhenPrinting) {
SetBodyInnerHTML(R"HTML(
<style>
* { margin: 0;}
span {
display: inline-block;
width: 150px;
height: 20px;
background: rebeccapurple;
}
</style>
<div><span id="a"></span><span id="b"></span><span id="c"></div>
)HTML");
auto* a = GetDocument().getElementById("a")->GetLayoutObject();
EXPECT_EQ(LayoutRect(0, 0, 150, 20), a->FirstFragment().VisualRect());
auto* b = GetDocument().getElementById("b")->GetLayoutObject();
EXPECT_EQ(LayoutRect(150, 0, 150, 20), b->FirstFragment().VisualRect());
auto* c = GetDocument().getElementById("c")->GetLayoutObject();
EXPECT_EQ(LayoutRect(300, 0, 150, 20), c->FirstFragment().VisualRect());
// Print the page with a width of 400px which will require wrapping 'c'.
FloatSize page_size(400, 200);
GetFrame().StartPrinting(page_size, page_size, 1);
GetDocument().View()->UpdateLifecyclePhasesForPrinting();
EXPECT_EQ(LayoutRect(0, 0, 150, 20), a->FirstFragment().VisualRect());
EXPECT_EQ(LayoutRect(150, 0, 150, 20), b->FirstFragment().VisualRect());
// 'c' should be on the next line.
EXPECT_EQ(LayoutRect(0, 20, 150, 20), c->FirstFragment().VisualRect());
GetFrame().EndPrinting();
GetDocument().View()->UpdateLifecyclePhasesForPrinting();
EXPECT_EQ(LayoutRect(0, 0, 150, 20), a->FirstFragment().VisualRect());
EXPECT_EQ(LayoutRect(150, 0, 150, 20), b->FirstFragment().VisualRect());
EXPECT_EQ(LayoutRect(300, 0, 150, 20), c->FirstFragment().VisualRect());
};
} // namespace } // namespace
} // namespace blink } // namespace blink
...@@ -559,9 +559,6 @@ void PaintInvalidator::InvalidatePaint( ...@@ -559,9 +559,6 @@ void PaintInvalidator::InvalidatePaint(
UpdatePaintingLayer(object, context); UpdatePaintingLayer(object, context);
if (document_printing_ && !RuntimeEnabledFeatures::PrintBrowserEnabled())
return; // Don't invalidate paints if we're printing.
// TODO(chrishtr): refactor to remove these slow paths by expanding their // TODO(chrishtr): refactor to remove these slow paths by expanding their
// LocalVisualRect to include repeated locations. // LocalVisualRect to include repeated locations.
if (object.IsTableSection()) { if (object.IsTableSection()) {
......
...@@ -182,7 +182,6 @@ class PaintInvalidator { ...@@ -182,7 +182,6 @@ class PaintInvalidator {
PaintInvalidatorContext&); PaintInvalidatorContext&);
Vector<const LayoutObject*> pending_delayed_paint_invalidations_; Vector<const LayoutObject*> pending_delayed_paint_invalidations_;
bool document_printing_ = false;
}; };
} // namespace blink } // namespace blink
......
...@@ -90,9 +90,6 @@ void PrePaintTreeWalk::Walk(LocalFrameView& frame_view) { ...@@ -90,9 +90,6 @@ void PrePaintTreeWalk::Walk(LocalFrameView& frame_view) {
auto context = [this]() -> PrePaintTreeWalkContext& { auto context = [this]() -> PrePaintTreeWalkContext& {
return context_storage_.back(); return context_storage_.back();
}; };
AutoReset<bool> printing_reset(
&paint_invalidator_.document_printing_,
frame_view.GetFrame().GetDocument()->Printing());
// ancestorOverflowLayer does not cross frame boundaries. // ancestorOverflowLayer does not cross frame boundaries.
context().ancestor_overflow_paint_layer = nullptr; context().ancestor_overflow_paint_layer = nullptr;
......
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