Title: [240512] trunk
Revision
240512
Author
dba...@webkit.org
Date
2019-01-25 14:35:10 -0800 (Fri, 25 Jan 2019)

Log Message

[iOS] uiController.keyDown() does not translate Control modified key
https://bugs.webkit.org/show_bug.cgi?id=192898

Reviewed by Wenson Hsieh.

Tools:

Implement uiController.keyDown() in terms of HIDEventGenerator so that UIKit performs
key translation, as applicable. Among other cases, key translation occurs when performing
a Control key modified key sequence. Writing uiController.keyDown() in terms of HIDEventGenerator
also makes the behavior of uiController.keyDown() more closely match the behavior of a
human pressing down and releasing key(s) using a hardware keyboard.

* WebKitTestRunner/ios/HIDEventGenerator.h:
* WebKitTestRunner/ios/HIDEventGenerator.mm:
(-[HIDEventGenerator sendMarkerHIDEventWithCompletionBlock:]): Renamed; formerly named _sendMarkerHIDEventWithCompletionBlock.

(-[HIDEventGenerator touchDown:touchCount:completionBlock:]):
(-[HIDEventGenerator liftUp:touchCount:completionBlock:]):
(-[HIDEventGenerator stylusDownAtPoint:azimuthAngle:altitudeAngle:pressure:completionBlock:]):
(-[HIDEventGenerator stylusMoveToPoint:azimuthAngle:altitudeAngle:pressure:completionBlock:]):
(-[HIDEventGenerator stylusUpAtPoint:completionBlock:]):
(-[HIDEventGenerator stylusTapAtPoint:azimuthAngle:altitudeAngle:pressure:completionBlock:]):
(-[HIDEventGenerator sendTaps:location:withNumberOfTouches:completionBlock:]):
(-[HIDEventGenerator longPress:completionBlock:]):
(-[HIDEventGenerator dragWithStartPoint:endPoint:duration:completionBlock:]):
Update code for above renaming.

(hidUsageCodeForCharacter): Translate \b to a backspace and teach this function to recognize the
DumpRenderTree EventSender-compatible modifier key names (e.g. "metaKey").

(-[HIDEventGenerator keyDown:]): Added.
(-[HIDEventGenerator keyUp:]): Added.
(-[HIDEventGenerator keyPress:completionBlock:]):
(-[HIDEventGenerator eventDispatchThreadEntry:]):
(-[HIDEventGenerator _sendMarkerHIDEventWithCompletionBlock:]): Deleted; renamed to sendMarkerHIDEventWithCompletionBlock.
* WebKitTestRunner/ios/UIScriptControllerIOS.mm:
(WTR::parseModifierArray): Modified to return a vector of strings that represent the modifier keys to press.
(WTR::UIScriptController::keyDown): Write in terms of HIDEventGenerator.
(WTR::parseModifier): Deleted.

LayoutTests:

Make tests more robusts.

* fast/events/ios/key-command-italic-dispatches-keydown.html: Remove the need to special-case the test runner and
expect a single key event that represents Command + I. Now that uiController.keyDown() makes use of HIDEventGenerator
we emit separate key events for each key pressed in the sequence: keydown Command, keydown i, keyup i, keyup Command.
This matches how a human being would execute such a key sequence.
* fast/forms/auto-fill-button/caps-lock-indicator-should-not-be-visible-when-auto-fill-strong-password-button-is-visible-expected.html:
Make the test less flaky by hiding the tap highlight. Depending on timing, the tap highlight may be snapshotted and thus
cause the reference test to mismatch the test. Mitigate this by hiding the tap highlight.
* fast/text/scroll-text-overflow-ellipsis.html: Wait for a keyup event for the down arrow before declaring the
test complete.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (240511 => 240512)


