OLD | NEW |
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 Loading... |
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(SelectionInDOMTree::Builder() |
| 75 .collapse(selection.base()) |
| 76 .extend(extentPosition.deepEquivalent()) |
| 77 .setAffinity(selection.affinity()) |
| 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 Loading... |
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.base()) |
| 157 .extend(newOffsetExtentPosition.deepEquivalent()) |
| 158 .setAffinity(selection.affinity()) |
| 159 .build()); |
152 } | 160 } |
153 | 161 |
154 int oldExtentBaseOrder = selection.isBaseFirst() ? 1 : -1; | 162 int oldExtentBaseOrder = selection.isBaseFirst() ? 1 : -1; |
155 | 163 |
156 int newExtentBaseOrder; | 164 int newExtentBaseOrder; |
157 bool thisMoveShrunkSelection; | 165 bool thisMoveShrunkSelection; |
158 if (newOffsetExtentPosition.deepEquivalent() == | 166 if (newOffsetExtentPosition.deepEquivalent() == |
159 oldOffsetExtentPosition.deepEquivalent()) { | 167 oldOffsetExtentPosition.deepEquivalent()) { |
160 if (m_granularity == CharacterGranularity) | 168 if (m_granularity == CharacterGranularity) |
161 return selection; | 169 return selection; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 : StrategyState::Expanding; | 267 : StrategyState::Expanding; |
260 | 268 |
261 m_diffExtentPointFromExtentPosition = | 269 m_diffExtentPointFromExtentPosition = |
262 extentPoint + IntSize(m_offset, 0) - positionLocation(newSelectionExtent); | 270 extentPoint + IntSize(m_offset, 0) - positionLocation(newSelectionExtent); |
263 VisibleSelection newSelection = selection; | 271 VisibleSelection newSelection = selection; |
264 newSelection.setExtent(newSelectionExtent); | 272 newSelection.setExtent(newSelectionExtent); |
265 return newSelection; | 273 return newSelection; |
266 } | 274 } |
267 | 275 |
268 } // namespace blink | 276 } // namespace blink |
OLD | NEW |