1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "chromeos/ime/ibus_keymap.h" 6 7 #define XK_MISCELLANY 8 #include <X11/keysymdef.h> 9 #include <X11/XF86keysym.h> 10 11 namespace chromeos { 12 namespace input_method { 13 14 std::string GetIBusKey(int keyval) { 15 // TODO: Ensure all keys are supported. 16 switch (keyval) { 17 case XK_Escape: 18 return "Esc"; 19 case XK_F1: 20 case XF86XK_Back: 21 return "HistoryBack"; 22 case XK_F2: 23 case XF86XK_Forward: 24 return "HistoryForward"; 25 case XK_F3: 26 case XF86XK_Reload: 27 return "BrowserRefresh"; 28 case XK_F4: 29 case XF86XK_LaunchB: 30 return "ChromeOSFullscreen"; // TODO: Check this value 31 case XK_F5: 32 case XF86XK_LaunchA: 33 return "ChromeOSSwitchWindow"; // TODO: Check this value 34 case XK_F6: 35 case XF86XK_MonBrightnessDown: 36 return "BrightnessDown"; 37 case XK_F7: 38 case XF86XK_MonBrightnessUp: 39 return "BrightnessUp"; 40 case XK_F8: 41 case XF86XK_AudioMute: 42 return "AudioVolumeMute"; 43 case XK_F9: 44 case XF86XK_AudioLowerVolume: 45 return "AudioVolumeDown"; 46 case XK_F10: 47 case XF86XK_AudioRaiseVolume: 48 return "AudioVolumeUp"; 49 case XK_BackSpace: 50 return "Backspace"; 51 case XK_Delete: 52 case XK_KP_Delete: 53 return "Delete"; 54 case XK_Tab: 55 return "Tab"; 56 case XK_KP_Enter: 57 case XK_Return: 58 return "Enter"; 59 case XK_Meta_L: 60 return "BrowserSearch"; 61 case XK_Up: 62 case XK_KP_Up: 63 return "Up"; 64 case XK_Down: 65 case XK_KP_Down: 66 return "Down"; 67 case XK_Left: 68 case XK_KP_Left: 69 return "Left"; 70 case XK_Right: 71 case XK_KP_Right: 72 return "Right"; 73 case XK_Page_Up: 74 return "PageUp"; 75 case XK_Page_Down: 76 return "PageDown"; 77 case XK_Home: 78 return "Home"; 79 case XK_End: 80 return "End"; 81 case XK_Shift_L: 82 case XK_Shift_R: 83 return "Shift"; 84 case XK_Alt_L: 85 case XK_Alt_R: 86 return "Alt"; 87 case XK_Control_L: 88 case XK_Control_R: 89 return "Ctrl"; 90 case XK_Caps_Lock: 91 return "CapsLock"; 92 default: { 93 // TODO: Properly support unicode characters. 94 char value[2]; 95 value[0] = keyval; 96 value[1] = '\0'; 97 return value; 98 } 99 } 100 } 101 102 // We should send KeyCode as string to meet DOM Level 4 event specification 103 // proposal. https://dvcs.w3.org/hg/d4e/raw-file/tip/source_respec.htm 104 // The original spec is 1:1 mapping with USB keycode, but for the Extension IME, 105 // mapping with XKB keycode is sufficient, because it works only on Chrome OS. 106 // We have to have own mapping because We can't use WebKit component in 107 // Extension IME, 108 // TODO(nona): Use if the original spec is introduced. 109 std::string GetIBusKeyCode(uint16 keycode) { 110 switch (keycode) { 111 // Function keys 112 case 0x0009: return "Esc"; 113 case 0x0043: return "F1"; 114 case 0x0044: return "F2"; 115 case 0x0045: return "F3"; 116 case 0x0046: return "F4"; 117 case 0x0047: return "F5"; 118 case 0x0048: return "F6"; 119 case 0x0049: return "F7"; 120 case 0x004a: return "F8"; 121 case 0x004b: return "F9"; 122 case 0x004c: return "F10"; 123 case 0x005f: return "F11"; 124 case 0x0060: return "F12"; 125 126 // Alphanumeric keys 127 case 0x000a: return "Digit1"; 128 case 0x000b: return "Digit2"; 129 case 0x000c: return "Digit3"; 130 case 0x000d: return "Digit4"; 131 case 0x000e: return "Digit5"; 132 case 0x000f: return "Digit6"; 133 case 0x0010: return "Digit7"; 134 case 0x0011: return "Digit8"; 135 case 0x0012: return "Digit9"; 136 case 0x0013: return "Digit0"; 137 case 0x0014: return "Minus"; 138 case 0x0015: return "Equal"; 139 case 0x0016: return "Backspace"; 140 case 0x0017: return "Tab"; 141 case 0x0018: return "KeyQ"; 142 case 0x0019: return "KeyW"; 143 case 0x001a: return "KeyE"; 144 case 0x001b: return "KeyR"; 145 case 0x001c: return "KeyT"; 146 case 0x001d: return "KeyY"; 147 case 0x001e: return "KeyU"; 148 case 0x001f: return "KeyI"; 149 case 0x0020: return "KeyO"; 150 case 0x0021: return "KeyP"; 151 case 0x0022: return "BracketLeft"; 152 case 0x0023: return "BracketRight"; 153 case 0x0024: return "Enter"; 154 case 0x0025: return "ControlLeft"; 155 case 0x0026: return "KeyA"; 156 case 0x0027: return "KeyS"; 157 case 0x0028: return "KeyD"; 158 case 0x0029: return "KeyF"; 159 case 0x002a: return "KeyG"; 160 case 0x002b: return "KeyH"; 161 case 0x002c: return "KeyJ"; 162 case 0x002d: return "KeyK"; 163 case 0x002e: return "KeyL"; 164 case 0x002f: return "Semicolon"; 165 case 0x0030: return "Quote"; 166 case 0x0031: return "BackQuote"; 167 case 0x0032: return "ShiftLeft"; 168 case 0x0033: return "Backslash"; 169 case 0x0034: return "KeyZ"; 170 case 0x0035: return "KeyX"; 171 case 0x0036: return "KeyC"; 172 case 0x0037: return "KeyV"; 173 case 0x0038: return "KeyB"; 174 case 0x0039: return "KeyN"; 175 case 0x003a: return "KeyM"; 176 case 0x003b: return "Comma"; 177 case 0x003c: return "Period"; 178 case 0x003d: return "Slash"; 179 case 0x003e: return "ShiftRight"; 180 case 0x003f: return "NumpadMultiply"; 181 case 0x0040: return "AltLeft"; 182 case 0x0041: return "Space"; 183 case 0x0042: return "CapsLock"; 184 case 0x004d: return "NumLock"; 185 case 0x004e: return "ScrollLock"; 186 case 0x005e: return "IntlBackslash"; 187 case 0x0064: return "Convert"; 188 case 0x0065: return "KanaMode"; 189 case 0x0066: return "NoConvert"; 190 case 0x0069: return "ControlRight"; 191 case 0x006c: return "AltRight"; 192 case 0x0082: return "HangulMode"; 193 case 0x0083: return "Hanja"; 194 case 0x0085: return "OSLeft"; 195 case 0x0086: return "OSRight"; 196 case 0x0087: return "ContextMenu"; 197 case 0x0061: return "IntlRo"; 198 case 0x0084: return "IntlYen"; 199 200 // Control pad keys 201 case 0x006b: return "PrintScreen"; 202 case 0x0070: return "PageUp"; 203 case 0x0073: return "End"; 204 case 0x0076: return "Insert"; 205 case 0x0077: return "Delete"; 206 case 0x006e: return "Home"; 207 case 0x0075: return "PageDown"; 208 case 0x0079: return "VolumeMute"; 209 case 0x007a: return "VolumeDown"; 210 case 0x007b: return "VolumeUp"; 211 case 0x007c: return "Power"; 212 case 0x007f: return "Pause"; 213 case 0x0092: return "Help"; 214 215 // Arrow pad keys 216 case 0x006f: return "ArrowUp"; 217 case 0x0071: return "ArrowLeft"; 218 case 0x0072: return "ArrowRight"; 219 case 0x0074: return "ArrowDown"; 220 221 // Numpad keys 222 case 0x005a: return "Numpad0"; 223 case 0x0057: return "Numpad1"; 224 case 0x0058: return "Numpad2"; 225 case 0x0059: return "Numpad3"; 226 case 0x0053: return "Numpad4"; 227 case 0x0054: return "Numpad5"; 228 case 0x0055: return "Numpad6"; 229 case 0x004f: return "Numpad7"; 230 case 0x0050: return "Numpad8"; 231 case 0x0051: return "Numpad9"; 232 case 0x0052: return "NumpadSubtract"; 233 case 0x0056: return "NumpadAdd"; 234 case 0x005b: return "NumpadDecimal"; 235 case 0x0068: return "NumpadEnter"; 236 case 0x006a: return "NumpadDivide"; 237 case 0x00bb: return "NumpadParenLeft"; 238 case 0x00bc: return "NumpadParenRight"; 239 240 // Unsupported keys 241 242 // No entry in specification. 243 case 0x0062: return ""; // UsbKeyCode: 0x070092(LANG3) 244 case 0x0063: return ""; // UsbKeyCode: 0x070093(LANG4) 245 case 0x007d: return ""; // UsbKeyCode: 0x070067(Num_=) 246 case 0x007e: return ""; // UsbkeyCode: 0x0700d7(Num_+-) 247 case 0x0081: return ""; // UsbKeyCode: 0x0700dc(NumpadDecimal) 248 case 0x0088: return ""; // UsbKeyCode: 0x07009b(Cancel) 249 case 0x0089: return ""; // UsbKeyCode: 0x070079(Again) 250 case 0x008b: return ""; // UsbKeyCode: 0x07007a(Undo) 251 case 0x008d: return ""; // UsbKeyCode: 0x07007c(Copy) 252 case 0x008f: return ""; // UsbKeyCode: 0x07007d(Paste) 253 case 0x0090: return ""; // UsbKeyCode: 0x07007e(Find) 254 case 0x0091: return ""; // UsbKeyCode: 0x07007b(Cut) 255 case 0x0093: return ""; // UsbKeyCode: 0x070076(Menu) 256 257 // USB Usage Page 0x01: Generic Desktop Page 258 case 0x0094: return ""; // 0x0C page: AL_Calculator 259 case 0x0096: return ""; // 0x01 page: SystemSleep 260 case 0x0097: return ""; // 0x01 page: SystemWakeUp 261 262 // USB Usage Page 0x0c: Consumer Page 263 case 0x0098: return ""; // AL_FileBrowser (Explorer)"; 264 case 0x00a4: return ""; // AC_Bookmarks (Favorites)"; 265 case 0x00a5: return ""; // AL_LocalMachineBrowser"; 266 case 0x00a6: return ""; // AC_Back"; 267 case 0x00a7: return ""; // AC_Forward"; 268 case 0x00b5: return ""; // AC_Refresh (Reload)"; 269 case 0x00ef: return ""; // AC_Send"; 270 case 0x00f0: return ""; // AC_Reply"; 271 case 0x00f1: return ""; // AC_ForwardMsg (MailForward)"; 272 case 0x00f3: return ""; // AL_Documents"; 273 274 default: return ""; 275 } 276 } 277 278 } // namespace input_method 279 } // namespace chromeos 280