Bug 1614658 - Enable accessibility.mouse_focuses_formcontrol by default. r=mac-reviewers,bradwerth,mstange

This aligns Mac's focus model with other platforms. Matches Chromium, but not
Safari.

Reasons why I think it's worth making this change:

 * Consistency with all other platforms.
 * Makes the :focus-visible implementation more useful.
 * Fixes focus navigation after e.g. clicking a button.
 * Shouldn't cause a lot more outlines to show up (at least not by default).

An example of the second point:

    data:text/html,<button onclick="this.nextElementSibling.focus()">Click</button><button>Imagine I'm a dialog close button or something</button>

In non-macOS platforms, we won't show an outline for the button in that case,
which matches the developer expectations (links below). We don't show the
outline because the focus comes from an element that has been focused by mouse
(and thus didn't show an outline). But on macOS that doesn't work, because the
button is not focused.

For completeness, the actual heuristics for :focus-visible may change a bit as
a result of the discussions in:

  * https://github.com/w3c/csswg-drafts/issues/5885
  * https://github.com/web-platform-tests/wpt/pull/27806

But it's not clear to me how to best define this so it works on the macOS focus
model.

An example of the third point:

    data:text/html,<input type=text><input type=submit><input type=text>

On Safari and Chrome (and Firefox on non-macOS platforms), clicking the button,
then pressing tab, goes to the input on the right. In Firefox on macOS it
doesn't because the button doesn't gain focus nor is selectable.

Differential Revision: https://phabricator.services.mozilla.com/D108808
This commit is contained in:
Emilio Cobos Álvarez 2021-03-17 22:34:55 +00:00
parent 8dcc772eea
commit 83d5691cbc
7 changed files with 11 additions and 82 deletions

View File

@ -128,7 +128,7 @@ function* tests() {
// Release.
sendMouseEvent("mouseup", label);
yield undefined;
var focusOnMouse = (navigator.platform.indexOf("Mac") != 0);
var focusOnMouse = navigator.platform.indexOf("Mac") != 0 || SpecialPowers.getBoolPref("accessibility.mouse_focuses_formcontrol");
compareSnapshots_(focusOnMouse ? normalFocusedButtonCanvas : normalButtonCanvas,
currentSnapshot, true, "Releasing the mouse over the label should have unpressed" +
(focusOnMouse ? " (and focused)" : "") + " the button.");

View File

@ -19,13 +19,7 @@ var result = "";
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(function() {
synthesizeMouseAtCenter(document.getElementById("button"), { });
if (/Mac/.test(navigator.platform)) {
// Buttons don't focus when clicked on Mac.
is(result, "", "Focus button then input");
}
else {
is(result, "(focus button)(blur button)(focus input)", "Focus button then input");
}
is(result, "(focus button)(blur button)(focus input)", "Focus button then input");
SimpleTest.finish();
});
</script>

View File

@ -14,8 +14,9 @@ if (navigator.platform.startsWith("Win")) {
}
SimpleTest.waitForExplicitFinish();
function runTest()
async function runTest()
{
await SpecialPowers.pushPrefEnv({"set": [['accessibility.mouse_focuses_formcontrol', false]]});
window.openDialog("window_focus.xhtml", "_blank", "chrome,width=600,height=550,noopener", window);
}
</script>

View File

@ -27,7 +27,11 @@ function snapShot(element) {
function initTest()
{
SpecialPowers.pushPrefEnv({"set": [['accessibility.tabfocus', 7]]}, runTest);
SpecialPowers.pushPrefEnv({
"set": [
['accessibility.mouse_focuses_formcontrol', false],
]
}, runTest);
}
function runTest()
@ -179,7 +183,7 @@ function testHTMLElements(list, isMac, expectedNoRingsOnWin)
}
}
SimpleTest.waitForFocus(runTest);
SimpleTest.waitForFocus(initTest);
]]>
</script>

View File

@ -720,7 +720,7 @@ pref("accessibility.force_disabled", 0);
pref("focusmanager.testmode", false);
pref("accessibility.usetexttospeech", "");
pref("accessibility.mouse_focuses_formcontrol", false);
pref("accessibility.mouse_focuses_formcontrol", true);
// Type Ahead Find
pref("accessibility.typeaheadfind", true);

View File

@ -1,39 +0,0 @@
[focus-visible-003.html]
expected:
if os == "mac": TIMEOUT
[Focus element BUTTON#el-4 via mouse should NOT match :focus-visible as it does NOT support keyboard input]
expected:
if os == "mac": TIMEOUT
[Focus element INPUT#el-10 via mouse should NOT match :focus-visible as it does NOT support keyboard input]
expected:
if os == "mac": NOTRUN
[Focus element INPUT#el-13 via mouse should NOT match :focus-visible as it does NOT support keyboard input]
expected:
if os == "mac": NOTRUN
[Focus element INPUT#el-8 via mouse should NOT match :focus-visible as it does NOT support keyboard input]
expected:
if os == "mac": NOTRUN
[Focus element INPUT#el-5 via mouse should NOT match :focus-visible as it does NOT support keyboard input]
expected:
if os == "mac": NOTRUN
[Focus element INPUT#el-7 via mouse should NOT match :focus-visible as it does NOT support keyboard input]
expected:
if os == "mac": NOTRUN
[Focus element INPUT#el-12 via mouse should NOT match :focus-visible as it does NOT support keyboard input]
expected:
if os == "mac": NOTRUN
[Focus element INPUT#el-9 via mouse should NOT match :focus-visible as it does NOT support keyboard input]
expected:
if os == "mac": NOTRUN
[Focus element INPUT#el-6 via mouse should NOT match :focus-visible as it does NOT support keyboard input]
expected:
if os == "mac": NOTRUN

View File

@ -1,31 +0,0 @@
[focus-visible-004.html]
expected:
if os == "mac": TIMEOUT
[Focus element BUTTON#el-4 via mouse should NOT match :focus-visible as it does NOT support keyboard input - not affected by "appearance: none"]
expected:
if os == "mac": TIMEOUT
[Focus element INPUT#el-5 via mouse should NOT match :focus-visible as it does NOT support keyboard input - not affected by "appearance: none"]
expected:
if os == "mac": NOTRUN
[Focus element INPUT#el-6 via mouse should NOT match :focus-visible as it does NOT support keyboard input - not affected by "appearance: none"]
expected:
if os == "mac": NOTRUN
[Focus element INPUT#el-7 via mouse should NOT match :focus-visible as it does NOT support keyboard input - not affected by "appearance: none"]
expected:
if os == "mac": NOTRUN
[Focus element INPUT#el-8 via mouse should NOT match :focus-visible as it does NOT support keyboard input - not affected by "appearance: none"]
expected:
if os == "mac": NOTRUN
[Focus element INPUT#el-10 via mouse should NOT match :focus-visible as it does NOT support keyboard input - not affected by "appearance: none"]
expected:
if os == "mac": NOTRUN
[Focus element INPUT#el-11 via mouse should NOT match :focus-visible as it does NOT support keyboard input - not affected by "appearance: none"]
expected:
if os == "mac": NOTRUN