зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1614224 - Fix <dialog> focus wrap-around, and add tests for it. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D62490 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
d0a5c12f8e
Коммит
9003451702
|
@ -3491,19 +3491,19 @@ nsresult nsFocusManager::GetNextTabbableContent(
|
|||
NS_ADDREF(*aResultContent = contentToFocus);
|
||||
return NS_OK;
|
||||
}
|
||||
// If we've wrapped around already, then carry on.
|
||||
if (aOriginalStartContent &&
|
||||
currentTopLevelScopeOwner ==
|
||||
GetTopLevelScopeOwner(aOriginalStartContent)) {
|
||||
// FIXME: Shouldn't this return null instead? aOriginalStartContent
|
||||
// isn't focusable after all.
|
||||
NS_ADDREF(*aResultContent = aOriginalStartContent);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
// There is no next tabbable content in currentTopLevelScopeOwner's
|
||||
// scope. We should continue the loop in order to skip all contents that
|
||||
// is in currentTopLevelScopeOwner's scope. Unless we've wrapped around
|
||||
// already.
|
||||
if (aOriginalStartContent &&
|
||||
currentTopLevelScopeOwner ==
|
||||
GetTopLevelScopeOwner(aOriginalStartContent)) {
|
||||
// FIXME: Shouldn't this return null instead? aOriginalStartContent
|
||||
// isn't focusable after all.
|
||||
NS_ADDREF(*aResultContent = aOriginalStartContent);
|
||||
return NS_OK;
|
||||
}
|
||||
// is in currentTopLevelScopeOwner's scope.
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ support-files =
|
|||
file_subscript_bindings.js
|
||||
focus_frameset.html
|
||||
focus_window2.xhtml
|
||||
focus_dialog.xhtml
|
||||
fullscreen.xhtml
|
||||
queryCaretRectUnix.html
|
||||
queryCaretRectWin.html
|
||||
|
@ -57,6 +58,7 @@ skip-if = os != 'mac' || os_version == '10.14' # 10.14 due to bug 1558642
|
|||
[test_elements_proto.xhtml]
|
||||
[test_focus.xhtml]
|
||||
skip-if = os == 'linux' # bug 1296622, Bug 1605253
|
||||
[test_focus_dialog.xhtml]
|
||||
[test_focus_docnav.xhtml]
|
||||
[test_focused_link_scroll.xhtml]
|
||||
[test_fullscreen.xhtml]
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
|
||||
|
||||
<window id="other-document"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
<dialog buttons="accept">
|
||||
|
||||
<script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
|
||||
|
||||
<button id="button-1" label="Something"/>
|
||||
<button id="button-2" label="Something else"/>
|
||||
|
||||
<script>
|
||||
<![CDATA[
|
||||
|
||||
window.is = window.arguments[0].is;
|
||||
window.isnot = window.arguments[0].isnot;
|
||||
window.ok = window.arguments[0].ok;
|
||||
window.SimpleTest = window.arguments[0].SimpleTest;
|
||||
|
||||
(async function() {
|
||||
await new Promise(resolve => {
|
||||
window.onload = resolve;
|
||||
});
|
||||
|
||||
await new Promise(resolve => SimpleTest.waitForFocus(resolve, window));
|
||||
|
||||
let dialog = document.querySelector("dialog");
|
||||
let shadow = dialog.shadowRoot;
|
||||
|
||||
let button = document.getElementById("button-1");
|
||||
let button2 = document.getElementById("button-2");
|
||||
let forwardSequence = [];
|
||||
|
||||
button.focus();
|
||||
|
||||
is(document.activeElement, button, "Should've focused the button");
|
||||
forwardSequence.push(button);
|
||||
|
||||
synthesizeKey("KEY_Tab");
|
||||
|
||||
is(document.activeElement, button2, "Should've moved to the second button");
|
||||
forwardSequence.push(button2);
|
||||
|
||||
synthesizeKey("KEY_Tab");
|
||||
|
||||
isnot(shadow.activeElement, null, "Should've focused the shadow root button");
|
||||
is(document.activeElement, dialog, "document.focusedElement should be the dialog because retargeting");
|
||||
forwardSequence.push(shadow.activeElement);
|
||||
|
||||
synthesizeKey("KEY_Tab");
|
||||
|
||||
is(document.activeElement, button, "Should properly wrap around going forward");
|
||||
|
||||
while (forwardSequence.length) {
|
||||
synthesizeKey("KEY_Tab", { shiftKey: true });
|
||||
is(
|
||||
shadow.activeElement || document.activeElement,
|
||||
forwardSequence.pop(),
|
||||
"Should travel backwards correctly: " + forwardSequence.length
|
||||
);
|
||||
}
|
||||
|
||||
window.close();
|
||||
SimpleTest.finish();
|
||||
}());
|
||||
|
||||
]]>
|
||||
</script>
|
||||
</dialog>
|
||||
</window>
|
|
@ -0,0 +1,33 @@
|
|||
<?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 title="Focus Tests"
|
||||
onload="setTimeout(runTest, 0);"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
|
||||
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
|
||||
|
||||
<script>
|
||||
if (navigator.platform.startsWith("Win")) {
|
||||
SimpleTest.expectAssertions(0, 1);
|
||||
}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
async function runTest() {
|
||||
// Enable full tab focus model on mac.
|
||||
await SpecialPowers.pushPrefEnv({ set: [["accessibility.tabfocus", 7]] });
|
||||
window.openDialog("focus_dialog.xhtml", "_blank", "chrome,modal,noopener", window);
|
||||
}
|
||||
</script>
|
||||
|
||||
<body xmlns="http://www.w3.org/1999/xhtml">
|
||||
<p id="display">
|
||||
</p>
|
||||
<div id="content" style="display: none">
|
||||
</div>
|
||||
<pre id="test">
|
||||
</pre>
|
||||
</body>
|
||||
|
||||
</window>
|
Загрузка…
Ссылка в новой задаче