Add ICU message format support
[chromium-blink-merge.git] / ui / events / keycodes / dom / keycode_converter.h
blob71c3fd3031eee8f09651831344e7ee2ba959c479
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_
8 #include <stdint.h>
9 #include "base/basictypes.h"
11 // For reference, the W3C UI Event spec is located at:
12 // http://www.w3.org/TR/uievents/
14 namespace ui {
16 enum class DomCode;
17 enum class DomKey;
19 enum class DomKeyLocation { STANDARD, LEFT, RIGHT, NUMPAD };
21 // This structure is used to define the keycode mapping table.
22 // It is defined here because the unittests need access to it.
23 typedef struct {
24 // USB keycode:
25 // Upper 16-bits: USB Usage Page.
26 // Lower 16-bits: USB Usage Id: Assigned ID within this usage page.
27 uint32_t usb_keycode;
29 // Contains one of the following:
30 // On Linux: XKB scancode
31 // On Windows: Windows OEM scancode
32 // On Mac: Mac keycode
33 int native_keycode;
35 // The UIEvents (aka: DOM4Events) |code| value as defined in:
36 // http://www.w3.org/TR/DOM-Level-3-Events-code/
37 const char* code;
38 } KeycodeMapEntry;
40 // A class to convert between the current platform's native keycode (scancode)
41 // and platform-neutral |code| values (as defined in the W3C UI Events
42 // spec (http://www.w3.org/TR/uievents/).
43 class KeycodeConverter {
44 public:
45 // Return the value that identifies an invalid native keycode.
46 static int InvalidNativeKeycode();
48 // Convert a native (Mac/Win/Linux) keycode into a DomCode.
49 static DomCode NativeKeycodeToDomCode(int native_keycode);
51 // Convert a DomCode into a native keycode.
52 static int DomCodeToNativeKeycode(DomCode code);
54 // Convert a UI Events |code| string value into a DomCode.
55 static DomCode CodeStringToDomCode(const char* code);
57 // Convert a DomCode into a UI Events |code| string value.
58 static const char* DomCodeToCodeString(DomCode dom_code);
60 // Return the DomKeyLocation of a DomCode. The DomKeyLocation distinguishes
61 // keys with the same meaning, and therefore the same DomKey or non-located
62 // KeyboardCode (VKEY), and corresponds to the DOM UI Events
63 // |KeyboardEvent.location|.
64 static DomKeyLocation DomCodeToLocation(DomCode dom_code);
66 // Convert a UI Events |key| string value into a DomKey.
67 static DomKey KeyStringToDomKey(const char* key);
69 // Convert a DomKey into a UI Events |key| string value.
70 static const char* DomKeyToKeyString(DomKey dom_key);
72 // Returns true if the DomKey is a modifier.
73 static bool IsDomKeyForModifier(DomKey dom_key);
75 // The following methods relate to USB keycodes.
76 // Note that USB keycodes are not part of any web standard.
77 // Please don't use USB keycodes in new code.
79 // Return the value that identifies an invalid USB keycode.
80 static uint32_t InvalidUsbKeycode();
82 // Convert a USB keycode into an equivalent platform native keycode.
83 static int UsbKeycodeToNativeKeycode(uint32_t usb_keycode);
85 // Convert a platform native keycode into an equivalent USB keycode.
86 static uint32_t NativeKeycodeToUsbKeycode(int native_keycode);
88 // Convert a USB keycode into a DomCode.
89 static DomCode UsbKeycodeToDomCode(uint32_t usb_keycode);
91 // Convert a DomCode into a USB keycode.
92 static uint32_t DomCodeToUsbKeycode(DomCode dom_code);
94 // Convert a DOM3 Event |code| string into a USB keycode value.
95 static uint32_t CodeToUsbKeycode(const char* code);
97 // Static methods to support testing.
98 static size_t NumKeycodeMapEntriesForTest();
99 static const KeycodeMapEntry* GetKeycodeMapForTest();
100 static const char* DomKeyStringForTest(size_t index);
102 private:
103 DISALLOW_COPY_AND_ASSIGN(KeycodeConverter);
106 } // namespace ui
108 #endif // UI_EVENTS_KEYCODES_DOM4_KEYCODE_CONVERTER_H_