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
3 // found in the LICENSE file.
5 #ifndef PPAPI_CPP_DEV_IME_INPUT_EVENT_DEV_H_
6 #define PPAPI_CPP_DEV_IME_INPUT_EVENT_DEV_H_
11 #include "ppapi/c/dev/ppb_ime_input_event_dev.h"
12 #include "ppapi/cpp/input_event.h"
15 /// This file defines the API used to handle IME input events.
21 class IMEInputEvent_Dev
: public InputEvent
{
23 /// Constructs an is_null() IME input event object.
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
28 /// event, the object will be is_null().
30 /// @param[in] event A generic input event.
31 explicit IMEInputEvent_Dev(const InputEvent
& event
);
33 /// This constructor manually constructs an IME event from the provided
36 /// @param[in] instance The instance for which this event occurred.
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.
41 /// @param[in] time_stamp A <code>PP_TimeTicks</code> indicating the time
42 /// when the event occurred.
44 /// @param[in] text The string returned by <code>GetText</code>.
46 /// @param[in] segment_offsets The array of numbers returned by
47 /// <code>GetSegmentOffset</code>.
49 /// @param[in] target_segment The number returned by
50 /// <code>GetTargetSegment</code>.
52 /// @param[in] selection The range returned by <code>GetSelection</code>.
53 IMEInputEvent_Dev(const InstanceHandle
& instance
,
54 PP_InputEvent_Type type
,
55 PP_TimeTicks time_stamp
,
57 const std::vector
<uint32_t>& segment_offsets
,
58 int32_t target_segment
,
59 const std::pair
<uint32_t, uint32_t>& selection
);
61 /// Returns the composition text as a UTF-8 string for the given IME event.
63 /// @return A string var representing the composition text. For non-IME
64 /// input events the return value will be an undefined var.
67 /// Returns the number of segments in the composition text.
69 /// @return The number of segments. For events other than COMPOSITION_UPDATE,
71 uint32_t GetSegmentNumber() const;
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
75 /// the string returned by GetText(). It always satisfies
76 /// 0=GetSegmentOffset(0) < ... < GetSegmentOffset(i) < GetSegmentOffset(i+1)
77 /// < ... < GetSegmentOffset(GetSegmentNumber())=(byte-length of GetText()).
78 /// Note that [GetSegmentOffset(i), GetSegmentOffset(i+1)) represents the
79 /// range of the i-th segment, and hence GetSegmentNumber() can be a valid
80 /// argument to this function instead of an off-by-1 error.
82 /// @param[in] ime_event A <code>PP_Resource</code> corresponding to an IME
85 /// @param[in] index An integer indicating a segment.
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.
89 uint32_t GetSegmentOffset(uint32_t index
) const;
91 /// Returns the index of the current target segment of composition.
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,
96 int32_t GetTargetSegment() const;
98 /// Returns the range selected by caret in the composition text.
100 /// @return A pair of integers indicating the selection range.
101 std::pair
<uint32_t, uint32_t> GetSelection() const;
106 #endif // PPAPI_CPP_DEV_IME_INPUT_EVENT_DEV_H_