Commit 7d685ad5 authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

Utilize Position::FirstPositionInNode()

This patch utilizes |Position::FirstPositionInNode()| instead of
constructor with |PositionAnchorType::kBeforeChildren| to reduce source
code size and preparation of getting rid of |kBeforeChildren|.

Bug: 592887
Change-Id: I66640fe772d506965f901326b39604dd83e9d408
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2556733
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@{#830871}
parent ec9a1382
...@@ -92,8 +92,7 @@ TEST_F(FrameCaretTest, ShouldNotBlinkWhenSelectionLooseFocus) { ...@@ -92,8 +92,7 @@ TEST_F(FrameCaretTest, ShouldNotBlinkWhenSelectionLooseFocus) {
outer->focus(); outer->focus();
UpdateAllLifecyclePhasesForTest(); UpdateAllLifecyclePhasesForTest();
const SelectionInDOMTree& selection = Selection().GetSelectionInDOMTree(); const SelectionInDOMTree& selection = Selection().GetSelectionInDOMTree();
EXPECT_EQ(selection.Base(), EXPECT_EQ(selection.Base(), Position::FirstPositionInNode(*input));
Position(input, PositionAnchorType::kBeforeChildren));
EXPECT_FALSE(ShouldShowCaret(caret)); EXPECT_FALSE(ShouldShowCaret(caret));
} }
......
...@@ -337,14 +337,14 @@ TEST_P(TextIteratorTest, StartingAtNodeInShadowRoot) { ...@@ -337,14 +337,14 @@ TEST_P(TextIteratorTest, StartingAtNodeInShadowRoot) {
GetDocument(), "host", shadow_content); GetDocument(), "host", shadow_content);
Node* outer_div = GetDocument().getElementById("outer"); Node* outer_div = GetDocument().getElementById("outer");
Node* span_in_shadow = shadow_root->firstChild(); Node* span_in_shadow = shadow_root->firstChild();
Position start(span_in_shadow, PositionAnchorType::kBeforeChildren); Position start = Position::FirstPositionInNode(*span_in_shadow);
Position end(outer_div, PositionAnchorType::kAfterChildren); Position end(outer_div, PositionAnchorType::kAfterChildren);
EXPECT_EQ( EXPECT_EQ(
"[ shadow][text][ iterator.]", "[ shadow][text][ iterator.]",
IteratePartial<DOMTree>(start, end, EntersOpenShadowRootsBehavior())); IteratePartial<DOMTree>(start, end, EntersOpenShadowRootsBehavior()));
PositionInFlatTree start_in_flat_tree(span_in_shadow, PositionInFlatTree start_in_flat_tree =
PositionAnchorType::kBeforeChildren); PositionInFlatTree::FirstPositionInNode(*span_in_shadow);
PositionInFlatTree end_in_flat_tree(outer_div, PositionInFlatTree end_in_flat_tree(outer_div,
PositionAnchorType::kAfterChildren); PositionAnchorType::kAfterChildren);
EXPECT_EQ("[text][ shadow][ iterator.]", EXPECT_EQ("[text][ shadow][ iterator.]",
...@@ -362,14 +362,14 @@ TEST_P(TextIteratorTest, FinishingAtNodeInShadowRoot) { ...@@ -362,14 +362,14 @@ TEST_P(TextIteratorTest, FinishingAtNodeInShadowRoot) {
GetDocument(), "host", shadow_content); GetDocument(), "host", shadow_content);
Node* outer_div = GetDocument().getElementById("outer"); Node* outer_div = GetDocument().getElementById("outer");
Node* span_in_shadow = shadow_root->firstChild(); Node* span_in_shadow = shadow_root->firstChild();
Position start(outer_div, PositionAnchorType::kBeforeChildren); Position start = Position::FirstPositionInNode(*outer_div);
Position end(span_in_shadow, PositionAnchorType::kAfterChildren); Position end(span_in_shadow, PositionAnchorType::kAfterChildren);
EXPECT_EQ( EXPECT_EQ(
"[Hello, ][ shadow]", "[Hello, ][ shadow]",
IteratePartial<DOMTree>(start, end, EntersOpenShadowRootsBehavior())); IteratePartial<DOMTree>(start, end, EntersOpenShadowRootsBehavior()));
PositionInFlatTree start_in_flat_tree(outer_div, PositionInFlatTree start_in_flat_tree =
PositionAnchorType::kBeforeChildren); PositionInFlatTree::FirstPositionInNode(*outer_div);
PositionInFlatTree end_in_flat_tree(span_in_shadow, PositionInFlatTree end_in_flat_tree(span_in_shadow,
PositionAnchorType::kAfterChildren); PositionAnchorType::kAfterChildren);
EXPECT_EQ("[Hello, ][text][ shadow]", EXPECT_EQ("[Hello, ][text][ shadow]",
......
...@@ -660,7 +660,7 @@ Position ToPositionInDOMTree(const PositionInFlatTree& position) { ...@@ -660,7 +660,7 @@ Position ToPositionInDOMTree(const PositionInFlatTree& position) {
case PositionAnchorType::kAfterAnchor: case PositionAnchorType::kAfterAnchor:
return Position::AfterNode(*anchor_node); return Position::AfterNode(*anchor_node);
case PositionAnchorType::kBeforeChildren: case PositionAnchorType::kBeforeChildren:
return Position(anchor_node, PositionAnchorType::kBeforeChildren); return Position::FirstPositionInNode(*anchor_node);
case PositionAnchorType::kBeforeAnchor: case PositionAnchorType::kBeforeAnchor:
return Position::BeforeNode(*anchor_node); return Position::BeforeNode(*anchor_node);
case PositionAnchorType::kOffsetInAnchor: { case PositionAnchorType::kOffsetInAnchor: {
...@@ -671,7 +671,7 @@ Position ToPositionInDOMTree(const PositionInFlatTree& position) { ...@@ -671,7 +671,7 @@ Position ToPositionInDOMTree(const PositionInFlatTree& position) {
if (child) if (child)
return Position(child->parentNode(), child->NodeIndex()); return Position(child->parentNode(), child->NodeIndex());
if (!position.OffsetInContainerNode()) if (!position.OffsetInContainerNode())
return Position(anchor_node, PositionAnchorType::kBeforeChildren); return Position::FirstPositionInNode(*anchor_node);
// |child| is null when the position is at the end of the children. // |child| is null when the position is at the end of the children.
// <div>foo|</div> // <div>foo|</div>
......
...@@ -198,9 +198,8 @@ TEST_F(PositionTest, ToPositionInFlatTreeWithShadowRoot) { ...@@ -198,9 +198,8 @@ TEST_F(PositionTest, ToPositionInFlatTreeWithShadowRoot) {
EXPECT_EQ(PositionInFlatTree(host, PositionAnchorType::kAfterChildren), EXPECT_EQ(PositionInFlatTree(host, PositionAnchorType::kAfterChildren),
ToPositionInFlatTree( ToPositionInFlatTree(
Position(shadow_root, PositionAnchorType::kAfterChildren))); Position(shadow_root, PositionAnchorType::kAfterChildren)));
EXPECT_EQ(PositionInFlatTree(host, PositionAnchorType::kBeforeChildren), EXPECT_EQ(PositionInFlatTree::FirstPositionInNode(*host),
ToPositionInFlatTree( ToPositionInFlatTree(Position::FirstPositionInNode(*shadow_root)));
Position(shadow_root, PositionAnchorType::kBeforeChildren)));
} }
TEST_F(PositionTest, TEST_F(PositionTest,
......
...@@ -44,8 +44,8 @@ class StyledMarkupSerializerTest : public EditingTestBase { ...@@ -44,8 +44,8 @@ class StyledMarkupSerializerTest : public EditingTestBase {
template <typename Strategy> template <typename Strategy>
std::string StyledMarkupSerializerTest::Serialize( std::string StyledMarkupSerializerTest::Serialize(
const CreateMarkupOptions& options) { const CreateMarkupOptions& options) {
PositionTemplate<Strategy> start = PositionTemplate<Strategy>( PositionTemplate<Strategy> start =
GetDocument().body(), PositionAnchorType::kBeforeChildren); PositionTemplate<Strategy>::FirstPositionInNode(*GetDocument().body());
PositionTemplate<Strategy> end = PositionTemplate<Strategy>( PositionTemplate<Strategy> end = PositionTemplate<Strategy>(
GetDocument().body(), PositionAnchorType::kAfterChildren); GetDocument().body(), PositionAnchorType::kAfterChildren);
return CreateMarkup(start, end, options).Utf8(); return CreateMarkup(start, end, options).Utf8();
......
...@@ -178,8 +178,8 @@ PositionWithAffinity HitTestResult::GetPosition() const { ...@@ -178,8 +178,8 @@ PositionWithAffinity HitTestResult::GetPosition() const {
return PositionWithAffinity(); return PositionWithAffinity();
if (inner_possibly_pseudo_node_->IsPseudoElement() && if (inner_possibly_pseudo_node_->IsPseudoElement() &&
inner_possibly_pseudo_node_->GetPseudoId() == kPseudoIdBefore) { inner_possibly_pseudo_node_->GetPseudoId() == kPseudoIdBefore) {
return PositionWithAffinity(MostForwardCaretPosition( return PositionWithAffinity(
Position(inner_node_, PositionAnchorType::kBeforeChildren))); MostForwardCaretPosition(Position::FirstPositionInNode(*inner_node_)));
} }
if (box_fragment_ && if (box_fragment_ &&
RuntimeEnabledFeatures::LayoutNGFullPositionForPointEnabled()) RuntimeEnabledFeatures::LayoutNGFullPositionForPointEnabled())
......
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