1/* 2 * Copyright (C) 2009 Google Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above 11 * copyright notice, this list of conditions and the following disclaimer 12 * in the documentation and/or other materials provided with the 13 * distribution. 14 * * Neither the name of Google Inc. nor the names of its 15 * contributors may be used to endorse or promote products derived from 16 * this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31#include "config.h" 32#include "WebInputEvent.h" 33 34#include "KeyboardCodes.h" 35 36#include <ctype.h> 37#include <stdio.h> 38 39#include <wtf/Assertions.h> 40#include <wtf/StringExtras.h> 41 42using namespace WebCore; 43 44namespace WebKit { 45 46static const char* staticKeyIdentifiers(unsigned short keyCode) 47{ 48 switch (keyCode) { 49 case VKEY_MENU: 50 return "Alt"; 51 case VKEY_CONTROL: 52 return "Control"; 53 case VKEY_SHIFT: 54 return "Shift"; 55 case VKEY_CAPITAL: 56 return "CapsLock"; 57 case VKEY_LWIN: 58 case VKEY_RWIN: 59 return "Win"; 60 case VKEY_CLEAR: 61 return "Clear"; 62 case VKEY_DOWN: 63 return "Down"; 64 case VKEY_END: 65 return "End"; 66 case VKEY_RETURN: 67 return "Enter"; 68 case VKEY_EXECUTE: 69 return "Execute"; 70 case VKEY_F1: 71 return "F1"; 72 case VKEY_F2: 73 return "F2"; 74 case VKEY_F3: 75 return "F3"; 76 case VKEY_F4: 77 return "F4"; 78 case VKEY_F5: 79 return "F5"; 80 case VKEY_F6: 81 return "F6"; 82 case VKEY_F7: 83 return "F7"; 84 case VKEY_F8: 85 return "F8"; 86 case VKEY_F9: 87 return "F9"; 88 case VKEY_F10: 89 return "F10"; 90 case VKEY_F11: 91 return "F11"; 92 case VKEY_F12: 93 return "F12"; 94 case VKEY_F13: 95 return "F13"; 96 case VKEY_F14: 97 return "F14"; 98 case VKEY_F15: 99 return "F15"; 100 case VKEY_F16: 101 return "F16"; 102 case VKEY_F17: 103 return "F17"; 104 case VKEY_F18: 105 return "F18"; 106 case VKEY_F19: 107 return "F19"; 108 case VKEY_F20: 109 return "F20"; 110 case VKEY_F21: 111 return "F21"; 112 case VKEY_F22: 113 return "F22"; 114 case VKEY_F23: 115 return "F23"; 116 case VKEY_F24: 117 return "F24"; 118 case VKEY_HELP: 119 return "Help"; 120 case VKEY_HOME: 121 return "Home"; 122 case VKEY_INSERT: 123 return "Insert"; 124 case VKEY_LEFT: 125 return "Left"; 126 case VKEY_NEXT: 127 return "PageDown"; 128 case VKEY_PRIOR: 129 return "PageUp"; 130 case VKEY_PAUSE: 131 return "Pause"; 132 case VKEY_SNAPSHOT: 133 return "PrintScreen"; 134 case VKEY_RIGHT: 135 return "Right"; 136 case VKEY_SCROLL: 137 return "Scroll"; 138 case VKEY_SELECT: 139 return "Select"; 140 case VKEY_UP: 141 return "Up"; 142 case VKEY_DELETE: 143 return "U+007F"; // Standard says that DEL becomes U+007F. 144 default: 145 return 0; 146 } 147} 148 149void WebKeyboardEvent::setKeyIdentifierFromWindowsKeyCode() 150{ 151 const char* id = staticKeyIdentifiers(windowsKeyCode); 152 if (id) { 153 strncpy(keyIdentifier, id, sizeof(keyIdentifier) - 1); 154 keyIdentifier[sizeof(keyIdentifier) - 1] = '\0'; 155 } else 156 snprintf(keyIdentifier, sizeof(keyIdentifier), "U+%04X", toupper(windowsKeyCode)); 157} 158 159} // namespace WebKit 160