| 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 |
| 6 /* From pp_input_event.idl modified Sat Jul 16 16:50:26 2011. */ |
| 7 |
| 5 #ifndef PPAPI_C_PP_INPUT_EVENT_H_ | 8 #ifndef PPAPI_C_PP_INPUT_EVENT_H_ |
| 6 #define PPAPI_C_PP_INPUT_EVENT_H_ | 9 #define PPAPI_C_PP_INPUT_EVENT_H_ |
| 7 | 10 |
| 8 /** | |
| 9 * @file | |
| 10 * This file defines the API used to handle mouse and keyboard input events. | |
| 11 */ | |
| 12 | |
| 13 #include "ppapi/c/pp_bool.h" | 11 #include "ppapi/c/pp_bool.h" |
| 14 #include "ppapi/c/pp_macros.h" | 12 #include "ppapi/c/pp_macros.h" |
| 15 #include "ppapi/c/pp_stdint.h" | 13 #include "ppapi/c/pp_stdint.h" |
| 16 #include "ppapi/c/pp_time.h" | 14 #include "ppapi/c/pp_time.h" |
| 17 #include "ppapi/c/ppb_input_event.h" | 15 #include "ppapi/c/ppb_input_event.h" |
| 18 | 16 |
| 19 /** | 17 /** |
| 18 * @file |
| 19 * This file defines the API used to handle mouse and keyboard input events. |
| 20 */ |
| 21 |
| 22 |
| 23 /** |
| 20 * @addtogroup Structs | 24 * @addtogroup Structs |
| 21 * @{ | 25 * @{ |
| 22 */ | 26 */ |
| 23 | |
| 24 /** | 27 /** |
| 25 * The <code>PP_InputEvent_Key</code> struct represents a key up or key down | 28 * The <code>PP_InputEvent_Key</code> struct represents a key up or key down |
| 26 * event. | 29 * event. |
| 27 * | 30 * |
| 28 * Key up and key down events correspond to physical keys on the keyboard. The | 31 * Key up and key down events correspond to physical keys on the keyboard. The |
| 29 * actual character that the user typed (if any) will be delivered in a | 32 * actual character that the user typed (if any) will be delivered in a |
| 30 * "character" event. | 33 * "character" event. |
| 31 * | 34 * |
| 32 * If the user loses focus on the module while a key is down, a key up | 35 * If the user loses focus on the module while a key is down, a key up |
| 33 * event might not occur. For example, if the module has focus and the user | 36 * event might not occur. For example, if the module has focus and the user |
| 34 * presses and holds the shift key, the module will see a "shift down" message. | 37 * presses and holds the shift key, the module will see a "shift down" message. |
| 35 * Then if the user clicks elsewhere on the web page, the module's focus will | 38 * Then if the user clicks elsewhere on the web page, the module's focus will |
| 36 * be lost and no more input events will be delivered. | 39 * be lost and no more input events will be delivered. |
| 37 * | 40 * |
| 38 * If your module depends on receiving key up events, it should also handle | 41 * If your module depends on receiving key up events, it should also handle |
| 39 * "lost focus" as the equivalent of "all keys up." | 42 * "lost focus" as the equivalent of "all keys up." |
| 40 */ | 43 */ |
| 41 struct PP_InputEvent_Key { | 44 struct PP_InputEvent_Key { |
| 42 /** This value is a bit field combination of the EVENT_MODIFIER flags. */ | 45 /** This value is a bit field combination of the EVENT_MODIFIER flags. */ |
| 43 uint32_t modifier; | 46 uint32_t modifier; |
| 44 | |
| 45 /** | 47 /** |
| 46 * This value reflects the DOM KeyboardEvent <code>keyCode</code> field. | 48 * This value reflects the DOM KeyboardEvent <code>keyCode</code> field. |
| 47 * Chrome populates this with the Windows-style Virtual Key code of the key. | 49 * Chrome populates this with the Windows-style Virtual Key code of the key. |
| 48 */ | 50 */ |
| 49 | |
| 50 uint32_t key_code; | 51 uint32_t key_code; |
| 51 }; | 52 }; |
| 52 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_InputEvent_Key, 8); | 53 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_InputEvent_Key, 8); |
| 53 /** | |
| 54 * @} | |
| 55 */ | |
| 56 | |
| 57 /** | |
| 58 * @addtogroup Structs | |
| 59 * @{ | |
| 60 */ | |
| 61 | 54 |
| 62 /** | 55 /** |
| 63 * The <code>PP_InputEvent_Character</code> struct represents a typed character | 56 * The <code>PP_InputEvent_Character</code> struct represents a typed character |
| 64 * event. | 57 * event. |
| 65 * | 58 * |
| 66 * Normally, the program will receive a key down event, followed by a character | 59 * Normally, the program will receive a key down event, followed by a character |
| 67 * event, followed by a key up event. The character event will have any | 60 * event, followed by a key up event. The character event will have any |
| 68 * modifier keys applied. Obvious examples are symbols, where Shift-5 gives you | 61 * modifier keys applied. Obvious examples are symbols, where Shift-5 gives you |
| 69 * a '%'. The key down and up events will give you the scan code for the "5" | 62 * a '%'. The key down and up events will give you the scan code for the "5" |
| 70 * key, and the character event will give you the '%' character. | 63 * key, and the character event will give you the '%' character. |
| 71 * | 64 * |
| 72 * You may not get a character event for all key down events if the key doesn't | 65 * You may not get a character event for all key down events if the key doesn't |
| 73 * generate a character. Likewise, you may actually get multiple character | 66 * generate a character. Likewise, you may actually get multiple character |
| 74 * events in a row. For example, some locales have an accent key that modifies | 67 * events in a row. For example, some locales have an accent key that modifies |
| 75 * the next character typed. You might get this stream of events: accent down, | 68 * the next character typed. You might get this stream of events: accent down, |
| 76 * accent up (it didn't generate a character), letter key down, letter with | 69 * accent up (it didn't generate a character), letter key down, letter with |
| 77 * accent character event (it was modified by the previous accent key), letter | 70 * accent character event (it was modified by the previous accent key), letter |
| 78 * key up. If the letter can't be combined with the accent, like an umlaut and | 71 * key up. If the letter can't be combined with the accent, like an umlaut and |
| 79 * an 'R', the system might send unlaut down, umlaut up, 'R' key down, umlaut | 72 * an 'R', the system might send unlaut down, umlaut up, 'R' key down, umlaut |
| 80 * character (can't combine it with 'R', so just send the raw unlaut so it | 73 * character (can't combine it with 'R', so just send the raw unlaut so it |
| 81 * isn't lost"), 'R' character event, 'R' key up. | 74 * isn't lost"), 'R' character event, 'R' key up. |
| 82 */ | 75 */ |
| 83 struct PP_InputEvent_Character { | 76 struct PP_InputEvent_Character { |
| 84 /** A combination of the <code>PP_InputEvent_Modifier</code> flags. */ | 77 /** A combination of the <code>PP_InputEvent_Modifier</code> flags. */ |
| 85 uint32_t modifier; | 78 uint32_t modifier; |
| 86 | |
| 87 /** | 79 /** |
| 88 * This value represents the typed character as a single null-terminated UTF-8 | 80 * This value represents the typed character as a single null-terminated UTF-8 |
| 89 * character. Any unused bytes will be filled with null bytes. Since the | 81 * character. Any unused bytes will be filled with null bytes. Since the |
| 90 * maximum UTF-8 character is 4 bytes, there will always be at least one null | 82 * maximum UTF-8 character is 4 bytes, there will always be at least one null |
| 91 * at the end so you can treat this as a null-termianted UTF-8 string. | 83 * at the end so you can treat this as a null-termianted UTF-8 string. |
| 92 */ | 84 */ |
| 93 char text[5]; | 85 char text[5]; |
| 94 }; | 86 }; |
| 95 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_InputEvent_Character, 12); | 87 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_InputEvent_Character, 12); |
| 96 /** | |
| 97 * @} | |
| 98 */ | |
| 99 | |
| 100 /** | |
| 101 * @addtogroup Structs | |
| 102 * @{ | |
| 103 */ | |
| 104 | 88 |
| 105 /** | 89 /** |
| 106 * The <code>PP_InputEvent_Mouse</code> struct represents all mouse events | 90 * The <code>PP_InputEvent_Mouse</code> struct represents all mouse events |
| 107 * except mouse wheel events. | 91 * except mouse wheel events. |
| 108 */ | 92 */ |
| 109 struct PP_InputEvent_Mouse { | 93 struct PP_InputEvent_Mouse { |
| 110 /** | 94 /** |
| 111 * This value is a bit field combination of the | 95 * This value is a bit field combination of the |
| 112 * <code>PP_InputEvent_Modifier</code> flags. | 96 * <code>PP_InputEvent_Modifier</code> flags. |
| 113 */ | 97 */ |
| 114 uint32_t modifier; | 98 uint32_t modifier; |
| 115 | |
| 116 /** | 99 /** |
| 117 * This value represents the button that changed for mouse down or up events. | 100 * This value represents the button that changed for mouse down or up events. |
| 118 * This value will be <code>PP_EVENT_MOUSEBUTTON_NONE</code> for mouse move, | 101 * This value will be <code>PP_EVENT_MOUSEBUTTON_NONE</code> for mouse move, |
| 119 * enter, and leave events. | 102 * enter, and leave events. |
| 120 */ | 103 */ |
| 121 PP_InputEvent_MouseButton button; | 104 PP_InputEvent_MouseButton button; |
| 122 | |
| 123 /** | 105 /** |
| 124 * This values represents the x coordinate of the mouse when the event | 106 * This values represents the x coordinate of the mouse when the event |
| 125 * occurred. | 107 * occurred. |
| 126 * | 108 * |
| 127 * In most, but not all, cases these coordinates will just be integers. | 109 * In most, but not all, cases these coordinates will just be integers. |
| 128 * For example, the plugin element might be arbitrarily scaled or transformed | 110 * For example, the plugin element might be arbitrarily scaled or transformed |
| 129 * in the DOM, and translating a mouse event into the coordinate space of the | 111 * in the DOM, and translating a mouse event into the coordinate space of the |
| 130 * plugin will give non-integer values. | 112 * plugin will give non-integer values. |
| 131 */ | 113 */ |
| 132 float x; | 114 float x; |
| 133 /** | 115 /** |
| 134 * This values represents the y coordinate of the mouse when the event | 116 * This values represents the y coordinate of the mouse when the event |
| 135 * occurred. | 117 * occurred. |
| 136 * | 118 * |
| 137 * In most, but not all, cases these coordinates will just be integers. | 119 * In most, but not all, cases these coordinates will just be integers. |
| 138 * For example, the plugin element might be arbitrarily scaled or transformed | 120 * For example, the plugin element might be arbitrarily scaled or transformed |
| 139 * in the DOM, and translating a mouse event into the coordinate space of the | 121 * in the DOM, and translating a mouse event into the coordinate space of the |
| 140 * plugin will give non-integer values. | 122 * plugin will give non-integer values. |
| 141 */ | 123 */ |
| 142 float y; | 124 float y; |
| 143 | 125 /* TODO(brettw) figure out exactly what this means. */ |
| 144 // TODO(brettw) figure out exactly what this means. | |
| 145 int32_t click_count; | 126 int32_t click_count; |
| 146 }; | 127 }; |
| 147 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_InputEvent_Mouse, 20); | 128 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_InputEvent_Mouse, 20); |
| 148 /** | |
| 149 * @} | |
| 150 */ | |
| 151 | |
| 152 /** | |
| 153 * @addtogroup Structs | |
| 154 * @{ | |
| 155 */ | |
| 156 | 129 |
| 157 /** | 130 /** |
| 158 * The <code>PP_InputEvent_Wheel</code> struct represents all mouse wheel | 131 * The <code>PP_InputEvent_Wheel</code> struct represents all mouse wheel |
| 159 * events. | 132 * events. |
| 160 */ | 133 */ |
| 161 struct PP_InputEvent_Wheel { | 134 struct PP_InputEvent_Wheel { |
| 162 /** | 135 /** |
| 163 * This value represents a combination of the <code>EVENT_MODIFIER</code> | 136 * This value represents a combination of the <code>EVENT_MODIFIER</code> |
| 164 * flags. | 137 * flags. |
| 165 */ | 138 */ |
| 166 uint32_t modifier; | 139 uint32_t modifier; |
| 167 | |
| 168 /** | 140 /** |
| 169 * Indicates the amount vertically and horizontally the user has requested | 141 * Indicates the amount vertically and horizontally the user has requested |
| 170 * to scroll by with their mouse wheel. A scroll down or to the right (where | 142 * to scroll by with their mouse wheel. A scroll down or to the right (where |
| 171 * the content moves up or left) is represented as positive values, and | 143 * the content moves up or left) is represented as positive values, and |
| 172 * a scroll up or to the left (where the content moves down or right) is | 144 * a scroll up or to the left (where the content moves down or right) is |
| 173 * represented as negative values. | 145 * represented as negative values. |
| 174 * | 146 * |
| 175 * The units are either in pixels (when scroll_by_page is false) or pages | 147 * The units are either in pixels (when scroll_by_page is false) or pages |
| 176 * (when scroll_by_page is true). For example, delta_y = -3 means scroll up 3 | 148 * (when scroll_by_page is true). For example, delta_y = -3 means scroll up 3 |
| 177 * pixels when scroll_by_page is false, and scroll up 3 pages when | 149 * pixels when scroll_by_page is false, and scroll up 3 pages when |
| 178 * scroll_by_page is true. | 150 * scroll_by_page is true. |
| 179 * | 151 * |
| 180 * This amount is system dependent and will take into account the user's | 152 * This amount is system dependent and will take into account the user's |
| 181 * preferred scroll sensitivity and potentially also nonlinear acceleration | 153 * preferred scroll sensitivity and potentially also nonlinear acceleration |
| 182 * based on the speed of the scrolling. | 154 * based on the speed of the scrolling. |
| 183 * | 155 * |
| 184 * Devices will be of varying resolution. Some mice with large detents will | 156 * Devices will be of varying resolution. Some mice with large detents will |
| 185 * only generate integer scroll amounts. But fractional values are also | 157 * only generate integer scroll amounts. But fractional values are also |
| 186 * possible, for example, on some trackpads and newer mice that don't have | 158 * possible, for example, on some trackpads and newer mice that don't have |
| 187 * "clicks". | 159 * "clicks". |
| 188 */ | 160 */ |
| 189 float delta_x; | 161 float delta_x; |
| 190 | |
| 191 /** This value represents */ | 162 /** This value represents */ |
| 192 float delta_y; | 163 float delta_y; |
| 193 | |
| 194 /** | 164 /** |
| 195 * The number of "clicks" of the scroll wheel that have produced the | 165 * The number of "clicks" of the scroll wheel that have produced the |
| 196 * event. The value may have system-specific acceleration applied to it, | 166 * event. The value may have system-specific acceleration applied to it, |
| 197 * depending on the device. The positive and negative meanings are the same | 167 * depending on the device. The positive and negative meanings are the same |
| 198 * as for <code>delta_x</code> and <code>delta_y</code>. | 168 * as for <code>delta_x</code> and <code>delta_y</code>. |
| 199 * | 169 * |
| 200 * If you are scrolling, you probably want to use the delta values above. | 170 * If you are scrolling, you probably want to use the delta values above. |
| 201 * These tick events can be useful if you aren't doing actual scrolling and | 171 * These tick events can be useful if you aren't doing actual scrolling and |
| 202 * don't want or pixel values. An example may be cycling between different | 172 * don't want or pixel values. An example may be cycling between different |
| 203 * items in a game. | 173 * items in a game. |
| 204 * | 174 * |
| 205 * You may receive fractional values for the wheel ticks if the mouse wheel | 175 * You may receive fractional values for the wheel ticks if the mouse wheel |
| 206 * is high resolution or doesn't have "clicks". If your program wants | 176 * is high resolution or doesn't have "clicks". If your program wants |
| 207 * discrete events (as in the "picking items" example) you should accumulate | 177 * discrete events (as in the "picking items" example) you should accumulate |
| 208 * fractional click values from multiple messages until the total value | 178 * fractional click values from multiple messages until the total value |
| 209 * reaches positive or negative one. This should represent a similar amount | 179 * reaches positive or negative one. This should represent a similar amount |
| 210 * of scrolling as for a mouse that has a discrete mouse wheel. | 180 * of scrolling as for a mouse that has a discrete mouse wheel. |
| 211 */ | 181 */ |
| 212 float wheel_ticks_x; | 182 float wheel_ticks_x; |
| 213 | |
| 214 /** This value represents */ | 183 /** This value represents */ |
| 215 float wheel_ticks_y; | 184 float wheel_ticks_y; |
| 216 | |
| 217 /** | 185 /** |
| 218 * Indicates if the scroll <code>delta_x</code>/<code>delta_y</code> | 186 * Indicates if the scroll <code>delta_x</code>/<code>delta_y</code> |
| 219 * indicates pages or lines to scroll by. When true, the user is requesting | 187 * indicates pages or lines to scroll by. When true, the user is requesting |
| 220 * to scroll by pages. | 188 * to scroll by pages. |
| 221 */ | 189 */ |
| 222 PP_Bool scroll_by_page; | 190 PP_Bool scroll_by_page; |
| 223 }; | 191 }; |
| 224 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_InputEvent_Wheel, 24); | 192 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_InputEvent_Wheel, 24); |
| 225 /** | |
| 226 * @} | |
| 227 */ | |
| 228 | |
| 229 /** | |
| 230 * | |
| 231 * @addtogroup Structs | |
| 232 * @{ | |
| 233 */ | |
| 234 | 193 |
| 235 /** | 194 /** |
| 236 * The PP_InputEventData union represents all input event data types. | 195 * The PP_InputEventData union represents all input event data types. |
| 237 */ | 196 */ |
| 238 union PP_InputEventData { | 197 union PP_InputEventData { |
| 239 struct PP_InputEvent_Key key; | 198 struct PP_InputEvent_Key key; |
| 240 struct PP_InputEvent_Character character; | 199 struct PP_InputEvent_Character character; |
| 241 struct PP_InputEvent_Mouse mouse; | 200 struct PP_InputEvent_Mouse mouse; |
| 242 struct PP_InputEvent_Wheel wheel; | 201 struct PP_InputEvent_Wheel wheel; |
| 243 | |
| 244 /** | 202 /** |
| 245 * This value allows new events to be added without changing the size of | 203 * This value allows new events to be added without changing the size of |
| 246 * this struct. | 204 * this struct. |
| 247 */ | 205 */ |
| 248 char padding[64]; | 206 char padding[64]; |
| 249 }; | 207 }; |
| 250 /** | |
| 251 * @} | |
| 252 */ | |
| 253 | |
| 254 /** | |
| 255 * | |
| 256 * @addtogroup Structs | |
| 257 * @{ | |
| 258 */ | |
| 259 | 208 |
| 260 /** | 209 /** |
| 261 * The PP_InputEvent struct represents all input events. | 210 * The PP_InputEvent struct represents all input events. |
| 262 */ | 211 */ |
| 263 struct PP_InputEvent { | 212 struct PP_InputEvent { |
| 264 /** This value represents the type of the event. */ | 213 /** This value represents the type of the event. */ |
| 265 PP_InputEvent_Type type; | 214 PP_InputEvent_Type type; |
| 266 | |
| 267 /** This value ensure the time_stamp is aligned on an 8-byte boundary | 215 /** This value ensure the time_stamp is aligned on an 8-byte boundary |
| 268 * relative to the start of the struct. Some compilers align doubles | 216 * relative to the start of the struct. Some compilers align doubles |
| 269 * on 8-byte boundaries for 32-bit x86, and some align on 4-byte boundaries. | 217 * on 8-byte boundaries for 32-bit x86, and some align on 4-byte boundaries. |
| 270 */ | 218 */ |
| 271 int32_t padding; | 219 int32_t padding; |
| 272 | |
| 273 /** | 220 /** |
| 274 * This value represents the time that this event was generated. This value | 221 * This value represents the time that this event was generated. This value |
| 275 * is not relative to any particular epoch; the most you can do is compare | 222 * is not relative to any particular epoch; the most you can do is compare |
| 276 * time stamps. | 223 * time stamps. |
| 277 */ | 224 */ |
| 278 PP_TimeTicks time_stamp; | 225 PP_TimeTicks time_stamp; |
| 279 | |
| 280 /** | 226 /** |
| 281 * This value represents the event type and its specific data. | 227 * This value represents the event type and its specific data. |
| 282 */ | 228 */ |
| 283 union PP_InputEventData u; | 229 union PP_InputEventData u; |
| 284 | |
| 285 }; | 230 }; |
| 286 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_InputEvent, 80); | 231 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_InputEvent, 80); |
| 287 /** | 232 /** |
| 288 * @} | 233 * @} |
| 289 */ | 234 */ |
| 290 | 235 |
| 291 #endif /* PPAPI_C_PP_INPUT_EVENT_H_ */ | 236 #endif /* PPAPI_C_PP_INPUT_EVENT_H_ */ |
| 237 |
| OLD | NEW |