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/
16 // This structure is used to define the keycode mapping table.
17 // It is defined here because the unittests need access to it.
20 // Upper 16-bits: USB Usage Page.
21 // Lower 16-bits: USB Usage Id: Assigned ID within this usage page.
24 // Contains one of the following:
25 // On Linux: XKB scancode
26 // On Windows: Windows OEM scancode
27 // On Mac: Mac keycode
28 uint16_t native_keycode
;
30 // The UIEvents (aka: DOM4Events) |code| value as defined in:
31 // https://dvcs.w3.org/hg/d4e/raw-file/tip/source_respec.htm
35 // 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
37 // spec (http://www.w3.org/TR/uievents/).
38 class KeycodeConverter
{
40 // Return the value that identifies an invalid native keycode.
41 static uint16_t InvalidNativeKeycode();
43 // Return the string that indentifies an invalid UI Event |code|.
44 // The returned pointer references a static global string.
45 static const char* InvalidKeyboardEventCode();
47 // Convert a native (Mac/Win/Linux) keycode into the |code| string.
48 // The returned pointer references a static global string.
49 static const char* NativeKeycodeToCode(uint16_t native_keycode
);
51 // Convert a UI Events |code| string value into a native keycode.
52 static uint16_t CodeToNativeKeycode(const char* code
);
54 // The following methods relate to USB keycodes.
55 // Note that USB keycodes are not part of any web standard.
56 // Please don't use USB keycodes in new code.
58 // Return the value that identifies an invalid USB keycode.
59 static uint16_t InvalidUsbKeycode();
61 // Convert a USB keycode into an equivalent platform native keycode.
62 static uint16_t UsbKeycodeToNativeKeycode(uint32_t usb_keycode
);
64 // Convert a platform native keycode into an equivalent USB keycode.
65 static uint32_t NativeKeycodeToUsbKeycode(uint16_t native_keycode
);
67 // Convert a USB keycode into the string with the DOM3 |code| value.
68 // The returned pointer references a static global string.
69 static const char* UsbKeycodeToCode(uint32_t usb_keycode
);
71 // Convert a DOM3 Event |code| string into a USB keycode value.
72 static uint32_t CodeToUsbKeycode(const char* code
);
74 // Static methods to support testing.
75 static size_t NumKeycodeMapEntriesForTest();
76 static const KeycodeMapEntry
* GetKeycodeMapForTest();
79 DISALLOW_COPY_AND_ASSIGN(KeycodeConverter
);
84 #endif // UI_EVENTS_KEYCODES_DOM4_KEYCODE_CONVERTER_H_