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