OLD | NEW |
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 |
(...skipping 25 matching lines...) Expand all Loading... |
36 } KeycodeMapEntry; | 36 } KeycodeMapEntry; |
37 | 37 |
38 // 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) |
39 // 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 |
40 // spec (http://www.w3.org/TR/uievents/). | 40 // spec (http://www.w3.org/TR/uievents/). |
41 class KeycodeConverter { | 41 class KeycodeConverter { |
42 public: | 42 public: |
43 // Return the value that identifies an invalid native keycode. | 43 // Return the value that identifies an invalid native keycode. |
44 static int InvalidNativeKeycode(); | 44 static int InvalidNativeKeycode(); |
45 | 45 |
46 // Convert a native (Mac/Win/Linux) keycode into the |code| string. | |
47 // The returned pointer references a static global string. | |
48 static const char* NativeKeycodeToCode(int native_keycode); | |
49 | |
50 // Convert a native (Mac/Win/Linux) keycode into a DomCode. | 46 // Convert a native (Mac/Win/Linux) keycode into a DomCode. |
51 static DomCode NativeKeycodeToDomCode(int native_keycode); | 47 static DomCode NativeKeycodeToDomCode(int native_keycode); |
52 | 48 |
53 // Convert a UI Events |code| string value into a native keycode. | |
54 static int CodeToNativeKeycode(const char* code); | |
55 | |
56 // Convert a DomCode into a native keycode. | 49 // Convert a DomCode into a native keycode. |
57 static int DomCodeToNativeKeycode(DomCode code); | 50 static int DomCodeToNativeKeycode(DomCode code); |
58 | 51 |
59 // Convert a UI Events |code| string value into a DomCode. | 52 // Convert a UI Events |code| string value into a DomCode. |
60 static DomCode CodeStringToDomCode(const char* code); | 53 static DomCode CodeStringToDomCode(const char* code); |
61 | 54 |
62 // Convert a DomCode into a UI Events |code| string value. | 55 // Convert a DomCode into a UI Events |code| string value. |
63 static const char* DomCodeToCodeString(DomCode dom_code); | 56 static const char* DomCodeToCodeString(DomCode dom_code); |
64 | 57 |
65 // Convert a UI Events |key| string value into a DomKey. | 58 // Convert a UI Events |key| string value into a DomKey. |
66 static DomKey KeyStringToDomKey(const char* key); | 59 static DomKey KeyStringToDomKey(const char* key); |
67 | 60 |
68 // Convert a DomKey into a UI Events |key| string value. | 61 // Convert a DomKey into a UI Events |key| string value. |
69 static const char* DomKeyToKeyString(DomKey dom_key); | 62 static const char* DomKeyToKeyString(DomKey dom_key); |
70 | 63 |
71 // The following methods relate to USB keycodes. | 64 // The following methods relate to USB keycodes. |
72 // Note that USB keycodes are not part of any web standard. | 65 // Note that USB keycodes are not part of any web standard. |
73 // Please don't use USB keycodes in new code. | 66 // Please don't use USB keycodes in new code. |
74 | 67 |
75 // Return the value that identifies an invalid USB keycode. | 68 // Return the value that identifies an invalid USB keycode. |
76 static uint32_t InvalidUsbKeycode(); | 69 static uint32_t InvalidUsbKeycode(); |
77 | 70 |
78 // Convert a USB keycode into an equivalent platform native keycode. | 71 // Convert a USB keycode into an equivalent platform native keycode. |
79 static int UsbKeycodeToNativeKeycode(uint32_t usb_keycode); | 72 static int UsbKeycodeToNativeKeycode(uint32_t usb_keycode); |
80 | 73 |
81 // Convert a platform native keycode into an equivalent USB keycode. | 74 // Convert a platform native keycode into an equivalent USB keycode. |
82 static uint32_t NativeKeycodeToUsbKeycode(int native_keycode); | 75 static uint32_t NativeKeycodeToUsbKeycode(int native_keycode); |
83 | 76 |
84 // Convert a USB keycode into the string with the DOM3 |code| value. | |
85 // The returned pointer references a static global string. | |
86 static const char* UsbKeycodeToCode(uint32_t usb_keycode); | |
87 | |
88 // Convert a USB keycode into a DomCode. | 77 // Convert a USB keycode into a DomCode. |
89 static DomCode UsbKeycodeToDomCode(uint32_t usb_keycode); | 78 static DomCode UsbKeycodeToDomCode(uint32_t usb_keycode); |
90 | 79 |
| 80 // Convert a DomCode into a USB keycode. |
| 81 static uint32_t DomCodeToUsbKeycode(DomCode dom_code); |
| 82 |
91 // Convert a DOM3 Event |code| string into a USB keycode value. | 83 // Convert a DOM3 Event |code| string into a USB keycode value. |
92 static uint32_t CodeToUsbKeycode(const char* code); | 84 static uint32_t CodeToUsbKeycode(const char* code); |
93 | 85 |
94 // Static methods to support testing. | 86 // Static methods to support testing. |
95 static size_t NumKeycodeMapEntriesForTest(); | 87 static size_t NumKeycodeMapEntriesForTest(); |
96 static const KeycodeMapEntry* GetKeycodeMapForTest(); | 88 static const KeycodeMapEntry* GetKeycodeMapForTest(); |
97 static const char* DomKeyStringForTest(size_t index); | 89 static const char* DomKeyStringForTest(size_t index); |
98 | 90 |
99 private: | 91 private: |
100 DISALLOW_COPY_AND_ASSIGN(KeycodeConverter); | 92 DISALLOW_COPY_AND_ASSIGN(KeycodeConverter); |
101 }; | 93 }; |
102 | 94 |
103 } // namespace ui | 95 } // namespace ui |
104 | 96 |
105 #endif // UI_EVENTS_KEYCODES_DOM4_KEYCODE_CONVERTER_H_ | 97 #endif // UI_EVENTS_KEYCODES_DOM4_KEYCODE_CONVERTER_H_ |
OLD | NEW |