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

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

Issue 2437873008: Get rid of flat tree version of createVisibleSelection() taking two VisiblePosition (Closed)
Patch Set: 2016-10-21T16:03:11 Created 4 years, 2 months 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
OLDNEW
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/GranularityStrategy.h" 5 #include "core/editing/GranularityStrategy.h"
6 6
7 #include "core/editing/EditingUtilities.h" 7 #include "core/editing/EditingUtilities.h"
8 #include "core/editing/FrameSelection.h" 8 #include "core/editing/FrameSelection.h"
9 9
10 namespace blink { 10 namespace blink {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 64
65 VisibleSelection CharacterGranularityStrategy::updateExtent( 65 VisibleSelection CharacterGranularityStrategy::updateExtent(
66 const IntPoint& extentPoint, 66 const IntPoint& extentPoint,
67 LocalFrame* frame) { 67 LocalFrame* frame) {
68 const VisiblePosition& extentPosition = 68 const VisiblePosition& extentPosition =
69 visiblePositionForContentsPoint(extentPoint, frame); 69 visiblePositionForContentsPoint(extentPoint, frame);
70 const VisibleSelection& selection = frame->selection().selection(); 70 const VisibleSelection& selection = frame->selection().selection();
71 if (selection.visibleBase().deepEquivalent() == 71 if (selection.visibleBase().deepEquivalent() ==
72 extentPosition.deepEquivalent()) 72 extentPosition.deepEquivalent())
73 return selection; 73 return selection;
74 return createVisibleSelection(selection.visibleBase(), extentPosition); 74 return createVisibleSelection(
75 SelectionInDOMTree::Builder()
76 .collapse(selection.visibleBase().toPositionWithAffinity())
Xiaocheng 2016/10/21 11:18:36 We should use collapse(selection.base()).setAffini
yosin_UTC9 2016/10/24 06:19:44 Good catch! Done
77 .extend(extentPosition.deepEquivalent())
78 .build());
75 } 79 }
76 80
77 DirectionGranularityStrategy::DirectionGranularityStrategy() 81 DirectionGranularityStrategy::DirectionGranularityStrategy()
78 : m_state(StrategyState::Cleared), 82 : m_state(StrategyState::Cleared),
79 m_granularity(CharacterGranularity), 83 m_granularity(CharacterGranularity),
80 m_offset(0) {} 84 m_offset(0) {}
81 85
82 DirectionGranularityStrategy::~DirectionGranularityStrategy() {} 86 DirectionGranularityStrategy::~DirectionGranularityStrategy() {}
83 87
84 SelectionStrategy DirectionGranularityStrategy::GetType() const { 88 SelectionStrategy DirectionGranularityStrategy::GetType() const {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 if (newOffsetExtentPosition.deepEquivalent() == base.deepEquivalent()) 144 if (newOffsetExtentPosition.deepEquivalent() == base.deepEquivalent())
141 return selection; 145 return selection;
142 146
143 // The direction granularity strategy, particularly the "offset" feature 147 // The direction granularity strategy, particularly the "offset" feature
144 // doesn't work with non-horizontal text (e.g. when the text is rotated). 148 // doesn't work with non-horizontal text (e.g. when the text is rotated).
145 // So revert to the behavior equivalent to the character granularity 149 // So revert to the behavior equivalent to the character granularity
146 // strategy if we detect that the text's baseline coordinate changed 150 // strategy if we detect that the text's baseline coordinate changed
147 // without a line change. 151 // without a line change.
148 if (verticalChange && 152 if (verticalChange &&
149 inSameLine(newOffsetExtentPosition, oldOffsetExtentPosition)) { 153 inSameLine(newOffsetExtentPosition, oldOffsetExtentPosition)) {
150 return createVisibleSelection(selection.visibleBase(), 154 return createVisibleSelection(
151 newOffsetExtentPosition); 155 SelectionInDOMTree::Builder()
156 .collapse(selection.visibleBase().toPositionWithAffinity())
Xiaocheng 2016/10/21 11:18:36 We should use collapse(selection.base()).setAffini
yosin_UTC9 2016/10/24 06:19:44 Good catch! Done.
157 .extend(newOffsetExtentPosition.deepEquivalent())
158 .build());
152 } 159 }
153 160
154 int oldExtentBaseOrder = selection.isBaseFirst() ? 1 : -1; 161 int oldExtentBaseOrder = selection.isBaseFirst() ? 1 : -1;
155 162
156 int newExtentBaseOrder; 163 int newExtentBaseOrder;
157 bool thisMoveShrunkSelection; 164 bool thisMoveShrunkSelection;
158 if (newOffsetExtentPosition.deepEquivalent() == 165 if (newOffsetExtentPosition.deepEquivalent() ==
159 oldOffsetExtentPosition.deepEquivalent()) { 166 oldOffsetExtentPosition.deepEquivalent()) {
160 if (m_granularity == CharacterGranularity) 167 if (m_granularity == CharacterGranularity)
161 return selection; 168 return selection;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 : StrategyState::Expanding; 266 : StrategyState::Expanding;
260 267
261 m_diffExtentPointFromExtentPosition = 268 m_diffExtentPointFromExtentPosition =
262 extentPoint + IntSize(m_offset, 0) - positionLocation(newSelectionExtent); 269 extentPoint + IntSize(m_offset, 0) - positionLocation(newSelectionExtent);
263 VisibleSelection newSelection = selection; 270 VisibleSelection newSelection = selection;
264 newSelection.setExtent(newSelectionExtent); 271 newSelection.setExtent(newSelectionExtent);
265 return newSelection; 272 return newSelection;
266 } 273 }
267 274
268 } // namespace blink 275 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698