Bug 1328410 - only restore focus if the user did not explicitly place focus elsewhere, r?jaws draft
authorNeil Deakin <neil@mozilla.com>
Wed, 04 Jan 2017 23:01:34 +0000
changeset 456439 b584531b8c28eaa76e4ceafca673f6af051edb1e
parent 455176 c91249f41e3766274131a84f9157a4d9d9949520
child 541223 ad5aff60fd9ba0844bd2a4c7b41af1e72e7747ec
push id40492
push usergijskruitbosch@gmail.com
push dateThu, 05 Jan 2017 16:44:24 +0000
reviewersjaws
bugs1328410
milestone53.0a1
Bug 1328410 - only restore focus if the user did not explicitly place focus elsewhere, r?jaws MozReview-Commit-ID: CdL2gN7EgbF
toolkit/content/widgets/popup.xml
--- a/toolkit/content/widgets/popup.xml
+++ b/toolkit/content/widgets/popup.xml
@@ -326,16 +326,29 @@
           } catch (e) {
             prevFocus.focus();
           }
         }
         var currentFocus = this._currentFocus;
         var prevFocus = this._prevFocus ? this._prevFocus.get() : null;
         this._currentFocus = null;
         this._prevFocus = null;
+
+        // Avoid changing focus if focus changed while we hide the popup
+        // (This can happen e.g. if the popup is hiding as a result of a
+        // click/keypress that focused something)
+        let nowFocus;
+        try {
+          nowFocus = document.commandDispatcher.focusedElement;
+        } catch (e) {
+          nowFocus = document.activeElement;
+        }
+        if (nowFocus && nowFocus != currentFocus)
+          return;
+
         if (prevFocus && 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) {