Bug 776390 - Get selected text for context menu actions. r=mbrubeck
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Mon, 23 Jul 2012 12:50:43 -0700
changeset 100202 24bdf8eb82244d8aebbaa06711da27ed9181815b
parent 100201 61666a1574f268fd62de24389cdcdf0b941fd157
child 100203 b9286b1d242b0007038adf4a925b28b50497bb91
push id23169
push useremorley@mozilla.com
push dateTue, 24 Jul 2012 09:54:00 +0000
treeherdermozilla-central@a26e751bfb54 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmbrubeck
bugs776390
milestone17.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 776390 - Get selected text for context menu actions. r=mbrubeck
mobile/android/chrome/content/browser.js
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -1781,30 +1781,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");
       }
     }