Chromium Code Reviews| Index: src/trusted/sel_universal/non_standard_pepper_events.cc |
| =================================================================== |
| --- src/trusted/sel_universal/non_standard_pepper_events.cc (revision 0) |
| +++ src/trusted/sel_universal/non_standard_pepper_events.cc (revision 0) |
| @@ -0,0 +1,78 @@ |
| +/* |
| + * Copyright (c) 2011 The Native Client Authors. All rights reserved. |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| + |
| +// This file provives a utilty function to translate and SDL event structure |
|
Sang Ahn
2011/06/09 20:34:48
s/provives/provides
s/and/an
robertm
2011/06/09 21:02:21
Done.
|
| +// into a PPAPI event structure. |
|
Sang Ahn
2011/06/09 20:34:48
s/into/to
robertm
2011/06/09 21:02:21
Done.
|
| +// This is very adhoc and especially the keyboard event part is very |
| +// incomplete. |
| + |
| +#include <stdint.h> |
| +#include "ppapi/c/pp_input_event.h" |
| + |
| +#include "native_client/src/trusted/sel_universal/primitives.h" |
| + |
| +const int PP_INPUTEVENT_USER = 88; |
| +const int PP_INPUTEVENT_TERMINATION = 90; |
| + |
| +// ppapi does not have a user defined event notion. |
| +// c.f. ppapi/c/pp_input_event.h |
| +typedef struct { |
| + int code; |
| + int data1; |
| + int data2; |
| +} PP_InputEvent_User; |
|
Sang Ahn
2011/06/09 20:34:48
Could this be wrapped to a namespace? It might be
robertm
2011/06/09 21:02:21
excellent idea - done
On 2011/06/09 20:34:48, Sang
|
| + |
| +static PP_InputEvent_User* GetUserEvent(PP_InputEvent* event) { |
| + return reinterpret_cast<PP_InputEvent_User*>(&event->u); |
| +} |
| + |
| +bool IsInvalidEvent(PP_InputEvent* event) { |
| + return event->type == PP_INPUTEVENT_TYPE_UNDEFINED; |
| +} |
| + |
| + |
| +void MakeInvalidEvent(PP_InputEvent* event) { |
| + event->type = PP_INPUTEVENT_TYPE_UNDEFINED; |
| +} |
| + |
| + |
| +bool IsTerminationEvent(PP_InputEvent* event) { |
| + return event->type == PP_INPUTEVENT_TERMINATION; |
| +} |
| + |
| + |
| +void MakeTerminationEvent(PP_InputEvent* event) { |
| + event->type = (PP_InputEvent_Type) PP_INPUTEVENT_TERMINATION; |
| +} |
| + |
| + |
| +bool IsUserEvent(PP_InputEvent* event) { |
| + return event->type == PP_INPUTEVENT_USER; |
| +} |
| + |
| + |
| +int GetCodeFromUserEvent(PP_InputEvent* event) { |
| + return GetUserEvent(event)->code; |
| +} |
| + |
| + |
| +int GetData1FromUserEvent(PP_InputEvent* event) { |
| + return GetUserEvent(event)->data1; |
| +} |
| + |
| + |
| +int GetData2FromUserEvent(PP_InputEvent* event) { |
| + return GetUserEvent(event)->data2; |
| +} |
| + |
| + |
| +void MakeUserEvent(PP_InputEvent* event, int code, int data1, int data2) { |
| + event->type = (PP_InputEvent_Type) PP_INPUTEVENT_USER; |
| + PP_InputEvent_User* user = GetUserEvent(event); |
| + user->code = code; |
| + user->data1 = data1; |
| + user->data2 = data2; |
| +} |