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

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

Issue 2374183004: Make non-null VisibleSelections creatable only by createVisibleSelection[Deprecated] (Closed)
Patch Set: Fix mac compile error 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 } 65 }
66 66
67 void CharacterGranularityStrategy::Clear() { } 67 void CharacterGranularityStrategy::Clear() { }
68 68
69 VisibleSelection CharacterGranularityStrategy::updateExtent(const IntPoint& exte ntPoint, LocalFrame* frame) 69 VisibleSelection CharacterGranularityStrategy::updateExtent(const IntPoint& exte ntPoint, LocalFrame* frame)
70 { 70 {
71 const VisiblePosition& extentPosition = visiblePositionForContentsPoint(exte ntPoint, frame); 71 const VisiblePosition& extentPosition = visiblePositionForContentsPoint(exte ntPoint, frame);
72 const VisibleSelection& selection = frame->selection().selection(); 72 const VisibleSelection& selection = frame->selection().selection();
73 if (selection.visibleBase().deepEquivalent() == extentPosition.deepEquivalen t()) 73 if (selection.visibleBase().deepEquivalent() == extentPosition.deepEquivalen t())
74 return selection; 74 return selection;
75 return VisibleSelection(selection.visibleBase(), extentPosition); 75 return createVisibleSelectionDeprecated(selection.visibleBase(), extentPosit ion);
76 } 76 }
77 77
78 DirectionGranularityStrategy::DirectionGranularityStrategy() 78 DirectionGranularityStrategy::DirectionGranularityStrategy()
79 : m_state(StrategyState::Cleared) 79 : m_state(StrategyState::Cleared)
80 , m_granularity(CharacterGranularity) 80 , m_granularity(CharacterGranularity)
81 , m_offset(0) { } 81 , m_offset(0) { }
82 82
83 DirectionGranularityStrategy::~DirectionGranularityStrategy() { } 83 DirectionGranularityStrategy::~DirectionGranularityStrategy() { }
84 84
85 SelectionStrategy DirectionGranularityStrategy::GetType() const 85 SelectionStrategy DirectionGranularityStrategy::GetType() const
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 // Do not allow empty selection. 137 // Do not allow empty selection.
138 if (newOffsetExtentPosition.deepEquivalent() == base.deepEquivalent()) 138 if (newOffsetExtentPosition.deepEquivalent() == base.deepEquivalent())
139 return selection; 139 return selection;
140 140
141 // The direction granularity strategy, particularly the "offset" feature 141 // The direction granularity strategy, particularly the "offset" feature
142 // doesn't work with non-horizontal text (e.g. when the text is rotated). 142 // doesn't work with non-horizontal text (e.g. when the text is rotated).
143 // So revert to the behavior equivalent to the character granularity 143 // So revert to the behavior equivalent to the character granularity
144 // strategy if we detect that the text's baseline coordinate changed 144 // strategy if we detect that the text's baseline coordinate changed
145 // without a line change. 145 // without a line change.
146 if (verticalChange && inSameLine(newOffsetExtentPosition, oldOffsetExtentPos ition)) 146 if (verticalChange && inSameLine(newOffsetExtentPosition, oldOffsetExtentPos ition))
147 return VisibleSelection(selection.visibleBase(), newOffsetExtentPosition ); 147 return createVisibleSelectionDeprecated(selection.visibleBase(), newOffs etExtentPosition);
148 148
149 int oldExtentBaseOrder = selection.isBaseFirst() ? 1 : -1; 149 int oldExtentBaseOrder = selection.isBaseFirst() ? 1 : -1;
150 150
151 int newExtentBaseOrder; 151 int newExtentBaseOrder;
152 bool thisMoveShrunkSelection; 152 bool thisMoveShrunkSelection;
153 if (newOffsetExtentPosition.deepEquivalent() == oldOffsetExtentPosition.deep Equivalent()) { 153 if (newOffsetExtentPosition.deepEquivalent() == oldOffsetExtentPosition.deep Equivalent()) {
154 if (m_granularity == CharacterGranularity) 154 if (m_granularity == CharacterGranularity)
155 return selection; 155 return selection;
156 156
157 // If we are in Word granularity, we cannot exit here, since we may pass 157 // If we are in Word granularity, we cannot exit here, since we may pass
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 if (newSelectionExtent.deepEquivalent() != selection.visibleExtent().deepEqu ivalent()) 229 if (newSelectionExtent.deepEquivalent() != selection.visibleExtent().deepEqu ivalent())
230 m_state = thisMoveShrunkSelection ? StrategyState::Shrinking : StrategyS tate::Expanding; 230 m_state = thisMoveShrunkSelection ? StrategyState::Shrinking : StrategyS tate::Expanding;
231 231
232 m_diffExtentPointFromExtentPosition = extentPoint + IntSize(m_offset, 0) - p ositionLocation(newSelectionExtent); 232 m_diffExtentPointFromExtentPosition = extentPoint + IntSize(m_offset, 0) - p ositionLocation(newSelectionExtent);
233 VisibleSelection newSelection = selection; 233 VisibleSelection newSelection = selection;
234 newSelection.setExtent(newSelectionExtent); 234 newSelection.setExtent(newSelectionExtent);
235 return newSelection; 235 return newSelection;
236 } 236 }
237 237
238 } // namespace blink 238 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698