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 7cadac5b0f79ad42fb52330e9cd4746ed0996b3a..49f9dfdd5e47e594c6cee8e0f5e8964962e9cc5d 100644 |
--- a/third_party/WebKit/Source/core/editing/SelectionController.cpp |
+++ b/third_party/WebKit/Source/core/editing/SelectionController.cpp |
@@ -137,16 +137,6 @@ bool SelectionController::handleMousePressEventSingleClick( |
// link or image. |
bool extendSelection = isExtendingSelection(event); |
- // Don't restart the selection when the mouse is pressed on an |
- // existing selection so we can allow for text dragging. |
- if (FrameView* view = m_frame->view()) { |
- LayoutPoint vPoint = view->rootFrameToContents(event.event().position()); |
- if (!extendSelection && selection().contains(vPoint)) { |
- m_mouseDownWasSingleClickInSelection = true; |
- return false; |
- } |
- } |
- |
VisiblePositionInFlatTree visiblePos = |
visiblePositionOfHitTestResult(event.hitTestResult()); |
if (visiblePos.isNull()) |
@@ -158,9 +148,21 @@ bool SelectionController::handleMousePressEventSingleClick( |
selection().visibleSelection<EditingInFlatTreeStrategy>(); |
TextGranularity granularity = CharacterGranularity; |
+ // Don't restart the selection when the mouse is pressed on an |
+ // existing selection so we can allow for text dragging. |
+ if (!extendSelection && selection().contains(event.hitTestResult())) { |
+ m_mouseDownWasSingleClickInSelection = true; |
+ if (!event.event().fromTouch()) |
+ return false; |
+ |
+ if (!selection().isHandleVisible()) { |
+ updateSelectionForMouseDownDispatchingSelectStart( |
+ innerNode, newSelection, granularity, HandleVisibility::Visible); |
+ return false; |
+ } |
+ } |
+ |
if (extendSelection && !newSelection.isNone()) { |
- // Note: "fast/events/shift-click-user-select-none.html" makes |
- // |pos.isNull()| true. |
SelectionInFlatTree::Builder builder; |
if (pos.isNotNull()) |
builder.collapse(pos); |
@@ -206,10 +208,22 @@ bool SelectionController::handleMousePressEventSingleClick( |
} |
} |
+ bool isHandleVisible = false; |
+ if (newSelection.isContentEditable()) { |
+ bool isTextBoxEmpty = |
+ VisibleSelection::selectionFromContentsOfNode(innerNode).isCaret(); |
yosin_UTC9
2016/10/19 06:33:05
nit: VisibleSelection::selectionFromContentsOfNode
amaralp
2016/10/21 03:47:18
Done.
|
+ bool notLeftClick = event.event().pointerProperties().button != |
yosin_UTC9
2016/10/19 06:33:05
nit: s/bool/const bool/
amaralp
2016/10/21 03:47:18
Done.
|
+ WebPointerProperties::Button::Left; |
+ if (!isTextBoxEmpty || notLeftClick) |
+ isHandleVisible = event.event().fromTouch(); |
+ } |
+ |
// Updating the selection is considered side-effect of the event and so it |
// doesn't impact the handled state. |
- updateSelectionForMouseDownDispatchingSelectStart(innerNode, newSelection, |
- granularity); |
+ updateSelectionForMouseDownDispatchingSelectStart( |
+ innerNode, newSelection, granularity, isHandleVisible |
+ ? HandleVisibility::Visible |
+ : HandleVisibility::NotVisible); |
return false; |
} |
@@ -339,7 +353,8 @@ void SelectionController::updateSelectionForMouseDrag( |
bool SelectionController::updateSelectionForMouseDownDispatchingSelectStart( |
Node* targetNode, |
const VisibleSelectionInFlatTree& selection, |
- TextGranularity granularity) { |
+ TextGranularity granularity, |
+ HandleVisibility visibility) { |
if (targetNode && targetNode->layoutObject() && |
!targetNode->layoutObject()->isSelectable()) |
return false; |
@@ -361,7 +376,8 @@ bool SelectionController::updateSelectionForMouseDownDispatchingSelectStart( |
m_selectionState = SelectionState::PlacedCaret; |
} |
- this->selection().setNonDirectionalSelectionIfNeeded(selection, granularity); |
+ this->selection().setNonDirectionalSelectionIfNeeded( |
+ selection, granularity, FrameSelection::DoNotAdjustEndpoints, visibility); |
return true; |
} |
@@ -394,6 +410,7 @@ void SelectionController::selectClosestWordFromHitTestResult( |
newSelection.expandUsingGranularity(WordGranularity); |
} |
+ HandleVisibility visibility = HandleVisibility::NotVisible; |
yosin_UTC9
2016/10/19 06:33:05
Better to use |handleVisibility|, name |visibility
amaralp
2016/10/21 03:47:18
Done.
|
if (selectInputEventType == SelectInputEventType::Touch) { |
// If node doesn't have text except space, tab or line break, do not |
// select that 'empty' area. |
@@ -411,6 +428,7 @@ void SelectionController::selectClosestWordFromHitTestResult( |
newSelection.rootEditableElement()) |
.deepEquivalent()) |
return; |
+ visibility = HandleVisibility::Visible; |
} |
if (appendTrailingWhitespace == AppendTrailingWhitespace::ShouldAppend && |
@@ -419,7 +437,7 @@ void SelectionController::selectClosestWordFromHitTestResult( |
updateSelectionForMouseDownDispatchingSelectStart( |
innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), |
- WordGranularity); |
+ WordGranularity, visibility); |
} |
void SelectionController::selectClosestMisspellingFromHitTestResult( |
@@ -453,7 +471,7 @@ void SelectionController::selectClosestMisspellingFromHitTestResult( |
updateSelectionForMouseDownDispatchingSelectStart( |
innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), |
- WordGranularity); |
+ WordGranularity, HandleVisibility::NotVisible); |
} |
void SelectionController::selectClosestWordFromMouseEvent( |
@@ -509,7 +527,7 @@ void SelectionController::selectClosestWordOrLinkFromMouseEvent( |
updateSelectionForMouseDownDispatchingSelectStart( |
innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), |
- WordGranularity); |
+ WordGranularity, HandleVisibility::NotVisible); |
} |
bool SelectionController::handleMousePressEventDoubleClick( |
@@ -571,9 +589,12 @@ bool SelectionController::handleMousePressEventTripleClick( |
newSelection.expandUsingGranularity(ParagraphGranularity); |
} |
+ bool isHandleVisible = event.event().fromTouch() && newSelection.isRange(); |
+ |
return updateSelectionForMouseDownDispatchingSelectStart( |
innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), |
- ParagraphGranularity); |
+ ParagraphGranularity, isHandleVisible ? HandleVisibility::Visible |
+ : HandleVisibility::NotVisible); |
} |
void SelectionController::handleMousePressEvent( |
@@ -771,7 +792,7 @@ void SelectionController::sendContextMenuEvent( |
const LayoutPoint& position) { |
if (!selection().isAvailable()) |
return; |
- if (selection().contains(position) || mev.scrollbar() || |
+ if (selection().contains(mev.hitTestResult()) || mev.scrollbar() || |
// FIXME: In the editable case, word selection sometimes selects content |
// that isn't underneath the mouse. |
// If the selection is non-editable, we do word selection to make it |
@@ -800,8 +821,7 @@ void SelectionController::passMousePressEventToSubframe( |
// greyed out even though we're clicking on the selection. This looks |
// really strange (having the whole frame be greyed out), so we deselect the |
// selection. |
- IntPoint p = m_frame->view()->rootFrameToContents(mev.event().position()); |
- if (!selection().contains(p)) |
+ if (!selection().contains(mev.hitTestResult())) |
return; |
// TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets |