[iOS] Numpad comma key has incorrect keyIdentifier property
https://bugs.webkit.org/show_bug.cgi?id=197753
<rdar://problem/50636274>

Reviewed by Brent Fulgham.

Source/WebCore:

Map the Numpad Comma HID usage code to its Window virtual key code, VK_SEPARATOR,
so that can compute the keyIdentifier property for the Numpad Comma key. Also
consider this key as a keypad key just like we do on Mac. There is no discernable
difference for doing so on iOS because the non-keypad code path computes the same result
due to GraphicsServices having fixed up the input string for the Numpad Comma to be
",", which is want.

* platform/ios/KeyEventIOS.mm:
(WebCore::windowsKeyCodeForKeyCode): Map kHIDUsage_KeypadComma to VK_SEPARATOR.
* platform/ios/PlatformEventFactoryIOS.mm:
(WebCore::codeForKeyEvent): Add a comment to explain that this key is only on
JIS keyboards.
(WebCore::isKeypadEvent): Return true for the Numpad Comma key.

Source/WebCore/PAL:

Expose enumerator for Numpad Comma.

* pal/spi/cocoa/IOKitSPI.h:

Tools:

Recognize "numpadComma" and return the appropriate HID usage code.

* WebKitTestRunner/ios/HIDEventGenerator.mm:
(hidUsageCodeForCharacter):

LayoutTests:

Update test results.

* fast/events/ios/keydown-keyup-special-keys-in-non-editable-element-expected.txt:
* fast/events/ios/keydown-keyup-special-keys-in-non-editable-element.html:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@245161 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 93408f4..2fad6d8 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,16 @@
+2019-05-09  Daniel Bates  <dabates@apple.com>
+
+        [iOS] Numpad comma key has incorrect keyIdentifier property
+        https://bugs.webkit.org/show_bug.cgi?id=197753
+        <rdar://problem/50636274>
+
+        Reviewed by Brent Fulgham.
+
+        Update test results.
+
+        * fast/events/ios/keydown-keyup-special-keys-in-non-editable-element-expected.txt:
+        * fast/events/ios/keydown-keyup-special-keys-in-non-editable-element.html:
+
 2019-05-08  Zalan Bujtas  <zalan@apple.com>
 
         Do not mix inline and block level boxes.
diff --git a/LayoutTests/fast/events/ios/keydown-keyup-special-keys-in-non-editable-element-expected.txt b/LayoutTests/fast/events/ios/keydown-keyup-special-keys-in-non-editable-element-expected.txt
index 84fc32e..400e289 100644
--- a/LayoutTests/fast/events/ios/keydown-keyup-special-keys-in-non-editable-element-expected.txt
+++ b/LayoutTests/fast/events/ios/keydown-keyup-special-keys-in-non-editable-element-expected.txt
@@ -1,4 +1,4 @@
-This tests that DOM keydown and keyup events are dispatched to a non-editable <body> on iOS when pressing special keys on a hardware keyboard. To run this test manually, verify that two messages are emitted when you press the following keys: Tab, ↑, ↓, ←, →, Delete, End, Enter, Escape, Home, left Alt, left ⌘ Command, left Ctrl, left ⇧ Shift, Page Down, Page Up, Return, right Alt, right ⌘ Command, right Ctrl, right ⇧ Shift, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, F14, F15, F16.
+This tests that DOM keydown and keyup events are dispatched to a non-editable <body> on iOS when pressing special keys on a hardware keyboard. To run this test manually, verify that two messages are emitted when you press the following keys: Tab, ↑, ↓, ←, →, Delete, End, Enter, Escape, Home, left Alt, left ⌘ Command, left Ctrl, left ⇧ Shift, Page Down, Page Up, Return, right Alt, right ⌘ Command, right Ctrl, right ⇧ Shift, Numpad ,, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, F14, F15, F16.
 
 type: keydown, key: Tab, code: Tab, keyIdentifier: U+0009, keyCode: 9, charCode: 0, keyCode: 9, which: 9
 type: keyup, key: Dead, code: Tab, keyIdentifier: Unidentified, keyCode: 9, charCode: 0, keyCode: 9, which: 9
