Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / web / WebInputEvent.cpp
blobbd556fbb339433d2f115364452bb260919dd4e2c
1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
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.
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.
31 #include "config.h"
32 #include "public/web/WebInputEvent.h"
34 #include "platform/KeyboardCodes.h"
35 #include "wtf/Assertions.h"
36 #include "wtf/StringExtras.h"
37 #include <ctype.h>
39 namespace blink {
41 struct SameSizeAsWebInputEvent {
42 int inputData[5];
45 struct SameSizeAsWebKeyboardEvent : public SameSizeAsWebInputEvent {
46 int keyboardData[14];
49 struct SameSizeAsWebMouseEvent : public SameSizeAsWebInputEvent {
50 int mouseData[15];
53 struct SameSizeAsWebMouseWheelEvent : public SameSizeAsWebMouseEvent {
54 int mousewheelData[12];
57 struct SameSizeAsWebGestureEvent : public SameSizeAsWebInputEvent {
58 int gestureData[11];
61 struct SameSizeAsWebTouchEvent : public SameSizeAsWebInputEvent {
62 WebTouchPoint touchPoints[WebTouchEvent::touchesLengthCap];
63 int touchData[3];
66 static_assert(sizeof(WebInputEvent) == sizeof(SameSizeAsWebInputEvent), "WebInputEvent should not have gaps");
67 static_assert(sizeof(WebKeyboardEvent) == sizeof(SameSizeAsWebKeyboardEvent), "WebKeyboardEvent should not have gaps");
68 static_assert(sizeof(WebMouseEvent) == sizeof(SameSizeAsWebMouseEvent), "WebMouseEvent should not have gaps");
69 static_assert(sizeof(WebMouseWheelEvent) == sizeof(SameSizeAsWebMouseWheelEvent), "WebMouseWheelEvent should not have gaps");
70 static_assert(sizeof(WebGestureEvent) == sizeof(SameSizeAsWebGestureEvent), "WebGestureEvent should not have gaps");
71 static_assert(sizeof(WebTouchEvent) == sizeof(SameSizeAsWebTouchEvent), "WebTouchEvent should not have gaps");
73 static const char* staticKeyIdentifiers(unsigned short keyCode)
75 switch (keyCode) {
76 case VKEY_MENU:
77 return "Alt";
78 case VKEY_CONTROL:
79 return "Control";
80 case VKEY_SHIFT:
81 return "Shift";
82 case VKEY_CAPITAL:
83 return "CapsLock";
84 case VKEY_LWIN:
85 case VKEY_RWIN:
86 return "Win";
87 case VKEY_CLEAR:
88 return "Clear";
89 case VKEY_DOWN:
90 return "Down";
91 case VKEY_END:
92 return "End";
93 case 0x0A: // Carriage return
94 case VKEY_RETURN:
95 return "Enter";
96 case VKEY_EXECUTE:
97 return "Execute";
98 case VKEY_F1:
99 return "F1";
100 case VKEY_F2:
101 return "F2";
102 case VKEY_F3:
103 return "F3";
104 case VKEY_F4:
105 return "F4";
106 case VKEY_F5:
107 return "F5";
108 case VKEY_F6:
109 return "F6";
110 case VKEY_F7:
111 return "F7";
112 case VKEY_F8:
113 return "F8";
114 case VKEY_F9:
115 return "F9";
116 case VKEY_F10:
117 return "F10";
118 case VKEY_F11:
119 return "F11";
120 case VKEY_F12:
121 return "F12";
122 case VKEY_F13:
123 return "F13";
124 case VKEY_F14:
125 return "F14";
126 case VKEY_F15:
127 return "F15";
128 case VKEY_F16:
129 return "F16";
130 case VKEY_F17:
131 return "F17";
132 case VKEY_F18:
133 return "F18";
134 case VKEY_F19:
135 return "F19";
136 case VKEY_F20:
137 return "F20";
138 case VKEY_F21:
139 return "F21";
140 case VKEY_F22:
141 return "F22";
142 case VKEY_F23:
143 return "F23";
144 case VKEY_F24:
145 return "F24";
146 case VKEY_HELP:
147 return "Help";
148 case VKEY_HOME:
149 return "Home";
150 case VKEY_INSERT:
151 return "Insert";
152 case VKEY_LEFT:
153 return "Left";
154 case VKEY_NEXT:
155 return "PageDown";
156 case VKEY_PRIOR:
157 return "PageUp";
158 case VKEY_PAUSE:
159 return "Pause";
160 case VKEY_SNAPSHOT:
161 return "PrintScreen";
162 case VKEY_RIGHT:
163 return "Right";
164 case VKEY_SCROLL:
165 return "Scroll";
166 case VKEY_SELECT:
167 return "Select";
168 case VKEY_UP:
169 return "Up";
170 case VKEY_DELETE:
171 return "U+007F"; // Standard says that DEL becomes U+007F.
172 case VKEY_MEDIA_NEXT_TRACK:
173 return "MediaNextTrack";
174 case VKEY_MEDIA_PREV_TRACK:
175 return "MediaPreviousTrack";
176 case VKEY_MEDIA_STOP:
177 return "MediaStop";
178 case VKEY_MEDIA_PLAY_PAUSE:
179 return "MediaPlayPause";
180 case VKEY_VOLUME_MUTE:
181 return "VolumeMute";
182 case VKEY_VOLUME_DOWN:
183 return "VolumeDown";
184 case VKEY_VOLUME_UP:
185 return "VolumeUp";
186 default:
187 return 0;
191 void WebKeyboardEvent::setKeyIdentifierFromWindowsKeyCode()
193 const char* id = staticKeyIdentifiers(windowsKeyCode);
194 if (id) {
195 strncpy(keyIdentifier, id, sizeof(keyIdentifier) - 1);
196 keyIdentifier[sizeof(keyIdentifier) - 1] = '\0';
197 } else
198 snprintf(keyIdentifier, sizeof(keyIdentifier), "U+%04X", toupper(windowsKeyCode));
201 } // namespace blink