Bug 1115370 - TextSelection lost abruptly on unrelated Tab:pagehide messages, r=margaret
authorMark Capella <markcapella@twcny.rr.com>
Tue, 30 Dec 2014 16:42:16 -0500
changeset 247551 af6aa5d204c4d7fabe810df1f54b398186687a59
parent 247550 5ff375efac3c25c77252942e6aa3ea1d78535ed3
child 247552 2329a689ff1b50f88ae1110f66ad6d7fb8ed404e
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret
bugs1115370
milestone37.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 1115370 - TextSelection lost abruptly on unrelated Tab:pagehide messages, r=margaret * * * Bug 1115370 - Update SelectionHandler test for Tab:pagehide messages, r=margaret
mobile/android/base/tests/roboextender/testSelectionHandler.html
mobile/android/chrome/content/SelectionHandler.js
--- a/mobile/android/base/tests/roboextender/testSelectionHandler.html
+++ b/mobile/android/base/tests/roboextender/testSelectionHandler.html
@@ -202,17 +202,20 @@ function testCloseSelection() {
 
   }).then(function() {
     sh.startSelection(inputNode);
     sh.observe(null, "Tab:Selected", {});
     return ok(!sh.isSelectionActive(), "Tab:Selected should close active selection");
 
   }).then(function() {
     sh.startSelection(inputNode);
-    sh.handleEvent({ type: "pagehide" });
+    sh.handleEvent({ type: "pagehide", originalTarget: {} });
+    return ok(sh.isSelectionActive(), "unrelated pagehide should not close active selection");
+  }).then(function() {
+    sh.handleEvent({ type: "pagehide", originalTarget: document });
     return ok(!sh.isSelectionActive(), "pagehide should close active selection");
 
   }).then(function() {
     sh.startSelection(inputNode);
     sh.handleEvent({ type: "blur" });
     return ok(!sh.isSelectionActive(), "blur should close active selection");
   });
 }
--- a/mobile/android/chrome/content/SelectionHandler.js
+++ b/mobile/android/chrome/content/SelectionHandler.js
@@ -217,17 +217,25 @@ var SelectionHandler = {
 
   handleEvent: function sh_handleEvent(aEvent) {
     switch (aEvent.type) {
       case "scroll":
         // Maintain position when top-level document is scrolled
         this._positionHandlesOnChange();
         break;
 
-      case "pagehide":
+      case "pagehide": {
+        // We only care about events on the selected tab.
+        let tab = BrowserApp.getTabForWindow(aEvent.originalTarget.defaultView);
+        if (tab == BrowserApp.selectedTab) {
+          this._closeSelection();
+        }
+        break;
+      }
+
       case "blur":
         this._closeSelection();
         break;
 
       // Update caret position on keyboard activity
       case "keyup":
         // Not generated by Swiftkeyboard
       case "compositionupdate":