Bug 1232918 - Map Windows Logo keys in Win/Linux to `Meta` and rename `OSLeft`/`OSRight` to `MetaLeft`/`MetaRight` r=smaug,webdriver-reviewers,jdescottes

When we implement `KeyboardEvent.key`, its value for Windows Logo key was
declared as `OS`, but now the spec declares it as `Meta`.

When we implement `KeyboardEvent.code`, its value for Windows Logo keys in
Win/Linux and Command keys in macOS are declared as `OSLeft`/`OSRight`, but
now the spec declares them as `MetaLeft`/`MetaRight`.

This patch remaps and renames them.

Differential Revision: https://phabricator.services.mozilla.com/D183481
This commit is contained in:
Masayuki Nakano 2023-08-04 00:10:12 +00:00
Родитель 0664d98bce
Коммит 035a69f44e
13 изменённых файлов: 71 добавлений и 99 удалений

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

@ -163,8 +163,9 @@ const TEST_CASES_EN = [
expectedKeyEvent: SHOULD_DELIVER_KEYDOWN,
result: {
key: "Meta",
code: "OSLeft",
code: "MetaLeft",
charCode: 0,
// Don't let web apps know pressing Command key on macOS
keyCode: KeyboardEvent.DOM_VK_WIN,
location: KeyboardEvent.DOM_KEY_LOCATION_LEFT,
altKey: false,
@ -182,40 +183,9 @@ const TEST_CASES_EN = [
expectedKeyEvent: SHOULD_DELIVER_KEYDOWN,
result: {
key: "Meta",
code: "OSRight",
charCode: 0,
keyCode: KeyboardEvent.DOM_VK_WIN,
location: KeyboardEvent.DOM_KEY_LOCATION_RIGHT,
altKey: false,
shiftKey: false,
ctrlKey: false,
altGraphKey: false,
},
},
{
key: "KEY_OS",
modifiers: { location: KeyboardEvent.DOM_KEY_LOCATION_LEFT, osKey: true },
expectedKeyEvent: SHOULD_DELIVER_KEYDOWN,
result: {
key: "OS",
code: "OSLeft",
charCode: 0,
keyCode: KeyboardEvent.DOM_VK_WIN,
location: KeyboardEvent.DOM_KEY_LOCATION_LEFT,
altKey: false,
shiftKey: false,
ctrlKey: false,
altGraphKey: false,
},
},
{
key: "KEY_OS",
modifiers: { location: KeyboardEvent.DOM_KEY_LOCATION_RIGHT, osKey: true },
expectedKeyEvent: SHOULD_DELIVER_KEYDOWN,
result: {
key: "OS",
code: "OSRight",
code: "MetaRight",
charCode: 0,
// Don't let web apps know pressing Command key on macOS
keyCode: KeyboardEvent.DOM_VK_WIN,
location: KeyboardEvent.DOM_KEY_LOCATION_RIGHT,
altKey: false,

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

@ -2814,8 +2814,8 @@ function runKeyTests()
{ code: "ControlLeft", location: KeyboardEvent.DOM_KEY_LOCATION_LEFT },
{ code: "ControlRight", location: KeyboardEvent.DOM_KEY_LOCATION_RIGHT },
{ code: "Enter", location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD },
{ code: "OSLeft", location: KeyboardEvent.DOM_KEY_LOCATION_LEFT },
{ code: "OSRight", location: KeyboardEvent.DOM_KEY_LOCATION_RIGHT },
{ code: "MetaLeft", location: KeyboardEvent.DOM_KEY_LOCATION_LEFT },
{ code: "MetaRight", location: KeyboardEvent.DOM_KEY_LOCATION_RIGHT },
{ code: "ShiftLeft", location: KeyboardEvent.DOM_KEY_LOCATION_LEFT },
{ code: "ShiftRight", location: KeyboardEvent.DOM_KEY_LOCATION_RIGHT },
{ code: "Space", location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD },
@ -2937,7 +2937,6 @@ function runKeyTests()
{ key: "PrintScreen", keyCode: KeyboardEvent.DOM_VK_PRINTSCREEN },
{ key: "Insert", keyCode: KeyboardEvent.DOM_VK_INSERT },
{ key: "Delete", keyCode: KeyboardEvent.DOM_VK_DELETE },
{ key: "OS", keyCode: KeyboardEvent.DOM_VK_WIN, isModifier: true },
{ key: "ContextMenu", keyCode: KeyboardEvent.DOM_VK_CONTEXT_MENU },
{ key: "F1", keyCode: KeyboardEvent.DOM_VK_F1 },
{ key: "F2", keyCode: KeyboardEvent.DOM_VK_F2 },
@ -2968,7 +2967,9 @@ function runKeyTests()
{ key: "AudioVolumeMute", keyCode: KeyboardEvent.DOM_VK_VOLUME_MUTE },
{ key: "AudioVolumeDown", keyCode: KeyboardEvent.DOM_VK_VOLUME_DOWN },
{ key: "AudioVolumeUp", keyCode: KeyboardEvent.DOM_VK_VOLUME_UP },
{ key: "Meta", keyCode: KeyboardEvent.DOM_VK_META, isModifier: true },
{ key: "Meta", keyCode: kIsMac
? KeyboardEvent.DOM_VK_META
: KeyboardEvent.DOM_VK_WIN, isModifier: true },
{ key: "AltGraph", keyCode: KeyboardEvent.DOM_VK_ALTGR, isModifier: true },
{ key: "Attn", keyCode: KeyboardEvent.DOM_VK_ATTN },
{ key: "CrSel", keyCode: KeyboardEvent.DOM_VK_CRSEL },
@ -3048,8 +3049,8 @@ function runKeyTests()
{ key: "Control", code: "ControlRight", isLockable: false },
{ key: "Fn", code: "Fn", isLockable: false },
{ key: "FnLock", code: "", isLockable: true },
{ key: "Meta", code: "OSLeft", isLockable: false },
{ key: "Meta", code: "OSRight", isLockable: false },
{ key: "Meta", code: "MetaLeft", isLockable: false },
{ key: "Meta", code: "MetaRight", isLockable: false },
{ key: "NumLock", code: "NumLock", isLockable: true },
{ key: "ScrollLock", code: "ScrollLock", isLockable: true },
{ key: "Shift", code: "ShiftLeft", isLockable: false },

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

@ -43,7 +43,6 @@ DEFINE_KEYNAME_WITH_SAME_NAME(FnLock)
DEFINE_KEYNAME_WITH_SAME_NAME(Hyper)
DEFINE_KEYNAME_WITH_SAME_NAME(Meta)
DEFINE_KEYNAME_WITH_SAME_NAME(NumLock)
DEFINE_KEYNAME_WITH_SAME_NAME(OS) // Dropped from the latest draft, bug 1232918
DEFINE_KEYNAME_WITH_SAME_NAME(ScrollLock)
DEFINE_KEYNAME_WITH_SAME_NAME(Shift)
DEFINE_KEYNAME_WITH_SAME_NAME(Super)

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

@ -85,8 +85,8 @@ DEFINE_PHYSICAL_KEY_CODE_NAME_WITH_SAME_NAME(ContextMenu)
DEFINE_PHYSICAL_KEY_CODE_NAME_WITH_SAME_NAME(ControlLeft)
DEFINE_PHYSICAL_KEY_CODE_NAME_WITH_SAME_NAME(ControlRight)
DEFINE_PHYSICAL_KEY_CODE_NAME_WITH_SAME_NAME(Enter)
DEFINE_PHYSICAL_KEY_CODE_NAME_WITH_SAME_NAME(OSLeft)
DEFINE_PHYSICAL_KEY_CODE_NAME_WITH_SAME_NAME(OSRight)
DEFINE_PHYSICAL_KEY_CODE_NAME_WITH_SAME_NAME(MetaLeft)
DEFINE_PHYSICAL_KEY_CODE_NAME_WITH_SAME_NAME(MetaRight)
DEFINE_PHYSICAL_KEY_CODE_NAME_WITH_SAME_NAME(ShiftLeft)
DEFINE_PHYSICAL_KEY_CODE_NAME_WITH_SAME_NAME(ShiftRight)
DEFINE_PHYSICAL_KEY_CODE_NAME_WITH_SAME_NAME(Space)

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

@ -176,7 +176,7 @@ const KEY_DATA = {
"\uE03B": { code: "F11", key: "F11", printable: false },
"\uE03C": { code: "F12", key: "F12", printable: false },
"\uE03D": {
code: "OSLeft",
code: "MetaLeft",
key: "Meta",
location: 1,
modifier: "metaKey",
@ -205,7 +205,7 @@ const KEY_DATA = {
printable: false,
},
"\uE053": {
code: "OSRight",
code: "MetaRight",
key: "Meta",
location: 2,
modifier: "metaKey",

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

@ -16,3 +16,15 @@
[test_keyup_only_sends_no_events]
expected: FAIL
[test_key_modifier_key[\\ue03d-META\]]
expected: FAIL
[test_key_modifier_key[\\ue053-R_META\]]
expected: FAIL
[test_key_special_key_sends_keydown[META-expected30\]]
expected: FAIL
[test_key_special_key_sends_keydown[R_META-expected58\]]
expected: FAIL

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

@ -0,0 +1,12 @@
[key_events.py]
[test_modifier_key_sends_correct_events[\\ue03d-META\]]
expected: FAIL
[test_modifier_key_sends_correct_events[\\ue053-R_META\]]
expected: FAIL
[test_special_key_sends_keydown[META-expected30\]]
expected: FAIL
[test_special_key_sends_keydown[R_META-expected58\]]
expected: FAIL

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

@ -51,8 +51,7 @@ CONTROL(Escape, Escape, dom::KeyboardEvent_Binding::DOM_VK_ESCAPE)
// Leaving "Help" key unimplemented; it only appears in some keyboard in Linux.
CONTROL(Home, Home, dom::KeyboardEvent_Binding::DOM_VK_HOME)
CONTROL(Insert, Insert, dom::KeyboardEvent_Binding::DOM_VK_INSERT)
CONTROL(Meta, OSLeft, dom::KeyboardEvent_Binding::DOM_VK_WIN)
CONTROL(OS, OSLeft, dom::KeyboardEvent_Binding::DOM_VK_WIN)
CONTROL(Meta, MetaLeft, dom::KeyboardEvent_Binding::DOM_VK_WIN)
CONTROL(PageDown, PageDown, dom::KeyboardEvent_Binding::DOM_VK_PAGE_DOWN)
CONTROL(PageUp, PageUp, dom::KeyboardEvent_Binding::DOM_VK_PAGE_UP)
// Leaving "Pause", "PrintScreen" and "ScrollLock" keys unimplemented; they are

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

@ -347,15 +347,15 @@ CODE_MAP_MAC(Enter, kVK_Return)
CODE_MAP_X11(Enter, 0x0024)
CODE_MAP_ANDROID(Enter, 0x001C)
CODE_MAP_WIN(OSLeft, 0xE05B)
CODE_MAP_MAC(OSLeft, kVK_Command)
CODE_MAP_X11(OSLeft, 0x0085)
CODE_MAP_ANDROID(OSLeft, 0x007D)
CODE_MAP_WIN(MetaLeft, 0xE05B)
CODE_MAP_MAC(MetaLeft, kVK_Command)
CODE_MAP_X11(MetaLeft, 0x0085)
CODE_MAP_ANDROID(MetaLeft, 0x007D)
CODE_MAP_WIN(OSRight, 0xE05C)
CODE_MAP_MAC(OSRight, kVK_RightCommand)
CODE_MAP_X11(OSRight, 0x0086)
CODE_MAP_ANDROID(OSRight, 0x007E)
CODE_MAP_WIN(MetaRight, 0xE05C)
CODE_MAP_MAC(MetaRight, kVK_RightCommand)
CODE_MAP_X11(MetaRight, 0x0086)
CODE_MAP_ANDROID(MetaRight, 0x007E)
CODE_MAP_WIN(ShiftLeft, 0x002A)
CODE_MAP_MAC(ShiftLeft, kVK_Shift)

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

@ -94,6 +94,8 @@ KEY_MAP_COCOA(Alt, kVK_Option)
KEY_MAP_COCOA(Alt, kVK_RightOption)
KEY_MAP_GTK(Alt, GDK_Alt_L)
KEY_MAP_GTK(Alt, GDK_Alt_R)
KEY_MAP_GTK(Alt, GDK_Meta_L)
KEY_MAP_GTK(Alt, GDK_Meta_R)
KEY_MAP_ANDROID(Alt, AKEYCODE_ALT_LEFT)
KEY_MAP_ANDROID(Alt, AKEYCODE_ALT_RIGHT)
@ -133,10 +135,14 @@ KEY_MAP_COCOA(Fn, kVK_Function)
KEY_MAP_ANDROID(Fn, AKEYCODE_FUNCTION)
// Meta
KEY_MAP_WIN(Meta, VK_LWIN)
KEY_MAP_WIN(Meta, VK_RWIN)
KEY_MAP_COCOA(Meta, kVK_Command)
KEY_MAP_COCOA(Meta, kVK_RightCommand)
KEY_MAP_GTK(Meta, GDK_Meta_L)
KEY_MAP_GTK(Meta, GDK_Meta_R)
KEY_MAP_GTK(Meta, GDK_Super_L)
KEY_MAP_GTK(Meta, GDK_Super_R)
KEY_MAP_GTK(Meta, GDK_Hyper_L)
KEY_MAP_GTK(Meta, GDK_Hyper_R)
KEY_MAP_ANDROID(Meta, AKEYCODE_META_LEFT)
KEY_MAP_ANDROID(Meta, AKEYCODE_META_RIGHT)
@ -145,14 +151,6 @@ KEY_MAP_WIN(NumLock, VK_NUMLOCK)
KEY_MAP_GTK(NumLock, GDK_Num_Lock)
KEY_MAP_ANDROID(NumLock, AKEYCODE_NUM_LOCK)
// OS
KEY_MAP_WIN(OS, VK_LWIN)
KEY_MAP_WIN(OS, VK_RWIN)
KEY_MAP_GTK(OS, GDK_Super_L)
KEY_MAP_GTK(OS, GDK_Super_R)
KEY_MAP_GTK(OS, GDK_Hyper_L)
KEY_MAP_GTK(OS, GDK_Hyper_R)
// ScrollLock
KEY_MAP_WIN(ScrollLock, VK_SCROLL)
KEY_MAP_GTK(ScrollLock, GDK_Scroll_Lock)

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

@ -344,8 +344,6 @@ class WidgetKeyboardEvent final : public WidgetInputEvent {
// legacy modifier keys:
case KEY_NAME_INDEX_Hyper:
case KEY_NAME_INDEX_Super:
// obsolete modifier key:
case KEY_NAME_INDEX_OS:
return false;
default:
return true;
@ -708,7 +706,6 @@ class WidgetKeyboardEvent final : public WidgetInputEvent {
case KEY_NAME_INDEX_Alt:
case KEY_NAME_INDEX_Control:
case KEY_NAME_INDEX_Meta:
case KEY_NAME_INDEX_OS:
case KEY_NAME_INDEX_Shift:
return true;
default:

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

@ -906,7 +906,6 @@ bool WidgetKeyboardEvent::ShouldCauseKeypressEvents() const {
// case KEY_NAME_INDEX_Hyper:
case KEY_NAME_INDEX_Meta:
case KEY_NAME_INDEX_NumLock:
case KEY_NAME_INDEX_OS:
case KEY_NAME_INDEX_ScrollLock:
case KEY_NAME_INDEX_Shift:
// case KEY_NAME_INDEX_Super:
@ -1299,12 +1298,12 @@ uint32_t WidgetKeyboardEvent::ComputeLocationFromCodeValue(
switch (aCodeNameIndex) {
case CODE_NAME_INDEX_AltLeft:
case CODE_NAME_INDEX_ControlLeft:
case CODE_NAME_INDEX_OSLeft:
case CODE_NAME_INDEX_MetaLeft:
case CODE_NAME_INDEX_ShiftLeft:
return eKeyLocationLeft;
case CODE_NAME_INDEX_AltRight:
case CODE_NAME_INDEX_ControlRight:
case CODE_NAME_INDEX_OSRight:
case CODE_NAME_INDEX_MetaRight:
case CODE_NAME_INDEX_ShiftRight:
return eKeyLocationRight;
case CODE_NAME_INDEX_Numpad0:
@ -1422,10 +1421,6 @@ uint32_t WidgetKeyboardEvent::ComputeKeyCodeFromKeyNameIndex(
return dom::KeyboardEvent_Binding::DOM_VK_INSERT;
case KEY_NAME_INDEX_Delete:
return dom::KeyboardEvent_Binding::DOM_VK_DELETE;
case KEY_NAME_INDEX_OS:
// case KEY_NAME_INDEX_Super:
// case KEY_NAME_INDEX_Hyper:
return dom::KeyboardEvent_Binding::DOM_VK_WIN;
case KEY_NAME_INDEX_ContextMenu:
return dom::KeyboardEvent_Binding::DOM_VK_CONTEXT_MENU;
case KEY_NAME_INDEX_Standby:
@ -1489,7 +1484,11 @@ uint32_t WidgetKeyboardEvent::ComputeKeyCodeFromKeyNameIndex(
case KEY_NAME_INDEX_AudioVolumeUp:
return dom::KeyboardEvent_Binding::DOM_VK_VOLUME_UP;
case KEY_NAME_INDEX_Meta:
#if defined(XP_WIN) || defined(MOZ_WIDGET_GTK)
return dom::KeyboardEvent_Binding::DOM_VK_WIN;
#else
return dom::KeyboardEvent_Binding::DOM_VK_META;
#endif
case KEY_NAME_INDEX_AltGraph:
return dom::KeyboardEvent_Binding::DOM_VK_ALTGR;
case KEY_NAME_INDEX_Process:
@ -1573,22 +1572,8 @@ CodeNameIndex WidgetKeyboardEvent::ComputeCodeNameIndexFromKeyNameIndex(
: CODE_NAME_INDEX_ControlLeft;
case KEY_NAME_INDEX_Shift:
return isRight ? CODE_NAME_INDEX_ShiftRight : CODE_NAME_INDEX_ShiftLeft;
#if defined(XP_WIN)
case KEY_NAME_INDEX_Meta:
return CODE_NAME_INDEX_UNKNOWN;
case KEY_NAME_INDEX_OS: // win key.
return isRight ? CODE_NAME_INDEX_OSRight : CODE_NAME_INDEX_OSLeft;
#elif defined(XP_MACOSX) || defined(ANDROID)
case KEY_NAME_INDEX_Meta: // command key.
return isRight ? CODE_NAME_INDEX_OSRight : CODE_NAME_INDEX_OSLeft;
case KEY_NAME_INDEX_OS:
return CODE_NAME_INDEX_UNKNOWN;
#else
case KEY_NAME_INDEX_Meta: // Alt + Shift.
return isRight ? CODE_NAME_INDEX_AltRight : CODE_NAME_INDEX_AltLeft;
case KEY_NAME_INDEX_OS: // Super/Hyper key.
return isRight ? CODE_NAME_INDEX_OSRight : CODE_NAME_INDEX_OSLeft;
#endif
return isRight ? CODE_NAME_INDEX_MetaRight : CODE_NAME_INDEX_MetaLeft;
default:
return CODE_NAME_INDEX_UNKNOWN;
}

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

@ -123,10 +123,10 @@ function eventToString(aEvent)
name += " [Right Alt]";
}
if (aEvent.modifiers.metaKey) {
name += " [Command]";
name += ` [${IS_MAC ? "Command" : "Win"}]`;
}
if (aEvent.modifiers.metaRightKey) {
name += " [Right Command]";
name += ` [Right ${IS_MAC ? "Command" : "Win"}]`;
}
return name;
@ -446,7 +446,6 @@ function* runKeyEventTests()
case "Alt":
case "AltGraph":
case "Meta":
case "OS":
case "CapsLock":
case "NumLock":
// XXX To check modifier state of modifiers, we need to check
@ -669,16 +668,16 @@ function* runKeyEventTests()
// Command/RightCommand key event
yield testKey({layout:KEYBOARD_LAYOUT_EN_US, keyCode:MAC_VK_Command,
modifiers:{metaKey:1}, chars:"", unmodifiedChars:""},
"Meta", "OSLeft", KeyboardEvent.DOM_VK_META, "", SHOULD_DELIVER_KEYDOWN, KeyboardEvent.DOM_KEY_LOCATION_LEFT);
"Meta", "MetaLeft", KeyboardEvent.DOM_VK_META, "", SHOULD_DELIVER_KEYDOWN, KeyboardEvent.DOM_KEY_LOCATION_LEFT);
yield testKey({layout:KEYBOARD_LAYOUT_EN_US, keyCode:MAC_VK_Command,
modifiers:{metaKey:0}, chars:"", unmodifiedChars:""},
"Meta", "OSLeft", KeyboardEvent.DOM_VK_META, "", SHOULD_DELIVER_KEYUP, KeyboardEvent.DOM_KEY_LOCATION_LEFT);
"Meta", "MetaLeft", KeyboardEvent.DOM_VK_META, "", SHOULD_DELIVER_KEYUP, KeyboardEvent.DOM_KEY_LOCATION_LEFT);
yield testKey({layout:KEYBOARD_LAYOUT_EN_US, keyCode:MAC_VK_RightCommand,
modifiers:{metaRightKey:1}, chars:"", unmodifiedChars:""},
"Meta", "OSRight", KeyboardEvent.DOM_VK_META, "", SHOULD_DELIVER_KEYDOWN, KeyboardEvent.DOM_KEY_LOCATION_RIGHT);
"Meta", "MetaRight", KeyboardEvent.DOM_VK_META, "", SHOULD_DELIVER_KEYDOWN, KeyboardEvent.DOM_KEY_LOCATION_RIGHT);
yield testKey({layout:KEYBOARD_LAYOUT_EN_US, keyCode:MAC_VK_RightCommand,
modifiers:{metaRightKey:0}, chars:"", unmodifiedChars:""},
"Meta", "OSRight", KeyboardEvent.DOM_VK_META, "", SHOULD_DELIVER_KEYUP, KeyboardEvent.DOM_KEY_LOCATION_RIGHT);
"Meta", "MetaRight", KeyboardEvent.DOM_VK_META, "", SHOULD_DELIVER_KEYUP, KeyboardEvent.DOM_KEY_LOCATION_RIGHT);
// all keys on keyboard (keyCode test)
yield testKey({layout:KEYBOARD_LAYOUT_EN_US, keyCode:MAC_VK_Tab,
@ -2997,10 +2996,10 @@ function* runKeyEventTests()
// Win keys
yield testKey({layout:KEYBOARD_LAYOUT_EN_US, keyCode:WIN_VK_LWIN,
modifiers:{metaKey:1}, chars:""},
"OS" /* bug 1232918 */, "OSLeft", KeyboardEvent.DOM_VK_WIN, "", SHOULD_DELIVER_KEYDOWN_KEYUP, KeyboardEvent.DOM_KEY_LOCATION_LEFT);
"Meta", "MetaLeft", KeyboardEvent.DOM_VK_WIN, "", SHOULD_DELIVER_KEYDOWN_KEYUP, KeyboardEvent.DOM_KEY_LOCATION_LEFT);
yield testKey({layout:KEYBOARD_LAYOUT_EN_US, keyCode:WIN_VK_RWIN,
modifiers:{metaRightKey:1}, chars:""},
"OS" /* bug 1232918 */, "OSRight", KeyboardEvent.DOM_VK_WIN, "", SHOULD_DELIVER_KEYDOWN_KEYUP, KeyboardEvent.DOM_KEY_LOCATION_RIGHT);
"Meta", "MetaRight", KeyboardEvent.DOM_VK_WIN, "", SHOULD_DELIVER_KEYDOWN_KEYUP, KeyboardEvent.DOM_KEY_LOCATION_RIGHT);
// all keys on keyboard (keyCode test)
yield testKey({layout:KEYBOARD_LAYOUT_EN_US, keyCode:WIN_VK_BACK,