--- trunk/LayoutTests/ChangeLog	2019-01-25 22:31:12 UTC (rev 240511)
+++ trunk/LayoutTests/ChangeLog	2019-01-25 22:35:10 UTC (rev 240512)
@@ -1,3 +1,22 @@
+2019-01-25  Daniel Bates  <daba...@apple.com>
+
+        [iOS] uiController.keyDown() does not translate Control modified key
+        https://bugs.webkit.org/show_bug.cgi?id=192898
+
+        Reviewed by Wenson Hsieh.
+
+        Make tests more robusts.
+
+        * fast/events/ios/key-command-italic-dispatches-keydown.html: Remove the need to special-case the test runner and
+        expect a single key event that represents Command + I. Now that uiController.keyDown() makes use of HIDEventGenerator
+        we emit separate key events for each key pressed in the sequence: keydown Command, keydown i, keyup i, keyup Command.
+        This matches how a human being would execute such a key sequence.
+        * fast/forms/auto-fill-button/caps-lock-indicator-should-not-be-visible-when-auto-fill-strong-password-button-is-visible-expected.html:
+        Make the test less flaky by hiding the tap highlight. Depending on timing, the tap highlight may be snapshotted and thus
+        cause the reference test to mismatch the test. Mitigate this by hiding the tap highlight.
+        * fast/text/scroll-text-overflow-ellipsis.html: Wait for a keyup event for the down arrow before declaring the
+        test complete.
+
 2019-01-25  Simon Fraser  <simon.fra...@apple.com>
 
         Move more scrolling tree tests into scrollingcoordinator/scrolling-tree

Modified: trunk/LayoutTests/fast/events/ios/key-command-italic-dispatches-keydown.html (240511 => 240512)


--- trunk/LayoutTests/fast/events/ios/key-command-italic-dispatches-keydown.html	2019-01-25 22:31:12 UTC (rev 240511)
+++ trunk/LayoutTests/fast/events/ios/key-command-italic-dispatches-keydown.html	2019-01-25 22:35:10 UTC (rev 240512)
@@ -32,7 +32,7 @@
     // When performing the test manually a person is not fast enough to press Command + I simultaneously.
     // We receive a key down for Command followed by a key down for Command + I. So, we ignore the first
     // event to normalize the test result.
-    if (window.testRunner || ignoredFirstKeyDownEvent)
+    if (ignoredFirstKeyDownEvent)
         return false;
     ignoredFirstKeyDownEvent = true;
     console.assert(event.key == "Meta");

Modified: trunk/LayoutTests/fast/forms/auto-fill-button/caps-lock-indicator-should-not-be-visible-when-auto-fill-strong-password-button-is-visible-expected.html (240511 => 240512)


--- trunk/LayoutTests/fast/forms/auto-fill-button/caps-lock-indicator-should-not-be-visible-when-auto-fill-strong-password-button-is-visible-expected.html	2019-01-25 22:31:12 UTC (rev 240511)
+++ trunk/LayoutTests/fast/forms/auto-fill-button/caps-lock-indicator-should-not-be-visible-when-auto-fill-strong-password-button-is-visible-expected.html	2019-01-25 22:35:10 UTC (rev 240512)
@@ -2,6 +2,13 @@
 <html>
 <head>
 <script src=""
+<style>
+input {
+    /* Hide the tap highlight to mitigate test differences due to when the snapshot
+    is taken with respect to tap highlight painting. */
+    -webkit-tap-highlight-color: transparent;
+}
+</style>
 <script>
 if (window.testRunner)
     testRunner.waitUntilDone();

Modified: trunk/LayoutTests/fast/text/scroll-text-overflow-ellipsis.html (240511 => 240512)


--- trunk/LayoutTests/fast/text/scroll-text-overflow-ellipsis.html	2019-01-25 22:31:12 UTC (rev 240511)
+++ trunk/LayoutTests/fast/text/scroll-text-overflow-ellipsis.html	2019-01-25 22:35:10 UTC (rev 240512)
@@ -36,22 +36,23 @@
 </div>
 <div id="ellipsizedText" contenteditable="true">abcde</div>
 <script>
