Skip to content

Commit

Permalink
Bug 1614658 - Enable accessibility.mouse_focuses_formcontrol by defau…
Browse files Browse the repository at this point in the history
…lt. 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:

  * w3c/csswg-drafts#5885
  * web-platform-tests/wpt#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
  • Loading branch information
emilio committed Mar 17, 2021
1 parent 8dcc772 commit 83d5691
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 82 deletions.
2 changes: 1 addition & 1 deletion dom/events/test/bug656379-1.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
// 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.");
Expand Down
8 changes: 1 addition & 7 deletions dom/html/test/test_focusshift_button.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,7 @@
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>
Expand Down
3 changes: 2 additions & 1 deletion dom/tests/mochitest/chrome/test_focus.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
8 changes: 6 additions & 2 deletions dom/tests/mochitest/general/test_focusrings.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -179,7 +183,7 @@ function testHTMLElements(list, isMac, expectedNoRingsOnWin)
}
}

SimpleTest.waitForFocus(runTest);
SimpleTest.waitForFocus(initTest);

]]>
</script>
Expand Down
2 changes: 1 addition & 1 deletion modules/libpref/init/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
39 changes: 0 additions & 39 deletions testing/web-platform/meta/css/selectors/focus-visible-003.html.ini

This file was deleted.

31 changes: 0 additions & 31 deletions testing/web-platform/meta/css/selectors/focus-visible-004.html.ini

This file was deleted.

0 comments on commit 83d5691

Please sign in to comment.