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

Utilize NGInlineCursor in NGCaretPositionTest

This patch changes |NGCaretPositionTest| to utilize |NGInlineCursor| instead of
|NGPaintFragment| and |NGPhysicalTextFragment| for prepration of migrating
to |NFragmentItem|.

Bug: 982194
Change-Id: I0bba9a20e4ff9150d65632f5c30892c43cf54887
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1888622
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Koji Ishii <kojii@chromium.org>
Auto-Submit: Yoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#710678}
parent 3cf1176f
...@@ -6,12 +6,9 @@ ...@@ -6,12 +6,9 @@
#include "third_party/blink/renderer/core/editing/text_affinity.h" #include "third_party/blink/renderer/core/editing/text_affinity.h"
#include "third_party/blink/renderer/core/layout/layout_block_flow.h" #include "third_party/blink/renderer/core/layout/layout_block_flow.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_inline_fragment_traversal.h" #include "third_party/blink/renderer/core/layout/ng/inline/ng_inline_cursor.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_offset_mapping.h" #include "third_party/blink/renderer/core/layout/ng/inline/ng_offset_mapping.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_physical_text_fragment.h"
#include "third_party/blink/renderer/core/layout/ng/ng_layout_test.h" #include "third_party/blink/renderer/core/layout/ng/ng_layout_test.h"
#include "third_party/blink/renderer/core/layout/ng/ng_physical_box_fragment.h"
#include "third_party/blink/renderer/core/paint/ng/ng_paint_fragment.h"
namespace blink { namespace blink {
...@@ -41,8 +38,6 @@ class NGCaretPositionTest : public NGLayoutTest { ...@@ -41,8 +38,6 @@ class NGCaretPositionTest : public NGLayoutTest {
context_ = To<LayoutBlockFlow>(container_->GetLayoutObject()); context_ = To<LayoutBlockFlow>(container_->GetLayoutObject());
DCHECK(context_); DCHECK(context_);
DCHECK(context_->IsLayoutNGMixin()); DCHECK(context_->IsLayoutNGMixin());
root_fragment_ = context_->CurrentFragment();
DCHECK(root_fragment_);
} }
NGCaretPosition ComputeNGCaretPosition(unsigned offset, NGCaretPosition ComputeNGCaretPosition(unsigned offset,
...@@ -50,22 +45,19 @@ class NGCaretPositionTest : public NGLayoutTest { ...@@ -50,22 +45,19 @@ class NGCaretPositionTest : public NGLayoutTest {
return blink::ComputeNGCaretPosition(*context_, offset, affinity); return blink::ComputeNGCaretPosition(*context_, offset, affinity);
} }
const NGPhysicalFragment* FragmentOf(const Node* node) const { NGInlineCursor FragmentOf(const Node* node) const {
const NGPaintFragment* const paint_fragment = NGInlineCursor cursor;
node->GetLayoutObject()->FirstInlineFragment(); cursor.MoveTo(*node->GetLayoutObject());
DCHECK(!paint_fragment->NextForSameLayoutObject()); return cursor;
return &paint_fragment->PhysicalFragment();
} }
Persistent<Element> container_; Persistent<Element> container_;
const LayoutBlockFlow* context_; const LayoutBlockFlow* context_;
const NGPhysicalBoxFragment* root_fragment_;
}; };
#define TEST_CARET(caret, fragment_, type_, offset_) \ #define TEST_CARET(caret, fragment_, type_, offset_) \
{ \ { \
EXPECT_EQ(&caret.PaintFragment()->PhysicalFragment(), fragment_) \ EXPECT_EQ(caret.cursor, fragment_); \
<< caret.PaintFragment()->PhysicalFragment().ToString(); \
EXPECT_EQ(caret.position_type, NGCaretPositionType::type_); \ EXPECT_EQ(caret.position_type, NGCaretPositionType::type_); \
EXPECT_EQ(caret.text_offset, offset_) << caret.text_offset.value_or(-1); \ EXPECT_EQ(caret.text_offset, offset_) << caret.text_offset.value_or(-1); \
} }
...@@ -73,7 +65,7 @@ class NGCaretPositionTest : public NGLayoutTest { ...@@ -73,7 +65,7 @@ class NGCaretPositionTest : public NGLayoutTest {
TEST_F(NGCaretPositionTest, CaretPositionInOneLineOfText) { TEST_F(NGCaretPositionTest, CaretPositionInOneLineOfText) {
SetInlineFormattingContext("t", "foo", 3); SetInlineFormattingContext("t", "foo", 3);
const Node* text = container_->firstChild(); const Node* text = container_->firstChild();
const NGPhysicalFragment* text_fragment = FragmentOf(text); const NGInlineCursor& text_fragment = FragmentOf(text);
// Beginning of line // Beginning of line
TEST_CARET(ComputeNGCaretPosition(0, TextAffinity::kDownstream), TEST_CARET(ComputeNGCaretPosition(0, TextAffinity::kDownstream),
...@@ -98,14 +90,15 @@ TEST_F(NGCaretPositionTest, CaretPositionAtSoftLineWrap) { ...@@ -98,14 +90,15 @@ TEST_F(NGCaretPositionTest, CaretPositionAtSoftLineWrap) {
SetInlineFormattingContext("t", "foobar", 3); SetInlineFormattingContext("t", "foobar", 3);
const LayoutText& text = const LayoutText& text =
*To<Text>(container_->firstChild())->GetLayoutObject(); *To<Text>(container_->firstChild())->GetLayoutObject();
const NGPhysicalFragment& foo_fragment = NGInlineCursor cursor;
text.FirstInlineFragment()->PhysicalFragment(); cursor.MoveTo(text);
const NGPhysicalFragment& bar_fragment = const NGInlineCursor foo_fragment = cursor;
text.FirstInlineFragment()->NextForSameLayoutObject()->PhysicalFragment(); cursor.MoveToNextForSameLayoutObject();
const NGInlineCursor bar_fragment = cursor;
TEST_CARET(ComputeNGCaretPosition(3, TextAffinity::kDownstream), TEST_CARET(ComputeNGCaretPosition(3, TextAffinity::kDownstream), bar_fragment,
&bar_fragment, kAtTextOffset, base::Optional<unsigned>(3)); kAtTextOffset, base::Optional<unsigned>(3));
TEST_CARET(ComputeNGCaretPosition(3, TextAffinity::kUpstream), &foo_fragment, TEST_CARET(ComputeNGCaretPosition(3, TextAffinity::kUpstream), foo_fragment,
kAtTextOffset, base::Optional<unsigned>(3)); kAtTextOffset, base::Optional<unsigned>(3));
} }
...@@ -113,21 +106,22 @@ TEST_F(NGCaretPositionTest, CaretPositionAtSoftLineWrapWithSpace) { ...@@ -113,21 +106,22 @@ TEST_F(NGCaretPositionTest, CaretPositionAtSoftLineWrapWithSpace) {
SetInlineFormattingContext("t", "foo bar", 3); SetInlineFormattingContext("t", "foo bar", 3);
const LayoutText& text = const LayoutText& text =
*To<Text>(container_->firstChild())->GetLayoutObject(); *To<Text>(container_->firstChild())->GetLayoutObject();
const NGPhysicalFragment& foo_fragment = NGInlineCursor cursor;
text.FirstInlineFragment()->PhysicalFragment(); cursor.MoveTo(text);
const NGPhysicalFragment& bar_fragment = const NGInlineCursor foo_fragment = cursor;
text.FirstInlineFragment()->NextForSameLayoutObject()->PhysicalFragment(); cursor.MoveToNextForSameLayoutObject();
const NGInlineCursor bar_fragment = cursor;
// Before the space // Before the space
TEST_CARET(ComputeNGCaretPosition(3, TextAffinity::kDownstream), TEST_CARET(ComputeNGCaretPosition(3, TextAffinity::kDownstream), foo_fragment,
&foo_fragment, kAtTextOffset, base::Optional<unsigned>(3)); kAtTextOffset, base::Optional<unsigned>(3));
TEST_CARET(ComputeNGCaretPosition(3, TextAffinity::kUpstream), &foo_fragment, TEST_CARET(ComputeNGCaretPosition(3, TextAffinity::kUpstream), foo_fragment,
kAtTextOffset, base::Optional<unsigned>(3)); kAtTextOffset, base::Optional<unsigned>(3));
// After the space // After the space
TEST_CARET(ComputeNGCaretPosition(4, TextAffinity::kDownstream), TEST_CARET(ComputeNGCaretPosition(4, TextAffinity::kDownstream), bar_fragment,
&bar_fragment, kAtTextOffset, base::Optional<unsigned>(4)); kAtTextOffset, base::Optional<unsigned>(4));
TEST_CARET(ComputeNGCaretPosition(4, TextAffinity::kUpstream), &bar_fragment, TEST_CARET(ComputeNGCaretPosition(4, TextAffinity::kUpstream), bar_fragment,
kAtTextOffset, base::Optional<unsigned>(4)); kAtTextOffset, base::Optional<unsigned>(4));
} }
...@@ -136,8 +130,8 @@ TEST_F(NGCaretPositionTest, CaretPositionAtForcedLineBreak) { ...@@ -136,8 +130,8 @@ TEST_F(NGCaretPositionTest, CaretPositionAtForcedLineBreak) {
const Node* foo = container_->firstChild(); const Node* foo = container_->firstChild();
const Node* br = foo->nextSibling(); const Node* br = foo->nextSibling();
const Node* bar = br->nextSibling(); const Node* bar = br->nextSibling();
const NGPhysicalFragment* foo_fragment = FragmentOf(foo); const NGInlineCursor& foo_fragment = FragmentOf(foo);
const NGPhysicalFragment* bar_fragment = FragmentOf(bar); const NGInlineCursor& bar_fragment = FragmentOf(bar);
// Before the BR // Before the BR
TEST_CARET(ComputeNGCaretPosition(3, TextAffinity::kDownstream), foo_fragment, TEST_CARET(ComputeNGCaretPosition(3, TextAffinity::kDownstream), foo_fragment,
...@@ -157,7 +151,7 @@ TEST_F(NGCaretPositionTest, CaretPositionAtEmptyLine) { ...@@ -157,7 +151,7 @@ TEST_F(NGCaretPositionTest, CaretPositionAtEmptyLine) {
const Node* foo = container_->firstChild(); const Node* foo = container_->firstChild();
const Node* br1 = foo->nextSibling(); const Node* br1 = foo->nextSibling();
const Node* br2 = br1->nextSibling(); const Node* br2 = br1->nextSibling();
const NGPhysicalFragment* br2_fragment = FragmentOf(br2); const NGInlineCursor& br2_fragment = FragmentOf(br2);
TEST_CARET(ComputeNGCaretPosition(4, TextAffinity::kDownstream), br2_fragment, TEST_CARET(ComputeNGCaretPosition(4, TextAffinity::kDownstream), br2_fragment,
kAtTextOffset, base::Optional<unsigned>(4)); kAtTextOffset, base::Optional<unsigned>(4));
...@@ -168,7 +162,7 @@ TEST_F(NGCaretPositionTest, CaretPositionAtEmptyLine) { ...@@ -168,7 +162,7 @@ TEST_F(NGCaretPositionTest, CaretPositionAtEmptyLine) {
TEST_F(NGCaretPositionTest, CaretPositionInOneLineOfImage) { TEST_F(NGCaretPositionTest, CaretPositionInOneLineOfImage) {
SetInlineFormattingContext("t", "<img>", 3); SetInlineFormattingContext("t", "<img>", 3);
const Node* img = container_->firstChild(); const Node* img = container_->firstChild();
const NGPhysicalFragment* img_fragment = FragmentOf(img); const NGInlineCursor& img_fragment = FragmentOf(img);
// Before the image // Before the image
TEST_CARET(ComputeNGCaretPosition(0, TextAffinity::kDownstream), img_fragment, TEST_CARET(ComputeNGCaretPosition(0, TextAffinity::kDownstream), img_fragment,
...@@ -190,8 +184,8 @@ TEST_F(NGCaretPositionTest, CaretPositionAtSoftLineWrapBetweenImages) { ...@@ -190,8 +184,8 @@ TEST_F(NGCaretPositionTest, CaretPositionAtSoftLineWrapBetweenImages) {
1); 1);
const Node* img1 = container_->firstChild(); const Node* img1 = container_->firstChild();
const Node* img2 = img1->nextSibling(); const Node* img2 = img1->nextSibling();
const NGPhysicalFragment* img1_fragment = FragmentOf(img1); const NGInlineCursor& img1_fragment = FragmentOf(img1);
const NGPhysicalFragment* img2_fragment = FragmentOf(img2); const NGInlineCursor& img2_fragment = FragmentOf(img2);
TEST_CARET(ComputeNGCaretPosition(1, TextAffinity::kDownstream), TEST_CARET(ComputeNGCaretPosition(1, TextAffinity::kDownstream),
img2_fragment, kBeforeBox, base::nullopt); img2_fragment, kBeforeBox, base::nullopt);
...@@ -211,8 +205,8 @@ TEST_F(NGCaretPositionTest, ...@@ -211,8 +205,8 @@ TEST_F(NGCaretPositionTest,
3); 3);
const Node* text_c = GetElementById("span-c")->firstChild(); const Node* text_c = GetElementById("span-c")->firstChild();
const Node* text_d = GetElementById("span-d")->firstChild(); const Node* text_d = GetElementById("span-d")->firstChild();
const NGPhysicalFragment* fragment_c = FragmentOf(text_c); const NGInlineCursor& fragment_c = FragmentOf(text_c);
const NGPhysicalFragment* fragment_d = FragmentOf(text_d); const NGInlineCursor& fragment_d = FragmentOf(text_d);
const Position wrap_position(text_c, 1); const Position wrap_position(text_c, 1);
const NGOffsetMapping& mapping = *NGOffsetMapping::GetFor(wrap_position); const NGOffsetMapping& mapping = *NGOffsetMapping::GetFor(wrap_position);
...@@ -236,8 +230,8 @@ TEST_F(NGCaretPositionTest, ...@@ -236,8 +230,8 @@ TEST_F(NGCaretPositionTest,
3, TextDirection::kRtl); 3, TextDirection::kRtl);
const Node* text_c = GetElementById("span-c")->firstChild(); const Node* text_c = GetElementById("span-c")->firstChild();
const Node* text_d = GetElementById("span-d")->firstChild(); const Node* text_d = GetElementById("span-d")->firstChild();
const NGPhysicalFragment* fragment_c = FragmentOf(text_c); const NGInlineCursor& fragment_c = FragmentOf(text_c);
const NGPhysicalFragment* fragment_d = FragmentOf(text_d); const NGInlineCursor& fragment_d = FragmentOf(text_d);
const Position wrap_position(text_c, 1); const Position wrap_position(text_c, 1);
const NGOffsetMapping& mapping = *NGOffsetMapping::GetFor(wrap_position); const NGOffsetMapping& mapping = *NGOffsetMapping::GetFor(wrap_position);
...@@ -262,8 +256,8 @@ TEST_F(NGCaretPositionTest, CaretPositionAtSoftLineWrapBetweenDeepTextNodes) { ...@@ -262,8 +256,8 @@ TEST_F(NGCaretPositionTest, CaretPositionAtSoftLineWrapBetweenDeepTextNodes) {
4); // Wider space to allow border and 3 characters 4); // Wider space to allow border and 3 characters
const Node* text_c = GetElementById("span-c")->firstChild(); const Node* text_c = GetElementById("span-c")->firstChild();
const Node* text_d = GetElementById("span-d")->firstChild(); const Node* text_d = GetElementById("span-d")->firstChild();
const NGPhysicalFragment* fragment_c = FragmentOf(text_c); const NGInlineCursor& fragment_c = FragmentOf(text_c);
const NGPhysicalFragment* fragment_d = FragmentOf(text_d); const NGInlineCursor& fragment_d = FragmentOf(text_d);
const Position wrap_position(text_c, 1); const Position wrap_position(text_c, 1);
const NGOffsetMapping& mapping = *NGOffsetMapping::GetFor(wrap_position); const NGOffsetMapping& mapping = *NGOffsetMapping::GetFor(wrap_position);
...@@ -282,7 +276,7 @@ TEST_F(NGCaretPositionTest, InlineBlockBeforeContent) { ...@@ -282,7 +276,7 @@ TEST_F(NGCaretPositionTest, InlineBlockBeforeContent) {
"<span id=span>bar</span>", "<span id=span>bar</span>",
100); // Line width doesn't matter here. 100); // Line width doesn't matter here.
const Node* text = GetElementById("span")->firstChild(); const Node* text = GetElementById("span")->firstChild();
const NGPhysicalFragment* text_fragment = FragmentOf(text); const NGInlineCursor& text_fragment = FragmentOf(text);
// Test caret position of "|bar", which shouldn't be affected by ::before // Test caret position of "|bar", which shouldn't be affected by ::before
const Position position(text, 0); const Position position(text, 0);
......
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