Bug 776390 - Get selected text for context menu actions. r=mbrubeck a=lsblakk
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Mon, 23 Jul 2012 12:50:43 -0700
changeset 102175 63e4dbbffa2c62542672da074a1b958d3e79c6e5
parent 102174 33799e1ebccff27baec42f19a8e40c34ade6bfd4
child 102176 6addc3c4408ecdaca3e572dbcf3bd4d11f19daae
push id1756
push usermleibovic@mozilla.com
push dateMon, 23 Jul 2012 23:27:54 +0000
treeherdermozilla-aurora@6addc3c4408e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmbrubeck, lsblakk
bugs776390
milestone16.0a2
Bug 776390 - Get selected text for context menu actions. r=mbrubeck a=lsblakk
mobile/android/chrome/content/browser.js
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -1701,30 +1701,34 @@ var SelectionHandler = {
   endSelection: function sh_endSelection(aX, aY) {
     if (!this._active)
       return;
 
     this._active = false;
     this.hideHandles();
 
     let selectedText = "";
+    let pointInSelection = false;
     if (this._view) {
       let selection = this._view.getSelection();
       if (selection) {
-        // Get the text to copy if the tap is in the selection
+        // Get the text before we clear the selection!
+        selectedText = selection.toString().trim();
+
+        // Also figure out if the point is in the selection before we clear it.
         if (arguments.length == 2 && this._pointInSelection(aX, aY))
-          selectedText = selection.toString().trim();
+          pointInSelection = true;
 
         selection.removeAllRanges();
         selection.QueryInterface(Ci.nsISelectionPrivate).removeSelectionListener(this);
       }
     }
 
     // Only try copying text if there's text to copy!
-    if (selectedText.length) {
+    if (pointInSelection && selectedText.length) {
       let element = ElementTouchHelper.anyElementFromPoint(BrowserApp.selectedBrowser.contentWindow, aX, aY);
       // Only try copying text if the tap happens in the same view
       if (element.ownerDocument.defaultView == this._view) {
         let clipboard = Cc["@mozilla.org/widget/clipboardhelper;1"].getService(Ci.nsIClipboardHelper);
         clipboard.copyString(selectedText, element.ownerDocument);
         NativeWindow.toast.show(Strings.browser.GetStringFromName("selectionHelper.textCopied"), "short");
       }
     }