1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "KeyCodeMapping.h"
32
33 #include "TestCommon.h"
34
35 namespace WebTestRunner {
36
NativeKeyCodeForWindowsKeyCode(int keysym)37 int NativeKeyCodeForWindowsKeyCode(int keysym)
38 {
39 #if defined(__linux__) && defined(TOOLKIT_GTK)
40 // See /usr/share/X11/xkb/keycodes/*
41 static const int asciiToKeyCode[] = {
42 0,
43 0,
44 0,
45 0,
46 0,
47 0,
48 0,
49 0,
50 22,
51 23,
52 0,
53 0,
54 0,
55 36,
56 0,
57 0,
58 50,
59 37,
60 64,
61 127,
62 66,
63 0,
64 0,
65 0,
66 0,
67 131,
68 0,
69 9,
70 100,
71 102,
72 0,
73 0,
74 65, // ' '
75 112, // '!'
76 117, // '"'
77 115, // '#'
78 110, // '$'
79 113, // '%'
80 111, // '&'
81 114, // '''
82 116, // '('
83 0, // ')'
84 107, // '*'
85 0, // '+'
86 0, // ','
87 118, // '-'
88 119, // '.'
89 146, // '/'
90 19, // '0'
91 10, // '1'
92 11, // '2'
93 12, // '3'
94 13, // '4'
95 14, // '5'
96 15, // '6'
97 16, // '7'
98 17, // '8'
99 18, // '9'
100 0, // ':'
101 0, // ';'
102 0, // '<'
103 0, // '='
104 0, // '>'
105 0, // '?'
106 0, // '@'
107 38, // 'A'
108 56, // 'B'
109 54, // 'C'
110 40, // 'D'
111 26, // 'E'
112 41, // 'F'
113 42, // 'G'
114 43, // 'H'
115 31, // 'I'
116 44, // 'J'
117 45, // 'K'
118 46, // 'L'
119 58, // 'M'
120 57, // 'N'
121 32, // 'O'
122 33, // 'P'
123 24, // 'Q'
124 27, // 'R'
125 39, // 'S'
126 28, // 'T'
127 30, // 'U'
128 55, // 'V'
129 25, // 'W'
130 53, // 'X'
131 29, // 'Y'
132 52, // 'Z'
133 133, // '['
134 134, // '\'
135 135, // ']'
136 0, // '^'
137 0, // '_'
138 90, // '`'
139 38, // 'a'
140 56, // 'b'
141 54, // 'c'
142 40, // 'd'
143 26, // 'e'
144 41, // 'f'
145 42, // 'g'
146 43, // 'h'
147 31, // 'i'
148 44, // 'j'
149 45, // 'k'
150 46, // 'l'
151 58, // 'm'
152 57, // 'n'
153 32, // 'o'
154 33, // 'p'
155 24, // 'q'
156 27, // 'r'
157 39, // 's'
158 28, // 't'
159 30, // 'u'
160 55, // 'v'
161 25, // 'w'
162 53, // 'x'
163 29, // 'y'
164 52, // 'z'
165 96, // '{'
166 0, // '|'
167 0, // '}'
168 0, // '~'
169 0, // DEL
170 };
171
172 if (keysym <= 127)
173 return asciiToKeyCode[keysym];
174
175 switch (keysym) {
176 case VKEY_PRIOR:
177 return 112;
178 case VKEY_NEXT:
179 return 117;
180 case VKEY_END:
181 return 115;
182 case VKEY_HOME:
183 return 110;
184 case VKEY_LEFT:
185 return 113;
186 case VKEY_UP:
187 return 111;
188 case VKEY_RIGHT:
189 return 114;
190 case VKEY_DOWN:
191 return 116;
192 case VKEY_SNAPSHOT:
193 return 107;
194 case VKEY_INSERT:
195 return 118;
196 case VKEY_DELETE:
197 return 119;
198 case VKEY_APPS:
199 return 135;
200 case VKEY_F1:
201 case VKEY_F1 + 1:
202 case VKEY_F1 + 2:
203 case VKEY_F1 + 3:
204 case VKEY_F1 + 4:
205 case VKEY_F1 + 5:
206 case VKEY_F1 + 6:
207 case VKEY_F1 + 7:
208 case VKEY_F1 + 8:
209 case VKEY_F1 + 9:
210 case VKEY_F1 + 10:
211 case VKEY_F1 + 11:
212 case VKEY_F1 + 12:
213 case VKEY_F1 + 13:
214 case VKEY_F1 + 14:
215 case VKEY_F1 + 15:
216 case VKEY_F1 + 16:
217 case VKEY_F1 + 17:
218 case VKEY_F1 + 18:
219 case VKEY_F1 + 19:
220 case VKEY_F1 + 20:
221 case VKEY_F1 + 21:
222 case VKEY_F1 + 22:
223 case VKEY_F1 + 23:
224 return 67 + (keysym - VKEY_F1);
225 case VKEY_LSHIFT:
226 return 50;
227 case VKEY_RSHIFT:
228 return 62;
229 case VKEY_LCONTROL:
230 return 37;
231 case VKEY_RCONTROL:
232 return 105;
233 case VKEY_LMENU:
234 return 64;
235 case VKEY_RMENU:
236 return 108;
237 case VKEY_NUMLOCK:
238 return 77;
239
240 default:
241 return 0;
242 }
243 #else
244 return keysym - keysym;
245 #endif
246 }
247
248 }
249