Keep LTR selection within the text range.

 Bug 8556162
 The end caret position for LTR text can be one beyond the range
 of the text. This change places the selection region back into
 the text so that the proper text is selected.

Change-Id: I470ee5e3438190aab9f5fb12deca95249d9d887e
diff --git a/Source/WebKit/android/jni/WebViewCore.cpp b/Source/WebKit/android/jni/WebViewCore.cpp
index 497cc9a..6a29823 100644
--- a/Source/WebKit/android/jni/WebViewCore.cpp
+++ b/Source/WebKit/android/jni/WebViewCore.cpp
@@ -4223,6 +4223,14 @@
     VisiblePosition endSelect =  visiblePositionForContentPoint(endX, endY);
     Position start = startSelect.deepEquivalent();
     Position end = endSelect.deepEquivalent();
+    if (isLtr(end)) {
+        // The end caret could be just to the right of the text.
+        endSelect =  visiblePositionForContentPoint(endX - 1, endY);
+        Position newEnd = endSelect.deepEquivalent();
+        if (!newEnd.isNull()) {
+            end = newEnd;
+        }
+    }
     Vector<VisibleSelection> ranges;
     if (!start.isNull() && !end.isNull()) {
         if (comparePositions(start, end) > 0) {