@@ -44,6 +44,8 @@
 type: keyup, key: Control, code: ControlRight, keyIdentifier: Control, keyCode: 17, charCode: 0, keyCode: 17, which: 17
 type: keydown, key: Shift, code: ShiftRight, keyIdentifier: Shift, keyCode: 16, charCode: 0, keyCode: 16, which: 16
 type: keyup, key: Shift, code: ShiftRight, keyIdentifier: Shift, keyCode: 16, charCode: 0, keyCode: 16, which: 16
+type: keydown, key: ,, code: NumpadComma, keyIdentifier: U+002C, keyCode: 108, charCode: 0, keyCode: 108, which: 108
+type: keyup, key: ,, code: NumpadComma, keyIdentifier: U+002C, keyCode: 108, charCode: 0, keyCode: 108, which: 108
 type: keydown, key: , code: F1, keyIdentifier: U+0010, keyCode: 112, charCode: 0, keyCode: 112, which: 112
 type: keyup, key: Dead, code: F1, keyIdentifier: Unidentified, keyCode: 112, charCode: 0, keyCode: 112, which: 112
 type: keydown, key: , code: F2, keyIdentifier: U+0010, keyCode: 113, charCode: 0, keyCode: 113, which: 113
diff --git a/LayoutTests/fast/events/ios/keydown-keyup-special-keys-in-non-editable-element.html b/LayoutTests/fast/events/ios/keydown-keyup-special-keys-in-non-editable-element.html
index a824482..2f5332a 100644
--- a/LayoutTests/fast/events/ios/keydown-keyup-special-keys-in-non-editable-element.html
+++ b/LayoutTests/fast/events/ios/keydown-keyup-special-keys-in-non-editable-element.html
@@ -12,7 +12,7 @@
 </script>
 </head>
 <body onkeydown="handleKeyDown(event)" onkeyup="handleKeyUp(event)">
-<p>This tests that DOM keydown and keyup events are dispatched to a non-editable &lt;body&gt; on iOS when pressing special keys on a hardware keyboard. To run this test manually, verify that two messages are emitted when you press the following keys: <kbd>Tab</kbd>, <kbd>↑</kbd>, <kbd>↓</kbd>, <kbd>←</kbd>, <kbd>→</kbd>, <kbd>Delete</kbd>, <kbd>End</kbd>, <kbd>Enter</kbd>, <kbd>Escape</kbd>, <kbd>Home</kbd><!-- FIXME: Add <kbd>Insert</kbd> once <rdar://problem/47128940> is fixed. -->, left <kbd>Alt</kbd>, left <kbd>⌘ Command</kbd>, left <kbd>Ctrl</kbd>, left <kbd>⇧ Shift</kbd>, <kbd>Page Down</kbd>, <kbd>Page Up</kbd>, <kbd>Return</kbd>, right <kbd>Alt</kbd>, right <kbd>⌘ Command</kbd>, right <kbd>Ctrl</kbd>, right <kbd>⇧ Shift</kbd>, <kbd>F1</kbd>, <kbd>F2</kbd>, <kbd>F3</kbd>, <kbd>F4</kbd>, <kbd>F5</kbd>, <kbd>F6</kbd>, <kbd>F7</kbd>, <kbd>F8</kbd>, <kbd>F9</kbd>, <kbd>F10</kbd>, <kbd>F11</kbd>, <kbd>F12</kbd>, <kbd>F13</kbd>, <kbd>F14</kbd>, <kbd>F15</kbd>, <kbd>F16</kbd><!-- FIXME: Add <kbd>F17</kbd>, <kbd>F18</kbd>, <kbd>F19</kbd>, <kbd>F20</kbd>, <kbd>F21</kbd>, <kbd>F22</kbd>, <kbd>F23</kbd>, <kbd>F24</kbd> once <rdar://problem/47128940> is fixed.-->.
+<p>This tests that DOM keydown and keyup events are dispatched to a non-editable &lt;body&gt; on iOS when pressing special keys on a hardware keyboard. To run this test manually, verify that two messages are emitted when you press the following keys: <kbd>Tab</kbd>, <kbd>↑</kbd>, <kbd>↓</kbd>, <kbd>←</kbd>, <kbd>→</kbd>, <kbd>Delete</kbd>, <kbd>End</kbd>, <kbd>Enter</kbd>, <kbd>Escape</kbd>, <kbd>Home</kbd><!-- FIXME: Add <kbd>Insert</kbd> once <rdar://problem/47128940> is fixed. -->, left <kbd>Alt</kbd>, left <kbd>⌘ Command</kbd>, left <kbd>Ctrl</kbd>, left <kbd>⇧ Shift</kbd>, <kbd>Page Down</kbd>, <kbd>Page Up</kbd>, <kbd>Return</kbd>, right <kbd>Alt</kbd>, right <kbd>⌘ Command</kbd>, right <kbd>Ctrl</kbd>, right <kbd>⇧ Shift</kbd>, <kbd>Numpad ,</kbd>, </kbd><kbd>F1</kbd>, <kbd>F2</kbd>, <kbd>F3</kbd>, <kbd>F4</kbd>, <kbd>F5</kbd>, <kbd>F6</kbd>, <kbd>F7</kbd>, <kbd>F8</kbd>, <kbd>F9</kbd>, <kbd>F10</kbd>, <kbd>F11</kbd>, <kbd>F12</kbd>, <kbd>F13</kbd>, <kbd>F14</kbd>, <kbd>F15</kbd>, <kbd>F16</kbd><!-- FIXME: Add <kbd>F17</kbd>, <kbd>F18</kbd>, <kbd>F19</kbd>, <kbd>F20</kbd>, <kbd>F21</kbd>, <kbd>F22</kbd>, <kbd>F23</kbd>, <kbd>F24</kbd> once <rdar://problem/47128940> is fixed.-->.
 </p>
 <pre id="console"></pre>
 <script>