+function done()
+{
+    document.getElementById("ellipsizedText").blur(); // To avoid painting the caret.
+    if (window.testRunner)
+        testRunner.notifyDone();
+}
+
 function runTest()
 {
-    function scrollToEndOfLine()
-    {
+    function scrollToEndOfLine() {
         return UIHelper.keyDown("downArrow");
     }
+    UIHelper.activateAndWaitForInputSessionAt(0, 0).then(scrollToEndOfLine);
+}
 
-    function done()
-    {
-        document.getElementById("ellipsizedText").blur(); // To avoid painting the caret.
-        testRunner.notifyDone();
-    }
+document.getElementById("ellipsizedText").addEventListener("scroll", done, {once: true});
 
-    UIHelper.activateAndWaitForInputSessionAt(0, 0).then(scrollToEndOfLine).then(done);
-}
-
 if (!window.testRunner)
     document.getElementById("manual-instructions").classList.remove("hidden"); // Show manual instructions
 else {

Modified: trunk/Tools/ChangeLog (240511 => 240512)


--- trunk/Tools/ChangeLog	2019-01-25 22:31:12 UTC (rev 240511)
+++ trunk/Tools/ChangeLog	2019-01-25 22:35:10 UTC (rev 240512)
@@ -1,3 +1,44 @@
+2019-01-25  Daniel Bates  <daba...@apple.com>
+
+        [iOS] uiController.keyDown() does not translate Control modified key
+        https://bugs.webkit.org/show_bug.cgi?id=192898
+
+        Reviewed by Wenson Hsieh.
+
+        Implement uiController.keyDown() in terms of HIDEventGenerator so that UIKit performs
+        key translation, as applicable. Among other cases, key translation occurs when performing
+        a Control key modified key sequence. Writing uiController.keyDown() in terms of HIDEventGenerator
+        also makes the behavior of uiController.keyDown() more closely match the behavior of a
+        human pressing down and releasing key(s) using a hardware keyboard.
+
+        * WebKitTestRunner/ios/HIDEventGenerator.h:
+        * WebKitTestRunner/ios/HIDEventGenerator.mm:
+        (-[HIDEventGenerator sendMarkerHIDEventWithCompletionBlock:]): Renamed; formerly named _sendMarkerHIDEventWithCompletionBlock.
+
+        (-[HIDEventGenerator touchDown:touchCount:completionBlock:]):
+        (-[HIDEventGenerator liftUp:touchCount:completionBlock:]):
+        (-[HIDEventGenerator stylusDownAtPoint:azimuthAngle:altitudeAngle:pressure:completionBlock:]):
+        (-[HIDEventGenerator stylusMoveToPoint:azimuthAngle:altitudeAngle:pressure:completionBlock:]):
+        (-[HIDEventGenerator stylusUpAtPoint:completionBlock:]):
+        (-[HIDEventGenerator stylusTapAtPoint:azimuthAngle:altitudeAngle:pressure:completionBlock:]):
+        (-[HIDEventGenerator sendTaps:location:withNumberOfTouches:completionBlock:]):
+        (-[HIDEventGenerator longPress:completionBlock:]):
+        (-[HIDEventGenerator dragWithStartPoint:endPoint:duration:completionBlock:]):
+        Update code for above renaming.
+
+        (hidUsageCodeForCharacter): Translate \b to a backspace and teach this function to recognize the
+        DumpRenderTree EventSender-compatible modifier key names (e.g. "metaKey").
+
+        (-[HIDEventGenerator keyDown:]): Added.
+        (-[HIDEventGenerator keyUp:]): Added.
+        (-[HIDEventGenerator keyPress:completionBlock:]):
+        (-[HIDEventGenerator eventDispatchThreadEntry:]):
+        (-[HIDEventGenerator _sendMarkerHIDEventWithCompletionBlock:]): Deleted; renamed to sendMarkerHIDEventWithCompletionBlock.
+        * WebKitTestRunner/ios/UIScriptControllerIOS.mm:
+        (WTR::parseModifierArray): Modified to return a vector of strings that represent the modifier keys to press.
+        (WTR::UIScriptController::keyDown): Write in terms of HIDEventGenerator.
+        (WTR::parseModifier): Deleted.
+
 2019-01-25  Keith Rollin  <krol...@apple.com>
 
         Complete the implementation of generate-xcfilelists

Modified: trunk/Tools/WebKitTestRunner/ios/HIDEventGenerator.h (240511 => 240512)


--- trunk/Tools/WebKitTestRunner/ios/HIDEventGenerator.h	2019-01-25 22:31:12 UTC (rev 240511)
+++ trunk/Tools/WebKitTestRunner/ios/HIDEventGenerator.h	2019-01-25 22:35:10 UTC (rev 240512)
@@ -109,4 +109,9 @@
 // Keyboard
 - (void)keyPress:(NSString *)character completionBlock:(void (^)(void))completionBlock;
 
+- (void)keyDown:(NSString *)character;
+- (void)keyUp:(NSString *)character;
+
+- (BOOL)sendMarkerHIDEventWithCompletionBlock:(void (^)(void))completionBlock;
+
 @end

Modified: trunk/Tools/WebKitTestRunner/ios/HIDEventGenerator.mm (240511 => 240512)


--- trunk/Tools/WebKitTestRunner/ios/HIDEventGenerator.mm	2019-01-25 22:31:12 UTC (rev 240511)
+++ trunk/Tools/WebKitTestRunner/ios/HIDEventGenerator.mm	2019-01-25 22:35:10 UTC (rev 240512)
@@ -475,7 +475,7 @@
     return YES;
 }
 
-- (BOOL)_sendMarkerHIDEventWithCompletionBlock:(void (^)(void))completionBlock
+- (BOOL)sendMarkerHIDEventWithCompletionBlock:(void (^)(void))completionBlock
 {
     auto callbackID = [HIDEventGenerator nextEventCallbackID];
     [_eventCallbacks setObject:Block_copy(completionBlock) forKey:@(callbackID)];
@@ -629,13 +629,13 @@
 - (void)touchDown:(CGPoint)location touchCount:(NSUInteger)count completionBlock:(void (^)(void))completionBlock
 {
     [self touchDown:location touchCount:count];
-    [self _sendMarkerHIDEventWithCompletionBlock:completionBlock];
+    [self sendMarkerHIDEventWithCompletionBlock:completionBlock];
 }
 
 - (void)liftUp:(CGPoint)location touchCount:(NSUInteger)count completionBlock:(void (^)(void))completionBlock
 {
     [self liftUp:location touchCount:count];
-    [self _sendMarkerHIDEventWithCompletionBlock:completionBlock];
+    [self sendMarkerHIDEventWithCompletionBlock:completionBlock];
 }
 
 - (void)stylusDownAtPoint:(CGPoint)location azimuthAngle:(CGFloat)azimuthAngle altitudeAngle:(CGFloat)altitudeAngle pressure:(CGFloat)pressure
@@ -686,19 +686,19 @@
 - (void)stylusDownAtPoint:(CGPoint)location azimuthAngle:(CGFloat)azimuthAngle altitudeAngle:(CGFloat)altitudeAngle pressure:(CGFloat)pressure completionBlock:(void (^)(void))completionBlock
 {
     [self stylusDownAtPoint:location azimuthAngle:azimuthAngle altitudeAngle:altitudeAngle pressure:pressure];
-    [self _sendMarkerHIDEventWithCompletionBlock:completionBlock];
+    [self sendMarkerHIDEventWithCompletionBlock:completionBlock];
 }
 
 - (void)stylusMoveToPoint:(CGPoint)location azimuthAngle:(CGFloat)azimuthAngle altitudeAngle:(CGFloat)altitudeAngle pressure:(CGFloat)pressure completionBlock:(void (^)(void))completionBlock
 {
     [self stylusMoveToPoint:location azimuthAngle:azimuthAngle altitudeAngle:altitudeAngle pressure:pressure];
-    [self _sendMarkerHIDEventWithCompletionBlock:completionBlock];
+    [self sendMarkerHIDEventWithCompletionBlock:completionBlock];
 }
 
 - (void)stylusUpAtPoint:(CGPoint)location completionBlock:(void (^)(void))completionBlock
 {
     [self stylusUpAtPoint:location];
-    [self _sendMarkerHIDEventWithCompletionBlock:completionBlock];
+    [self sendMarkerHIDEventWithCompletionBlock:completionBlock];
 }
 
 - (void)stylusTapAtPoint:(CGPoint)location azimuthAngle:(CGFloat)azimuthAngle altitudeAngle:(CGFloat)altitudeAngle pressure:(CGFloat)pressure completionBlock:(void (^)(void))completionBlock
@@ -709,7 +709,7 @@
     nanosleep(&pressDelay, 0);
     [self stylusUpAtPoint:location];
 
-    [self _sendMarkerHIDEventWithCompletionBlock:completionBlock];
+    [self sendMarkerHIDEventWithCompletionBlock:completionBlock];
 }
 
 - (void)sendTaps:(int)tapCount location:(CGPoint)location withNumberOfTouches:(int)touchCount completionBlock:(void (^)(void))completionBlock
