| 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 createVisibleSelectionDeprecated(selection.visibleBase(), | 74 return createVisibleSelection(selection.visibleBase(), extentPosition); |
| 75 extentPosition); | |
| 76 } | 75 } |
| 77 | 76 |
| 78 DirectionGranularityStrategy::DirectionGranularityStrategy() | 77 DirectionGranularityStrategy::DirectionGranularityStrategy() |
| 79 : m_state(StrategyState::Cleared), | 78 : m_state(StrategyState::Cleared), |
| 80 m_granularity(CharacterGranularity), | 79 m_granularity(CharacterGranularity), |
| 81 m_offset(0) {} | 80 m_offset(0) {} |
| 82 | 81 |
| 83 DirectionGranularityStrategy::~DirectionGranularityStrategy() {} | 82 DirectionGranularityStrategy::~DirectionGranularityStrategy() {} |
| 84 | 83 |
| 85 SelectionStrategy DirectionGranularityStrategy::GetType() const { | 84 SelectionStrategy DirectionGranularityStrategy::GetType() const { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 // Do not allow empty selection. | 139 // Do not allow empty selection. |
| 141 if (newOffsetExtentPosition.deepEquivalent() == base.deepEquivalent()) | 140 if (newOffsetExtentPosition.deepEquivalent() == base.deepEquivalent()) |
| 142 return selection; | 141 return selection; |
| 143 | 142 |
| 144 // The direction granularity strategy, particularly the "offset" feature | 143 // The direction granularity strategy, particularly the "offset" feature |
| 145 // doesn't work with non-horizontal text (e.g. when the text is rotated). | 144 // doesn't work with non-horizontal text (e.g. when the text is rotated). |
| 146 // So revert to the behavior equivalent to the character granularity | 145 // So revert to the behavior equivalent to the character granularity |
| 147 // strategy if we detect that the text's baseline coordinate changed | 146 // strategy if we detect that the text's baseline coordinate changed |
| 148 // without a line change. | 147 // without a line change. |
| 149 if (verticalChange && | 148 if (verticalChange && |
| 150 inSameLine(newOffsetExtentPosition, oldOffsetExtentPosition)) | 149 inSameLine(newOffsetExtentPosition, oldOffsetExtentPosition)) { |
| 151 return createVisibleSelectionDeprecated(selection.visibleBase(), | 150 return createVisibleSelection(selection.visibleBase(), |
| 152 newOffsetExtentPosition); | 151 newOffsetExtentPosition); |
| 152 } |
| 153 | 153 |
| 154 int oldExtentBaseOrder = selection.isBaseFirst() ? 1 : -1; | 154 int oldExtentBaseOrder = selection.isBaseFirst() ? 1 : -1; |
| 155 | 155 |
| 156 int newExtentBaseOrder; | 156 int newExtentBaseOrder; |
| 157 bool thisMoveShrunkSelection; | 157 bool thisMoveShrunkSelection; |
| 158 if (newOffsetExtentPosition.deepEquivalent() == | 158 if (newOffsetExtentPosition.deepEquivalent() == |
| 159 oldOffsetExtentPosition.deepEquivalent()) { | 159 oldOffsetExtentPosition.deepEquivalent()) { |
| 160 if (m_granularity == CharacterGranularity) | 160 if (m_granularity == CharacterGranularity) |
| 161 return selection; | 161 return selection; |
| 162 | 162 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 : StrategyState::Expanding; | 259 : StrategyState::Expanding; |
| 260 | 260 |
| 261 m_diffExtentPointFromExtentPosition = | 261 m_diffExtentPointFromExtentPosition = |
| 262 extentPoint + IntSize(m_offset, 0) - positionLocation(newSelectionExtent); | 262 extentPoint + IntSize(m_offset, 0) - positionLocation(newSelectionExtent); |
| 263 VisibleSelection newSelection = selection; | 263 VisibleSelection newSelection = selection; |
| 264 newSelection.setExtent(newSelectionExtent); | 264 newSelection.setExtent(newSelectionExtent); |
| 265 return newSelection; | 265 return newSelection; |
| 266 } | 266 } |
| 267 | 267 |
| 268 } // namespace blink | 268 } // namespace blink |
| OLD | NEW |