Bug 513186, add noinitialfocus attribute to indicate that the element is skipped when determining the initial focus in a dialog, r=neil

This commit is contained in:
Neil Deakin 2009-10-05 10:00:09 -04:00
Родитель 9844a90a44
Коммит 0168dbd7f9
5 изменённых файлов: 160 добавлений и 8 удалений

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

@ -60,7 +60,7 @@
<description id="info.title" class="dialogTitle"/>
#endif
<description id="info.header" class="header"/>
<description id="info.body" context="contentAreaContextMenu"/>
<description id="info.body" context="contentAreaContextMenu" noinitialfocus="true"/>
</vbox>
</row>
<row id="loginContainer" hidden="true" align="center">

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

@ -91,6 +91,8 @@ _TEST_FILES = findbar_window.xul \
test_showcaret.xul \
window_showcaret.xul \
test_righttoleft.xul \
test_dialogfocus.xul \
dialog_dialogfocus.xul \
$(NULL)
# test_panel_focus.xul won't work if the Full Keyboard Access preference is set to

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

@ -0,0 +1,49 @@
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<dialog buttons="extra2,accept,cancel" onload="loaded()"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<tabbox id="tabbox" hidden="true">
<tabs>
<tab id="tab" label="Tab"/>
</tabs>
<tabpanels>
<tabpanel>
<button id="tabbutton" label="Tab Button"/>
<button id="tabbutton2" label="Tab Button 2"/>
</tabpanel>
</tabpanels>
</tabbox>
<button id="one" label="One"/>
<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;
case 4:
document.getElementById("tabbutton2").setAttribute("noinitialfocus", "true");
case 5:
document.getElementById("tabbutton").setAttribute("noinitialfocus", "true");
case 6:
document.getElementById("tabbox").hidden = false;
break;
case 7:
var two = document.getElementById("two");
two.hidden = false;
two.focus();
break;
}
}
}
</script>
</dialog>

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

@ -0,0 +1,94 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
<window width="500" height="600"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/MochiKit/packed.js"/>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
<button id="test" label="Test"/>
<body xmlns="http://www.w3.org/1999/xhtml">
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
<script>
<![CDATA[
SimpleTest.waitForExplicitFinish();
var expected = [ "one", "_extra2", "tab", "one", "tabbutton2", "tabbutton", "two" ];
// 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";
var step = 0;
var fullKeyboardAccess = false;
function startTest()
{
var testButton = document.getElementById("test");
synthesizeKey("VK_TAB", { });
fullKeyboardAccess = (document.activeElement == testButton);
runTest();
}
function runTest()
{
step++;
if (step > expected.length || (!fullKeyboardAccess && step == 2)) {
SimpleTest.finish();
return;
}
var expectedFocus = expected[step - 1];
netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserWrite');
var win = window.openDialog("dialog_dialogfocus.xul", "_new", "chrome,dialog", step);
function checkDialogFocus(event)
{
// if full keyboard access is not on, just skip the tests
var match = false;
if (fullKeyboardAccess) {
if (!(event.target instanceof Element))
return;
if (expectedFocus[0] == "_")
match = (win.document.activeElement.dlgType == expectedFocus.substring(1));
else
match = (win.document.activeElement.id == expectedFocus);
if (!match)
return;
}
else {
match = (win.document.activeElement == win.document.documentElement);
}
win.removeEventListener("focus", checkDialogFocus, true);
ok(match, "focus step " + step);
win.close();
SimpleTest.waitForFocus(runTest, window);
}
win.addEventListener("focus", checkDialogFocus, true);
}
SimpleTest.waitForFocus(startTest, window);
]]>
</script>
</window>

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

@ -160,21 +160,28 @@
// give focus to the first focusable element in the dialog
if (!document.commandDispatcher.focusedElement) {
document.commandDispatcher.advanceFocusIntoSubtree(dialog);
var focusedElt = document.commandDispatcher.focusedElement;
if (focusedElt) {
if (focusedElt.localName == 'tab') {
// Move focus into the tab
var initialFocusedElt = focusedElt;
while (focusedElt.localName == "tab" ||
focusedElt.getAttribute("noinitialfocus") == "true") {
document.commandDispatcher.advanceFocusIntoSubtree(focusedElt);
if (document.commandDispatcher.focusedElement.hasAttribute("dlgtype")) {
focusedElt = document.commandDispatcher.focusedElement;
if (focusedElt == initialFocusedElt)
break;
}
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
focusedElt.focus();
initialFocusedElt.focus();
}
}
#ifndef XP_MACOSX
else {
if (focusedElt.hasAttribute("dlgtype") && focusedElt != defaultButton)
defaultButton.focus();
else if (focusedElt.hasAttribute("dlgtype") && focusedElt != defaultButton) {
defaultButton.focus();
}
#endif
}