Bug 322155: if the only focusable elements in a dialog are the buttons, focus the default button on load, r=Neil

This commit is contained in:
gavin%gavinsharp.com 2006-03-29 21:33:41 +00:00
parent 101509c76a
commit 5cc9afaeb4
2 changed files with 35 additions and 20 deletions

View File

@ -157,22 +157,29 @@
<parameter name="aEvent"/> <parameter name="aEvent"/>
<body> <body>
<![CDATA[ <![CDATA[
var focusInit = function focusInit() {
function() { // give focus to the first focusable element in the dialog
// give focus to the first focusable element in the dialog if (!document.commandDispatcher.focusedElement) {
if (!document.commandDispatcher.focusedElement) { document.commandDispatcher.advanceFocusIntoSubtree(document.documentElement);
document.commandDispatcher.advanceFocusIntoSubtree(document.documentElement); var focusedElt = document.commandDispatcher.focusedElement;
var focusedElt = document.commandDispatcher.focusedElement; if (focusedElt) {
if (focusedElt && focusedElt.localName == 'tab') { if (focusedElt.localName == 'tab') {
// We don't want to focus on anonymous OK, Cancel, etc. buttons // Move focus into the tab
document.commandDispatcher.advanceFocusIntoSubtree(focusedElt); document.commandDispatcher.advanceFocusIntoSubtree(focusedElt);
if (document.commandDispatcher.focusedElement.hasAttribute("dlgtype")) { if (document.commandDispatcher.focusedElement.hasAttribute("dlgtype")) {
// Prefer to keep focus on label rather than focus a dialog button // We don't want to focus on anonymous OK, Cancel, etc. buttons,
// so return focus to the tab itself
focusedElt.focus(); focusedElt.focus();
} }
} else {
const dialog = document.documentElement;
const defaultButton = dialog.getButton(dialog.defaultButton);
if (focusedElt.hasAttribute("dlgtype") && focusedElt != defaultButton)
defaultButton.focus();
} }
} }
}; }
}
// Give focus after onload completes, see bug 103197. // Give focus after onload completes, see bug 103197.
setTimeout(focusInit, 0); setTimeout(focusInit, 0);
@ -273,6 +280,7 @@
if (aButtons) { if (aButtons) {
// expect a comma delimited list of dlgtype values // expect a comma delimited list of dlgtype values
var list = aButtons.split(","); var list = aButtons.split(",");
// mark shown dlgtypes as true // mark shown dlgtypes as true
var shown = { accept: false, cancel: false, help: false, var shown = { accept: false, cancel: false, help: false,
disclosure: false, extra1: false, extra2: false }; disclosure: false, extra1: false, extra2: false };

View File

@ -145,22 +145,29 @@
<parameter name="aEvent"/> <parameter name="aEvent"/>
<body> <body>
<![CDATA[ <![CDATA[
var focusInit = function focusInit() {
function() { // give focus to the first focusable element in the dialog
// give focus to the first focusable element in the dialog if (!document.commandDispatcher.focusedElement) {
if (!document.commandDispatcher.focusedElement) { document.commandDispatcher.advanceFocusIntoSubtree(document.documentElement);
document.commandDispatcher.advanceFocusIntoSubtree(document.documentElement); var focusedElt = document.commandDispatcher.focusedElement;
var focusedElt = document.commandDispatcher.focusedElement; if (focusedElt) {
if (focusedElt && focusedElt.localName == 'tab') { if (focusedElt.localName == 'tab') {
// We don't want to focus on anonymous OK, Cancel, etc. buttons // Move focus into the tab
document.commandDispatcher.advanceFocusIntoSubtree(focusedElt); document.commandDispatcher.advanceFocusIntoSubtree(focusedElt);
if (document.commandDispatcher.focusedElement.hasAttribute("dlgtype")) { if (document.commandDispatcher.focusedElement.hasAttribute("dlgtype")) {
// Prefer to keep focus on label rather than focus a dialog button // We don't want to focus on anonymous OK, Cancel, etc. buttons,
// so return focus to the tab itself
focusedElt.focus(); focusedElt.focus();
} }
} else {
const dialog = document.documentElement;
const defaultButton = dialog.getButton(dialog.defaultButton);
if (focusedElt.hasAttribute("dlgtype") && focusedElt != defaultButton)
defaultButton.focus();
} }
} }
}; }
}
// Give focus after onload completes, see bug 103197. // Give focus after onload completes, see bug 103197.
setTimeout(focusInit, 0); setTimeout(focusInit, 0);