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
Родитель 101509c76a
Коммит 5cc9afaeb4
2 изменённых файлов: 35 добавлений и 20 удалений

Просмотреть файл

@ -157,22 +157,29 @@
<parameter name="aEvent"/>
<body>
<![CDATA[
var focusInit =
function() {
// give focus to the first focusable element in the dialog
if (!document.commandDispatcher.focusedElement) {
document.commandDispatcher.advanceFocusIntoSubtree(document.documentElement);
var focusedElt = document.commandDispatcher.focusedElement;
if (focusedElt && focusedElt.localName == 'tab') {
// We don't want to focus on anonymous OK, Cancel, etc. buttons
function focusInit() {
// give focus to the first focusable element in the dialog
if (!document.commandDispatcher.focusedElement) {
document.commandDispatcher.advanceFocusIntoSubtree(document.documentElement);
var focusedElt = document.commandDispatcher.focusedElement;
if (focusedElt) {
if (focusedElt.localName == 'tab') {
// Move focus into the tab
document.commandDispatcher.advanceFocusIntoSubtree(focusedElt);
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();
}
} 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.
setTimeout(focusInit, 0);
@ -273,6 +280,7 @@
if (aButtons) {
// expect a comma delimited list of dlgtype values
var list = aButtons.split(",");
// mark shown dlgtypes as true
var shown = { accept: false, cancel: false, help: false,
disclosure: false, extra1: false, extra2: false };

Просмотреть файл

@ -145,22 +145,29 @@
<parameter name="aEvent"/>
<body>
<![CDATA[
var focusInit =
function() {
// give focus to the first focusable element in the dialog
if (!document.commandDispatcher.focusedElement) {
document.commandDispatcher.advanceFocusIntoSubtree(document.documentElement);
var focusedElt = document.commandDispatcher.focusedElement;
if (focusedElt && focusedElt.localName == 'tab') {
// We don't want to focus on anonymous OK, Cancel, etc. buttons
function focusInit() {
// give focus to the first focusable element in the dialog
if (!document.commandDispatcher.focusedElement) {
document.commandDispatcher.advanceFocusIntoSubtree(document.documentElement);
var focusedElt = document.commandDispatcher.focusedElement;
if (focusedElt) {
if (focusedElt.localName == 'tab') {
// Move focus into the tab
document.commandDispatcher.advanceFocusIntoSubtree(focusedElt);
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();
}
} 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.
setTimeout(focusInit, 0);