зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1781434 - Clean-up dialog initial focus code. r=pbz,Gijs
Make it a bit easier to read and less prone to race conditions. Remove a setTimeout referencing bug 103197 which I'm pretty sure it's not an issue. Differential Revision: https://phabricator.services.mozilla.com/D156543
This commit is contained in:
Родитель
33d42fbb13
Коммит
93d2bb3408
|
@ -6,33 +6,34 @@
|
|||
<script src="chrome://mochikit/content/tests/SimpleTest/WindowSnapshot.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body style="height: 100%" onload="setTimeout(onBodyLoad, 0);">
|
||||
<iframe id="test" src="398289-resource.xhtml" width="100%" height="100%">
|
||||
</iframe>
|
||||
<body style="height: 100%; margin: 0; overflow: hidden;" onload="setTimeout(onBodyLoad, 0);">
|
||||
<iframe id="test" style="border: 0; width: 100%; height: 100%" scrolling="no" src="398289-resource.xhtml"></iframe>
|
||||
|
||||
<script class="testbody" type="text/javascript">
|
||||
<script class="testbody">
|
||||
var snap1, snap2;
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
|
||||
async function onBodyLoad() {
|
||||
window.frames[0].document.getElementById("test").selectedIndex = 0;
|
||||
window.frames[0].document.getElementById("test").selectedIndex = 1;
|
||||
|
||||
|
||||
frames[0].scrollTo(0, 0);
|
||||
scrollTo(0, 0);
|
||||
snap1 = await snapshotWindow(window);
|
||||
|
||||
|
||||
document.getElementById("test").onload = onFrameLoad;
|
||||
window.frames[0].location.reload();
|
||||
}
|
||||
|
||||
|
||||
async function onFrameLoad() {
|
||||
frames[0].scrollTo(0, 0);
|
||||
scrollTo(0, 0);
|
||||
snap2 = await snapshotWindow(window);
|
||||
|
||||
var equal, str1, str2;
|
||||
[equal, str1, str2] = compareSnapshots(snap1, snap2, true);
|
||||
|
||||
ok(equal, "persistent attribute in tab box broken, expected: "+str1+" got: "+str2);
|
||||
|
||||
SimpleTest.finish();
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -4,9 +4,8 @@ support-files =
|
|||
chromeScript.js
|
||||
|
||||
[test_modal_prompts.html]
|
||||
skip-if =
|
||||
toolkit == 'android'
|
||||
skip-if =
|
||||
toolkit == 'android'
|
||||
os == 'linux' && (debug || asan) #android: TIMED_OUT (For Linux : 950636)
|
||||
win10_2004 # Bug 1781434
|
||||
[test_modal_select.html]
|
||||
skip-if = toolkit == 'android' #android: TIMED_OUT
|
||||
|
|
|
@ -1063,13 +1063,19 @@ async function runTests(util) {
|
|||
passValue: "",
|
||||
checkMsg: "",
|
||||
checked: false,
|
||||
focused: "infoBody",
|
||||
focused: null, // Nothing focused until the delay triggers.
|
||||
defButton: "button0",
|
||||
butt0Label: "OK",
|
||||
butt1Label: "Cancel",
|
||||
butt0Disabled: true,
|
||||
};
|
||||
|
||||
if (isOSX) {
|
||||
// OS X doesn't initially focus the button, but rather the infoBody.
|
||||
// The focus stays there even after the button-enable delay has fired.
|
||||
state.focused = "infoBody";
|
||||
}
|
||||
|
||||
action = {
|
||||
buttonClick: "pollOK",
|
||||
};
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
|
||||
|
||||
<window onload="loaded()"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
xmlns:html="http://www.w3.org/1999/xhtml">
|
||||
<dialog id="dialog-focus"
|
||||
buttons="extra2,accept,cancel">
|
||||
|
@ -24,38 +23,37 @@
|
|||
<button id="two" label="Two" hidden="true"/>
|
||||
|
||||
<script>
|
||||
function loaded()
|
||||
{
|
||||
if (window.arguments) {
|
||||
var step = window.arguments[0];
|
||||
switch (step) {
|
||||
case 2:
|
||||
document.getElementById("one").setAttribute("noinitialfocus", "true");
|
||||
break;
|
||||
case 3:
|
||||
document.getElementById("one").hidden = true;
|
||||
// no-fallthrough
|
||||
case 4:
|
||||
document.getElementById("tabbutton2").setAttribute("noinitialfocus", "true");
|
||||
// no-fallthrough
|
||||
case 5:
|
||||
document.getElementById("tabbutton").setAttribute("noinitialfocus", "true");
|
||||
// no-fallthrough
|
||||
case 6:
|
||||
document.getElementById("tabbox").hidden = false;
|
||||
break;
|
||||
case 7:
|
||||
if (window.arguments) {
|
||||
var step = window.arguments[0];
|
||||
switch (step) {
|
||||
case 2:
|
||||
document.getElementById("one").setAttribute("noinitialfocus", "true");
|
||||
break;
|
||||
case 3:
|
||||
document.getElementById("one").hidden = true;
|
||||
// no-fallthrough
|
||||
case 4:
|
||||
document.getElementById("tabbutton2").setAttribute("noinitialfocus", "true");
|
||||
// no-fallthrough
|
||||
case 5:
|
||||
document.getElementById("tabbutton").setAttribute("noinitialfocus", "true");
|
||||
// no-fallthrough
|
||||
case 6:
|
||||
document.getElementById("tabbox").hidden = false;
|
||||
break;
|
||||
case 7:
|
||||
window.addEventListener("load", function() {
|
||||
var two = document.getElementById("two");
|
||||
two.hidden = false;
|
||||
two.focus();
|
||||
break;
|
||||
case 8:
|
||||
document.getElementById("textbox-yes").hidden = false;
|
||||
break;
|
||||
case 9:
|
||||
document.getElementById("textbox-no").hidden = false;
|
||||
break;
|
||||
}
|
||||
});
|
||||
break;
|
||||
case 8:
|
||||
document.getElementById("textbox-yes").hidden = false;
|
||||
break;
|
||||
case 9:
|
||||
document.getElementById("textbox-no").hidden = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -240,73 +240,80 @@
|
|||
window.moveTo(xOffset, yOffset);
|
||||
}
|
||||
|
||||
postLoadInit(aEvent) {
|
||||
let focusInit = () => {
|
||||
const defaultButton = this.getButton(this.defaultButton);
|
||||
// Give focus to the first focusable element in the dialog
|
||||
_setInitialFocusIfNeeded() {
|
||||
let focusedElt = document.commandDispatcher.focusedElement;
|
||||
if (focusedElt) {
|
||||
return;
|
||||
}
|
||||
|
||||
// give focus to the first focusable element in the dialog
|
||||
let focusedElt = document.commandDispatcher.focusedElement;
|
||||
if (!focusedElt) {
|
||||
Services.focus.moveFocus(
|
||||
window,
|
||||
null,
|
||||
Services.focus.MOVEFOCUS_FORWARD,
|
||||
Services.focus.FLAG_NOPARENTFRAME
|
||||
);
|
||||
const defaultButton = this.getButton(this.defaultButton);
|
||||
Services.focus.moveFocus(
|
||||
window,
|
||||
null,
|
||||
Services.focus.MOVEFOCUS_FORWARD,
|
||||
Services.focus.FLAG_NOPARENTFRAME
|
||||
);
|
||||
|
||||
focusedElt = document.commandDispatcher.focusedElement;
|
||||
if (focusedElt) {
|
||||
var initialFocusedElt = focusedElt;
|
||||
while (
|
||||
focusedElt.localName == "tab" ||
|
||||
focusedElt.getAttribute("noinitialfocus") == "true"
|
||||
) {
|
||||
Services.focus.moveFocus(
|
||||
window,
|
||||
focusedElt,
|
||||
Services.focus.MOVEFOCUS_FORWARD,
|
||||
Services.focus.FLAG_NOPARENTFRAME
|
||||
);
|
||||
focusedElt = document.commandDispatcher.focusedElement;
|
||||
if (focusedElt) {
|
||||
if (focusedElt == initialFocusedElt) {
|
||||
if (focusedElt.getAttribute("noinitialfocus") == "true") {
|
||||
focusedElt.blur();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
focusedElt = document.commandDispatcher.focusedElement;
|
||||
if (!focusedElt) {
|
||||
return; // No focusable element?
|
||||
}
|
||||
|
||||
if (initialFocusedElt.localName == "tab") {
|
||||
if (focusedElt.hasAttribute("dlgtype")) {
|
||||
// We don't want to focus on anonymous OK, Cancel, etc. buttons,
|
||||
// so return focus to the tab itself
|
||||
initialFocusedElt.focus();
|
||||
}
|
||||
} else if (
|
||||
AppConstants.platform != "macosx" &&
|
||||
focusedElt.hasAttribute("dlgtype") &&
|
||||
focusedElt != defaultButton
|
||||
) {
|
||||
// If the default button is not focusable, then return focus.
|
||||
defaultButton.focus();
|
||||
if (document.commandDispatcher.focusedElement != defaultButton) {
|
||||
initialFocusedElt.focus();
|
||||
}
|
||||
}
|
||||
let firstFocusedElt = focusedElt;
|
||||
while (
|
||||
focusedElt.localName == "tab" ||
|
||||
focusedElt.getAttribute("noinitialfocus") == "true"
|
||||
) {
|
||||
Services.focus.moveFocus(
|
||||
window,
|
||||
focusedElt,
|
||||
Services.focus.MOVEFOCUS_FORWARD,
|
||||
Services.focus.FLAG_NOPARENTFRAME
|
||||
);
|
||||
focusedElt = document.commandDispatcher.focusedElement;
|
||||
if (focusedElt == firstFocusedElt) {
|
||||
if (focusedElt.getAttribute("noinitialfocus") == "true") {
|
||||
focusedElt.blur();
|
||||
}
|
||||
// Didn't find anything else to focus, we're done.
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (firstFocusedElt.localName == "tab") {
|
||||
if (focusedElt.hasAttribute("dlgtype")) {
|
||||
// We don't want to focus on anonymous OK, Cancel, etc. buttons,
|
||||
// so return focus to the tab itself
|
||||
firstFocusedElt.focus();
|
||||
}
|
||||
} else if (
|
||||
AppConstants.platform != "macosx" &&
|
||||
focusedElt.hasAttribute("dlgtype") &&
|
||||
focusedElt != defaultButton
|
||||
) {
|
||||
defaultButton.focus();
|
||||
if (document.commandDispatcher.focusedElement != defaultButton) {
|
||||
// If the default button is not focusable, then return focus to the
|
||||
// initial element if possible, or blur otherwise.
|
||||
if (firstFocusedElt.getAttribute("noinitialfocus") == "true") {
|
||||
focusedElt.blur();
|
||||
} else {
|
||||
firstFocusedElt.focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (defaultButton) {
|
||||
window.notifyDefaultButtonLoaded(defaultButton);
|
||||
}
|
||||
} catch (e) {}
|
||||
};
|
||||
postLoadInit(aEvent) {
|
||||
this._setInitialFocusIfNeeded();
|
||||
|
||||
// Give focus after onload completes, see bug 103197.
|
||||
setTimeout(focusInit, 0);
|
||||
try {
|
||||
const defaultButton = this.getButton(this.defaultButton);
|
||||
if (defaultButton) {
|
||||
window.notifyDefaultButtonLoaded(defaultButton);
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
if (this._l10nButtons.length) {
|
||||
document.l10n.translateElements(this._l10nButtons).then(() => {
|
||||
|
|
Загрузка…
Ссылка в новой задаче