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

Unified Diff: third_party/WebKit/Source/core/editing/SelectionController.cpp

Issue 2657703003: Clean up updateSelectionIfSelectAll using SelectionBuilder (Closed)
Patch Set: update Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/editing/SelectionController.cpp
diff --git a/third_party/WebKit/Source/core/editing/SelectionController.cpp b/third_party/WebKit/Source/core/editing/SelectionController.cpp
index cb993f2721b79ec2066926ee84780d34ba4bb27a..cc60d8684f3e548ab29216599add7571e2f9d122 100644
--- a/third_party/WebKit/Source/core/editing/SelectionController.cpp
+++ b/third_party/WebKit/Source/core/editing/SelectionController.cpp
@@ -278,8 +278,8 @@ static bool targetPositionIsBeforeDragStartPosition(
return targetPosition.compareTo(dragStartPosition) < 0;
}
-static void updateSelectionIfSelectAll(
- VisibleSelectionInFlatTree& newSelection,
+static SelectionInFlatTree applySelectAll(
+ const VisibleSelectionInFlatTree& newSelection,
Node* mousePressNode,
const LayoutPoint& dragStartPoint,
Node* target,
@@ -292,42 +292,39 @@ static void updateSelectionIfSelectAll(
if (rootUserSelectAllForMousePressNode &&
rootUserSelectAllForMousePressNode == rootUserSelectAllForTarget) {
- newSelection.setBase(mostBackwardCaretPosition(
- PositionInFlatTree::beforeNode(rootUserSelectAllForMousePressNode),
- CanCrossEditingBoundary));
- newSelection.setExtent(mostForwardCaretPosition(
- PositionInFlatTree::afterNode(rootUserSelectAllForMousePressNode),
- CanCrossEditingBoundary));
- return;
+ return SelectionInFlatTree::Builder()
+ .setBaseAndExtent(
+ PositionInFlatTree::beforeNode(rootUserSelectAllForMousePressNode),
+ PositionInFlatTree::afterNode(rootUserSelectAllForMousePressNode))
+ .build();
}
+ SelectionInFlatTree::Builder builder;
// Reset base for user select all when base is inside user-select-all area
// and extent < base.
- if (rootUserSelectAllForMousePressNode) {
- if (targetPositionIsBeforeDragStartPosition(mousePressNode, dragStartPoint,
- target, hitTestPoint)) {
- newSelection.setBase(mostForwardCaretPosition(
- PositionInFlatTree::afterNode(rootUserSelectAllForMousePressNode),
- CanCrossEditingBoundary));
- }
+ if (rootUserSelectAllForMousePressNode &&
+ targetPositionIsBeforeDragStartPosition(mousePressNode, dragStartPoint,
+ target, hitTestPoint)) {
+ builder.collapse(
+ PositionInFlatTree::afterNode(rootUserSelectAllForMousePressNode));
+ } else {
+ builder.collapse(newSelection.base());
}
if (rootUserSelectAllForTarget && mousePressNode->layoutObject()) {
if (targetPositionIsBeforeDragStartPosition(mousePressNode, dragStartPoint,
target, hitTestPoint)) {
- newSelection.setExtent(mostBackwardCaretPosition(
- PositionInFlatTree::beforeNode(rootUserSelectAllForTarget),
- CanCrossEditingBoundary));
- return;
+ builder.extend(
+ PositionInFlatTree::beforeNode(rootUserSelectAllForTarget));
+ return builder.build();
}
- newSelection.setExtent(mostForwardCaretPosition(
- PositionInFlatTree::afterNode(rootUserSelectAllForTarget),
- CanCrossEditingBoundary));
- return;
+ builder.extend(PositionInFlatTree::afterNode(rootUserSelectAllForTarget));
+ return builder.build();
}
- newSelection.setExtent(targetPosition);
+ builder.extend(targetPosition.deepEquivalent());
+ return builder.build();
}
void SelectionController::updateSelectionForMouseDrag(
@@ -390,8 +387,9 @@ void SelectionController::updateSelectionForMouseDrag(
newSelection = createVisibleSelection(builder.build());
}
- updateSelectionIfSelectAll(newSelection, mousePressNode, dragStartPos, target,
- hitTestResult.localPoint(), targetPosition);
+ newSelection = createVisibleSelection(
+ applySelectAll(newSelection, mousePressNode, dragStartPos, target,
+ hitTestResult.localPoint(), targetPosition));
// TODO(yosin): We should have |newBase| and |newExtent| instead of
// |newSelection|.
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698