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/keyboard_codes.h" | 12 #include "ui/events/keycodes/keyboard_codes.h" |
12 | 13 |
13 namespace ui { | 14 namespace ui { |
14 | 15 |
15 enum class DomCode; | 16 enum class DomCode; |
16 enum class DomKey; | |
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 Windows key 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 // | 32 // |
33 // TODO(kpschoedel): replace remaining uses of the ...FromKeyCode() functions | 33 // TODO(kpschoedel): replace remaining uses of the ...FromKeyCode() functions |
34 // and remove them, to avoid future creation of underspecified key events. | 34 // and remove them, to avoid future creation of underspecified key events. |
35 // crbug.com/444045 | 35 // crbug.com/444045 |
36 EVENTS_BASE_EXPORT base::char16 GetCharacterFromKeyCode(KeyboardCode key_code, | 36 EVENTS_BASE_EXPORT base::char16 GetCharacterFromKeyCode(KeyboardCode key_code, |
37 int flags); | 37 int flags); |
38 EVENTS_BASE_EXPORT bool GetMeaningFromKeyCode(KeyboardCode key_code, | 38 EVENTS_BASE_EXPORT DomKey GetDomKeyFromKeyCode(KeyboardCode key_code, |
39 int flags, | 39 int flags); |
40 DomKey* dom_key, | |
41 base::char16* character); | |
42 | 40 |
43 // Helper function to map a physical key state (dom_code and flags) | 41 // Helper function to map a physical key state (dom_code and flags) |
44 // to a meaning (dom_key and character, together corresponding to the | 42 // to a meaning (dom_key and character, together corresponding to the |
45 // DOM keyboard event |key| value), along with a corresponding non-located | 43 // DOM keyboard event |key| value), along with a corresponding non-located |
46 // Windows-based key_code. | 44 // Windows-based key_code. |
47 // | 45 // |
48 // This follows a US keyboard layout, so it should only be used when there | 46 // This follows a US keyboard layout, so it should only be used when there |
49 // is no other better way to obtain the meaning (e.g. actual keyboard layout). | 47 // is no other better way to obtain the meaning (e.g. actual keyboard layout). |
50 // Returns true and sets the output parameters if the (dom_code, flags) pair | 48 // Returns true and sets the output parameters if the (dom_code, flags) pair |
51 // has an interpretation in the US English layout; otherwise the output | 49 // has an interpretation in the US English layout; otherwise the output |
52 // parameters are untouched. | 50 // parameters are untouched. |
53 EVENTS_BASE_EXPORT bool DomCodeToUsLayoutMeaning(DomCode dom_code, | 51 EVENTS_BASE_EXPORT bool DomCodeToUsLayoutDomKey(DomCode dom_code, |
54 int flags, | 52 int flags, |
55 DomKey* dom_key, | 53 DomKey* dom_key, |
56 base::char16* character, | 54 KeyboardCode* key_code) |
57 KeyboardCode* key_code) | |
58 WARN_UNUSED_RESULT; | 55 WARN_UNUSED_RESULT; |
59 | 56 |
60 // Obtains the control character corresponding to a physical key; | 57 // Obtains the control character corresponding to a physical key; |
61 // that is, the meaning of the physical key state (dom_code, and flags | 58 // that is, the meaning of the physical key state (dom_code, and flags |
62 // containing EF_CONTROL_DOWN) under the base US English layout. | 59 // containing EF_CONTROL_DOWN) under the base US English layout. |
63 // Returns true and sets the output parameters if the (dom_code, flags) pair | 60 // Returns true and sets the output parameters if the (dom_code, flags) pair |
64 // is interpreted as a control character; otherwise the output parameters | 61 // is interpreted as a control character; otherwise the output parameters |
65 // are untouched. | 62 // are untouched. |
66 EVENTS_BASE_EXPORT bool DomCodeToControlCharacter(DomCode dom_code, | 63 EVENTS_BASE_EXPORT bool DomCodeToControlCharacter(DomCode dom_code, |
67 int flags, | 64 int flags, |
68 DomKey* dom_key, | 65 DomKey* dom_key, |
69 base::char16* character, | |
70 KeyboardCode* key_code) | 66 KeyboardCode* key_code) |
71 WARN_UNUSED_RESULT; | 67 WARN_UNUSED_RESULT; |
72 | 68 |
73 // Returns the DomKey value associated with an ASCII/Unicode character. | |
74 // All printable characters and most other character codes use | |
75 // DomKey::CHARACTER, but a few ASCII C0 codes have their own DomKey. | |
76 EVENTS_BASE_EXPORT DomKey CharacterToDomKey(uint32 character); | |
77 | |
78 // Returns a Windows-based VKEY for a non-printable DOM Level 3 |key|. | 69 // Returns a Windows-based VKEY for a non-printable DOM Level 3 |key|. |
79 // The returned VKEY is non-located (e.g. VKEY_SHIFT). | 70 // The returned VKEY is non-located (e.g. VKEY_SHIFT). |
80 EVENTS_BASE_EXPORT KeyboardCode | 71 EVENTS_BASE_EXPORT KeyboardCode |
81 NonPrintableDomKeyToKeyboardCode(DomKey dom_key); | 72 NonPrintableDomKeyToKeyboardCode(DomKey dom_key); |
82 | 73 |
83 // Determine the non-located VKEY corresponding to a located VKEY. | 74 // Determine the non-located VKEY corresponding to a located VKEY. |
84 // Most modifier keys have two kinds of KeyboardCode: located (e.g. | 75 // Most modifier keys have two kinds of KeyboardCode: located (e.g. |
85 // VKEY_LSHIFT and VKEY_RSHIFT), that indentify one of two specific | 76 // VKEY_LSHIFT and VKEY_RSHIFT), that indentify one of two specific |
86 // physical keys, and non-located (e.g. VKEY_SHIFT) that identify | 77 // physical keys, and non-located (e.g. VKEY_SHIFT) that identify |
87 // only the operation. Similarly digit keys have a number-pad variant | 78 // only the operation. Similarly digit keys have a number-pad variant |
(...skipping 14 matching lines...) Expand all Loading... |
102 EVENTS_BASE_EXPORT DomCode UsLayoutKeyboardCodeToDomCode(KeyboardCode key_code); | 93 EVENTS_BASE_EXPORT DomCode UsLayoutKeyboardCodeToDomCode(KeyboardCode key_code); |
103 | 94 |
104 // Returns the Windows-based VKEY value corresponding to a DOM Level 3 |code|, | 95 // Returns the Windows-based VKEY value corresponding to a DOM Level 3 |code|, |
105 // assuming a base US English layout. The returned VKEY is located | 96 // assuming a base US English layout. The returned VKEY is located |
106 // (e.g. VKEY_LSHIFT). | 97 // (e.g. VKEY_LSHIFT). |
107 EVENTS_BASE_EXPORT KeyboardCode DomCodeToUsLayoutKeyboardCode(DomCode dom_code); | 98 EVENTS_BASE_EXPORT KeyboardCode DomCodeToUsLayoutKeyboardCode(DomCode dom_code); |
108 | 99 |
109 } // namespace ui | 100 } // namespace ui |
110 | 101 |
111 #endif // UI_EVENTS_KEYCODES_KEYBOARD_CODE_CONVERSION_H_ | 102 #endif // UI_EVENTS_KEYCODES_KEYBOARD_CODE_CONVERSION_H_ |
OLD | NEW |