1[iOS] Keyups for non-modifier keys identified as "Dead" when not focused in a content-editable element
2https://bugs.webkit.org/show_bug.cgi?id=192824
3<rdar://problem/47100332>
4
5Reviewed by Wenson Hsieh.
6
7Source/WebCore:
8
9When building with USE(UIKIT_KEYBOARD_ADDITIONS) enabled, normalize input strings for some more key codes
10now that hardware key events to non-editable elements use the same code path as for editable elements.
11
12* platform/ios/KeyEventIOS.mm:
13(WebCore::windowsKeyCodeForCharCode): Demarcate mappings that are only needed when building with
14!USE(UIKIT_KEYBOARD_ADDITIONS) in the hope that one day we can remove this code.
15(WebCore::isFunctionKey): Ditto.
16* platform/ios/WebEvent.mm:
17(normalizedStringWithAppKitCompatibilityMapping): Normalize some more input strings when building with
18USE(UIKIT_KEYBOARD_ADDITIONS) enabled.
19
20Source/WebCore/PAL:
21
22Expose more enumerators.
23
24* pal/spi/cocoa/IOKitSPI.h:
25
26Source/WebKit:
27
28Use the same code path for key events to editable elements and non-editable elements.
29
30Currently we have different code paths for hardware key events depending on whether the active element
31is editable or non-editable. Historically to support dispatching DOM keyboard events for hardware key
32presses this differentiation was a necessary workaround for UIKit's event processing precedence of
33interpreting key events for system text editing commands and app commands before dispatching unhandled
34key events to WebKit. This workaround intercepted raw key UIEvents and manually reconstructed a
35WebEvent from it. However there is not enough information in an UIEvent to reconstruct a WebEvent that
36is identical to the WebEvent that UIKit would have dispatched. In particular, keyup UIEvents always have
37empty modified and unmodified input strings. The UIKit keyboard machinery maintains additional state
38that is necessary to manufacture the correct WebEvent corresponding to a UIEvent.
39
40As a side benefit of this change, with the exception of modifier flag changes, both hardware and software
41key events use the same code path.
42
43* UIProcess/ios/WKContentViewInteraction.h:
44* UIProcess/ios/WKContentViewInteraction.mm:
45(-[WKContentView _disableAutomaticKeyboardUI]): Implement UIKit SPI to prevent showing the keyboard UI
46when there is no focused element now that we are no longer intercepting key UIEvents. Formerly the
47keyboard UI was disabled as a side effect of not becoming first responder when there was no focused
48element (by returning NO in -_requiresKeyboardWhenFirstResponder).
49(-[WKContentView _requiresKeyboardWhenFirstResponder]): Return YES when there is no focused element.
50(-[WKContentView textInputTraits]): Do not update traits when the keyboard is going to be dismissed
51now that we require a keyboard when first responder even if the focused element is non-editable.
52(-[WKContentView _didHandleKeyEvent:eventWasHandled:]): Skip logic for re-sending UIEvents to UIKit
53as UIKit now processes the event first. This logic was necessary in order to finally allow UIKit
54its chance to interpret the UIEvent, we intercepted, for app key commands.
55
56Tools:
57
58Fix a bug where the wrong usage code was used for F13 thru F24.
59
60* WebKitTestRunner/ios/HIDEventGenerator.mm:
61(keyCodeForDOMFunctionKey):
62
63LayoutTests:
64
65Update tests and expected results. As it turns out fixing the bug in WebKitTestRunner/ios/HIDEventGenerator.mm
66so that we now dispatch key events for F17 thru F24 exposed a bug in UIKit. See <rdar://problem/47128940>.
67This same bug is also responsible for a lack of key events when the Insert key is pressed.
68
69Added sub-test for Tab key to keypress-keys-in-non-editable-element.html. Changed expected result in test
70keypress-keys-in-non-editable-element.html for the forward delete key to expect failure. We expect that pressing
71the forward delete key will not dispatch a keypress to match the behavior on Mac. This will be addressed by a
72UIKit fix.
73
74* fast/events/ios/keydown-keyup-special-keys-in-non-editable-element-expected.txt:
75* fast/events/ios/keydown-keyup-special-keys-in-non-editable-element.html:
76* fast/events/ios/keypress-keys-in-non-editable-element-expected.txt:
77* fast/events/ios/keypress-keys-in-non-editable-element.html: