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

This commit is contained in:
Neil Deakin 2017-10-04 11:10:05 -04:00
Родитель 98bc4660c7
Коммит 4d3b46e590
4 изменённых файлов: 37 добавлений и 5 удалений

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

@ -13,6 +13,7 @@ support-files =
bug429723_window.xul
bug624329_window.xul
dialog_dialogfocus.xul
dialog_dialogfocus2.xul
file_about_networking_wsh.py
file_autocomplete_with_composition.js
findbar_entireword_window.xul

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

@ -0,0 +1,6 @@
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<dialog id="root" buttons="none" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<button id="nonbutton" noinitialfocus="true"/>
</dialog>

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

@ -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" ? "dialog_dialogfocus2.xul" : "dialog_dialogfocus.xul";
var win = window.openDialog(filename, "_new", "chrome,dialog", step);
function checkDialogFocus(event)
{
@ -83,14 +88,30 @@ 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 checkDialogFocusRoot(event) {
if (event.target == win) {
is(win.document.activeElement, win.document.documentElement, "No other focus but root");
win.close();
SimpleTest.waitForFocus(runTest, window);
}
}
function checkDialogFocusEvent(event) {
// Delay to have time for focus/blur to occur.
if (expectedFocus == "root") {
setTimeout(checkDialogFocusRoot, 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") {