Commit c484549d authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Commit Bot

[LayoutNG] Implement EmitsSpaceForNbsp behavior for TextIterator

Our NG TextIterator didn't implement the EmitsSpaceForNbsp behavior.
This patch implements it.

Change-Id: I76e7531ee013494566c15417658042b012462690
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1506972
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#638594}
parent f6f19f09
...@@ -75,6 +75,10 @@ TextIteratorBehavior EmitsCharactersBetweenAllVisiblePositionsBehavior() { ...@@ -75,6 +75,10 @@ TextIteratorBehavior EmitsCharactersBetweenAllVisiblePositionsBehavior() {
.Build(); .Build();
} }
TextIteratorBehavior EmitsSpaceForNbspBehavior() {
return TextIteratorBehavior::Builder().SetEmitsSpaceForNbsp(true).Build();
}
struct DOMTree : NodeTraversal { struct DOMTree : NodeTraversal {
using PositionType = Position; using PositionType = Position;
using TextIteratorType = TextIterator; using TextIteratorType = TextIterator;
...@@ -1151,5 +1155,10 @@ TEST_P(TextIteratorTest, TextOffsetMappingAndFlatTree) { ...@@ -1151,5 +1155,10 @@ TEST_P(TextIteratorTest, TextOffsetMappingAndFlatTree) {
Iterate<FlatTree>(EmitsCharactersBetweenAllVisiblePositionsBehavior())); Iterate<FlatTree>(EmitsCharactersBetweenAllVisiblePositionsBehavior()));
} }
TEST_P(TextIteratorTest, EmitsSpaceForNbsp) {
SetBodyContent("foo &nbsp;bar");
EXPECT_EQ("[foo bar]", Iterate<DOMTree>(EmitsSpaceForNbspBehavior()));
}
} // namespace text_iterator_test } // namespace text_iterator_test
} // namespace blink } // namespace blink
...@@ -60,8 +60,8 @@ StringAndOffsetRange ComputeTextAndOffsetsForEmission( ...@@ -60,8 +60,8 @@ StringAndOffsetRange ComputeTextAndOffsetsForEmission(
String string = mapping.GetText().Substring( String string = mapping.GetText().Substring(
unit.TextContentStart(), unit.TextContentStart(),
unit.TextContentEnd() - unit.TextContentStart()); unit.TextContentEnd() - unit.TextContentStart());
// TODO(xiaochengh): This seems wrong... Add real handling. string.Replace(kNoBreakSpaceCharacter, kSpaceCharacter);
return {string, 0, 0}; return {string, 0, string.length()};
} }
return {mapping.GetText(), unit.TextContentStart(), unit.TextContentEnd()}; return {mapping.GetText(), unit.TextContentStart(), unit.TextContentEnd()};
} }
......
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