Changeset 240604 in webkit


Ignore:
Timestamp:
Jan 28, 2019 3:00:41 PM (5 years ago)
Author:
dbates@webkit.org
Message:

[iOS] Make Window virtual key code computation match Mac
https://bugs.webkit.org/show_bug.cgi?id=193452

Reviewed by Ryosuke Niwa.

Source/WebCore:

Use the same approach for computing the Windows virtual key code on iOS as we do on Mac for
web compatibility. On Mac, we prefer to compute the Windows virtual key code from the input
strings of the key event and use the key event's keycode as a last resort.

Test: fast/events/ios/key-events-meta-alt-combinations.html

  • platform/ios/PlatformEventFactoryIOS.h:
  • platform/ios/PlatformEventFactoryIOS.mm:

(WebCore::isKeypadEvent): Added.
(WebCore::windowsKeyCodeForKeyEvent): Added.
(WebCore::PlatformKeyboardEventBuilder::PlatformKeyboardEventBuilder): Modified to call
WebCore::windowsKeyCodeForKeyEvent() to compute the Windows virtual key code.

Source/WebKit:

Compute the Windows virtual key code from the WebEvent.

  • Shared/ios/WebIOSEventFactory.mm:

(WebIOSEventFactory::createWebKeyboardEvent):

LayoutTests:

Add a test that ensures we do not regress DOM key events dispatches for combinations
of Option and Command + Option key commands.

  • fast/events/ios/key-events-meta-alt-combinations-expected.txt: Added.
  • fast/events/ios/key-events-meta-alt-combinations.html: Added.
  • fast/events/ios/resources/key-tester.js: Added.

(computeDifference):
(areArraysEqual):
(areKeyCommandsEqual):
(KeyCommand):
(KeyCommand.prototype.toString):
(keyCommandsHasCommand):
(computeSubsets.compareByModifierOrder):
(handleKeyUp):
(handleKeyPress):
(log):
(logKeyEvent):
(displayNameForTest):
(nextKeyPress):
(runTest):
(setUp):

