summaryrefslogtreecommitdiffstats
path: root/Source/WebKit/android/jni/WebViewCore.cpp
diff options
context:
space:
mode:
authorGeorge Mount <mount@google.com>2012-05-15 07:30:46 -0700
committerGeorge Mount <mount@google.com>2012-05-15 12:39:16 -0700
commite47f743261938b674d8871217236c03420bd2020 (patch)
tree3c5c9b9a271192e0770c2ba039043693e3eee2eb /Source/WebKit/android/jni/WebViewCore.cpp
parent8001929cfbff025063aab7bd129277b24cf3a9ff (diff)
downloadexternal_webkit-e47f743261938b674d8871217236c03420bd2020.zip
external_webkit-e47f743261938b674d8871217236c03420bd2020.tar.gz
external_webkit-e47f743261938b674d8871217236c03420bd2020.tar.bz2
Only start or end selection with non-empty text fields.
Bug 6496951 Change-Id: I5ea68aebe4c3652eae49b20d4c07418725190549
Diffstat (limited to 'Source/WebKit/android/jni/WebViewCore.cpp')
-rw-r--r--Source/WebKit/android/jni/WebViewCore.cpp35
1 files changed, 34 insertions, 1 deletions
diff --git a/Source/WebKit/android/jni/WebViewCore.cpp b/Source/WebKit/android/jni/WebViewCore.cpp
index ede8b69..84b605a 100644
--- a/Source/WebKit/android/jni/WebViewCore.cpp
+++ b/Source/WebKit/android/jni/WebViewCore.cpp
@@ -1685,6 +1685,35 @@ IntPoint WebViewCore::convertGlobalContentToFrameContent(const IntPoint& point,
return IntPoint(point.x() + frameOffset.x(), point.y() + frameOffset.y());
}
+Position WebViewCore::trimSelectionPosition(const Position &start, const Position& stop)
+{
+ int direction = comparePositions(start, stop);
+ if (direction == 0)
+ return start;
+ bool forward = direction < 0;
+ EAffinity affinity = forward ? DOWNSTREAM : UPSTREAM;
+ bool move;
+ Position pos = start;
+ bool movedTooFar = false;
+ do {
+ move = true;
+ Node* node = pos.anchorNode();
+ if (node && node->isTextNode() && node->renderer()) {
+ RenderText *textRenderer = toRenderText(node->renderer());
+ move = !textRenderer->textLength();
+ }
+ if (move) {
+ Position nextPos = forward ? pos.next() : pos.previous();
+ movedTooFar = nextPos.isNull() || pos == nextPos
+ || ((comparePositions(nextPos, stop) < 0) != forward);
+ pos = nextPos;
+ }
+ } while (move && !movedTooFar);
+ if (movedTooFar)
+ pos = stop;
+ return pos;
+}
+
void WebViewCore::selectText(int startX, int startY, int endX, int endY)
{
SelectionController* sc = focusedFrame()->selection();
@@ -1721,7 +1750,11 @@ void WebViewCore::selectText(int startX, int startY, int endX, int endY)
endPosition = prevEndPosition;
}
- VisibleSelection selection(startPosition, endPosition);
+ Position start = startPosition.deepEquivalent();
+ Position end = endPosition.deepEquivalent();
+ start = trimSelectionPosition(start, end);
+ end = trimSelectionPosition(end, start);
+ VisibleSelection selection(start, end);
// Only allow changes between caret positions or to text selection.
bool selectChangeAllowed = (!selection.isCaret() || sc->isCaret());
if (selectChangeAllowed && sc->shouldChangeSelection(selection))