| 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_DEV_IME_INPUT_EVENT_DEV_H_ | 5 #ifndef PPAPI_CPP_IME_INPUT_EVENT_H_ |
| 6 #define PPAPI_CPP_DEV_IME_INPUT_EVENT_DEV_H_ | 6 #define PPAPI_CPP_IME_INPUT_EVENT_H_ |
| 7 | 7 |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "ppapi/c/dev/ppb_ime_input_event_dev.h" | 11 #include "ppapi/c/ppb_ime_input_event.h" |
| 12 #include "ppapi/cpp/input_event.h" | 12 #include "ppapi/cpp/input_event.h" |
| 13 | 13 |
| 14 /// @file | 14 /// @file |
| 15 /// This file defines the API used to handle IME input events. | 15 /// This file defines the API used to handle IME input events. |
| 16 | 16 |
| 17 namespace pp { | 17 namespace pp { |
| 18 | 18 |
| 19 class Var; | 19 class Var; |
| 20 | 20 |
| 21 class IMEInputEvent_Dev : public InputEvent { | 21 class IMEInputEvent : public InputEvent { |
| 22 public: | 22 public: |
| 23 /// Constructs an is_null() IME input event object. | 23 /// Constructs an is_null() IME input event object. |
| 24 IMEInputEvent_Dev(); | 24 IMEInputEvent(); |
| 25 | 25 |
| 26 /// Constructs an IME input event object from the provided generic input | 26 /// Constructs an IME input event object from the provided generic input |
| 27 /// event. If the given event is itself is_null() or is not an IME input | 27 /// event. If the given event is itself is_null() or is not an IME input |
| 28 /// event, the object will be is_null(). | 28 /// event, the object will be is_null(). |
| 29 /// | 29 /// |
| 30 /// @param[in] event A generic input event. | 30 /// @param[in] event A generic input event. |
| 31 explicit IMEInputEvent_Dev(const InputEvent& event); | 31 explicit IMEInputEvent(const InputEvent& event); |
| 32 | 32 |
| 33 /// This constructor manually constructs an IME event from the provided | 33 /// This constructor manually constructs an IME event from the provided |
| 34 /// parameters. | 34 /// parameters. |
| 35 /// | 35 /// |
| 36 /// @param[in] instance The instance for which this event occurred. | 36 /// @param[in] instance The instance for which this event occurred. |
| 37 /// | 37 /// |
| 38 /// @param[in] type A <code>PP_InputEvent_Type</code> identifying the type of | 38 /// @param[in] type A <code>PP_InputEvent_Type</code> identifying the type of |
| 39 /// input event. The type must be one of the ime event types. | 39 /// input event. The type must be one of the ime event types. |
| 40 /// | 40 /// |
| 41 /// @param[in] time_stamp A <code>PP_TimeTicks</code> indicating the time | 41 /// @param[in] time_stamp A <code>PP_TimeTicks</code> indicating the time |
| 42 /// when the event occurred. | 42 /// when the event occurred. |
| 43 /// | 43 /// |
| 44 /// @param[in] text The string returned by <code>GetText</code>. | 44 /// @param[in] text The string returned by <code>GetText</code>. |
| 45 /// | 45 /// |
| 46 /// @param[in] segment_offsets The array of numbers returned by | 46 /// @param[in] segment_offsets The array of numbers returned by |
| 47 /// <code>GetSegmentOffset</code>. | 47 /// <code>GetSegmentOffset</code>. |
| 48 /// | 48 /// |
| 49 /// @param[in] target_segment The number returned by | 49 /// @param[in] target_segment The number returned by |
| 50 /// <code>GetTargetSegment</code>. | 50 /// <code>GetTargetSegment</code>. |
| 51 /// | 51 /// |
| 52 /// @param[in] selection The range returned by <code>GetSelection</code>. | 52 /// @param[in] selection The range returned by <code>GetSelection</code>. |
| 53 IMEInputEvent_Dev(const InstanceHandle& instance, | 53 IMEInputEvent(const InstanceHandle& instance, |
| 54 PP_InputEvent_Type type, | 54 PP_InputEvent_Type type, |
| 55 PP_TimeTicks time_stamp, | 55 PP_TimeTicks time_stamp, |
| 56 const Var& text, | 56 const Var& text, |
| 57 const std::vector<uint32_t>& segment_offsets, | 57 const std::vector<uint32_t>& segment_offsets, |
| 58 int32_t target_segment, | 58 int32_t target_segment, |
| 59 const std::pair<uint32_t, uint32_t>& selection); | 59 const std::pair<uint32_t, uint32_t>& selection); |
| 60 | 60 |
| 61 /// Returns the composition text as a UTF-8 string for the given IME event. | 61 /// Returns the composition text as a UTF-8 string for the given IME event. |
| 62 /// | 62 /// |
| 63 /// @return A string var representing the composition text. For non-IME | 63 /// @return A string var representing the composition text. For non-IME |
| 64 /// input events the return value will be an undefined var. | 64 /// input events the return value will be an undefined var. |
| 65 Var GetText() const; | 65 Var GetText() const; |
| 66 | 66 |
| 67 /// Returns the number of segments in the composition text. | 67 /// Returns the number of segments in the composition text. |
| 68 /// | 68 /// |
| 69 /// @return The number of segments. For events other than COMPOSITION_UPDATE, | 69 /// @return The number of segments. For events other than COMPOSITION_UPDATE, |
| 70 /// returns 0. | 70 /// returns 0. |
| 71 uint32_t GetSegmentNumber() const; | 71 uint32_t GetSegmentCount() const; |
| 72 | 72 |
| 73 /// Returns the position of the index-th segmentation point in the composition | 73 /// Returns the position of the index-th segmentation point in the composition |
| 74 /// text. The position is given by a byte-offset (not a character-offset) of | 74 /// text. The position is given by a byte-offset (not a character-offset) of |
| 75 /// the string returned by GetText(). It always satisfies | 75 /// the string returned by GetText(). It always satisfies |
| 76 /// 0=GetSegmentOffset(0) < ... < GetSegmentOffset(i) < GetSegmentOffset(i+1) | 76 /// 0=GetSegmentOffset(0) < ... < GetSegmentOffset(i) < GetSegmentOffset(i+1) |
| 77 /// < ... < GetSegmentOffset(GetSegmentNumber())=(byte-length of GetText()). | 77 /// < ... < GetSegmentOffset(GetSegmentCount())=(byte-length of GetText()). |
| 78 /// Note that [GetSegmentOffset(i), GetSegmentOffset(i+1)) represents the | 78 /// Note that [GetSegmentOffset(i), GetSegmentOffset(i+1)) represents the |
| 79 /// range of the i-th segment, and hence GetSegmentNumber() can be a valid | 79 /// range of the i-th segment, and hence GetSegmentCount() can be a valid |
| 80 /// argument to this function instead of an off-by-1 error. | 80 /// argument to this function instead of an off-by-1 error. |
| 81 /// | 81 /// |
| 82 /// @param[in] ime_event A <code>PP_Resource</code> corresponding to an IME | 82 /// @param[in] ime_event A <code>PP_Resource</code> corresponding to an IME |
| 83 /// event. | 83 /// event. |
| 84 /// | 84 /// |
| 85 /// @param[in] index An integer indicating a segment. | 85 /// @param[in] index An integer indicating a segment. |
| 86 /// | 86 /// |
| 87 /// @return The byte-offset of the segmentation point. If the event is not | 87 /// @return The byte-offset of the segmentation point. If the event is not |
| 88 /// COMPOSITION_UPDATE or index is out of range, returns 0. | 88 /// COMPOSITION_UPDATE or index is out of range, returns 0. |
| 89 uint32_t GetSegmentOffset(uint32_t index) const; | 89 uint32_t GetSegmentOffset(uint32_t index) const; |
| 90 | 90 |
| 91 /// Returns the index of the current target segment of composition. | 91 /// Returns the index of the current target segment of composition. |
| 92 /// | 92 /// |
| 93 /// @return An integer indicating the index of the target segment. When there | 93 /// @return An integer indicating the index of the target segment. When there |
| 94 /// is no active target segment, or the event is not COMPOSITION_UPDATE, | 94 /// is no active target segment, or the event is not COMPOSITION_UPDATE, |
| 95 /// returns -1. | 95 /// returns -1. |
| 96 int32_t GetTargetSegment() const; | 96 int32_t GetTargetSegment() const; |
| 97 | 97 |
| 98 /// Returns the range selected by caret in the composition text. | 98 /// Returns the range selected by caret in the composition text. |
| 99 /// | 99 /// |
| 100 /// @return A pair of integers indicating the selection range. | 100 /// @return A pair of integers indicating the selection range. |
| 101 std::pair<uint32_t, uint32_t> GetSelection() const; | 101 std::pair<uint32_t, uint32_t> GetSelection() const; |
| 102 }; | 102 }; |
| 103 | 103 |
| 104 } // namespace pp | 104 } // namespace pp |
| 105 | 105 |
| 106 #endif // PPAPI_CPP_DEV_IME_INPUT_EVENT_DEV_H_ | 106 #endif // PPAPI_CPP_IME_INPUT_EVENT_H_ |
| OLD | NEW |