Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: ui/events/keycodes/keyboard_code_conversion.h

Issue 841263005: Use DOM- rather than Windows-based key code for non-layout cases. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/strings/string16.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 enum class DomCode; 14 enum class DomCode;
15 enum class DomKey; 15 enum class DomKey;
16 16
17 // Helper functions to get the meaning of a Windows key code in a 17 // Helper functions to get the meaning of a Windows key code in a
18 // platform independent way. It supports control characters as well. 18 // platform independent way. It supports control characters as well.
19 // It assumes a US keyboard layout is used, so it may only be used when there 19 // It assumes a US keyboard layout is used, so it may only be used when there
20 // is no native event or no better way to get the character. 20 // is no native event or no better way to get the character.
21 //
21 // For example, if a virtual keyboard implementation can only generate key 22 // For example, if a virtual keyboard implementation can only generate key
22 // events with key_code and flags information, then there is no way for us to 23 // events with key_code and flags information, then there is no way for us to
23 // determine the actual character that should be generate by the key. Because 24 // determine the actual character that should be generate by the key. Because
24 // a key_code only represents a physical key on the keyboard, it has nothing 25 // a key_code only represents a physical key on the keyboard, it has nothing
25 // to do with the actual character printed on that key. In such case, the only 26 // to do with the actual character printed on that key. In such case, the only
26 // thing we can do is to assume that we are using a US keyboard and get the 27 // thing we can do is to assume that we are using a US keyboard and get the
27 // character according to US keyboard layout definition. 28 // character according to US keyboard layout definition. Preferably, such
28 // If a virtual keyboard implementation wants to support other keyboard 29 // events should be created using a full KeyEvent constructor, explicitly
29 // layouts, that may generate different text for a certain key than on a US 30 // specifying the character and DOM 3 values as well as the legacy VKEY.
30 // keyboard, a special native event object should be introduced to carry extra 31 //
31 // information to help determine the correct character. 32 // TODO(kpschoedel): replace remaining uses of the ...FromKeyCode() functions
32 // Take XKeyEvent as an example, it contains not only keycode and modifier 33 // and remove them, to avoid future creation of underspecified key events.
33 // flags but also group and other extra XKB information to help determine the 34 // crbug.com/444045
34 // correct character. That's why we can use XLookupString() function to get
35 // the correct text generated by a X key event (See how is GetCharacter()
36 // implemented in event_x.cc).
37 EVENTS_BASE_EXPORT base::char16 GetCharacterFromKeyCode(KeyboardCode key_code, 35 EVENTS_BASE_EXPORT base::char16 GetCharacterFromKeyCode(KeyboardCode key_code,
38 int flags); 36 int flags);
39 EVENTS_BASE_EXPORT bool GetMeaningFromKeyCode(KeyboardCode key_code, 37 EVENTS_BASE_EXPORT bool GetMeaningFromKeyCode(KeyboardCode key_code,
40 int flags, 38 int flags,
41 DomKey* dom_key, 39 DomKey* dom_key,
42 base::char16* character); 40 base::char16* character);
43 41
42 // Helper function to map a physical key state (dom_code and flags)
43 // to a meaning (dom_key and character, together corresponding to the
44 // DOM keyboard event |key| value), along with a corresponding Windows-based
45 // key_code.
46 //
47 // This follows a US keyboard layout, so it should only be used when there
48 // is other better way to obtain the meaning (e.g. actual keyboard layout).
Wez 2015/02/19 23:16:08 Do you mean where there *isn't* a better way? Sug
kpschoedel 2015/04/10 18:32:34 Done.
49 EVENTS_BASE_EXPORT bool DomCodeToMeaning(DomCode dom_code,
50 int flags,
51 DomKey* dom_key,
52 base::char16* character,
53 KeyboardCode* key_code);
54
55 // Obtains the control character corresponding to a physical key;
56 // that is, the meaning of the physical key state (dom_code, and flags
57 // containing EF_CONTROL_DOWN) under a specific US ASCII layout.
Wez 2015/02/19 23:16:08 You mean under _the_ US English layout?
kpschoedel 2015/04/10 18:32:34 Done.
58 // Returns true and sets the output parameters if the (dom_code, flags) pair
59 // is interpreted as a control character; otherwise the output parameters
60 // are untouched.
61 EVENTS_BASE_EXPORT bool DomCodeToControlCharacter(
62 DomCode dom_code,
63 int flags,
64 DomKey* dom_key,
65 base::char16* character,
66 KeyboardCode* key_code);
67
68 // Returns a Windows-based VKEY for a non-printable DOM Level 3 |key|.
69 // The returned VKEY is non-located (e.g. VKEY_SHIFT).
70 EVENTS_BASE_EXPORT KeyboardCode
71 NonPrintableDomKeyToKeyboardCode(DomKey dom_key);
72
73 // Returns the Windows-based VKEY value corresponding to a DOM Level 3 |code|.
74 // The returned VKEY is located (e.g. VKEY_LSHIFT) and considered as a
75 // layout-independent physical key (e.g. DomCode::KEY_Q -> VKEY_Q). This
Wez 2015/02/19 23:16:08 Rather than layout independent, you're really sayi
kpschoedel 2015/04/10 18:32:34 The intent was that the VKEY here is used purely t
76 // should only be used as a last resort when other means of determining a
77 // suitable VKEY fail.
78 EVENTS_BASE_EXPORT KeyboardCode DomCodeToKeyboardCode(DomCode dom_code);
79
44 // Determine the non-located VKEY corresponding to a located VKEY. 80 // Determine the non-located VKEY corresponding to a located VKEY.
45 // Most modifier keys have two kinds of KeyboardCode: located (e.g. 81 // Most modifier keys have two kinds of KeyboardCode: located (e.g.
46 // VKEY_LSHIFT and VKEY_RSHIFT), that indentify one of two specific 82 // VKEY_LSHIFT and VKEY_RSHIFT), that indentify one of two specific
47 // physical keys, and non-located (e.g. VKEY_SHIFT) that identify 83 // physical keys, and non-located (e.g. VKEY_SHIFT) that identify
48 // only the operation. 84 // only the operation.
49 EVENTS_BASE_EXPORT KeyboardCode 85 EVENTS_BASE_EXPORT KeyboardCode
50 LocatedToNonLocatedKeyboardCode(KeyboardCode key_code); 86 LocatedToNonLocatedKeyboardCode(KeyboardCode key_code);
51 87
52 // Determine the located VKEY corresponding to a non-located VKEY. 88 // Determine the located VKEY corresponding to a non-located VKEY.
53 EVENTS_BASE_EXPORT KeyboardCode 89 EVENTS_BASE_EXPORT KeyboardCode
54 NonLocatedToLocatedKeyboardCode(KeyboardCode key_code, DomCode dom_code); 90 NonLocatedToLocatedKeyboardCode(KeyboardCode key_code, DomCode dom_code);
55 91
92 // Returns a DOM Level 3 |code| from a Windows-based VKEY value.
93 // This assumes a US layout and should only be used when |code| cannot be
94 // determined from a physical scan code, for example when a key event was
95 // generated synthetically by JavaScript with only a VKEY value supplied.
96 EVENTS_BASE_EXPORT DomCode KeyboardCodeToDomCode(KeyboardCode key_code);
97
56 } // namespace ui 98 } // namespace ui
57 99
58 #endif // UI_EVENTS_KEYCODES_KEYBOARD_CODE_CONVERSION_H_ 100 #endif // UI_EVENTS_KEYCODES_KEYBOARD_CODE_CONVERSION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698