Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(235)

Side by Side Diff: sky/engine/platform/exported/WebInputEvent.cpp

Issue 872233002: Switch KeyboardEvents over to NewEventHandler (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Rename virtualKeyCode to key Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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 "sky/engine/config.h"
32 #include "sky/engine/public/platform/WebInputEvent.h"
33
34 #include <ctype.h>
35 #include "sky/engine/platform/KeyboardCodes.h"
36 #include "sky/engine/wtf/Assertions.h"
37 #include "sky/engine/wtf/StringExtras.h"
38
39 namespace blink {
40
41 struct SameSizeAsWebInputEvent {
42 int inputData[5];
43 };
44
45 struct SameSizeAsWebKeyboardEvent : public SameSizeAsWebInputEvent {
46 int keyboardData[12];
47 };
48
49 struct SameSizeAsWebGestureEvent : public SameSizeAsWebInputEvent {
50 int gestureData[9];
51 };
52
53 COMPILE_ASSERT(sizeof(WebInputEvent) == sizeof(SameSizeAsWebInputEvent), WebInpu tEvent_has_gaps);
54 COMPILE_ASSERT(sizeof(WebKeyboardEvent) == sizeof(SameSizeAsWebKeyboardEvent), W ebKeyboardEvent_has_gaps);
55 COMPILE_ASSERT(sizeof(WebGestureEvent) == sizeof(SameSizeAsWebGestureEvent), Web GestureEvent_has_gaps);
56
57 static const char* staticKeyIdentifiers(unsigned short keyCode)
58 {
59 switch (keyCode) {
60 case VKEY_MENU:
61 return "Alt";
62 case VKEY_CONTROL:
63 return "Control";
64 case VKEY_SHIFT:
65 return "Shift";
66 case VKEY_CAPITAL:
67 return "CapsLock";
68 case VKEY_LWIN:
69 case VKEY_RWIN:
70 return "Win";
71 case VKEY_CLEAR:
72 return "Clear";
73 case VKEY_DOWN:
74 return "Down";
75 case VKEY_END:
76 return "End";
77 case VKEY_RETURN:
78 return "Enter";
79 case VKEY_EXECUTE:
80 return "Execute";
81 case VKEY_F1:
82 return "F1";
83 case VKEY_F2:
84 return "F2";
85 case VKEY_F3:
86 return "F3";
87 case VKEY_F4:
88 return "F4";
89 case VKEY_F5:
90 return "F5";
91 case VKEY_F6:
92 return "F6";
93 case VKEY_F7:
94 return "F7";
95 case VKEY_F8:
96 return "F8";
97 case VKEY_F9:
98 return "F9";
99 case VKEY_F10:
100 return "F10";
101 case VKEY_F11:
102 return "F11";
103 case VKEY_F12:
104 return "F12";
105 case VKEY_F13:
106 return "F13";
107 case VKEY_F14:
108 return "F14";
109 case VKEY_F15:
110 return "F15";
111 case VKEY_F16:
112 return "F16";
113 case VKEY_F17:
114 return "F17";
115 case VKEY_F18:
116 return "F18";
117 case VKEY_F19:
118 return "F19";
119 case VKEY_F20:
120 return "F20";
121 case VKEY_F21:
122 return "F21";
123 case VKEY_F22:
124 return "F22";
125 case VKEY_F23:
126 return "F23";
127 case VKEY_F24:
128 return "F24";
129 case VKEY_HELP:
130 return "Help";
131 case VKEY_HOME:
132 return "Home";
133 case VKEY_INSERT:
134 return "Insert";
135 case VKEY_LEFT:
136 return "Left";
137 case VKEY_NEXT:
138 return "PageDown";
139 case VKEY_PRIOR:
140 return "PageUp";
141 case VKEY_PAUSE:
142 return "Pause";
143 case VKEY_SNAPSHOT:
144 return "PrintScreen";
145 case VKEY_RIGHT:
146 return "Right";
147 case VKEY_SCROLL:
148 return "Scroll";
149 case VKEY_SELECT:
150 return "Select";
151 case VKEY_UP:
152 return "Up";
153 case VKEY_DELETE:
154 return "U+007F"; // Standard says that DEL becomes U+007F.
155 case VKEY_MEDIA_NEXT_TRACK:
156 return "MediaNextTrack";
157 case VKEY_MEDIA_PREV_TRACK:
158 return "MediaPreviousTrack";
159 case VKEY_MEDIA_STOP:
160 return "MediaStop";
161 case VKEY_MEDIA_PLAY_PAUSE:
162 return "MediaPlayPause";
163 case VKEY_VOLUME_MUTE:
164 return "VolumeMute";
165 case VKEY_VOLUME_DOWN:
166 return "VolumeDown";
167 case VKEY_VOLUME_UP:
168 return "VolumeUp";
169 default:
170 return 0;
171 }
172 }
173
174 void WebKeyboardEvent::setKeyIdentifierFromWindowsKeyCode()
175 {
176 const char* id = staticKeyIdentifiers(windowsKeyCode);
177 if (id) {
178 strncpy(keyIdentifier, id, sizeof(keyIdentifier) - 1);
179 keyIdentifier[sizeof(keyIdentifier) - 1] = '\0';
180 } else
181 snprintf(keyIdentifier, sizeof(keyIdentifier), "U+%04X", toupper(windows KeyCode));
182 }
183
184 // static
185 int WebKeyboardEvent::windowsKeyCodeWithoutLocation(int keycode)
186 {
187 switch (keycode) {
188 case VK_LCONTROL:
189 case VK_RCONTROL:
190 return VK_CONTROL;
191 case VK_LSHIFT:
192 case VK_RSHIFT:
193 return VK_SHIFT;
194 case VK_LMENU:
195 case VK_RMENU:
196 return VK_MENU;
197 default:
198 return keycode;
199 }
200 }
201
202 // static
203 int WebKeyboardEvent::locationModifiersFromWindowsKeyCode(int keycode)
204 {
205 switch (keycode) {
206 case VK_LCONTROL:
207 case VK_LSHIFT:
208 case VK_LMENU:
209 case VK_LWIN:
210 return IsLeft;
211 case VK_RCONTROL:
212 case VK_RSHIFT:
213 case VK_RMENU:
214 case VK_RWIN:
215 return IsRight;
216 default:
217 return 0;
218 }
219 }
220
221 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/platform/PlatformKeyboardEvent.cpp ('k') | sky/engine/public/platform/WebInputEvent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698