#include "base/time/time.h"
#include "base/strings/utf_string_conversions.h"
+#include "platform/WindowsKeyboardCodes.h"
#include "third_party/WebKit/public/web/WebInputEvent.h"
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/events/keycodes/keyboard_code_conversion_x.h"
namespace content {
+typedef base::hash_map<std::string, int> WindowsKeyMap;
static const float cDefaultScrollStep = 20;
-static ui::KeyboardCode KeyboardCodeFromEflKey(const char* key) {
- return ui::KeyboardCodeFromXKeysym(XStringToKeysym(key));
+static WindowsKeyMap& WinKeyMap() {
+ CR_DEFINE_STATIC_LOCAL(WindowsKeyMap, windowsKeyMap, ());
+ return windowsKeyMap;
+}
+
+static inline void AddCharactersToWinKeyMap(const char from, const char to, const int baseCode) {
+ int i = 0;
+ for (char c = from; c <= to; c++, i++) {
+ WinKeyMap()[std::string(&c, 1)] = baseCode + i;
+ }
+}
+
+static void PopulateWindowsKeyMap() {
+ WinKeyMap()["Return"] = VK_RETURN;
+ WinKeyMap()["KP_Return"] = VK_RETURN;
+ WinKeyMap()["Alt_L"] = VK_LMENU;
+ WinKeyMap()["Alt_R"] = VK_RMENU;
+ WinKeyMap()["ISO_Level3_Shift"] = VK_MENU;
+ WinKeyMap()["Menu"] = VK_MENU;
+ WinKeyMap()["Shift_L"] = VK_LSHIFT;
+ WinKeyMap()["Shift_R"] = VK_RSHIFT;
+ WinKeyMap()["Control_L"] = VK_LCONTROL;
+ WinKeyMap()["Control_R"] = VK_RCONTROL;
+ WinKeyMap()["Pause"] = VK_PAUSE;
+ WinKeyMap()["Break"] = VK_PAUSE;
+ WinKeyMap()["Caps_Lock"] = VK_CAPITAL;
+ WinKeyMap()["Scroll_Lock"] = VK_SCROLL;
+ WinKeyMap()["Num_Lock"] = VK_NUMLOCK;
+ WinKeyMap()["Escape"] = VK_ESCAPE;
+ WinKeyMap()["Tab"] = VK_TAB;
+ WinKeyMap()["ISO_Left_Tab"] = VK_TAB;
+ WinKeyMap()["BackSpace"] = VK_BACK;
+ WinKeyMap()["space"] = VK_SPACE;
+ WinKeyMap()["Next"] = VK_NEXT;
+ WinKeyMap()["Prior"] = VK_PRIOR;
+ WinKeyMap()["Home"] = VK_HOME;
+ WinKeyMap()["End"] = VK_END;
+ WinKeyMap()["Right"] = VK_RIGHT;
+ WinKeyMap()["Left"] = VK_LEFT;
+ WinKeyMap()["Up"] = VK_UP;
+ WinKeyMap()["Down"] = VK_DOWN;
+ WinKeyMap()["Print"] = VK_SNAPSHOT;
+ WinKeyMap()["Insert"] = VK_INSERT;
+ WinKeyMap()["Delete"] = VK_DELETE;
+
+ WinKeyMap()["comma"] = VK_OEM_COMMA;
+ WinKeyMap()["less"] = VK_OEM_COMMA;
+ WinKeyMap()["period"] = VK_OEM_PERIOD;
+ WinKeyMap()["greater"] = VK_OEM_PERIOD;
+ WinKeyMap()["semicolon"] = VK_OEM_1;
+ WinKeyMap()["colon"] = VK_OEM_1;
+ WinKeyMap()["slash"] = VK_OEM_2;
+ WinKeyMap()["question"] = VK_OEM_2;
+ WinKeyMap()["grave"] = VK_OEM_3;
+ WinKeyMap()["asciitilde"] = VK_OEM_3;
+ WinKeyMap()["bracketleft"] = VK_OEM_4;
+ WinKeyMap()["braceleft"] = VK_OEM_4;
+ WinKeyMap()["backslash"] = VK_OEM_5;
+ WinKeyMap()["bar"] = VK_OEM_5;
+ WinKeyMap()["bracketright"] = VK_OEM_6;
+ WinKeyMap()["braceright"] = VK_OEM_6;
+ WinKeyMap()["apostrophe"] = VK_OEM_7;
+ WinKeyMap()["quotedbl"] = VK_OEM_7;
+ // Keypad location
+ WinKeyMap()["KP_Left"] = VK_LEFT;
+ WinKeyMap()["KP_Right"] = VK_RIGHT;
+ WinKeyMap()["KP_Up"] = VK_UP;
+ WinKeyMap()["KP_Down"] = VK_DOWN;
+ WinKeyMap()["KP_Prior"] = VK_PRIOR;
+ WinKeyMap()["KP_Next"] = VK_NEXT;
+ WinKeyMap()["KP_Home"] = VK_HOME;
+ WinKeyMap()["KP_End"] = VK_END;
+ WinKeyMap()["KP_Insert"] = VK_INSERT;
+ WinKeyMap()["KP_Delete"] = VK_DELETE;
+
+ // Set alphabet to the windowsKeyMap.
+ AddCharactersToWinKeyMap('a', 'z', VK_A);
+ AddCharactersToWinKeyMap('A', 'Z', VK_A);
+
+ // Set digits to the windowsKeyMap.
+ AddCharactersToWinKeyMap('0', '9', VK_0);
+
+ // Set shifted digits to the windowsKeyMap.
+ WinKeyMap()["exclam"] = VK_1;
+ WinKeyMap()["at"] = VK_2;
+ WinKeyMap()["numbersign"] = VK_3;
+ WinKeyMap()["dollar"] = VK_4;
+ WinKeyMap()["percent"] = VK_5;
+ WinKeyMap()["asciicircum"] = VK_6;
+ WinKeyMap()["ampersand"] = VK_7;
+ WinKeyMap()["asterisk"] = VK_8;
+ WinKeyMap()["parenleft"] = VK_9;
+ WinKeyMap()["parenright"] = VK_0;
+ WinKeyMap()["minus"] = VK_OEM_MINUS;
+ WinKeyMap()["underscore"] = VK_OEM_MINUS;
+ WinKeyMap()["equal"] = VK_OEM_PLUS;
+ WinKeyMap()["plus"] = VK_OEM_PLUS;
+
+ // Set F_XX keys to the windowsKeyMap.
+ for (unsigned i = 1; i < 25; i++) {
+ std::string key = "F" + std::to_string(i);
+ WinKeyMap()[key] = VK_F1 + i - 1;
+ }
+
+ WinKeyMap()["KP_Enter"] = VK_RETURN;
+ WinKeyMap()["Hangul"] = VK_HANGUL;
+ WinKeyMap()["Hangul_Hanja"] = VK_HANJA;
+ WinKeyMap()["KP_Multiply"] = VK_MULTIPLY;
+ WinKeyMap()["KP_Add"] = VK_ADD;
+ WinKeyMap()["KP_Subtract"] = VK_SUBTRACT;
+ WinKeyMap()["KP_Decimal"] = VK_DECIMAL;
+ WinKeyMap()["KP_Divide"] = VK_DIVIDE;
+ WinKeyMap()["dead_grave"] = VK_OEM_3;
+ WinKeyMap()["ISO_Level3_Shift"] = 0xE1;
+
+ for (unsigned i = 0; i < 10; i++) {
+ std::string key = "KP_" + std::to_string(i);
+ WinKeyMap()[key] = VK_NUMPAD0 + i;
+ }
+}
+
+static int KeyboardCodeFromEflKey(const char* key) {
+
+ if (WinKeyMap().empty())
+ PopulateWindowsKeyMap();
+
+ std::string keyName(key);
+ WindowsKeyMap::iterator it = WinKeyMap().find(keyName);
+
+ if (it != WinKeyMap().end())
+ return it->second;
+
+ return 0;
}
static int WindowsKeyCodeFromEflKey(const char* key) {