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

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

Issue 1845193002: Fix long-press image selection inside editables. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Bring back containsOnlyWhitespace to address test flake Created 4 years, 8 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 e26e1732d57ef92bb4111b2507ed4856c894f2d5..24142c1d8ddb0ec5394828ea68f6d79d2df23ce7 100644
--- a/third_party/WebKit/Source/core/editing/SelectionController.cpp
+++ b/third_party/WebKit/Source/core/editing/SelectionController.cpp
@@ -287,7 +287,7 @@ bool SelectionController::updateSelectionForMouseDownDispatchingSelectStart(Node
return true;
}
-void SelectionController::selectClosestWordFromHitTestResult(const HitTestResult& result, AppendTrailingWhitespace appendTrailingWhitespace)
+void SelectionController::selectClosestWordFromHitTestResult(const HitTestResult& result, AppendTrailingWhitespace appendTrailingWhitespace, bool isLongPress)
aelias_OOO_until_Jul13 2016/04/05 06:48:36 The failing layout tests were due to the OS(ANDROI
{
Node* innerNode = result.innerNode();
VisibleSelectionInFlatTree newSelection;
@@ -295,20 +295,28 @@ void SelectionController::selectClosestWordFromHitTestResult(const HitTestResult
if (!innerNode || !innerNode->layoutObject())
return;
- const VisiblePositionInFlatTree& pos = visiblePositionOfHitTestResult(result);
+ // Special-case image local offset to always be zero, to avoid triggering
+ // LayoutReplaced::positionFromPoint's advancement of the position at the
+ // mid-point of the the image (which was intended for mouse-drag selection
+ // and isn't desirable for long-press).
+ HitTestResult adjustedHitTestResult = result;
+ if (isLongPress && result.image())
+ adjustedHitTestResult.setNodeAndPosition(result.innerNode(), LayoutPoint(0, 0));
+
+ const VisiblePositionInFlatTree& pos = visiblePositionOfHitTestResult(adjustedHitTestResult);
if (pos.isNotNull()) {
newSelection = VisibleSelectionInFlatTree(pos);
newSelection.expandUsingGranularity(WordGranularity);
}
-#if OS(ANDROID)
- // If node doesn't have text except space, tab or line break, do not
- // select that 'empty' area.
- EphemeralRangeInFlatTree range = EphemeralRangeInFlatTree(newSelection.start(), newSelection.end());
- const String& str = plainText(range, TextIteratorDefaultBehavior);
- if (str.isEmpty() || str.simplifyWhiteSpace().containsOnlyWhitespace())
- return;
-#endif
+ if (isLongPress) {
+ // If node doesn't have text except space, tab or line break, do not
+ // select that 'empty' area.
+ EphemeralRangeInFlatTree range(newSelection.start(), newSelection.end());
+ const String& str = plainText(range, TextIteratorEmitsObjectReplacementCharacter);
+ if (str.isEmpty() || str.simplifyWhiteSpace().containsOnlyWhitespace())
+ return;
+ }
if (appendTrailingWhitespace == AppendTrailingWhitespace::ShouldAppend && newSelection.isRange())
newSelection.appendTrailingWhitespace();
@@ -540,15 +548,11 @@ bool SelectionController::handleGestureLongPress(const PlatformGestureEvent& ges
return false;
Node* innerNode = hitTestResult.innerNode();
-#if OS(ANDROID)
bool innerNodeIsSelectable = innerNode && (innerNode->isContentEditable() || innerNode->isTextNode() || innerNode->canStartSelection());
-#else
- bool innerNodeIsSelectable = innerNode && (innerNode->isContentEditable() || innerNode->isTextNode());
-#endif
if (!innerNodeIsSelectable)
return false;
- selectClosestWordFromHitTestResult(hitTestResult, AppendTrailingWhitespace::DontAppend);
+ selectClosestWordFromHitTestResult(hitTestResult, AppendTrailingWhitespace::DontAppend, true);
yosin_UTC9 2016/04/05 07:27:46 Could you introduce enum class rather than |bool|
aelias_OOO_until_Jul13 2016/04/05 08:26:53 Done.
return selection().isRange();
}
« no previous file with comments | « third_party/WebKit/Source/core/editing/SelectionController.h ('k') | third_party/WebKit/Source/web/tests/WebViewTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698