Commit 9549db41 authored by Yoichi Osato's avatar Yoichi Osato Committed by Commit Bot

[LayoutNG] Not paint a line break at the end of inline-block

This patch stops painting a line break the end of inline-block
because if an inline-block is at the middle of line, we should not paint
a line break.
Old layout paints line break if the inline-block is at the end of line, but
since its complex to determine if the inline-block is at the end of line on NG,
this patch just cancels block-end line break painting for any inline-block.

This patch fixes:
 paint/selection/text-selection-inline-block-rtl.html
 paint/selection/text-selection-inline-block.html
(rebase is for 1px line height).

Bug: 708452
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: I270b48fd432e31b327796b098edc7c9553b356ad
Reviewed-on: https://chromium-review.googlesource.com/1096922
Commit-Queue: Koji Ishii <kojii@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567670}
parent f2173900
...@@ -104,22 +104,22 @@ ...@@ -104,22 +104,22 @@
"paintInvalidations": [ "paintInvalidations": [
{ {
"object": "NGPaintFragment", "object": "NGPaintFragment",
"rect": [0, 100, 42, 20], "rect": [0, 160, 40, 20],
"reason": "selection" "reason": "selection"
}, },
{ {
"object": "NGPaintFragment", "object": "NGPaintFragment",
"rect": [0, 160, 40, 20], "rect": [0, 80, 40, 20],
"reason": "selection" "reason": "selection"
}, },
{ {
"object": "NGPaintFragment", "object": "NGPaintFragment",
"rect": [0, 80, 40, 20], "rect": [0, 180, 39, 20],
"reason": "selection" "reason": "selection"
}, },
{ {
"object": "NGPaintFragment", "object": "NGPaintFragment",
"rect": [0, 180, 39, 20], "rect": [0, 100, 39, 20],
"reason": "selection" "reason": "selection"
} }
] ]
......
<!DOCTYPE html>
<style>
span {
background-color: #3333ff;
color: #ffffcc;
}
.padding {
padding-bottom:1px;
}
</style>
<div id="start"><span style="white-space:pre" class="padding">xx </span></div>
<div style="font-family: monospace"><span>inline block inside selection root</span></div>
<div id="end"><span class="padding">xx</span></div>
...@@ -703,6 +703,20 @@ static unsigned ClampOffset(unsigned offset, ...@@ -703,6 +703,20 @@ static unsigned ClampOffset(unsigned offset,
text_fragment.EndOffset()); text_fragment.EndOffset());
} }
// We don't paint a line break the end of inline-block
// because if an inline-block is at the middle of line, we should not paint
// a line break.
// Old layout paints line break if the inline-block is at the end of line, but
// since its complex to determine if the inline-block is at the end of line on NG,
// we just cancels block-end line break painting for any inline-block.
static bool IsLastLineInInlineBlock(const NGPaintFragment& line) {
DCHECK(line.PhysicalFragment().IsLineBox());
NGPaintFragment* parent = line.Parent();
if (!parent->PhysicalFragment().IsAtomicInline())
return false;
return parent->Children().back().get() == &line;
}
static bool IsBeforeSoftLineBreak(const NGPaintFragment& fragment) { static bool IsBeforeSoftLineBreak(const NGPaintFragment& fragment) {
if (ToNGPhysicalTextFragmentOrDie(fragment.PhysicalFragment()).IsLineBreak()) if (ToNGPhysicalTextFragmentOrDie(fragment.PhysicalFragment()).IsLineBreak())
return false; return false;
...@@ -711,6 +725,8 @@ static bool IsBeforeSoftLineBreak(const NGPaintFragment& fragment) { ...@@ -711,6 +725,8 @@ static bool IsBeforeSoftLineBreak(const NGPaintFragment& fragment) {
// See paint/selection/text-selection-inline-block.html. // See paint/selection/text-selection-inline-block.html.
const NGPaintFragment* container_line_box = fragment.ContainerLineBox(); const NGPaintFragment* container_line_box = fragment.ContainerLineBox();
DCHECK(container_line_box); DCHECK(container_line_box);
if (IsLastLineInInlineBlock(*container_line_box))
return false;
const NGPhysicalLineBoxFragment& physical_line_box = const NGPhysicalLineBoxFragment& physical_line_box =
ToNGPhysicalLineBoxFragment(container_line_box->PhysicalFragment()); ToNGPhysicalLineBoxFragment(container_line_box->PhysicalFragment());
const NGPhysicalFragment* last_leaf = physical_line_box.LastLogicalLeaf(); const NGPhysicalFragment* last_leaf = physical_line_box.LastLogicalLeaf();
......
...@@ -899,6 +899,12 @@ TEST_F(NGLayoutSelectionTest, LineBreakBasic) { ...@@ -899,6 +899,12 @@ TEST_F(NGLayoutSelectionTest, LineBreakBasic) {
// "<div style='display:inline-block'>f^oo</div>bar|")); // "<div style='display:inline-block'>f^oo</div>bar|"));
} }
TEST_F(NGLayoutSelectionTest, LineBreakInlineBlock) {
LoadAhem();
EXPECT_FALSE(
IsFirstTextLineBreak("<div style='display:inline-block'>^x</div>y|"));
}
TEST_F(NGLayoutSelectionTest, LineBreakImage) { TEST_F(NGLayoutSelectionTest, LineBreakImage) {
SetSelectionAndUpdateLayoutSelection( SetSelectionAndUpdateLayoutSelection(
"<div>^<img id=img1 width=10px height=10px>foo<br>" "<div>^<img id=img1 width=10px height=10px>foo<br>"
......
...@@ -269,8 +269,8 @@ TEST_F(NGPaintFragmentTest, InlineBlock) { ...@@ -269,8 +269,8 @@ TEST_F(NGPaintFragmentTest, InlineBlock) {
EXPECT_EQ(LayoutRect(0, 0, 60, 10), outer_text.SelectionVisualRect()); EXPECT_EQ(LayoutRect(0, 0, 60, 10), outer_text.SelectionVisualRect());
EXPECT_EQ(LayoutRect(60, 0, 10, 10), box1.VisualRect()); EXPECT_EQ(LayoutRect(60, 0, 10, 10), box1.VisualRect());
EXPECT_EQ(LayoutRect(), box1.SelectionVisualRect()); EXPECT_EQ(LayoutRect(), box1.SelectionVisualRect());
EXPECT_EQ(LayoutRect(60, 0, 20, 10), inner_text.VisualRect()); EXPECT_EQ(LayoutRect(60, 0, 10, 10), inner_text.VisualRect());
EXPECT_EQ(LayoutRect(60, 0, 20, 10), inner_text.SelectionVisualRect()); EXPECT_EQ(LayoutRect(60, 0, 10, 10), inner_text.SelectionVisualRect());
EXPECT_EQ(LayoutRect(70, 10, 10, 10), box2.VisualRect()); EXPECT_EQ(LayoutRect(70, 10, 10, 10), box2.VisualRect());
EXPECT_EQ(LayoutRect(), box2.SelectionVisualRect()); EXPECT_EQ(LayoutRect(), box2.SelectionVisualRect());
} }
......
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