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

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: Disable Mac-only failure (Mac doesn't support long-press anyway) 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..baefa5f78888ec35caafd0334d0bd4f3a1eb44e5 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, SelectInputEventType selectInputEventType)
{
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 (selectInputEventType == SelectInputEventType::GestureLongPress && 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 (selectInputEventType == SelectInputEventType::GestureLongPress) {
+ // 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();
@@ -349,7 +357,7 @@ void SelectionController::selectClosestWordFromMouseEvent(const MouseEventWithHi
AppendTrailingWhitespace appendTrailingWhitespace = (result.event().clickCount() == 2 && m_frame->editor().isSelectTrailingWhitespaceEnabled()) ? AppendTrailingWhitespace::ShouldAppend : AppendTrailingWhitespace::DontAppend;
- return selectClosestWordFromHitTestResult(result.hitTestResult(), appendTrailingWhitespace);
+ return selectClosestWordFromHitTestResult(result.hitTestResult(), appendTrailingWhitespace, SelectInputEventType::Mouse);
}
void SelectionController::selectClosestMisspellingFromMouseEvent(const MouseEventWithHitTestResults& result)
@@ -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, SelectInputEventType::GestureLongPress);
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