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_CPP_INPUT_EVENT_H_ | 5 #ifndef PPAPI_CPP_INPUT_EVENT_H_ |
| 6 #define PPAPI_CPP_INPUT_EVENT_H_ | 6 #define PPAPI_CPP_INPUT_EVENT_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "ppapi/c/ppb_input_event.h" | 10 #include "ppapi/c/ppb_input_event.h" |
| 11 #include "ppapi/cpp/resource.h" | 11 #include "ppapi/cpp/resource.h" |
| 12 | 12 |
| 13 /// @file | |
| 14 /// This file defines the API used to handle mouse and keyboard input events. | |
| 15 | |
| 13 namespace pp { | 16 namespace pp { |
| 14 | 17 |
| 15 class FloatPoint; | 18 class FloatPoint; |
| 16 class Instance; | 19 class Instance; |
| 17 class Point; | 20 class Point; |
| 18 class Var; | 21 class Var; |
| 19 | 22 |
| 20 /// Represents an input event resource. Normally you will get passed this | 23 /// This class represents an input event resource. Normally you will get passed |
| 21 /// object through the HandleInputEvent on the Instance object. | 24 /// this object through the HandleInputEvent() function on the |
| 25 /// <code>Instance</code> object. | |
| 22 /// | 26 /// |
| 23 /// Typically you would check the type of the event and then create the | 27 /// Typically you would check the type of the event and then create the |
| 24 /// appropriate event-specific object to query the properties. | 28 /// appropriate event-specific object to query the properties. |
| 25 /// | 29 /// |
| 30 /// <strong>Example:</strong> | |
| 31 /// @code | |
| 32 /// | |
| 26 /// bool MyInstance::HandleInputEvent(const pp::InputEvent& event) { | 33 /// bool MyInstance::HandleInputEvent(const pp::InputEvent& event) { |
| 27 /// switch (event.GetType()) { | 34 /// switch (event.GetType()) { |
| 28 /// case PP_INPUTEVENT_TYPE_MOUSE_DOWN { | 35 /// case PP_INPUTEVENT_TYPE_MOUSE_DOWN { |
| 29 /// pp::MouseInputEvent mouse_event(event); | 36 /// pp::MouseInputEvent mouse_event(event); |
| 30 /// return HandleMouseDown(mouse_event.GetMousePosition()); | 37 /// return HandleMouseDown(mouse_event.GetMousePosition()); |
| 31 /// } | 38 /// } |
| 32 /// default: | 39 /// default: |
| 33 /// return false; | 40 /// return false; |
| 34 /// } | 41 /// } |
| 42 /// | |
| 43 /// @endcode | |
| 35 class InputEvent : public Resource { | 44 class InputEvent : public Resource { |
| 36 public: | 45 public: |
| 37 /// Default constructor that creates an is_null() InputEvent object. | 46 /// Default constructor that creates an is_null() InputEvent object. |
| 38 InputEvent(); | 47 InputEvent(); |
| 39 | 48 |
| 40 /// Constructs an input event from the given input event resource ID. The | 49 /// This constructor constructs an input event from the provided input event |
| 41 /// InputEvent object will be is_null() if the given resource is not a valid | 50 /// resource ID. The InputEvent object will be is_null() if the given |
| 42 /// input event. | 51 /// resource is not a valid input event. |
| 52 /// | |
| 53 /// @param[in] input_event_resource A input event resource ID. | |
| 43 explicit InputEvent(PP_Resource input_event_resource); | 54 explicit InputEvent(PP_Resource input_event_resource); |
| 44 | 55 |
| 45 ~InputEvent(); | 56 ~InputEvent(); |
| 46 | 57 |
| 47 /// Returns the type of input event for the given input event resource. | 58 /// GetType() returns the type of input event for this input event |
| 48 /// This is valid for all input events. Returns PP_INPUTEVENT_TYPE_UNDEFINED | 59 /// object. |
| 49 /// if the resource is invalid. | 60 /// |
| 61 /// @return A <code>PP_InputEvent_Type</code> if successful, | |
| 62 /// PP_INPUTEVENT_TYPE_UNDEFINED if the resource is invalid. | |
| 50 PP_InputEvent_Type GetType() const; | 63 PP_InputEvent_Type GetType() const; |
| 51 | 64 |
| 52 /// Returns the time that the event was generated. This will be before the | 65 /// GetTimeStamp() returns the time that the event was generated. The time |
| 53 /// current time since processing and dispatching the event has some overhead. | 66 /// will be before the current time since processing and dispatching the |
| 54 /// Use this value to compare the times the user generated two events without | 67 /// event has some overhead. Use this value to compare the times the user |
| 55 /// being sensitive to variable processing time. | 68 /// generated two events without being sensitive to variable processing time. |
| 56 /// | 69 /// |
| 57 /// The return value is in time ticks, which is a monotonically increasing | 70 /// The return value is in time ticks, which is a monotonically increasing |
| 58 /// clock not related to the wall clock time. It will not change if the user | 71 /// clock not related to the wall clock time. It will not change if the user |
| 59 /// changes their clock or daylight savings time starts, so can be reliably | 72 /// changes their clock or daylight savings time starts, so can be reliably |
| 60 /// used to compare events. This means, however, that you can't correlate | 73 /// used to compare events. This means, however, that you can't correlate |
| 61 /// event times to a particular time of day on the system clock. | 74 /// event times to a particular time of day on the system clock. |
| 75 /// | |
| 76 /// @return A <code>PP_TimeTicks</code> containing the time the event was | |
| 77 /// generated. | |
| 62 PP_TimeTicks GetTimeStamp() const; | 78 PP_TimeTicks GetTimeStamp() const; |
| 63 | 79 |
| 64 /// Returns a bitfield indicating which modifiers were down at the time of | 80 /// GetModifiers() returns a bitfield indicating which modifiers were down |
| 65 /// the event. This is a combination of the flags in the | 81 /// at the time of the event. This is a combination of the flags in the |
| 66 /// PP_InputEvent_Modifier enum. | 82 /// <code>PP_InputEvent_Modifier</code> enum. |
| 67 /// | 83 /// |
| 68 /// @return The modifiers associated with the event, or 0 if the given | 84 /// @return The modifiers associated with the event, or 0 if the given |
| 69 /// resource is not a valid event resource. | 85 /// resource is not a valid event resource. |
| 70 uint32_t GetModifiers() const; | 86 uint32_t GetModifiers() const; |
| 71 }; | 87 }; |
| 72 | 88 |
| 89 /// This class handles mouse events. | |
| 73 class MouseInputEvent : public InputEvent { | 90 class MouseInputEvent : public InputEvent { |
| 74 public: | 91 public: |
| 75 /// Constructs an is_null() mouse input event object. | 92 /// Constructs an is_null() mouse input event object. |
| 76 MouseInputEvent(); | 93 MouseInputEvent(); |
| 77 | 94 |
| 78 /// Constructs a mouse input event object from the given generic input | 95 /// This constructor constructs a mouse input event object from the provided |
| 79 /// event. If the given event is itself is_null() or is not a mouse input | 96 /// generic input event. If the given event is itself is_null() or is not |
| 80 /// event, the mouse object will be is_null(). | 97 /// a mouse input event, the mouse object will be is_null(). |
| 98 /// | |
| 99 /// @param event An <code>InputEvent</code>. | |
| 81 explicit MouseInputEvent(const InputEvent& event); | 100 explicit MouseInputEvent(const InputEvent& event); |
| 82 | 101 |
| 83 /// Manually constructs a mouse event from the given parameters. | 102 /// This constructor manually constructs a mouse event from the provided |
| 103 /// parameters. | |
| 104 /// | |
| 105 /// @param[in] instance The instance for which this event occured. | |
| 106 /// | |
| 107 /// @param[in] type A <code>PP_InputEvent_Type</code> identifying the type of | |
| 108 /// input event. | |
| 109 /// | |
| 110 /// @param[in] time_stamp A <code>PP_TimeTicks</code> indicating the time | |
| 111 /// when the event occured. | |
| 112 /// | |
| 113 /// @param[in] modifiers A bit field combination of the | |
| 114 /// <code>PP_InputEvent_Modifier</code> flags. | |
| 115 /// | |
| 116 /// @param[in] mouse_button The button that changed for mouse down or up | |
| 117 /// events. This value will be <code>PP_EVENT_MOUSEBUTTON_NONE</code> for | |
| 118 /// mouse move, enter, and leave events. | |
| 119 /// | |
| 120 /// @param[in] mouse_position A <code>Point</code> containing the x and y | |
| 121 /// position of the mouse when the eent occurred. | |
| 122 /// | |
| 123 /// @param[in] click_count | |
| 124 /// TODO(brettw) figure out exactly what this means. | |
| 125 /// | |
| 84 MouseInputEvent(Instance* instance, | 126 MouseInputEvent(Instance* instance, |
| 85 PP_InputEvent_Type type, | 127 PP_InputEvent_Type type, |
| 86 PP_TimeTicks time_stamp, | 128 PP_TimeTicks time_stamp, |
| 87 uint32_t modifiers, | 129 uint32_t modifiers, |
| 88 PP_InputEvent_MouseButton mouse_button, | 130 PP_InputEvent_MouseButton mouse_button, |
| 89 const Point& mouse_position, | 131 const Point& mouse_position, |
| 90 int32_t click_count); | 132 int32_t click_count); |
| 91 | 133 |
| 92 /// Returns the mouse position for a mouse input event. | 134 /// GetButton() returns the mouse position for a mouse input event. |
| 93 /// | 135 /// |
| 94 /// @return The mouse button associated with mouse down and up events. This | 136 /// @return The mouse button associated with mouse down and up events. This |
| 95 /// value will be PP_EVENT_MOUSEBUTTON_NONE for mouse move, enter, and leave | 137 /// value will be PP_EVENT_MOUSEBUTTON_NONE for mouse move, enter, and leave |
| 96 /// events, and for all non-mouse events. | 138 /// events, and for all non-mouse events. |
| 97 PP_InputEvent_MouseButton GetButton() const; | 139 PP_InputEvent_MouseButton GetButton() const; |
| 98 | 140 |
| 99 /// Returns the pixel location of a mouse input event. This value is in | 141 /// GetPostion() returns the pixel location of a mouse input event. This |
| 100 /// floating-point units to support high-resolution input events. | 142 /// value is in floating-point units to support high-resolution input events. |
| 101 /// | 143 /// |
| 102 /// @return The point associated with the mouse event, relative to the upper- | 144 /// @return The point associated with the mouse event, relative to the upper- |
| 103 /// left of the instance receiving the event. These values can be negative for | 145 /// left of the instance receiving the event. These values can be negative for |
| 104 /// mouse drags. The return value will be (0, 0) for non-mouse events. | 146 /// mouse drags. The return value will be (0, 0) for non-mouse events. |
| 105 Point GetPosition() const; | 147 Point GetPosition() const; |
| 106 | 148 |
| 107 // TODO(brettw) figure out exactly what this means. | 149 // TODO(brettw) figure out exactly what this means. |
| 108 int32_t GetClickCount() const; | 150 int32_t GetClickCount() const; |
| 109 }; | 151 }; |
| 110 | 152 |
| 111 class WheelInputEvent : public InputEvent { | 153 class WheelInputEvent : public InputEvent { |
| 112 public: | 154 public: |
| 113 /// Constructs an is_null() wheel input event object. | 155 /// Constructs an is_null() wheel input event object. |
| 114 WheelInputEvent(); | 156 WheelInputEvent(); |
| 115 | 157 |
| 116 /// Constructs a wheel input event object from the given generic input | 158 /// This constructor constructs a wheel input event object from the |
| 117 /// event. If the given event is itself is_null() or is not a wheel input | 159 /// provided generic input event. If the given event is itself |
| 118 /// event, the wheel object will be is_null(). | 160 /// is_null() or is not a wheel input event, the wheel object will be |
| 161 /// is_null(). | |
| 162 /// | |
| 163 /// @param[in] A generic input event. | |
| 119 explicit WheelInputEvent(const InputEvent& event); | 164 explicit WheelInputEvent(const InputEvent& event); |
| 120 | 165 |
| 121 /// Constructs a wheel input even from the given parameters. | 166 /// Constructs a wheel input even from the given parameters. |
| 167 /// | |
| 168 /// @param[in] instance The instance for which this event occured. | |
| 169 /// | |
| 170 /// @param[in] time_stamp A <code>PP_TimeTicks</code> indicating the time | |
| 171 /// when the event occured. | |
| 172 /// | |
| 173 /// @param modifiers A bit field combination of the | |
|
dmichael (off chromium)
2011/08/12 21:32:37
[in]?
jond
2011/08/15 17:32:11
Done.
| |
| 174 /// <code>PP_InputEvent_Modifier</code> flags. | |
| 175 /// | |
| 176 /// @param[in] wheel_delta The scroll wheel's horizontal and vertical scroll | |
| 177 /// amounts. | |
| 178 /// | |
| 179 /// @param[in] wheel_ticks he number of "clicks" of the scroll wheel that | |
| 180 /// have produced the event. | |
| 181 /// | |
| 182 /// @param[in] scroll_by_page * When true, the user is requesting to scroll | |
|
dmichael (off chromium)
2011/08/12 21:32:37
What's the asterisk mean here? Is that intentional
jond
2011/08/15 17:32:11
Done.
| |
| 183 /// by pages. When false, the user user is requesting to scroll by lines. | |
|
dmichael (off chromium)
2011/08/12 21:32:37
you have an extra 'user'
jond
2011/08/15 17:32:11
Done.
| |
| 122 WheelInputEvent(Instance* instance, | 184 WheelInputEvent(Instance* instance, |
| 123 PP_TimeTicks time_stamp, | 185 PP_TimeTicks time_stamp, |
| 124 uint32_t modifiers, | 186 uint32_t modifiers, |
| 125 const FloatPoint& wheel_delta, | 187 const FloatPoint& wheel_delta, |
| 126 const FloatPoint& wheel_ticks, | 188 const FloatPoint& wheel_ticks, |
| 127 bool scroll_by_page); | 189 bool scroll_by_page); |
| 128 | 190 |
| 129 /// Indicates the amount vertically and horizontally the user has requested | 191 /// GetDelta() returns the amount vertically and horizontally the user has |
| 130 /// to scroll by with their mouse wheel. A scroll down or to the right (where | 192 /// requested to scroll by with their mouse wheel. A scroll down or to the |
| 131 /// the content moves up or left) is represented as positive values, and | 193 /// right (where the content moves up or left) is represented as positive |
| 132 /// a scroll up or to the left (where the content moves down or right) is | 194 /// values, and a scroll up or to the left (where the content moves down or |
| 133 /// represented as negative values. | 195 /// right) is represented as negative values. |
| 134 /// | |
| 135 /// The units are either in pixels (when scroll_by_page is false) or pages | |
| 136 /// (when scroll_by_page is true). For example, y = -3 means scroll up 3 | |
| 137 /// pixels when scroll_by_page is false, and scroll up 3 pages when | |
| 138 /// scroll_by_page is true. | |
| 139 /// | 196 /// |
| 140 /// This amount is system dependent and will take into account the user's | 197 /// This amount is system dependent and will take into account the user's |
| 141 /// preferred scroll sensitivity and potentially also nonlinear acceleration | 198 /// preferred scroll sensitivity and potentially also nonlinear acceleration |
| 142 /// based on the speed of the scrolling. | 199 /// based on the speed of the scrolling. |
| 143 /// | 200 /// |
| 144 /// Devices will be of varying resolution. Some mice with large detents will | 201 /// Devices will be of varying resolution. Some mice with large detents will |
| 145 /// only generate integer scroll amounts. But fractional values are also | 202 /// only generate integer scroll amounts. But fractional values are also |
| 146 /// possible, for example, on some trackpads and newer mice that don't have | 203 /// possible, for example, on some trackpads and newer mice that don't have |
| 147 /// "clicks". | 204 /// "clicks". |
| 205 /// | |
| 206 /// @return The vertial and horizontal scroll values. The units are either in | |
| 207 /// pixels (when scroll_by_page is false) or pages (when scroll_by_page is | |
| 208 /// true). For example, y = -3 means scroll up 3 pixels when scroll_by_page | |
| 209 /// is false, and scroll up 3 pages when scroll_by_page is true. | |
| 148 FloatPoint GetDelta() const; | 210 FloatPoint GetDelta() const; |
| 149 | 211 |
| 150 /// The number of "clicks" of the scroll wheel that have produced the | 212 /// GetTicks() returns the number of "clicks" of the scroll wheel |
| 151 /// event. The value may have system-specific acceleration applied to it, | 213 /// that have produced the event. The value may have system-specific |
| 152 /// depending on the device. The positive and negative meanings are the same | 214 /// acceleration applied to it, depending on the device. The positive and |
| 153 /// as for GetDelta(). | 215 /// negative meanings are the same as for GetDelta(). |
| 154 /// | 216 /// |
| 155 /// If you are scrolling, you probably want to use the delta values. These | 217 /// If you are scrolling, you probably want to use the delta values. These |
| 156 /// tick events can be useful if you aren't doing actual scrolling and don't | 218 /// tick events can be useful if you aren't doing actual scrolling and don't |
| 157 /// want or pixel values. An example may be cycling between different items in | 219 /// want or pixel values. An example may be cycling between different items in |
| 158 /// a game. | 220 /// a game. |
| 159 /// | 221 /// |
| 160 /// You may receive fractional values for the wheel ticks if the mouse wheel | 222 /// @return The number of "clicks" of the scroll wheel. You may receive |
| 161 /// is high resolution or doesn't have "clicks". If your program wants | 223 /// fractional values for the wheel ticks if the mouse wheel is high |
| 162 /// discrete events (as in the "picking items" example) you should accumulate | 224 /// resolution or doesn't have "clicks". If your program wants discrete |
| 225 /// events (as in the "picking items" example) you should accumulate | |
| 163 /// fractional click values from multiple messages until the total value | 226 /// fractional click values from multiple messages until the total value |
| 164 /// reaches positive or negative one. This should represent a similar amount | 227 /// reaches positive or negative one. This should represent a similar amount |
| 165 /// of scrolling as for a mouse that has a discrete mouse wheel. | 228 /// of scrolling as for a mouse that has a discrete mouse wheel. |
| 166 FloatPoint GetTicks() const; | 229 FloatPoint GetTicks() const; |
| 167 | 230 |
| 168 // Indicates if the scroll delta x/y indicates pages or lines to | 231 // Indicates if the scroll delta x/y indicates pages or lines to |
| 169 // scroll by. | 232 // scroll by. |
| 170 // | 233 // |
| 171 // @return PP_TRUE if the event is a wheel event and the user is scrolling | 234 // @return true if the event is a wheel event and the user is scrolling |
| 172 // by pages. PP_FALSE if not or if the resource is not a wheel event. | 235 // by pages, false if not or if the resource is not a wheel event. |
| 173 bool GetScrollByPage() const; | 236 bool GetScrollByPage() const; |
| 174 }; | 237 }; |
| 175 | 238 |
| 176 class KeyboardInputEvent : public InputEvent { | 239 class KeyboardInputEvent : public InputEvent { |
| 177 public: | 240 public: |
| 178 /// Constructs an is_null() keyboard input event object. | 241 /// Constructs an is_null() keyboard input event object. |
| 179 KeyboardInputEvent(); | 242 KeyboardInputEvent(); |
| 180 | 243 |
| 181 /// Constructs a keyboard input event object from the given generic input | 244 /// Constructs a keyboard input event object from the provided generic input |
| 182 /// event. If the given event is itself is_null() or is not a keyboard input | 245 /// event. If the given event is itself is_null() or is not a keyboard input |
| 183 /// event, the keybaord object will be is_null(). | 246 /// event, the keybaord object will be is_null(). |
| 247 /// | |
| 248 /// @param[in] event A generic input event. | |
| 184 explicit KeyboardInputEvent(const InputEvent& event); | 249 explicit KeyboardInputEvent(const InputEvent& event); |
| 185 | 250 |
| 186 /// Constructs a keyboard input even from the given parameters. | 251 /// Constructs a keyboard input even from the given parameters. |
| 252 /// | |
| 253 /// @param[in] instance The instance for which this event occured. | |
| 254 /// | |
| 255 /// @param[in] type A <code>PP_InputEvent_Type</code> identifying the type of | |
| 256 /// input event. | |
| 257 /// | |
| 258 /// @param[in] time_stamp A <code>PP_TimeTicks</code> indicating the time | |
| 259 /// when the event occured. | |
| 260 /// | |
| 261 /// @param[in] modifiers A bit field combination of the | |
| 262 /// <code>PP_InputEvent_Modifier</code> flags. | |
| 263 /// | |
| 264 /// @param[in] key_code This value reflects the DOM KeyboardEvent | |
| 265 /// <code>keyCode</code> field. Chrome populates this with the Windows-style | |
| 266 /// Virtual Key code of the key. | |
| 267 /// | |
| 268 /// @param[in] character_text This value represents the typed character as a | |
| 269 /// single null-terminated UTF-8 character. Any unused bytes will be filled | |
| 270 /// with null bytes. Since the maximum UTF-8 character is 4 bytes, there will | |
| 271 /// always be at least one null at the end so you can treat this as a | |
| 272 /// null-termianted UTF-8 string. | |
|
dmichael (off chromium)
2011/08/12 21:32:37
Oops, everything after the first sentence is wrong
jond
2011/08/15 17:32:11
Done.
| |
| 187 KeyboardInputEvent(Instance* instance, | 273 KeyboardInputEvent(Instance* instance, |
| 188 PP_InputEvent_Type type, | 274 PP_InputEvent_Type type, |
| 189 PP_TimeTicks time_stamp, | 275 PP_TimeTicks time_stamp, |
| 190 uint32_t modifiers, | 276 uint32_t modifiers, |
| 191 uint32_t key_code, | 277 uint32_t key_code, |
| 192 const Var& character_text); | 278 const Var& character_text); |
| 193 | 279 |
| 194 /// Returns the DOM |keyCode| field for the keyboard event. | 280 /// Returns the DOM |keyCode| field for the keyboard event. |
| 195 /// Chrome populates this with the Windows-style Virtual Key code of the key. | 281 /// Chrome populates this with the Windows-style Virtual Key code of the key. |
| 196 uint32_t GetKeyCode() const; | 282 uint32_t GetKeyCode() const; |
| 197 | 283 |
| 198 /// Returns the typed character for the given character event. | 284 /// Returns the typed character for the given character event. |
| 199 /// | 285 /// |
| 200 /// @return A string var representing a single typed character for character | 286 /// @return A string var representing a single typed character for character |
| 201 /// input events. For non-character input events the return value will be an | 287 /// input events. For non-character input events the return value will be an |
| 202 /// undefined var. | 288 /// undefined var. |
| 203 Var GetCharacterText() const; | 289 Var GetCharacterText() const; |
| 204 }; | 290 }; |
| 205 | 291 |
| 206 } // namespace pp | 292 } // namespace pp |
| 207 | 293 |
| 208 #endif // PPAPI_CPP_INPUT_EVENT_H_ | 294 #endif // PPAPI_CPP_INPUT_EVENT_H_ |
| OLD | NEW |