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

Side by Side Diff: src/trusted/sel_universal/sdl_ppapi_event_translator.cc

Issue 7046064: Some small refactoring and renaming of sel_universel pepper emulation components. (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: '' Created 9 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « src/trusted/sel_universal/primitives_sdl.cc ('k') | src/trusted/sel_universal/sel_universal.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. 2 * Copyright (c) 2011 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6 6
7 // This file provives a utilty function to translate and SDL event structure 7 // This file provives a utilty function to translate and SDL event structure
8 // into a PPAPI event structure. 8 // into a PPAPI event structure.
9 // This is very adhoc and especially the keyboard event part is very 9 // This is very adhoc and especially the keyboard event part is very
10 // incomplete. 10 // incomplete.
11 11
12 #include <stdint.h> 12 #include <stdint.h>
13 #include <SDL/SDL_keysym.h> 13 #include <SDL/SDL_keysym.h>
14 #include <SDL/SDL_events.h> 14 #include <SDL/SDL_events.h>
15 #include "ppapi/c/pp_input_event.h" 15 #include "ppapi/c/pp_input_event.h"
16 16
17 #include "native_client/src/trusted/sel_universal/multimedia.h" 17 #include "native_client/src/trusted/sel_universal/primitives.h"
18
19 const int PP_INPUTEVENT_USER = 88;
20 const int PP_INPUTEVENT_TERMINATION = 90;
21
22 // ppapi does not have a user defined event notion.
23 // c.f. ppapi/c/pp_input_event.h
24 typedef struct {
25 int code;
26 int data1;
27 int data2;
28 } PP_InputEvent_User;
29
30 static PP_InputEvent_User* GetUserEvent(PP_InputEvent* event) {
31 return reinterpret_cast<PP_InputEvent_User*>(&event->u);
32 }
33
34 bool IsInvalidEvent(PP_InputEvent* event) {
35 return event->type == PP_INPUTEVENT_TYPE_UNDEFINED;
36 }
37
38
39 void MakeInvalidEvent(PP_InputEvent* event) {
40 event->type = PP_INPUTEVENT_TYPE_UNDEFINED;
41 }
42
43
44 bool IsTerminationEvent(PP_InputEvent* event) {
45 return event->type == PP_INPUTEVENT_TERMINATION;
46 }
47
48
49 void MakeTerminationEvent(PP_InputEvent* event) {
50 event->type = (PP_InputEvent_Type) PP_INPUTEVENT_TERMINATION;
51 }
52
53
54 bool IsUserEvent(PP_InputEvent* event) {
55 return event->type == PP_INPUTEVENT_USER;
56 }
57
58
59 int GetCodeFromUserEvent(PP_InputEvent* event) {
60 return GetUserEvent(event)->code;
61 }
62
63
64 int GetData1FromUserEvent(PP_InputEvent* event) {
65 return GetUserEvent(event)->data1;
66 }
67
68
69 int GetData2FromUserEvent(PP_InputEvent* event) {
70 return GetUserEvent(event)->data2;
71 }
72
73
74 void MakeUserEvent(PP_InputEvent* event, int code, int data1, int data2) {
75 event->type = (PP_InputEvent_Type) PP_INPUTEVENT_USER;
76 PP_InputEvent_User* user = GetUserEvent(event);
77 user->code = code;
78 user->data1 = data1;
79 user->data2 = data2;
80 }
81
82 18
83 static PP_InputEvent_MouseButton SDLButtonToPPButton(uint32_t button) { 19 static PP_InputEvent_MouseButton SDLButtonToPPButton(uint32_t button) {
84 switch (button) { 20 switch (button) {
85 case SDL_BUTTON_LEFT: 21 case SDL_BUTTON_LEFT:
86 return PP_INPUTEVENT_MOUSEBUTTON_LEFT; 22 return PP_INPUTEVENT_MOUSEBUTTON_LEFT;
87 case SDL_BUTTON_MIDDLE: 23 case SDL_BUTTON_MIDDLE:
88 return PP_INPUTEVENT_MOUSEBUTTON_MIDDLE; 24 return PP_INPUTEVENT_MOUSEBUTTON_MIDDLE;
89 case SDL_BUTTON_RIGHT: 25 case SDL_BUTTON_RIGHT:
90 return PP_INPUTEVENT_MOUSEBUTTON_RIGHT; 26 return PP_INPUTEVENT_MOUSEBUTTON_RIGHT;
91 default: 27 default:
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 pp_event->u.mouse.button = SDLButtonToPPButton(sdl_event.button.button); 164 pp_event->u.mouse.button = SDLButtonToPPButton(sdl_event.button.button);
229 return true; 165 return true;
230 166
231 case SDL_USEREVENT: 167 case SDL_USEREVENT:
232 MakeUserEvent(pp_event, 168 MakeUserEvent(pp_event,
233 sdl_event.user.code, 169 sdl_event.user.code,
234 ptr2int(sdl_event.user.data1), 170 ptr2int(sdl_event.user.data1),
235 ptr2int(sdl_event.user.data2)); 171 ptr2int(sdl_event.user.data2));
236 return true; 172 return true;
237 case SDL_QUIT: 173 case SDL_QUIT:
238 pp_event->type = (PP_InputEvent_Type) PP_INPUTEVENT_TERMINATION; 174 MakeTerminationEvent(pp_event);
239 return true; 175 return true;
240 case SDL_ACTIVEEVENT: 176 case SDL_ACTIVEEVENT:
241 case SDL_SYSWMEVENT: 177 case SDL_SYSWMEVENT:
242 case SDL_VIDEORESIZE: 178 case SDL_VIDEORESIZE:
243 case SDL_VIDEOEXPOSE: 179 case SDL_VIDEOEXPOSE:
244 180
245 case SDL_JOYAXISMOTION: 181 case SDL_JOYAXISMOTION:
246 case SDL_JOYBALLMOTION: 182 case SDL_JOYBALLMOTION:
247 case SDL_JOYHATMOTION: 183 case SDL_JOYHATMOTION:
248 case SDL_JOYBUTTONDOWN: 184 case SDL_JOYBUTTONDOWN:
249 case SDL_JOYBUTTONUP: 185 case SDL_JOYBUTTONUP:
250 186
251 default: 187 default:
252 return false; 188 return false;
253 } 189 }
254 } 190 }
OLDNEW
« no previous file with comments | « src/trusted/sel_universal/primitives_sdl.cc ('k') | src/trusted/sel_universal/sel_universal.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698