Chromium Code Reviews| 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 b6c80b53489d732acb45ea5dec59c1417ab72efc..be6aa2733de162b878087f6c4edde2a10a8b9984 100644 |
| --- a/third_party/WebKit/Source/core/editing/SelectionController.cpp |
| +++ b/third_party/WebKit/Source/core/editing/SelectionController.cpp |
| @@ -137,14 +137,15 @@ bool SelectionController::handleMousePressEventSingleClick( |
| // link or image. |
| bool extendSelection = isExtendingSelection(event); |
| + VisibleSelectionInFlatTree newSelection = |
| + selection().visibleSelection<EditingInFlatTreeStrategy>(); |
| + |
| // 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; |
| + if (!extendSelection && selection().contains(event.hitTestResult())) { |
| + m_mouseDownWasSingleClickInSelection = true; |
| + if (!event.event().fromTouch()) |
| return false; |
| - } |
| } |
| VisiblePositionInFlatTree visiblePos = |
| @@ -154,11 +155,11 @@ bool SelectionController::handleMousePressEventSingleClick( |
| PositionInFlatTree::firstPositionInOrBeforeNode(innerNode)); |
| PositionInFlatTree pos = visiblePos.deepEquivalent(); |
| - VisibleSelectionInFlatTree newSelection = |
| - selection().visibleSelection<EditingInFlatTreeStrategy>(); |
| TextGranularity granularity = CharacterGranularity; |
| - if (extendSelection && !newSelection.isNone()) { |
| + if (mouseDownWasSingleClickInSelection() && !newSelection.isHandleVisible()) { |
| + newSelection.setIsHandleVisible(true); |
| + } else if (extendSelection && !newSelection.isNone()) { |
| const VisibleSelectionInFlatTree selectionInUserSelectAll( |
| expandSelectionToRespectUserSelectAll(innerNode, |
| createVisibleSelection(pos))); |
| @@ -193,6 +194,14 @@ bool SelectionController::handleMousePressEventSingleClick( |
| } else if (m_selectionState != SelectionState::ExtendedSelection) { |
| newSelection = expandSelectionToRespectUserSelectAll( |
| innerNode, createVisibleSelection(visiblePos)); |
| + if (newSelection.isContentEditable()) { |
| + bool isTextBoxEmpty = |
| + VisibleSelection::selectionFromContentsOfNode(innerNode).isCaret(); |
| + bool notLeftClick = event.event().pointerProperties().button != |
| + WebPointerProperties::Button::Left; |
| + if (!isTextBoxEmpty || notLeftClick) |
| + newSelection.setIsHandleVisible(event.event().fromTouch()); |
|
aelias_OOO_until_Jul13
2016/10/07 02:40:20
Can you add a test that handles are *not* created
amaralp
2016/10/14 00:53:07
Added to EventHandlerTest.cpp
|
| + } |
| } |
| // Updating the selection is considered side-effect of the event and so it |
| @@ -396,6 +405,7 @@ void SelectionController::selectClosestWordFromHitTestResult( |
| newSelection.rootEditableElement()) |
| .deepEquivalent()) |
| return; |
| + newSelection.setIsHandleVisible(true); |
| } |
| if (appendTrailingWhitespace == AppendTrailingWhitespace::ShouldAppend && |
| @@ -554,6 +564,9 @@ bool SelectionController::handleMousePressEventTripleClick( |
| newSelection.expandUsingGranularity(ParagraphGranularity); |
| } |
| + newSelection.setIsHandleVisible(event.event().fromTouch() && |
| + newSelection.isRange()); |
| + |
| return updateSelectionForMouseDownDispatchingSelectStart( |
| innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), |
| ParagraphGranularity); |
| @@ -720,6 +733,17 @@ bool SelectionController::handleGestureLongPress( |
| if (!innerNodeIsSelectable) |
| return false; |
| + // If longpress occurs inside of a selection that doesn't have handles |
| + // then we want to show the handes on the entire selection. |
| + VisibleSelectionInFlatTree newSelection = |
| + selection().visibleSelection<EditingInFlatTreeStrategy>(); |
| + if (selection().contains(hitTestResult) && !newSelection.isHandleVisible()) { |
| + newSelection.setIsHandleVisible(true); |
| + selection().setNonDirectionalSelectionIfNeeded(newSelection, |
| + selection().granularity()); |
| + return true; |
| + } |
| + |
| selectClosestWordFromHitTestResult(hitTestResult, |
| AppendTrailingWhitespace::DontAppend, |
| SelectInputEventType::Touch); |
| @@ -753,7 +777,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 |
| @@ -782,8 +806,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 |