Changeset 27372 in webkit


Ignore:
Timestamp:
Nov 1, 2007 4:30:25 PM (16 years ago)
Author:
oliver
Message:

Correct event behaviour on certain control keys

Reviewed by Geoff

Make sure we send the correct keyDown and keyUp events for the
control keys CapsLock, Shift, Ctrl, Alt, and Meta/Command, and
uses Windows key codes for the event keyCode.

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r27370 r27372  
     12007-11-01  Oliver Hunt  <oliver@apple.com>
     2
     3        Reviewed by Geoff.
     4
     5        Correct event behaviour on certain control keys
     6
     7        Make sure we send the correct keyDown and keyUp events for the
     8        control keys CapsLock, Shift, Ctrl, Alt, and Meta/Command, and
     9        uses Windows key codes for the event keyCode.
     10
     11        * WebCore.base.exp:
     12        * page/EventHandler.cpp:
     13        (WebCore::EventHandler::keyEvent):
     14        * platform/PlatformKeyboardEvent.h:
     15        * platform/gtk/KeyEventGtk.cpp:
     16        (WebCore::PlatformKeyboardEvent::PlatformKeyboardEvent):
     17        * platform/mac/KeyEventMac.mm:
     18        (WebCore::keyIdentifierForKeyEvent):
     19        (WebCore::WindowsKeyCodeForKeyEvent):
     20        (WebCore::isKeyUpEvent):
     21        (WebCore::textFromEvent):
     22        (WebCore::unmodifiedTextFromEvent):
     23        (WebCore::PlatformKeyboardEvent::PlatformKeyboardEvent):
     24        * platform/win/KeyEventWin.cpp:
     25        (WebCore::PlatformKeyboardEvent::PlatformKeyboardEvent):
     26        * platform/wx/KeyEventWin.cpp:
     27        (WebCore::PlatformKeyboardEvent::PlatformKeyboardEvent):
     28
    1292007-11-01  Timothy Hatcher  <timothy@apple.com>
    230
  • trunk/WebCore/WebCore.base.exp

    r27277 r27372  
    209209__ZN7WebCore12EventHandler27capsLockStateMayHaveChangedEv
    210210__ZN7WebCore12EventHandler7mouseUpEP7NSEvent
     211__ZN7WebCore12EventHandler8keyEventERKNS_21PlatformKeyboardEventE
    211212__ZN7WebCore12EventHandler8keyEventEP7NSEvent
    212213__ZN7WebCore12EventHandler9mouseDownEP7NSEvent
  • trunk/WebCore/page/EventHandler.cpp

    r27264 r27372  
    14731473        return true;
    14741474   
    1475     if (handledByInputMethod)
     1475    if (handledByInputMethod || initialKeyEvent.isModifierKeyPress())
    14761476        return result;
    14771477   
  • trunk/WebCore/platform/PlatformKeyboardEvent.h

    r27264 r27372  
    7474        bool altKey() const { return m_altKey; }
    7575        bool metaKey() const { return m_metaKey; }
     76        bool isModifierKeyPress() const { return m_isModifierKeyPress; }
    7677
    7778        static bool currentCapsLockState();
     
    111112        bool m_altKey;
    112113        bool m_metaKey;
     114       
     115        // A control key event -- eg. keydown/up for shift, ctrl, alt, and meta -- needs
     116        // a flag to indicate that we should not generate a keyPress event.
     117        bool m_isModifierKeyPress;
    113118#if PLATFORM(WX)
    114119        bool m_isWxCharEvent;
  • trunk/WebCore/platform/gtk/KeyEventGtk.cpp

    r27306 r27372  
    481481    , m_altKey(event->state & GDK_MOD1_MASK)
    482482    , m_metaKey(event->state & GDK_MOD2_MASK)
     483    , m_isModifierKeyPress(false)
    483484{
    484485}
  • trunk/WebCore/platform/mac/KeyEventMac.mm

    r27264 r27372  
    3737static String keyIdentifierForKeyEvent(NSEvent* event)
    3838{
     39    if ([event type] == NSFlagsChanged)
     40        switch ([event keyCode]) {
     41            case 54: // Right Command
     42            case 55: // Left Command
     43                return "Meta";
     44               
     45            case 57: // Capslock
     46                return "CapsLock";
     47               
     48            case 56: // Left Shift
     49            case 60: // Right Shift
     50                return "Shift";
     51               
     52            case 58: // Left Alt
     53            case 61: // Right Alt
     54                return "Alt";
     55               
     56            case 59: // Left Ctrl
     57            case 62: // Right Ctrl
     58                return "Control";
     59               
     60            default:
     61                ASSERT_NOT_REACHED();
     62                return "";
     63        }
     64   
    3965    NSString *s = [event charactersIgnoringModifiers];
    4066    if ([s length] != 1) {
     
    374400        case 48: return 0x09;
    375401
     402        // VK_APPS (5D) Right windows/meta key
     403        case 54: // Right Command
     404            return 0x5D;
     405           
     406        // VK_LWIN (5B) Left windows/meta key
     407        case 55: // Left Command
     408            return 0x5B;
     409           
     410        // VK_CAPITAL (14) caps locks key
     411        case 57: // Capslock
     412            return 0x14;
     413           
     414        // VK_SHIFT (10) either shift key
     415        case 56: // Left Shift
     416        case 60: // Right Shift
     417            return 0x10;
     418           
     419        // VK_MENU (12) either alt key
     420        case 58: // Left Alt
     421        case 61: // Right Alt
     422            return 0x12;
     423           
     424        // VK_CONTROL (11) either ctrl key
     425        case 59: // Left Ctrl
     426        case 62: // Right Ctrl
     427            return 0x11;
     428           
    376429        // VK_CLEAR (0C) CLEAR key
    377430        case 71: return 0x0C;
     
    709762}
    710763
     764static inline bool isKeyUpEvent(NSEvent *event)
     765{
     766    if ([event type] != NSFlagsChanged)
     767        return false;
     768    switch ([event keyCode]) {
     769        case 54: // Right Command
     770        case 55: // Left Command
     771            return ([event modifierFlags] & NSCommandKeyMask) == 0;
     772           
     773        case 57: // Capslock
     774            return ([event modifierFlags] & NSAlphaShiftKeyMask) == 0;
     775           
     776        case 56: // Left Shift
     777        case 60: // Right Shift
     778            return ([event modifierFlags] & NSShiftKeyMask) == 0;
     779           
     780        case 58: // Left Alt
     781        case 61: // Right Alt
     782            return ([event modifierFlags] & NSAlternateKeyMask) == 0;
     783           
     784        case 59: // Left Ctrl
     785        case 62: // Right Ctrl
     786            return ([event modifierFlags] & NSControlKeyMask) == 0;
     787           
     788        case 63: // Function
     789            return ([event modifierFlags] & NSFunctionKeyMask) == 0;
     790    }
     791    return false;
     792}
     793
     794static inline String textFromEvent(NSEvent* event)
     795{
     796    if ([event type] == NSFlagsChanged)
     797        return "";
     798    return [event characters];
     799}
     800   
     801   
     802static inline String unmodifiedTextFromEvent(NSEvent* event)
     803{
     804    if ([event type] == NSFlagsChanged)
     805        return "";
     806    return [event charactersIgnoringModifiers];
     807}
     808   
    711809PlatformKeyboardEvent::PlatformKeyboardEvent(NSEvent *event, bool forceAutoRepeat)
    712     : m_text([event characters])
    713     , m_unmodifiedText([event charactersIgnoringModifiers])
     810    : m_text(textFromEvent(event))
     811    , m_unmodifiedText(unmodifiedTextFromEvent(event))
    714812    , m_keyIdentifier(keyIdentifierForKeyEvent(event))
    715     , m_isKeyUp([event type] == NSKeyUp)
    716     , m_autoRepeat(forceAutoRepeat || [event isARepeat])
     813    , m_isKeyUp([event type] == NSKeyUp || isKeyUpEvent(event))
     814    , m_autoRepeat(([event type] != NSFlagsChanged) && (forceAutoRepeat || [event isARepeat]))
    717815    , m_WindowsKeyCode(WindowsKeyCodeForKeyEvent(event))
    718816    , m_isKeypad(isKeypadEvent(event))
     
    721819    , m_altKey([event modifierFlags] & NSAlternateKeyMask)
    722820    , m_metaKey([event modifierFlags] & NSCommandKeyMask)
     821    , m_isModifierKeyPress([event type] == NSFlagsChanged)
    723822    , m_macEvent(event)
    724823{
  • trunk/WebCore/platform/win/KeyEventWin.cpp

    r27264 r27372  
    152152    , m_altKey(GetKeyState(VK_MENU) & HIGH_BIT_MASK_SHORT)
    153153    , m_metaKey(m_altKey)
     154    , m_isModifierKeyPress(false)
    154155{
    155156}
  • trunk/WebCore/platform/wx/KeyEventWin.cpp

    r21445 r27372  
    149149    , m_altKey(lParam & ALT_KEY_DOWN_MASK)
    150150    , m_metaKey(lParam & ALT_KEY_DOWN_MASK) // FIXME: Is this right?
     151    , m_isModifierKeyPress(false)
    151152{
    152153    if (!m_shiftKey)
  • trunk/WebKit/WebView/WebHTMLView.mm

    r27369 r27372  
    35863586    if (Frame* frame = core([self _frame]))
    35873587        frame->eventHandler()->capsLockStateMayHaveChanged();
     3588   
     3589    RetainPtr<WebHTMLView> selfProtector = self;
     3590   
     3591    //Don't make an event from the function key
     3592    if ([event keyCode] != 63)
     3593        core([self _frame])->eventHandler()->keyEvent(PlatformKeyboardEvent(event));
     3594       
    35883595    [super flagsChanged:event];
    35893596}
     
    52225229        if ([macEvent type] == NSKeyDown && [_private->compController filterKeyDown:macEvent])
    52235230            return true;
     5231       
     5232        if ([macEvent type] == NSFlagsChanged)
     5233            return false;
     5234       
    52245235        parameters.event = event;
    52255236        _private->interpretKeyEventsParameters = &parameters;
Note: See TracChangeset for help on using the changeset viewer.