diff options
author | nona@chromium.org <nona@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-01 00:22:48 +0000 |
---|---|---|
committer | nona@chromium.org <nona@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-01 00:22:48 +0000 |
commit | 79cad34f87841d010fd39023d369e406daef39f7 (patch) | |
tree | 4bf8330916574fe9fa103f92c381f77d36ffdf73 /ppapi/cpp | |
parent | 934e3c950dad11ddc4198005ea2bc5ec6df3a5ec (diff) | |
download | chromium_src-79cad34f87841d010fd39023d369e406daef39f7.zip chromium_src-79cad34f87841d010fd39023d369e406daef39f7.tar.gz chromium_src-79cad34f87841d010fd39023d369e406daef39f7.tar.bz2 |
PPAPI: Move IMEInputEvent and TextInput to stable.
To be able to work with current ppapi Flash, this CL keeps ABI of "PPB_IMEInputEvent_Dev_0_2", "PPB_TextInput_Dev_0_2" and "PPP_TextInput_Dev_0_2".
BUG=None
TEST=Manually checked that ppapi_example_ime works and also works with current Flash.
NOTRY=True
Review URL: https://chromiumcodereview.appspot.com/18671004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@214878 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/cpp')
-rw-r--r-- | ppapi/cpp/input_event.cc | 79 | ||||
-rw-r--r-- | ppapi/cpp/input_event.h | 84 | ||||
-rw-r--r-- | ppapi/cpp/text_input_controller.cc | 63 | ||||
-rw-r--r-- | ppapi/cpp/text_input_controller.h | 73 |
4 files changed, 299 insertions, 0 deletions
diff --git a/ppapi/cpp/input_event.cc b/ppapi/cpp/input_event.cc index 1f368b0..e4e0003 100644 --- a/ppapi/cpp/input_event.cc +++ b/ppapi/cpp/input_event.cc @@ -35,6 +35,10 @@ template <> const char* interface_name<PPB_TouchInputEvent_1_0>() { return PPB_TOUCH_INPUT_EVENT_INTERFACE_1_0; } +template <> const char* interface_name<PPB_IMEInputEvent_1_0>() { + return PPB_IME_INPUT_EVENT_INTERFACE_1_0; +} + } // namespace // InputEvent ------------------------------------------------------------------ @@ -280,4 +284,79 @@ TouchPoint TouchInputEvent::GetTouchByIndex(PP_TouchListType list, GetTouchByIndex(pp_resource(), list, index)); } +// IMEInputEvent ------------------------------------------------------- + +IMEInputEvent::IMEInputEvent() : InputEvent() { +} + +IMEInputEvent::IMEInputEvent(const InputEvent& event) : InputEvent() { + if (has_interface<PPB_IMEInputEvent_1_0>()) { + if (get_interface<PPB_IMEInputEvent_1_0>()->IsIMEInputEvent( + event.pp_resource())) { + Module::Get()->core()->AddRefResource(event.pp_resource()); + PassRefFromConstructor(event.pp_resource()); + } + } +} + +IMEInputEvent::IMEInputEvent( + const InstanceHandle& instance, + PP_InputEvent_Type type, + PP_TimeTicks time_stamp, + const Var& text, + const std::vector<uint32_t>& segment_offsets, + int32_t target_segment, + const std::pair<uint32_t, uint32_t>& selection) : InputEvent() { + if (!has_interface<PPB_IMEInputEvent_1_0>()) + return; + uint32_t dummy = 0; + PassRefFromConstructor(get_interface<PPB_IMEInputEvent_1_0>()->Create( + instance.pp_instance(), type, time_stamp, text.pp_var(), + segment_offsets.empty() ? 0 : segment_offsets.size() - 1, + segment_offsets.empty() ? &dummy : &segment_offsets[0], + target_segment, selection.first, selection.second)); +} + + +Var IMEInputEvent::GetText() const { + if (has_interface<PPB_IMEInputEvent_1_0>()) { + return Var(PASS_REF, + get_interface<PPB_IMEInputEvent_1_0>()->GetText( + pp_resource())); + } + return Var(); +} + +uint32_t IMEInputEvent::GetSegmentNumber() const { + if (has_interface<PPB_IMEInputEvent_1_0>()) { + return get_interface<PPB_IMEInputEvent_1_0>()->GetSegmentNumber( + pp_resource()); + } + return 0; +} + +uint32_t IMEInputEvent::GetSegmentOffset(uint32_t index) const { + if (has_interface<PPB_IMEInputEvent_1_0>()) { + return get_interface<PPB_IMEInputEvent_1_0>()->GetSegmentOffset( + pp_resource(), index); + } + return 0; +} + +int32_t IMEInputEvent::GetTargetSegment() const { + if (has_interface<PPB_IMEInputEvent_1_0>()) { + return get_interface<PPB_IMEInputEvent_1_0>()->GetTargetSegment( + pp_resource()); + } + return 0; +} + +void IMEInputEvent::GetSelection(uint32_t* start, uint32_t* end) const { + if (has_interface<PPB_IMEInputEvent_1_0>()) { + get_interface<PPB_IMEInputEvent_1_0>()->GetSelection(pp_resource(), + start, + end); + } +} + } // namespace pp diff --git a/ppapi/cpp/input_event.h b/ppapi/cpp/input_event.h index 40e1df1..6965184 100644 --- a/ppapi/cpp/input_event.h +++ b/ppapi/cpp/input_event.h @@ -6,6 +6,7 @@ #define PPAPI_CPP_INPUT_EVENT_H_ #include <string> +#include <vector> #include "ppapi/c/ppb_input_event.h" #include "ppapi/cpp/resource.h" @@ -342,7 +343,90 @@ class TouchInputEvent : public InputEvent { TouchPoint GetTouchById(PP_TouchListType list, uint32_t id) const; }; +class IMEInputEvent : public InputEvent { + public: + /// Constructs an is_null() IME input event object. + IMEInputEvent(); + + /// Constructs an IME input event object from the provided generic input + /// event. If the given event is itself is_null() or is not an IME input + /// event, the object will be is_null(). + /// + /// @param[in] event A generic input event. + explicit IMEInputEvent(const InputEvent& event); + + /// This constructor manually constructs an IME event from the provided + /// parameters. + /// + /// @param[in] instance The instance for which this event occurred. + /// + /// @param[in] type A <code>PP_InputEvent_Type</code> identifying the type of + /// input event. The type must be one of the ime event types. + /// + /// @param[in] time_stamp A <code>PP_TimeTicks</code> indicating the time + /// when the event occurred. + /// + /// @param[in] text The string returned by <code>GetText</code>. + /// + /// @param[in] segment_offsets The array of numbers returned by + /// <code>GetSegmentOffset</code>. + /// + /// @param[in] target_segment The number returned by + /// <code>GetTargetSegment</code>. + /// + /// @param[in] selection The range returned by <code>GetSelection</code>. + IMEInputEvent(const InstanceHandle& instance, + PP_InputEvent_Type type, + PP_TimeTicks time_stamp, + const Var& text, + const std::vector<uint32_t>& segment_offsets, + int32_t target_segment, + const std::pair<uint32_t, uint32_t>& selection); + + /// Returns the composition text as a UTF-8 string for the given IME event. + /// + /// @return A string var representing the composition text. For non-IME + /// input events the return value will be an undefined var. + Var GetText() const; + /// Returns the number of segments in the composition text. + /// + /// @return The number of segments. For events other than COMPOSITION_UPDATE, + /// returns 0. + uint32_t GetSegmentNumber() const; + + /// Returns the position of the index-th segmentation point in the composition + /// text. The position is given by a byte-offset (not a character-offset) of + /// the string returned by GetText(). It always satisfies + /// 0=GetSegmentOffset(0) < ... < GetSegmentOffset(i) < GetSegmentOffset(i+1) + /// < ... < GetSegmentOffset(GetSegmentNumber())=(byte-length of GetText()). + /// Note that [GetSegmentOffset(i), GetSegmentOffset(i+1)) represents the + /// range of the i-th segment, and hence GetSegmentNumber() can be a valid + /// argument to this function instead of an off-by-1 error. + /// + /// @param[in] ime_event A <code>PP_Resource</code> corresponding to an IME + /// event. + /// + /// @param[in] index An integer indicating a segment. + /// + /// @return The byte-offset of the segmentation point. If the event is not + /// COMPOSITION_UPDATE or index is out of range, returns 0. + uint32_t GetSegmentOffset(uint32_t index) const; + + /// Returns the index of the current target segment of composition. + /// + /// @return An integer indicating the index of the target segment. When there + /// is no active target segment, or the event is not COMPOSITION_UPDATE, + /// returns -1. + int32_t GetTargetSegment() const; + + /// Obtains the range selected by caret in the composition text. + /// + /// @param[out] start An integer indicating a start offset of selection range. + /// + /// @param[out] end An integer indicating an end offset of selection range. + void GetSelection(uint32_t* start, uint32_t* end) const; +}; } // namespace pp #endif // PPAPI_CPP_INPUT_EVENT_H_ diff --git a/ppapi/cpp/text_input_controller.cc b/ppapi/cpp/text_input_controller.cc new file mode 100644 index 0000000..59850d3 --- /dev/null +++ b/ppapi/cpp/text_input_controller.cc @@ -0,0 +1,63 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/cpp/text_input_controller.h" + +#include "ppapi/cpp/module_impl.h" +#include "ppapi/cpp/rect.h" +#include "ppapi/cpp/var.h" + +namespace pp { + +namespace { + +template <> const char* interface_name<PPB_TextInputController_1_0>() { + return PPB_TEXTINPUTCONTROLLER_INTERFACE_1_0; +} + +} // namespace + + +TextInputController::TextInputController(const InstanceHandle& instance) + : instance_(instance) { +} + +TextInputController::~TextInputController() { +} + +void TextInputController::SetTextInputType(PP_TextInput_Type type) { + if (has_interface<PPB_TextInputController_1_0>()) { + get_interface<PPB_TextInputController_1_0>()->SetTextInputType( + instance_.pp_instance(), type); + } +} + +void TextInputController::UpdateCaretPosition(const Rect& caret) { + if (has_interface<PPB_TextInputController_1_0>()) { + get_interface<PPB_TextInputController_1_0>()->UpdateCaretPosition( + instance_.pp_instance(), &caret.pp_rect()); + } +} + +void TextInputController::CancelCompositionText() { + if (has_interface<PPB_TextInputController_1_0>()) { + get_interface<PPB_TextInputController_1_0>()->CancelCompositionText( + instance_.pp_instance()); + } +} + +void TextInputController::UpdateSurroundingText(const Var& text, + uint32_t caret, + uint32_t anchor) { + if (has_interface<PPB_TextInputController_1_0>()) { + get_interface<PPB_TextInputController_1_0>()->UpdateSurroundingText( + instance_.pp_instance(), + text.pp_var(), + caret, + anchor); + } +} + + +} // namespace pp diff --git a/ppapi/cpp/text_input_controller.h b/ppapi/cpp/text_input_controller.h new file mode 100644 index 0000000..8843bd3 --- /dev/null +++ b/ppapi/cpp/text_input_controller.h @@ -0,0 +1,73 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_CPP_TEXT_INPUT_CONTROLLER_H_ +#define PPAPI_CPP_TEXT_INPUT_CONTROLLER_H_ + +#include <string> + +#include "ppapi/c/ppb_text_input_controller.h" +#include "ppapi/cpp/instance_handle.h" +#include "ppapi/cpp/var.h" + +/// @file +/// This file defines the APIs for text input handling. + +namespace pp { + +class Rect; +class Instance; + +/// This class can be used for giving hints to the browser about the text input +/// status of plugins. +class TextInputController { + public: + /// A constructor for creating a <code>TextInputController</code>. + /// + /// @param[in] instance The instance with which this resource will be + /// associated. + explicit TextInputController(const InstanceHandle& instance); + + /// Destructor. + ~TextInputController(); + + /// SetTextInputType() informs the browser about the current text input mode + /// of the plugin. + /// + /// @param[in] type The type of text input type. + void SetTextInputType(PP_TextInput_Type type); + + /// UpdateCaretPosition() informs the browser about the coordinates of the + /// text input caret area. + /// + /// @param[in] caret A rectangle indicating the caret area. + void UpdateCaretPosition(const Rect& caret); + + /// CancelCompositionText() informs the browser that the current composition + /// text is cancelled by the plugin. + void CancelCompositionText(); + + /// UpdateSurroundingText() informs the browser about the current text + /// selection and surrounding text. + /// + /// @param[in] text A UTF-8 sting indicating string buffer of current input + /// context. + /// + /// @param[in] caret A integer indicating the byte index of caret location in + /// <code>text</code>. + /// + /// @param[in] caret A integer indicating the byte index of anchor location in + /// <code>text</code>. If there is no selection, this value should be equal to + /// <code>caret</code>. + void UpdateSurroundingText(const Var& text, + uint32_t caret, + uint32_t anchor); + + private: + InstanceHandle instance_; +}; + +} // namespace pp + +#endif // PPAPI_CPP_TEXT_INPUT_CONTROLLER_H_ |