@@ -725,7 +725,7 @@
             nanosleep(&doubleDelay, 0);
     }
     
-    [self _sendMarkerHIDEventWithCompletionBlock:completionBlock];
+    [self sendMarkerHIDEventWithCompletionBlock:completionBlock];
 }
 
 - (void)tap:(CGPoint)location completionBlock:(void (^)(void))completionBlock
@@ -750,7 +750,7 @@
 
     dispatch_after(dispatch_time(DISPATCH_TIME_NOW, longPressHoldDelay * nanosecondsPerSecond), dispatch_get_main_queue(), ^ {
         [self liftUp:location];
-        [self _sendMarkerHIDEventWithCompletionBlock:completionBlockCopy.get()];
+        [self sendMarkerHIDEventWithCompletionBlock:completionBlockCopy.get()];
     });
 }
 
@@ -759,7 +759,7 @@
     [self touchDown:startLocation touchCount:1];
     [self moveToPoints:&endLocation touchCount:1 duration:seconds];
     [self liftUp:endLocation];
-    [self _sendMarkerHIDEventWithCompletionBlock:completionBlock];
+    [self sendMarkerHIDEventWithCompletionBlock:completionBlock];
 }
 
 - (void)pinchCloseWithStartPoint:(CGPoint)startLocation endPoint:(CGPoint)endLocation duration:(double)seconds completionBlock:(void (^)(void))completionBlock
@@ -888,6 +888,8 @@
         case '=':
         case '+':
             return kHIDUsage_KeyboardEqualSign;
+        case '\b':
+            return kHIDUsage_KeyboardDeleteOrBackspace;
         case '\t':
             return kHIDUsage_KeyboardTab;
         case '[':
@@ -925,7 +927,7 @@
     if (auto keyCode = keyCodeForDOMFunctionKey(key))
         return *keyCode;
 
-    if ([key isEqualToString:@"capsLock"])
+    if ([key isEqualToString:@"capsLock"] || [key isEqualToString:@"capsLockKey"])
         return kHIDUsage_KeyboardCapsLock;
     if ([key isEqualToString:@"pageUp"])
         return kHIDUsage_KeyboardPageUp;
@@ -953,21 +955,21 @@
         return kHIDUsage_KeyboardDeleteOrBackspace;
     if ([key isEqualToString:@"forwardDelete"])
         return kHIDUsage_KeyboardDeleteForward;
-    if ([key isEqualToString:@"leftCommand"])
+    if ([key isEqualToString:@"leftCommand"] || [key isEqualToString:@"metaKey"])
         return kHIDUsage_KeyboardLeftGUI;
     if ([key isEqualToString:@"rightCommand"])
         return kHIDUsage_KeyboardRightGUI;
     if ([key isEqualToString:@"clear"]) // Num Lock / Clear
         return kHIDUsage_KeypadNumLock;
-    if ([key isEqualToString:@"leftControl"])
+    if ([key isEqualToString:@"leftControl"] || [key isEqualToString:@"ctrlKey"])
         return kHIDUsage_KeyboardLeftControl;
     if ([key isEqualToString:@"rightControl"])
         return kHIDUsage_KeyboardRightControl;
