Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/base/keycodes/keyboard_code_conversion_x.h" | 5 #include "ui/base/keycodes/keyboard_code_conversion_x.h" |
| 6 | 6 |
| 7 #define XK_3270 // for XK_3270_BackTab | |
|
sadrul
2011/12/05 16:00:28
This ... looks weird. Why is this necessary? Is th
Yusuke Sato
2011/12/06 04:30:39
The Xlib reference manual says "This file declares
| |
| 7 #include <X11/keysym.h> | 8 #include <X11/keysym.h> |
| 8 #include <X11/Xlib.h> | 9 #include <X11/Xlib.h> |
| 9 #include <X11/Xutil.h> | 10 #include <X11/Xutil.h> |
| 10 | 11 |
| 11 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 13 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 14 | 15 |
| 15 namespace ui { | 16 namespace ui { |
| 16 | 17 |
| 17 // Get an ui::KeyboardCode from an X keyevent | 18 // Get an ui::KeyboardCode from an X keyevent |
| 18 KeyboardCode KeyboardCodeFromXKeyEvent(XEvent* xev) { | 19 KeyboardCode KeyboardCodeFromXKeyEvent(XEvent* xev) { |
| 19 // XLookupKeysym does not take into consideration the state of the lock/shift | 20 // XLookupKeysym does not take into consideration the state of the lock/shift |
| 20 // etc. keys. So it is necessary to use XLookupString instead. | 21 // etc. keys. So it is necessary to use XLookupString instead. |
| 21 KeySym keysym; | 22 KeySym keysym; |
| 22 XLookupString(&xev->xkey, NULL, 0, &keysym, NULL); | 23 XLookupString(&xev->xkey, NULL, 0, &keysym, NULL); |
| 23 KeyboardCode keycode = KeyboardCodeFromXKeysym(keysym); | 24 KeyboardCode keycode = KeyboardCodeFromXKeysym(keysym); |
| 24 if (keycode == VKEY_UNKNOWN) { | 25 if (keycode == VKEY_UNKNOWN) { |
| 25 keysym = DefaultXKeysymFromHardwareKeycode(xev->xkey.keycode); | 26 keysym = DefaultXKeysymFromHardwareKeycode(xev->xkey.keycode); |
| 26 keycode = KeyboardCodeFromXKeysym(keysym); | 27 keycode = KeyboardCodeFromXKeysym(keysym); |
| 27 } | 28 } |
| 28 | 29 |
| 29 return keycode; | 30 return keycode; |
| 30 } | 31 } |
| 31 | 32 |
| 32 KeyboardCode KeyboardCodeFromXKeysym(unsigned int keysym) { | 33 KeyboardCode KeyboardCodeFromXKeysym(unsigned int keysym) { |
| 33 // Consult GDK key translation (in WindowsKeyCodeForGdkKeyCode) for details | |
| 34 // about the following translations. | |
| 35 | |
| 36 // TODO(sad): Have |keysym| go through the X map list? | 34 // TODO(sad): Have |keysym| go through the X map list? |
| 37 | 35 |
| 38 switch (keysym) { | 36 switch (keysym) { |
| 39 case XK_BackSpace: | 37 case XK_BackSpace: |
| 40 return VKEY_BACK; | 38 return VKEY_BACK; |
| 41 case XK_Delete: | 39 case XK_Delete: |
| 42 case XK_KP_Delete: | 40 case XK_KP_Delete: |
| 43 return VKEY_DELETE; | 41 return VKEY_DELETE; |
| 44 case XK_Tab: | 42 case XK_Tab: |
| 45 case XK_KP_Tab: | 43 case XK_KP_Tab: |
| 44 case XK_ISO_Left_Tab: | |
| 45 case XK_3270_BackTab: | |
| 46 return VKEY_TAB; | 46 return VKEY_TAB; |
| 47 case XK_Linefeed: | 47 case XK_Linefeed: |
| 48 case XK_Return: | 48 case XK_Return: |
| 49 case XK_KP_Enter: | 49 case XK_KP_Enter: |
| 50 case XK_ISO_Enter: | |
| 50 return VKEY_RETURN; | 51 return VKEY_RETURN; |
| 51 case XK_Clear: | 52 case XK_Clear: |
| 52 return VKEY_CLEAR; | 53 return VKEY_CLEAR; |
| 53 case XK_KP_Space: | 54 case XK_KP_Space: |
| 54 case XK_space: | 55 case XK_space: |
| 55 return VKEY_SPACE; | 56 return VKEY_SPACE; |
| 56 case XK_Home: | 57 case XK_Home: |
| 57 case XK_KP_Home: | 58 case XK_KP_Home: |
| 58 return VKEY_HOME; | 59 return VKEY_HOME; |
| 59 case XK_End: | 60 case XK_End: |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 72 case XK_KP_Right: | 73 case XK_KP_Right: |
| 73 return VKEY_RIGHT; | 74 return VKEY_RIGHT; |
| 74 case XK_Down: | 75 case XK_Down: |
| 75 case XK_KP_Down: | 76 case XK_KP_Down: |
| 76 return VKEY_DOWN; | 77 return VKEY_DOWN; |
| 77 case XK_Up: | 78 case XK_Up: |
| 78 case XK_KP_Up: | 79 case XK_KP_Up: |
| 79 return VKEY_UP; | 80 return VKEY_UP; |
| 80 case XK_Escape: | 81 case XK_Escape: |
| 81 return VKEY_ESCAPE; | 82 return VKEY_ESCAPE; |
| 83 case XK_Kana_Lock: | |
| 84 case XK_Kana_Shift: | |
| 85 return VKEY_KANA; | |
| 86 case XK_Hangul: | |
| 87 return VKEY_HANGUL; | |
| 88 case XK_Hangul_Hanja: | |
| 89 return VKEY_HANJA; | |
| 90 case XK_Kanji: | |
| 91 return VKEY_KANJI; | |
| 82 case XK_A: | 92 case XK_A: |
| 83 case XK_a: | 93 case XK_a: |
| 84 return VKEY_A; | 94 return VKEY_A; |
| 85 case XK_B: | 95 case XK_B: |
| 86 case XK_b: | 96 case XK_b: |
| 87 return VKEY_B; | 97 return VKEY_B; |
| 88 case XK_C: | 98 case XK_C: |
| 89 case XK_c: | 99 case XK_c: |
| 90 return VKEY_C; | 100 return VKEY_C; |
| 91 case XK_D: | 101 case XK_D: |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 case XK_KP_2: | 185 case XK_KP_2: |
| 176 case XK_KP_3: | 186 case XK_KP_3: |
| 177 case XK_KP_4: | 187 case XK_KP_4: |
| 178 case XK_KP_5: | 188 case XK_KP_5: |
| 179 case XK_KP_6: | 189 case XK_KP_6: |
| 180 case XK_KP_7: | 190 case XK_KP_7: |
| 181 case XK_KP_8: | 191 case XK_KP_8: |
| 182 case XK_KP_9: | 192 case XK_KP_9: |
| 183 return static_cast<KeyboardCode>(VKEY_NUMPAD0 + (keysym - XK_KP_0)); | 193 return static_cast<KeyboardCode>(VKEY_NUMPAD0 + (keysym - XK_KP_0)); |
| 184 | 194 |
| 195 case XK_parenright: | |
| 196 return VKEY_0; | |
| 197 case XK_exclam: | |
| 198 return VKEY_1; | |
| 199 case XK_at: | |
| 200 return VKEY_2; | |
| 201 case XK_numbersign: | |
| 202 return VKEY_3; | |
| 203 case XK_dollar: | |
| 204 return VKEY_4; | |
| 205 case XK_percent: | |
| 206 return VKEY_5; | |
| 207 case XK_asciicircum: | |
| 208 return VKEY_6; | |
| 209 case XK_ampersand: | |
| 210 return VKEY_7; | |
| 211 case XK_asterisk: | |
| 212 return VKEY_8; | |
| 213 case XK_parenleft: | |
| 214 return VKEY_9; | |
| 215 | |
| 185 case XK_multiply: | 216 case XK_multiply: |
| 186 case XK_KP_Multiply: | 217 case XK_KP_Multiply: |
| 187 return VKEY_MULTIPLY; | 218 return VKEY_MULTIPLY; |
| 188 case XK_KP_Add: | 219 case XK_KP_Add: |
| 189 return VKEY_ADD; | 220 return VKEY_ADD; |
| 190 case XK_KP_Separator: | 221 case XK_KP_Separator: |
| 191 return VKEY_SEPARATOR; | 222 return VKEY_SEPARATOR; |
| 192 case XK_KP_Subtract: | 223 case XK_KP_Subtract: |
| 193 return VKEY_SUBTRACT; | 224 return VKEY_SUBTRACT; |
| 194 case XK_KP_Decimal: | 225 case XK_KP_Decimal: |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 593 case VKEY_F23: | 624 case VKEY_F23: |
| 594 case VKEY_F24: | 625 case VKEY_F24: |
| 595 return XK_F1 + (keycode - VKEY_F1); | 626 return XK_F1 + (keycode - VKEY_F1); |
| 596 | 627 |
| 597 default: | 628 default: |
| 598 return 0; | 629 return 0; |
| 599 } | 630 } |
| 600 } | 631 } |
| 601 | 632 |
| 602 } // namespace ui | 633 } // namespace ui |
| OLD | NEW |