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 @@
#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/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_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_physical_box_fragment.h"
#include "third_party/blink/renderer/core/paint/ng/ng_paint_fragment.h"
namespace blink {
......@@ -41,8 +38,6 @@ class NGCaretPositionTest : public NGLayoutTest {
context_ = To<LayoutBlockFlow>(container_->GetLayoutObject());
DCHECK(context_);
DCHECK(context_->IsLayoutNGMixin());
root_fragment_ = context_->CurrentFragment();
DCHECK(root_fragment_);
}
NGCaretPosition ComputeNGCaretPosition(unsigned offset,
......@@ -50,22 +45,19 @@ class NGCaretPositionTest : public NGLayoutTest {
return blink::ComputeNGCaretPosition(*context_, offset, affinity);
}
const NGPhysicalFragment* FragmentOf(const Node* node) const {
const NGPaintFragment* const paint_fragment =
node->GetLayoutObject()->FirstInlineFragment();
DCHECK(!paint_fragment->NextForSameLayoutObject());
return &paint_fragment->PhysicalFragment();
NGInlineCursor FragmentOf(const Node* node) const {
NGInlineCursor cursor;
cursor.MoveTo(*node->GetLayoutObject());
return cursor;
}
Persistent<Element> container_;
const LayoutBlockFlow* context_;
const NGPhysicalBoxFragment* root_fragment_;
};
#define TEST_CARET(caret, fragment_, type_, offset_) \
{ \
EXPECT_EQ(&caret.PaintFragment()->PhysicalFragment(), fragment_) \
<< caret.PaintFragment()->PhysicalFragment().ToString(); \
EXPECT_EQ(caret.cursor, fragment_); \
EXPECT_EQ(caret.position_type, NGCaretPositionType::type_); \
EXPECT_EQ(caret.text_offset, offset_) << caret.text_offset.value_or(-1); \
}
......@@ -73,7 +65,7 @@ class NGCaretPositionTest : public NGLayoutTest {
TEST_F(NGCaretPositionTest, CaretPositionInOneLineOfText) {
SetInlineFormattingContext("t", "foo", 3);
const Node* text = container_->firstChild();
const NGPhysicalFragment* text_fragment = FragmentOf(text);
const NGInlineCursor& text_fragment = FragmentOf(text);
// Beginning of line
TEST_CARET(ComputeNGCaretPosition(0, TextAffinity::kDownstream),
......@@ -98,14 +90,15 @@ TEST_F(NGCaretPositionTest, CaretPositionAtSoftLineWrap) {
SetInlineFormattingContext("t", "foobar", 3);
const LayoutText& text =
*To<Text>(container_->firstChild())->GetLayoutObject();
const NGPhysicalFragment& foo_fragment =
text.FirstInlineFragment()->PhysicalFragment();
const NGPhysicalFragment& bar_fragment =
text.FirstInlineFragment()->NextForSameLayoutObject()->PhysicalFragment();
NGInlineCursor cursor;
cursor.MoveTo(text);
const NGInlineCursor foo_fragment = cursor;
cursor.MoveToNextForSameLayoutObject();
const NGInlineCursor bar_fragment = cursor;
TEST_CARET(ComputeNGCaretPosition(3, TextAffinity::kDownstream),
&bar_fragment, kAtTextOffset, base::Optional<unsigned>(3));
TEST_CARET(ComputeNGCaretPosition(3, TextAffinity::kUpstream), &foo_fragment,
TEST_CARET(ComputeNGCaretPosition(3, TextAffinity::kDownstream), bar_fragment,
kAtTextOffset, base::Optional<unsigned>(3));
TEST_CARET(ComputeNGCaretPosition(3, TextAffinity::kUpstream), foo_fragment,
kAtTextOffset, base::Optional<unsigned>(3));
}
......@@ -113,21 +106,22 @@ TEST_F(NGCaretPositionTest, CaretPositionAtSoftLineWrapWithSpace) {
SetInlineFormattingContext("t", "foo bar", 3);
const LayoutText& text =
*To<Text>(container_->firstChild())->GetLayoutObject();
const NGPhysicalFragment& foo_fragment =
text.FirstInlineFragment()->PhysicalFragment();
const NGPhysicalFragment& bar_fragment =
text.FirstInlineFragment()->NextForSameLayoutObject()->PhysicalFragment();
NGInlineCursor cursor;
cursor.MoveTo(text);
const NGInlineCursor foo_fragment = cursor;
cursor.MoveToNextForSameLayoutObject();
const NGInlineCursor bar_fragment = cursor;
// Before the space
TEST_CARET(ComputeNGCaretPosition(3, TextAffinity::kDownstream),
&foo_fragment, kAtTextOffset, base::Optional<unsigned>(3));
TEST_CARET(ComputeNGCaretPosition(3, TextAffinity::kUpstream), &foo_fragment,
TEST_CARET(ComputeNGCaretPosition(3, TextAffinity::kDownstream), foo_fragment,
kAtTextOffset, base::Optional<unsigned>(3));
TEST_CARET(ComputeNGCaretPosition(3, TextAffinity::kUpstream), foo_fragment,
kAtTextOffset, base::Optional<unsigned>(3));
// After the space
TEST_CARET(ComputeNGCaretPosition(4, TextAffinity::kDownstream),
&bar_fragment, kAtTextOffset, base::Optional<unsigned>(4));
TEST_CARET(ComputeNGCaretPosition(4, TextAffinity::kUpstream), &bar_fragment,
TEST_CARET(ComputeNGCaretPosition(4, TextAffinity::kDownstream), bar_fragment,
kAtTextOffset, base::Optional<unsigned>(4));
TEST_CARET(ComputeNGCaretPosition(4, TextAffinity::kUpstream), bar_fragment,
kAtTextOffset, base::Optional<unsigned>(4));
}
......@@ -136,8 +130,8 @@ TEST_F(NGCaretPositionTest, CaretPositionAtForcedLineBreak) {
const Node* foo = container_->firstChild();
const Node* br = foo->nextSibling();
const Node* bar = br->nextSibling();
const NGPhysicalFragment* foo_fragment = FragmentOf(foo);
const NGPhysicalFragment* bar_fragment = FragmentOf(bar);
const NGInlineCursor& foo_fragment = FragmentOf(foo);
const NGInlineCursor& bar_fragment = FragmentOf(bar);
// Before the BR
TEST_CARET(ComputeNGCaretPosition(3, TextAffinity::kDownstream), foo_fragment,
......@@ -157,7 +151,7 @@ TEST_F(NGCaretPositionTest, CaretPositionAtEmptyLine) {
const Node* foo = container_->firstChild();
const Node* br1 = foo->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,
kAtTextOffset, base::Optional<unsigned>(4));
......@@ -168,7 +162,7 @@ TEST_F(NGCaretPositionTest, CaretPositionAtEmptyLine) {
TEST_F(NGCaretPositionTest, CaretPositionInOneLineOfImage) {
SetInlineFormattingContext("t", "<img>", 3);
const Node* img = container_->firstChild();
const NGPhysicalFragment* img_fragment = FragmentOf(img);
const NGInlineCursor& img_fragment = FragmentOf(img);
// Before the image
TEST_CARET(ComputeNGCaretPosition(0, TextAffinity::kDownstream), img_fragment,
......@@ -190,8 +184,8 @@ TEST_F(NGCaretPositionTest, CaretPositionAtSoftLineWrapBetweenImages) {
1);
const Node* img1 = container_->firstChild();
const Node* img2 = img1->nextSibling();
const NGPhysicalFragment* img1_fragment = FragmentOf(img1);
const NGPhysicalFragment* img2_fragment = FragmentOf(img2);
const NGInlineCursor& img1_fragment = FragmentOf(img1);
const NGInlineCursor& img2_fragment = FragmentOf(img2);
TEST_CARET(ComputeNGCaretPosition(1, TextAffinity::kDownstream),
img2_fragment, kBeforeBox, base::nullopt);
......@@ -211,8 +205,8 @@ TEST_F(NGCaretPositionTest,
3);
const Node* text_c = GetElementById("span-c")->firstChild();
const Node* text_d = GetElementById("span-d")->firstChild();
const NGPhysicalFragment* fragment_c = FragmentOf(text_c);
const NGPhysicalFragment* fragment_d = FragmentOf(text_d);
const NGInlineCursor& fragment_c = FragmentOf(text_c);
const NGInlineCursor& fragment_d = FragmentOf(text_d);
const Position wrap_position(text_c, 1);
const NGOffsetMapping& mapping = *NGOffsetMapping::GetFor(wrap_position);
......@@ -236,8 +230,8 @@ TEST_F(NGCaretPositionTest,
3, TextDirection::kRtl);
const Node* text_c = GetElementById("span-c")->firstChild();
const Node* text_d = GetElementById("span-d")->firstChild();
const NGPhysicalFragment* fragment_c = FragmentOf(text_c);
const NGPhysicalFragment* fragment_d = FragmentOf(text_d);
const NGInlineCursor& fragment_c = FragmentOf(text_c);
const NGInlineCursor& fragment_d = FragmentOf(text_d);
const Position wrap_position(text_c, 1);
const NGOffsetMapping& mapping = *NGOffsetMapping::GetFor(wrap_position);
......@@ -262,8 +256,8 @@ TEST_F(NGCaretPositionTest, CaretPositionAtSoftLineWrapBetweenDeepTextNodes) {
4); // Wider space to allow border and 3 characters
const Node* text_c = GetElementById("span-c")->firstChild();
const Node* text_d = GetElementById("span-d")->firstChild();
const NGPhysicalFragment* fragment_c = FragmentOf(text_c);
const NGPhysicalFragment* fragment_d = FragmentOf(text_d);
const NGInlineCursor& fragment_c = FragmentOf(text_c);
const NGInlineCursor& fragment_d = FragmentOf(text_d);
const Position wrap_position(text_c, 1);
const NGOffsetMapping& mapping = *NGOffsetMapping::GetFor(wrap_position);
......@@ -282,7 +276,7 @@ TEST_F(NGCaretPositionTest, InlineBlockBeforeContent) {
"<span id=span>bar</span>",
100); // Line width doesn't matter here.
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
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