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