-    if ([key isEqualToString:@"leftShift"])
+    if ([key isEqualToString:@"leftShift"] || [key isEqualToString:@"shiftKey"])
         return kHIDUsage_KeyboardLeftShift;
     if ([key isEqualToString:@"rightShift"])
         return kHIDUsage_KeyboardRightShift;
-    if ([key isEqualToString:@"leftAlt"])
+    if ([key isEqualToString:@"leftAlt"] || [key isEqualToString:@"altKey"])
         return kHIDUsage_KeyboardLeftAlt;
     if ([key isEqualToString:@"rightAlt"])
         return kHIDUsage_KeyboardRightAlt;
@@ -980,6 +982,16 @@
     return adoptCF(IOHIDEventCreateKeyboardEvent(kCFAllocatorDefault, timestamp, kHIDPage_KeyboardOrKeypad, hidUsageCodeForCharacter(character), isKeyDown, kIOHIDEventOptionNone));
 }
 
+- (void)keyDown:(NSString *)character
+{
+    [self _sendIOHIDKeyboardEvent:mach_absolute_time() usage:hidUsageCodeForCharacter(character) isKeyDown:true];
+}
+
+- (void)keyUp:(NSString *)character
+{
+    [self _sendIOHIDKeyboardEvent:mach_absolute_time() usage:hidUsageCodeForCharacter(character) isKeyDown:false];
+}
+
 - (void)keyPress:(NSString *)character completionBlock:(void (^)(void))completionBlock
 {
     bool shouldWrapWithShift = shouldWrapWithShiftKeyEventForCharacter(character);
@@ -995,7 +1007,7 @@
     if (shouldWrapWithShift)
         [self _sendIOHIDKeyboardEvent:absoluteMachTime usage:kHIDUsage_KeyboardLeftShift isKeyDown:false];
 
-    [self _sendMarkerHIDEventWithCompletionBlock:completionBlock];
+    [self sendMarkerHIDEventWithCompletionBlock:completionBlock];
 }
 
 - (void)dispatchEventWithInfo:(NSDictionary *)eventInfo
@@ -1112,7 +1124,7 @@
     }
     
     dispatch_async(dispatch_get_main_queue(), ^ {
-        [self _sendMarkerHIDEventWithCompletionBlock:completionBlock];
+        [self sendMarkerHIDEventWithCompletionBlock:completionBlock];
     });
 }
 

Modified: trunk/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm (240511 => 240512)


--- trunk/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm	2019-01-25 22:31:12 UTC (rev 240511)
+++ trunk/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm	2019-01-25 22:35:10 UTC (rev 240512)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 Apple Inc. All rights reserved.
+ * Copyright (C) 2015-2019 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -43,6 +43,7 @@
 #import <WebKit/WKWebViewPrivate.h>
 #import <WebKit/WebKit.h>
 #import <wtf/SoftLinking.h>
+#import <wtf/Vector.h>
 
 SOFT_LINK_FRAMEWORK(UIKit)
 SOFT_LINK_CLASS(UIKit, UIPhysicalKeyboardEvent)
@@ -356,37 +357,23 @@
     return 0;
 }
 
