OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <vector> |
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 #include "ppapi/cpp/touch_point.h" | 13 #include "ppapi/cpp/touch_point.h" |
13 | 14 |
14 /// @file | 15 /// @file |
15 /// This file defines the API used to handle mouse and keyboard input events. | 16 /// This file defines the API used to handle mouse and keyboard input events. |
16 | 17 |
17 namespace pp { | 18 namespace pp { |
18 | 19 |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 /// @return The TouchPoint at the given index of the given list, or an empty | 336 /// @return The TouchPoint at the given index of the given list, or an empty |
336 /// TouchPoint if the index is out of range. | 337 /// TouchPoint if the index is out of range. |
337 TouchPoint GetTouchByIndex(PP_TouchListType list, uint32_t index) const; | 338 TouchPoint GetTouchByIndex(PP_TouchListType list, uint32_t index) const; |
338 | 339 |
339 /// @return The TouchPoint in the given list with the given identifier, or an | 340 /// @return The TouchPoint in the given list with the given identifier, or an |
340 /// empty TouchPoint if the list does not contain a TouchPoint with that | 341 /// empty TouchPoint if the list does not contain a TouchPoint with that |
341 /// identifier. | 342 /// identifier. |
342 TouchPoint GetTouchById(PP_TouchListType list, uint32_t id) const; | 343 TouchPoint GetTouchById(PP_TouchListType list, uint32_t id) const; |
343 }; | 344 }; |
344 | 345 |
| 346 class IMEInputEvent : public InputEvent { |
| 347 public: |
| 348 /// Constructs an is_null() IME input event object. |
| 349 IMEInputEvent(); |
345 | 350 |
| 351 /// Constructs an IME input event object from the provided generic input |
| 352 /// event. If the given event is itself is_null() or is not an IME input |
| 353 /// event, the object will be is_null(). |
| 354 /// |
| 355 /// @param[in] event A generic input event. |
| 356 explicit IMEInputEvent(const InputEvent& event); |
| 357 |
| 358 /// This constructor manually constructs an IME event from the provided |
| 359 /// parameters. |
| 360 /// |
| 361 /// @param[in] instance The instance for which this event occurred. |
| 362 /// |
| 363 /// @param[in] type A <code>PP_InputEvent_Type</code> identifying the type of |
| 364 /// input event. The type must be one of the ime event types. |
| 365 /// |
| 366 /// @param[in] time_stamp A <code>PP_TimeTicks</code> indicating the time |
| 367 /// when the event occurred. |
| 368 /// |
| 369 /// @param[in] text The string returned by <code>GetText</code>. |
| 370 /// |
| 371 /// @param[in] segment_offsets The array of numbers returned by |
| 372 /// <code>GetSegmentOffset</code>. |
| 373 /// |
| 374 /// @param[in] target_segment The number returned by |
| 375 /// <code>GetTargetSegment</code>. |
| 376 /// |
| 377 /// @param[in] selection The range returned by <code>GetSelection</code>. |
| 378 IMEInputEvent(const InstanceHandle& instance, |
| 379 PP_InputEvent_Type type, |
| 380 PP_TimeTicks time_stamp, |
| 381 const Var& text, |
| 382 const std::vector<uint32_t>& segment_offsets, |
| 383 int32_t target_segment, |
| 384 const std::pair<uint32_t, uint32_t>& selection); |
| 385 |
| 386 /// Returns the composition text as a UTF-8 string for the given IME event. |
| 387 /// |
| 388 /// @return A string var representing the composition text. For non-IME |
| 389 /// input events the return value will be an undefined var. |
| 390 Var GetText() const; |
| 391 |
| 392 /// Returns the number of segments in the composition text. |
| 393 /// |
| 394 /// @return The number of segments. For events other than COMPOSITION_UPDATE, |
| 395 /// returns 0. |
| 396 uint32_t GetSegmentNumber() const; |
| 397 |
| 398 /// Returns the position of the index-th segmentation point in the composition |
| 399 /// text. The position is given by a byte-offset (not a character-offset) of |
| 400 /// the string returned by GetText(). It always satisfies |
| 401 /// 0=GetSegmentOffset(0) < ... < GetSegmentOffset(i) < GetSegmentOffset(i+1) |
| 402 /// < ... < GetSegmentOffset(GetSegmentNumber())=(byte-length of GetText()). |
| 403 /// Note that [GetSegmentOffset(i), GetSegmentOffset(i+1)) represents the |
| 404 /// range of the i-th segment, and hence GetSegmentNumber() can be a valid |
| 405 /// argument to this function instead of an off-by-1 error. |
| 406 /// |
| 407 /// @param[in] ime_event A <code>PP_Resource</code> corresponding to an IME |
| 408 /// event. |
| 409 /// |
| 410 /// @param[in] index An integer indicating a segment. |
| 411 /// |
| 412 /// @return The byte-offset of the segmentation point. If the event is not |
| 413 /// COMPOSITION_UPDATE or index is out of range, returns 0. |
| 414 uint32_t GetSegmentOffset(uint32_t index) const; |
| 415 |
| 416 /// Returns the index of the current target segment of composition. |
| 417 /// |
| 418 /// @return An integer indicating the index of the target segment. When there |
| 419 /// is no active target segment, or the event is not COMPOSITION_UPDATE, |
| 420 /// returns -1. |
| 421 int32_t GetTargetSegment() const; |
| 422 |
| 423 /// Obtains the range selected by caret in the composition text. |
| 424 /// |
| 425 /// @param[out] start An integer indicating a start offset of selection range. |
| 426 /// |
| 427 /// @param[out] end An integer indicating an end offset of selection range. |
| 428 void GetSelection(uint32_t* start, uint32_t* end) const; |
| 429 }; |
346 } // namespace pp | 430 } // namespace pp |
347 | 431 |
348 #endif // PPAPI_CPP_INPUT_EVENT_H_ | 432 #endif // PPAPI_CPP_INPUT_EVENT_H_ |
OLD | NEW |