Bug 892926 - Findbar steals focus from content when switching tabs r=mconley
authorAdam Dane [:hobophobe] <unusualtears@gmail.com>
Tue, 22 Apr 2014 15:37:47 -0500
changeset 198218 dd60c3189c8a996a62368628db55206b01c986cd
parent 198217 7aaf686b18a8e86f941984353e7a14c528ed63cf
child 198219 7bd04d2f29844200251a852ad7e9cfcc443746c3
push idunknown
push userunknown
push dateunknown
reviewersmconley
bugs892926
milestone31.0a1
Bug 892926 - Findbar steals focus from content when switching tabs r=mconley
browser/base/content/tabbrowser.xml
browser/base/content/test/general/browser_bug537013.js
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -1120,16 +1120,21 @@
                 let prompts = promptBox.listPrompts();
                 // NB: This code assumes that the beforeunload prompt
                 //     is the top-most prompt on the tab.
                 promptBox.removePrompt(prompts[prompts.length - 1]);
               }
 
               // Adjust focus
               oldBrowser._urlbarFocused = (gURLBar && gURLBar.focused);
+              if (this.isFindBarInitialized(oldTab)) {
+                let findBar = this.getFindBar(oldTab);
+                oldTab._findBarFocused = (!findBar.hidden &&
+                  findBar._findField.getAttribute("focused") == "true");
+              }
               do {
                 // When focus is in the tab bar, retain it there.
                 if (document.activeElement == oldTab) {
                   // We need to explicitly focus the new tab, because
                   // tabbox.xml does this only in some cases.
                   this.mCurrentTab.focus();
                   break;
                 }
@@ -1155,18 +1160,19 @@
                     gURLBar.focus();
                     break;
                   } else if (isTabEmpty(this.mCurrentTab)) {
                     focusAndSelectUrlBar();
                     break;
                   }
                 }
 
-                // If the find bar is open, focus it.
-                if (gFindBarInitialized && !gFindBar.hidden) {
+                // Focus the find bar if it was previously focused for that tab.
+                if (gFindBarInitialized && !gFindBar.hidden &&
+                    this.selectedTab._findBarFocused) {
                   gFindBar._findField.focus();
                   break;
                 }
 
                 // Otherwise, focus the content area.
                 let fm = Cc["@mozilla.org/focus-manager;1"].getService(Ci.nsIFocusManager);
                 let focusFlags = fm.FLAG_NOSCROLL;
 
--- a/browser/base/content/test/general/browser_bug537013.js
+++ b/browser/base/content/test/general/browser_bug537013.js
@@ -81,25 +81,29 @@ function continueTests2() {
   ok(!gFindBar.getElement("highlight").checked, "Highlight button reset!");
   gFindBar.close();
   ok(gFindBar.hidden, "First tab doesn't show find bar!");
   gBrowser.selectedTab = tabs[1];
   ok(!gFindBar.hidden, "Second tab shows find bar!");
   // Test for bug 892384
   is(gFindBar._findField.getAttribute("focused"), "true",
      "Open findbar refocused on tab change!");
+  gURLBar.focus();
   gBrowser.selectedTab = tabs[0];
   ok(gFindBar.hidden, "First tab doesn't show find bar!");
 
   // Set up a third tab, no tests here
   gBrowser.selectedTab = tabs[2];
   setFindString(texts[2]);
 
   // Now we jump to the second, then first, and then fourth
   gBrowser.selectedTab = tabs[1];
+  // Test for bug 892384
+  ok(!gFindBar._findField.hasAttribute("focused"),
+     "Open findbar not refocused on tab change!");
   gBrowser.selectedTab = tabs[0];
   gBrowser.selectedTab = tabs[3];
   ok(gFindBar.hidden, "Fourth tab doesn't show find bar!");
   is(gFindBar, gBrowser.getFindBar(), "Find bar is right one!");
   gFindBar.open();
   // Disabled the following assertion due to intermittent failure on OSX 10.6 Debug.
   if (!HasFindClipboard) {
     is(gFindBar._findField.value, texts[1],