Changeset 239277 in webkit


Ignore:
Timestamp:
Dec 17, 2018 11:19:25 AM (5 years ago)
Author:
dbates@webkit.org
Message:

Implement UIScriptController::toggleCapsLock() for iOS
https://bugs.webkit.org/show_bug.cgi?id=191815

Reviewed by Andy Estes.

Source/WebCore/PAL:

Add HID usage enumerator for the Caps Lock key.

  • pal/spi/cocoa/IOKitSPI.h:

Source/WebKit:

Add test infrastructure to clear the current modifier state. We will use this to ensure that
the caps lock state does not persist between tests.

  • UIProcess/API/C/WKContext.cpp:

(WKContextClearCurrentModifierStateForTesting): Added.

  • UIProcess/API/C/WKContextPrivate.h:
  • UIProcess/WebProcessPool.cpp:

(WebKit::WebProcessPool::clearCurrentModifierStateForTesting): Added.

  • UIProcess/WebProcessPool.h:
  • WebProcess/WebProcess.cpp:

(WebKit::WebProcess::clearCurrentModifierStateForTesting): Added.

  • WebProcess/WebProcess.h:
  • WebProcess/WebProcess.messages.in:

Tools:

Add support for toggling the caps lock state in WebKitTestRunner on iOS.

  • TestRunnerShared/UIScriptContext/UIScriptController.h:
  • WebKitTestRunner/TestController.cpp:

(WTR::TestController::resetStateToConsistentValues): Clear the current modifier state
before running a test. This ensures that the caps lock state does not persist between
tests should a test enable caps lock and not disable it.

  • WebKitTestRunner/ios/HIDEventGenerator.mm:

(hidUsageCodeForCharacter): Map "capsLock" to the Caps Lock key usage code.

  • WebKitTestRunner/ios/UIScriptControllerIOS.mm:

(WTR::createUIPhysicalKeyboardEvent): Modified to take the keyboard input flags to use to
create the event. Also substituted NSString* for const String& as the data type for the first
two parameters to avoid conversions in the implementation of UIScriptController::toggleCapsLock()
below.
(WTR::UIScriptController::keyDown): Update as needed due to changes to prototype of createUIPhysicalKeyboardEvent().
(WTR::UIScriptController::toggleCapsLock): Dispatch a UIEvent to toggle caps lock.

LayoutTests:

Add iOS-specific results for some of the tests. We need to continue to skip the caps
lock tests on iOS until we have the fix for <rdar://problem/44930119>.

  • fast/forms/password-scrolled-after-caps-lock-toggled.html: Replace input.focus() with

UIHelper.activateElement(input) to make it work on iOS and update logic accordingly.
Compensate for the fact that one less character than the size of the input is visible in
a password field on iOS.

  • fast/repaint/placeholder-after-caps-lock-hidden.html: Replace input.focus() with

UIHelper.activateElement(input) to make it work on iOS and update logic accordingly.

  • platform/ios-wk2/TestExpectations:
  • platform/ios-wk2/fast/forms/password-scrolled-after-caps-lock-toggled-expected.txt: Added.
  • platform/ios-wk2/fast/repaint/placeholder-after-caps-lock-hidden-expected.txt: Added.
