Bug 907271 - Fix startSelection() processing re: new text SelectionListener(), r=margaret
authorMark Capella <markcapella@twcny.rr.com>
Wed, 28 Aug 2013 20:44:03 -0400
changeset 144913 1536b018539c384b23e6367e431415d3d7300385
parent 144731 098b935f5f3abb450116a2364110e089655865ce
child 144914 ed58ee0f5829054f0c91913bf24b8e766e52461b
push id25183
push useremorley@mozilla.com
push dateThu, 29 Aug 2013 14:02:53 +0000
treeherdermozilla-central@21b5af569ca2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret
bugs907271
milestone26.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 907271 - Fix startSelection() processing re: new text SelectionListener(), r=margaret
mobile/android/chrome/content/SelectionHandler.js
--- a/mobile/android/chrome/content/SelectionHandler.js
+++ b/mobile/android/chrome/content/SelectionHandler.js
@@ -73,17 +73,17 @@ var SelectionHandler = {
           let data = JSON.parse(aData);
           if (this._pointInSelection(data.x, data.y))
             this.copySelection();
           else
             this._closeSelection();
         } else if (this._activeType == this.TYPE_CURSOR) {
           // attachCaret() is called in the "Gesture:SingleTap" handler in BrowserEventHandler
           // We're guaranteed to call this first, because this observer was added last
-          this._closeSelection();
+          this._deactivate();
         }
         break;
       }
       case "Tab:Selected":
         this._closeSelection();
         break;
 
       case "Window:Resize": {
@@ -154,17 +154,17 @@ var SelectionHandler = {
       // We only add keydown and blur listeners for TYPE_CURSOR
       case "keydown":
       case "blur":
         this._closeSelection();
         break;
 
       case "compositionend":
         if (this._activeType == this.TYPE_CURSOR) {
-          this._closeSelection();
+          this._deactivate();
         }
         break;
     }
   },
 
   /** Returns true if the provided element can be selected in text selection, false otherwise. */
   canSelect: function sh_canSelect(aElement) {
     return !(aElement instanceof Ci.nsIDOMHTMLButtonElement ||
@@ -211,35 +211,35 @@ var SelectionHandler = {
    *
    * @param aX, aY tap location in client coordinates.
    */
   startSelection: function sh_startSelection(aElement, aX, aY) {
     // Clear out any existing active selection
     this._closeSelection();
 
     this._initTargetInfo(aElement);
-    this._activeType = this.TYPE_SELECTION;
 
     // Clear any existing selection from the document
     this._contentWindow.getSelection().removeAllRanges();
 
     if (!this._domWinUtils.selectAtPoint(aX, aY, Ci.nsIDOMWindowUtils.SELECT_WORDNOSPACE)) {
-      this._closeSelection();
+      this._deactivate();
       return;
     }
 
     let selection = this._getSelection();
     // If the range didn't have any text, let's bail
     if (!selection || selection.rangeCount == 0) {
-      this._closeSelection();
+      this._deactivate();
       return;
     }
 
     // Add a listener to end the selection if it's removed programatically
     selection.QueryInterface(Ci.nsISelectionPrivate).addSelectionListener(this);
+    this._activeType = this.TYPE_SELECTION;
 
     // Initialize the cache
     this._cache = { start: {}, end: {}};
     this._updateCacheForSelection();
 
     let scroll = this._getScrollPos();
     // Figure out the distance between the selection and the click
     let positions = this._getHandlePositions(scroll);
@@ -493,26 +493,33 @@ var SelectionHandler = {
   /*
    * Shuts SelectionHandler down.
    */
   _closeSelection: function sh_closeSelection() {
     // Bail if there's no active selection
     if (this._activeType == this.TYPE_NONE)
       return;
 
-    if (this._activeType == this.TYPE_SELECTION) {
-      let selection = this._getSelection();
-      if (selection) {
-        // Remove our listener before we clear the selection
-        selection.QueryInterface(Ci.nsISelectionPrivate).removeSelectionListener(this);
-        // Clear selection without clearing the anchorNode or focusNode
-        selection.collapseToStart();
-      }
+    if (this._activeType == this.TYPE_SELECTION)
+      this._clearSelection();
+
+    this._deactivate();
+  },
+
+  _clearSelection: function sh_clearSelection() {
+    let selection = this._getSelection();
+    if (selection) {
+      // Remove our listener before we clear the selection
+      selection.QueryInterface(Ci.nsISelectionPrivate).removeSelectionListener(this);
+      // Clear selection without clearing the anchorNode or focusNode
+      selection.collapseToStart();
     }
+  },
 
+  _deactivate: function sh_deactivate() {
     this._activeType = this.TYPE_NONE;
 
     sendMessageToJava({ type: "TextSelection:HideHandles" });
 
     this._removeObservers();
     this._contentWindow.removeEventListener("pagehide", this, false);
     this._contentWindow.removeEventListener("keydown", this, false);
     this._contentWindow.removeEventListener("blur", this, true);