@@ -39,6 +39,7 @@
     "rightCommand",
     "rightControl",
     "rightShift",
+    "numpadComma",
 ];
 
 // FIXME: Check function keys up to F24 once <rdar://problem/47128940> is fixed.
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index 7de812b..ea70ef1 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,25 @@
+2019-05-09  Daniel Bates  <dabates@apple.com>
+
+        [iOS] Numpad comma key has incorrect keyIdentifier property
+        https://bugs.webkit.org/show_bug.cgi?id=197753
+        <rdar://problem/50636274>
+
+        Reviewed by Brent Fulgham.
+
+        Map the Numpad Comma HID usage code to its Window virtual key code, VK_SEPARATOR,
+        so that can compute the keyIdentifier property for the Numpad Comma key. Also
+        consider this key as a keypad key just like we do on Mac. There is no discernable
+        difference for doing so on iOS because the non-keypad code path computes the same result
+        due to GraphicsServices having fixed up the input string for the Numpad Comma to be
+        ",", which is want.
+
+        * platform/ios/KeyEventIOS.mm:
+        (WebCore::windowsKeyCodeForKeyCode): Map kHIDUsage_KeypadComma to VK_SEPARATOR.
+        * platform/ios/PlatformEventFactoryIOS.mm:
+        (WebCore::codeForKeyEvent): Add a comment to explain that this key is only on
+        JIS keyboards.
+        (WebCore::isKeypadEvent): Return true for the Numpad Comma key.
+
 2019-05-09  Zalan Bujtas  <zalan@apple.com>
 
         Do not mix inline and block level boxes.
diff --git a/Source/WebCore/PAL/ChangeLog b/Source/WebCore/PAL/ChangeLog
index 3d9f182..61521bb 100644
--- a/Source/WebCore/PAL/ChangeLog
+++ b/Source/WebCore/PAL/ChangeLog
@@ -1,3 +1,15 @@
+2019-05-09  Daniel Bates  <dabates@apple.com>
+
+        [iOS] Numpad comma key has incorrect keyIdentifier property
+        https://bugs.webkit.org/show_bug.cgi?id=197753
+        <rdar://problem/50636274>
+
+        Reviewed by Brent Fulgham.
+
+        Expose enumerator for Numpad Comma.
+
+        * pal/spi/cocoa/IOKitSPI.h:
+
 2019-05-08  Alex Christensen  <achristensen@webkit.org>
 
         Add SPI to set HSTS storage directory
diff --git a/Source/WebCore/PAL/pal/spi/cocoa/IOKitSPI.h b/Source/WebCore/PAL/pal/spi/cocoa/IOKitSPI.h
index 4299518..8b8d1fa 100644
--- a/Source/WebCore/PAL/pal/spi/cocoa/IOKitSPI.h
+++ b/Source/WebCore/PAL/pal/spi/cocoa/IOKitSPI.h
@@ -197,6 +197,7 @@
     kHIDUsage_KeyboardF13 = 0x68,
     kHIDUsage_KeyboardF24 = 0x73,
     kHIDUsage_KeyboardMenu = 0x76,