Location:
trunk
Files:
3 added
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r239268 r239277  
     12018-12-17  Daniel Bates  <dabates@apple.com>
     2
     3        Implement UIScriptController::toggleCapsLock() for iOS
     4        https://bugs.webkit.org/show_bug.cgi?id=191815
     5
     6        Reviewed by Andy Estes.
     7
     8        Add iOS-specific results for some of the tests. We need to continue to skip the caps
     9        lock tests on iOS until we have the fix for <rdar://problem/44930119>.
     10
     11        * fast/forms/password-scrolled-after-caps-lock-toggled.html: Replace input.focus() with
     12        UIHelper.activateElement(input) to make it work on iOS and update logic accordingly.
     13        Compensate for the fact that one less character than the size of the input is visible in
     14        a password field on iOS.
     15        * fast/repaint/placeholder-after-caps-lock-hidden.html: Replace input.focus() with
     16        UIHelper.activateElement(input) to make it work on iOS and update logic accordingly.
     17        * platform/ios-wk2/TestExpectations:
     18        * platform/ios-wk2/fast/forms/password-scrolled-after-caps-lock-toggled-expected.txt: Added.
     19        * platform/ios-wk2/fast/repaint/placeholder-after-caps-lock-hidden-expected.txt: Added.
     20
    1212018-12-17  Simon Fraser  <simon.fraser@apple.com>
    222
  • trunk/LayoutTests/fast/forms/password-scrolled-after-caps-lock-toggled.html

    r238522 r239277  
    5353{
    5454    debug("Case 1: Empty field:");
    55     input.focus();
    56     shouldBeZero("document.getElementById('input').scrollLeft");
    57     runNextTest();
     55    function handleFocus() {
     56        shouldBeZero("document.getElementById('input').scrollLeft");
     57        runNextTest();
     58    }
     59    input.addEventListener("focus", handleFocus, { once: true });
     60    if (window.testRunner)
     61        UIHelper.activateElement(input);
     62    else
     63        input.focus();
    5864}
    5965
     
    9197    }
    9298
    93     let oldValue = document.getElementById('input').scrollLeft;
     99    let oldValue = document.getElementById("input").scrollLeft;
    94100    function handleCapsLockChange(event) {
    95101        console.assert(event.key === "CapsLock");
    96         callback(oldValue, document.getElementById('input').scrollLeft);
     102        callback(oldValue, document.getElementById("input").scrollLeft);
    97103        runNextTest();
    98104    }
     
    167173console.assert(input.hasAttribute("size"));
    168174numberOfCharactersToOverflowFieldWhenCapsLockShown = input.size;
     175
     176// FIXME: Find a way to compute the maximum number of visible characters the field can hold
     177// in a way that allows for running this test by hand.
     178let mayBeIOS = window.TouchEvent != undefined;
     179if (mayBeIOS) {
     180    // The look of the password field on iOS gives less space to the value than on Mac.
     181    --numberOfCharactersToOverflowFieldWhenCapsLockShown;
     182}
    169183console.assert(numberOfCharactersToOverflowFieldWhenCapsLockShown >= 3);
    170184
  • trunk/LayoutTests/fast/repaint/placeholder-after-caps-lock-hidden.html

    r238520 r239277  
    3939
    4040    let input = document.getElementById("input");
    41     input.focus();
    42 
    43     function handleCapsLockEnabled(event) {
    44         console.assert(event.key === "CapsLock");
    45         input.addEventListener("keyup", handleKeyUp, false);
    46         UIHelper.keyDown("a");
     41    function handleFocus() {
     42        function handleCapsLockEnabled(event) {
     43            console.assert(event.key === "CapsLock");
     44            input.addEventListener("keyup", handleKeyUp, false);
     45            UIHelper.keyDown("a");
     46        }
     47        input.addEventListener("keydown", handleCapsLockEnabled, { once: true });
     48        UIHelper.toggleCapsLock();
    4749    }
    48     input.addEventListener("keydown", handleCapsLockEnabled, { once: true });
    49     UIHelper.toggleCapsLock();
     50    input.addEventListener("focus", handleFocus, { once: true });
     51    UIHelper.activateElement(input);
    5052}
    5153</script>
  • trunk/LayoutTests/platform/ios-wk2/TestExpectations

    r238939 r239277  
    13251325http/wpt/webauthn/public-key-credential-get-failure-hid.https.html [ Skip ]
    13261326http/wpt/webauthn/public-key-credential-get-success-hid.https.html [ Skip ]
     1327
     1328# FIXME: Unskip these tests once we have the fix for <rdar://problem/44930119>.
     1329fast/forms/auto-fill-button/caps-lock-indicator-should-be-visible-after-hiding-auto-fill-strong-password-button.html [ Skip ]
     1330fast/forms/auto-fill-button/caps-lock-indicator-should-not-be-visible-when-auto-fill-strong-password-button-is-visible.html [ Skip ]
     1331fast/forms/password-scrolled-after-caps-lock-toggled.html [ Skip ]
     1332fast/repaint/placeholder-after-caps-lock-hidden.html [ Skip ]
  • trunk/Source/WebCore/PAL/ChangeLog

    r239273 r239277  
     12018-12-17  Daniel Bates  <dabates@apple.com>
     2
     3        Implement UIScriptController::toggleCapsLock() for iOS
     4        https://bugs.webkit.org/show_bug.cgi?id=191815
     5
     6        Reviewed by Andy Estes.
     7
     8        Add HID usage enumerator for the Caps Lock key.
     9
     10        * pal/spi/cocoa/IOKitSPI.h:
     11
    1122018-12-17  Matt Lewis  <jlewis3@apple.com>
    213
  • trunk/Source/WebCore/PAL/pal/spi/cocoa/IOKitSPI.h

    r236678 r239277  
    184184    kHIDUsage_KeyboardPeriod = 0x37,
    185185    kHIDUsage_KeyboardSlash = 0x38,
     186    kHIDUsage_KeyboardCapsLock = 0x39,
    186187    kHIDUsage_KeyboardF1 = 0x3A,
    187188    kHIDUsage_KeyboardPrintScreen = 0x46,
  • trunk/Source/WebKit/ChangeLog

    r239276 r239277  
     12018-12-17  Daniel Bates  <dabates@apple.com>
     2
     3        Implement UIScriptController::toggleCapsLock() for iOS
     4        https://bugs.webkit.org/show_bug.cgi?id=191815
     5
     6        Reviewed by Andy Estes.
     7
     8        Add test infrastructure to clear the current modifier state. We will use this to ensure that
     9        the caps lock state does not persist between tests.
     10
     11        * UIProcess/API/C/WKContext.cpp:
     12        (WKContextClearCurrentModifierStateForTesting): Added.
     13        * UIProcess/API/C/WKContextPrivate.h:
     14        * UIProcess/WebProcessPool.cpp:
     15        (WebKit::WebProcessPool::clearCurrentModifierStateForTesting): Added.
     16        * UIProcess/WebProcessPool.h:
     17        * WebProcess/WebProcess.cpp:
     18        (WebKit::WebProcess::clearCurrentModifierStateForTesting): Added.
     19        * WebProcess/WebProcess.h:
     20        * WebProcess/WebProcess.messages.in:
     21
    1222018-12-17  David Kilzer  <ddkilzer@apple.com>
    223
  • trunk/Source/WebKit/UIProcess/API/C/WKContext.cpp

    r239258 r239277  
    650650    WebKit::toImpl(contextRef)->setIDBPerOriginQuota(quota);
    651651}
     652
     653void WKContextClearCurrentModifierStateForTesting(WKContextRef contextRef)
     654{
     655    toImpl(contextRef)->clearCurrentModifierStateForTesting();
     656}
  • trunk/Source/WebKit/UIProcess/API/C/WKContextPrivate.h

    r237700 r239277  
    119119WK_EXPORT void WKContextSetIDBPerOriginQuota(WKContextRef context, uint64_t quota);
    120120
     121WK_EXPORT void WKContextClearCurrentModifierStateForTesting(WKContextRef context);
     122
    121123#ifdef __cplusplus
    122124}
  • trunk/Source/WebKit/UIProcess/WebProcessPool.cpp

    r239273 r239277  
    23592359}
    23602360
     2361void WebProcessPool::clearCurrentModifierStateForTesting()
     2362{
     2363    sendToAllProcesses(Messages::WebProcess::ClearCurrentModifierStateForTesting());
     2364}
     2365
    23612366} // namespace WebKit
  • trunk/Source/WebKit/UIProcess/WebProcessPool.h

    r239080 r239277  
    468468
    469469    void sendDisplayConfigurationChangedMessageForTesting();
     470    void clearCurrentModifierStateForTesting();
    470471
    471472#if PLATFORM(GTK) || PLATFORM(WPE)
  • trunk/Source/WebKit/WebProcess/WebProcess.cpp

    r238867 r239277  
    105105#include <WebCore/PageCache.h>
    106106#include <WebCore/PageGroup.h>
     107#include <WebCore/PlatformKeyboardEvent.h>
    107108#include <WebCore/PlatformMediaSessionManager.h>
    108109#include <WebCore/ProcessWarming.h>
     
    17621763#endif
    17631764
     1765void WebProcess::clearCurrentModifierStateForTesting()
     1766{
     1767    PlatformKeyboardEvent::setCurrentModifierState({ });
     1768}
     1769
    17641770} // namespace WebKit
  • trunk/Source/WebKit/WebProcess/WebProcess.h

    r238867 r239277  
    400400#endif
    401401
     402    void clearCurrentModifierStateForTesting();
     403
    402404    RefPtr<WebConnectionToUIProcess> m_webConnection;
    403405
  • trunk/Source/WebKit/WebProcess/WebProcess.messages.in

    r238593 r239277  
    154154    ResetMockMediaDevices();
    155155#endif
     156
     157    ClearCurrentModifierStateForTesting()
    156158}
  • trunk/Tools/ChangeLog

    r239275 r239277  
     12018-12-17  Daniel Bates  <dabates@apple.com>
     2
     3        Implement UIScriptController::toggleCapsLock() for iOS
     4        https://bugs.webkit.org/show_bug.cgi?id=191815
     5
     6        Reviewed by Andy Estes.
     7
     8        Add support for toggling the caps lock state in WebKitTestRunner on iOS.
     9
     10        * TestRunnerShared/UIScriptContext/UIScriptController.h:
     11        * WebKitTestRunner/TestController.cpp:
     12        (WTR::TestController::resetStateToConsistentValues): Clear the current modifier state
     13        before running a test. This ensures that the caps lock state does not persist between
     14        tests should a test enable caps lock and not disable it.
     15        * WebKitTestRunner/ios/HIDEventGenerator.mm:
     16        (hidUsageCodeForCharacter): Map "capsLock" to the Caps Lock key usage code.
     17        * WebKitTestRunner/ios/UIScriptControllerIOS.mm:
     18        (WTR::createUIPhysicalKeyboardEvent): Modified to take the keyboard input flags to use to
     19        create the event. Also substituted NSString* for const String& as the data type for the first
     20        two parameters to avoid conversions in the implementation of UIScriptController::toggleCapsLock()
     21        below.
     22        (WTR::UIScriptController::keyDown): Update as needed due to changes to prototype of createUIPhysicalKeyboardEvent().
     23        (WTR::UIScriptController::toggleCapsLock): Dispatch a UIEvent to toggle caps lock.
     24
    1252018-12-17  Daniel Bates  <dabates@apple.com>
    226
  • trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h

    r238939 r239277  
    229229    UIScriptContext* m_context;
    230230
    231 #if PLATFORM(MAC)
     231#if PLATFORM(COCOA)
    232232    bool m_capsLockOn { false };
    233233#endif
  • trunk/Tools/WebKitTestRunner/TestController.cpp

    r239273 r239277  
    873873    WKContextSetAllowsAnySSLCertificateForServiceWorkerTesting(platformContext(), true);
    874874
     875    WKContextClearCurrentModifierStateForTesting(TestController::singleton().context());
     876
    875877    // FIXME: This function should also ensure that there is only one page open.
    876878
  • trunk/Tools/WebKitTestRunner/ios/HIDEventGenerator.mm

    r238526 r239277  
    926926        return *keyCode;
    927927
     928    if ([key isEqualToString:@"capsLock"])
     929        return kHIDUsage_KeyboardCapsLock;
    928930    if ([key isEqualToString:@"pageUp"])
    929931        return kHIDUsage_KeyboardPageUp;
  • trunk/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm

    r238939 r239277  
    401401}
    402402
    403 static UIPhysicalKeyboardEvent *createUIPhysicalKeyboardEvent(const String& hidInputString, const String& uiEventInputString, UIKeyModifierFlags modifierFlags, bool isKeyDown)
    404 {
    405     auto* keyboardEvent = [getUIPhysicalKeyboardEventClass() _eventWithInput:uiEventInputString inputFlags:(UIKeyboardInputFlags)0];
     403static UIPhysicalKeyboardEvent *createUIPhysicalKeyboardEvent(NSString *hidInputString, NSString *uiEventInputString, UIKeyModifierFlags modifierFlags, UIKeyboardInputFlags inputFlags, bool isKeyDown)
     404{
     405    auto* keyboardEvent = [getUIPhysicalKeyboardEventClass() _eventWithInput:uiEventInputString inputFlags:inputFlags];
    406406    keyboardEvent._modifierFlags = modifierFlags;
    407407    auto hidEvent = createHIDKeyEvent(hidInputString, keyboardEvent.timestamp, isKeyDown);
     
    423423    String uiEventInputString = inputString.length() > 1 ? emptyString() : inputString;
    424424    auto modifierFlags = parseModifierArray(m_context->jsContext(), modifierArray);
     425    UIKeyboardInputFlags inputFlags = static_cast<UIKeyboardInputFlags>(0);
    425426
    426427    // Note that UIKit will call -release on the passed UIPhysicalKeyboardEvent.
    427428
    428429    // Key down
    429     auto* keyboardEvent = createUIPhysicalKeyboardEvent(inputString, uiEventInputString, modifierFlags, true /* isKeyDown */);
     430    auto* keyboardEvent = createUIPhysicalKeyboardEvent(inputString, uiEventInputString, modifierFlags, inputFlags, true /* isKeyDown */);
    430431    [[UIApplication sharedApplication] handleKeyUIEvent:keyboardEvent];
    431432
    432433    // Key up
    433     keyboardEvent = createUIPhysicalKeyboardEvent(inputString, uiEventInputString, modifierFlags, false /* isKeyDown */);
     434    keyboardEvent = createUIPhysicalKeyboardEvent(inputString, uiEventInputString, modifierFlags, inputFlags, false /* isKeyDown */);
    434435    [[UIApplication sharedApplication] handleKeyUIEvent:keyboardEvent];
    435436}
     
    933934void UIScriptController::toggleCapsLock(JSValueRef callback)
    934935{
    935     // FIXME: Implement for iOS. See <https://bugs.webkit.org/show_bug.cgi?id=191815>.
     936    m_capsLockOn = !m_capsLockOn;
     937    auto *keyboardEvent = createUIPhysicalKeyboardEvent(@"capsLock", [NSString string], m_capsLockOn ? UIKeyModifierAlphaShift : 0,
     938        kUIKeyboardInputModifierFlagsChanged, m_capsLockOn);
     939    [[UIApplication sharedApplication] handleKeyUIEvent:keyboardEvent];
    936940    doAsyncTask(callback);
    937941}
Note: See TracChangeset for help on using the changeset viewer.