OLD | NEW |
1 /* Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 /* Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 * Use of this source code is governed by a BSD-style license that can be | 2 * Use of this source code is governed by a BSD-style license that can be |
3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
4 */ | 4 */ |
5 #ifndef PPAPI_C_PP_INPUT_EVENT_H_ | 5 #ifndef PPAPI_C_PP_INPUT_EVENT_H_ |
6 #define PPAPI_C_PP_INPUT_EVENT_H_ | 6 #define PPAPI_C_PP_INPUT_EVENT_H_ |
7 | 7 |
8 /** | 8 /** |
9 * @file | 9 * @file |
10 * Defines the API ... | 10 * This file defines the API used to handle mouse and keyboard input events. |
11 */ | 11 */ |
12 | 12 |
13 #include "ppapi/c/pp_bool.h" | 13 #include "ppapi/c/pp_bool.h" |
14 #include "ppapi/c/pp_macros.h" | 14 #include "ppapi/c/pp_macros.h" |
15 #include "ppapi/c/pp_stdint.h" | 15 #include "ppapi/c/pp_stdint.h" |
16 #include "ppapi/c/pp_time.h" | 16 #include "ppapi/c/pp_time.h" |
17 | 17 |
18 /** | 18 /** |
19 * | 19 * |
20 * @addtogroup Enums | 20 * @addtogroup Enums |
21 * @{ | 21 * @{ |
22 */ | 22 */ |
| 23 |
| 24 /** |
| 25 * This enumeration contains constants representing each mouse button. |
| 26 */ |
23 typedef enum { | 27 typedef enum { |
24 PP_INPUTEVENT_MOUSEBUTTON_NONE = -1, | 28 PP_INPUTEVENT_MOUSEBUTTON_NONE = -1, |
25 PP_INPUTEVENT_MOUSEBUTTON_LEFT = 0, | 29 PP_INPUTEVENT_MOUSEBUTTON_LEFT = 0, |
26 PP_INPUTEVENT_MOUSEBUTTON_MIDDLE = 1, | 30 PP_INPUTEVENT_MOUSEBUTTON_MIDDLE = 1, |
27 PP_INPUTEVENT_MOUSEBUTTON_RIGHT = 2 | 31 PP_INPUTEVENT_MOUSEBUTTON_RIGHT = 2 |
28 } PP_InputEvent_MouseButton; | 32 } PP_InputEvent_MouseButton; |
29 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_InputEvent_MouseButton, 4); | 33 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_InputEvent_MouseButton, 4); |
30 /** | 34 /** |
31 * @} | 35 * @} |
32 */ | 36 */ |
33 | 37 |
34 /** | 38 /** |
35 * | |
36 * @addtogroup Enums | 39 * @addtogroup Enums |
37 * @{ | 40 * @{ |
38 */ | 41 */ |
| 42 |
| 43 /** |
| 44 * This enumeration contains mouse and keyboard event constants. |
| 45 */ |
39 typedef enum { | 46 typedef enum { |
40 PP_INPUTEVENT_TYPE_UNDEFINED = -1, | 47 PP_INPUTEVENT_TYPE_UNDEFINED = -1, |
41 PP_INPUTEVENT_TYPE_MOUSEDOWN = 0, // PP_InputEvent_Mouse | 48 PP_INPUTEVENT_TYPE_MOUSEDOWN = 0, // PP_InputEvent_Mouse |
42 PP_INPUTEVENT_TYPE_MOUSEUP = 1, // PP_InputEvent_Mouse | 49 PP_INPUTEVENT_TYPE_MOUSEUP = 1, // PP_InputEvent_Mouse |
43 PP_INPUTEVENT_TYPE_MOUSEMOVE = 2, // PP_InputEvent_Mouse | 50 PP_INPUTEVENT_TYPE_MOUSEMOVE = 2, // PP_InputEvent_Mouse |
44 PP_INPUTEVENT_TYPE_MOUSEENTER = 3, // PP_InputEvent_Mouse | 51 PP_INPUTEVENT_TYPE_MOUSEENTER = 3, // PP_InputEvent_Mouse |
45 PP_INPUTEVENT_TYPE_MOUSELEAVE = 4, // PP_InputEvent_Mouse | 52 PP_INPUTEVENT_TYPE_MOUSELEAVE = 4, // PP_InputEvent_Mouse |
46 PP_INPUTEVENT_TYPE_MOUSEWHEEL = 5, // PP_InputEvent_Wheel | 53 PP_INPUTEVENT_TYPE_MOUSEWHEEL = 5, // PP_InputEvent_Wheel |
47 PP_INPUTEVENT_TYPE_RAWKEYDOWN = 6, // PP_InputEvent_Key | 54 PP_INPUTEVENT_TYPE_RAWKEYDOWN = 6, // PP_InputEvent_Key |
48 PP_INPUTEVENT_TYPE_KEYDOWN = 7, // PP_InputEvent_Key | 55 PP_INPUTEVENT_TYPE_KEYDOWN = 7, // PP_InputEvent_Key |
49 PP_INPUTEVENT_TYPE_KEYUP = 8, // PP_InputEvent_Key | 56 PP_INPUTEVENT_TYPE_KEYUP = 8, // PP_InputEvent_Key |
50 PP_INPUTEVENT_TYPE_CHAR = 9, // PP_InputEvent_Character | 57 PP_INPUTEVENT_TYPE_CHAR = 9, // PP_InputEvent_Character |
51 PP_INPUTEVENT_TYPE_CONTEXTMENU = 10 // PP_InputEvent_Mouse | 58 PP_INPUTEVENT_TYPE_CONTEXTMENU = 10 // PP_InputEvent_Mouse |
52 } PP_InputEvent_Type; | 59 } PP_InputEvent_Type; |
53 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_InputEvent_Type, 4); | 60 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_InputEvent_Type, 4); |
54 /** | 61 /** |
55 * @} | 62 * @} |
56 */ | 63 */ |
57 | 64 |
58 /** | 65 /** |
59 * | |
60 * @addtogroup Enums | 66 * @addtogroup Enums |
61 * @{ | 67 * @{ |
62 */ | 68 */ |
| 69 |
| 70 /** |
| 71 * This enumeration contains event modifier constants. |
| 72 */ |
63 typedef enum { | 73 typedef enum { |
64 PP_INPUTEVENT_MODIFIER_SHIFTKEY = 1 << 0, | 74 PP_INPUTEVENT_MODIFIER_SHIFTKEY = 1 << 0, |
65 PP_INPUTEVENT_MODIFIER_CONTROLKEY = 1 << 1, | 75 PP_INPUTEVENT_MODIFIER_CONTROLKEY = 1 << 1, |
66 PP_INPUTEVENT_MODIFIER_ALTKEY = 1 << 2, | 76 PP_INPUTEVENT_MODIFIER_ALTKEY = 1 << 2, |
67 PP_INPUTEVENT_MODIFIER_METAKEY = 1 << 3, | 77 PP_INPUTEVENT_MODIFIER_METAKEY = 1 << 3, |
68 PP_INPUTEVENT_MODIFIER_ISKEYPAD = 1 << 4, | 78 PP_INPUTEVENT_MODIFIER_ISKEYPAD = 1 << 4, |
69 PP_INPUTEVENT_MODIFIER_ISAUTOREPEAT = 1 << 5, | 79 PP_INPUTEVENT_MODIFIER_ISAUTOREPEAT = 1 << 5, |
70 PP_INPUTEVENT_MODIFIER_LEFTBUTTONDOWN = 1 << 6, | 80 PP_INPUTEVENT_MODIFIER_LEFTBUTTONDOWN = 1 << 6, |
71 PP_INPUTEVENT_MODIFIER_MIDDLEBUTTONDOWN = 1 << 7, | 81 PP_INPUTEVENT_MODIFIER_MIDDLEBUTTONDOWN = 1 << 7, |
72 PP_INPUTEVENT_MODIFIER_RIGHTBUTTONDOWN = 1 << 8, | 82 PP_INPUTEVENT_MODIFIER_RIGHTBUTTONDOWN = 1 << 8, |
73 PP_INPUTEVENT_MODIFIER_CAPSLOCKKEY = 1 << 9, | 83 PP_INPUTEVENT_MODIFIER_CAPSLOCKKEY = 1 << 9, |
74 PP_INPUTEVENT_MODIFIER_NUMLOCKKEY = 1 << 10 | 84 PP_INPUTEVENT_MODIFIER_NUMLOCKKEY = 1 << 10 |
75 } PP_InputEvent_Modifier; | 85 } PP_InputEvent_Modifier; |
76 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_InputEvent_Modifier, 4); | 86 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_InputEvent_Modifier, 4); |
77 /** | 87 /** |
78 * @} | 88 * @} |
79 */ | 89 */ |
80 | 90 |
81 /** | 91 /** |
82 * @addtogroup Structs | 92 * @addtogroup Structs |
83 * @{ | 93 * @{ |
84 */ | 94 */ |
85 | 95 |
86 /** | 96 /** |
87 * An event representing a key up or down event. | 97 * The PP_InputEvent_Key struct represents a key up or key down event. |
88 * | 98 * |
89 * Key up and down events correspond to physical keys on the keyboard. The | 99 * Key up and key down events correspond to physical keys on the keyboard. The |
90 * actual character that the user typed (if any) will be delivered in a | 100 * actual character that the user typed (if any) will be delivered in a |
91 * "character" event. | 101 * "character" event. |
92 * | 102 * |
93 * If the user kills focus on the plugin while a key is down, you may not get | 103 * If the user loses focus on the module while a key is down, a key up |
94 * a key up event. For example, if the plugin has focus and the user presses | 104 * event might not occur. For example, if the module has focus and the user |
95 * and holds shift, the plugin will see a "shift down" message. Then if they | 105 * presses and holds the shift key, the module will see a "shift down" message. |
96 * click elsewhere on the web page, the plugin focus will be lost and no more | 106 * Then if the user clicks elsewhere on the web page, the module's focus will |
97 * input events will be delivered. If you depend on getting key up events, you | 107 * be lost and no more input events will be delivered. |
98 * will also want to handle "lost focus" as the equivalent of "all keys up." | |
99 * | 108 * |
| 109 * If your module depends on receiving key up events, it should also handle |
| 110 * "lost focus" as the equivalent of "all keys up." |
100 */ | 111 */ |
101 struct PP_InputEvent_Key { | 112 struct PP_InputEvent_Key { |
102 /** A combination of the EVENT_MODIFIER flags. */ | 113 /** This value is a bit field combination of the EVENT_MODIFIER flags. */ |
103 uint32_t modifier; | 114 uint32_t modifier; |
104 | 115 |
105 /** | 116 /** |
106 * The key code. | 117 * The key code. |
107 * | 118 * |
108 * TODO(brettw) define what these actually are. | 119 * TODO(brettw) define what these actually are. |
109 */ | 120 */ |
110 uint32_t key_code; | 121 uint32_t key_code; |
111 }; | 122 }; |
112 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_InputEvent_Key, 8); | 123 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_InputEvent_Key, 8); |
113 /** | 124 /** |
114 * @} | 125 * @} |
115 */ | 126 */ |
116 | 127 |
117 /** | 128 /** |
118 * @addtogroup Structs | 129 * @addtogroup Structs |
119 * @{ | 130 * @{ |
120 */ | 131 */ |
121 | 132 |
122 /** | 133 /** |
123 * An event representing a typed character. | 134 * The PP_InputEvent_Character struct represents a typed character event. |
124 * | 135 * |
125 * Normally, the program will receive a key down event, followed by a character | 136 * Normally, the program will receive a key down event, followed by a character |
126 * event, followed by a key up event. The character event will have any | 137 * event, followed by a key up event. The character event will have any |
127 * modifier keys applied. Obvious examples are symbols, where Shift-5 gives you | 138 * modifier keys applied. Obvious examples are symbols, where Shift-5 gives you |
128 * a '%'. The key down and up events will give you the scan code for the "5" | 139 * a '%'. The key down and up events will give you the scan code for the "5" |
129 * key, and the character event will give you the '%' character. | 140 * key, and the character event will give you the '%' character. |
130 * | 141 * |
131 * You may not get a character event for all key down if the key doesn't | 142 * You may not get a character event for all key down events if the key doesn't |
132 * generate a character. Likewise, you may actually get multiple character | 143 * generate a character. Likewise, you may actually get multiple character |
133 * events in a row. For example, some locales have an accent key that modifies | 144 * events in a row. For example, some locales have an accent key that modifies |
134 * the next character typed. You might get this stream of events: accent down, | 145 * the next character typed. You might get this stream of events: accent down, |
135 * accent up (it didn't generate a character), letter key down, letter with | 146 * accent up (it didn't generate a character), letter key down, letter with |
136 * accent character event (it was modified by the previous accent key), letter | 147 * accent character event (it was modified by the previous accent key), letter |
137 * key up. If the letter can't be combined with the accent, like an umlaut and | 148 * key up. If the letter can't be combined with the accent, like an umlaut and |
138 * an 'R', the system might send unlaut down, umlaut up, 'R' key down, umlaut | 149 * an 'R', the system might send unlaut down, umlaut up, 'R' key down, umlaut |
139 * character ("whoops, I can't combine it with 'R', I better just send the raw | 150 * character (can't combine it with 'R', so just send the raw unlaut so it |
140 * unlaut so it isn't lost"), 'R' character event, 'R' key up. | 151 * isn't lost"), 'R' character event, 'R' key up. |
141 * | |
142 */ | 152 */ |
143 struct PP_InputEvent_Character { | 153 struct PP_InputEvent_Character { |
144 /** A combination of the EVENT_MODIFIER flags. */ | 154 /** A combination of the EVENT_MODIFIER flags. */ |
145 uint32_t modifier; | 155 uint32_t modifier; |
146 | 156 |
147 /** | 157 /** |
148 * The character the user typed, as a single null-terminated UTF-8 character. | 158 * This value represents the typed character as a single null-terminated UTF-8 |
149 * Any unused bytes will be filled with null bytes. Since the maximum UTF-8 | 159 * character. Any unused bytes will be filled with null bytes. Since the |
150 * character is 4 bytes, there will always be at least one null at the end | 160 * maximum UTF-8 character is 4 bytes, there will always be at least one null |
151 * so you can treat this as a null-termianted UTF-8 string. | 161 * at the end so you can treat this as a null-termianted UTF-8 string. |
152 */ | 162 */ |
153 char text[5]; | 163 char text[5]; |
154 }; | 164 }; |
155 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_InputEvent_Character, 12); | 165 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_InputEvent_Character, 12); |
156 /** | 166 /** |
157 * @} | 167 * @} |
158 */ | 168 */ |
159 | 169 |
160 /** | 170 /** |
161 * @addtogroup Structs | 171 * @addtogroup Structs |
162 * @{ | 172 * @{ |
163 */ | 173 */ |
164 | 174 |
165 /** Represents a mouse event for everything other than the mouse wheel. */ | 175 /** |
| 176 * The PP_InputEvent_Mouse struct represents all mouse events except |
| 177 * mouse wheel events. |
| 178 */ |
166 struct PP_InputEvent_Mouse { | 179 struct PP_InputEvent_Mouse { |
167 /** A combination of the EVENT_MODIFIER flags. */ | 180 /** This value is a bit field combination of the EVENT_MODIFIER flags. */ |
168 uint32_t modifier; | 181 uint32_t modifier; |
169 | 182 |
170 /** | 183 /** |
171 * Which button changed in the case of mouse down or up events. For mouse | 184 * This value represents the button that changed for mouse down or up events. |
172 * move, enter, and leave events, this will be PP_EVENT_MOUSEBUTTON_NONE. | 185 * This value will be PP_EVENT_MOUSEBUTTON_NONE for mouse move, enter, and |
| 186 * leave events. |
173 */ | 187 */ |
174 PP_InputEvent_MouseButton button; | 188 PP_InputEvent_MouseButton button; |
175 | 189 |
176 /** | 190 /** |
177 * The coordinates of the mouse when the event occurred. | 191 * This values represents the x coordinate of the mouse when the event |
| 192 * occurred. |
178 * | 193 * |
179 * In most cases these coordinates will just be integers, but they may not | 194 * In most, but not all, cases these coordinates will just be integers. |
180 * be in some cases. For example, the plugin element might be arbitrarily | 195 * For example, the plugin element might be arbitrarily scaled or transformed |
181 * scaled or transformed in the DOM, and translating a mouse event into the | 196 * in the DOM, and translating a mouse event into the coordinate space of the |
182 * coordinate space of the plugin will give non-integer values. | 197 * plugin will give non-integer values. |
183 */ | 198 */ |
184 float x; | 199 float x; |
| 200 /** |
| 201 * This values represents the y coordinate of the mouse when the event |
| 202 * occurred. |
| 203 * |
| 204 * In most, but not all, cases these coordinates will just be integers. |
| 205 * For example, the plugin element might be arbitrarily scaled or transformed |
| 206 * in the DOM, and translating a mouse event into the coordinate space of the |
| 207 * plugin will give non-integer values. |
| 208 */ |
185 float y; | 209 float y; |
186 | 210 |
187 /** TODO(brettw) figure out exactly what this means. */ | 211 /** TODO(brettw) figure out exactly what this means. */ |
188 int32_t click_count; | 212 int32_t click_count; |
189 }; | 213 }; |
190 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_InputEvent_Mouse, 20); | 214 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_InputEvent_Mouse, 20); |
191 /** | 215 /** |
192 * @} | 216 * @} |
193 */ | 217 */ |
194 | 218 |
195 /** | 219 /** |
196 * @addtogroup Structs | 220 * @addtogroup Structs |
197 * @{ | 221 * @{ |
198 */ | 222 */ |
| 223 |
| 224 /** |
| 225 * The PP_InputEvent_Wheel struct represents all mouse wheel events. |
| 226 */ |
199 struct PP_InputEvent_Wheel { | 227 struct PP_InputEvent_Wheel { |
200 /** A combination of the EVENT_MODIFIER flags. */ | 228 /** This value represents a combination of the EVENT_MODIFIER flags. */ |
201 uint32_t modifier; | 229 uint32_t modifier; |
202 | 230 |
| 231 /** This value represents */ |
203 float delta_x; | 232 float delta_x; |
| 233 |
| 234 /** This value represents */ |
204 float delta_y; | 235 float delta_y; |
| 236 |
| 237 /** This value represents */ |
205 float wheel_ticks_x; | 238 float wheel_ticks_x; |
| 239 |
| 240 /** This value represents */ |
206 float wheel_ticks_y; | 241 float wheel_ticks_y; |
207 | 242 |
| 243 /** This value represents */ |
208 PP_Bool scroll_by_page; | 244 PP_Bool scroll_by_page; |
209 }; | 245 }; |
210 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_InputEvent_Wheel, 24); | 246 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_InputEvent_Wheel, 24); |
211 /** | 247 /** |
212 * @} | 248 * @} |
213 */ | 249 */ |
214 | 250 |
215 /** | 251 /** |
216 * | 252 * |
217 * @addtogroup Structs | 253 * @addtogroup Structs |
218 * @{ | 254 * @{ |
219 */ | 255 */ |
| 256 |
| 257 /** |
| 258 * The PP_InputEvent struct represents all input events. |
| 259 */ |
220 struct PP_InputEvent { | 260 struct PP_InputEvent { |
221 /** Identifies the type of the event. */ | 261 /** This value represents the type of the event. */ |
222 PP_InputEvent_Type type; | 262 PP_InputEvent_Type type; |
223 | 263 |
224 /* Ensure the time_stamp is aligned on an 8-byte boundary relative to the | 264 /** This value ensure the time_stamp is aligned on an 8-byte boundary |
225 start of the struct. Some compilers align doubles on 8-byte boundaries | 265 * relative to the start of the struct. Some compilers align doubles |
226 for 32-bit x86, and some align on 4-byte boundaries. */ | 266 * on 8-byte boundaries for 32-bit x86, and some align on 4-byte boundaries. |
| 267 */ |
227 int32_t padding; | 268 int32_t padding; |
228 | 269 |
229 /** | 270 /** |
230 * When this event was generated. This is not relative to any particular | 271 * This value represents the time that this event was generated. This value |
231 * epoch, the most you can do is compare time stamps. | 272 * is not relative to any particular epoch; the most you can do is compare |
| 273 * time stamps. |
232 */ | 274 */ |
233 PP_TimeTicks time_stamp; | 275 PP_TimeTicks time_stamp; |
234 | 276 |
235 /** Event-specific data. */ | 277 /** This value represents the event type and its specific data. */ |
236 union { | 278 union { |
237 struct PP_InputEvent_Key key; | 279 struct PP_InputEvent_Key key; |
238 struct PP_InputEvent_Character character; | 280 struct PP_InputEvent_Character character; |
239 struct PP_InputEvent_Mouse mouse; | 281 struct PP_InputEvent_Mouse mouse; |
240 struct PP_InputEvent_Wheel wheel; | 282 struct PP_InputEvent_Wheel wheel; |
241 | 283 |
242 /** | 284 /** |
243 * Allows new events to be added without changing the size of this | 285 * This value allows new events to be added without changing the size of |
244 * struct. | 286 * this struct. |
245 */ | 287 */ |
246 char padding[64]; | 288 char padding[64]; |
247 } u; | 289 } u; |
248 }; | 290 }; |
249 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_InputEvent, 80); | 291 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_InputEvent, 80); |
250 /** | 292 /** |
251 * @} | 293 * @} |
252 */ | 294 */ |
253 | 295 |
254 #endif /* PPAPI_C_PP_INPUT_EVENT_H_ */ | 296 #endif /* PPAPI_C_PP_INPUT_EVENT_H_ */ |
OLD | NEW |