Bug 1330144, don't focus 'noinitialfocus' elements at all in dialogs, r=gijs

This commit is contained in:
Neil Deakin 2017-02-16 08:53:58 -05:00
Родитель 095953b36b
Коммит e553c554fc
2 изменённых файлов: 22 добавлений и 5 удалений

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

@ -26,12 +26,16 @@
SimpleTest.waitForExplicitFinish();
SimpleTest.requestCompleteLog();
var expected = [ "one", "_extra2", "tab", "one", "tabbutton2", "tabbutton", "two", "textbox-yes", "one" ];
var expected = [ "one", "_extra2", "tab", "one", "tabbutton2", "tabbutton", "two", "textbox-yes", "one", "root" ];
// non-Mac will always focus the default button if any of the dialog buttons
// would be focused
if (navigator.platform.indexOf("Mac") == -1)
expected[1] = "_accept";
let extraDialog = "data:application/vnd.mozilla.xul+xml,<dialog id='root' buttons='none' " +
"xmlns='http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul'>" +
"<button id='nonbutton' noinitialfocus='true'/></dialog>";
var step = 0;
var fullKeyboardAccess = false;
@ -55,7 +59,8 @@ function runTest()
}
var expectedFocus = expected[step - 1];
var win = window.openDialog("dialog_dialogfocus.xul", "_new", "chrome,dialog", step);
let filename = expectedFocus == "root" ? extraDialog : "dialog_dialogfocus.xul";
var win = window.openDialog(filename, "_new", "chrome,dialog", step);
function checkDialogFocus(event)
{
@ -83,14 +88,22 @@ function runTest()
info("match = " + match);
}
win.removeEventListener("focus", checkDialogFocus, true);
win.removeEventListener("focus", checkDialogFocusEvent, true);
ok(match, "focus step " + step);
win.close();
SimpleTest.waitForFocus(runTest, window);
}
win.addEventListener("focus", checkDialogFocus, true);
function checkDialogFocusEvent(event) {
// Delay to have time for focus/blur to occur.
if (expectedFocus == "root") {
setTimeout(checkDialogFocus, 0, event);
} else {
checkDialogFocus(event);
}
}
win.addEventListener("focus", checkDialogFocusEvent, true);
}
SimpleTest.waitForFocus(startTest, window);

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

@ -176,8 +176,12 @@
focusedElt.getAttribute("noinitialfocus") == "true") {
document.commandDispatcher.advanceFocusIntoSubtree(focusedElt);
focusedElt = document.commandDispatcher.focusedElement;
if (focusedElt == initialFocusedElt)
if (focusedElt == initialFocusedElt) {
if (focusedElt.getAttribute("noinitialfocus") == "true") {
focusedElt.blur();
}
break;
}
}
if (initialFocusedElt.localName == "tab") {