Changeset 238235 in webkit


Ignore:
Timestamp:
Nov 15, 2018 11:15:28 AM (5 years ago)
Author:
dbates@webkit.org
Message:

[iOS] Shift + Tab does not focus previous field
https://bugs.webkit.org/show_bug.cgi?id=191596
<rdar://problem/45892053>

Reviewed by Wenson Hsieh.

Source/WebKit:

Wire up the the tab and shift + tab key commands to the WKWebView/WKContentView's
action forwarding mechanism. Also rename -_prevAccessoryTab to -_previousAccessoryTab.

  • Platform/spi/ios/UIKitSPI.h: Add more SPI.
  • UIProcess/API/Cocoa/WKWebViewInternal.h:
  • UIProcess/ios/WKContentViewInteraction.h:
  • UIProcess/ios/WKContentViewInteraction.mm:

(-[WKContentView canPerformActionForWebView:withSender:]):
(-[WKContentView keyCommands]):
(-[WKContentView _nextAccessoryTabForWebView:]): Added.
(-[WKContentView _previousAccessoryTabForWebView:]): Added.
(-[WKContentView _nextAccessoryTab:]): Deleted.
(-[WKContentView _prevAccessoryTab:]): Deleted.

Tools:

Add infrastructure to support testing a key down event with modifiers by creating
and dispatching a UIEvent. This infrastructure replaces the previous mechanism in
Tools/WebKitTestRunner/ios/HIDEventGenerator.mm to generate a IOHIDEvent for a
keydown as it did not support creating an event with modifier key state that would
be recognized by UIKit.

  • DumpRenderTree/ios/UIScriptControllerIOS.mm:

(WTR::UIScriptController::keyDown):
(WTR::UIScriptController::keyDownUsingHardwareKeyboard): Deleted.
(WTR::UIScriptController::keyUpUsingHardwareKeyboard): Deleted.

  • TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:

Add function uiController.keyDown() that takes a character that represents a keyboard key
and an array of modifier keys. The behavior of this function is analogous to eventSender.keyDown().
Remove functions uiController.keyDownUsingHardwareKeyboard() and uiController.keyUpUsingHardwareKeyboard()
as the former is replaced by uiController.keyDown() and the latter was never used.

  • TestRunnerShared/UIScriptContext/UIScriptController.cpp:

(WTR::UIScriptController::keyDown): Added.
(WTR::UIScriptController::keyUpUsingHardwareKeyboard): Deleted.
(WTR::UIScriptController::keyDownUsingHardwareKeyboard): Deleted.

  • TestRunnerShared/UIScriptContext/UIScriptController.h:
  • WebKitTestRunner/ios/HIDEventGenerator.h:
  • WebKitTestRunner/ios/HIDEventGenerator.mm:

(createHIDKeyDownEvent): Added.
(-[HIDEventGenerator keyDown:completionBlock:]): Deleted.
(-[HIDEventGenerator keyUp:completionBlock:]): Deleted.

  • WebKitTestRunner/ios/UIScriptControllerIOS.mm:

(WTR::arrayLength): Added.
(WTR::parseModifier): Added.
(WTR::parseModifierArray): Added.
(WTR::UIScriptController::keyDown):
(WTR::UIScriptController::keyDownUsingHardwareKeyboard): Deleted.
(WTR::UIScriptController::keyUpUsingHardwareKeyboard): Deleted.

LayoutTests:

Add tests to ensure that we do not regress the tab and shift + tab key commands.

  • fast/events/ios/focus-tab-next-field-expected.txt: Added.
  • fast/events/ios/focus-tab-next-field.html: Added.
  • fast/events/ios/focus-tab-previous-field-expected.txt: Added.
  • fast/events/ios/focus-tab-previous-field.html: Added.
  • platform/ios-wk1/TestExpectations: Skip test focus-tab-previous-field.html in Legacy WebKit as

we do not support testing key commands with modifier keys.

  • resources/ui-helper.js:

(window.UIHelper.keyDown): Updated to support taking an optional array of modifiers (defaults: [])
and use the new infrastructure to generate a key down event for the specified character.