-static UIKeyModifierFlags parseModifier(JSStringRef modifier)
+static Vector<String> parseModifierArray(JSContextRef context, JSValueRef arrayValue)
 {
-    if (JSStringIsEqualToUTF8CString(modifier, "altKey"))
-        return UIKeyModifierAlternate;
-    if (JSStringIsEqualToUTF8CString(modifier, "capsLockKey"))
-        return UIKeyModifierAlphaShift;
-    if (JSStringIsEqualToUTF8CString(modifier, "ctrlKey"))
-        return UIKeyModifierControl;
-    if (JSStringIsEqualToUTF8CString(modifier, "metaKey"))
-        return UIKeyModifierCommand;
-    if (JSStringIsEqualToUTF8CString(modifier, "shiftKey"))
-        return UIKeyModifierShift;
-    return 0;
-}
-
-static UIKeyModifierFlags parseModifierArray(JSContextRef context, JSValueRef arrayValue)
-{
     if (!arrayValue)
-        return 0;
+        return { };
 
     // The value may either be a string with a single modifier or an array of modifiers.
     if (JSValueIsString(context, arrayValue)) {
-        auto string = adopt(JSValueToStringCopy(context, arrayValue, nullptr));
-        return parseModifier(string.get());
+        auto string = toWTFString(toWK(adopt(JSValueToStringCopy(context, arrayValue, nullptr))));
+        return { string };
     }
 
     if (!JSValueIsObject(context, arrayValue))
-        return 0;
+        return { };
     JSObjectRef array = const_cast<JSObjectRef>(arrayValue);
     unsigned length = arrayLength(context, array);
-    UIKeyModifierFlags modifiers = 0;
+    Vector<String> modifiers;
+    modifiers.reserveInitialCapacity(length);
     for (unsigned i = 0; i < length; ++i) {
         JSValueRef exception = nullptr;
         JSValueRef value = JSObjectGetPropertyAtIndex(context, array, i, &exception);
@@ -395,7 +382,7 @@
         auto string = adopt(JSValueToStringCopy(context, value, &exception));
         if (exception)
             continue;
-        modifiers |= parseModifier(string.get());
+        modifiers.append(toWTFString(toWK(string.get())));
     }
     return modifiers;
 }
@@ -412,27 +399,22 @@
 void UIScriptController::keyDown(JSStringRef character, JSValueRef modifierArray)
 {
     // Character can be either a single Unicode code point or the name of a special key (e.g. "downArrow").
-    // createHIDKeyEvent() knows how to map these special keys to the appropriate keycode.
-    //
-    // FIXME: The UIEvent input string for special keys (e.g. "downArrow") should either be a UIKeyInput*
-    // string constant or an ASCII control character. In practice the input string for a special key is
-    // ambiguious (e.g. F5 and F6 have the same string - the ASCII DLE character) and hence it is effectively
-    // ignored in favor of key identification by keycode. So, we just take the empty string as the input string
-    // for a special key.
+    // HIDEventGenerator knows how to map these special keys to the appropriate keycode.
     String inputString = toWTFString(toWK(character));
-    String uiEventInputString = inputString.length() > 1 ? emptyString() : inputString;
     auto modifierFlags = parseModifierArray(m_context->jsContext(), modifierArray);
-    UIKeyboardInputFlags inputFlags = static_cast<UIKeyboardInputFlags>(0);
 
-    // Note that UIKit will call -release on the passed UIPhysicalKeyboardEvent.
+    for (auto& modifierFlag : modifierFlags)
+        [[HIDEventGenerator sharedHIDEventGenerator] keyDown:modifierFlag];
 
-    // Key down
-    auto* keyboardEvent = createUIPhysicalKeyboardEvent(inputString, uiEventInputString, modifierFlags, inputFlags, true /* isKeyDown */);
-    [[UIApplication sharedApplication] handleKeyUIEvent:keyboardEvent];
+    [[HIDEventGenerator sharedHIDEventGenerator] keyDown:inputString];
+    [[HIDEventGenerator sharedHIDEventGenerator] keyUp:inputString];
 
-    // Key up
-    keyboardEvent = createUIPhysicalKeyboardEvent(inputString, uiEventInputString, modifierFlags, inputFlags, false /* isKeyDown */);
-    [[UIApplication sharedApplication] handleKeyUIEvent:keyboardEvent];
+    for (size_t i = modifierFlags.size(); i; ) {
+        --i;
+        [[HIDEventGenerator sharedHIDEventGenerator] keyUp:modifierFlags[i]];
+    }
+
+    [[HIDEventGenerator sharedHIDEventGenerator] sendMarkerHIDEventWithCompletionBlock:^{ /* Do nothing */ }];
 }
 
 void UIScriptController::dismissFormAccessoryView()
@@ -943,6 +925,8 @@
     TestController::singleton().setKeyboardInputModeIdentifier(toWTFString(toWK(identifier)));
 }
 
+// FIXME: Write this in terms of HIDEventGenerator once we know how to reset caps lock state
+// on test completion to avoid it effecting subsequent tests.
 void UIScriptController::toggleCapsLock(JSValueRef callback)
 {
     m_capsLockOn = !m_capsLockOn;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to