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
3 // found in the LICENSE file.
5 #ifndef UI_EVENTS_KEYCODES_DOM4_KEYCODE_CONVERTER_H_
6 #define UI_EVENTS_KEYCODES_DOM4_KEYCODE_CONVERTER_H_
9 #include "base/basictypes.h"
11 // For reference, the W3C UI Event spec is located at:
12 // http://www.w3.org/TR/uievents/
19 // This structure is used to define the keycode mapping table.
20 // It is defined here because the unittests need access to it.
23 // Upper 16-bits: USB Usage Page.
24 // Lower 16-bits: USB Usage Id: Assigned ID within this usage page.
27 // Contains one of the following:
28 // On Linux: XKB scancode
29 // On Windows: Windows OEM scancode
30 // On Mac: Mac keycode
33 // The UIEvents (aka: DOM4Events) |code| value as defined in:
34 // http://www.w3.org/TR/DOM-Level-3-Events-code/
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
40 // spec (http://www.w3.org/TR/uievents/).
41 class KeycodeConverter
{
43 // Return the value that identifies an invalid native keycode.
44 static int InvalidNativeKeycode();
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
);
50 // Convert a native (Mac/Win/Linux) keycode into a DomCode.
51 static DomCode
NativeKeycodeToDomCode(int native_keycode
);
53 // Convert a UI Events |code| string value into a native keycode.
54 static int CodeToNativeKeycode(const char* code
);
56 // Convert a DomCode into a native keycode.
57 static int DomCodeToNativeKeycode(DomCode code
);
59 // Convert a UI Events |code| string value into a DomCode.
60 static DomCode
CodeStringToDomCode(const char* code
);
62 // Convert a DomCode into a UI Events |code| string value.
63 static const char* DomCodeToCodeString(DomCode dom_code
);
65 // Convert a UI Events |key| string value into a DomKey.
66 static DomKey
KeyStringToDomKey(const char* key
);
68 // Convert a DomKey into a UI Events |key| string value.
69 static const char* DomKeyToKeyString(DomKey dom_key
);
71 // The following methods relate to USB keycodes.
72 // Note that USB keycodes are not part of any web standard.
73 // Please don't use USB keycodes in new code.
75 // Return the value that identifies an invalid USB keycode.
76 static uint32_t InvalidUsbKeycode();
78 // Convert a USB keycode into an equivalent platform native keycode.
79 static int UsbKeycodeToNativeKeycode(uint32_t usb_keycode
);
81 // Convert a platform native keycode into an equivalent USB keycode.
82 static uint32_t NativeKeycodeToUsbKeycode(int native_keycode
);
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
);
88 // Convert a USB keycode into a DomCode.
89 static DomCode
UsbKeycodeToDomCode(uint32_t usb_keycode
);
91 // Convert a DOM3 Event |code| string into a USB keycode value.
92 static uint32_t CodeToUsbKeycode(const char* code
);
94 // Static methods to support testing.
95 static size_t NumKeycodeMapEntriesForTest();
96 static const KeycodeMapEntry
* GetKeycodeMapForTest();
97 static const char* DomKeyStringForTest(size_t index
);
100 DISALLOW_COPY_AND_ASSIGN(KeycodeConverter
);
105 #endif // UI_EVENTS_KEYCODES_DOM4_KEYCODE_CONVERTER_H_