| 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 #include <utility> |
| 9 | 10 |
| 10 #include "ppapi/c/ppb_input_event.h" | 11 #include "ppapi/c/ppb_input_event.h" |
| 11 #include "ppapi/cpp/resource.h" | 12 #include "ppapi/cpp/resource.h" |
| 12 | 13 |
| 13 /// @file | 14 /// @file |
| 14 /// This file defines the API used to handle mouse and keyboard input events. | 15 /// This file defines the API used to handle mouse and keyboard input events. |
| 15 | 16 |
| 16 namespace pp { | 17 namespace pp { |
| 17 | 18 |
| 18 class FloatPoint; | 19 class FloatPoint; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 /// This constructor constructs a mouse input event object from the provided | 96 /// This constructor constructs a mouse input event object from the provided |
| 96 /// generic input event. If the given event is itself is_null() or is not | 97 /// generic input event. If the given event is itself is_null() or is not |
| 97 /// a mouse input event, the mouse object will be is_null(). | 98 /// a mouse input event, the mouse object will be is_null(). |
| 98 /// | 99 /// |
| 99 /// @param event An <code>InputEvent</code>. | 100 /// @param event An <code>InputEvent</code>. |
| 100 explicit MouseInputEvent(const InputEvent& event); | 101 explicit MouseInputEvent(const InputEvent& event); |
| 101 | 102 |
| 102 /// This constructor manually constructs a mouse event from the provided | 103 /// This constructor manually constructs a mouse event from the provided |
| 103 /// parameters. | 104 /// parameters. |
| 104 /// | 105 /// |
| 105 /// @param[in] instance The instance for which this event occured. | 106 /// @param[in] instance The instance for which this event occurred. |
| 106 /// | 107 /// |
| 107 /// @param[in] type A <code>PP_InputEvent_Type</code> identifying the type of | 108 /// @param[in] type A <code>PP_InputEvent_Type</code> identifying the type of |
| 108 /// input event. | 109 /// input event. |
| 109 /// | 110 /// |
| 110 /// @param[in] time_stamp A <code>PP_TimeTicks</code> indicating the time | 111 /// @param[in] time_stamp A <code>PP_TimeTicks</code> indicating the time |
| 111 /// when the event occured. | 112 /// when the event occurred. |
| 112 /// | 113 /// |
| 113 /// @param[in] modifiers A bit field combination of the | 114 /// @param[in] modifiers A bit field combination of the |
| 114 /// <code>PP_InputEvent_Modifier</code> flags. | 115 /// <code>PP_InputEvent_Modifier</code> flags. |
| 115 /// | 116 /// |
| 116 /// @param[in] mouse_button The button that changed for mouse down or up | 117 /// @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 /// events. This value will be <code>PP_EVENT_MOUSEBUTTON_NONE</code> for |
| 118 /// mouse move, enter, and leave events. | 119 /// mouse move, enter, and leave events. |
| 119 /// | 120 /// |
| 120 /// @param[in] mouse_position A <code>Point</code> containing the x and y | 121 /// @param[in] mouse_position A <code>Point</code> containing the x and y |
| 121 /// position of the mouse when the eent occurred. | 122 /// position of the mouse when the event occurred. |
| 122 /// | 123 /// |
| 123 /// @param[in] click_count | 124 /// @param[in] click_count |
| 124 /// TODO(brettw) figure out exactly what this means. | 125 /// TODO(brettw) figure out exactly what this means. |
| 125 /// | 126 /// |
| 126 /// @param[in] mouse_movement The change in position of the mouse. | 127 /// @param[in] mouse_movement The change in position of the mouse. |
| 127 MouseInputEvent(Instance* instance, | 128 MouseInputEvent(Instance* instance, |
| 128 PP_InputEvent_Type type, | 129 PP_InputEvent_Type type, |
| 129 PP_TimeTicks time_stamp, | 130 PP_TimeTicks time_stamp, |
| 130 uint32_t modifiers, | 131 uint32_t modifiers, |
| 131 PP_InputEvent_MouseButton mouse_button, | 132 PP_InputEvent_MouseButton mouse_button, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 /// is_null(). | 178 /// is_null(). |
| 178 /// | 179 /// |
| 179 /// @param[in] A generic input event. | 180 /// @param[in] A generic input event. |
| 180 explicit WheelInputEvent(const InputEvent& event); | 181 explicit WheelInputEvent(const InputEvent& event); |
| 181 | 182 |
| 182 /// Constructs a wheel input even from the given parameters. | 183 /// Constructs a wheel input even from the given parameters. |
| 183 /// | 184 /// |
| 184 /// @param[in] instance The instance for which this event occured. | 185 /// @param[in] instance The instance for which this event occured. |
| 185 /// | 186 /// |
| 186 /// @param[in] time_stamp A <code>PP_TimeTicks</code> indicating the time | 187 /// @param[in] time_stamp A <code>PP_TimeTicks</code> indicating the time |
| 187 /// when the event occured. | 188 /// when the event occurred. |
| 188 /// | 189 /// |
| 189 /// @param[in] modifiers A bit field combination of the | 190 /// @param[in] modifiers A bit field combination of the |
| 190 /// <code>PP_InputEvent_Modifier</code> flags. | 191 /// <code>PP_InputEvent_Modifier</code> flags. |
| 191 /// | 192 /// |
| 192 /// @param[in] wheel_delta The scroll wheel's horizontal and vertical scroll | 193 /// @param[in] wheel_delta The scroll wheel's horizontal and vertical scroll |
| 193 /// amounts. | 194 /// amounts. |
| 194 /// | 195 /// |
| 195 /// @param[in] wheel_ticks The number of "clicks" of the scroll wheel that | 196 /// @param[in] wheel_ticks The number of "clicks" of the scroll wheel that |
| 196 /// have produced the event. | 197 /// have produced the event. |
| 197 /// | 198 /// |
| (...skipping 14 matching lines...) Expand all Loading... |
| 212 /// | 213 /// |
| 213 /// This amount is system dependent and will take into account the user's | 214 /// This amount is system dependent and will take into account the user's |
| 214 /// preferred scroll sensitivity and potentially also nonlinear acceleration | 215 /// preferred scroll sensitivity and potentially also nonlinear acceleration |
| 215 /// based on the speed of the scrolling. | 216 /// based on the speed of the scrolling. |
| 216 /// | 217 /// |
| 217 /// Devices will be of varying resolution. Some mice with large detents will | 218 /// Devices will be of varying resolution. Some mice with large detents will |
| 218 /// only generate integer scroll amounts. But fractional values are also | 219 /// only generate integer scroll amounts. But fractional values are also |
| 219 /// possible, for example, on some trackpads and newer mice that don't have | 220 /// possible, for example, on some trackpads and newer mice that don't have |
| 220 /// "clicks". | 221 /// "clicks". |
| 221 /// | 222 /// |
| 222 /// @return The vertial and horizontal scroll values. The units are either in | 223 /// @return The vertical and horizontal scroll values. The units are either in |
| 223 /// pixels (when scroll_by_page is false) or pages (when scroll_by_page is | 224 /// pixels (when scroll_by_page is false) or pages (when scroll_by_page is |
| 224 /// true). For example, y = -3 means scroll up 3 pixels when scroll_by_page | 225 /// true). For example, y = -3 means scroll up 3 pixels when scroll_by_page |
| 225 /// is false, and scroll up 3 pages when scroll_by_page is true. | 226 /// is false, and scroll up 3 pages when scroll_by_page is true. |
| 226 FloatPoint GetDelta() const; | 227 FloatPoint GetDelta() const; |
| 227 | 228 |
| 228 /// GetTicks() returns the number of "clicks" of the scroll wheel | 229 /// GetTicks() returns the number of "clicks" of the scroll wheel |
| 229 /// that have produced the event. The value may have system-specific | 230 /// that have produced the event. The value may have system-specific |
| 230 /// acceleration applied to it, depending on the device. The positive and | 231 /// acceleration applied to it, depending on the device. The positive and |
| 231 /// negative meanings are the same as for GetDelta(). | 232 /// negative meanings are the same as for GetDelta(). |
| 232 /// | 233 /// |
| (...skipping 19 matching lines...) Expand all Loading... |
| 252 bool GetScrollByPage() const; | 253 bool GetScrollByPage() const; |
| 253 }; | 254 }; |
| 254 | 255 |
| 255 class KeyboardInputEvent : public InputEvent { | 256 class KeyboardInputEvent : public InputEvent { |
| 256 public: | 257 public: |
| 257 /// Constructs an is_null() keyboard input event object. | 258 /// Constructs an is_null() keyboard input event object. |
| 258 KeyboardInputEvent(); | 259 KeyboardInputEvent(); |
| 259 | 260 |
| 260 /// Constructs a keyboard input event object from the provided generic input | 261 /// Constructs a keyboard input event object from the provided generic input |
| 261 /// event. If the given event is itself is_null() or is not a keyboard input | 262 /// event. If the given event is itself is_null() or is not a keyboard input |
| 262 /// event, the keybaord object will be is_null(). | 263 /// event, the keyboard object will be is_null(). |
| 263 /// | 264 /// |
| 264 /// @param[in] event A generic input event. | 265 /// @param[in] event A generic input event. |
| 265 explicit KeyboardInputEvent(const InputEvent& event); | 266 explicit KeyboardInputEvent(const InputEvent& event); |
| 266 | 267 |
| 267 /// Constructs a keyboard input even from the given parameters. | 268 /// Constructs a keyboard input even from the given parameters. |
| 268 /// | 269 /// |
| 269 /// @param[in] instance The instance for which this event occured. | 270 /// @param[in] instance The instance for which this event occurred. |
| 270 /// | 271 /// |
| 271 /// @param[in] type A <code>PP_InputEvent_Type</code> identifying the type of | 272 /// @param[in] type A <code>PP_InputEvent_Type</code> identifying the type of |
| 272 /// input event. | 273 /// input event. |
| 273 /// | 274 /// |
| 274 /// @param[in] time_stamp A <code>PP_TimeTicks</code> indicating the time | 275 /// @param[in] time_stamp A <code>PP_TimeTicks</code> indicating the time |
| 275 /// when the event occured. | 276 /// when the event occurred. |
| 276 /// | 277 /// |
| 277 /// @param[in] modifiers A bit field combination of the | 278 /// @param[in] modifiers A bit field combination of the |
| 278 /// <code>PP_InputEvent_Modifier</code> flags. | 279 /// <code>PP_InputEvent_Modifier</code> flags. |
| 279 /// | 280 /// |
| 280 /// @param[in] key_code This value reflects the DOM KeyboardEvent | 281 /// @param[in] key_code This value reflects the DOM KeyboardEvent |
| 281 /// <code>keyCode</code> field. Chrome populates this with the Windows-style | 282 /// <code>keyCode</code> field. Chrome populates this with the Windows-style |
| 282 /// Virtual Key code of the key. | 283 /// Virtual Key code of the key. |
| 283 /// | 284 /// |
| 284 /// @param[in] character_text This value represents the typed character as a | 285 /// @param[in] character_text This value represents the typed character as a |
| 285 /// UTF-8 string. | 286 /// UTF-8 string. |
| 286 KeyboardInputEvent(Instance* instance, | 287 KeyboardInputEvent(Instance* instance, |
| 287 PP_InputEvent_Type type, | 288 PP_InputEvent_Type type, |
| 288 PP_TimeTicks time_stamp, | 289 PP_TimeTicks time_stamp, |
| 289 uint32_t modifiers, | 290 uint32_t modifiers, |
| 290 uint32_t key_code, | 291 uint32_t key_code, |
| 291 const Var& character_text); | 292 const Var& character_text); |
| 292 | 293 |
| 293 /// Returns the DOM keyCode field for the keyboard event. | 294 /// Returns the DOM keyCode field for the keyboard event. |
| 294 /// Chrome populates this with the Windows-style Virtual Key code of the key. | 295 /// Chrome populates this with the Windows-style Virtual Key code of the key. |
| 295 uint32_t GetKeyCode() const; | 296 uint32_t GetKeyCode() const; |
| 296 | 297 |
| 297 /// Returns the typed character for the given character event. | 298 /// Returns the typed character for the given character event. |
| 298 /// | 299 /// |
| 299 /// @return A string var representing a single typed character for character | 300 /// @return A string var representing a single typed character for character |
| 300 /// input events. For non-character input events the return value will be an | 301 /// input events. For non-character input events the return value will be an |
| 301 /// undefined var. | 302 /// undefined var. |
| 302 Var GetCharacterText() const; | 303 Var GetCharacterText() const; |
| 303 }; | 304 }; |
| 304 | 305 |
| 306 class CompositionInputEvent : public InputEvent { |
| 307 public: |
| 308 /// Constructs an is_null() composition input event object. |
| 309 CompositionInputEvent(); |
| 310 |
| 311 /// Constructs a composition input event object from the provided generic |
| 312 /// input event. If the given event is itself is_null() or is not a |
| 313 /// composition input event, the composition object will be is_null(). |
| 314 /// |
| 315 /// @param[in] event A generic input event. |
| 316 explicit CompositionInputEvent(const InputEvent& event); |
| 317 |
| 318 /// Returns the composition text as a UTF-8 string for the given composition |
| 319 /// event. |
| 320 /// |
| 321 /// @return A string var representing the composition text. For non- |
| 322 /// composition input events the return value will be an undefined var. |
| 323 Var GetText() const; |
| 324 |
| 325 /// Returns the number of segments in the composition text. |
| 326 /// |
| 327 /// @return The number of segments. For events other than COMPOSITION_UPDATE, |
| 328 /// returns 0. |
| 329 uint32_t GetSegmentNumber() const; |
| 330 |
| 331 /// Returns the start and the end position of the index-th segment in the |
| 332 /// composition text. The positions are given by byte-indices of the string |
| 333 /// GetText(). They always satisfy 0 <= .first < .second <= (Length of |
| 334 /// GetText()) and GetSegmentAt(index).first < GetSegmentAt(index+1).first. |
| 335 /// When the event is not COMPOSITION_UPDATE or index >= GetSegmentNumber(), |
| 336 /// returns (0, 0). |
| 337 /// |
| 338 /// @param[in] index An integer indicating a segment. |
| 339 /// |
| 340 /// @return A pair of integers representing the index-th segment. |
| 341 std::pair<uint32_t, uint32_t> GetSegmentAt(uint32_t index) const; |
| 342 |
| 343 /// Returns the index of the current target segment of composition. |
| 344 /// |
| 345 /// @return An integer indicating the index of the target segment. When there |
| 346 /// is no active target segment, or the event is not COMPOSITION_UPDATE, |
| 347 /// returns -1. |
| 348 int32_t GetTargetSegment() const; |
| 349 |
| 350 /// Returns the range selected by caret in the composition text. |
| 351 /// |
| 352 /// @return A pair of integers indicating the selection range. |
| 353 std::pair<uint32_t, uint32_t> GetSelection() const; |
| 354 }; |
| 355 |
| 305 } // namespace pp | 356 } // namespace pp |
| 306 | 357 |
| 307 #endif // PPAPI_CPP_INPUT_EVENT_H_ | 358 #endif // PPAPI_CPP_INPUT_EVENT_H_ |
| OLD | NEW |