Changeset 56361 in webkit


Ignore:
Timestamp:
Mar 22, 2010 2:56:45 PM (14 years ago)
Author:
Joseph Pecoraro
Message:

2010-03-22 Joseph Pecoraro <Joseph Pecoraro>

Reviewed by David Kilzer.

Upstream Part of the iPhone Platform sharing code with the Mac Platform
https://bugs.webkit.org/show_bug.cgi?id=35870
<rdar://problem/7707283>

Part 2 of 3: No changes other than moving code around.
Copied KeyEvent function from platform/mac to a platform/cocoa shared directory.

  • WebCore.xcodeproj/project.pbxproj: Added cocoa group and new files.
  • platform/cocoa/KeyEventCocoa.h: Added.
  • platform/cocoa/KeyEventCocoa.mm: Copied from WebCore/platform/mac/KeyEventMac.mm. (WebCore::keyIdentifierForKeyEvent): (WebCore::windowsKeyCodeForKeyEvent): Include the shared code.
  • platform/mac/KeyEventMac.mm:
Location:
trunk/WebCore
Files:
2 added
3 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r56360 r56361  
     12010-03-22  Joseph Pecoraro  <joepeck@webkit.org>
     2
     3        Reviewed by David Kilzer.
     4
     5        Upstream Part of the iPhone Platform sharing code with the Mac Platform
     6        https://bugs.webkit.org/show_bug.cgi?id=35870
     7        <rdar://problem/7707283>
     8
     9        Part 2 of 3: No changes other than moving code around.
     10        Copied KeyEvent function from platform/mac to a platform/cocoa shared directory.
     11
     12        * WebCore.xcodeproj/project.pbxproj: Added cocoa group and new files.
     13        * platform/cocoa/KeyEventCocoa.h: Added.
     14        * platform/cocoa/KeyEventCocoa.mm: Copied from WebCore/platform/mac/KeyEventMac.mm.
     15        (WebCore::keyIdentifierForKeyEvent):
     16        (WebCore::windowsKeyCodeForKeyEvent): Include the shared code.
     17        * platform/mac/KeyEventMac.mm:
     18
    1192010-03-22  Joseph Pecoraro  <joepeck@webkit.org>
    220
  • trunk/WebCore/WebCore.xcodeproj/project.pbxproj

    r56360 r56361  
    24942494                A43BF59C1149292800C643CA /* RenderProgress.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A43BF59A1149292800C643CA /* RenderProgress.cpp */; };
    24952495                A43BF59D1149292800C643CA /* RenderProgress.h in Headers */ = {isa = PBXBuildFile; fileRef = A43BF59B1149292800C643CA /* RenderProgress.h */; };
     2496                A513B3D7114B1666001C429B /* KeyEventCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = A5C974CF11485FF10066F2AB /* KeyEventCocoa.h */; };
     2497                A513B3D8114B166A001C429B /* KeyEventCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = A5C974D011485FF10066F2AB /* KeyEventCocoa.mm */; };
    24962498                A59E3C1E11580F510072928E /* KeyEventCodesIPhone.h in Headers */ = {isa = PBXBuildFile; fileRef = A59E3C1C11580F510072928E /* KeyEventCodesIPhone.h */; };
    24972499                A59E3C1F11580F510072928E /* KeyEventIPhone.mm in Sources */ = {isa = PBXBuildFile; fileRef = A59E3C1D11580F510072928E /* KeyEventIPhone.mm */; };
     
    79067908                A5AFB34D115151A700B045CB /* StepRange.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StepRange.cpp; sourceTree = "<group>"; };
    79077909                A5AFB34E115151A700B045CB /* StepRange.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StepRange.h; sourceTree = "<group>"; };
     7910                A5C974CF11485FF10066F2AB /* KeyEventCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KeyEventCocoa.h; path = cocoa/KeyEventCocoa.h; sourceTree = "<group>"; };
     7911                A5C974D011485FF10066F2AB /* KeyEventCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = KeyEventCocoa.mm; path = cocoa/KeyEventCocoa.mm; sourceTree = "<group>"; };
    79087912                A718760D0B2A120100A16ECE /* DragActions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DragActions.h; sourceTree = "<group>"; };
    79097913                A718788F0B2D04AC00A16ECE /* DragControllerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DragControllerMac.mm; sourceTree = "<group>"; };
     
    1321613220                        sourceTree = "<group>";
    1321713221                };
     13222                A5C974CE11485FDA0066F2AB /* cocoa */ = {
     13223                        isa = PBXGroup;
     13224                        children = (
     13225                                A5C974CF11485FF10066F2AB /* KeyEventCocoa.h */,
     13226                                A5C974D011485FF10066F2AB /* KeyEventCocoa.mm */,
     13227                        );
     13228                        name = cocoa;
     13229                        sourceTree = "<group>";
     13230                };
    1321813231                A75E8B7F0E1DE2B0007F2481 /* filters */ = {
    1321913232                        isa = PBXGroup;
     
    1530115314                                49E912A40EFAC8E6009D0CAF /* animation */,
    1530215315                                1AE42F670AA4B8CB00C8612D /* cf */,
     15316                                A5C974CE11485FDA0066F2AB /* cocoa */,
    1530315317                                B2A015910AF6CD53006BCE0E /* graphics */,
    1530415318                                A59E3C1B11580F340072928E /* iphone */,
     
    1872718741                                A5AFB350115151A700B045CB /* StepRange.h in Headers */,
    1872818742                                A59E3C1E11580F510072928E /* KeyEventCodesIPhone.h in Headers */,
     18743                                A513B3D7114B1666001C429B /* KeyEventCocoa.h in Headers */,
    1872918744                        );
    1873018745                        runOnlyForDeploymentPostprocessing = 0;
     
    2093720952                                A5AFB34F115151A700B045CB /* StepRange.cpp in Sources */,
    2093820953                                A59E3C1F11580F510072928E /* KeyEventIPhone.mm in Sources */,
     20954                                A513B3D8114B166A001C429B /* KeyEventCocoa.mm in Sources */,
    2093920955                        );
    2094020956                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/WebCore/platform/cocoa/KeyEventCocoa.mm

    r56360 r56361  
    11/*
    2  * Copyright (C) 2004, 2006, 2007, 2010 Apple Inc. All rights reserved.
     2 * Copyright (C) 2004, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2121 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    2222 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
     23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2424 */
    2525
    2626#import "config.h"
    27 #import "PlatformKeyboardEvent.h"
    28 
    29 #if PLATFORM(MAC)
     27#import "KeyEventCocoa.h"
    3028
    3129#import "Logging.h"
    32 #import <Carbon/Carbon.h>
     30#import "PlatformString.h"
    3331#import <wtf/ASCIICType.h>
    3432
     
    3735namespace WebCore {
    3836
    39 static String keyIdentifierForKeyEvent(NSEvent* event)
     37String keyIdentifierForKeyEvent(NSEvent* event)
    4038{
    41     if ([event type] == NSFlagsChanged) 
     39    if ([event type] == NSFlagsChanged)
    4240        switch ([event keyCode]) {
    4341            case 54: // Right Command
    4442            case 55: // Left Command
    4543                return "Meta";
    46                
     44
    4745            case 57: // Capslock
    4846                return "CapsLock";
    49                
     47
    5048            case 56: // Left Shift
    5149            case 60: // Right Shift
    5250                return "Shift";
    53                
     51
    5452            case 58: // Left Alt
    5553            case 61: // Right Alt
    5654                return "Alt";
    57                
     55
    5856            case 59: // Left Ctrl
    5957            case 62: // Right Ctrl
    6058                return "Control";
    61                
     59
    6260            default:
    6361                ASSERT_NOT_REACHED();
    6462                return "";
    6563        }
    66    
     64
    6765    NSString *s = [event charactersIgnoringModifiers];
    6866    if ([s length] != 1) {
     
    332330        case NSDeleteFunctionKey:
    333331            return "U+007F";
    334            
     332
    335333        // Always use 0x09 for tab instead of AppKit's backtab character.
    336334        case NSBackTabCharacter:
     
    359357}
    360358
    361 static bool isKeypadEvent(NSEvent* event)
    362 {
    363     // Check that this is the type of event that has a keyCode.
    364     switch ([event type]) {
    365         case NSKeyDown:
    366         case NSKeyUp:
    367         case NSFlagsChanged:
    368             break;
    369         default:
    370             return false;
    371     }
    372 
    373     if ([event modifierFlags] & NSNumericPadKeyMask)
    374         return true;
    375 
    376     switch ([event keyCode]) {
    377         case 71: // Clear
    378         case 81: // =
    379         case 75: // /
    380         case 67: // *
    381         case 78: // -
    382         case 69: // +
    383         case 76: // Enter
    384         case 65: // .
    385         case 82: // 0
    386         case 83: // 1
    387         case 84: // 2
    388         case 85: // 3
    389         case 86: // 4
    390         case 87: // 5
    391         case 88: // 6
    392         case 89: // 7
    393         case 91: // 8
    394         case 92: // 9
    395             return true;
    396      }
    397      
    398      return false;
    399 }
    400 
    401 static int windowsKeyCodeForKeyEvent(NSEvent* event)
     359int windowsKeyCodeForKeyEvent(NSEvent* event)
    402360{
    403361    switch ([event keyCode]) {
     
    408366        case 54: // Right Command
    409367            return 0x5D;
    410            
     368
    411369        // VK_LWIN (5B) Left windows/meta key
    412370        case 55: // Left Command
    413371            return 0x5B;
    414            
     372
    415373        // VK_CAPITAL (14) caps locks key
    416374        case 57: // Capslock
    417375            return 0x14;
    418            
     376
    419377        // VK_SHIFT (10) either shift key
    420378        case 56: // Left Shift
    421379        case 60: // Right Shift
    422380            return 0x10;
    423            
     381
    424382        // VK_MENU (12) either alt key
    425383        case 58: // Left Alt
    426384        case 61: // Right Alt
    427385            return 0x12;
    428            
     386
    429387        // VK_CONTROL (11) either ctrl key
    430388        case 59: // Left Ctrl
    431389        case 62: // Right Ctrl
    432390            return 0x11;
    433            
     391
    434392        // VK_CLEAR (0C) CLEAR key
    435393        case 71: return 0x0C;
     
    767725}
    768726
    769 static inline bool isKeyUpEvent(NSEvent *event)
    770 {
    771     if ([event type] != NSFlagsChanged)
    772         return [event type] == NSKeyUp;
    773     // FIXME: This logic fails if the user presses both Shift keys at once, for example:
    774     // we treat releasing one of them as keyDown.
    775     switch ([event keyCode]) {
    776         case 54: // Right Command
    777         case 55: // Left Command
    778             return ([event modifierFlags] & NSCommandKeyMask) == 0;
    779            
    780         case 57: // Capslock
    781             return ([event modifierFlags] & NSAlphaShiftKeyMask) == 0;
    782            
    783         case 56: // Left Shift
    784         case 60: // Right Shift
    785             return ([event modifierFlags] & NSShiftKeyMask) == 0;
    786            
    787         case 58: // Left Alt
    788         case 61: // Right Alt
    789             return ([event modifierFlags] & NSAlternateKeyMask) == 0;
    790            
    791         case 59: // Left Ctrl
    792         case 62: // Right Ctrl
    793             return ([event modifierFlags] & NSControlKeyMask) == 0;
    794            
    795         case 63: // Function
    796             return ([event modifierFlags] & NSFunctionKeyMask) == 0;
    797     }
    798     return false;
    799727}
    800 
    801 static inline String textFromEvent(NSEvent* event)
    802 {
    803     if ([event type] == NSFlagsChanged)
    804         return "";
    805     return [event characters];
    806 }
    807    
    808    
    809 static inline String unmodifiedTextFromEvent(NSEvent* event)
    810 {
    811     if ([event type] == NSFlagsChanged)
    812         return "";
    813     return [event charactersIgnoringModifiers];
    814 }
    815 
    816 PlatformKeyboardEvent::PlatformKeyboardEvent(NSEvent *event)
    817     : m_type(isKeyUpEvent(event) ? PlatformKeyboardEvent::KeyUp : PlatformKeyboardEvent::KeyDown)
    818     , m_text(textFromEvent(event))
    819     , m_unmodifiedText(unmodifiedTextFromEvent(event))
    820     , m_keyIdentifier(keyIdentifierForKeyEvent(event))
    821     , m_autoRepeat(([event type] != NSFlagsChanged) && [event isARepeat])
    822     , m_windowsVirtualKeyCode(windowsKeyCodeForKeyEvent(event))
    823     , m_nativeVirtualKeyCode([event keyCode])
    824     , m_isKeypad(isKeypadEvent(event))
    825     , m_shiftKey([event modifierFlags] & NSShiftKeyMask)
    826     , m_ctrlKey([event modifierFlags] & NSControlKeyMask)
    827     , m_altKey([event modifierFlags] & NSAlternateKeyMask)
    828     , m_metaKey([event modifierFlags] & NSCommandKeyMask)
    829     , m_macEvent(event)
    830 {
    831     // Always use 13 for Enter/Return -- we don't want to use AppKit's different character for Enter.
    832     if (m_windowsVirtualKeyCode == '\r') {
    833         m_text = "\r";
    834         m_unmodifiedText = "\r";
    835     }
    836 
    837     // The adjustments below are only needed in backward compatibility mode, but we cannot tell what mode we are in from here.
    838 
    839     // Turn 0x7F into 8, because backspace needs to always be 8.
    840     if (m_text == "\x7F")
    841         m_text = "\x8";
    842     if (m_unmodifiedText == "\x7F")
    843         m_unmodifiedText = "\x8";
    844     // Always use 9 for tab -- we don't want to use AppKit's different character for shift-tab.
    845     if (m_windowsVirtualKeyCode == 9) {
    846         m_text = "\x9";
    847         m_unmodifiedText = "\x9";
    848     }
    849 }
    850 
    851 void PlatformKeyboardEvent::disambiguateKeyDownEvent(Type type, bool backwardCompatibilityMode)
    852 {
    853     // Can only change type from KeyDown to RawKeyDown or Char, as we lack information for other conversions.
    854     ASSERT(m_type == KeyDown);
    855     ASSERT(type == RawKeyDown || type == Char);
    856     m_type = type;
    857     if (backwardCompatibilityMode)
    858         return;
    859 
    860     if (type == RawKeyDown) {
    861         m_text = String();
    862         m_unmodifiedText = String();
    863     } else {
    864         m_keyIdentifier = String();
    865         m_windowsVirtualKeyCode = 0;
    866         if (m_text.length() == 1 && (m_text[0U] >= 0xF700 && m_text[0U] <= 0xF7FF)) {
    867             // According to NSEvents.h, OpenStep reserves the range 0xF700-0xF8FF for function keys. However, some actual private use characters
    868             // happen to be in this range, e.g. the Apple logo (Option+Shift+K).
    869             // 0xF7FF is an arbitrary cut-off.
    870             m_text = String();
    871             m_unmodifiedText = String();
    872         }
    873     }
    874 }
    875 
    876 bool PlatformKeyboardEvent::currentCapsLockState()
    877 {
    878     return GetCurrentKeyModifiers() & alphaLock;
    879 }
    880 
    881 void PlatformKeyboardEvent::getCurrentModifierState(bool& shiftKey, bool& ctrlKey, bool& altKey, bool& metaKey)
    882 {
    883     UInt32 currentModifiers = GetCurrentKeyModifiers();
    884     shiftKey = currentModifiers & ::shiftKey;
    885     ctrlKey = currentModifiers & ::controlKey;
    886     altKey = currentModifiers & ::optionKey;
    887     metaKey = currentModifiers & ::cmdKey;
    888 }
    889 
    890 }
    891 
    892 #endif // PLATFORM(MAC)
  • trunk/WebCore/platform/mac/KeyEventMac.mm

    r56360 r56361  
    2929#if PLATFORM(MAC)
    3030
     31#import "KeyEventCocoa.h"
    3132#import "Logging.h"
    3233#import <Carbon/Carbon.h>
     
    3637
    3738namespace WebCore {
    38 
    39 static String keyIdentifierForKeyEvent(NSEvent* event)
    40 {
    41     if ([event type] == NSFlagsChanged)
    42         switch ([event keyCode]) {
    43             case 54: // Right Command
    44             case 55: // Left Command
    45                 return "Meta";
    46                
    47             case 57: // Capslock
    48                 return "CapsLock";
    49                
    50             case 56: // Left Shift
    51             case 60: // Right Shift
    52                 return "Shift";
    53                
    54             case 58: // Left Alt
    55             case 61: // Right Alt
    56                 return "Alt";
    57                
    58             case 59: // Left Ctrl
    59             case 62: // Right Ctrl
    60                 return "Control";
    61                
    62             default:
    63                 ASSERT_NOT_REACHED();
    64                 return "";
    65         }
    66    
    67     NSString *s = [event charactersIgnoringModifiers];
    68     if ([s length] != 1) {
    69         LOG(Events, "received an unexpected number of characters in key event: %u", [s length]);
    70         return "Unidentified";
    71     }
    72     unichar c = [s characterAtIndex:0];
    73     switch (c) {
    74         // Each identifier listed in the DOM spec is listed here.
    75         // Many are simply commented out since they do not appear on standard Macintosh keyboards
    76         // or are on a key that doesn't have a corresponding character.
    77 
    78         // "Accept"
    79         // "AllCandidates"
    80 
    81         // "Alt"
    82         case NSMenuFunctionKey:
    83             return "Alt";
    84 
    85         // "Apps"
    86         // "BrowserBack"
    87         // "BrowserForward"
    88         // "BrowserHome"
    89         // "BrowserRefresh"
    90         // "BrowserSearch"
    91         // "BrowserStop"
    92         // "CapsLock"
    93 
    94         // "Clear"
    95         case NSClearLineFunctionKey:
    96             return "Clear";
    97 
    98         // "CodeInput"
    99         // "Compose"
    100         // "Control"
    101         // "Crsel"
    102         // "Convert"
    103         // "Copy"
    104         // "Cut"
    105 
    106         // "Down"
    107         case NSDownArrowFunctionKey:
    108             return "Down";
    109         // "End"
    110         case NSEndFunctionKey:
    111             return "End";
    112         // "Enter"
    113         case 0x3: case 0xA: case 0xD: // Macintosh calls the one on the main keyboard Return, but Windows calls it Enter, so we'll do the same for the DOM
    114             return "Enter";
    115 
    116         // "EraseEof"
    117 
    118         // "Execute"
    119         case NSExecuteFunctionKey:
    120             return "Execute";
    121 
    122         // "Exsel"
    123 
    124         // "F1"
    125         case NSF1FunctionKey:
    126             return "F1";
    127         // "F2"
    128         case NSF2FunctionKey:
    129             return "F2";
    130         // "F3"
    131         case NSF3FunctionKey:
    132             return "F3";
    133         // "F4"
    134         case NSF4FunctionKey:
    135             return "F4";
    136         // "F5"
    137         case NSF5FunctionKey:
    138             return "F5";
    139         // "F6"
    140         case NSF6FunctionKey:
    141             return "F6";
    142         // "F7"
    143         case NSF7FunctionKey:
    144             return "F7";
    145         // "F8"
    146         case NSF8FunctionKey:
    147             return "F8";
    148         // "F9"
    149         case NSF9FunctionKey:
    150             return "F9";
    151         // "F10"
    152         case NSF10FunctionKey:
    153             return "F10";
    154         // "F11"
    155         case NSF11FunctionKey:
    156             return "F11";
    157         // "F12"
    158         case NSF12FunctionKey:
    159             return "F12";
    160         // "F13"
    161         case NSF13FunctionKey:
    162             return "F13";
    163         // "F14"
    164         case NSF14FunctionKey:
    165             return "F14";
    166         // "F15"
    167         case NSF15FunctionKey:
    168             return "F15";
    169         // "F16"
    170         case NSF16FunctionKey:
    171             return "F16";
    172         // "F17"
    173         case NSF17FunctionKey:
    174             return "F17";
    175         // "F18"
    176         case NSF18FunctionKey:
    177             return "F18";
    178         // "F19"
    179         case NSF19FunctionKey:
    180             return "F19";
    181         // "F20"
    182         case NSF20FunctionKey:
    183             return "F20";
    184         // "F21"
    185         case NSF21FunctionKey:
    186             return "F21";
    187         // "F22"
    188         case NSF22FunctionKey:
    189             return "F22";
    190         // "F23"
    191         case NSF23FunctionKey:
    192             return "F23";
    193         // "F24"
    194         case NSF24FunctionKey:
    195             return "F24";
    196 
    197         // "FinalMode"
    198 
    199         // "Find"
    200         case NSFindFunctionKey:
    201             return "Find";
    202 
    203         // "FullWidth"
    204         // "HalfWidth"
    205         // "HangulMode"
    206         // "HanjaMode"
    207 
    208         // "Help"
    209         case NSHelpFunctionKey:
    210             return "Help";
    211 
    212         // "Hiragana"
    213 
    214         // "Home"
    215         case NSHomeFunctionKey:
    216             return "Home";
    217         // "Insert"
    218         case NSInsertFunctionKey:
    219             return "Insert";
    220 
    221         // "JapaneseHiragana"
    222         // "JapaneseKatakana"
    223         // "JapaneseRomaji"
    224         // "JunjaMode"
    225         // "KanaMode"
    226         // "KanjiMode"
    227         // "Katakana"
    228         // "LaunchApplication1"
    229         // "LaunchApplication2"
    230         // "LaunchMail"
    231 
    232         // "Left"
    233         case NSLeftArrowFunctionKey:
    234             return "Left";
    235 
    236         // "Meta"
    237         // "MediaNextTrack"
    238         // "MediaPlayPause"
    239         // "MediaPreviousTrack"
    240         // "MediaStop"
    241 
    242         // "ModeChange"
    243         case NSModeSwitchFunctionKey:
    244             return "ModeChange";
    245 
    246         // "Nonconvert"
    247         // "NumLock"
    248 
    249         // "PageDown"
    250         case NSPageDownFunctionKey:
    251             return "PageDown";
    252         // "PageUp"
    253         case NSPageUpFunctionKey:
    254             return "PageUp";
    255 
    256         // "Paste"
    257 
    258         // "Pause"
    259         case NSPauseFunctionKey:
    260             return "Pause";
    261 
    262         // "Play"
    263         // "PreviousCandidate"
    264 
    265         // "PrintScreen"
    266         case NSPrintScreenFunctionKey:
    267             return "PrintScreen";
    268 
    269         // "Process"
    270         // "Props"
    271 
    272         // "Right"
    273         case NSRightArrowFunctionKey:
    274             return "Right";
    275 
    276         // "RomanCharacters"
    277 
    278         // "Scroll"
    279         case NSScrollLockFunctionKey:
    280             return "Scroll";
    281         // "Select"
    282         case NSSelectFunctionKey:
    283             return "Select";
    284 
    285         // "SelectMedia"
    286         // "Shift"
    287 
    288         // "Stop"
    289         case NSStopFunctionKey:
    290             return "Stop";
    291         // "Up"
    292         case NSUpArrowFunctionKey:
    293             return "Up";
    294         // "Undo"
    295         case NSUndoFunctionKey:
    296             return "Undo";
    297 
    298         // "VolumeDown"
    299         // "VolumeMute"
    300         // "VolumeUp"
    301         // "Win"
    302         // "Zoom"
    303 
    304         // More function keys, not in the key identifier specification.
    305         case NSF25FunctionKey:
    306             return "F25";
    307         case NSF26FunctionKey:
    308             return "F26";
    309         case NSF27FunctionKey:
    310             return "F27";
    311         case NSF28FunctionKey:
    312             return "F28";
    313         case NSF29FunctionKey:
    314             return "F29";
    315         case NSF30FunctionKey:
    316             return "F30";
    317         case NSF31FunctionKey:
    318             return "F31";
    319         case NSF32FunctionKey:
    320             return "F32";
    321         case NSF33FunctionKey:
    322             return "F33";
    323         case NSF34FunctionKey:
    324             return "F34";
    325         case NSF35FunctionKey:
    326             return "F35";
    327 
    328         // Turn 0x7F into 0x08, because backspace needs to always be 0x08.
    329         case 0x7F:
    330             return "U+0008";
    331         // Standard says that DEL becomes U+007F.
    332         case NSDeleteFunctionKey:
    333             return "U+007F";
    334            
    335         // Always use 0x09 for tab instead of AppKit's backtab character.
    336         case NSBackTabCharacter:
    337             return "U+0009";
    338 
    339         case NSBeginFunctionKey:
    340         case NSBreakFunctionKey:
    341         case NSClearDisplayFunctionKey:
    342         case NSDeleteCharFunctionKey:
    343         case NSDeleteLineFunctionKey:
    344         case NSInsertCharFunctionKey:
    345         case NSInsertLineFunctionKey:
    346         case NSNextFunctionKey:
    347         case NSPrevFunctionKey:
    348         case NSPrintFunctionKey:
    349         case NSRedoFunctionKey:
    350         case NSResetFunctionKey:
    351         case NSSysReqFunctionKey:
    352         case NSSystemFunctionKey:
    353         case NSUserFunctionKey:
    354             // FIXME: We should use something other than the vendor-area Unicode values for the above keys.
    355             // For now, just fall through to the default.
    356         default:
    357             return String::format("U+%04X", toASCIIUpper(c));
    358     }
    359 }
    36039
    36140static bool isKeypadEvent(NSEvent* event)
     
    39978}
    40079
    401 static int windowsKeyCodeForKeyEvent(NSEvent* event)
    402 {
    403     switch ([event keyCode]) {
    404         // VK_TAB (09) TAB key
    405         case 48: return 0x09;
    406 
    407         // VK_APPS (5D) Right windows/meta key
    408         case 54: // Right Command
    409             return 0x5D;
    410            
    411         // VK_LWIN (5B) Left windows/meta key
    412         case 55: // Left Command
    413             return 0x5B;
    414            
    415         // VK_CAPITAL (14) caps locks key
    416         case 57: // Capslock
    417             return 0x14;
    418            
    419         // VK_SHIFT (10) either shift key
    420         case 56: // Left Shift
    421         case 60: // Right Shift
    422             return 0x10;
    423            
    424         // VK_MENU (12) either alt key
    425         case 58: // Left Alt
    426         case 61: // Right Alt
    427             return 0x12;
    428            
    429         // VK_CONTROL (11) either ctrl key
    430         case 59: // Left Ctrl
    431         case 62: // Right Ctrl
    432             return 0x11;
    433            
    434         // VK_CLEAR (0C) CLEAR key
    435         case 71: return 0x0C;
    436 
    437         // VK_NUMPAD0 (60) Numeric keypad 0 key
    438         case 82: return 0x60;
    439         // VK_NUMPAD1 (61) Numeric keypad 1 key
    440         case 83: return 0x61;
    441         // VK_NUMPAD2 (62) Numeric keypad 2 key
    442         case 84: return 0x62;
    443         // VK_NUMPAD3 (63) Numeric keypad 3 key
    444         case 85: return 0x63;
    445         // VK_NUMPAD4 (64) Numeric keypad 4 key
    446         case 86: return 0x64;
    447         // VK_NUMPAD5 (65) Numeric keypad 5 key
    448         case 87: return 0x65;
    449         // VK_NUMPAD6 (66) Numeric keypad 6 key
    450         case 88: return 0x66;
    451         // VK_NUMPAD7 (67) Numeric keypad 7 key
    452         case 89: return 0x67;
    453         // VK_NUMPAD8 (68) Numeric keypad 8 key
    454         case 91: return 0x68;
    455         // VK_NUMPAD9 (69) Numeric keypad 9 key
    456         case 92: return 0x69;
    457         // VK_MULTIPLY (6A) Multiply key
    458         case 67: return 0x6A;
    459         // VK_ADD (6B) Add key
    460         case 69: return 0x6B;
    461 
    462         // VK_SUBTRACT (6D) Subtract key
    463         case 78: return 0x6D;
    464         // VK_DECIMAL (6E) Decimal key
    465         case 65: return 0x6E;
    466         // VK_DIVIDE (6F) Divide key
    467         case 75: return 0x6F;
    468      }
    469 
    470     NSString* s = [event charactersIgnoringModifiers];
    471     if ([s length] != 1)
    472         return 0;
    473 
    474     switch ([s characterAtIndex:0]) {
    475         // VK_LBUTTON (01) Left mouse button
    476         // VK_RBUTTON (02) Right mouse button
    477         // VK_CANCEL (03) Control-break processing
    478         // VK_MBUTTON (04) Middle mouse button (three-button mouse)
    479         // VK_XBUTTON1 (05)
    480         // VK_XBUTTON2 (06)
    481 
    482         // VK_BACK (08) BACKSPACE key
    483         case 8: case 0x7F: return 0x08;
    484         // VK_TAB (09) TAB key
    485         case 9: return 0x09;
    486 
    487         // VK_CLEAR (0C) CLEAR key
    488         // handled by key code above
    489 
    490         // VK_RETURN (0D)
    491         case 0xD: case 3: return 0x0D;
    492 
    493         // VK_SHIFT (10) SHIFT key
    494         // VK_CONTROL (11) CTRL key
    495         // VK_MENU (12) ALT key
    496 
    497         // VK_PAUSE (13) PAUSE key
    498         case NSPauseFunctionKey: return 0x13;
    499 
    500         // VK_CAPITAL (14) CAPS LOCK key
    501         // VK_KANA (15) Input Method Editor (IME) Kana mode
    502         // VK_HANGUEL (15) IME Hanguel mode (maintained for compatibility; use VK_HANGUL)
    503         // VK_HANGUL (15) IME Hangul mode
    504         // VK_JUNJA (17) IME Junja mode
    505         // VK_FINAL (18) IME final mode
    506         // VK_HANJA (19) IME Hanja mode
    507         // VK_KANJI (19) IME Kanji mode
    508 
    509         // VK_ESCAPE (1B) ESC key
    510         case 0x1B: return 0x1B;
    511 
    512         // VK_CONVERT (1C) IME convert
    513         // VK_NONCONVERT (1D) IME nonconvert
    514         // VK_ACCEPT (1E) IME accept
    515         // VK_MODECHANGE (1F) IME mode change request
    516 
    517         // VK_SPACE (20) SPACEBAR
    518         case ' ': return 0x20;
    519         // VK_PRIOR (21) PAGE UP key
    520         case NSPageUpFunctionKey: return 0x21;
    521         // VK_NEXT (22) PAGE DOWN key
    522         case NSPageDownFunctionKey: return 0x22;
    523         // VK_END (23) END key
    524         case NSEndFunctionKey: return 0x23;
    525         // VK_HOME (24) HOME key
    526         case NSHomeFunctionKey: return 0x24;
    527         // VK_LEFT (25) LEFT ARROW key
    528         case NSLeftArrowFunctionKey: return 0x25;
    529         // VK_UP (26) UP ARROW key
    530         case NSUpArrowFunctionKey: return 0x26;
    531         // VK_RIGHT (27) RIGHT ARROW key
    532         case NSRightArrowFunctionKey: return 0x27;
    533         // VK_DOWN (28) DOWN ARROW key
    534         case NSDownArrowFunctionKey: return 0x28;
    535         // VK_SELECT (29) SELECT key
    536         case NSSelectFunctionKey: return 0x29;
    537         // VK_PRINT (2A) PRINT key
    538         case NSPrintFunctionKey: return 0x2A;
    539         // VK_EXECUTE (2B) EXECUTE key
    540         case NSExecuteFunctionKey: return 0x2B;
    541         // VK_SNAPSHOT (2C) PRINT SCREEN key
    542         case NSPrintScreenFunctionKey: return 0x2C;
    543         // VK_INSERT (2D) INS key
    544         case NSInsertFunctionKey: case NSHelpFunctionKey: return 0x2D;
    545         // VK_DELETE (2E) DEL key
    546         case NSDeleteFunctionKey: return 0x2E;
    547 
    548         // VK_HELP (2F) HELP key
    549 
    550         //  (30) 0 key
    551         case '0': case ')': return 0x30;
    552         //  (31) 1 key
    553         case '1': case '!': return 0x31;
    554         //  (32) 2 key
    555         case '2': case '@': return 0x32;
    556         //  (33) 3 key
    557         case '3': case '#': return 0x33;
    558         //  (34) 4 key
    559         case '4': case '$': return 0x34;
    560         //  (35) 5 key
    561         case '5': case '%': return 0x35;
    562         //  (36) 6 key
    563         case '6': case '^': return 0x36;
    564         //  (37) 7 key
    565         case '7': case '&': return 0x37;
    566         //  (38) 8 key
    567         case '8': case '*': return 0x38;
    568         //  (39) 9 key
    569         case '9': case '(': return 0x39;
    570         //  (41) A key
    571         case 'a': case 'A': return 0x41;
    572         //  (42) B key
    573         case 'b': case 'B': return 0x42;
    574         //  (43) C key
    575         case 'c': case 'C': return 0x43;
    576         //  (44) D key
    577         case 'd': case 'D': return 0x44;
    578         //  (45) E key
    579         case 'e': case 'E': return 0x45;
    580         //  (46) F key
    581         case 'f': case 'F': return 0x46;
    582         //  (47) G key
    583         case 'g': case 'G': return 0x47;
    584         //  (48) H key
    585         case 'h': case 'H': return 0x48;
    586         //  (49) I key
    587         case 'i': case 'I': return 0x49;
    588         //  (4A) J key
    589         case 'j': case 'J': return 0x4A;
    590         //  (4B) K key
    591         case 'k': case 'K': return 0x4B;
    592         //  (4C) L key
    593         case 'l': case 'L': return 0x4C;
    594         //  (4D) M key
    595         case 'm': case 'M': return 0x4D;
    596         //  (4E) N key
    597         case 'n': case 'N': return 0x4E;
    598         //  (4F) O key
    599         case 'o': case 'O': return 0x4F;
    600         //  (50) P key
    601         case 'p': case 'P': return 0x50;
    602         //  (51) Q key
    603         case 'q': case 'Q': return 0x51;
    604         //  (52) R key
    605         case 'r': case 'R': return 0x52;
    606         //  (53) S key
    607         case 's': case 'S': return 0x53;
    608         //  (54) T key
    609         case 't': case 'T': return 0x54;
    610         //  (55) U key
    611         case 'u': case 'U': return 0x55;
    612         //  (56) V key
    613         case 'v': case 'V': return 0x56;
    614         //  (57) W key
    615         case 'w': case 'W': return 0x57;
    616         //  (58) X key
    617         case 'x': case 'X': return 0x58;
    618         //  (59) Y key
    619         case 'y': case 'Y': return 0x59;
    620         //  (5A) Z key
    621         case 'z': case 'Z': return 0x5A;
    622 
    623         // VK_LWIN (5B) Left Windows key (Microsoft Natural keyboard)
    624         // VK_RWIN (5C) Right Windows key (Natural keyboard)
    625         // VK_APPS (5D) Applications key (Natural keyboard)
    626         // VK_SLEEP (5F) Computer Sleep key
    627 
    628         // VK_NUMPAD0 (60) Numeric keypad 0 key
    629         // VK_NUMPAD1 (61) Numeric keypad 1 key
    630         // VK_NUMPAD2 (62) Numeric keypad 2 key
    631         // VK_NUMPAD3 (63) Numeric keypad 3 key
    632         // VK_NUMPAD4 (64) Numeric keypad 4 key
    633         // VK_NUMPAD5 (65) Numeric keypad 5 key
    634         // VK_NUMPAD6 (66) Numeric keypad 6 key
    635         // VK_NUMPAD7 (67) Numeric keypad 7 key
    636         // VK_NUMPAD8 (68) Numeric keypad 8 key
    637         // VK_NUMPAD9 (69) Numeric keypad 9 key
    638         // VK_MULTIPLY (6A) Multiply key
    639         // VK_ADD (6B) Add key
    640         // handled by key code above
    641 
    642         // VK_SEPARATOR (6C) Separator key
    643 
    644         // VK_SUBTRACT (6D) Subtract key
    645         // VK_DECIMAL (6E) Decimal key
    646         // VK_DIVIDE (6F) Divide key
    647         // handled by key code above
    648 
    649         // VK_F1 (70) F1 key
    650         case NSF1FunctionKey: return 0x70;
    651         // VK_F2 (71) F2 key
    652         case NSF2FunctionKey: return 0x71;
    653         // VK_F3 (72) F3 key
    654         case NSF3FunctionKey: return 0x72;
    655         // VK_F4 (73) F4 key
    656         case NSF4FunctionKey: return 0x73;
    657         // VK_F5 (74) F5 key
    658         case NSF5FunctionKey: return 0x74;
    659         // VK_F6 (75) F6 key
    660         case NSF6FunctionKey: return 0x75;
    661         // VK_F7 (76) F7 key
    662         case NSF7FunctionKey: return 0x76;
    663         // VK_F8 (77) F8 key
    664         case NSF8FunctionKey: return 0x77;
    665         // VK_F9 (78) F9 key
    666         case NSF9FunctionKey: return 0x78;
    667         // VK_F10 (79) F10 key
    668         case NSF10FunctionKey: return 0x79;
    669         // VK_F11 (7A) F11 key
    670         case NSF11FunctionKey: return 0x7A;
    671         // VK_F12 (7B) F12 key
    672         case NSF12FunctionKey: return 0x7B;
    673         // VK_F13 (7C) F13 key
    674         case NSF13FunctionKey: return 0x7C;
    675         // VK_F14 (7D) F14 key
    676         case NSF14FunctionKey: return 0x7D;
    677         // VK_F15 (7E) F15 key
    678         case NSF15FunctionKey: return 0x7E;
    679         // VK_F16 (7F) F16 key
    680         case NSF16FunctionKey: return 0x7F;
    681         // VK_F17 (80H) F17 key
    682         case NSF17FunctionKey: return 0x80;
    683         // VK_F18 (81H) F18 key
    684         case NSF18FunctionKey: return 0x81;
    685         // VK_F19 (82H) F19 key
    686         case NSF19FunctionKey: return 0x82;
    687         // VK_F20 (83H) F20 key
    688         case NSF20FunctionKey: return 0x83;
    689         // VK_F21 (84H) F21 key
    690         case NSF21FunctionKey: return 0x84;
    691         // VK_F22 (85H) F22 key
    692         case NSF22FunctionKey: return 0x85;
    693         // VK_F23 (86H) F23 key
    694         case NSF23FunctionKey: return 0x86;
    695         // VK_F24 (87H) F24 key
    696         case NSF24FunctionKey: return 0x87;
    697 
    698         // VK_NUMLOCK (90) NUM LOCK key
    699 
    700         // VK_SCROLL (91) SCROLL LOCK key
    701         case NSScrollLockFunctionKey: return 0x91;
    702 
    703         // VK_LSHIFT (A0) Left SHIFT key
    704         // VK_RSHIFT (A1) Right SHIFT key
    705         // VK_LCONTROL (A2) Left CONTROL key
    706         // VK_RCONTROL (A3) Right CONTROL key
    707         // VK_LMENU (A4) Left MENU key
    708         // VK_RMENU (A5) Right MENU key
    709         // VK_BROWSER_BACK (A6) Windows 2000/XP: Browser Back key
    710         // VK_BROWSER_FORWARD (A7) Windows 2000/XP: Browser Forward key
    711         // VK_BROWSER_REFRESH (A8) Windows 2000/XP: Browser Refresh key
    712         // VK_BROWSER_STOP (A9) Windows 2000/XP: Browser Stop key
    713         // VK_BROWSER_SEARCH (AA) Windows 2000/XP: Browser Search key
    714         // VK_BROWSER_FAVORITES (AB) Windows 2000/XP: Browser Favorites key
    715         // VK_BROWSER_HOME (AC) Windows 2000/XP: Browser Start and Home key
    716         // VK_VOLUME_MUTE (AD) Windows 2000/XP: Volume Mute key
    717         // VK_VOLUME_DOWN (AE) Windows 2000/XP: Volume Down key
    718         // VK_VOLUME_UP (AF) Windows 2000/XP: Volume Up key
    719         // VK_MEDIA_NEXT_TRACK (B0) Windows 2000/XP: Next Track key
    720         // VK_MEDIA_PREV_TRACK (B1) Windows 2000/XP: Previous Track key
    721         // VK_MEDIA_STOP (B2) Windows 2000/XP: Stop Media key
    722         // VK_MEDIA_PLAY_PAUSE (B3) Windows 2000/XP: Play/Pause Media key
    723         // VK_LAUNCH_MAIL (B4) Windows 2000/XP: Start Mail key
    724         // VK_LAUNCH_MEDIA_SELECT (B5) Windows 2000/XP: Select Media key
    725         // VK_LAUNCH_APP1 (B6) Windows 2000/XP: Start Application 1 key
    726         // VK_LAUNCH_APP2 (B7) Windows 2000/XP: Start Application 2 key
    727 
    728         // VK_OEM_1 (BA) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the ';:' key
    729         case ';': case ':': return 0xBA;
    730         // VK_OEM_PLUS (BB) Windows 2000/XP: For any country/region, the '+' key
    731         case '=': case '+': return 0xBB;
    732         // VK_OEM_COMMA (BC) Windows 2000/XP: For any country/region, the ',' key
    733         case ',': case '<': return 0xBC;
    734         // VK_OEM_MINUS (BD) Windows 2000/XP: For any country/region, the '-' key
    735         case '-': case '_': return 0xBD;
    736         // VK_OEM_PERIOD (BE) Windows 2000/XP: For any country/region, the '.' key
    737         case '.': case '>': return 0xBE;
    738         // VK_OEM_2 (BF) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '/?' key
    739         case '/': case '?': return 0xBF;
    740         // VK_OEM_3 (C0) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '`~' key
    741         case '`': case '~': return 0xC0;
    742         // VK_OEM_4 (DB) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '[{' key
    743         case '[': case '{': return 0xDB;
    744         // VK_OEM_5 (DC) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '\|' key
    745         case '\\': case '|': return 0xDC;
    746         // VK_OEM_6 (DD) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the ']}' key
    747         case ']': case '}': return 0xDD;
    748         // VK_OEM_7 (DE) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the 'single-quote/double-quote' key
    749         case '\'': case '"': return 0xDE;
    750 
    751         // VK_OEM_8 (DF) Used for miscellaneous characters; it can vary by keyboard.
    752         // VK_OEM_102 (E2) Windows 2000/XP: Either the angle bracket key or the backslash key on the RT 102-key keyboard
    753         // VK_PROCESSKEY (E5) Windows 95/98/Me, Windows NT 4.0, Windows 2000/XP: IME PROCESS key
    754         // VK_PACKET (E7) Windows 2000/XP: Used to pass Unicode characters as if they were keystrokes. The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT,SendInput, WM_KEYDOWN, and WM_KEYUP
    755         // VK_ATTN (F6) Attn key
    756         // VK_CRSEL (F7) CrSel key
    757         // VK_EXSEL (F8) ExSel key
    758         // VK_EREOF (F9) Erase EOF key
    759         // VK_PLAY (FA) Play key
    760         // VK_ZOOM (FB) Zoom key
    761         // VK_NONAME (FC) Reserved for future use
    762         // VK_PA1 (FD) PA1 key
    763         // VK_OEM_CLEAR (FE) Clear key
    764     }
    765 
    766     return 0;
    767 }
    768 
    76980static inline bool isKeyUpEvent(NSEvent *event)
    77081{
Note: See TracChangeset for help on using the changeset viewer.