+    kHIDUsage_KeypadComma = 0x85,
     kHIDUsage_KeyboardLeftControl = 0xE0,
     kHIDUsage_KeyboardLeftShift = 0xE1,
     kHIDUsage_KeyboardLeftAlt = 0xE2,
diff --git a/Source/WebCore/platform/ios/KeyEventIOS.mm b/Source/WebCore/platform/ios/KeyEventIOS.mm
index 7ccc967..e580373 100644
--- a/Source/WebCore/platform/ios/KeyEventIOS.mm
+++ b/Source/WebCore/platform/ios/KeyEventIOS.mm
@@ -172,8 +172,10 @@
         /* 0x80 */ VK_VOLUME_UP, // Volume Up
         /* 0x81 */ VK_VOLUME_DOWN, // Volume Down
     };
-    // Check if key is a modifier.
+    // Check if key is a modifier or the keypad comma (on JIS keyboard).
     switch (keyCode) {
+    case kHIDUsage_KeypadComma:
+        return VK_SEPARATOR;
     case kHIDUsage_KeyboardLeftControl:
         return VK_LCONTROL;
     case kHIDUsage_KeyboardLeftShift:
diff --git a/Source/WebCore/platform/ios/PlatformEventFactoryIOS.mm b/Source/WebCore/platform/ios/PlatformEventFactoryIOS.mm
index a171b9d..63221d4 100644
--- a/Source/WebCore/platform/ios/PlatformEventFactoryIOS.mm
+++ b/Source/WebCore/platform/ios/PlatformEventFactoryIOS.mm
@@ -322,7 +322,7 @@
     // NumpadBackspace.
     // NumpadClear.
     // NumpadClearEntry.
-    case VK_SEPARATOR: return "NumpadComma"_s;
+    case VK_SEPARATOR: return "NumpadComma"_s; // On JIS keyboard
     case VK_DECIMAL: return "NumpadDecimal"_s;
     case VK_DIVIDE: return "NumpadDivide"_s;
     // NumpadEnter.
@@ -427,8 +427,6 @@
     if (event.type != WebEventKeyDown && event.type != WebEventKeyUp)
         return false;
 
-    // With the exception of keypad comma, the following corresponds to the criterion for UIKeyModifierNumericPad.
-    // FIXME: Recognize keypad comma.
     switch (event.keyCode) {
     case VK_CLEAR: // Num Pad Clear
     case VK_OEM_PLUS: // Num Pad =
@@ -438,6 +436,7 @@
     case VK_ADD:
     case VK_RETURN: // Num Pad Enter
     case VK_DECIMAL: // Num Pad .
+    case VK_SEPARATOR: // Num Pad , (on JIS keyboard)
     case VK_NUMPAD0:
     case VK_NUMPAD1:
     case VK_NUMPAD2:
diff --git a/Tools/ChangeLog b/Tools/ChangeLog
index 0e842f1..94cccbf 100644
--- a/Tools/ChangeLog
+++ b/Tools/ChangeLog
@@ -1,3 +1,16 @@
+2019-05-09  Daniel Bates  <dabates@apple.com>
+
+        [iOS] Numpad comma key has incorrect keyIdentifier property
+        https://bugs.webkit.org/show_bug.cgi?id=197753
+        <rdar://problem/50636274>
+
+        Reviewed by Brent Fulgham.
+
+        Recognize "numpadComma" and return the appropriate HID usage code.
+
+        * WebKitTestRunner/ios/HIDEventGenerator.mm:
+        (hidUsageCodeForCharacter):
+
 2019-05-09  Eric Carlson  <eric.carlson@apple.com>
 
         Refine AudioSession route sharing policy
diff --git a/Tools/WebKitTestRunner/ios/HIDEventGenerator.mm b/Tools/WebKitTestRunner/ios/HIDEventGenerator.mm
index 5775626..89991c2 100644
--- a/Tools/WebKitTestRunner/ios/HIDEventGenerator.mm
+++ b/Tools/WebKitTestRunner/ios/HIDEventGenerator.mm
@@ -973,6 +973,8 @@
         return kHIDUsage_KeyboardLeftAlt;
     if ([key isEqualToString:@"rightAlt"])
         return kHIDUsage_KeyboardRightAlt;
+    if ([key isEqualToString:@"numpadComma"])
+        return kHIDUsage_KeypadComma;
 
     return 0;
 }