summaryrefslogtreecommitdiff
path: root/chromium/third_party/WebKit/Source/testing/runner/KeyCodeMapping.cpp
blob: 3fb4ece0528237851802552c6ea35655ffd32a70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/*
 * Copyright (C) 2012 Google Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 *     * Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above
 * copyright notice, this list of conditions and the following disclaimer
 * in the documentation and/or other materials provided with the
 * distribution.
 *     * Neither the name of Google Inc. nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include "KeyCodeMapping.h"

#include "TestCommon.h"

namespace WebTestRunner {

int NativeKeyCodeForWindowsKeyCode(int keysym)
{
#if defined(__linux__) && defined(TOOLKIT_GTK)
    // See /usr/share/X11/xkb/keycodes/*
    static const int asciiToKeyCode[] = {
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        22,
        23,
        0,
        0,
        0,
        36,
        0,
        0,
        50,
        37,
        64,
        127,
        66,
        0,
        0,
        0,
        0,
        131,
        0,
        9,
        100,
        102,
        0,
        0,
        65, // ' '
        112, // '!'
        117, // '"'
        115, // '#'
        110, // '$'
        113, // '%'
        111, // '&'
        114, // '''
        116, // '('
        0, // ')'
        107, // '*'
        0, // '+'
        0, // ','
        118, // '-'
        119, // '.'
        146, // '/'
        19, // '0'
        10, // '1'
        11, // '2'
        12, // '3'
        13, // '4'
        14, // '5'
        15, // '6'
        16, // '7'
        17, // '8'
        18, // '9'
        0, // ':'
        0, // ';'
        0, // '<'
        0, // '='
        0, // '>'
        0, // '?'
        0, // '@'
        38, // 'A'
        56, // 'B'
        54, // 'C'
        40, // 'D'
        26, // 'E'
        41, // 'F'
        42, // 'G'
        43, // 'H'
        31, // 'I'
        44, // 'J'
        45, // 'K'
        46, // 'L'
        58, // 'M'
        57, // 'N'
        32, // 'O'
        33, // 'P'
        24, // 'Q'
        27, // 'R'
        39, // 'S'
        28, // 'T'
        30, // 'U'
        55, // 'V'
        25, // 'W'
        53, // 'X'
        29, // 'Y'
        52, // 'Z'
        133, // '['
        134, // '\'
        135, // ']'
        0, // '^'
        0, // '_'
        90, // '`'
        38, // 'a'
        56, // 'b'
        54, // 'c'
        40, // 'd'
        26, // 'e'
        41, // 'f'
        42, // 'g'
        43, // 'h'
        31, // 'i'
        44, // 'j'
        45, // 'k'
        46, // 'l'
        58, // 'm'
        57, // 'n'
        32, // 'o'
        33, // 'p'
        24, // 'q'
        27, // 'r'
        39, // 's'
        28, // 't'
        30, // 'u'
        55, // 'v'
        25, // 'w'
        53, // 'x'
        29, // 'y'
        52, // 'z'
        96, // '{'
        0, // '|'
        0, // '}'
        0, // '~'
        0, // DEL
    };

    if (keysym <= 127)
        return asciiToKeyCode[keysym];

    switch (keysym) {
    case VKEY_PRIOR:
        return 112;
    case VKEY_NEXT:
        return 117;
    case VKEY_END:
        return 115;
    case VKEY_HOME:
        return 110;
    case VKEY_LEFT:
        return 113;
    case VKEY_UP:
        return 111;
    case VKEY_RIGHT:
        return 114;
    case VKEY_DOWN:
        return 116;
    case VKEY_SNAPSHOT:
        return 107;
    case VKEY_INSERT:
        return 118;
    case VKEY_DELETE:
        return 119;
    case VKEY_APPS:
        return 135;
    case VKEY_F1:
    case VKEY_F1 + 1:
    case VKEY_F1 + 2:
    case VKEY_F1 + 3:
    case VKEY_F1 + 4:
    case VKEY_F1 + 5:
    case VKEY_F1 + 6:
    case VKEY_F1 + 7:
    case VKEY_F1 + 8:
    case VKEY_F1 + 9:
    case VKEY_F1 + 10:
    case VKEY_F1 + 11:
    case VKEY_F1 + 12:
    case VKEY_F1 + 13:
    case VKEY_F1 + 14:
    case VKEY_F1 + 15:
    case VKEY_F1 + 16:
    case VKEY_F1 + 17:
    case VKEY_F1 + 18:
    case VKEY_F1 + 19:
    case VKEY_F1 + 20:
    case VKEY_F1 + 21:
    case VKEY_F1 + 22:
    case VKEY_F1 + 23:
        return 67 + (keysym - VKEY_F1);
    case VKEY_LSHIFT:
        return 50;
    case VKEY_RSHIFT:
        return 62;
    case VKEY_LCONTROL:
        return 37;
    case VKEY_RCONTROL:
        return 105;
    case VKEY_LMENU:
        return 64;
    case VKEY_RMENU:
        return 108;
    case VKEY_NUMLOCK:
        return 77;

    default:
        return 0;
    }
#else
    return keysym - keysym;
#endif
}

}