Changeset 134855 in webkit


Ignore:
Timestamp:
Nov 15, 2012 4:30:14 PM (11 years ago)
Author:
bfulgham@webkit.org
Message:

[Win] key event's location does not work on Windows platform.
https://bugs.webkit.org/show_bug.cgi?id=89742

Patch by Takashi Sakamoto <tasak@google.com> on 2012-11-15
Reviewed by Brent Fulgham.

As WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, and WM_SYSKEYUP doesn't
directly provide a virtual keycode which distinguish between left-hand
and right-hand keys. To obtain a virtual keycode, we have to look at
lparam, i.e. scancode and extended key bit. So if the given virtual
keycode is control, shift, or menu, use MapVirtualKey with scancode and
extended key bit and recreate a virtual keycode which distinguishes
between left-hand and right-hand.

No new tests, because left-hand keys, right-hand keys layout tests
have been already added.

  • platform/win/KeyEventWin.cpp:

(WebCore::windowsKeycodeWithLocation):
Use wparam and lparam to recreate a virtual keycode which distinguishes
between left-hand and right-hand if the given wparam (=virtual keycode)
is control, shift, or menu.
(WebCore):
(WebCore::PlatformKeyboardEvent::PlatformKeyboardEvent):
Use the newly added function to obtain windows virtual keycode.

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r134853 r134855  
     12012-11-15  Takashi Sakamoto  <tasak@google.com>
     2
     3        [Win] key event's location does not work on Windows platform.
     4        https://bugs.webkit.org/show_bug.cgi?id=89742
     5
     6        Reviewed by Brent Fulgham.
     7
     8        As WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, and WM_SYSKEYUP doesn't
     9        directly provide a virtual keycode which distinguish between left-hand
     10        and right-hand keys. To obtain a virtual keycode, we have to look at
     11        lparam, i.e. scancode and extended key bit. So if the given virtual
     12        keycode is control, shift, or menu, use MapVirtualKey with scancode and
     13        extended key bit and recreate a virtual keycode which distinguishes
     14        between left-hand and right-hand.
     15
     16        No new tests, because left-hand keys, right-hand keys layout tests
     17        have been already added.
     18
     19        * platform/win/KeyEventWin.cpp:
     20        (WebCore::windowsKeycodeWithLocation):
     21        Use wparam and lparam to recreate a virtual keycode which distinguishes
     22        between left-hand and right-hand if the given wparam (=virtual keycode)
     23        is control, shift, or menu.
     24        (WebCore):
     25        (WebCore::PlatformKeyboardEvent::PlatformKeyboardEvent):
     26        Use the newly added function to obtain windows virtual keycode.
     27
    1282012-11-15  Joe Mason  <jmason@rim.com>
    229
  • trunk/Source/WebCore/platform/win/KeyEventWin.cpp

    r103643 r134855  
    2929#include <windows.h>
    3030#include <wtf/ASCIICType.h>
     31
     32#ifndef MAPVK_VSC_TO_VK_EX
     33#define MAPVK_VSC_TO_VK_EX 3
     34#endif
    3135
    3236using namespace WTF;
     
    185189}
    186190
     191static int windowsKeycodeWithLocation(WPARAM keycode, LPARAM keyData)
     192{
     193    if (keycode != VK_CONTROL && keycode != VK_MENU && keycode != VK_SHIFT)
     194        return keycode;
     195
     196    // If we don't need to support Windows XP or older Windows,
     197    // it might be better to use MapVirtualKeyEx with scancode and
     198    // extended keycode (i.e. 0xe0 or 0xe1).
     199    if ((keyData >> 16) & KF_EXTENDED) {
     200        switch (keycode) {
     201        case VK_CONTROL:
     202            return VK_RCONTROL;
     203        case VK_SHIFT:
     204            return VK_RSHIFT;
     205        case VK_MENU:
     206            return VK_RMENU;
     207        default:
     208            break;
     209        }
     210    }
     211
     212    int scancode = (keyData >> 16) & 0xFF;
     213    int regeneratedVirtualKeyCode = ::MapVirtualKey(scancode, MAPVK_VSC_TO_VK_EX);
     214    return regeneratedVirtualKeyCode ? regeneratedVirtualKeyCode : keycode;
     215}
     216
    187217static inline String singleCharacterString(UChar c)
    188218{
     
    195225    , m_unmodifiedText((type == PlatformEvent::Char) ? singleCharacterString(code) : String())
    196226    , m_keyIdentifier((type == PlatformEvent::Char) ? String() : keyIdentifierForWindowsKeyCode(code))
    197     , m_windowsVirtualKeyCode((type == RawKeyDown || type == KeyUp) ? code : 0)
     227    , m_windowsVirtualKeyCode((type == RawKeyDown || type == KeyUp) ? windowsKeycodeWithLocation(code, keyData) : 0)
    198228    , m_nativeVirtualKeyCode(m_windowsVirtualKeyCode)
    199229    , m_macCharCode(0)
Note: See TracChangeset for help on using the changeset viewer.