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

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: removed ESTABLISHED/DISSOLVED Created 4 years, 1 month 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 dd384c4b22ef557ecc2b242a9d7dfbf21f46575f..c46c304808dbc598fb85482c42a4e6d4e6abde85 100644
--- a/third_party/WebKit/Source/core/editing/SelectionController.cpp
+++ b/third_party/WebKit/Source/core/editing/SelectionController.cpp
@@ -164,16 +164,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 =
@@ -184,6 +174,21 @@ 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 (!extendSelection && this->selection().contains(event.hitTestResult())) {
+ 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.
@@ -208,22 +213,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(
@@ -231,7 +251,8 @@ bool SelectionController::handleMousePressEventSingleClick(
SelectionInFlatTree::Builder()
.collapse(visiblePos.toPositionWithAffinity())
.build())),
- CharacterGranularity);
+ CharacterGranularity, isHandleVisible ? HandleVisibility::Visible
+ : HandleVisibility::NotVisible);
return false;
}
@@ -361,13 +382,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;
@@ -390,7 +413,7 @@ bool SelectionController::updateSelectionForMouseDownDispatchingSelectStart(
}
setNonDirectionalSelectionIfNeeded(selection, granularity,
- DoNotAdjustEndpoints);
+ DoNotAdjustEndpoints, handleVisibility);
return true;
}
@@ -424,6 +447,7 @@ void 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.
@@ -441,6 +465,7 @@ void SelectionController::selectClosestWordFromHitTestResult(
newSelection.rootEditableElement())
.deepEquivalent())
return;
+ visibility = HandleVisibility::Visible;
}
if (appendTrailingWhitespace == AppendTrailingWhitespace::ShouldAppend)
@@ -448,7 +473,7 @@ void SelectionController::selectClosestWordFromHitTestResult(
updateSelectionForMouseDownDispatchingSelectStart(
innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection),
- WordGranularity);
+ WordGranularity, visibility);
}
void SelectionController::selectClosestMisspellingFromHitTestResult(
@@ -482,7 +507,7 @@ void SelectionController::selectClosestMisspellingFromHitTestResult(
updateSelectionForMouseDownDispatchingSelectStart(
innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection),
- WordGranularity);
+ WordGranularity, HandleVisibility::NotVisible);
}
void SelectionController::selectClosestWordFromMouseEvent(
@@ -539,7 +564,7 @@ void SelectionController::selectClosestWordOrLinkFromMouseEvent(
updateSelectionForMouseDownDispatchingSelectStart(
innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection),
- WordGranularity);
+ WordGranularity, HandleVisibility::NotVisible);
}
// TODO(xiaochengh): We should not use reference to return value.
@@ -597,7 +622,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() ||
@@ -636,11 +662,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 =
FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle;
+ if (isHandleVisible)
+ options |= FrameSelection::HandleVisible;
selection().setSelection(newSelection, options, CursorAlignOnScroll::IfNeeded,
granularity);
}
@@ -705,9 +736,12 @@ bool SelectionController::handleMousePressEventTripleClick(
.build());
}
+ bool isHandleVisible = event.event().fromTouch() && newSelection.isRange();
+
return updateSelectionForMouseDownDispatchingSelectStart(
innerNode, expandSelectionToRespectUserSelectAll(innerNode, newSelection),
- ParagraphGranularity);
+ ParagraphGranularity, isHandleVisible ? HandleVisibility::Visible
+ : HandleVisibility::NotVisible);
}
void SelectionController::handleMousePressEvent(
@@ -909,7 +943,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
@@ -938,8 +972,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