| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2006, 2007 Apple 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 | |
| 6 * are met: | |
| 7 * 1. Redistributions of source code must retain the above copyright | |
| 8 * notice, this list of conditions and the following disclaimer. | |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer in the | |
| 11 * documentation and/or other materials provided with the distribution. | |
| 12 * | |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 22 * (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. | |
| 24 */ | |
| 25 | |
| 26 #include "config.h" | |
| 27 #include "PlatformKeyboardEvent.h" | |
| 28 #include <windows.h> | |
| 29 | |
| 30 namespace WebCore { | |
| 31 | |
| 32 static const unsigned short HIGH_BIT_MASK_SHORT = 0x8000; | |
| 33 | |
| 34 // FIXME: This is incomplete. We could change this to mirror | |
| 35 // more like what Firefox does, and generate these switch statements | |
| 36 // at build time. | |
| 37 static String keyIdentifierForWindowsKeyCode(unsigned short keyCode) | |
| 38 { | |
| 39 switch (keyCode) { | |
| 40 case VK_MENU: | |
| 41 return "Alt"; | |
| 42 case VK_CONTROL: | |
| 43 return "Control"; | |
| 44 case VK_SHIFT: | |
| 45 return "Shift"; | |
| 46 case VK_CAPITAL: | |
| 47 return "CapsLock"; | |
| 48 case VK_LWIN: | |
| 49 case VK_RWIN: | |
| 50 return "Win"; | |
| 51 case VK_CLEAR: | |
| 52 return "Clear"; | |
| 53 case VK_DOWN: | |
| 54 return "Down"; | |
| 55 // "End" | |
| 56 case VK_END: | |
| 57 return "End"; | |
| 58 // "Enter" | |
| 59 case VK_RETURN: | |
| 60 return "Enter"; | |
| 61 case VK_EXECUTE: | |
| 62 return "Execute"; | |
| 63 case VK_F1: | |
| 64 return "F1"; | |
| 65 case VK_F2: | |
| 66 return "F2"; | |
| 67 case VK_F3: | |
| 68 return "F3"; | |
| 69 case VK_F4: | |
| 70 return "F4"; | |
| 71 case VK_F5: | |
| 72 return "F5"; | |
| 73 case VK_F6: | |
| 74 return "F6"; | |
| 75 case VK_F7: | |
| 76 return "F7"; | |
| 77 case VK_F8: | |
| 78 return "F8"; | |
| 79 case VK_F9: | |
| 80 return "F9"; | |
| 81 case VK_F10: | |
| 82 return "F11"; | |
| 83 case VK_F12: | |
| 84 return "F12"; | |
| 85 case VK_F13: | |
| 86 return "F13"; | |
| 87 case VK_F14: | |
| 88 return "F14"; | |
| 89 case VK_F15: | |
| 90 return "F15"; | |
| 91 case VK_F16: | |
| 92 return "F16"; | |
| 93 case VK_F17: | |
| 94 return "F17"; | |
| 95 case VK_F18: | |
| 96 return "F18"; | |
| 97 case VK_F19: | |
| 98 return "F19"; | |
| 99 case VK_F20: | |
| 100 return "F20"; | |
| 101 case VK_F21: | |
| 102 return "F21"; | |
| 103 case VK_F22: | |
| 104 return "F22"; | |
| 105 case VK_F23: | |
| 106 return "F23"; | |
| 107 case VK_F24: | |
| 108 return "F24"; | |
| 109 case VK_HELP: | |
| 110 return "Help"; | |
| 111 case VK_HOME: | |
| 112 return "Home"; | |
| 113 case VK_INSERT: | |
| 114 return "Insert"; | |
| 115 case VK_LEFT: | |
| 116 return "Left"; | |
| 117 case VK_NEXT: | |
| 118 return "PageDown"; | |
| 119 case VK_PRIOR: | |
| 120 return "PageUp"; | |
| 121 case VK_PAUSE: | |
| 122 return "Pause"; | |
| 123 case VK_SNAPSHOT: | |
| 124 return "PrintScreen"; | |
| 125 case VK_RIGHT: | |
| 126 return "Right"; | |
| 127 case VK_SCROLL: | |
| 128 return "Scroll"; | |
| 129 case VK_SELECT: | |
| 130 return "Select"; | |
| 131 case VK_UP: | |
| 132 return "Up"; | |
| 133 // Standard says that DEL becomes U+007F. | |
| 134 case VK_DELETE: | |
| 135 return "U+007F"; | |
| 136 default: | |
| 137 return String::format("U+%04X", toupper(keyCode)); | |
| 138 } | |
| 139 } | |
| 140 | |
| 141 static bool isKeypadEvent(WPARAM code, LPARAM keyData, PlatformKeyboardEvent::Ty
pe type) | |
| 142 { | |
| 143 if (type != PlatformKeyboardEvent::RawKeyDown && type != PlatformKeyboardEve
nt::KeyUp) | |
| 144 return false; | |
| 145 | |
| 146 switch (code) { | |
| 147 case VK_NUMLOCK: | |
| 148 case VK_NUMPAD0: | |
| 149 case VK_NUMPAD1: | |
| 150 case VK_NUMPAD2: | |
| 151 case VK_NUMPAD3: | |
| 152 case VK_NUMPAD4: | |
| 153 case VK_NUMPAD5: | |
| 154 case VK_NUMPAD6: | |
| 155 case VK_NUMPAD7: | |
| 156 case VK_NUMPAD8: | |
| 157 case VK_NUMPAD9: | |
| 158 case VK_MULTIPLY: | |
| 159 case VK_ADD: | |
| 160 case VK_SEPARATOR: | |
| 161 case VK_SUBTRACT: | |
| 162 case VK_DECIMAL: | |
| 163 case VK_DIVIDE: | |
| 164 return true; | |
| 165 case VK_RETURN: | |
| 166 return (keyData >> 16) & KF_EXTENDED; | |
| 167 case VK_INSERT: | |
| 168 case VK_DELETE: | |
| 169 case VK_PRIOR: | |
| 170 case VK_NEXT: | |
| 171 case VK_END: | |
| 172 case VK_HOME: | |
| 173 case VK_LEFT: | |
| 174 case VK_UP: | |
| 175 case VK_RIGHT: | |
| 176 case VK_DOWN: | |
| 177 return !((keyData >> 16) & KF_EXTENDED); | |
| 178 default: | |
| 179 return false; | |
| 180 } | |
| 181 } | |
| 182 | |
| 183 static inline String singleCharacterString(UChar c) { return String(&c, 1); } | |
| 184 | |
| 185 // When constructing a PlatformKeyboardEvent instance, WParam will be the | |
| 186 // keyCode, LParam will be characterData. | |
| 187 PlatformKeyboardEvent::PlatformKeyboardEvent(HWND, WPARAM code, LPARAM keyData,
Type type, bool systemKey) | |
| 188 : m_type(type) | |
| 189 , m_text((type == Char || type == KeyDown) ? singleCharacterString(code) : S
tring()) | |
| 190 , m_unmodifiedText((type == Char || type == KeyDown) ? singleCharacterString
(code) : String()) | |
| 191 , m_keyIdentifier((type == Char) ? String() : keyIdentifierForWindowsKeyCode
(code)) | |
| 192 , m_windowsVirtualKeyCode((type == RawKeyDown || type == KeyDown || type ==
KeyUp || type == Char) ? code : 0) | |
| 193 , m_isSystemKey(systemKey) | |
| 194 // All other members are initialized by glue/event_conversion.cc | |
| 195 { | |
| 196 } | |
| 197 | |
| 198 void PlatformKeyboardEvent::disambiguateKeyDownEvent(Type, bool) | |
| 199 { | |
| 200 // No KeyDown events on Windows to disambiguate. | |
| 201 ASSERT_NOT_REACHED(); | |
| 202 } | |
| 203 | |
| 204 bool PlatformKeyboardEvent::currentCapsLockState() | |
| 205 { | |
| 206 return GetKeyState(VK_CAPITAL) & 1; | |
| 207 } | |
| 208 | |
| 209 } | |
| OLD | NEW |