Location:
trunk
Files:
4 added
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r238230 r238235  
     12018-11-15  Daniel Bates  <dabates@apple.com>
     2
     3        [iOS] Shift + Tab does not focus previous field
     4        https://bugs.webkit.org/show_bug.cgi?id=191596
     5        <rdar://problem/45892053>
     6
     7        Reviewed by Wenson Hsieh.
     8
     9        Add tests to ensure that we do not regress the tab and shift + tab key commands.
     10
     11        * fast/events/ios/focus-tab-next-field-expected.txt: Added.
     12        * fast/events/ios/focus-tab-next-field.html: Added.
     13        * fast/events/ios/focus-tab-previous-field-expected.txt: Added.
     14        * fast/events/ios/focus-tab-previous-field.html: Added.
     15        * platform/ios-wk1/TestExpectations: Skip test focus-tab-previous-field.html in Legacy WebKit as
     16        we do not support testing key commands with modifier keys.
     17        * resources/ui-helper.js:
     18        (window.UIHelper.keyDown): Updated to support taking an optional array of modifiers (defaults: [])
     19        and use the new infrastructure to generate a key down event for the specified character.
     20
    1212018-11-15  Youenn Fablet  <youenn@apple.com>
    222
  • trunk/LayoutTests/platform/ios-wk1/TestExpectations

    r238038 r238235  
    3131fast/forms/datalist [ WontFix ]
    3232imported/w3c/web-platform-tests/html/semantics/forms/the-datalist-element [ WontFix ]
     33
     34# No support for testing key commands with modifiers in WK1
     35fast/events/ios/focus-tab-previous-field.html [ Skip ]
    3336
    3437# <input type=color> is not supported in WebKit1 on iOS.
  • trunk/LayoutTests/resources/ui-helper.js

    r238146 r238235  
    5555    }
    5656
    57     static keyDown(key)
     57    static keyDown(key, modifiers=[])
    5858    {
    5959        if (!this.isWebKit2() || !this.isIOS()) {
     
    6363
    6464        return new Promise((resolve) => {
    65             testRunner.runUIScript(`
    66                 uiController.keyDownUsingHardwareKeyboard("downArrow", function() {
    67                     uiController.uiScriptComplete("Done");
    68                 });`, resolve);
     65            testRunner.runUIScript(`uiController.keyDown("${key}", ${JSON.stringify(modifiers)});`, resolve);
    6966        });
    7067    }
  • trunk/Source/WebKit/ChangeLog

    r238231 r238235  
     12018-11-15  Daniel Bates  <dabates@apple.com>
     2
     3        [iOS] Shift + Tab does not focus previous field
     4        https://bugs.webkit.org/show_bug.cgi?id=191596
     5        <rdar://problem/45892053>
     6
     7        Reviewed by Wenson Hsieh.
     8
     9        Wire up the the tab and shift + tab key commands to the WKWebView/WKContentView's
     10        action forwarding mechanism. Also rename -_prevAccessoryTab to -_previousAccessoryTab.
     11
     12        * Platform/spi/ios/UIKitSPI.h: Add more SPI.
     13        * UIProcess/API/Cocoa/WKWebViewInternal.h:
     14        * UIProcess/ios/WKContentViewInteraction.h:
     15        * UIProcess/ios/WKContentViewInteraction.mm:
     16        (-[WKContentView canPerformActionForWebView:withSender:]):
     17        (-[WKContentView keyCommands]):
     18        (-[WKContentView _nextAccessoryTabForWebView:]): Added.
     19        (-[WKContentView _previousAccessoryTabForWebView:]): Added.
     20        (-[WKContentView _nextAccessoryTab:]): Deleted.
     21        (-[WKContentView _prevAccessoryTab:]): Deleted.
     22
    1232018-11-15  Keith Rollin  <krollin@apple.com>
    224
  • trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h

    r238186 r238235  
    159159
    160160WTF_EXTERN_C_BEGIN
    161 typedef struct __IOHIDEvent * IOHIDEventRef;
     161typedef struct __IOHIDEvent* IOHIDEventRef;
     162typedef struct __GSKeyboard* GSKeyboardRef;
    162163WTF_EXTERN_C_END
    163164
     
    169170- (void)_enqueueHIDEvent:(IOHIDEventRef)event;
    170171- (void)_handleHIDEvent:(IOHIDEventRef)event;
     172- (void)handleKeyUIEvent:(UIEvent *)event;
    171173@end
    172174
     
    10241026
    10251027@interface UIPhysicalKeyboardEvent ()
     1028+ (UIPhysicalKeyboardEvent *)_eventWithInput:(NSString *)input inputFlags:(UIKeyboardInputFlags)flags;
     1029- (void)_setHIDEvent:(IOHIDEventRef)event keyboard:(GSKeyboardRef)gsKeyboard;
     1030- (UIPhysicalKeyboardEvent *)_cloneEvent NS_RETURNS_RETAINED;
    10261031@property (nonatomic, readonly) UIKeyboardInputFlags _inputFlags;
    1027 - (UIPhysicalKeyboardEvent *)_cloneEvent NS_RETURNS_RETAINED;
    10281032@property (nonatomic, readonly) CFIndex _keyCode;
    10291033@end
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h

    r238190 r238235  
    152152- (void)replace:(id)sender;
    153153
     154- (void)_nextAccessoryTab:(id)sender;
     155- (void)_previousAccessoryTab:(id)sender;
     156
    154157- (void)_incrementFocusPreservationCount;
    155158- (void)_decrementFocusPreservationCount;
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h

    r238188 r238235  
    11/*
    2  * Copyright (C) 2012-2017 Apple Inc. All rights reserved.
     2 * Copyright (C) 2012-2018 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    115115    M(_showTextStyleOptions) \
    116116    M(_transliterateChinese) \
     117    M(_nextAccessoryTab) \
     118    M(_previousAccessoryTab) \
    117119    M(copy) \
    118120    M(cut) \
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm

    r238188 r238235  
    11/*
    2  * Copyright (C) 2012-2017 Apple Inc. All rights reserved.
     2 * Copyright (C) 2012-2018 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    24412441
    24422442- (BOOL)canPerformActionForWebView:(SEL)action withSender:(id)sender
    2443 {       
     2443{
     2444    if (action == @selector(_nextAccessoryTab:))
     2445        return hasAssistedNode(_assistedNodeInformation) && _assistedNodeInformation.hasNextNode;
     2446    if (action == @selector(_previousAccessoryTab:))
     2447        return hasAssistedNode(_assistedNodeInformation) && _assistedNodeInformation.hasPreviousNode;
     2448
    24442449    auto editorState = _page->editorState();
    24452450    if (action == @selector(_showTextStyleOptions:))
     
    32193224
    32203225    static NSArray* editableKeyCommands = [@[
    3221        [UIKeyCommand keyCommandWithInput:@"\t" modifierFlags:0 action:@selector(_nextAccessoryTab:)],
    3222        [UIKeyCommand keyCommandWithInput:@"\t" modifierFlags:UIKeyModifierShift action:@selector(_prevAccessoryTab:)]
     3226        [UIKeyCommand keyCommandWithInput:@"\t" modifierFlags:0 action:@selector(_nextAccessoryTab:)],
     3227        [UIKeyCommand keyCommandWithInput:@"\t" modifierFlags:UIKeyModifierShift action:@selector(_previousAccessoryTab:)]
    32233228    ] retain];
    32243229    return editableKeyCommands;
    32253230}
    32263231
    3227 - (void)_nextAccessoryTab:(id)sender
     3232- (void)_nextAccessoryTabForWebView:(id)sender
    32283233{
    32293234    [self accessoryTab:YES];
    32303235}
    32313236
    3232 - (void)_prevAccessoryTab:(id)sender
     3237- (void)_previousAccessoryTabForWebView:(id)sender
    32333238{
    32343239    [self accessoryTab:NO];
  • trunk/Tools/ChangeLog

    r238231 r238235  
     12018-11-15  Daniel Bates  <dabates@apple.com>
     2
     3        [iOS] Shift + Tab does not focus previous field
     4        https://bugs.webkit.org/show_bug.cgi?id=191596
     5        <rdar://problem/45892053>
     6
     7        Reviewed by Wenson Hsieh.
     8
     9        Add infrastructure to support testing a key down event with modifiers by creating
     10        and dispatching a UIEvent. This infrastructure replaces the previous mechanism in
     11        Tools/WebKitTestRunner/ios/HIDEventGenerator.mm to generate a IOHIDEvent for a
     12        keydown as it did not support creating an event with modifier key state that would
     13        be recognized by UIKit.
     14
     15        * DumpRenderTree/ios/UIScriptControllerIOS.mm:
     16        (WTR::UIScriptController::keyDown):
     17        (WTR::UIScriptController::keyDownUsingHardwareKeyboard): Deleted.
     18        (WTR::UIScriptController::keyUpUsingHardwareKeyboard): Deleted.
     19        * TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
     20        Add function uiController.keyDown() that takes a character that represents a keyboard key
     21        and an array of modifier keys. The behavior of this function is analogous to eventSender.keyDown().
     22        Remove functions uiController.keyDownUsingHardwareKeyboard() and uiController.keyUpUsingHardwareKeyboard()
     23        as the former is replaced by uiController.keyDown() and the latter was never used.
     24
     25        * TestRunnerShared/UIScriptContext/UIScriptController.cpp:
     26        (WTR::UIScriptController::keyDown): Added.
     27        (WTR::UIScriptController::keyUpUsingHardwareKeyboard): Deleted.
     28        (WTR::UIScriptController::keyDownUsingHardwareKeyboard): Deleted.
     29        * TestRunnerShared/UIScriptContext/UIScriptController.h:
     30        * WebKitTestRunner/ios/HIDEventGenerator.h:
     31        * WebKitTestRunner/ios/HIDEventGenerator.mm:
     32        (createHIDKeyDownEvent): Added.
     33        (-[HIDEventGenerator keyDown:completionBlock:]): Deleted.
     34        (-[HIDEventGenerator keyUp:completionBlock:]): Deleted.
     35        * WebKitTestRunner/ios/UIScriptControllerIOS.mm:
     36        (WTR::arrayLength): Added.
     37        (WTR::parseModifier): Added.
     38        (WTR::parseModifierArray): Added.
     39        (WTR::UIScriptController::keyDown):
     40        (WTR::UIScriptController::keyDownUsingHardwareKeyboard): Deleted.
     41        (WTR::UIScriptController::keyUpUsingHardwareKeyboard): Deleted.
     42
    1432018-11-15  Keith Rollin  <krollin@apple.com>
    244
  • trunk/Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm

    r238146 r238235  
    152152}
    153153
    154 void UIScriptController::keyDownUsingHardwareKeyboard(JSStringRef character, JSValueRef callback)
    155 {
    156 }
    157 
    158 void UIScriptController::keyUpUsingHardwareKeyboard(JSStringRef character, JSValueRef callback)
     154void UIScriptController::keyDown(JSStringRef, JSValueRef)
    159155{
    160156}
  • trunk/Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl

    r238146 r238235  
    11/*
    2  * Copyright (C) 2015 Apple Inc. All rights reserved.
     2 * Copyright (C) 2015-2018 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3131};
    3232
     33enum ModifierKey {
     34    "alt",
     35    "capsLock",
     36    "ctrl",
     37    "meta", // Command key on Mac and iOS
     38    "shift"
     39};
     40
    3341interface UIScriptController {
    3442
     
    6169    void enterText(DOMString text);
    6270    void typeCharacterUsingHardwareKeyboard(DOMString character, object callback);
    63     void keyDownUsingHardwareKeyboard(DOMString character, object callback);
    64     void keyUpUsingHardwareKeyboard(DOMString character, object callback);
     71
     72    void keyDown(DOMString character, object modifierArray);
    6573
    6674    // eventsJSON describes a series of user events in JSON form. For the keys, see HIDEventGenerator.mm.
  • trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp

    r238146 r238235  
    297297}
    298298
    299 void UIScriptController::keyUpUsingHardwareKeyboard(JSStringRef, JSValueRef)
    300 {
    301 }
    302 
    303 void UIScriptController::keyDownUsingHardwareKeyboard(JSStringRef, JSValueRef)
     299void UIScriptController::keyDown(JSStringRef, JSValueRef)
    304300{
    305301}
  • trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h

    r238146 r238235  
    9090    void enterText(JSStringRef);
    9191    void typeCharacterUsingHardwareKeyboard(JSStringRef character, JSValueRef callback);
    92     void keyDownUsingHardwareKeyboard(JSStringRef character, JSValueRef callback);
    93     void keyUpUsingHardwareKeyboard(JSStringRef character, JSValueRef callback);
     92
     93    void keyDown(JSStringRef character, JSValueRef modifierArray);
    9494
    9595    void keyboardAccessoryBarNext();
  • trunk/Tools/WebKitTestRunner/ios/HIDEventGenerator.h

    r238134 r238235  
    2727
    2828#import <CoreGraphics/CGGeometry.h>
     29#import <wtf/RetainPtr.h>
    2930
    3031// Keys for sendEventStream:completionBlock:.
     
    6970extern NSUInteger const HIDMaxTouchCount;
    7071
     72RetainPtr<IOHIDEventRef> createHIDKeyDownEvent(NSString *, uint64_t timestamp);
     73
    7174@interface HIDEventGenerator : NSObject
    7275
     
    106109// Keyboard
    107110- (void)keyPress:(NSString *)character completionBlock:(void (^)(void))completionBlock;
    108 - (void)keyDown:(NSString *)character completionBlock:(void (^)(void))completionBlock;
    109 - (void)keyUp:(NSString *)character completionBlock:(void (^)(void))completionBlock;
    110111
    111112@end
  • trunk/Tools/WebKitTestRunner/ios/HIDEventGenerator.mm

    r238134 r238235  
    3434#import <wtf/BlockPtr.h>
    3535#import <wtf/Optional.h>
    36 #import <wtf/RetainPtr.h>
    3736#import <wtf/SoftLinking.h>
    3837
     
    199198    [super dealloc];
    200199}
    201 
    202 
    203200
    204201- (void)_sendIOHIDKeyboardEvent:(uint64_t)timestamp usage:(uint32_t)usage isKeyDown:(bool)isKeyDown
     
    977974}
    978975
     976RetainPtr<IOHIDEventRef> createHIDKeyDownEvent(NSString *character, uint64_t timestamp)
     977{
     978    return adoptCF(IOHIDEventCreateKeyboardEvent(kCFAllocatorDefault, timestamp, kHIDPage_KeyboardOrKeypad, hidUsageCodeForCharacter(character), true /* key down */, kIOHIDEventOptionNone));
     979}
     980
    979981- (void)keyPress:(NSString *)character completionBlock:(void (^)(void))completionBlock
    980982{
     
    987989
    988990    [self _sendIOHIDKeyboardEvent:absoluteMachTime usage:usage isKeyDown:true];
    989     [self _sendIOHIDKeyboardEvent:absoluteMachTime usage:usage isKeyDown:false];
    990 
    991     if (shouldWrapWithShift)
    992         [self _sendIOHIDKeyboardEvent:absoluteMachTime usage:kHIDUsage_KeyboardLeftShift isKeyDown:false];
    993 
    994     [self _sendMarkerHIDEventWithCompletionBlock:completionBlock];
    995 }
    996 
    997 - (void)keyDown:(NSString *)character completionBlock:(void (^)(void))completionBlock
    998 {
    999     bool shouldWrapWithShift = shouldWrapWithShiftKeyEventForCharacter(character);
    1000     uint32_t usage = hidUsageCodeForCharacter(character);
    1001     uint64_t absoluteMachTime = mach_absolute_time();
    1002 
    1003     if (shouldWrapWithShift)
    1004         [self _sendIOHIDKeyboardEvent:absoluteMachTime usage:kHIDUsage_KeyboardLeftShift isKeyDown:true];
    1005 
    1006     [self _sendIOHIDKeyboardEvent:absoluteMachTime usage:usage isKeyDown:true];
    1007 
    1008     [self _sendMarkerHIDEventWithCompletionBlock:completionBlock];
    1009 }
    1010 
    1011 - (void)keyUp:(NSString *)character completionBlock:(void (^)(void))completionBlock
    1012 {
    1013     bool shouldWrapWithShift = shouldWrapWithShiftKeyEventForCharacter(character);
    1014     uint32_t usage = hidUsageCodeForCharacter(character);
    1015     uint64_t absoluteMachTime = mach_absolute_time();
    1016 
    1017991    [self _sendIOHIDKeyboardEvent:absoluteMachTime usage:usage isKeyDown:false];
    1018992
  • trunk/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm

    r238146 r238235  
    4343#import <WebKit/WKWebViewPrivate.h>
    4444#import <WebKit/WebKit.h>
     45#import <wtf/SoftLinking.h>
     46
     47SOFT_LINK_FRAMEWORK(UIKit)
     48SOFT_LINK_CLASS(UIKit, UIPhysicalKeyboardEvent)
     49
     50@interface UIPhysicalKeyboardEvent (UIPhysicalKeyboardEventHack)
     51@property (nonatomic, assign) NSInteger _modifierFlags;
     52@end
    4553
    4654namespace WTR {
     
    341349}
    342350
    343 void UIScriptController::keyDownUsingHardwareKeyboard(JSStringRef character, JSValueRef callback)
    344 {
    345     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
    346 
    347     // Assumes that the keyboard is already shown.
    348     [[HIDEventGenerator sharedHIDEventGenerator] keyDown:toWTFString(toWK(character)) completionBlock:^{
    349         if (!m_context)
    350             return;
    351         m_context->asyncTaskComplete(callbackID);
    352     }];
    353 }
    354 
    355 void UIScriptController::keyUpUsingHardwareKeyboard(JSStringRef character, JSValueRef callback)
    356 {
    357     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
    358 
    359     // Assumes that the keyboard is already shown.
    360     [[HIDEventGenerator sharedHIDEventGenerator] keyUp:toWTFString(toWK(character)) completionBlock:^{
    361         if (!m_context)
    362             return;
    363         m_context->asyncTaskComplete(callbackID);
    364     }];
     351static unsigned arrayLength(JSContextRef context, JSObjectRef array)
     352{
     353    auto lengthString = adopt(JSStringCreateWithUTF8CString("length"));
     354    if (auto lengthValue = JSObjectGetProperty(context, array, lengthString.get(), nullptr))
     355        return static_cast<unsigned>(JSValueToNumber(context, lengthValue, nullptr));
     356    return 0;
     357}
     358
     359static UIKeyModifierFlags parseModifier(JSStringRef modifier)
     360{
     361    if (JSStringIsEqualToUTF8CString(modifier, "altKey"))
     362        return UIKeyModifierAlternate;
     363    if (JSStringIsEqualToUTF8CString(modifier, "capsLockKey"))
     364        return UIKeyModifierAlphaShift;
     365    if (JSStringIsEqualToUTF8CString(modifier, "ctrlKey"))
     366        return UIKeyModifierControl;
     367    if (JSStringIsEqualToUTF8CString(modifier, "metaKey"))
     368        return UIKeyModifierCommand;
     369    if (JSStringIsEqualToUTF8CString(modifier, "shiftKey"))
     370        return UIKeyModifierShift;
     371    return 0;
     372}
     373
     374static UIKeyModifierFlags parseModifierArray(JSContextRef context, JSValueRef arrayValue)
     375{
     376    if (!arrayValue)
     377        return 0;
     378
     379    // The value may either be a string with a single modifier or an array of modifiers.
     380    if (JSValueIsString(context, arrayValue)) {
     381        auto string = adopt(JSValueToStringCopy(context, arrayValue, nullptr));
     382        return parseModifier(string.get());
     383    }
     384
     385    if (!JSValueIsObject(context, arrayValue))
     386        return 0;
     387    JSObjectRef array = const_cast<JSObjectRef>(arrayValue);
     388    unsigned length = arrayLength(context, array);
     389    UIKeyModifierFlags modifiers = 0;
     390    for (unsigned i = 0; i < length; ++i) {
     391        JSValueRef exception = nullptr;
     392        JSValueRef value = JSObjectGetPropertyAtIndex(context, array, i, &exception);
     393        if (exception)
     394            continue;
     395        auto string = adopt(JSValueToStringCopy(context, value, &exception));
     396        if (exception)
     397            continue;
     398        modifiers |= parseModifier(string.get());
     399    }
     400    return modifiers;
     401}
     402
     403void UIScriptController::keyDown(JSStringRef character, JSValueRef modifierArray)
     404{
     405    // Character can be either a single Unicode code point or the name of a special key (e.g. "downArrow").
     406    // createHIDKeyEvent() knows how to map these special keys to the appropriate keycode.
     407    //
     408    // FIXME: The UIEvent input string for special keys (e.g. "downArrow") should either be a UIKeyInput*
     409    // string constant or an ASCII control character. In practice the input string for a special key is
     410    // ambiguious (e.g. F5 and F6 have the same string - the ASCII DLE character) and hence it is effectively
     411    // ignored in favor of key identification by keycode. So, we just take the empty string as the input string
     412    // for a special key.
     413    String inputString = toWTFString(toWK(character));
     414    String uiEventInputString = inputString.length() > 1 ? emptyString() : inputString;
     415    auto *keyboardEvent = [getUIPhysicalKeyboardEventClass() _eventWithInput:uiEventInputString inputFlags:(UIKeyboardInputFlags)0];
     416    keyboardEvent._modifierFlags = parseModifierArray(m_context->jsContext(), modifierArray);
     417    auto hidEvent = createHIDKeyDownEvent(inputString, keyboardEvent.timestamp);
     418    [keyboardEvent _setHIDEvent:hidEvent.get() keyboard:nullptr];
     419    [[UIApplication sharedApplication] handleKeyUIEvent:keyboardEvent];
    365420}
    366421
Note: See TracChangeset for help on using the changeset viewer.