Google suggested that browsers shouldn't set ctrlKey and altKey to true for keyboard events during AltGr key is pressed on Windows. We will follow the new behavior for compatibility with Chromium and better accessibility for some language users.
https://github.com/w3c/uievents/issues/147

Background: On Windows, AltGr key is mapped to AltRight key by some keyboard layouts. However, Windows represents AltGraph state with both Control and Alt modifier states. For example, if user cannot use AltRight key (e.g., there is no AltRight key), user can emulate it with pressing both Ctrl and Alt keys. Another example, when user presses AltGr key, ControlLeft keydown and AltRight keydown are fired, and when user releases it, CtrlLeft keyup and AltRight keyup are fired.

Firefox, Chrome and Edge set ctrlKey and altKey to true when getModifierState("AltGraph") returns true. However, web apps cannot distinguish whether given keydown event will input some characters strictly. So, if both ctrlKey and altKey are set to false when user types some character(s) even with AltGr key, the keys won't be handled as shortcut key on the web apps. The new behavior improves accessibility of users who use keyboard layout which has AltGr key, especially when they use different locale's web apps.

When user presses a key with AltGr key to input a character, Gecko has dispatched:

1. keydown for ControlLeft whose ctrlKey is true.
2. keydown for AltRight whose ctrlKey and altKey are true and getModifierState("AltGraph") returns true. 3. keydown for the key whose ctrlKey and altKey are true and getModifierState("AltGraph") returns true. 4. keypress for the key whose ctrlKey and altKey are *false* and getModifierState("AltGraph") returns true. 5. keyup for the key whose ctrlKey and altKey are true and getModifierState("AltGraph") returns true.
6. keyup for ControlLeft whose altKey is true.
7. keyup for AltRight (currently, this is not fired due regression of e10s <https://bugzilla.mozilla.org/show_bug.cgi?id=1435717>)

This becomes:

1. keydown for ControlLeft whose ctrlKey is true.
2. keydown for AltRight whose ctrlKey and altKey are *false* and getModifierState("AltGraph") returns true. 3. keydown for the key whose ctrlKey and altKey are *false* and getModifierState("AltGraph") returns true. 4. keypress for the key whose ctrlKey and altKey are false and getModifierState("AltGraph") returns true. 5. keyup for the key whose ctrlKey and altKey are *false* and getModifierState("AltGraph") returns true. 6. keyup for ControlLeft whose altKey is *false* but getModifierState("AltGraph") returns *true*.
7. keyup for AltRight

Additionally, KeyboardEvent.key value for AltRight key becomes "AltGraph" instead of "Alt" (but KeyboardEvent.keyCode won't be changed for backward compatibility).

When user types a character with emulating AltGr with ControlLeft and AltLeft keys:

1. keydown for ControlLeft whose ctrlKey is true.
2. keydown for AltLeft whose ctrlKey and altKey are *true* and getModifierState("AltGraph") returns *false*. 3. keydown for the key whose ctrlKey and altKey are *false* and getModifierState("AltGraph") returns *true*. 4. keypress for the key whose ctrlKey and altKey are false and getModifierState("AltGraph") returns true. 5. keyup for the key whose ctrlKey and altKey are *false* and getModifierState("AltGraph") returns true. 6. keyup for ControlLeft whose altKey is *true* and also getModifierState("AltGraph") returns *false*.
7. keyup for AltRight

If the key produces no character when emulating AltGr key press with Ctrl and Alt keys, its keydown and keyup event's ctrlKey and altKey are set to *true* and getModifierState("AltGraph") returns false.

In other words, if user emulates AltGr key, only printable key's events are changed. So, when a key does not input any characters with AltGraph state, the key combinations can be handled as shortcut keys. Although any web apps and extensions shouldn't use Control - Alt combination for shortcut keys at least on Windows.

Note that if active keyboard layout does not have AltGr key, getModifierState("AltGraph") always returns false (even if both Ctrl and Alt are pressed).

The bug: https://bugzilla.mozilla.org/show_bug.cgi?id=900750
Target: Firefox 62 or 63.

Chrome has started to release new behavior with 67. And starting from 68, they will switch this behavior permanently.

--
Masayuki Nakano <masay...@d-toybox.com>
Software Engineer, Mozilla
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to