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 <code>HandleInputEvent</code> on the |
dmichael (off chromium)
2011/08/12 20:17:59
HandleInputEvent()?
Probably should either remove
jond
2011/08/12 20:50:59
Done.
| |
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 | |
dmichael (off chromium)
2011/08/12 20:17:59
This still looks super weird to me. Can we resolve
jond
2011/08/12 20:50:59
Sure. Josie is back on Monday.
On 2011/08/12 20:1
| |
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 |
dmichael (off chromium)
2011/08/12 20:17:59
What's wrong with 'given'? I don't care particular
jond
2011/08/12 20:50:59
I believe the word "given" is improperly used in t
dmichael (off chromium)
2011/08/12 21:32:37
Yeah, makes sense. There is a sense of the word Gi
| |
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. This function is valid for all input events. |
dmichael (off chromium)
2011/08/12 20:17:59
You can delete the last sentence; it's a holdover
jond
2011/08/12 20:50:59
Done.
| |
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 | |
106 /// | |
107 /// @param[in] type A <code>PP_InputEvent_Type</code> identifying the type of | |
108 /// input event. | |
109 /// | |
110 /// @param[in] time_stamp | |
111 /// | |
112 /// @param modifiers A bit field combination of the | |
113 /// <code>PP_InputEvent_Modifier</code> flags. | |
114 /// | |
115 /// @param mouse_button The button that changed for mouse down or up events. | |
116 /// This value will be <code>PP_EVENT_MOUSEBUTTON_NONE</code> for mouse move, | |
117 /// enter, and leave events. | |
118 /// | |
119 /// @param[in] mouse_position A <code>Point</code> containing the x and y | |
120 /// position of the mouse when the eent occurred. | |
121 /// | |
122 /// @param[in] click_count | |
123 /// TODO(brettw) figure out exactly what this means. | |
124 /// | |
84 MouseInputEvent(Instance* instance, | 125 MouseInputEvent(Instance* instance, |
85 PP_InputEvent_Type type, | 126 PP_InputEvent_Type type, |
86 PP_TimeTicks time_stamp, | 127 PP_TimeTicks time_stamp, |
87 uint32_t modifiers, | 128 uint32_t modifiers, |
88 PP_InputEvent_MouseButton mouse_button, | 129 PP_InputEvent_MouseButton mouse_button, |
89 const Point& mouse_position, | 130 const Point& mouse_position, |
90 int32_t click_count); | 131 int32_t click_count); |
91 | 132 |
92 /// Returns the mouse position for a mouse input event. | 133 /// GetButton() returns the mouse position for a mouse input event. |
93 /// | 134 /// |
94 /// @return The mouse button associated with mouse down and up events. This | 135 /// @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 | 136 /// value will be PP_EVENT_MOUSEBUTTON_NONE for mouse move, enter, and leave |
96 /// events, and for all non-mouse events. | 137 /// events, and for all non-mouse events. |
97 PP_InputEvent_MouseButton GetButton() const; | 138 PP_InputEvent_MouseButton GetButton() const; |
98 | 139 |
99 /// Returns the pixel location of a mouse input event. This value is in | 140 /// GetPostion() returns the pixel location of a mouse input event. This |
100 /// floating-point units to support high-resolution input events. | 141 /// value is in floating-point units to support high-resolution input events. |
101 /// | 142 /// |
102 /// @return The point associated with the mouse event, relative to the upper- | 143 /// @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 | 144 /// 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. | 145 /// mouse drags. The return value will be (0, 0) for non-mouse events. |
105 Point GetPosition() const; | 146 Point GetPosition() const; |
106 | 147 |
107 // TODO(brettw) figure out exactly what this means. | 148 // TODO(brettw) figure out exactly what this means. |
108 int32_t GetClickCount() const; | 149 int32_t GetClickCount() const; |
109 }; | 150 }; |
110 | 151 |
111 class WheelInputEvent : public InputEvent { | 152 class WheelInputEvent : public InputEvent { |
112 public: | 153 public: |
113 /// Constructs an is_null() wheel input event object. | 154 /// Constructs an is_null() wheel input event object. |
114 WheelInputEvent(); | 155 WheelInputEvent(); |
115 | 156 |
116 /// Constructs a wheel input event object from the given generic input | 157 /// 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 | 158 /// provided generic input event. If the given event is itself |
118 /// event, the wheel object will be is_null(). | 159 /// is_null() or is not a wheel input event, the wheel object will be |
160 /// is_null(). | |
dmichael (off chromium)
2011/08/12 20:17:59
missing param? I think it's okay either way, but y
jond
2011/08/12 20:50:59
Done.
| |
119 explicit WheelInputEvent(const InputEvent& event); | 161 explicit WheelInputEvent(const InputEvent& event); |
120 | 162 |
121 /// Constructs a wheel input even from the given parameters. | 163 /// Constructs a wheel input even from the given parameters. |
dmichael (off chromium)
2011/08/12 20:17:59
you added params for the analogous Mouse construct
jond
2011/08/12 20:50:59
Done.
jond
2011/08/12 20:50:59
Done.
| |
122 WheelInputEvent(Instance* instance, | 164 WheelInputEvent(Instance* instance, |
123 PP_TimeTicks time_stamp, | 165 PP_TimeTicks time_stamp, |
124 uint32_t modifiers, | 166 uint32_t modifiers, |
125 const FloatPoint& wheel_delta, | 167 const FloatPoint& wheel_delta, |
126 const FloatPoint& wheel_ticks, | 168 const FloatPoint& wheel_ticks, |
127 bool scroll_by_page); | 169 bool scroll_by_page); |
128 | 170 |
129 /// Indicates the amount vertically and horizontally the user has requested | 171 /// 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 | 172 /// 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 | 173 /// 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 | 174 /// values, and a scroll up or to the left (where the content moves down or |
133 /// represented as negative values. | 175 /// 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 /// | 176 /// |
140 /// This amount is system dependent and will take into account the user's | 177 /// This amount is system dependent and will take into account the user's |
141 /// preferred scroll sensitivity and potentially also nonlinear acceleration | 178 /// preferred scroll sensitivity and potentially also nonlinear acceleration |
142 /// based on the speed of the scrolling. | 179 /// based on the speed of the scrolling. |
143 /// | 180 /// |
144 /// Devices will be of varying resolution. Some mice with large detents will | 181 /// Devices will be of varying resolution. Some mice with large detents will |
145 /// only generate integer scroll amounts. But fractional values are also | 182 /// only generate integer scroll amounts. But fractional values are also |
146 /// possible, for example, on some trackpads and newer mice that don't have | 183 /// possible, for example, on some trackpads and newer mice that don't have |
147 /// "clicks". | 184 /// "clicks". |
185 /// | |
186 /// @return The vertial and horizontal scroll values. The units are either in | |
187 /// pixels (when scroll_by_page is false) or pages (when scroll_by_page is | |
188 /// true). For example, y = -3 means scroll up 3 pixels when scroll_by_page | |
189 /// is false, and scroll up 3 pages when scroll_by_page is true. | |
148 FloatPoint GetDelta() const; | 190 FloatPoint GetDelta() const; |
149 | 191 |
150 /// The number of "clicks" of the scroll wheel that have produced the | 192 /// GetScrollByPage() returns the number of "clicks" of the scroll wheel |
dmichael (off chromium)
2011/08/12 20:17:59
GetScrollByPage->GetTicks
| |
151 /// event. The value may have system-specific acceleration applied to it, | 193 /// that have produced the event. The value may have system-specific |
152 /// depending on the device. The positive and negative meanings are the same | 194 /// acceleration applied to it, depending on the device. The positive and |
153 /// as for GetDelta(). | 195 /// negative meanings are the same as for GetDelta(). |
154 /// | 196 /// |
155 /// If you are scrolling, you probably want to use the delta values. These | 197 /// 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 | 198 /// 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 | 199 /// want or pixel values. An example may be cycling between different items in |
158 /// a game. | 200 /// a game. |
159 /// | 201 /// |
160 /// You may receive fractional values for the wheel ticks if the mouse wheel | 202 /// @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 | 203 /// fractional values for the wheel ticks if the mouse wheel is high |
162 /// discrete events (as in the "picking items" example) you should accumulate | 204 /// resolution or doesn't have "clicks". If your program wants discrete |
205 /// events (as in the "picking items" example) you should accumulate | |
163 /// fractional click values from multiple messages until the total value | 206 /// fractional click values from multiple messages until the total value |
164 /// reaches positive or negative one. This should represent a similar amount | 207 /// reaches positive or negative one. This should represent a similar amount |
165 /// of scrolling as for a mouse that has a discrete mouse wheel. | 208 /// of scrolling as for a mouse that has a discrete mouse wheel. |
166 FloatPoint GetTicks() const; | 209 FloatPoint GetTicks() const; |
167 | 210 |
168 // Indicates if the scroll delta x/y indicates pages or lines to | 211 // Indicates if the scroll delta x/y indicates pages or lines to |
169 // scroll by. | 212 // scroll by. |
170 // | 213 // |
171 // @return PP_TRUE if the event is a wheel event and the user is scrolling | 214 // @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. | 215 // by pages, false if not or if the resource is not a wheel event. |
173 bool GetScrollByPage() const; | 216 bool GetScrollByPage() const; |
174 }; | 217 }; |
175 | 218 |
176 class KeyboardInputEvent : public InputEvent { | 219 class KeyboardInputEvent : public InputEvent { |
177 public: | 220 public: |
178 /// Constructs an is_null() keyboard input event object. | 221 /// Constructs an is_null() keyboard input event object. |
179 KeyboardInputEvent(); | 222 KeyboardInputEvent(); |
180 | 223 |
181 /// Constructs a keyboard input event object from the given generic input | 224 /// 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 | 225 /// event. If the given event is itself is_null() or is not a keyboard input |
183 /// event, the keybaord object will be is_null(). | 226 /// event, the keybaord object will be is_null(). |
227 /// | |
228 /// @param[in] event A generic input event. | |
184 explicit KeyboardInputEvent(const InputEvent& event); | 229 explicit KeyboardInputEvent(const InputEvent& event); |
185 | 230 |
186 /// Constructs a keyboard input even from the given parameters. | 231 /// Constructs a keyboard input even from the given parameters. |
dmichael (off chromium)
2011/08/12 20:17:59
Ditto about params fields; we should probably be c
jond
2011/08/12 20:50:59
Done.
| |
187 KeyboardInputEvent(Instance* instance, | 232 KeyboardInputEvent(Instance* instance, |
188 PP_InputEvent_Type type, | 233 PP_InputEvent_Type type, |
189 PP_TimeTicks time_stamp, | 234 PP_TimeTicks time_stamp, |
190 uint32_t modifiers, | 235 uint32_t modifiers, |
191 uint32_t key_code, | 236 uint32_t key_code, |
192 const Var& character_text); | 237 const Var& character_text); |
193 | 238 |
194 /// Returns the DOM |keyCode| field for the keyboard event. | 239 /// Returns the DOM |keyCode| field for the keyboard event. |
195 /// Chrome populates this with the Windows-style Virtual Key code of the key. | 240 /// Chrome populates this with the Windows-style Virtual Key code of the key. |
196 uint32_t GetKeyCode() const; | 241 uint32_t GetKeyCode() const; |
197 | 242 |
198 /// Returns the typed character for the given character event. | 243 /// Returns the typed character for the given character event. |
199 /// | 244 /// |
200 /// @return A string var representing a single typed character for character | 245 /// @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 | 246 /// input events. For non-character input events the return value will be an |
202 /// undefined var. | 247 /// undefined var. |
203 Var GetCharacterText() const; | 248 Var GetCharacterText() const; |
204 }; | 249 }; |
205 | 250 |
206 } // namespace pp | 251 } // namespace pp |
207 | 252 |
208 #endif // PPAPI_CPP_INPUT_EVENT_H_ | 253 #endif // PPAPI_CPP_INPUT_EVENT_H_ |
OLD | NEW |