Location:
trunk
Files:
4 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r240579 r240604  
     12019-01-28  Daniel Bates  <dabates@apple.com>
     2
     3        [iOS] Make Window virtual key code computation match Mac
     4        https://bugs.webkit.org/show_bug.cgi?id=193452
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Add a test that ensures we do not regress DOM key events dispatches for combinations
     9        of Option and Command + Option key commands.
     10
     11        * fast/events/ios/key-events-meta-alt-combinations-expected.txt: Added.
     12        * fast/events/ios/key-events-meta-alt-combinations.html: Added.
     13        * fast/events/ios/resources/key-tester.js: Added.
     14        (computeDifference):
     15        (areArraysEqual):
     16        (areKeyCommandsEqual):
     17        (KeyCommand):
     18        (KeyCommand.prototype.toString):
     19        (keyCommandsHasCommand):
     20        (computeSubsets.compareByModifierOrder):
     21        (handleKeyUp):
     22        (handleKeyPress):
     23        (log):
     24        (logKeyEvent):
     25        (displayNameForTest):
     26        (nextKeyPress):
     27        (runTest):
     28        (setUp):
     29
    1302019-01-28  Antoine Quint  <graouts@apple.com>
    231
  • trunk/Source/WebCore/ChangeLog

    r240596 r240604  
     12019-01-28  Daniel Bates  <dabates@apple.com>
     2
     3        [iOS] Make Window virtual key code computation match Mac
     4        https://bugs.webkit.org/show_bug.cgi?id=193452
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Use the same approach for computing the Windows virtual key code on iOS as we do on Mac for
     9        web compatibility. On Mac, we prefer to compute the  Windows virtual key code from the input
     10        strings of the key event and use the key event's keycode as a last resort.
     11
     12        Test: fast/events/ios/key-events-meta-alt-combinations.html
     13
     14        * platform/ios/PlatformEventFactoryIOS.h:
     15        * platform/ios/PlatformEventFactoryIOS.mm:
     16        (WebCore::isKeypadEvent): Added.
     17        (WebCore::windowsKeyCodeForKeyEvent): Added.
     18        (WebCore::PlatformKeyboardEventBuilder::PlatformKeyboardEventBuilder): Modified to call
     19        WebCore::windowsKeyCodeForKeyEvent() to compute the Windows virtual key code.
     20
    1212019-01-28  Antoine Quint  <graouts@apple.com>
    222
  • trunk/Source/WebCore/platform/ios/PlatformEventFactoryIOS.h

    r237266 r240604  
    5454WEBCORE_EXPORT String codeForKeyEvent(WebEvent *);
    5555WEBCORE_EXPORT String keyIdentifierForKeyEvent(WebEvent *);
     56WEBCORE_EXPORT int windowsKeyCodeForKeyEvent(WebEvent*);
    5657
    5758} // namespace WebCore
  • trunk/Source/WebCore/platform/ios/PlatformEventFactoryIOS.mm

    r239361 r240604  
    11/*
    2  * Copyright (C) 2004, 2006, 2007, 2008, 2009, 2010, 2011, 2014 Apple Inc. All rights reserved.
     2 * Copyright (C) 2004, 2006-2011, 2014, 2019 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    421421}
    422422
     423static bool isKeypadEvent(WebEvent* event)
     424{
     425    // Check that this is the type of event that has a keyCode.
     426    if (event.type != WebEventKeyDown && event.type != WebEventKeyUp)
     427        return false;
     428
     429    // With the exception of keypad comma, the following corresponds to the criterion for UIKeyModifierNumericPad.
     430    // FIXME: Recognize keypad comma.
     431    switch (event.keyCode) {
     432    case VK_CLEAR: // Num Pad Clear
     433    case VK_OEM_PLUS: // Num Pad =
     434    case VK_DIVIDE:
     435    case VK_MULTIPLY:
     436    case VK_SUBTRACT:
     437    case VK_ADD:
     438    case VK_RETURN: // Num Pad Enter
     439    case VK_DECIMAL: // Num Pad .
     440    case VK_NUMPAD0:
     441    case VK_NUMPAD1:
     442    case VK_NUMPAD2:
     443    case VK_NUMPAD3:
     444    case VK_NUMPAD4:
     445    case VK_NUMPAD5:
     446    case VK_NUMPAD6:
     447    case VK_NUMPAD7:
     448    case VK_NUMPAD8:
     449    case VK_NUMPAD9:
     450        return true;
     451    }
     452    return false;
     453}
     454
     455int windowsKeyCodeForKeyEvent(WebEvent* event)
     456{
     457    if (event.keyboardFlags & WebEventKeyboardInputModifierFlagsChanged)
     458        return event.keyCode;
     459
     460    // There are several kinds of characters for which we produce key code from char code:
     461    // 1. Roman letters. Windows keyboard layouts affect both virtual key codes and character codes for these,
     462    //    so e.g. 'A' gets the same keyCode on QWERTY, AZERTY or Dvorak layouts.
     463    // 2. Keys for which there is no known iOS virtual key codes, like PrintScreen.
     464    // 3. Certain punctuation keys. On Windows, these are also remapped depending on current keyboard layout,
     465    //    but see comment in windowsKeyCodeForCharCode().
     466    if (!isKeypadEvent(event) && (event.type == WebEventKeyDown || event.type == WebEventKeyUp)) {
     467        // Cmd switches Roman letters for Dvorak-QWERTY layout, so try modified characters first.
     468        NSString *string = event.characters;
     469        int code = string.length > 0 ? windowsKeyCodeForCharCode([string characterAtIndex:0]) : 0;
     470        if (code)
     471            return code;
     472
     473        // Ctrl+A on an AZERTY keyboard would get VK_Q keyCode if we relied on -[WebEvent keyCode] below.
     474        string = event.charactersIgnoringModifiers;
     475        code = string.length > 0 ? windowsKeyCodeForCharCode([string characterAtIndex:0]) : 0;
     476        if (code)
     477            return code;
     478    }
     479
     480    // Use iOS virtual key code directly for any keys not handled above.
     481    // E.g. the key next to Caps Lock has the same Event.keyCode on U.S. keyboard ('A') and on
     482    // Russian keyboard (CYRILLIC LETTER EF).
     483    return event.keyCode;
     484}
     485
    423486class PlatformKeyboardEventBuilder : public PlatformKeyboardEvent {
    424487public:
     
    443506        m_code = codeForKeyEvent(event);
    444507        m_keyIdentifier = keyIdentifierForKeyEvent(event);
    445         m_windowsVirtualKeyCode = event.keyCode;
     508        m_windowsVirtualKeyCode = windowsKeyCodeForKeyEvent(event);
    446509        m_isKeypad = false; // iOS does not distinguish the numpad. See <rdar://problem/7190835>.
    447510        m_isSystemKey = false;
  • trunk/Source/WebKit/ChangeLog

    r240602 r240604  
     12019-01-28  Daniel Bates  <dabates@apple.com>
     2
     3        [iOS] Make Window virtual key code computation match Mac
     4        https://bugs.webkit.org/show_bug.cgi?id=193452
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Compute the Windows virtual key code from the WebEvent.
     9
     10        * Shared/ios/WebIOSEventFactory.mm:
     11        (WebIOSEventFactory::createWebKeyboardEvent):
     12
    1132019-01-28  Brent Fulgham  <bfulgham@apple.com>
    214
  • trunk/Source/WebKit/Shared/ios/WebIOSEventFactory.mm

    r237738 r240604  
    6969    String code = WebCore::codeForKeyEvent(event);
    7070    String keyIdentifier = WebCore::keyIdentifierForKeyEvent(event);
    71     int windowsVirtualKeyCode = event.keyCode;
     71    int windowsVirtualKeyCode = WebCore::windowsKeyCodeForKeyEvent(event);
    7272    // FIXME: This is not correct. WebEvent.keyCode represents the Windows native virtual key code.
    7373    int nativeVirtualKeyCode = event.keyCode;
Note: See TracChangeset for help on using the changeset viewer.