| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/VisibleSelection.h" | 5 #include "core/editing/VisibleSelection.h" |
| 6 | 6 |
| 7 #include "core/dom/Range.h" | 7 #include "core/dom/Range.h" |
| 8 #include "core/editing/EditingTestBase.h" | 8 #include "core/editing/EditingTestBase.h" |
| 9 #include "core/editing/SelectionAdjuster.h" | 9 #include "core/editing/SelectionAdjuster.h" |
| 10 | 10 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 Node* one = document().getElementById("one")->firstChild(); | 58 Node* one = document().getElementById("one")->firstChild(); |
| 59 Node* two = document().getElementById("two")->firstChild(); | 59 Node* two = document().getElementById("two")->firstChild(); |
| 60 Node* three = shadowRoot->getElementById("three")->firstChild(); | 60 Node* three = shadowRoot->getElementById("three")->firstChild(); |
| 61 Node* four = shadowRoot->getElementById("four")->firstChild(); | 61 Node* four = shadowRoot->getElementById("four")->firstChild(); |
| 62 Node* five = shadowRoot->getElementById("five")->firstChild(); | 62 Node* five = shadowRoot->getElementById("five")->firstChild(); |
| 63 | 63 |
| 64 VisibleSelection selection; | 64 VisibleSelection selection; |
| 65 VisibleSelectionInFlatTree selectionInFlatTree; | 65 VisibleSelectionInFlatTree selectionInFlatTree; |
| 66 | 66 |
| 67 // From a position at distributed node | 67 // From a position at distributed node |
| 68 selection = VisibleSelection(createVisiblePositionDeprecated(Position(one, 1
))); | 68 selection = VisibleSelection(createVisiblePosition(Position(one, 1))); |
| 69 selection.expandUsingGranularity(WordGranularity); | 69 selection.expandUsingGranularity(WordGranularity); |
| 70 selectionInFlatTree = VisibleSelectionInFlatTree(createVisiblePositionDeprec
ated(PositionInFlatTree(one, 1))); | 70 selectionInFlatTree = VisibleSelectionInFlatTree(createVisiblePosition(Posit
ionInFlatTree(one, 1))); |
| 71 selectionInFlatTree.expandUsingGranularity(WordGranularity); | 71 selectionInFlatTree.expandUsingGranularity(WordGranularity); |
| 72 | 72 |
| 73 EXPECT_EQ(Position(one, 1), selection.base()); | 73 EXPECT_EQ(Position(one, 1), selection.base()); |
| 74 EXPECT_EQ(Position(one, 1), selection.extent()); | 74 EXPECT_EQ(Position(one, 1), selection.extent()); |
| 75 EXPECT_EQ(Position(one, 0), selection.start()); | 75 EXPECT_EQ(Position(one, 0), selection.start()); |
| 76 EXPECT_EQ(Position(two, 2), selection.end()); | 76 EXPECT_EQ(Position(two, 2), selection.end()); |
| 77 | 77 |
| 78 EXPECT_EQ(PositionInFlatTree(one, 1), selectionInFlatTree.base()); | 78 EXPECT_EQ(PositionInFlatTree(one, 1), selectionInFlatTree.base()); |
| 79 EXPECT_EQ(PositionInFlatTree(one, 1), selectionInFlatTree.extent()); | 79 EXPECT_EQ(PositionInFlatTree(one, 1), selectionInFlatTree.extent()); |
| 80 EXPECT_EQ(PositionInFlatTree(one, 0), selectionInFlatTree.start()); | 80 EXPECT_EQ(PositionInFlatTree(one, 0), selectionInFlatTree.start()); |
| 81 EXPECT_EQ(PositionInFlatTree(five, 5), selectionInFlatTree.end()); | 81 EXPECT_EQ(PositionInFlatTree(five, 5), selectionInFlatTree.end()); |
| 82 | 82 |
| 83 // From a position at distributed node | 83 // From a position at distributed node |
| 84 selection = VisibleSelection(createVisiblePositionDeprecated(Position(two, 1
))); | 84 selection = VisibleSelection(createVisiblePosition(Position(two, 1))); |
| 85 selection.expandUsingGranularity(WordGranularity); | 85 selection.expandUsingGranularity(WordGranularity); |
| 86 selectionInFlatTree = VisibleSelectionInFlatTree(createVisiblePositionDeprec
ated(PositionInFlatTree(two, 1))); | 86 selectionInFlatTree = VisibleSelectionInFlatTree(createVisiblePosition(Posit
ionInFlatTree(two, 1))); |
| 87 selectionInFlatTree.expandUsingGranularity(WordGranularity); | 87 selectionInFlatTree.expandUsingGranularity(WordGranularity); |
| 88 | 88 |
| 89 EXPECT_EQ(Position(two, 1), selection.base()); | 89 EXPECT_EQ(Position(two, 1), selection.base()); |
| 90 EXPECT_EQ(Position(two, 1), selection.extent()); | 90 EXPECT_EQ(Position(two, 1), selection.extent()); |
| 91 EXPECT_EQ(Position(one, 0), selection.start()); | 91 EXPECT_EQ(Position(one, 0), selection.start()); |
| 92 EXPECT_EQ(Position(two, 2), selection.end()); | 92 EXPECT_EQ(Position(two, 2), selection.end()); |
| 93 | 93 |
| 94 EXPECT_EQ(PositionInFlatTree(two, 1), selectionInFlatTree.base()); | 94 EXPECT_EQ(PositionInFlatTree(two, 1), selectionInFlatTree.base()); |
| 95 EXPECT_EQ(PositionInFlatTree(two, 1), selectionInFlatTree.extent()); | 95 EXPECT_EQ(PositionInFlatTree(two, 1), selectionInFlatTree.extent()); |
| 96 EXPECT_EQ(PositionInFlatTree(three, 0), selectionInFlatTree.start()); | 96 EXPECT_EQ(PositionInFlatTree(three, 0), selectionInFlatTree.start()); |
| 97 EXPECT_EQ(PositionInFlatTree(four, 4), selectionInFlatTree.end()); | 97 EXPECT_EQ(PositionInFlatTree(four, 4), selectionInFlatTree.end()); |
| 98 | 98 |
| 99 // From a position at node in shadow tree | 99 // From a position at node in shadow tree |
| 100 selection = VisibleSelection(createVisiblePositionDeprecated(Position(three,
1))); | 100 selection = VisibleSelection(createVisiblePosition(Position(three, 1))); |
| 101 selection.expandUsingGranularity(WordGranularity); | 101 selection.expandUsingGranularity(WordGranularity); |
| 102 selectionInFlatTree = VisibleSelectionInFlatTree(createVisiblePositionDeprec
ated(PositionInFlatTree(three, 1))); | 102 selectionInFlatTree = VisibleSelectionInFlatTree(createVisiblePosition(Posit
ionInFlatTree(three, 1))); |
| 103 selectionInFlatTree.expandUsingGranularity(WordGranularity); | 103 selectionInFlatTree.expandUsingGranularity(WordGranularity); |
| 104 | 104 |
| 105 EXPECT_EQ(Position(three, 1), selection.base()); | 105 EXPECT_EQ(Position(three, 1), selection.base()); |
| 106 EXPECT_EQ(Position(three, 1), selection.extent()); | 106 EXPECT_EQ(Position(three, 1), selection.extent()); |
| 107 EXPECT_EQ(Position(three, 0), selection.start()); | 107 EXPECT_EQ(Position(three, 0), selection.start()); |
| 108 EXPECT_EQ(Position(four, 4), selection.end()); | 108 EXPECT_EQ(Position(four, 4), selection.end()); |
| 109 | 109 |
| 110 EXPECT_EQ(PositionInFlatTree(three, 1), selectionInFlatTree.base()); | 110 EXPECT_EQ(PositionInFlatTree(three, 1), selectionInFlatTree.base()); |
| 111 EXPECT_EQ(PositionInFlatTree(three, 1), selectionInFlatTree.extent()); | 111 EXPECT_EQ(PositionInFlatTree(three, 1), selectionInFlatTree.extent()); |
| 112 EXPECT_EQ(PositionInFlatTree(three, 0), selectionInFlatTree.start()); | 112 EXPECT_EQ(PositionInFlatTree(three, 0), selectionInFlatTree.start()); |
| 113 EXPECT_EQ(PositionInFlatTree(four, 4), selectionInFlatTree.end()); | 113 EXPECT_EQ(PositionInFlatTree(four, 4), selectionInFlatTree.end()); |
| 114 | 114 |
| 115 // From a position at node in shadow tree | 115 // From a position at node in shadow tree |
| 116 selection = VisibleSelection(createVisiblePositionDeprecated(Position(four,
1))); | 116 selection = VisibleSelection(createVisiblePosition(Position(four, 1))); |
| 117 selection.expandUsingGranularity(WordGranularity); | 117 selection.expandUsingGranularity(WordGranularity); |
| 118 selectionInFlatTree = VisibleSelectionInFlatTree(createVisiblePositionDeprec
ated(PositionInFlatTree(four, 1))); | 118 selectionInFlatTree = VisibleSelectionInFlatTree(createVisiblePosition(Posit
ionInFlatTree(four, 1))); |
| 119 selectionInFlatTree.expandUsingGranularity(WordGranularity); | 119 selectionInFlatTree.expandUsingGranularity(WordGranularity); |
| 120 | 120 |
| 121 EXPECT_EQ(Position(four, 1), selection.base()); | 121 EXPECT_EQ(Position(four, 1), selection.base()); |
| 122 EXPECT_EQ(Position(four, 1), selection.extent()); | 122 EXPECT_EQ(Position(four, 1), selection.extent()); |
| 123 EXPECT_EQ(Position(three, 0), selection.start()); | 123 EXPECT_EQ(Position(three, 0), selection.start()); |
| 124 EXPECT_EQ(Position(four, 4), selection.end()); | 124 EXPECT_EQ(Position(four, 4), selection.end()); |
| 125 | 125 |
| 126 EXPECT_EQ(PositionInFlatTree(four, 1), selectionInFlatTree.base()); | 126 EXPECT_EQ(PositionInFlatTree(four, 1), selectionInFlatTree.base()); |
| 127 EXPECT_EQ(PositionInFlatTree(four, 1), selectionInFlatTree.extent()); | 127 EXPECT_EQ(PositionInFlatTree(four, 1), selectionInFlatTree.extent()); |
| 128 EXPECT_EQ(PositionInFlatTree(three, 0), selectionInFlatTree.start()); | 128 EXPECT_EQ(PositionInFlatTree(three, 0), selectionInFlatTree.start()); |
| 129 EXPECT_EQ(PositionInFlatTree(four, 4), selectionInFlatTree.end()); | 129 EXPECT_EQ(PositionInFlatTree(four, 4), selectionInFlatTree.end()); |
| 130 | 130 |
| 131 // From a position at node in shadow tree | 131 // From a position at node in shadow tree |
| 132 selection = VisibleSelection(createVisiblePositionDeprecated(Position(five,
1))); | 132 selection = VisibleSelection(createVisiblePosition(Position(five, 1))); |
| 133 selection.expandUsingGranularity(WordGranularity); | 133 selection.expandUsingGranularity(WordGranularity); |
| 134 selectionInFlatTree = VisibleSelectionInFlatTree(createVisiblePositionDeprec
ated(PositionInFlatTree(five, 1))); | 134 selectionInFlatTree = VisibleSelectionInFlatTree(createVisiblePosition(Posit
ionInFlatTree(five, 1))); |
| 135 selectionInFlatTree.expandUsingGranularity(WordGranularity); | 135 selectionInFlatTree.expandUsingGranularity(WordGranularity); |
| 136 | 136 |
| 137 EXPECT_EQ(Position(five, 1), selection.base()); | 137 EXPECT_EQ(Position(five, 1), selection.base()); |
| 138 EXPECT_EQ(Position(five, 1), selection.extent()); | 138 EXPECT_EQ(Position(five, 1), selection.extent()); |
| 139 EXPECT_EQ(Position(five, 0), selection.start()); | 139 EXPECT_EQ(Position(five, 0), selection.start()); |
| 140 EXPECT_EQ(Position(five, 5), selection.end()); | 140 EXPECT_EQ(Position(five, 5), selection.end()); |
| 141 | 141 |
| 142 EXPECT_EQ(PositionInFlatTree(five, 1), selectionInFlatTree.base()); | 142 EXPECT_EQ(PositionInFlatTree(five, 1), selectionInFlatTree.base()); |
| 143 EXPECT_EQ(PositionInFlatTree(five, 1), selectionInFlatTree.extent()); | 143 EXPECT_EQ(PositionInFlatTree(five, 1), selectionInFlatTree.extent()); |
| 144 EXPECT_EQ(PositionInFlatTree(one, 0), selectionInFlatTree.start()); | 144 EXPECT_EQ(PositionInFlatTree(one, 0), selectionInFlatTree.start()); |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 // Simulates to restore selection from undo stack. | 370 // Simulates to restore selection from undo stack. |
| 371 selection.validatePositionsIfNeeded(); | 371 selection.validatePositionsIfNeeded(); |
| 372 EXPECT_EQ(Position(sample->firstChild(), 0), selection.start()); | 372 EXPECT_EQ(Position(sample->firstChild(), 0), selection.start()); |
| 373 | 373 |
| 374 VisibleSelectionInFlatTree selectionInFlatTree; | 374 VisibleSelectionInFlatTree selectionInFlatTree; |
| 375 SelectionAdjuster::adjustSelectionInFlatTree(&selectionInFlatTree, selection
); | 375 SelectionAdjuster::adjustSelectionInFlatTree(&selectionInFlatTree, selection
); |
| 376 EXPECT_EQ(PositionInFlatTree(sample->firstChild(), 0), selectionInFlatTree.s
tart()); | 376 EXPECT_EQ(PositionInFlatTree(sample->firstChild(), 0), selectionInFlatTree.s
tart()); |
| 377 } | 377 } |
| 378 | 378 |
| 379 } // namespace blink | 379 } // namespace blink |
| OLD | NEW |