Backed out changeset 11921c9f7d11 for causing bug 1328410, a=backout
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Wed, 04 Jan 2017 20:52:41 +0000
changeset 357070 1672ba92485f35fad11519b18fb9f0136aa09c4d
parent 357069 b0bc6095804be7340749e6011b8d6043e5b320ec
child 357071 6a017a5fdf0185d3fecf1bbd20641581590fcab7
push id6731
push usergijskruitbosch@gmail.com
push dateWed, 04 Jan 2017 20:54:18 +0000
treeherdermozilla-beta@1672ba92485f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbackout
bugs1328410
milestone51.0
backs out11921c9f7d11e52db8da6f7dbaa9d6567227a3ad
Backed out changeset 11921c9f7d11 for causing bug 1328410, a=backout
toolkit/content/widgets/popup.xml
--- a/toolkit/content/widgets/popup.xml
+++ b/toolkit/content/widgets/popup.xml
@@ -311,45 +311,37 @@
       <handler event="popuphiding"><![CDATA[
         try {
           this._currentFocus = document.commandDispatcher.focusedElement;
         } catch (e) {
           this._currentFocus = document.activeElement;
         }
       ]]></handler>
       <handler event="popuphidden"><![CDATA[
-        function doFocus() {
-          // Focus was set on an element inside this panel,
-          // so we need to move it back to where it was previously
-          try {
-            let fm = Components.classes["@mozilla.org/focus-manager;1"]
-                               .getService(Components.interfaces.nsIFocusManager);
-            fm.setFocus(prevFocus, fm.FLAG_NOSCROLL);
-          } catch (e) {
-            prevFocus.focus();
-          }
-        }
         var currentFocus = this._currentFocus;
         var prevFocus = this._prevFocus ? this._prevFocus.get() : null;
         this._currentFocus = null;
         this._prevFocus = null;
-        if (prevFocus && this.getAttribute("norestorefocus") != "true") {
+        if (prevFocus && currentFocus && this.getAttribute("norestorefocus") != "true") {
           // Try to restore focus
           try {
             if (document.commandDispatcher.focusedWindow != window)
               return; // Focus has already been set to a window outside of this panel
           } catch (ex) {}
-
-          if (!currentFocus) {
-            doFocus();
-            return;
-          }
           while (currentFocus) {
             if (currentFocus == this) {
-              doFocus();
+              // Focus was set on an element inside this panel,
+              // so we need to move it back to where it was previously
+              try {
+                let fm = Components.classes["@mozilla.org/focus-manager;1"]
+                                   .getService(Components.interfaces.nsIFocusManager);
+                fm.setFocus(prevFocus, fm.FLAG_NOSCROLL);
+              } catch (e) {
+                prevFocus.focus();
+              }
               return;
             }
             currentFocus = currentFocus.parentNode;
           }
         }
       ]]></handler>
     </handlers>
   </binding>