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

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

Issue 2201853002: Blink handle selection handle visibility (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed contextual search test function Created 4 years, 2 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
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 f914c37182f54a58dc10ae16974d1319aab28bab..27df500fb2ac45fd8bc2024351e4c7ece92b6047 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,6 +148,20 @@ 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, true);
+ return false;
+ }
+ }
+
if (extendSelection && !newSelection.isNone()) {
const VisibleSelectionInFlatTree selectionInUserSelectAll(
expandSelectionToRespectUserSelectAll(innerNode,
@@ -195,10 +199,20 @@ bool SelectionController::handleMousePressEventSingleClick(
innerNode, createVisibleSelection(visiblePos));
}
+ bool isHandleVisible = false;
+ if (newSelection.isContentEditable()) {
+ bool isTextBoxEmpty =
+ VisibleSelection::selectionFromContentsOfNode(innerNode).isCaret();
+ bool notLeftClick = event.event().pointerProperties().button !=
+ 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);
return false;
}
@@ -326,7 +340,8 @@ void SelectionController::updateSelectionForMouseDrag(
bool SelectionController::updateSelectionForMouseDownDispatchingSelectStart(
Node* targetNode,
const VisibleSelectionInFlatTree& selection,
- TextGranularity granularity) {
+ TextGranularity granularity,
+ bool isHandleVisible) {
if (targetNode && targetNode->layoutObject() &&
!targetNode->layoutObject()->isSelectable())
return false;
@@ -348,7 +363,9 @@ bool SelectionController::updateSelectionForMouseDownDispatchingSelectStart(
m_selectionState = SelectionState::PlacedCaret;
}
- this->selection().setNonDirectionalSelectionIfNeeded(selection, granularity);
+ this->selection().setNonDirectionalSelectionIfNeeded(
+ selection, granularity, FrameSelection::DoNotAdjustEndpoints,
+ isHandleVisible);
return true;
}
@@ -379,6 +396,7 @@ void SelectionController::selectClosestWordFromHitTestResult(
newSelection.expandUsingGranularity(WordGranularity);
}
+ bool isHandleVisible = false;
if (selectInputEventType == SelectInputEventType::Touch) {
// If node doesn't have text except space, tab or line break, do not
// select that 'empty' area.
@@ -396,6 +414,7 @@ void SelectionController::selectClosestWordFromHitTestResult(
newSelection.rootEditableElement())
.deepEquivalent())
return;
+ isHandleVisible = true;
}
if (appendTrailingWhitespace == AppendTrailingWhitespace::ShouldAppend &&
@@ -404,7 +423,7 @@ void SelectionController::selectClosestWordFromHitTestResult(
updateSelectionForMouseDownDispatchingSelectStart(
innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection),
- WordGranularity);
+ WordGranularity, isHandleVisible);
}
void SelectionController::selectClosestMisspellingFromHitTestResult(
@@ -554,9 +573,11 @@ bool SelectionController::handleMousePressEventTripleClick(
newSelection.expandUsingGranularity(ParagraphGranularity);
}
+ bool isHandleVisible = event.event().fromTouch() && newSelection.isRange();
+
return updateSelectionForMouseDownDispatchingSelectStart(
innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection),
- ParagraphGranularity);
+ ParagraphGranularity, isHandleVisible);
}
void SelectionController::handleMousePressEvent(
@@ -750,7 +771,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
@@ -779,8 +800,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

Powered by Google App Engine
This is Rietveld 408576698