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 8d1af8b3f8b07421eac69d352524ca13405bf9d4..0f1516ea1128b8ad3346ea69f11d49413d8c6963 100644 |
| --- a/third_party/WebKit/Source/core/editing/SelectionController.cpp |
| +++ b/third_party/WebKit/Source/core/editing/SelectionController.cpp |
| @@ -167,16 +167,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; |
| - } |
| - } |
| - |
| const VisiblePositionInFlatTree& visibleHitPos = |
| visiblePositionOfHitTestResult(event.hitTestResult()); |
| const VisiblePositionInFlatTree& visiblePos = |
| @@ -187,6 +177,24 @@ bool SelectionController::handleMousePressEventSingleClick( |
| const VisibleSelectionInFlatTree& selection = |
| this->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()); |
|
yosin_UTC9
2017/01/13 01:55:18
nit: s/LayoutPoint/const LayoutPoint/
to avoid cop
amaralp
2017/01/13 23:52:51
Done.
|
| + if (!extendSelection && this->selection().contains(vPoint)) { |
| + m_mouseDownWasSingleClickInSelection = true; |
| + if (!event.event().fromTouch()) |
| + return false; |
| + |
| + if (!this->selection().isHandleVisible()) { |
| + updateSelectionForMouseDownDispatchingSelectStart( |
| + innerNode, selection, CharacterGranularity, |
| + HandleVisibility::Visible); |
| + return false; |
| + } |
| + } |
| + } |
| + |
| if (extendSelection && !selection.isNone()) { |
| // Note: "fast/events/shift-click-user-select-none.html" makes |
| // |pos.isNull()| true. |
| @@ -211,22 +219,37 @@ bool SelectionController::handleMousePressEventSingleClick( |
| updateSelectionForMouseDownDispatchingSelectStart( |
| innerNode, createVisibleSelection(builder.build()), |
| - this->selection().granularity()); |
| + this->selection().granularity(), HandleVisibility::NotVisible); |
| return false; |
| } |
| if (m_selectionState == SelectionState::ExtendedSelection) { |
| - updateSelectionForMouseDownDispatchingSelectStart(innerNode, selection, |
| - CharacterGranularity); |
| + updateSelectionForMouseDownDispatchingSelectStart( |
| + innerNode, selection, CharacterGranularity, |
| + HandleVisibility::NotVisible); |
| return false; |
| } |
| if (visiblePos.isNull()) { |
| updateSelectionForMouseDownDispatchingSelectStart( |
| - innerNode, VisibleSelectionInFlatTree(), CharacterGranularity); |
| + innerNode, VisibleSelectionInFlatTree(), CharacterGranularity, |
| + HandleVisibility::NotVisible); |
| return false; |
| } |
| + bool isHandleVisible = false; |
| + if (hasEditableStyle(*innerNode)) { |
| + const bool isTextBoxEmpty = |
| + createVisibleSelection(SelectionInFlatTree::Builder() |
| + .selectAllChildren(*innerNode) |
| + .build()) |
| + .isCaret(); |
| + const bool notLeftClick = event.event().pointerProperties().button != |
| + WebPointerProperties::Button::Left; |
| + if (!isTextBoxEmpty || notLeftClick) |
| + isHandleVisible = event.event().fromTouch(); |
| + } |
| + |
| updateSelectionForMouseDownDispatchingSelectStart( |
| innerNode, |
| expandSelectionToRespectUserSelectAll( |
| @@ -234,7 +257,8 @@ bool SelectionController::handleMousePressEventSingleClick( |
| SelectionInFlatTree::Builder() |
| .collapse(visiblePos.toPositionWithAffinity()) |
| .build())), |
| - CharacterGranularity); |
| + CharacterGranularity, isHandleVisible ? HandleVisibility::Visible |
| + : HandleVisibility::NotVisible); |
| return false; |
| } |
| @@ -364,13 +388,15 @@ void SelectionController::updateSelectionForMouseDrag( |
| } |
| setNonDirectionalSelectionIfNeeded(newSelection, selection().granularity(), |
| - AdjustEndpointsAtBidiBoundary); |
| + AdjustEndpointsAtBidiBoundary, |
| + HandleVisibility::NotVisible); |
| } |
| bool SelectionController::updateSelectionForMouseDownDispatchingSelectStart( |
| Node* targetNode, |
| const VisibleSelectionInFlatTree& selection, |
| - TextGranularity granularity) { |
| + TextGranularity granularity, |
| + HandleVisibility handleVisibility) { |
| if (targetNode && targetNode->layoutObject() && |
| !targetNode->layoutObject()->isSelectable()) |
| return false; |
| @@ -393,7 +419,7 @@ bool SelectionController::updateSelectionForMouseDownDispatchingSelectStart( |
| } |
| setNonDirectionalSelectionIfNeeded(selection, granularity, |
| - DoNotAdjustEndpoints); |
| + DoNotAdjustEndpoints, handleVisibility); |
| return true; |
| } |
| @@ -427,6 +453,7 @@ bool SelectionController::selectClosestWordFromHitTestResult( |
| .build()); |
| } |
| + HandleVisibility visibility = HandleVisibility::NotVisible; |
| if (selectInputEventType == SelectInputEventType::Touch) { |
| // If node doesn't have text except space, tab or line break, do not |
| // select that 'empty' area. |
| @@ -444,6 +471,8 @@ bool SelectionController::selectClosestWordFromHitTestResult( |
| newSelection.rootEditableElement()) |
| .deepEquivalent()) |
| return false; |
| + |
| + visibility = HandleVisibility::Visible; |
| } |
| if (appendTrailingWhitespace == AppendTrailingWhitespace::ShouldAppend) |
| @@ -451,7 +480,7 @@ bool SelectionController::selectClosestWordFromHitTestResult( |
| return updateSelectionForMouseDownDispatchingSelectStart( |
| innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), |
| - WordGranularity); |
| + WordGranularity, visibility); |
| } |
| void SelectionController::selectClosestMisspellingFromHitTestResult( |
| @@ -485,7 +514,7 @@ void SelectionController::selectClosestMisspellingFromHitTestResult( |
| updateSelectionForMouseDownDispatchingSelectStart( |
| innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), |
| - WordGranularity); |
| + WordGranularity, HandleVisibility::NotVisible); |
| } |
| void SelectionController::selectClosestWordFromMouseEvent( |
| @@ -542,7 +571,7 @@ void SelectionController::selectClosestWordOrLinkFromMouseEvent( |
| updateSelectionForMouseDownDispatchingSelectStart( |
| innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), |
| - WordGranularity); |
| + WordGranularity, HandleVisibility::NotVisible); |
| } |
| // TODO(xiaochengh): We should not use reference to return value. |
| @@ -600,7 +629,8 @@ static void adjustEndpointsAtBidiBoundary( |
| void SelectionController::setNonDirectionalSelectionIfNeeded( |
| const VisibleSelectionInFlatTree& passedNewSelection, |
| TextGranularity granularity, |
| - EndPointsAdjustmentMode endpointsAdjustmentMode) { |
| + EndPointsAdjustmentMode endpointsAdjustmentMode, |
| + HandleVisibility handleVisibility) { |
| VisibleSelectionInFlatTree newSelection = passedNewSelection; |
| bool isDirectional = |
| m_frame->editor().behavior().shouldConsiderSelectionAsDirectional() || |
| @@ -640,11 +670,16 @@ void SelectionController::setNonDirectionalSelectionIfNeeded( |
| // Adjusting base and extent will make newSelection always directional |
| newSelection.setIsDirectional(isDirectional); |
| - if (selection().visibleSelection<EditingInFlatTreeStrategy>() == newSelection) |
| + const bool isHandleVisible = handleVisibility == HandleVisibility::Visible; |
| + if (selection().visibleSelection<EditingInFlatTreeStrategy>() == |
| + newSelection && |
| + selection().isHandleVisible() == isHandleVisible) |
| return; |
| - const FrameSelection::SetSelectionOptions options = |
| + FrameSelection::SetSelectionOptions options = |
|
yosin_UTC9
2017/01/13 01:55:18
nit: How about below?
const FrameSelection::SetSe
amaralp
2017/01/13 23:52:52
Done.
|
| FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle; |
| + if (isHandleVisible) |
| + options |= FrameSelection::HandleVisible; |
| selection().setSelection(newSelection, options, CursorAlignOnScroll::IfNeeded, |
| granularity); |
| } |
| @@ -667,7 +702,7 @@ void SelectionController::setCaretAtHitTestResult( |
| SelectionInFlatTree::Builder() |
| .collapse(visiblePos.toPositionWithAffinity()) |
| .build())), |
| - CharacterGranularity); |
| + CharacterGranularity, HandleVisibility::Visible); |
| } |
| bool SelectionController::handleMousePressEventDoubleClick( |
| @@ -730,9 +765,12 @@ bool SelectionController::handleMousePressEventTripleClick( |
| .build()); |
| } |
| + bool isHandleVisible = event.event().fromTouch() && newSelection.isRange(); |
|
yosin_UTC9
2017/01/13 01:55:18
nit: s/bool/const bool/
amaralp
2017/01/13 23:52:51
Done.
|
| + |
| return updateSelectionForMouseDownDispatchingSelectStart( |
| innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection), |
| - ParagraphGranularity); |
| + ParagraphGranularity, isHandleVisible ? HandleVisibility::Visible |
| + : HandleVisibility::NotVisible); |
| } |
| void SelectionController::handleMousePressEvent( |