Bug 1278889 - Stop the toolbox losing focus when changing docking modes. r=bgrins a=gchang
authorMichael Ratcliffe <mratcliffe@mozilla.com>
Thu, 04 Aug 2016 16:37:17 +0100
changeset 347651 4a8ba94870387a6ebf87c8a1cae6287e4b5012e4
parent 347650 0463f6653d4830bb793fb43678161dc08b827389
child 347652 08fce3513fac56f170c166d946ea44ab2bac8969
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbgrins, gchang
bugs1278889
milestone50.0a2
Bug 1278889 - Stop the toolbox losing focus when changing docking modes. r=bgrins a=gchang MozReview-Commit-ID: 7yyrLumR3BZ
devtools/client/framework/toolbox.js
--- a/devtools/client/framework/toolbox.js
+++ b/devtools/client/framework/toolbox.js
@@ -1402,19 +1402,24 @@ Toolbox.prototype = {
     });
   },
 
   /**
    * Focus a tool's panel by id
    * @param  {string} id
    *         The id of tool to focus
    */
-  focusTool: function (id) {
+  focusTool: function (id, state = true) {
     let iframe = this.doc.getElementById("toolbox-panel-iframe-" + id);
-    iframe.focus();
+
+    if (state) {
+      iframe.focus();
+    } else {
+      iframe.blur();
+    }
   },
 
   /**
    * Focus split console's input line
    */
   focusConsoleInput: function () {
     let consolePanel = this.getPanel("webconsole");
     if (consolePanel) {
@@ -1793,44 +1798,44 @@ Toolbox.prototype = {
    */
   switchHost: function (hostType) {
     if (hostType == this._host.type || !this._target.isLocalTab) {
       return null;
     }
 
     this.emit("host-will-change", hostType);
 
+    // If we call swapFrameLoaders() when a tool if focused it leaves the
+    // browser in a state where it thinks that the tool is focused but in
+    // reality the content area is focused. Blurring the tool before calling
+    // swapFrameLoaders() works around this issue.
+    this.focusTool(this.currentToolId, false);
+
     let newHost = this._createHost(hostType);
     return newHost.create().then(iframe => {
       // change toolbox document's parent to the new host
       iframe.QueryInterface(Ci.nsIFrameLoaderOwner);
       iframe.swapFrameLoaders(this.frame);
 
-      // See bug 1022726, most probably because of swapFrameLoaders we need to
-      // first focus the window here, and then once again further below to make
-      // sure focus actually happens.
-      this.win.focus();
-
       this._host.off("window-closed", this.destroy);
       this.destroyHost();
 
       let prevHostType = this._host.type;
       this._host = newHost;
 
       if (this.hostType != Toolbox.HostType.CUSTOM) {
         Services.prefs.setCharPref(this._prefs.LAST_HOST, this._host.type);
         Services.prefs.setCharPref(this._prefs.PREVIOUS_HOST, prevHostType);
       }
 
       this._buildDockButtons();
       this._addKeysToWindow();
 
-      // Focus the contentWindow to make sure keyboard shortcuts work straight
-      // away.
-      this.win.focus();
+      // Focus the tool to make sure keyboard shortcuts work straight away.
+      this.focusTool(this.currentToolId, true);
 
       this.emit("host-changed");
     });
   },
 
   /**
    * Return if the tool is available as a tab (i.e. if it's checked
    * in the options panel). This is different from Toolbox.getPanel -