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

Side by Side Diff: ui/events/keycodes/dom4/keycode_converter.h

Issue 641753003: DOM Level 3 .code and .key value enumerations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add code for unicode keys Created 6 years, 1 month 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_DOM4_KEYCODE_CONVERTER_H_ 5 #ifndef UI_EVENTS_KEYCODES_DOM4_KEYCODE_CONVERTER_H_
6 #define UI_EVENTS_KEYCODES_DOM4_KEYCODE_CONVERTER_H_ 6 #define UI_EVENTS_KEYCODES_DOM4_KEYCODE_CONVERTER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 10
11 // For reference, the W3C UI Event spec is located at: 11 // For reference, the W3C UI Event spec is located at:
12 // http://www.w3.org/TR/uievents/ 12 // http://www.w3.org/TR/uievents/
13 13
14 namespace ui { 14 namespace ui {
15 15
16 enum class DomCode;
17 enum class DomKey;
18
16 // This structure is used to define the keycode mapping table. 19 // This structure is used to define the keycode mapping table.
17 // It is defined here because the unittests need access to it. 20 // It is defined here because the unittests need access to it.
18 typedef struct { 21 typedef struct {
19 // USB keycode: 22 // USB keycode:
20 // Upper 16-bits: USB Usage Page. 23 // Upper 16-bits: USB Usage Page.
21 // Lower 16-bits: USB Usage Id: Assigned ID within this usage page. 24 // Lower 16-bits: USB Usage Id: Assigned ID within this usage page.
22 uint32_t usb_keycode; 25 uint32_t usb_keycode;
23 26
24 // Contains one of the following: 27 // Contains one of the following:
25 // On Linux: XKB scancode 28 // On Linux: XKB scancode
26 // On Windows: Windows OEM scancode 29 // On Windows: Windows OEM scancode
27 // On Mac: Mac keycode 30 // On Mac: Mac keycode
28 uint16_t native_keycode; 31 uint16_t native_keycode;
29 32
30 // The UIEvents (aka: DOM4Events) |code| value as defined in: 33 // The UIEvents (aka: DOM4Events) |code| value as defined in:
31 // https://dvcs.w3.org/hg/d4e/raw-file/tip/source_respec.htm 34 // http://www.w3.org/TR/DOM-Level-3-Events-code/
32 const char* code; 35 const char* code;
33 } KeycodeMapEntry; 36 } KeycodeMapEntry;
34 37
35 // A class to convert between the current platform's native keycode (scancode) 38 // A class to convert between the current platform's native keycode (scancode)
36 // and platform-neutral |code| values (as defined in the W3C UI Events 39 // and platform-neutral |code| values (as defined in the W3C UI Events
37 // spec (http://www.w3.org/TR/uievents/). 40 // spec (http://www.w3.org/TR/uievents/).
38 class KeycodeConverter { 41 class KeycodeConverter {
39 public: 42 public:
40 // Return the value that identifies an invalid native keycode. 43 // Return the value that identifies an invalid native keycode.
41 static uint16_t InvalidNativeKeycode(); 44 static uint16_t InvalidNativeKeycode();
42 45
43 // Return the string that indentifies an invalid UI Event |code|. 46 // Return the string that indentifies an invalid UI Event |code|.
44 // The returned pointer references a static global string. 47 // The returned pointer references a static global string.
45 static const char* InvalidKeyboardEventCode(); 48 static const char* InvalidKeyboardEventCode();
46 49
47 // Convert a native (Mac/Win/Linux) keycode into the |code| string. 50 // Convert a native (Mac/Win/Linux) keycode into the |code| string.
48 // The returned pointer references a static global string. 51 // The returned pointer references a static global string.
49 static const char* NativeKeycodeToCode(uint16_t native_keycode); 52 static const char* NativeKeycodeToCode(uint16_t native_keycode);
50 53
54 // Convert a native (Mac/Win/Linux) keycode into a DomCode.
55 static DomCode NativeKeycodeToDomCode(uint16_t native_keycode);
56
51 // Convert a UI Events |code| string value into a native keycode. 57 // Convert a UI Events |code| string value into a native keycode.
52 static uint16_t CodeToNativeKeycode(const char* code); 58 static uint16_t CodeToNativeKeycode(const char* code);
53 59
60 // Convert a DomCode into a native keycode.
61 static uint16_t DomCodeToNativeKeycode(DomCode code);
62
63 // Convert a UI Events |code| string value into a DomCode.
64 static DomCode CodeStringToDomCode(const char* code);
65
66 // Convert a DomCode into a UI Events |code| string value.
67 static const char* DomCodeToCodeString(DomCode dom_code);
68
69 // Convert a UI Events |key| string value into a DomKey.
70 static DomKey KeyStringToDomKey(const char* key);
71
72 // Convert a DomKey into a UI Events |key| string value.
73 static const char* DomKeyToKeyString(DomKey dom_key);
74
54 // The following methods relate to USB keycodes. 75 // The following methods relate to USB keycodes.
55 // Note that USB keycodes are not part of any web standard. 76 // Note that USB keycodes are not part of any web standard.
56 // Please don't use USB keycodes in new code. 77 // Please don't use USB keycodes in new code.
57 78
58 // Return the value that identifies an invalid USB keycode. 79 // Return the value that identifies an invalid USB keycode.
59 static uint16_t InvalidUsbKeycode(); 80 static uint16_t InvalidUsbKeycode();
60 81
61 // Convert a USB keycode into an equivalent platform native keycode. 82 // Convert a USB keycode into an equivalent platform native keycode.
62 static uint16_t UsbKeycodeToNativeKeycode(uint32_t usb_keycode); 83 static uint16_t UsbKeycodeToNativeKeycode(uint32_t usb_keycode);
63 84
64 // Convert a platform native keycode into an equivalent USB keycode. 85 // Convert a platform native keycode into an equivalent USB keycode.
65 static uint32_t NativeKeycodeToUsbKeycode(uint16_t native_keycode); 86 static uint32_t NativeKeycodeToUsbKeycode(uint16_t native_keycode);
66 87
67 // Convert a USB keycode into the string with the DOM3 |code| value. 88 // Convert a USB keycode into the string with the DOM3 |code| value.
68 // The returned pointer references a static global string. 89 // The returned pointer references a static global string.
69 static const char* UsbKeycodeToCode(uint32_t usb_keycode); 90 static const char* UsbKeycodeToCode(uint32_t usb_keycode);
70 91
71 // Convert a DOM3 Event |code| string into a USB keycode value. 92 // Convert a DOM3 Event |code| string into a USB keycode value.
72 static uint32_t CodeToUsbKeycode(const char* code); 93 static uint32_t CodeToUsbKeycode(const char* code);
73 94
74 // Static methods to support testing. 95 // Static methods to support testing.
75 static size_t NumKeycodeMapEntriesForTest(); 96 static size_t NumKeycodeMapEntriesForTest();
76 static const KeycodeMapEntry* GetKeycodeMapForTest(); 97 static const KeycodeMapEntry* GetKeycodeMapForTest();
98 static const char* DomCodeStringForTest(size_t index);
99 static const char* DomKeyStringForTest(size_t index);
77 100
78 private: 101 private:
79 DISALLOW_COPY_AND_ASSIGN(KeycodeConverter); 102 DISALLOW_COPY_AND_ASSIGN(KeycodeConverter);
80 }; 103 };
81 104
82 } // namespace ui 105 } // namespace ui
83 106
84 #endif // UI_EVENTS_KEYCODES_DOM4_KEYCODE_CONVERTER_H_ 107 #endif // UI_EVENTS_KEYCODES_DOM4_KEYCODE_CONVERTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698