Commit 3029f607 authored by Xianzhu Wang's avatar Xianzhu Wang Committed by Commit Bot

[PE] Fix caret visual rect and painting when scrolled

This fixes 2 problems:
1. The caret visual rect was incorrectly added by scroll offset in
   composited scrolling block;
2. The painting of caret was not clipped.

Bug: 882794
Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_layout_ng;luci.chromium.try:linux_layout_tests_slimming_paint_v2;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Ib7c6979acf6000a747e1ac8ae439633f338d3c3f
Reviewed-on: https://chromium-review.googlesource.com/c/1257892
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Reviewed-by: default avatarChris Harrelson <chrishtr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#596498}
parent dcd2eecc
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
"reason": "incremental" "reason": "incremental"
}, },
{ {
"object": "Caret", "object": "LayoutBlockFlow DIV",
"rect": [10, 58, 1, 57], "rect": [10, 58, 1, 57],
"reason": "incremental" "reason": "incremental"
} }
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
"reason": "subtree" "reason": "subtree"
}, },
{ {
"object": "Caret", "object": "LayoutBlockFlow DIV",
"rect": [209, 11, 2, 16], "rect": [209, 11, 2, 16],
"reason": "chunk appeared" "reason": "chunk appeared"
} }
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
"reason": "incremental" "reason": "incremental"
}, },
{ {
"object": "Caret", "object": "LayoutBlockFlow DIV",
"rect": [10, 58, 1, 57], "rect": [10, 58, 1, 57],
"reason": "incremental" "reason": "incremental"
} }
......
<!DOCTYPE html>
<div style="position: relative; top: 100px; width: 200px; height: 200px; overflow: hidden; border: 1px solid black">
<div id="target" contenteditable
style="position: relative; top: -50px; font-size: 100px; color: green; outline-style: none">
<br>
<br>
<br>
<br>
</div>
</div>
<script>
target.focus();
</script>
<!DOCTYPE html>
<style>
::-webkit-scrollbar { display: none; }
</style>
<div id="target" contenteditable
style="position: relative; top: 100px; width: 200px; height: 200px; overflow: scroll; will-change: transform;
font-size: 100px; border: 1px solid black; outline-style: none">
<br>
<br>
<br>
<br>
</div>
<script src="../../resources/run-after-layout-and-paint.js"></script>
<script>
target.focus();
target.scrollTop = 50;
runAfterLayoutAndPaint(function() {
target.style.color = 'green';
}, true);
</script>
<!DOCTYPE html>
<div style="position: relative; top: 100px; width: 200px; height: 200px; overflow: hidden; border: 1px solid black">
<div id="target" contenteditable
style="position: relative; top: -50px; font-size: 100px; color: green; outline-style: none">
<br>
<br>
<br>
<br>
</div>
</div>
<script>
target.focus();
</script>
<!DOCTYPE html>
<style>
::-webkit-scrollbar { display: none; }
</style>
<div id="target" contenteditable
style="position: relative; top: 100px; width: 200px; height: 200px; overflow: scroll;
font-size: 100px; border: 1px solid black; outline-style: none">
<br>
<br>
<br>
<br>
</div>
<script src="../../resources/run-after-layout-and-paint.js"></script>
<script>
target.focus();
target.scrollTop = 50;
runAfterLayoutAndPaint(function() {
target.style.color = 'green';
}, true);
</script>
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
"reason": "subtree" "reason": "subtree"
}, },
{ {
"object": "Caret", "object": "LayoutBlockFlow DIV",
"rect": [210, 11, 2, 13], "rect": [210, 11, 2, 13],
"reason": "chunk appeared" "reason": "chunk appeared"
} }
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
"reason": "incremental" "reason": "incremental"
}, },
{ {
"object": "Caret", "object": "LayoutBlockFlow DIV",
"rect": [11, 58, 1, 61], "rect": [11, 58, 1, 61],
"reason": "incremental" "reason": "incremental"
} }
......
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
"reason": "chunk appeared" "reason": "chunk appeared"
}, },
{ {
"object": "Caret", "object": "LayoutBlockFlow DIV",
"rect": [3, 1003, 1, 13], "rect": [3, 1003, 1, 13],
"reason": "chunk appeared" "reason": "chunk appeared"
} }
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
"reason": "subtree" "reason": "subtree"
}, },
{ {
"object": "Caret", "object": "LayoutBlockFlow DIV",
"rect": [209, 11, 2, 16], "rect": [209, 11, 2, 16],
"reason": "chunk appeared" "reason": "chunk appeared"
} }
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
"reason": "incremental" "reason": "incremental"
}, },
{ {
"object": "Caret", "object": "LayoutBlockFlow DIV",
"rect": [10, 58, 1, 57], "rect": [10, 58, 1, 57],
"reason": "incremental" "reason": "incremental"
} }
......
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
"reason": "chunk appeared" "reason": "chunk appeared"
}, },
{ {
"object": "Caret", "object": "LayoutBlockFlow DIV",
"rect": [3, 1003, 1, 16], "rect": [3, 1003, 1, 16],
"reason": "chunk appeared" "reason": "chunk appeared"
} }
......
...@@ -223,13 +223,6 @@ void CaretDisplayItemClient::InvalidatePaintInCurrentLayoutBlock( ...@@ -223,13 +223,6 @@ void CaretDisplayItemClient::InvalidatePaintInCurrentLayoutBlock(
if (!local_rect_.IsEmpty()) { if (!local_rect_.IsEmpty()) {
new_visual_rect = local_rect_; new_visual_rect = local_rect_;
context.MapLocalRectToVisualRect(*layout_block_, new_visual_rect); context.MapLocalRectToVisualRect(*layout_block_, new_visual_rect);
if (layout_block_->UsesCompositedScrolling()) {
// The caret should use scrolling coordinate space.
DCHECK(layout_block_ == context.paint_invalidation_container);
new_visual_rect.Move(
LayoutSize(layout_block_->ScrolledContentOffset()));
}
} }
} else { } else {
new_visual_rect = visual_rect_; new_visual_rect = visual_rect_;
......
...@@ -59,6 +59,20 @@ void BlockPainter::Paint(const PaintInfo& paint_info) { ...@@ -59,6 +59,20 @@ void BlockPainter::Paint(const PaintInfo& paint_info) {
// any painting order steps within the CSS spec. // any painting order steps within the CSS spec.
if (original_phase == PaintPhase::kForeground && if (original_phase == PaintPhase::kForeground &&
layout_block_.ShouldPaintCarets()) { layout_block_.ShouldPaintCarets()) {
// Apply overflow clip if needed. TODO(wangxianzhu): Move PaintCarets()
// under |contents_paint_state| in the above block and let the caret
// painters paint in the space of scrolling contents.
base::Optional<ScopedPaintChunkProperties> paint_chunk_properties;
if (const auto* fragment = paint_state.FragmentToPaint()) {
if (const auto* properties = fragment->PaintProperties()) {
if (const auto* overflow_clip = properties->OverflowClip()) {
paint_chunk_properties.emplace(
paint_info.context.GetPaintController(), overflow_clip,
layout_block_, DisplayItem::kCaret);
}
}
}
PaintCarets(paint_info, paint_offset); PaintCarets(paint_info, paint_offset);
} }
......
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