Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / native_client_sdk / src / libraries / ppapi_simple / ps_event.h
blob7c2f0d4db0c48990b9fada820c467600c1f017fb
1 /* Copyright 2013 The Chromium Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file. */
5 #ifndef PPAPI_SIMPLE_PS_EVENT_H_
6 #define PPAPI_SIMPLE_PS_EVENT_H_
8 #include "ppapi/c/pp_bool.h"
9 #include "ppapi/c/pp_resource.h"
10 #include "ppapi/c/pp_var.h"
12 #include "sdk_util/macros.h"
14 EXTERN_C_BEGIN
16 /**
17 * PSEvent
19 * The PSEvent system provides an in-order event processing mechanism.
20 * As Pepper events such as input, or focus and view changes arrive on the
21 * main pepper thread, they are placed on various FIFOs based on event type.
22 * For any given event type, only a single thread will process those events.
24 * By default, the "EventThread" will receive all messages. However any thread
25 * can call PSRequestEventsType to request that all new events of that type
26 * are placed on that particular thread's queue.
28 * This allows the developer to choose which threads handle which event types
29 * while keeping all events belonging to a particular thread in order. This
30 * is useful, for example, in the case of graphics to synchronize the size
31 * of the graphics context, with mouse clicks to correctly interpret location.
35 typedef enum {
36 /* Mask off all events. */
37 PSE_NONE = 0,
39 /* From HandleInputEvent, conatins an input resource. */
40 PSE_INSTANCE_HANDLEINPUT = 1,
42 /* From HandleMessage, contains a PP_Var. */
43 PSE_INSTANCE_HANDLEMESSAGE = 2,
45 /* From DidChangeView, contains a view resource */
46 PSE_INSTANCE_DIDCHANGEVIEW = 4,
48 /* From DidChangeFocus, contains a PP_Bool with the current focus state. */
49 PSE_INSTANCE_DIDCHANGEFOCUS = 8,
51 /* When the 3D context is lost, no resource. */
52 PSE_GRAPHICS3D_GRAPHICS3DCONTEXTLOST = 16,
54 /* When the mouse lock is lost. */
55 PSE_MOUSELOCK_MOUSELOCKLOST = 32,
57 /* Enable all events. */
58 PSE_ALL = -1,
59 } PSEventType;
61 typedef uint32_t PSEventTypeMask;
63 // Generic Event
64 typedef struct PSEvent {
65 PSEventType type;
66 union {
67 PP_Bool as_bool;
68 PP_Resource as_resource;
69 struct PP_Var as_var;
72 /* Internal */
73 struct PSEvent* next;
74 } PSEvent;
76 typedef void (*PSMessageHandler_t)(struct PP_Var key,
77 struct PP_Var value,
78 void* user_data);
80 /**
81 * Function for queuing, acquiring, and releasing events.
83 PSEvent* PSEventTryAcquire();
84 PSEvent* PSEventWaitAcquire();
85 void PSEventRelease(PSEvent* event);
86 void PSEventSetFilter(PSEventTypeMask mask);
88 /**
89 * Creates and adds an event of the specified type to the event queue if
90 * that event type is not currently filtered.
92 void PSEventPost(PSEventType type);
93 void PSEventPostBool(PSEventType type, PP_Bool state);
94 void PSEventPostVar(PSEventType type, struct PP_Var var);
95 void PSEventPostResource(PSEventType type, PP_Resource resource);
98 /* Register a message handler for messages that arrive from JavaScript with a
99 * give names.
100 * Messages are of the form: { message_name : <value> }.
102 * PSInstance will then not generate events but instead cause the handler to be
103 * called upon message arrival. If handler is NULL then the current handler
104 * will be removed. Example usage:
106 * JavaScript:
107 * nacl_module.postMessage({'foo': 123});
109 * C:
110 * void MyMessageHandler(struct PP_Var key,
111 * struct PP_Var value,
112 * void* user_data) {
113 * assert(key.type == PP_VARTYPE_STRING);
114 * assert(value.type == PP_VARTYPE_INT32));
115 * assert(value.value.as_int == 123);
117 * ...
118 * PSInstanceRegisterMessageHandler("foo", &MyMessageHandler, NULL); */
119 void PSEventRegisterMessageHandler(const char* message_name,
120 PSMessageHandler_t handler,
121 void* user_data);
123 EXTERN_C_END
125 #endif /* PPAPI_SIMPLE_PS_EVENT_H_ */