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/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "ui/events/events_base_export.h" | 10 #include "ui/events/events_base_export.h" |
11 #include "ui/events/keycodes/dom/dom_key.h" | 11 #include "ui/events/keycodes/dom/dom_key.h" |
12 #include "ui/events/keycodes/keyboard_codes.h" | 12 #include "ui/events/keycodes/keyboard_codes.h" |
13 | 13 |
14 namespace ui { | 14 namespace ui { |
15 | 15 |
16 enum class DomCode; | 16 enum class DomCode; |
17 | 17 |
18 // Helper functions to get the meaning of a Windows key code in a | 18 // Helper functions to get the meaning of a DOM |code| in a |
19 // platform independent way. It supports control characters as well. | 19 // platform independent way. It supports control characters as well. |
20 // It assumes a US keyboard layout is used, so it may only be used when there | 20 // It assumes a US keyboard layout is used, so it may only be used when there |
21 // is no native event or no better way to get the character. | 21 // is no native event or no better way to get the character. |
22 // | 22 // |
23 // For example, if a virtual keyboard implementation can only generate key | 23 // For example, if a virtual keyboard implementation can only generate key |
24 // events with key_code and flags information, then there is no way for us to | 24 // events with key_code and flags information, then there is no way for us to |
25 // determine the actual character that should be generate by the key. Because | 25 // determine the actual character that should be generate by the key. Because |
26 // a key_code only represents a physical key on the keyboard, it has nothing | 26 // a key_code only represents a physical key on the keyboard, it has nothing |
27 // to do with the actual character printed on that key. In such case, the only | 27 // to do with the actual character printed on that key. In such case, the only |
28 // thing we can do is to assume that we are using a US keyboard and get the | 28 // thing we can do is to assume that we are using a US keyboard and get the |
29 // character according to US keyboard layout definition. Preferably, such | 29 // character according to US keyboard layout definition. Preferably, such |
30 // events should be created using a full KeyEvent constructor, explicitly | 30 // events should be created using a full KeyEvent constructor, explicitly |
31 // specifying the character and DOM 3 values as well as the legacy VKEY. | 31 // specifying the character and DOM 3 values as well as the legacy VKEY. |
32 // | |
33 // TODO(kpschoedel): replace remaining uses of the ...FromKeyCode() functions | |
34 // and remove them, to avoid future creation of underspecified key events. | |
35 // crbug.com/444045 | |
36 EVENTS_BASE_EXPORT base::char16 GetCharacterFromKeyCode(KeyboardCode key_code, | |
37 int flags); | |
38 EVENTS_BASE_EXPORT DomKey GetDomKeyFromKeyCode(KeyboardCode key_code, | |
39 int flags); | |
40 | 32 |
41 // Helper function to map a physical key state (dom_code and flags) | 33 // Helper function to map a physical key state (dom_code and flags) |
42 // to a meaning (dom_key and character, together corresponding to the | 34 // to a meaning (dom_key and character, together corresponding to the |
43 // DOM keyboard event |key| value), along with a corresponding non-located | 35 // DOM keyboard event |key| value), along with a corresponding non-located |
44 // Windows-based key_code. | 36 // Windows-based key_code. |
45 // | 37 // |
46 // This follows a US keyboard layout, so it should only be used when there | 38 // This follows a US keyboard layout, so it should only be used when there |
47 // is no other better way to obtain the meaning (e.g. actual keyboard layout). | 39 // is no other better way to obtain the meaning (e.g. actual keyboard layout). |
48 // Returns true and sets the output parameters if the (dom_code, flags) pair | 40 // Returns true and sets the output parameters if the (dom_code, flags) pair |
49 // has an interpretation in the US English layout; otherwise the output | 41 // has an interpretation in the US English layout; otherwise the output |
50 // parameters are untouched. | 42 // parameters are untouched. |
| 43 EVENTS_BASE_EXPORT base::char16 DomCodeToUsLayoutCharacter(DomCode dom_code, |
| 44 int flags); |
51 EVENTS_BASE_EXPORT bool DomCodeToUsLayoutDomKey(DomCode dom_code, | 45 EVENTS_BASE_EXPORT bool DomCodeToUsLayoutDomKey(DomCode dom_code, |
52 int flags, | 46 int flags, |
53 DomKey* dom_key, | 47 DomKey* dom_key, |
54 KeyboardCode* key_code) | 48 KeyboardCode* key_code) |
55 WARN_UNUSED_RESULT; | 49 WARN_UNUSED_RESULT; |
56 | 50 |
57 // Obtains the control character corresponding to a physical key; | 51 // Obtains the control character corresponding to a physical key; |
58 // that is, the meaning of the physical key state (dom_code, and flags | 52 // that is, the meaning of the physical key state (dom_code, and flags |
59 // containing EF_CONTROL_DOWN) under the base US English layout. | 53 // containing EF_CONTROL_DOWN) under the base US English layout. |
60 // Returns true and sets the output parameters if the (dom_code, flags) pair | 54 // Returns true and sets the output parameters if the (dom_code, flags) pair |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 EVENTS_BASE_EXPORT DomCode UsLayoutKeyboardCodeToDomCode(KeyboardCode key_code); | 87 EVENTS_BASE_EXPORT DomCode UsLayoutKeyboardCodeToDomCode(KeyboardCode key_code); |
94 | 88 |
95 // Returns the Windows-based VKEY value corresponding to a DOM Level 3 |code|, | 89 // Returns the Windows-based VKEY value corresponding to a DOM Level 3 |code|, |
96 // assuming a base US English layout. The returned VKEY is located | 90 // assuming a base US English layout. The returned VKEY is located |
97 // (e.g. VKEY_LSHIFT). | 91 // (e.g. VKEY_LSHIFT). |
98 EVENTS_BASE_EXPORT KeyboardCode DomCodeToUsLayoutKeyboardCode(DomCode dom_code); | 92 EVENTS_BASE_EXPORT KeyboardCode DomCodeToUsLayoutKeyboardCode(DomCode dom_code); |
99 | 93 |
100 } // namespace ui | 94 } // namespace ui |
101 | 95 |
102 #endif // UI_EVENTS_KEYCODES_KEYBOARD_CODE_CONVERSION_H_ | 96 #endif // UI_EVENTS_KEYCODES_KEYBOARD_CODE_CONVERSION_H_ |
OLD | NEW |