Bug 613763 - Form elements can regain focus under a tab-modal prompt. r=enn, a=blocking
authorJustin Dolske <dolske>
Tue, 23 Nov 2010 19:33:00 -0800
changeset 58939 695ee208215d155afa5d8c2890df1e6a789485d6
parent 58938 0567fd4cf0880dfd03d76c329c430521aec59262
child 58940 94b21d08be3dfd85a68461c4abc82d9f4b23b62b
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersenn, blocking
bugs613763
milestone2.0b8pre
Bug 613763 - Form elements can regain focus under a tab-modal prompt. r=enn, a=blocking
browser/base/content/browser.css
toolkit/components/prompts/src/nsPrompter.js
--- a/browser/base/content/browser.css
+++ b/browser/base/content/browser.css
@@ -470,8 +470,12 @@ window[chromehidden~="toolbar"] toolbar:
 #status-bar {
   display: -moz-box;
 }
 
 /* Remove the resizer from the statusbar compatibility shim */
 #status-bar > .statusbar-resizerpanel {
   display: none;
 }
+
+browser[tabmodalPromptShowing] {
+  -moz-user-focus: none !important;
+}
--- a/toolkit/components/prompts/src/nsPrompter.js
+++ b/toolkit/components/prompts/src/nsPrompter.js
@@ -417,17 +417,24 @@ function openTabPrompt(domWin, tabPrompt
     // until the other prompts had been closed.
     let callbackInvoked = false;
     function onPromptClose(forceCleanup) {
         if (!newPrompt && !forceCleanup)
             return;
         callbackInvoked = true;
         if (newPrompt)
             tabPrompt.removePrompt(newPrompt);
+
         winUtils.leaveModalState();
+
+        // Restore focus to the previously focused element within tab.
+        let fm = Cc["@mozilla.org/focus-manager;1"].
+                 getService(Ci.nsIFocusManager);
+        let e = fm.getFocusedElementForWindow(domWin.top, false, {});
+        fm.setFocus(e, fm.FLAG_NOSCROLL);
     }
 
     let newPrompt;
     try {
         // tab-modal prompts need to watch for navigation changes, give it the
         // domWindow to watch for pagehide events.
         args.domWindow = domWin;
         args.promptActive = true;