2 * Copyright (C) 2011 Samsung Electronics
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include "EflKeyboardUtilities.h"
31 #include "WindowsKeyboardCodes.h"
32 #include <wtf/HashMap.h>
33 #include <wtf/text/StringHash.h>
34 #include <wtf/text/WTFString.h>
38 typedef HashMap<String, String> KeyMap;
39 typedef HashMap<String, int> WindowsKeyMap;
41 static KeyMap& keyMap()
43 DEFINE_STATIC_LOCAL(KeyMap, keyMap, ());
47 static WindowsKeyMap& windowsKeyMap()
49 DEFINE_STATIC_LOCAL(WindowsKeyMap, windowsKeyMap, ());
53 static void createKeyMap()
55 for (unsigned int i = 1; i < 25; i++) {
56 String key = "F" + String::number(i);
57 keyMap().set(key, key);
59 keyMap().set("Alt_L", "Alt");
60 keyMap().set("ISO_Level3_Shift", "Alt");
61 keyMap().set("Menu", "Alt");
62 keyMap().set("Shift_L", "Shift");
63 keyMap().set("Shift_R", "Shift");
64 keyMap().set("Down", "Down");
65 keyMap().set("End", "End");
66 keyMap().set("Return", "Enter");
67 keyMap().set("KP_Enter", "Enter");
68 keyMap().set("Home", "Home");
69 keyMap().set("Insert", "Insert");
70 keyMap().set("Left", "Left");
71 keyMap().set("Down", "Down");
72 keyMap().set("Next", "PageDown");
73 keyMap().set("Prior", "PageUp");
74 keyMap().set("Right", "Right");
75 keyMap().set("Up", "Up");
76 keyMap().set("Delete", "U+007F");
77 keyMap().set("Tab", "U+0009");
78 keyMap().set("ISO_Left_Tab", "U+0009");
81 static void createWindowsKeyMap()
83 windowsKeyMap().set("Return", VK_RETURN);
84 windowsKeyMap().set("KP_Return", VK_RETURN);
85 windowsKeyMap().set("Alt_L", VK_MENU);
86 windowsKeyMap().set("ISO_Level3_Shift", VK_MENU);
87 windowsKeyMap().set("Menu", VK_MENU);
88 windowsKeyMap().set("Shift_L", VK_SHIFT);
89 windowsKeyMap().set("Shift_R", VK_SHIFT);
90 windowsKeyMap().set("Control_L", VK_CONTROL);
91 windowsKeyMap().set("Control_R", VK_CONTROL);
92 windowsKeyMap().set("Pause", VK_PAUSE);
93 windowsKeyMap().set("Break", VK_PAUSE);
94 windowsKeyMap().set("Caps_Lock", VK_CAPITAL);
95 windowsKeyMap().set("Scroll_Lock", VK_SCROLL);
96 windowsKeyMap().set("Num_Lock", VK_NUMLOCK);
97 windowsKeyMap().set("Escape", VK_ESCAPE);
98 windowsKeyMap().set("Tab", VK_TAB);
99 windowsKeyMap().set("ISO_Left_Tab", VK_TAB);
100 windowsKeyMap().set("BackSpace", VK_BACK);
101 windowsKeyMap().set("Space", VK_SPACE);
102 windowsKeyMap().set("Next", VK_NEXT);
103 windowsKeyMap().set("Prior", VK_PRIOR);
104 windowsKeyMap().set("Home", VK_HOME);
105 windowsKeyMap().set("End", VK_END);
106 windowsKeyMap().set("Right", VK_RIGHT);
107 windowsKeyMap().set("Left", VK_LEFT);
108 windowsKeyMap().set("Up", VK_UP);
109 windowsKeyMap().set("Down", VK_DOWN);
110 windowsKeyMap().set("Print", VK_PRINT);
111 windowsKeyMap().set("Insert", VK_INSERT);
112 windowsKeyMap().set("Delete", VK_DELETE);
114 windowsKeyMap().set("comma", VK_OEM_COMMA);
115 windowsKeyMap().set("less", VK_OEM_COMMA);
116 windowsKeyMap().set("period", VK_OEM_PERIOD);
117 windowsKeyMap().set("greater", VK_OEM_PERIOD);
118 windowsKeyMap().set("semicolon", VK_OEM_1);
119 windowsKeyMap().set("colon", VK_OEM_1);
120 windowsKeyMap().set("slash", VK_OEM_2);
121 windowsKeyMap().set("question", VK_OEM_2);
122 windowsKeyMap().set("grave", VK_OEM_3);
123 windowsKeyMap().set("asciitilde", VK_OEM_3);
124 windowsKeyMap().set("bracketleft", VK_OEM_4);
125 windowsKeyMap().set("braceleft", VK_OEM_4);
126 windowsKeyMap().set("backslash", VK_OEM_5);
127 windowsKeyMap().set("bar", VK_OEM_5);
128 windowsKeyMap().set("bracketright", VK_OEM_6);
129 windowsKeyMap().set("braceright", VK_OEM_6);
130 windowsKeyMap().set("apostrophe", VK_OEM_7);
131 windowsKeyMap().set("quotedbl", VK_OEM_7);
133 // Set alphabet to the windowsKeyMap.
134 const char* alphabet = "abcdefghijklmnopqrstuvwxyz";
135 for (unsigned int i = 0; i < 26; i++) {
136 String key(alphabet + i, 1);
137 windowsKeyMap().set(key, VK_A + i);
140 // Set digits to the windowsKeyMap.
141 for (unsigned int i = 0; i < 10; i++) {
142 String key = String::number(i);
143 windowsKeyMap().set(key, VK_0 + i);
146 // Set shifted digits to the windowsKeyMap.
147 windowsKeyMap().set("exclam", VK_1);
148 windowsKeyMap().set("at", VK_2);
149 windowsKeyMap().set("numbersign", VK_3);
150 windowsKeyMap().set("dollar", VK_4);
151 windowsKeyMap().set("percent", VK_5);
152 windowsKeyMap().set("asciicircum", VK_6);
153 windowsKeyMap().set("ampersand", VK_7);
154 windowsKeyMap().set("asterisk", VK_8);
155 windowsKeyMap().set("parenleft", VK_9);
156 windowsKeyMap().set("parenright", VK_0);
157 windowsKeyMap().set("minus", VK_OEM_MINUS);
158 windowsKeyMap().set("underscore", VK_OEM_MINUS);
159 windowsKeyMap().set("equal", VK_OEM_PLUS);
160 windowsKeyMap().set("plus", VK_OEM_PLUS);
162 // Set F_XX keys to the windowsKeyMap.
163 for (unsigned int i = 1; i < 25; i++) {
164 String key = "F" + String::number(i);
165 windowsKeyMap().set(key, VK_F1 + i);
169 String keyIdentifierForEvasKeyName(String& keyName)
171 if (keyMap().isEmpty())
174 if (keyMap().contains(keyName))
175 return keyMap().get(keyName);
180 int windowsKeyCodeForEvasKeyName(String& keyName)
182 if (windowsKeyMap().isEmpty())
183 createWindowsKeyMap();
185 if (windowsKeyMap().contains(keyName))
186 return windowsKeyMap().get(keyName);
191 } // namespace WebCore