Commit fd34a051 authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

Get rid of false DCHECK from ReusingTextShaper::CollectReusableShapeResults()

This patch gets rid of false |DCHECK_LE(start_offset, item->StartOffset())| from
|ReusingTextShaper::CollectReusableShapeResults()| when inserted text starts
with newline character as control character, e.g. white-space:pre, <pre>, etc.

This DCHECK is wrong when adding newline chracter as control character, e.g.
appending "\nX" to "n".

In |ReusingTextShaper|, we have two items in |reusable_items_|.
 * reusable_items_[0] = kText 0-1 "n", shape_result=avaiable
 * reusable_items_[1] = kText 1-3 "\nX", shape_result=null

Shaping items are
 * items[0] = kText 0-1 "n", shape_result=reused
 * items[1] = kControl 1-2 "\n", shape_result=n/a
 * items[2] = kText 2-3 "X", shape_result=new
When |ReusingTextShaper| to shape for "X", |DCHECK| hits for handling
|reusable_items_[1]|, because |start_offset| is 2 and |item->StartOffset()| is
1.

Bug: 1003666
Change-Id: I800fae637ff7a39b0e65d07699c07b204051399e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1824516
Auto-Submit: Yoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#700111}
parent 8989f098
...@@ -47,6 +47,21 @@ class LayoutNGTextTest : public PageTestBase { ...@@ -47,6 +47,21 @@ class LayoutNGTextTest : public PageTestBase {
} }
}; };
TEST_F(LayoutNGTextTest, SetTextWithOffsetAppendControl) {
if (!RuntimeEnabledFeatures::LayoutNGEnabled())
return;
SetBodyInnerHTML(u"<pre id=target>a</pre>");
Text& text = To<Text>(*GetElementById("target")->firstChild());
// Note: "\n" is control character instead of text character.
text.appendData("\nX");
EXPECT_EQ(
"*{'a', ShapeResult=0+1}\n"
"*{'X', ShapeResult=2+1}\n",
GetItemsAsString(*text.GetLayoutObject()));
}
TEST_F(LayoutNGTextTest, SetTextWithOffsetAppendCollapseWhiteSpace) { TEST_F(LayoutNGTextTest, SetTextWithOffsetAppendCollapseWhiteSpace) {
if (!RuntimeEnabledFeatures::LayoutNGEnabled()) if (!RuntimeEnabledFeatures::LayoutNGEnabled())
return; return;
......
...@@ -208,7 +208,6 @@ class ReusingTextShaper final { ...@@ -208,7 +208,6 @@ class ReusingTextShaper final {
return item.EndOffset() <= offset; return item.EndOffset() <= offset;
}); });
item != reusable_items_->end(); ++item) { item != reusable_items_->end(); ++item) {
DCHECK_LE(start_offset, item->StartOffset());
if (end_offset <= item->StartOffset()) if (end_offset <= item->StartOffset())
break; break;
if (item->EndOffset() < start_offset) if (item->EndOffset() < start_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