Bug 1108555 - [e10s] closing last tab does not focus urlbar (browser.tabs.closeWindowWithLastTab = false). r=jimm,mconley
authorDão Gottwald <dao@mozilla.com>
Wed, 17 Dec 2014 18:17:38 +0100
changeset 220126 03348b46166b9f6849ffbb81201f3d3d77d6f726
parent 220125 66cc38d90f25acc0d946a360bd5192fc477788ac
child 220127 e0ee525cb90391fa5eb059a7f3179ac8d500d085
push id10450
push userdgottwald@mozilla.com
push dateWed, 17 Dec 2014 17:17:52 +0000
treeherderfx-team@03348b46166b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm, mconley
bugs1108555
milestone37.0a1
Bug 1108555 - [e10s] closing last tab does not focus urlbar (browser.tabs.closeWindowWithLastTab = false). r=jimm,mconley
browser/base/content/tabbrowser.xml
browser/base/content/utilityOverlay.js
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -1185,16 +1185,20 @@
                   findBar._findField.getAttribute("focused") == "true");
               }
 
               // If 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();
+              } else if (gMultiProcessBrowser) {
+                // Clear focus so that _adjustFocusAfterTabSwitch can detect if
+                // some element has been focused and respect that.
+                document.activeElement.blur();
               }
 
               if (!gMultiProcessBrowser)
                 this._adjustFocusAfterTabSwitch(this.mCurrentTab);
             }
 
             this.tabContainer._setPositionalAttributes();
 
@@ -1202,36 +1206,35 @@
               TelemetryStopwatch.finish("FX_TAB_SWITCH_UPDATE_MS");
           ]]>
         </body>
       </method>
 
       <method name="_adjustFocusAfterTabSwitch">
         <parameter name="newTab"/>
         <body><![CDATA[
-        let newBrowser = this.getBrowserForTab(newTab);
-
         // Don't steal focus from the tab bar.
         if (document.activeElement == newTab)
           return;
 
+        let newBrowser = this.getBrowserForTab(newTab);
+
         // If there's a tabmodal prompt showing, focus it.
         if (newBrowser.hasAttribute("tabmodalPromptShowing")) {
           let XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
           let prompts = newBrowser.parentNode.getElementsByTagNameNS(XUL_NS, "tabmodalprompt");
           let prompt = prompts[prompts.length - 1];
           prompt.Dialog.setDefaultFocus();
           return;
         }
 
         // Focus the location bar if it was previously focused for that tab.
         // In full screen mode, only bother making the location bar visible
         // if the tab is a blank one.
         if (newBrowser._urlbarFocused && gURLBar) {
-
           // Explicitly close the popup if the URL bar retains focus
           gURLBar.closePopup();
 
           if (!window.fullScreen) {
             gURLBar.focus();
             return;
           }
 
@@ -1243,30 +1246,23 @@
 
         // Focus the find bar if it was previously focused for that tab.
         if (gFindBarInitialized && !gFindBar.hidden &&
             this.selectedTab._findBarFocused) {
           gFindBar._findField.focus();
           return;
         }
 
-        // Otherwise, focus the content area. If we're not using remote tabs, we
-        // can focus the content area right away, since tab switching is synchronous.
-        // If we're using remote tabs, we have to wait until after we've finalized
-        // switching the tabs.
-
-        if (newTab._skipContentFocus) {
-          // It's possible the tab we're switching to is ready to focus asynchronously,
-          // when we've already focused something else. In that case, this
-          // _skipContentFocus property can be set so that we skip focusing the
-          // content after we switch tabs.
-          delete newTab._skipContentFocus;
+        // Don't focus the content area if something has been focused after the
+        // tab switch was initiated.
+        if (gMultiProcessBrowser &&
+            document.activeElement != document.documentElement)
           return;
-        }
-
+
+        // We're now committed to focusing the content area.
         let fm = Services.focus;
         let focusFlags = fm.FLAG_NOSCROLL;
 
         if (!gMultiProcessBrowser) {
           let newFocusedElement = fm.getFocusedElementForWindow(window.content, true, {});
 
           // for anchors, use FLAG_SHOWRING so that it is clear what link was
           // last clicked when switching back to that tab
--- a/browser/base/content/utilityOverlay.js
+++ b/browser/base/content/utilityOverlay.js
@@ -304,18 +304,16 @@ function openLinkIn(url, where, params) 
       loadInBackground = false;
     }
   }
 
   // Raise the target window before loading the URI, since loading it may
   // result in a new frontmost window (e.g. "javascript:window.open('');").
   w.focus();
 
-  let newTab;
-
   switch (where) {
   case "current":
     let flags = Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
 
     if (aAllowThirdPartyFixup) {
       flags |= Ci.nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP;
       flags |= Ci.nsIWebNavigation.LOAD_FLAGS_FIXUP_SCHEME_TYPOS;
     }
@@ -328,38 +326,32 @@ function openLinkIn(url, where, params) 
       flags |= Ci.nsIWebNavigation.LOAD_FLAGS_DISALLOW_INHERIT_OWNER;
 
     w.gBrowser.loadURIWithFlags(url, flags, aReferrerURI, null, aPostData);
     break;
   case "tabshifted":
     loadInBackground = !loadInBackground;
     // fall through
   case "tab":
-    newTab = w.gBrowser.loadOneTab(url, {
+    w.gBrowser.loadOneTab(url, {
       referrerURI: aReferrerURI,
       charset: aCharset,
       postData: aPostData,
       inBackground: loadInBackground,
       allowThirdPartyFixup: aAllowThirdPartyFixup,
       relatedToCurrent: aRelatedToCurrent,
       skipAnimation: aSkipTabAnimation,
       allowMixedContent: aAllowMixedContent
     });
     break;
   }
 
   w.gBrowser.selectedBrowser.focus();
 
   if (!loadInBackground && w.isBlankPageURL(url)) {
-    if (newTab && gMultiProcessBrowser) {
-      // Remote browsers are switched to asynchronously, and we need to
-      // ensure that the location bar remains focused in that case rather
-      // than the content area being focused.
-      newTab._skipContentFocus = true;
-    }
     w.focusAndSelectUrlBar();
   }
 }
 
 // Used as an onclick handler for UI elements with link-like behavior.
 // e.g. onclick="checkForMiddleClick(this, event);"
 function checkForMiddleClick(node, event) {
   // We should be using the disabled property here instead of the attribute,