Commit 8d78c42c authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

[LayoutNG] Implement LayoutNG version of {First,Last}CharacterAfterWhitespaceCollapsing()

This patch implements LayoutNG version of |LayoutText::
{First,Last}CharacterAfterWhitespaceCollapsing()| with making a unit test,
|CharacterAfterWhitespaceCollapsing| to run on both legacy and ng layout tree.

This patch also changes legacy layout tree path of
|LastCharacterAfterWhitespaceCollapsing()| to use |StringView::CodepointAt()|
instead of |String::CharacterStartingAt()| to return last code point in string
instead of trail part of surrogate pair.

Bug: 906915
Change-Id: I364195c5b9366cf7ca890ba2738a4be37779a6bd
Reviewed-on: https://chromium-review.googlesource.com/c/1341776
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609652}
parent e73ecbd3
......@@ -1564,16 +1564,26 @@ UChar32 LayoutText::FirstCharacterAfterWhitespaceCollapsing() const {
String text = text_box->GetText();
return text.length() ? text.CharacterStartingAt(0) : 0;
}
// TODO(kojii): Support LayoutNG once we have NGInlineItem pointers.
if (const NGPaintFragment* paint_fragment = FirstInlineFragment()) {
const StringView text =
ToNGPhysicalTextFragment(paint_fragment->PhysicalFragment()).Text();
return text.length() ? text.CodepointAt(0) : 0;
}
return 0;
}
UChar32 LayoutText::LastCharacterAfterWhitespaceCollapsing() const {
if (InlineTextBox* text_box = LastTextBox()) {
String text = text_box->GetText();
return text.length() ? text.CharacterStartingAt(text.length() - 1) : 0;
return text.length() ? StringView(text).CodepointAt(text.length() - 1) : 0;
}
if (const NGPaintFragment* paint_fragment = FirstInlineFragment()) {
const StringView text =
ToNGPhysicalTextFragment(
paint_fragment->LastForSameLayoutObject()->PhysicalFragment())
.Text();
return text.length() ? text.CodepointAt(text.length() - 1) : 0;
}
// TODO(kojii): Support LayoutNG once we have NGInlineItem pointers.
return 0;
}
......
......@@ -233,9 +233,7 @@ TEST_P(MapDOMOffsetToTextContentOffset, Basic) {
}
}
// TODO(kojii): Include LayoutNG tests by switching to
// ParameterizedLayoutTextTest when these functions support LayoutNG.
TEST_F(LayoutTextTest, CharacterAfterWhitespaceCollapsing) {
TEST_P(ParameterizedLayoutTextTest, CharacterAfterWhitespaceCollapsing) {
SetBodyInnerHTML("a<span id=target> b </span>");
LayoutText* layout_text = GetLayoutTextById("target");
EXPECT_EQ(' ', layout_text->FirstCharacterAfterWhitespaceCollapsing());
......@@ -272,6 +270,11 @@ TEST_F(LayoutTextTest, CharacterAfterWhitespaceCollapsing) {
DCHECK(!layout_text->HasTextBoxes());
EXPECT_EQ(0, layout_text->FirstCharacterAfterWhitespaceCollapsing());
EXPECT_EQ(0, layout_text->LastCharacterAfterWhitespaceCollapsing());
SetBodyInnerHTML("<b id=target>&#x1F34C;_&#x1F34D;</b>");
layout_text = GetLayoutTextById("target");
EXPECT_EQ(0x1F34C, layout_text->FirstCharacterAfterWhitespaceCollapsing());
EXPECT_EQ(0x1F34D, layout_text->LastCharacterAfterWhitespaceCollapsing());
}
TEST_P(ParameterizedLayoutTextTest, CaretMinMaxOffset) {
......
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