Bug 943071 - When caretPositionFromPoint fails fall back on selectAtPoint apis for selecting text. r=mbrubeck, a=lsblakk
authorJim Mathies <jmathies@mozilla.com>
Thu, 02 Jan 2014 13:05:33 -0600
changeset 175541 22408820aa27fa0c475e2815a554efdd1f9f0c6c
parent 175540 c9fa98eb81031da02958557d3417da0050ba1d8e
child 175542 4ff735ca9563c4e5a6910d953c0bcad16ee5dd42
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmbrubeck, lsblakk
bugs943071
milestone28.0a2
Bug 943071 - When caretPositionFromPoint fails fall back on selectAtPoint apis for selecting text. r=mbrubeck, a=lsblakk
browser/metro/base/content/library/SelectionPrototype.js
--- a/browser/metro/base/content/library/SelectionPrototype.js
+++ b/browser/metro/base/content/library/SelectionPrototype.js
@@ -146,19 +146,21 @@ SelectionPrototype.prototype = {
 
     // SelectionHelperUI sends text input tap coordinates and a caret move
     // event at the start of a monocle drag. caretPositionFromPoint isn't
     // going to give us correct info if the coord is outside the edit bounds,
     // so restrict the coordinates before we call cpfp.
     let containedCoords = this._restrictCoordinateToEditBounds(aX, aY);
     let cp = this._contentWindow.document.caretPositionFromPoint(containedCoords.xPos,
                                                                  containedCoords.yPos);
-    let input = cp.offsetNode;
-    let offset = cp.offset;
-    input.selectionStart = input.selectionEnd = offset;
+    if (cp) {
+      let input = cp.offsetNode;
+      let offset = cp.offset;
+      input.selectionStart = input.selectionEnd = offset;
+    }
   },
 
   /*
    * Turning on or off various debug features.
    */
   _onSelectionDebug: function _onSelectionDebug(aMsg) {
     this._debugOptions = aMsg;
     this._debugEvents = aMsg.dumpEvents;
@@ -292,30 +294,29 @@ SelectionPrototype.prototype = {
     } else {
       // If we aren't out-of-bounds, clear the scroll timer if it exists.
       this._clearTimers();
 
       // Restrict the client point to the interior of the control.
       let constrainedPoint =
         this._constrainPointWithinControl(aAdjustedClientPoint);
 
-      // For textareas we fall back on the selectAtPoint logic due to various
-      // issues with caretPositionFromPoint (bug 882149).
-      if (Util.isMultilineInput(this._targetElement)) {
+      //  Add or subtract selection
+      let cp =
+        this._contentWindow.document.caretPositionFromPoint(constrainedPoint.xPos,
+                                                            constrainedPoint.yPos);
+
+      // For textareas or if cpfp fails we fall back on the selectAtPoint
+      // logic (bugs 882149, 943071).
+      if (Util.isMultilineInput(this._targetElement) || !cp ||
+          !this._offsetNodeIsValid(cp.offsetNode)) {
         this._adjustSelectionAtPoint(aMarker, constrainedPoint, aEndOfSelection);
         return;
       }
 
-      //  Add or subtract selection
-      let cp =
-        this._contentWindow.document.caretPositionFromPoint(constrainedPoint.xPos,
-                                                            constrainedPoint.yPos);
-      if (!cp || !this._offsetNodeIsValid(cp.offsetNode)) {
-        return;
-      }
       if (aMarker == "start") {
         this._targetElement.selectionStart = cp.offset;
       } else {
         this._targetElement.selectionEnd = cp.offset;
       }
     }
   },