| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/editing/EditingUtilities.h" | 5 #include "core/editing/EditingUtilities.h" |
| 6 | 6 |
| 7 #include "core/dom/StaticNodeList.h" | 7 #include "core/dom/StaticNodeList.h" |
| 8 #include "core/editing/EditingTestBase.h" | 8 #include "core/editing/EditingTestBase.h" |
| 9 | 9 |
| 10 namespace blink { | 10 namespace blink { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 EXPECT_EQ(LTR, directionOfEnclosingBlock(Position(one, 0))); | 24 EXPECT_EQ(LTR, directionOfEnclosingBlock(Position(one, 0))); |
| 25 EXPECT_EQ(RTL, directionOfEnclosingBlock(PositionInFlatTree(one, 0))); | 25 EXPECT_EQ(RTL, directionOfEnclosingBlock(PositionInFlatTree(one, 0))); |
| 26 } | 26 } |
| 27 | 27 |
| 28 TEST_F(EditingUtilitiesTest, firstEditablePositionAfterPositionInRoot) | 28 TEST_F(EditingUtilitiesTest, firstEditablePositionAfterPositionInRoot) |
| 29 { | 29 { |
| 30 const char* bodyContent = "<p id='host' contenteditable><b id='one'>1</b><b
id='two'>22</b></p>"; | 30 const char* bodyContent = "<p id='host' contenteditable><b id='one'>1</b><b
id='two'>22</b></p>"; |
| 31 const char* shadowContent = "<content select=#two></content><content select=
#one></content><b id='three'>333</b>"; | 31 const char* shadowContent = "<content select=#two></content><content select=
#one></content><b id='three'>333</b>"; |
| 32 setBodyContent(bodyContent); | 32 setBodyContent(bodyContent); |
| 33 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent,
"host"); | 33 RawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent, "host"); |
| 34 updateLayoutAndStyleForPainting(); | 34 updateLayoutAndStyleForPainting(); |
| 35 Element* host = document().getElementById("host"); | 35 Element* host = document().getElementById("host"); |
| 36 Node* one = document().getElementById("one"); | 36 Node* one = document().getElementById("one"); |
| 37 Node* two = document().getElementById("two"); | 37 Node* two = document().getElementById("two"); |
| 38 Node* three = shadowRoot->getElementById("three"); | 38 Node* three = shadowRoot->getElementById("three"); |
| 39 | 39 |
| 40 EXPECT_EQ(Position(one, 0), firstEditablePositionAfterPositionInRoot(Positio
n(one, 0), *host)); | 40 EXPECT_EQ(Position(one, 0), firstEditablePositionAfterPositionInRoot(Positio
n(one, 0), *host)); |
| 41 EXPECT_EQ(Position(one->firstChild(), 0), firstEditableVisiblePositionAfterP
ositionInRoot(Position(one, 0), *host).deepEquivalent()); | 41 EXPECT_EQ(Position(one->firstChild(), 0), firstEditableVisiblePositionAfterP
ositionInRoot(Position(one, 0), *host).deepEquivalent()); |
| 42 | 42 |
| 43 EXPECT_EQ(PositionInFlatTree(one, 0), firstEditablePositionAfterPositionInRo
ot(PositionInFlatTree(one, 0), *host)); | 43 EXPECT_EQ(PositionInFlatTree(one, 0), firstEditablePositionAfterPositionInRo
ot(PositionInFlatTree(one, 0), *host)); |
| 44 EXPECT_EQ(PositionInFlatTree(two->firstChild(), 2), firstEditableVisiblePosi
tionAfterPositionInRoot(PositionInFlatTree(one, 0), *host).deepEquivalent()); | 44 EXPECT_EQ(PositionInFlatTree(two->firstChild(), 2), firstEditableVisiblePosi
tionAfterPositionInRoot(PositionInFlatTree(one, 0), *host).deepEquivalent()); |
| 45 | 45 |
| 46 EXPECT_EQ(Position::firstPositionInNode(host), firstEditablePositionAfterPos
itionInRoot(Position(three, 0), *host)); | 46 EXPECT_EQ(Position::firstPositionInNode(host), firstEditablePositionAfterPos
itionInRoot(Position(three, 0), *host)); |
| 47 EXPECT_EQ(Position(one->firstChild(), 0), firstEditableVisiblePositionAfterP
ositionInRoot(Position(three, 0), *host).deepEquivalent()); | 47 EXPECT_EQ(Position(one->firstChild(), 0), firstEditableVisiblePositionAfterP
ositionInRoot(Position(three, 0), *host).deepEquivalent()); |
| 48 EXPECT_EQ(PositionInFlatTree::afterNode(host), firstEditablePositionAfterPos
itionInRoot(PositionInFlatTree(three, 0), *host)); | 48 EXPECT_EQ(PositionInFlatTree::afterNode(host), firstEditablePositionAfterPos
itionInRoot(PositionInFlatTree(three, 0), *host)); |
| 49 EXPECT_EQ(PositionInFlatTree::lastPositionInNode(host), firstEditableVisible
PositionAfterPositionInRoot(PositionInFlatTree(three, 0), *host).deepEquivalent(
)); | 49 EXPECT_EQ(PositionInFlatTree::lastPositionInNode(host), firstEditableVisible
PositionAfterPositionInRoot(PositionInFlatTree(three, 0), *host).deepEquivalent(
)); |
| 50 } | 50 } |
| 51 | 51 |
| 52 TEST_F(EditingUtilitiesTest, enclosingBlock) | 52 TEST_F(EditingUtilitiesTest, enclosingBlock) |
| 53 { | 53 { |
| 54 const char* bodyContent = "<p id='host'><b id='one'>11</b></p>"; | 54 const char* bodyContent = "<p id='host'><b id='one'>11</b></p>"; |
| 55 const char* shadowContent = "<content select=#two></content><div id='three'>
<content select=#one></content></div>"; | 55 const char* shadowContent = "<content select=#two></content><div id='three'>
<content select=#one></content></div>"; |
| 56 setBodyContent(bodyContent); | 56 setBodyContent(bodyContent); |
| 57 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent,
"host"); | 57 RawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent, "host"); |
| 58 updateLayoutAndStyleForPainting(); | 58 updateLayoutAndStyleForPainting(); |
| 59 Node* host = document().getElementById("host"); | 59 Node* host = document().getElementById("host"); |
| 60 Node* one = document().getElementById("one"); | 60 Node* one = document().getElementById("one"); |
| 61 Node* three = shadowRoot->getElementById("three"); | 61 Node* three = shadowRoot->getElementById("three"); |
| 62 | 62 |
| 63 EXPECT_EQ(host, enclosingBlock(Position(one, 0), CannotCrossEditingBoundary)
); | 63 EXPECT_EQ(host, enclosingBlock(Position(one, 0), CannotCrossEditingBoundary)
); |
| 64 EXPECT_EQ(three, enclosingBlock(PositionInFlatTree(one, 0), CannotCrossEditi
ngBoundary)); | 64 EXPECT_EQ(three, enclosingBlock(PositionInFlatTree(one, 0), CannotCrossEditi
ngBoundary)); |
| 65 } | 65 } |
| 66 | 66 |
| 67 TEST_F(EditingUtilitiesTest, enclosingNodeOfType) | 67 TEST_F(EditingUtilitiesTest, enclosingNodeOfType) |
| 68 { | 68 { |
| 69 const char* bodyContent = "<p id='host'><b id='one'>11</b></p>"; | 69 const char* bodyContent = "<p id='host'><b id='one'>11</b></p>"; |
| 70 const char* shadowContent = "<content select=#two></content><div id='three'>
<content select=#one></div></content>"; | 70 const char* shadowContent = "<content select=#two></content><div id='three'>
<content select=#one></div></content>"; |
| 71 setBodyContent(bodyContent); | 71 setBodyContent(bodyContent); |
| 72 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent,
"host"); | 72 RawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent, "host"); |
| 73 updateLayoutAndStyleForPainting(); | 73 updateLayoutAndStyleForPainting(); |
| 74 Node* host = document().getElementById("host"); | 74 Node* host = document().getElementById("host"); |
| 75 Node* one = document().getElementById("one"); | 75 Node* one = document().getElementById("one"); |
| 76 Node* three = shadowRoot->getElementById("three"); | 76 Node* three = shadowRoot->getElementById("three"); |
| 77 | 77 |
| 78 EXPECT_EQ(host, enclosingNodeOfType(Position(one, 0), isEnclosingBlock)); | 78 EXPECT_EQ(host, enclosingNodeOfType(Position(one, 0), isEnclosingBlock)); |
| 79 EXPECT_EQ(three, enclosingNodeOfType(PositionInFlatTree(one, 0), isEnclosing
Block)); | 79 EXPECT_EQ(three, enclosingNodeOfType(PositionInFlatTree(one, 0), isEnclosing
Block)); |
| 80 } | 80 } |
| 81 | 81 |
| 82 TEST_F(EditingUtilitiesTest, isEditablePositionWithTable) | 82 TEST_F(EditingUtilitiesTest, isEditablePositionWithTable) |
| 83 { | 83 { |
| 84 // We would like to have below DOM tree without HTML, HEAD and BODY element. | 84 // We would like to have below DOM tree without HTML, HEAD and BODY element. |
| 85 // <table id=table><caption>foo</caption></table> | 85 // <table id=table><caption>foo</caption></table> |
| 86 // However, |setBodyContent()| automatically creates HTML, HEAD and BODY | 86 // However, |setBodyContent()| automatically creates HTML, HEAD and BODY |
| 87 // element. So, we build DOM tree manually. | 87 // element. So, we build DOM tree manually. |
| 88 // Note: This is unusual HTML taken from http://crbug.com/574230 | 88 // Note: This is unusual HTML taken from http://crbug.com/574230 |
| 89 RefPtrWillBeRawPtr<Element> table = document().createElement("table", ASSERT
_NO_EXCEPTION); | 89 RawPtr<Element> table = document().createElement("table", ASSERT_NO_EXCEPTIO
N); |
| 90 table->setInnerHTML("<caption>foo</caption>", ASSERT_NO_EXCEPTION); | 90 table->setInnerHTML("<caption>foo</caption>", ASSERT_NO_EXCEPTION); |
| 91 while (document().firstChild()) | 91 while (document().firstChild()) |
| 92 document().firstChild()->remove(); | 92 document().firstChild()->remove(); |
| 93 document().appendChild(table); | 93 document().appendChild(table); |
| 94 document().setDesignMode("on"); | 94 document().setDesignMode("on"); |
| 95 updateLayoutAndStyleForPainting(); | 95 updateLayoutAndStyleForPainting(); |
| 96 | 96 |
| 97 EXPECT_FALSE(isEditablePosition(Position(table.get(), 0))); | 97 EXPECT_FALSE(isEditablePosition(Position(table.get(), 0))); |
| 98 } | 98 } |
| 99 | 99 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 121 | 121 |
| 122 EXPECT_EQ(nullptr, isFirstPositionAfterTable(createVisiblePosition(Position:
:lastPositionInNode(host)))); | 122 EXPECT_EQ(nullptr, isFirstPositionAfterTable(createVisiblePosition(Position:
:lastPositionInNode(host)))); |
| 123 EXPECT_EQ(table, isFirstPositionAfterTable(createVisiblePosition(PositionInF
latTree::lastPositionInNode(host)))); | 123 EXPECT_EQ(table, isFirstPositionAfterTable(createVisiblePosition(PositionInF
latTree::lastPositionInNode(host)))); |
| 124 } | 124 } |
| 125 | 125 |
| 126 TEST_F(EditingUtilitiesTest, lastEditablePositionBeforePositionInRoot) | 126 TEST_F(EditingUtilitiesTest, lastEditablePositionBeforePositionInRoot) |
| 127 { | 127 { |
| 128 const char* bodyContent = "<p id='host' contenteditable><b id='one'>1</b><b
id='two'>22</b></p>"; | 128 const char* bodyContent = "<p id='host' contenteditable><b id='one'>1</b><b
id='two'>22</b></p>"; |
| 129 const char* shadowContent = "<content select=#two></content><content select=
#one></content><b id='three'>333</b>"; | 129 const char* shadowContent = "<content select=#two></content><content select=
#one></content><b id='three'>333</b>"; |
| 130 setBodyContent(bodyContent); | 130 setBodyContent(bodyContent); |
| 131 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent,
"host"); | 131 RawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent, "host"); |
| 132 updateLayoutAndStyleForPainting(); | 132 updateLayoutAndStyleForPainting(); |
| 133 Element* host = document().getElementById("host"); | 133 Element* host = document().getElementById("host"); |
| 134 Node* one = document().getElementById("one"); | 134 Node* one = document().getElementById("one"); |
| 135 Node* two = document().getElementById("two"); | 135 Node* two = document().getElementById("two"); |
| 136 Node* three = shadowRoot->getElementById("three"); | 136 Node* three = shadowRoot->getElementById("three"); |
| 137 | 137 |
| 138 EXPECT_EQ(Position(one, 0), lastEditablePositionBeforePositionInRoot(Positio
n(one, 0), *host)); | 138 EXPECT_EQ(Position(one, 0), lastEditablePositionBeforePositionInRoot(Positio
n(one, 0), *host)); |
| 139 EXPECT_EQ(Position(one->firstChild(), 0), lastEditableVisiblePositionBeforeP
ositionInRoot(Position(one, 0), *host).deepEquivalent()); | 139 EXPECT_EQ(Position(one->firstChild(), 0), lastEditableVisiblePositionBeforeP
ositionInRoot(Position(one, 0), *host).deepEquivalent()); |
| 140 | 140 |
| 141 EXPECT_EQ(PositionInFlatTree(one, 0), lastEditablePositionBeforePositionInRo
ot(PositionInFlatTree(one, 0), *host)); | 141 EXPECT_EQ(PositionInFlatTree(one, 0), lastEditablePositionBeforePositionInRo
ot(PositionInFlatTree(one, 0), *host)); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 172 Node* three = document().getElementById("three"); | 172 Node* three = document().getElementById("three"); |
| 173 | 173 |
| 174 EXPECT_EQ(Position(two->firstChild(), 1), nextVisuallyDistinctCandidate(Posi
tion(one, 1))); | 174 EXPECT_EQ(Position(two->firstChild(), 1), nextVisuallyDistinctCandidate(Posi
tion(one, 1))); |
| 175 EXPECT_EQ(PositionInFlatTree(three->firstChild(), 1), nextVisuallyDistinctCa
ndidate(PositionInFlatTree(one, 1))); | 175 EXPECT_EQ(PositionInFlatTree(three->firstChild(), 1), nextVisuallyDistinctCa
ndidate(PositionInFlatTree(one, 1))); |
| 176 } | 176 } |
| 177 | 177 |
| 178 TEST_F(EditingUtilitiesTest, AreaIdenticalElements) | 178 TEST_F(EditingUtilitiesTest, AreaIdenticalElements) |
| 179 { | 179 { |
| 180 setBodyContent("<style>li:nth-child(even) { -webkit-user-modify: read-write;
}</style><ul><li>first item</li><li>second item</li><li class=foo>third</li><li
>fourth</li></ul>"); | 180 setBodyContent("<style>li:nth-child(even) { -webkit-user-modify: read-write;
}</style><ul><li>first item</li><li>second item</li><li class=foo>third</li><li
>fourth</li></ul>"); |
| 181 updateLayoutAndStyleForPainting(); | 181 updateLayoutAndStyleForPainting(); |
| 182 RefPtrWillBeRawPtr<StaticElementList> items = document().querySelectorAll("l
i", ASSERT_NO_EXCEPTION); | 182 RawPtr<StaticElementList> items = document().querySelectorAll("li", ASSERT_N
O_EXCEPTION); |
| 183 ASSERT(items->length() == 4); | 183 ASSERT(items->length() == 4); |
| 184 | 184 |
| 185 EXPECT_FALSE(areIdenticalElements(*items->item(0)->firstChild(), *items->ite
m(1)->firstChild())) | 185 EXPECT_FALSE(areIdenticalElements(*items->item(0)->firstChild(), *items->ite
m(1)->firstChild())) |
| 186 << "Can't merge non-elements. e.g. Text nodes"; | 186 << "Can't merge non-elements. e.g. Text nodes"; |
| 187 | 187 |
| 188 // Compare a LI and a UL. | 188 // Compare a LI and a UL. |
| 189 EXPECT_FALSE(areIdenticalElements(*items->item(0), *items->item(0)->parentNo
de())) | 189 EXPECT_FALSE(areIdenticalElements(*items->item(0), *items->item(0)->parentNo
de())) |
| 190 << "Can't merge different tag names."; | 190 << "Can't merge different tag names."; |
| 191 | 191 |
| 192 EXPECT_FALSE(areIdenticalElements(*items->item(0), *items->item(2))) | 192 EXPECT_FALSE(areIdenticalElements(*items->item(0), *items->item(2))) |
| (...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 | 734 |
| 735 // Edge case: specify middle of surrogate pairs. | 735 // Edge case: specify middle of surrogate pairs. |
| 736 setBodyContent("<p id='target'>👁👁👁</p>"); | 736 setBodyContent("<p id='target'>👁👁👁</p>"); |
| 737 node = document().getElementById("target")->firstChild(); | 737 node = document().getElementById("target")->firstChild(); |
| 738 EXPECT_EQ(Position(node, 4), previousPositionOf(Position(node, 5), PositionM
oveType::BackwardDeletion)); | 738 EXPECT_EQ(Position(node, 4), previousPositionOf(Position(node, 5), PositionM
oveType::BackwardDeletion)); |
| 739 EXPECT_EQ(Position(node, 2), previousPositionOf(Position(node, 3), PositionM
oveType::BackwardDeletion)); | 739 EXPECT_EQ(Position(node, 2), previousPositionOf(Position(node, 3), PositionM
oveType::BackwardDeletion)); |
| 740 EXPECT_EQ(Position(node, 0), previousPositionOf(Position(node, 1), PositionM
oveType::BackwardDeletion)); | 740 EXPECT_EQ(Position(node, 0), previousPositionOf(Position(node, 1), PositionM
oveType::BackwardDeletion)); |
| 741 } | 741 } |
| 742 | 742 |
| 743 } // namespace blink | 743 } // namespace blink |
| OLD | NEW |