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 #include "base/memory/singleton.h" | |
11 | 10 |
12 // For reference, the W3C UI Event spec is located at: | 11 // For reference, the W3C UI Event spec is located at: |
13 // http://www.w3.org/TR/uievents/ | 12 // http://www.w3.org/TR/uievents/ |
14 | 13 |
15 namespace ui { | 14 namespace ui { |
16 | 15 |
17 // This structure is used to define the keycode mapping table. | 16 // This structure is used to define the keycode mapping table. |
18 // It is defined here because the unittests need access to it. | 17 // It is defined here because the unittests need access to it. |
19 typedef struct { | 18 typedef struct { |
20 // USB keycode: | 19 // USB keycode: |
(...skipping 10 matching lines...) Expand all Loading... |
31 // The UIEvents (aka: DOM4Events) |code| value as defined in: | 30 // The UIEvents (aka: DOM4Events) |code| value as defined in: |
32 // https://dvcs.w3.org/hg/d4e/raw-file/tip/source_respec.htm | 31 // https://dvcs.w3.org/hg/d4e/raw-file/tip/source_respec.htm |
33 const char* code; | 32 const char* code; |
34 } KeycodeMapEntry; | 33 } KeycodeMapEntry; |
35 | 34 |
36 // A class to convert between the current platform's native keycode (scancode) | 35 // A class to convert between the current platform's native keycode (scancode) |
37 // and platform-neutral |code| values (as defined in the W3C UI Events | 36 // and platform-neutral |code| values (as defined in the W3C UI Events |
38 // spec (http://www.w3.org/TR/uievents/). | 37 // spec (http://www.w3.org/TR/uievents/). |
39 class KeycodeConverter { | 38 class KeycodeConverter { |
40 public: | 39 public: |
41 static KeycodeConverter* GetInstance(); | |
42 | |
43 // Return the value that identifies an invalid native keycode. | 40 // Return the value that identifies an invalid native keycode. |
44 uint16_t InvalidNativeKeycode(); | 41 static uint16_t InvalidNativeKeycode(); |
45 | 42 |
46 // Return the string that indentifies an invalid UI Event |code|. | 43 // Return the string that indentifies an invalid UI Event |code|. |
47 // The returned pointer references a static global string. | 44 // The returned pointer references a static global string. |
48 const char* InvalidKeyboardEventCode(); | 45 static const char* InvalidKeyboardEventCode(); |
49 | 46 |
50 // Convert a native (Mac/Win/Linux) keycode into the |code| string. | 47 // Convert a native (Mac/Win/Linux) keycode into the |code| string. |
51 // The returned pointer references a static global string. | 48 // The returned pointer references a static global string. |
52 const char* NativeKeycodeToCode(uint16_t native_keycode); | 49 static const char* NativeKeycodeToCode(uint16_t native_keycode); |
53 | 50 |
54 // Convert a UI Events |code| string value into a native keycode. | 51 // Convert a UI Events |code| string value into a native keycode. |
55 uint16_t CodeToNativeKeycode(const char* code); | 52 static uint16_t CodeToNativeKeycode(const char* code); |
56 | 53 |
57 // The following methods relate to USB keycodes. | 54 // The following methods relate to USB keycodes. |
58 // Note that USB keycodes are not part of any web standard. | 55 // Note that USB keycodes are not part of any web standard. |
59 // Please don't use USB keycodes in new code. | 56 // Please don't use USB keycodes in new code. |
60 | 57 |
61 // Return the value that identifies an invalid USB keycode. | 58 // Return the value that identifies an invalid USB keycode. |
62 uint16_t InvalidUsbKeycode(); | 59 static uint16_t InvalidUsbKeycode(); |
63 | 60 |
64 // Convert a USB keycode into an equivalent platform native keycode. | 61 // Convert a USB keycode into an equivalent platform native keycode. |
65 uint16_t UsbKeycodeToNativeKeycode(uint32_t usb_keycode); | 62 static uint16_t UsbKeycodeToNativeKeycode(uint32_t usb_keycode); |
66 | 63 |
67 // Convert a platform native keycode into an equivalent USB keycode. | 64 // Convert a platform native keycode into an equivalent USB keycode. |
68 uint32_t NativeKeycodeToUsbKeycode(uint16_t native_keycode); | 65 static uint32_t NativeKeycodeToUsbKeycode(uint16_t native_keycode); |
69 | 66 |
70 // Convert a USB keycode into the string with the DOM3 |code| value. | 67 // Convert a USB keycode into the string with the DOM3 |code| value. |
71 // The returned pointer references a static global string. | 68 // The returned pointer references a static global string. |
72 const char* UsbKeycodeToCode(uint32_t usb_keycode); | 69 static const char* UsbKeycodeToCode(uint32_t usb_keycode); |
73 | 70 |
74 // Convert a DOM3 Event |code| string into a USB keycode value. | 71 // Convert a DOM3 Event |code| string into a USB keycode value. |
75 uint32_t CodeToUsbKeycode(const char* code); | 72 static uint32_t CodeToUsbKeycode(const char* code); |
76 | 73 |
77 // Static methods to support testing. | 74 // Static methods to support testing. |
78 size_t NumKeycodeMapEntriesForTest(); | 75 static size_t NumKeycodeMapEntriesForTest(); |
79 const KeycodeMapEntry* GetKeycodeMapForTest(); | 76 static const KeycodeMapEntry* GetKeycodeMapForTest(); |
80 | 77 |
81 private: | 78 private: |
82 KeycodeConverter(); | |
83 friend struct DefaultSingletonTraits<KeycodeConverter>; | |
84 | |
85 DISALLOW_COPY_AND_ASSIGN(KeycodeConverter); | 79 DISALLOW_COPY_AND_ASSIGN(KeycodeConverter); |
86 }; | 80 }; |
87 | 81 |
88 } // namespace ui | 82 } // namespace ui |
89 | 83 |
90 #endif // UI_EVENTS_KEYCODES_DOM4_KEYCODE_CONVERTER_H_ | 84 #endif // UI_EVENTS_KEYCODES_DOM4_KEYCODE_CONVERTER_H_ |
OLD | NEW |