OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 "chrome/browser/chromeos/input_method/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_KbdBrightnessUp: | |
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 default: { | |
91 // TODO: Properly support unicode characters. | |
92 char value[2]; | |
93 value[0] = keyval; | |
94 value[1] = '\0'; | |
95 return value; | |
96 } | |
97 } | |
98 } | |
99 | |
100 // We should send KeyCode as string to meet DOM Level 4 event specification | |
101 // proposal. https://dvcs.w3.org/hg/d4e/raw-file/tip/source_respec.htm | |
102 // The original spec is 1:1 mapping with USB keycode, but for the Extension IME, | |
103 // mapping with XKB keycode is sufficient, because it works only on Chrome OS. | |
104 // We have to have own mapping because We can't use WebKit component in | |
105 // Extension IME, | |
106 // TODO(nona): Use if the original spec is introduced. | |
107 std::string GetIBusKeyCode(uint16 keycode) { | |
108 switch (keycode) { | |
109 // Function keys | |
110 case 0x0009: return "Esc"; | |
111 case 0x0043: return "F1"; | |
112 case 0x0044: return "F2"; | |
113 case 0x0045: return "F3"; | |
114 case 0x0046: return "F4"; | |
115 case 0x0047: return "F5"; | |
116 case 0x0048: return "F6"; | |
117 case 0x0049: return "F7"; | |
118 case 0x004a: return "F8"; | |
119 case 0x004b: return "F9"; | |
120 case 0x004c: return "F10"; | |
121 case 0x005f: return "F11"; | |
122 case 0x0060: return "F12"; | |
123 | |
124 // Alphanumeric keys | |
125 case 0x000a: return "Digit1"; | |
126 case 0x000b: return "Digit2"; | |
127 case 0x000c: return "Digit3"; | |
128 case 0x000d: return "Digit4"; | |
129 case 0x000e: return "Digit5"; | |
130 case 0x000f: return "Digit6"; | |
131 case 0x0010: return "Digit7"; | |
132 case 0x0011: return "Digit8"; | |
133 case 0x0012: return "Digit9"; | |
134 case 0x0013: return "Digit0"; | |
135 case 0x0014: return "Minus"; | |
136 case 0x0015: return "Equal"; | |
137 case 0x0016: return "Backspace"; | |
138 case 0x0017: return "Tab"; | |
139 case 0x0018: return "KeyQ"; | |
140 case 0x0019: return "KeyW"; | |
141 case 0x001a: return "KeyE"; | |
142 case 0x001b: return "KeyR"; | |
143 case 0x001c: return "KeyT"; | |
144 case 0x001d: return "KeyY"; | |
145 case 0x001e: return "KeyU"; | |
146 case 0x001f: return "KeyI"; | |
147 case 0x0020: return "KeyO"; | |
148 case 0x0021: return "KeyP"; | |
149 case 0x0022: return "BracketLeft"; | |
150 case 0x0023: return "BlacketRight"; | |
151 case 0x0024: return "Enter"; | |
152 case 0x0025: return "ControlLeft"; | |
153 case 0x0026: return "KeyA"; | |
154 case 0x0027: return "KeyS"; | |
155 case 0x0028: return "KeyD"; | |
156 case 0x0029: return "KeyF"; | |
157 case 0x002a: return "KeyG"; | |
158 case 0x002b: return "KeyH"; | |
159 case 0x002c: return "KeyJ"; | |
160 case 0x002d: return "KeyK"; | |
161 case 0x002e: return "KeyL"; | |
162 case 0x002f: return "Semicolon"; | |
163 case 0x0030: return "Quote"; | |
164 case 0x0031: return "BackQuote"; | |
165 case 0x0032: return "ShiftLeft"; | |
166 case 0x0033: return "Backslash"; | |
167 case 0x0034: return "KeyZ"; | |
168 case 0x0035: return "KeyX"; | |
169 case 0x0036: return "KeyC"; | |
170 case 0x0037: return "KeyV"; | |
171 case 0x0038: return "KeyB"; | |
172 case 0x0039: return "KeyN"; | |
173 case 0x003a: return "KeyM"; | |
174 case 0x003b: return "Comma"; | |
175 case 0x003c: return "Period"; | |
176 case 0x003d: return "Slash"; | |
177 case 0x003e: return "ShiftRight"; | |
178 case 0x003f: return "NumpadMultiply"; | |
179 case 0x0040: return "AltLeft"; | |
180 case 0x0041: return "Space"; | |
181 case 0x0042: return "CapsLock"; | |
182 case 0x004d: return "NumLock"; | |
183 case 0x004e: return "ScrollLock"; | |
184 case 0x005e: return "IntlBackslash"; | |
185 case 0x0064: return "Convert"; | |
186 case 0x0065: return "KanaMode"; | |
187 case 0x0066: return "NoConvert"; | |
188 case 0x0069: return "ControlRight"; | |
189 case 0x006c: return "AltRight"; | |
190 case 0x0082: return "HangulMode"; | |
191 case 0x0083: return "Hanja"; | |
192 case 0x0085: return "OSLeft"; | |
193 case 0x0086: return "OSRight"; | |
194 case 0x0087: return "ContextMenu"; | |
195 case 0x0061: return "IntlRo"; | |
196 case 0x0084: return "IntlYen"; | |
197 | |
198 // Control pad keys | |
199 case 0x006b: return "PrintScreen"; | |
200 case 0x0070: return "PageUp"; | |
201 case 0x0073: return "End"; | |
202 case 0x0076: return "Insert"; | |
203 case 0x0077: return "Delete"; | |
204 case 0x006e: return "Home"; | |
205 case 0x0075: return "PageDown"; | |
206 case 0x0079: return "VolumeMute"; | |
207 case 0x007a: return "VolumeDown"; | |
208 case 0x007b: return "VolumeUp"; | |
209 case 0x007c: return "Power"; | |
210 case 0x007f: return "Pause"; | |
211 case 0x0092: return "Help"; | |
212 | |
213 // Arrow pad keys | |
214 case 0x006f: return "ArrowUp"; | |
215 case 0x0071: return "ArrowLeft"; | |
216 case 0x0072: return "ArrowRight"; | |
217 case 0x0074: return "ArrowDown"; | |
218 | |
219 // Numpad keys | |
220 case 0x005a: return "Numpad0"; | |
221 case 0x0057: return "Numpad1"; | |
222 case 0x0058: return "Numpad2"; | |
223 case 0x0059: return "Numpad3"; | |
224 case 0x0053: return "Numpad4"; | |
225 case 0x0054: return "Numpad5"; | |
226 case 0x0055: return "Numpad6"; | |
227 case 0x004f: return "Numpad7"; | |
228 case 0x0050: return "Numpad8"; | |
229 case 0x0051: return "Numpad9"; | |
230 case 0x0052: return "NumpadSubtract"; | |
231 case 0x0056: return "NumpadAdd"; | |
232 case 0x005b: return "NumpadDecimal"; | |
233 case 0x0068: return "NumpadEnter"; | |
234 case 0x006a: return "NumpadDivide"; | |
235 case 0x00bb: return "NumpadParentLeft"; | |
236 case 0x00bc: return "NumpadParentRight"; | |
237 | |
238 // Unsupported keys | |
239 | |
240 // No entry in specification. | |
241 case 0x0062: return ""; // UsbKeyCode: 0x070092(LANG3) | |
242 case 0x0063: return ""; // UsbKeyCode: 0x070093(LANG4) | |
243 case 0x007d: return ""; // UsbKeyCode: 0x070067(Num_=) | |
244 case 0x007e: return ""; // UsbkeyCode: 0x0700d7(Num_+-) | |
245 case 0x0081: return ""; // UsbKeyCode: 0x0700dc(NumpadDecimal) | |
246 case 0x0088: return ""; // UsbKeyCode: 0x07009b(Cancel) | |
247 case 0x0089: return ""; // UsbKeyCode: 0x070079(Again) | |
248 case 0x008b: return ""; // UsbKeyCode: 0x07007a(Undo) | |
249 case 0x008d: return ""; // UsbKeyCode: 0x07007c(Copy) | |
250 case 0x008f: return ""; // UsbKeyCode: 0x07007d(Paste) | |
251 case 0x0090: return ""; // UsbKeyCode: 0x07007e(Find) | |
252 case 0x0091: return ""; // UsbKeyCode: 0x07007b(Cut) | |
253 case 0x0093: return ""; // UsbKeyCode: 0x070076(Menu) | |
254 | |
255 // USB Usage Page 0x01: Generic Desktop Page | |
256 case 0x0094: return ""; // 0x0C page: AL_Calculator | |
257 case 0x0096: return ""; // 0x01 page: SystemSleep | |
258 case 0x0097: return ""; // 0x01 page: SystemWakeUp | |
259 | |
260 // USB Usage Page 0x0c: Consumer Page | |
261 case 0x0098: return ""; // AL_FileBrowser (Explorer)"; | |
262 case 0x00a4: return ""; // AC_Bookmarks (Favorites)"; | |
263 case 0x00a5: return ""; // AL_LocalMachineBrowser"; | |
264 case 0x00a6: return ""; // AC_Back"; | |
265 case 0x00a7: return ""; // AC_Forward"; | |
266 case 0x00b5: return ""; // AC_Refresh (Reload)"; | |
267 case 0x00ef: return ""; // AC_Send"; | |
268 case 0x00f0: return ""; // AC_Reply"; | |
269 case 0x00f1: return ""; // AC_ForwardMsg (MailForward)"; | |
270 case 0x00f3: return ""; // AL_Documents"; | |
271 | |
272 default: return ""; | |
273 } | |
274 } | |
275 | |
276 } // namespace input_method | |
277 } // namespace chromeos | |
OLD | NEW |