Bug 503829, focus and select textfield when common dialog and prompts are shown, r=neil
authorNeil Deakin <neil@mozilla.com>
Thu, 20 Aug 2009 10:19:15 -0400
changeset 31683 76581fc3f3eaf037a82a6a49667bcadca6aa4583
parent 31682 873809032158d19f0189fea2f3b6a129141ee82a
child 31684 64770800c4e2616f8bc5c1275a8fadc25da3e103
push id8667
push userneil@mozilla.com
push dateThu, 20 Aug 2009 14:20:28 +0000
treeherdermozilla-central@64770800c4e2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersneil
bugs503829
milestone1.9.3a1pre
Bug 503829, focus and select textfield when common dialog and prompts are shown, r=neil
toolkit/components/passwordmgr/test/test_prompt.html
toolkit/content/commonDialog.js
toolkit/content/commonDialog.xul
--- a/toolkit/components/passwordmgr/test/test_prompt.html
+++ b/toolkit/components/passwordmgr/test/test_prompt.html
@@ -104,35 +104,40 @@ function finishTest() {
  * should call startCallbackTimer() each time the auth dialog is expected (the
  * timer is a one-shot).
  */
 function handleDialog(doc, testNum) {
   netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
   ok(true, "handleDialog running for test " + testNum);
 
   var clickOK = true;
+  var body = doc.getElementById("info.body");
   var userfield = doc.getElementById("loginTextbox");
   var passfield = doc.getElementById("password1Textbox");
   var username = userfield.getAttribute("value");
   var password = passfield.getAttribute("value");
   var dialog    = doc.getElementById("commonDialog");
 
   switch(testNum) {
     case 1:
         is(username, "abc", "Checking provided username");
         userfield.setAttribute("value", "xyz");
+        is(doc.activeElement, userfield.inputField, "focus correct for test" + testNum);
+        doc.commandDispatcher.rewindFocus();
+        is(doc.activeElement, body, "description focusable");
         break;
 
     case 2:
         clickOK = false;
         break;
 
     case 10:
         is(password, "inputpw", "Checking provided password");
         passfield.setAttribute("value", "secret");
+        is(doc.activeElement, passfield.inputField, "focus correct for test" + testNum);
         break;
 
     case 11:
         is(password, "inputpw", "Checking provided password");
         clickOK = false;
         break;
 
     case 12:
--- a/toolkit/content/commonDialog.js
+++ b/toolkit/content/commonDialog.js
@@ -202,16 +202,22 @@ function commonDialogOnLoad()
 
     // Set the default button and focus it on non-OS X systems
     var dButton = dlgButtons[gCommonDialogParam.GetInt(5)];
     document.documentElement.defaultButton = dButton;
 #ifndef XP_MACOSX
     document.documentElement.getButton(dButton).focus();
 #endif
   }
+  else {
+    if (gCommonDialogParam.GetInt(4) == 1)
+      document.getElementById("password1Textbox").select();
+    else
+      document.getElementById("loginTextbox").select();
+  }
 
   if (gCommonDialogParam.GetInt(6) != 0) // delay button enable
   {
     var delayInterval = 2000;
     try {
       var prefs = Cc["@mozilla.org/preferences-service;1"]
                     .getService(Ci.nsIPrefBranch);
       delayInterval = prefs.getIntPref("security.dialog_enable_delay");
--- a/toolkit/content/commonDialog.xul
+++ b/toolkit/content/commonDialog.xul
@@ -55,17 +55,17 @@
           <image id="info.icon" class="spaced"/>
         </hbox>
         <vbox id="infoContainer">
 #ifdef XP_MACOSX
           <!-- Dialog title is inside dialog for OS X -->
           <description id="info.title" class="dialogTitle"/>
 #endif
           <description id="info.header" class="header"/>
-          <description id="info.body" context="contentAreaContextMenu" tabindex="-1"/>
+          <description id="info.body" context="contentAreaContextMenu"/>
         </vbox>
       </row>
       <row id="loginContainer" hidden="true" align="center">
         <label id="loginLabel" value="&editfield0.label;" control="loginTextbox"/>
         <textbox id="loginTextbox"/>
       </row>
       <row id ="password1Container" hidden="true" align="center">
         <label id="password1Label" value="&editfield1.label;" control="password1Textbox"/>