| 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 19 matching lines...) Expand all Loading... |
| 30 void setSelection(VisibleSelectionTemplate<Strategy>& selection, int base) { | 30 void setSelection(VisibleSelectionTemplate<Strategy>& selection, int base) { |
| 31 setSelection(selection, base, base); | 31 setSelection(selection, base, base); |
| 32 } | 32 } |
| 33 | 33 |
| 34 // Helper function to set the VisibleSelection base/extent. | 34 // Helper function to set the VisibleSelection base/extent. |
| 35 template <typename Strategy> | 35 template <typename Strategy> |
| 36 void setSelection(VisibleSelectionTemplate<Strategy>& selection, | 36 void setSelection(VisibleSelectionTemplate<Strategy>& selection, |
| 37 int base, | 37 int base, |
| 38 int extend) { | 38 int extend) { |
| 39 Node* node = document().body()->firstChild(); | 39 Node* node = document().body()->firstChild(); |
| 40 selection.setBase(PositionTemplate<Strategy>(node, base)); | 40 selection = createVisibleSelection( |
| 41 selection.setExtent(PositionTemplate<Strategy>(node, extend)); | 41 typename SelectionTemplate<Strategy>::Builder(selection.asSelection()) |
| 42 .collapse(PositionTemplate<Strategy>(node, base)) |
| 43 .extend(PositionTemplate<Strategy>(node, extend)) |
| 44 .build()); |
| 42 } | 45 } |
| 43 }; | 46 }; |
| 44 | 47 |
| 45 static void testFlatTreePositionsToEqualToDOMTreePositions( | 48 static void testFlatTreePositionsToEqualToDOMTreePositions( |
| 46 const VisibleSelection& selection, | 49 const VisibleSelection& selection, |
| 47 const VisibleSelectionInFlatTree& selectionInFlatTree) { | 50 const VisibleSelectionInFlatTree& selectionInFlatTree) { |
| 48 // Since DOM tree positions can't be map to flat tree version, e.g. | 51 // Since DOM tree positions can't be map to flat tree version, e.g. |
| 49 // shadow root, not distributed node, we map a position in flat tree | 52 // shadow root, not distributed node, we map a position in flat tree |
| 50 // to DOM tree position. | 53 // to DOM tree position. |
| 51 EXPECT_EQ(selection.start(), | 54 EXPECT_EQ(selection.start(), |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 selection.updateIfNeeded(); | 455 selection.updateIfNeeded(); |
| 453 EXPECT_EQ(Position(sample->firstChild(), 0), selection.start()); | 456 EXPECT_EQ(Position(sample->firstChild(), 0), selection.start()); |
| 454 | 457 |
| 455 VisibleSelectionInFlatTree selectionInFlatTree; | 458 VisibleSelectionInFlatTree selectionInFlatTree; |
| 456 SelectionAdjuster::adjustSelectionInFlatTree(&selectionInFlatTree, selection); | 459 SelectionAdjuster::adjustSelectionInFlatTree(&selectionInFlatTree, selection); |
| 457 EXPECT_EQ(PositionInFlatTree(sample->firstChild(), 0), | 460 EXPECT_EQ(PositionInFlatTree(sample->firstChild(), 0), |
| 458 selectionInFlatTree.start()); | 461 selectionInFlatTree.start()); |
| 459 } | 462 } |
| 460 | 463 |
| 461 } // namespace blink | 464 } // namespace blink |
| OLD | NEW |