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 #ifndef UI_EVENTS_KEYCODES_KEYBOARD_CODE_CONVERSION_H_ | 5 #ifndef UI_EVENTS_KEYCODES_KEYBOARD_CODE_CONVERSION_H_ |
6 #define UI_EVENTS_KEYCODES_KEYBOARD_CODE_CONVERSION_H_ | 6 #define UI_EVENTS_KEYCODES_KEYBOARD_CODE_CONVERSION_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/strings/string16.h" |
9 #include "ui/events/events_base_export.h" | 9 #include "ui/events/events_base_export.h" |
10 #include "ui/events/keycodes/keyboard_codes.h" | 10 #include "ui/events/keycodes/keyboard_codes.h" |
11 | 11 |
12 namespace ui { | 12 namespace ui { |
13 | 13 |
14 // A helper function to get the character generated by a key event in a | 14 enum class DomKey; |
15 | |
16 // Helper functions to get the meaning of a Windows key code in a | |
15 // platform independent way. It supports control characters as well. | 17 // platform independent way. It supports control characters as well. |
16 // It assumes a US keyboard layout is used, so it may only be used when there | 18 // It assumes a US keyboard layout is used, so it may only be used when there |
17 // is no native event or no better way to get the character. | 19 // is no native event or no better way to get the character. |
18 // For example, if a virtual keyboard implementation can only generate key | 20 // For example, if a virtual keyboard implementation can only generate key |
19 // events with key_code and flags information, then there is no way for us to | 21 // events with key_code and flags information, then there is no way for us to |
20 // determine the actual character that should be generate by the key. Because | 22 // determine the actual character that should be generate by the key. Because |
21 // a key_code only represents a physical key on the keyboard, it has nothing | 23 // a key_code only represents a physical key on the keyboard, it has nothing |
22 // to do with the actual character printed on that key. In such case, the only | 24 // to do with the actual character printed on that key. In such case, the only |
23 // thing we can do is to assume that we are using a US keyboard and get the | 25 // thing we can do is to assume that we are using a US keyboard and get the |
24 // character according to US keyboard layout definition. | 26 // character according to US keyboard layout definition. |
25 // If a virtual keyboard implementation wants to support other keyboard | 27 // If a virtual keyboard implementation wants to support other keyboard |
26 // layouts, that may generate different text for a certain key than on a US | 28 // layouts, that may generate different text for a certain key than on a US |
27 // keyboard, a special native event object should be introduced to carry extra | 29 // keyboard, a special native event object should be introduced to carry extra |
28 // information to help determine the correct character. | 30 // information to help determine the correct character. |
29 // Take XKeyEvent as an example, it contains not only keycode and modifier | 31 // Take XKeyEvent as an example, it contains not only keycode and modifier |
30 // flags but also group and other extra XKB information to help determine the | 32 // flags but also group and other extra XKB information to help determine the |
31 // correct character. That's why we can use XLookupString() function to get | 33 // correct character. That's why we can use XLookupString() function to get |
32 // the correct text generated by a X key event (See how is GetCharacter() | 34 // the correct text generated by a X key event (See how is GetCharacter() |
33 // implemented in event_x.cc). | 35 // implemented in event_x.cc). |
34 EVENTS_BASE_EXPORT uint16 GetCharacterFromKeyCode(KeyboardCode key_code, | 36 EVENTS_BASE_EXPORT base::char16 GetCharacterFromKeyCode(KeyboardCode key_code, |
35 int flags); | 37 int flags); |
38 EVENTS_BASE_EXPORT bool GetMeaningFromKeyCode(KeyboardCode key_code, | |
39 int flags, | |
40 DomKey* dom_key, | |
41 base::char16* character); | |
Wez
2014/12/12 20:04:18
I think it'd be best to include "US" somewhere in
kpschoedel
2014/12/12 21:20:39
Good idea. I'll do that in a separate CL, since I
| |
36 | 42 |
37 } // namespace ui | 43 } // namespace ui |
38 | 44 |
39 #endif // UI_EVENTS_KEYCODES_KEYBOARD_CODE_CONVERSION_H_ | 45 #endif // UI_EVENTS_KEYCODES_KEYBOARD_CODE_CONVERSION_H_ |
OLD | NEW |