Commit 2f7fdcb0 authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Commit Bot

[LayoutNG] Apply segment break transformation rules before reusing inline items

When a text node starts with a space run that contains newlines, it's
possible that the text node's inline items can't be reused in relayout
due to segment break transformation rules.

This patch applies the rules to check if the newline is handled
differently in relayout, and if so, stops reusing the old inline items.

Bug: 969089
Change-Id: I163b2542154ea79971fb13922489441873c1712b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1641989Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#665689}
parent 01c26cb9
...@@ -315,12 +315,26 @@ bool NGInlineItemsBuilderTemplate<OffsetMappingBuilder>::AppendTextReusing( ...@@ -315,12 +315,26 @@ bool NGInlineItemsBuilderTemplate<OffsetMappingBuilder>::AppendTextReusing(
} }
break; break;
case NGInlineItem::kNotCollapsible: { case NGInlineItem::kNotCollapsible: {
// If the start of the original string was collapsed, it may be
// restored.
const String& source_text = layout_text->GetText(); const String& source_text = layout_text->GetText();
if (source_text.length() && IsCollapsibleSpace(source_text[0]) && if (source_text.length() && IsCollapsibleSpace(source_text[0])) {
original_string[old_item0.StartOffset()] != kSpaceCharacter) // If the start of the original string was collapsed, it may be
return false; // restored.
if (original_string[old_item0.StartOffset()] != kSpaceCharacter)
return false;
// If the start of the original string was not collapsed, and the
// collapsible space run contains newline, the newline may be
// removed.
unsigned offset = 0;
UChar c = source_text[0];
bool contains_newline =
MoveToEndOfCollapsibleSpaces(source_text, &offset, &c);
if (contains_newline &&
ShouldRemoveNewline(text_, text_.length(), last_item->Style(),
StringView(source_text, offset),
&new_style)) {
return false;
}
}
break; break;
} }
case NGInlineItem::kCollapsed: case NGInlineItem::kCollapsed:
......
...@@ -1432,6 +1432,20 @@ TEST_F(NGInlineNodeTest, PreservedNewlineWithRemovedBidiAndRelayout) { ...@@ -1432,6 +1432,20 @@ TEST_F(NGInlineNodeTest, PreservedNewlineWithRemovedBidiAndRelayout) {
EXPECT_EQ("foo\nbar", GetText()); EXPECT_EQ("foo\nbar", GetText());
} }
// https://crbug.com/969089
TEST_F(NGInlineNodeTest, InsertedWBRWithLineBreakInRelayout) {
SetupHtml("container", "<div id=container><span>foo</span>\nbar</div>");
EXPECT_EQ("foo bar", GetText());
Element* div = GetElementById("container");
Element* wbr = GetDocument().CreateElementForBinding("wbr");
div->insertBefore(wbr, div->lastChild());
UpdateAllLifecyclePhasesForTest();
// The '\n' should be collapsed by the inserted <wbr>
EXPECT_EQ(String(u"foo\u200Bbar"), GetText());
}
#if SEGMENT_BREAK_TRANSFORMATION_FOR_EAST_ASIAN_WIDTH #if SEGMENT_BREAK_TRANSFORMATION_FOR_EAST_ASIAN_WIDTH
// https://crbug.com/879088 // https://crbug.com/879088
TEST_F(NGInlineNodeTest, RemoveSegmentBreakFromJapaneseInRelayout) { TEST_F(NGInlineNodeTest, RemoveSegmentBreakFromJapaneseInRelayout) {
......
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