Index: third_party/WebKit/Source/core/editing/SelectionAdjuster.cpp |
diff --git a/third_party/WebKit/Source/core/editing/SelectionAdjuster.cpp b/third_party/WebKit/Source/core/editing/SelectionAdjuster.cpp |
index 4d77b449cacd339be95c2410fa4a0a6cd2836a65..b31245be7e826d1264dd88e5979f50d4f26e96ac 100644 |
--- a/third_party/WebKit/Source/core/editing/SelectionAdjuster.cpp |
+++ b/third_party/WebKit/Source/core/editing/SelectionAdjuster.cpp |
@@ -30,6 +30,8 @@ |
namespace blink { |
+// TODO(xiaochengh): Move everything to VisibleSelection.cpp. |
+ |
namespace { |
Node* enclosingShadowHost(Node* node) { |
@@ -153,57 +155,52 @@ Position adjustPositionForStart(const Position& currentPosition, |
} // namespace |
-void SelectionAdjuster::adjustSelectionToAvoidCrossingShadowBoundaries( |
- VisibleSelection* selection) { |
+std::pair<AdjustDirection, Position> adjustmentToAvoidCrossingShadowBoundaries( |
+ const VisibleSelection& selection) { |
// Note: |m_selectionType| isn't computed yet. |
- DCHECK(selection->base().isNotNull()); |
- DCHECK(selection->extent().isNotNull()); |
- DCHECK(selection->start().isNotNull()); |
- DCHECK(selection->end().isNotNull()); |
+ DCHECK(selection.base().isNotNull()); |
+ DCHECK(selection.extent().isNotNull()); |
+ DCHECK(selection.start().isNotNull()); |
+ DCHECK(selection.end().isNotNull()); |
// TODO(hajimehoshi): Checking treeScope is wrong when a node is |
// distributed, but we leave it as it is for backward compatibility. |
- if (selection->start().anchorNode()->treeScope() == |
- selection->end().anchorNode()->treeScope()) |
- return; |
+ if (selection.start().anchorNode()->treeScope() == |
+ selection.end().anchorNode()->treeScope()) |
+ return std::make_pair(AdjustDirection::kAdjustNone, Position()); |
- if (selection->isBaseFirst()) { |
+ if (selection.isBaseFirst()) { |
const Position& newEnd = adjustPositionForEnd( |
- selection->end(), selection->start().computeContainerNode()); |
- selection->m_extent = newEnd; |
- selection->m_end = newEnd; |
- return; |
+ selection.end(), selection.start().computeContainerNode()); |
+ return std::make_pair(AdjustDirection::kAdjustEnd, newEnd); |
} |
const Position& newStart = adjustPositionForStart( |
- selection->start(), selection->end().computeContainerNode()); |
- selection->m_extent = newStart; |
- selection->m_start = newStart; |
+ selection.start(), selection.end().computeContainerNode()); |
+ return std::make_pair(AdjustDirection::kAdjustStart, newStart); |
} |
// This function is called twice. The first is called when |m_start| and |m_end| |
// or |m_extent| are same, and the second when |m_start| and |m_end| are changed |
// after downstream/upstream. |
-void SelectionAdjuster::adjustSelectionToAvoidCrossingShadowBoundaries( |
- VisibleSelectionInFlatTree* selection) { |
- Node* const shadowHostStart = enclosingShadowHostForStart(selection->start()); |
- Node* const shadowHostEnd = enclosingShadowHostForEnd(selection->end()); |
+std::pair<AdjustDirection, PositionInFlatTree> |
+adjustmentToAvoidCrossingShadowBoundaries( |
+ const VisibleSelectionInFlatTree& selection) { |
+ Node* const shadowHostStart = enclosingShadowHostForStart(selection.start()); |
+ Node* const shadowHostEnd = enclosingShadowHostForEnd(selection.end()); |
if (shadowHostStart == shadowHostEnd) |
- return; |
+ return std::make_pair(AdjustDirection::kAdjustNone, PositionInFlatTree()); |
- if (selection->isBaseFirst()) { |
+ if (selection.isBaseFirst()) { |
Node* const shadowHost = shadowHostStart ? shadowHostStart : shadowHostEnd; |
const PositionInFlatTree& newEnd = |
- adjustPositionInFlatTreeForEnd(selection->end(), shadowHost); |
- selection->m_extent = newEnd; |
- selection->m_end = newEnd; |
- return; |
+ adjustPositionInFlatTreeForEnd(selection.end(), shadowHost); |
+ return std::make_pair(AdjustDirection::kAdjustEnd, newEnd); |
} |
Node* const shadowHost = shadowHostEnd ? shadowHostEnd : shadowHostStart; |
const PositionInFlatTree& newStart = |
- adjustPositionInFlatTreeForStart(selection->start(), shadowHost); |
- selection->m_extent = newStart; |
- selection->m_start = newStart; |
+ adjustPositionInFlatTreeForStart(selection.start(), shadowHost); |
+ return std::make_pair(AdjustDirection::kAdjustStart, newStart); |
} |
} // namespace blink |