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 <string> | |
| 10 | |
| 9 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "ui/events/keycodes/dom/dom_key.h" | |
| 10 | 13 |
| 11 // For reference, the W3C UI Event spec is located at: | 14 // For reference, the W3C UI Event spec is located at: |
| 12 // http://www.w3.org/TR/uievents/ | 15 // http://www.w3.org/TR/uievents/ |
| 13 | 16 |
| 14 namespace ui { | 17 namespace ui { |
| 15 | 18 |
| 16 enum class DomCode; | 19 enum class DomCode; |
| 17 enum class DomKey; | |
| 18 | 20 |
| 19 enum class DomKeyLocation { STANDARD, LEFT, RIGHT, NUMPAD }; | 21 enum class DomKeyLocation { STANDARD, LEFT, RIGHT, NUMPAD }; |
| 20 | 22 |
| 21 // This structure is used to define the keycode mapping table. | 23 // This structure is used to define the keycode mapping table. |
| 22 // It is defined here because the unittests need access to it. | 24 // It is defined here because the unittests need access to it. |
| 23 typedef struct { | 25 typedef struct { |
| 24 // USB keycode: | 26 // USB keycode: |
| 25 // Upper 16-bits: USB Usage Page. | 27 // Upper 16-bits: USB Usage Page. |
| 26 // Lower 16-bits: USB Usage Id: Assigned ID within this usage page. | 28 // Lower 16-bits: USB Usage Id: Assigned ID within this usage page. |
| 27 uint32_t usb_keycode; | 29 uint32_t usb_keycode; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 55 static DomCode CodeStringToDomCode(const char* code); | 57 static DomCode CodeStringToDomCode(const char* code); |
| 56 | 58 |
| 57 // Convert a DomCode into a UI Events |code| string value. | 59 // Convert a DomCode into a UI Events |code| string value. |
| 58 static const char* DomCodeToCodeString(DomCode dom_code); | 60 static const char* DomCodeToCodeString(DomCode dom_code); |
| 59 | 61 |
| 60 // Return the DomKeyLocation of a DomCode. The DomKeyLocation distinguishes | 62 // Return the DomKeyLocation of a DomCode. The DomKeyLocation distinguishes |
| 61 // keys with the same meaning, and therefore the same DomKey or non-located | 63 // keys with the same meaning, and therefore the same DomKey or non-located |
| 62 // KeyboardCode (VKEY), and corresponds to the DOM UI Events | 64 // KeyboardCode (VKEY), and corresponds to the DOM UI Events |
| 63 // |KeyboardEvent.location|. | 65 // |KeyboardEvent.location|. |
| 64 static DomKeyLocation DomCodeToLocation(DomCode dom_code); | 66 static DomKeyLocation DomCodeToLocation(DomCode dom_code); |
| 65 | 67 |
|
kpschoedel
2015/08/07 20:42:12
KeyStringToDomKey() and DomKeyToKeyString() now ha
| |
| 66 // Convert a UI Events |key| string value into a DomKey. | 68 // Convert a UI Events |key| string value into a DomKey. |
| 69 // Accepts a character string containing either | |
| 70 // - a key name from http://www.w3.org/TR/DOM-Level-3-Events-key/, or | |
| 71 // - a single Unicode character (represented in UTF-8). | |
| 72 // Returns DomKey::NONE for other inputs, including |nullptr|. | |
| 67 static DomKey KeyStringToDomKey(const char* key); | 73 static DomKey KeyStringToDomKey(const char* key); |
| 68 | 74 |
| 69 // Convert a DomKey into a UI Events |key| string value. | 75 // Convert a DomKey into a UI Events |key| string value. |
| 70 static const char* DomKeyToKeyString(DomKey dom_key); | 76 static std::string DomKeyToKeyString(DomKey dom_key); |
| 71 | 77 |
| 72 // Returns true if the DomKey is a modifier. | 78 // Returns true if the DomKey is a modifier. |
| 73 static bool IsDomKeyForModifier(DomKey dom_key); | 79 static bool IsDomKeyForModifier(DomKey dom_key); |
| 74 | 80 |
| 75 // The following methods relate to USB keycodes. | 81 // The following methods relate to USB keycodes. |
| 76 // Note that USB keycodes are not part of any web standard. | 82 // Note that USB keycodes are not part of any web standard. |
| 77 // Please don't use USB keycodes in new code. | 83 // Please don't use USB keycodes in new code. |
| 78 | 84 |
| 79 // Return the value that identifies an invalid USB keycode. | 85 // Return the value that identifies an invalid USB keycode. |
| 80 static uint32_t InvalidUsbKeycode(); | 86 static uint32_t InvalidUsbKeycode(); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 99 static const KeycodeMapEntry* GetKeycodeMapForTest(); | 105 static const KeycodeMapEntry* GetKeycodeMapForTest(); |
| 100 static const char* DomKeyStringForTest(size_t index); | 106 static const char* DomKeyStringForTest(size_t index); |
| 101 | 107 |
| 102 private: | 108 private: |
| 103 DISALLOW_COPY_AND_ASSIGN(KeycodeConverter); | 109 DISALLOW_COPY_AND_ASSIGN(KeycodeConverter); |
| 104 }; | 110 }; |
| 105 | 111 |
| 106 } // namespace ui | 112 } // namespace ui |
| 107 | 113 |
| 108 #endif // UI_EVENTS_KEYCODES_DOM4_KEYCODE_CONVERTER_H_ | 114 #endif // UI_EVENTS_KEYCODES_DOM4_KEYCODE_CONVERTER_H_ |
| OLD | NEW |