Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: third_party/WebKit/Source/core/editing/VisibleSelectionTest.cpp

Issue 2455083003: Reduce usage of VisibleSelection::setBase() and setExtent() (Closed)
Patch Set: 2016-10-31T10:31:10 Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/editing/VisibleSelection.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/VisibleSelection.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698