1 // Copyright 2014 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 #include "ui/base/ime/chromeos/ime_keymap.h"
9 #include "base/lazy_instance.h"
15 const struct KeyCodeTable
{
16 KeyboardCode keyboard_code
;
19 {VKEY_BACK
, "Backspace"},
21 {VKEY_RETURN
, "Enter"},
22 {VKEY_MENU
, "ContextMenu"},
23 {VKEY_PAUSE
, "Pause"},
24 {VKEY_CAPITAL
, "CapsLock"},
25 {VKEY_KANA
, "KanaMode"},
26 {VKEY_HANGUL
, "HangulMode"},
27 {VKEY_HANJA
, "Hanja"},
28 {VKEY_KANJI
, "Kanji"},
29 {VKEY_ESCAPE
, "Escape"},
30 {VKEY_CONVERT
, "Convert"},
31 {VKEY_NONCONVERT
, "NoConvert"},
32 {VKEY_SPACE
, "Space"},
35 {VKEY_LEFT
, "ArrowLeft"},
37 {VKEY_RIGHT
, "ArrowRight"},
38 {VKEY_DOWN
, "ArrowDown"},
39 {VKEY_PRINT
, "PrintScreen"},
40 {VKEY_INSERT
, "Insert"},
41 {VKEY_DELETE
, "Delete"},
79 {VKEY_LWIN
, "OSLeft"},
80 {VKEY_RWIN
, "OSRight"},
81 {VKEY_NUMPAD0
, "Numpad0"},
82 {VKEY_NUMPAD1
, "Numpad1"},
83 {VKEY_NUMPAD2
, "Numpad2"},
84 {VKEY_NUMPAD3
, "Numpad3"},
85 {VKEY_NUMPAD4
, "Numpad4"},
86 {VKEY_NUMPAD5
, "Numpad5"},
87 {VKEY_NUMPAD6
, "Numpad6"},
88 {VKEY_NUMPAD7
, "Numpad7"},
89 {VKEY_NUMPAD8
, "Numpad8"},
90 {VKEY_NUMPAD9
, "Numpad9"},
91 {VKEY_MULTIPLY
, "NumpadMultiply"},
92 {VKEY_ADD
, "NumpadAdd"},
93 {VKEY_SUBTRACT
, "NumpadSubtract"},
94 {VKEY_DECIMAL
, "NumpadDecimal"},
95 {VKEY_DIVIDE
, "NumpadDivide"},
120 {VKEY_NUMLOCK
, "NumLock"},
121 {VKEY_SCROLL
, "ScrollLock"},
122 {VKEY_LSHIFT
, "ShiftLeft"},
123 {VKEY_RSHIFT
, "ShiftRight"},
124 {VKEY_LCONTROL
, "ControlLeft"},
125 {VKEY_RCONTROL
, "ControlRight"},
126 {VKEY_LMENU
, "AltLeft"},
127 {VKEY_RMENU
, "AltRight"},
128 {VKEY_BROWSER_BACK
, "BrowserBack"},
129 {VKEY_BROWSER_FORWARD
, "BrowserForward"},
130 {VKEY_BROWSER_REFRESH
, "BrowserRefresh"},
131 {VKEY_BROWSER_STOP
, "BrowserStop"},
132 {VKEY_BROWSER_SEARCH
, "BrowserSearch"},
133 {VKEY_BROWSER_HOME
, "BrowserHome"},
134 {VKEY_VOLUME_MUTE
, "VolumeMute"},
135 {VKEY_VOLUME_DOWN
, "VolumeDown"},
136 {VKEY_VOLUME_UP
, "VolumeUp"},
137 {VKEY_BRIGHTNESS_DOWN
, "BrightnessDown"},
138 {VKEY_BRIGHTNESS_UP
, "BrightnessUp"},
139 {VKEY_MEDIA_LAUNCH_APP1
, "ChromeOSSwitchWindow"},
140 {VKEY_MEDIA_LAUNCH_APP2
, "ChromeOSFullscreen"},
141 {VKEY_MEDIA_NEXT_TRACK
, "MediaTrackNext"},
142 {VKEY_MEDIA_PREV_TRACK
, "MediaTrackPrevious"},
143 {VKEY_MEDIA_STOP
, "MediaStop"},
144 {VKEY_MEDIA_PLAY_PAUSE
, "MediaPlayPause"},
145 {VKEY_MEDIA_LAUNCH_MAIL
, "LaunchMail"},
146 {VKEY_OEM_1
, "Semicolon"},
147 {VKEY_OEM_PLUS
, "Equal"},
148 {VKEY_OEM_COMMA
, "Comma"},
149 {VKEY_OEM_MINUS
, "Minus"},
150 {VKEY_OEM_PERIOD
, "Period"},
151 {VKEY_OEM_2
, "Slash"},
152 {VKEY_OEM_3
, "Backquote"},
153 {VKEY_OEM_4
, "BracketLeft"},
154 {VKEY_OEM_5
, "Backslash"},
155 {VKEY_OEM_6
, "BracketRight"},
156 {VKEY_OEM_7
, "Quote"}};
161 for (size_t i
= 0; i
< arraysize(kKeyCodeTable
); ++i
) {
162 map_dom_key_
[kKeyCodeTable
[i
].dom_code
] = kKeyCodeTable
[i
].keyboard_code
;
163 map_key_dom_
[kKeyCodeTable
[i
].keyboard_code
] = kKeyCodeTable
[i
].dom_code
;
167 KeyboardCode
GetKeyboardCode(const std::string
& dom_code
) const {
168 std::map
<std::string
, KeyboardCode
>::const_iterator it
=
169 map_dom_key_
.find(dom_code
);
170 return (it
== map_dom_key_
.end()) ? VKEY_UNKNOWN
: it
->second
;
173 std::string
GetDomKeycode(KeyboardCode key_code
) const {
174 std::map
<KeyboardCode
, std::string
>::const_iterator it
=
175 map_key_dom_
.find(key_code
);
176 return (it
== map_key_dom_
.end()) ? "" : it
->second
;
180 std::map
<std::string
, KeyboardCode
> map_dom_key_
;
181 std::map
<KeyboardCode
, std::string
> map_key_dom_
;
184 base::LazyInstance
<KeyCodeMap
>::Leaky g_keycode_map
=
185 LAZY_INSTANCE_INITIALIZER
;
189 KeyboardCode
DomKeycodeToKeyboardCode(const std::string
& code
) {
190 return g_keycode_map
.Get().GetKeyboardCode(code
);
193 std::string
KeyboardCodeToDomKeycode(KeyboardCode code
) {
194 return g_keycode_map
.Get().GetDomKeycode(code
);