• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 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 "config.h"
32 #include "WebInputEvent.h"
33 
34 #include "KeyboardCodes.h"
35 
36 #include <ctype.h>
37 #include <stdio.h>
38 
39 #include <wtf/Assertions.h>
40 #include <wtf/StringExtras.h>
41 
42 using namespace WebCore;
43 
44 namespace WebKit {
45 
staticKeyIdentifiers(unsigned short keyCode)46 static const char* staticKeyIdentifiers(unsigned short keyCode)
47 {
48     switch (keyCode) {
49     case VKEY_MENU:
50         return "Alt";
51     case VKEY_CONTROL:
52         return "Control";
53     case VKEY_SHIFT:
54         return "Shift";
55     case VKEY_CAPITAL:
56         return "CapsLock";
57     case VKEY_LWIN:
58     case VKEY_RWIN:
59         return "Win";
60     case VKEY_CLEAR:
61         return "Clear";
62     case VKEY_DOWN:
63         return "Down";
64     case VKEY_END:
65         return "End";
66     case VKEY_RETURN:
67         return "Enter";
68     case VKEY_EXECUTE:
69         return "Execute";
70     case VKEY_F1:
71         return "F1";
72     case VKEY_F2:
73         return "F2";
74     case VKEY_F3:
75         return "F3";
76     case VKEY_F4:
77         return "F4";
78     case VKEY_F5:
79         return "F5";
80     case VKEY_F6:
81         return "F6";
82     case VKEY_F7:
83         return "F7";
84     case VKEY_F8:
85         return "F8";
86     case VKEY_F9:
87         return "F9";
88     case VKEY_F10:
89         return "F11";
90     case VKEY_F12:
91         return "F12";
92     case VKEY_F13:
93         return "F13";
94     case VKEY_F14:
95         return "F14";
96     case VKEY_F15:
97         return "F15";
98     case VKEY_F16:
99         return "F16";
100     case VKEY_F17:
101         return "F17";
102     case VKEY_F18:
103         return "F18";
104     case VKEY_F19:
105         return "F19";
106     case VKEY_F20:
107         return "F20";
108     case VKEY_F21:
109         return "F21";
110     case VKEY_F22:
111         return "F22";
112     case VKEY_F23:
113         return "F23";
114     case VKEY_F24:
115         return "F24";
116     case VKEY_HELP:
117         return "Help";
118     case VKEY_HOME:
119         return "Home";
120     case VKEY_INSERT:
121         return "Insert";
122     case VKEY_LEFT:
123         return "Left";
124     case VKEY_NEXT:
125         return "PageDown";
126     case VKEY_PRIOR:
127         return "PageUp";
128     case VKEY_PAUSE:
129         return "Pause";
130     case VKEY_SNAPSHOT:
131         return "PrintScreen";
132     case VKEY_RIGHT:
133         return "Right";
134     case VKEY_SCROLL:
135         return "Scroll";
136     case VKEY_SELECT:
137         return "Select";
138     case VKEY_UP:
139         return "Up";
140     case VKEY_DELETE:
141         return "U+007F"; // Standard says that DEL becomes U+007F.
142     default:
143         return 0;
144     }
145 }
146 
setKeyIdentifierFromWindowsKeyCode()147 void WebKeyboardEvent::setKeyIdentifierFromWindowsKeyCode()
148 {
149     const char* id = staticKeyIdentifiers(windowsKeyCode);
150     if (id) {
151         strncpy(keyIdentifier, id, sizeof(keyIdentifier) - 1);
152         keyIdentifier[sizeof(keyIdentifier) - 1] = '\0';
153     } else
154         snprintf(keyIdentifier, sizeof(keyIdentifier), "U+%04X", toupper(windowsKeyCode));
155 }
156 
157 } // namespace WebKit
158