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