15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef PPAPI_CPP_DEV_IME_INPUT_EVENT_DEV_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define PPAPI_CPP_DEV_IME_INPUT_EVENT_DEV_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <utility> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector> 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/c/dev/ppb_ime_input_event_dev.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/cpp/input_event.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// @file 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// This file defines the API used to handle IME input events. 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace pp { 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Var; 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class IMEInputEvent_Dev : public InputEvent { 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// Constructs an is_null() IME input event object. 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) IMEInputEvent_Dev(); 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// Constructs an IME input event object from the provided generic input 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// event. If the given event is itself is_null() or is not an IME input 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// event, the object will be is_null(). 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// @param[in] event A generic input event. 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) explicit IMEInputEvent_Dev(const InputEvent& event); 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// This constructor manually constructs an IME event from the provided 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// parameters. 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// @param[in] instance The instance for which this event occurred. 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// @param[in] type A <code>PP_InputEvent_Type</code> identifying the type of 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// input event. The type must be one of the ime event types. 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// @param[in] time_stamp A <code>PP_TimeTicks</code> indicating the time 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// when the event occurred. 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// @param[in] text The string returned by <code>GetText</code>. 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// @param[in] segment_offsets The array of numbers returned by 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// <code>GetSegmentOffset</code>. 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// @param[in] target_segment The number returned by 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// <code>GetTargetSegment</code>. 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// @param[in] selection The range returned by <code>GetSelection</code>. 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) IMEInputEvent_Dev(const InstanceHandle& instance, 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PP_InputEvent_Type type, 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PP_TimeTicks time_stamp, 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Var& text, 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::vector<uint32_t>& segment_offsets, 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int32_t target_segment, 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::pair<uint32_t, uint32_t>& selection); 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// Returns the composition text as a UTF-8 string for the given IME event. 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// @return A string var representing the composition text. For non-IME 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// input events the return value will be an undefined var. 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Var GetText() const; 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// Returns the number of segments in the composition text. 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// @return The number of segments. For events other than COMPOSITION_UPDATE, 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// returns 0. 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) uint32_t GetSegmentNumber() const; 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// Returns the position of the index-th segmentation point in the composition 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// text. The position is given by a byte-offset (not a character-offset) of 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// the string returned by GetText(). It always satisfies 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// 0=GetSegmentOffset(0) < ... < GetSegmentOffset(i) < GetSegmentOffset(i+1) 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// < ... < GetSegmentOffset(GetSegmentNumber())=(byte-length of GetText()). 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// Note that [GetSegmentOffset(i), GetSegmentOffset(i+1)) represents the 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// range of the i-th segment, and hence GetSegmentNumber() can be a valid 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// argument to this function instead of an off-by-1 error. 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// @param[in] ime_event A <code>PP_Resource</code> corresponding to an IME 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// event. 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// @param[in] index An integer indicating a segment. 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// @return The byte-offset of the segmentation point. If the event is not 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// COMPOSITION_UPDATE or index is out of range, returns 0. 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) uint32_t GetSegmentOffset(uint32_t index) const; 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// Returns the index of the current target segment of composition. 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// @return An integer indicating the index of the target segment. When there 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// is no active target segment, or the event is not COMPOSITION_UPDATE, 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// returns -1. 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int32_t GetTargetSegment() const; 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// Returns the range selected by caret in the composition text. 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// @return A pair of integers indicating the selection range. 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::pair<uint32_t, uint32_t> GetSelection() const; 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace pp 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // PPAPI_CPP_DEV_IME_INPUT_EVENT_DEV_H_ 107