inputmode="numeric" should show a number pad with digits 0-9, instead of the numeric keyplane
https://bugs.webkit.org/show_bug.cgi?id=197916
<rdar://problem/50815427>

Reviewed by Timothy Hatcher.

Source/WebKit:

Use UIKeyboardTypeNumberPad instead of UIKeyboardTypeNumbersAndPunctuation when presenting a keyboard for a
field with inputmode="numeric". While the WhatWG specification merely requires the UA to display a keyboard
"capable of numeric input", it suggests that the keyboard should be "useful for PIN entry", which loosely
implies a number pad.

This is also generally in line with feedback from web developers.

* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView textInputTraits]):

Tools:

Re-enable this previously flaky test, and rebaseline the result to to expect UIKeyboardTypeNumberPad for
inputmode="numeric".

* TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm:
(TestWebKitAPI::TEST):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@245338 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog
index 1a4bd78..d154f67 100644
--- a/Source/WebKit/ChangeLog
+++ b/Source/WebKit/ChangeLog
@@ -1,3 +1,21 @@
+2019-05-15  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        inputmode="numeric" should show a number pad with digits 0-9, instead of the numeric keyplane
+        https://bugs.webkit.org/show_bug.cgi?id=197916
+        <rdar://problem/50815427>
+
+        Reviewed by Timothy Hatcher.
+
+        Use UIKeyboardTypeNumberPad instead of UIKeyboardTypeNumbersAndPunctuation when presenting a keyboard for a
+        field with inputmode="numeric". While the WhatWG specification merely requires the UA to display a keyboard
+        "capable of numeric input", it suggests that the keyboard should be "useful for PIN entry", which loosely
+        implies a number pad.
+
+        This is also generally in line with feedback from web developers.
+
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView textInputTraits]):
+
 2019-05-15  Don Olmstead  <don.olmstead@sony.com>
 
         Add USE(LIBWPE) for AcceleratedSurface
diff --git a/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm b/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
index b8aa435..4803498 100644
--- a/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
+++ b/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
@@ -4380,7 +4380,7 @@
         [_traits setKeyboardType:UIKeyboardTypeEmailAddress];
         break;
     case WebCore::InputMode::Numeric:
-        [_traits setKeyboardType:UIKeyboardTypeNumbersAndPunctuation];
+        [_traits setKeyboardType:UIKeyboardTypeNumberPad];
         break;
     case WebCore::InputMode::Decimal:
         [_traits setKeyboardType:UIKeyboardTypeDecimalPad];
diff --git a/Tools/ChangeLog b/Tools/ChangeLog
index a612a37..fa2f1d1 100644
--- a/Tools/ChangeLog
+++ b/Tools/ChangeLog
@@ -1,3 +1,17 @@
+2019-05-15  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        inputmode="numeric" should show a number pad with digits 0-9, instead of the numeric keyplane
+        https://bugs.webkit.org/show_bug.cgi?id=197916
+        <rdar://problem/50815427>
+
+        Reviewed by Timothy Hatcher.
+
+        Re-enable this previously flaky test, and rebaseline the result to to expect UIKeyboardTypeNumberPad for
+        inputmode="numeric".
+
+        * TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm:
+        (TestWebKitAPI::TEST):
+
 2019-05-15  Youenn Fablet  <youenn@apple.com>
 
         Reuse existing WebPageProxy quota handler for NetworkProcessProxy quota requests
diff --git a/Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm b/Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm
index 655ef13..fe3b01d 100644
--- a/Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm
+++ b/Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm
@@ -359,7 +359,7 @@
     [webView waitForSelectionViewRectsToBecome:expectedSelectionRects];
 }
 
-TEST(KeyboardInputTests, DISABLED_KeyboardTypeForInput)
+TEST(KeyboardInputTests, KeyboardTypeForInput)
 {
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
     auto inputDelegate = adoptNS([[TestInputDelegate alloc] init]);
@@ -369,11 +369,11 @@
     }];
     [webView _setInputDelegate:inputDelegate.get()];
     [webView synchronouslyLoadHTMLString:@"<input id='input'>"];
+    [webView evaluateJavaScriptAndWaitForInputSessionToChange:@"input.focus()"];
 
     auto runTest = ^(NSString *inputType, NSString *inputMode, NSString *pattern, UIKeyboardType expectedKeyboardType) {
-        [webView stringByEvaluatingJavaScript:@"input.blur()"];
-        [webView stringByEvaluatingJavaScript:[NSString stringWithFormat:@"input.type = '%@'; input.inputMode = '%@'; input.pattern = '%@'", inputType, inputMode, pattern]];
-        [webView stringByEvaluatingJavaScript:@"input.focus()"];
+        [webView evaluateJavaScriptAndWaitForInputSessionToChange:@"input.blur()"];
+        [webView evaluateJavaScriptAndWaitForInputSessionToChange:[NSString stringWithFormat:@"input.type = '%@'; input.inputMode = '%@'; input.pattern = '%@'; input.focus()", inputType, inputMode, pattern]];
 
         UIView<UITextInputPrivate> *textInput = (UIView<UITextInputPrivate> *)[webView textInputContentView];
         UIKeyboardType keyboardType = [textInput textInputTraits].keyboardType;
@@ -401,7 +401,7 @@
         @"tel": @(UIKeyboardTypePhonePad),
         @"url": @(UIKeyboardTypeURL),
         @"email": @(UIKeyboardTypeEmailAddress),
-        @"numeric": @(UIKeyboardTypeNumbersAndPunctuation),
+        @"numeric": @(UIKeyboardTypeNumberPad),
         @"decimal": @(UIKeyboardTypeDecimalPad),
         @"search": @(UIKeyboardTypeWebSearch)
     };
@@ -412,21 +412,17 @@
         @"[0-9]*": @(UIKeyboardTypeNumberPad)
     };
 
-    for (NSString *inputType in [expectedKeyboardTypeForInputType allKeys]) {
-        for (NSString *inputMode in [expectedKeyboardTypeForInputMode allKeys]) {
-            for (NSString *pattern in [expectedKeyboardTypeForPattern allKeys]) {
+    for (NSString *inputType in expectedKeyboardTypeForInputType) {
+        BOOL isNumberOrTextInput = [inputType isEqual:@"text"] || [inputType isEqual:@"number"];
+        for (NSString *inputMode in expectedKeyboardTypeForInputMode) {
+            for (NSString *pattern in expectedKeyboardTypeForPattern) {
                 NSNumber *keyboardType;
                 if (inputMode.length) {
                     // inputmode has the highest priority.
                     keyboardType = expectedKeyboardTypeForInputMode[inputMode];
                 } else {
-                    if (pattern.length && ([inputType isEqual: @"text"] || [inputType isEqual: @"number"])) {
-                        // Special case for text and number inputs that have a numeric pattern.
-                        keyboardType = expectedKeyboardTypeForPattern[pattern];
-                    } else {
-                        // Otherwise, the input type determines the keyboard type.
-                        keyboardType = expectedKeyboardTypeForInputType[inputType];
-                    }
+                    // Special case for text and number inputs that have a numeric pattern. Otherwise, the input type determines the keyboard type.
+                    keyboardType = pattern.length && isNumberOrTextInput ? expectedKeyboardTypeForPattern[pattern] : expectedKeyboardTypeForInputType[inputType];
                 }
 
                 EXPECT_TRUE(runTest(inputType, inputMode, pattern, (UIKeyboardType)keyboardType.intValue));