Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(223)

Unified Diff: ppapi/cpp/dev/text_input_dev.cc

Issue 8769003: Pepper IME API for surrounding text retrieval. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge master. Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ppapi/cpp/dev/text_input_dev.h ('k') | ppapi/examples/ime/ime.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/cpp/dev/text_input_dev.cc
diff --git a/ppapi/cpp/dev/text_input_dev.cc b/ppapi/cpp/dev/text_input_dev.cc
index 6783892ca74e315240abbd7c300fde6a6e68a34f..f65fa0297714ed5779885bb9bac6945425008fc4 100644
--- a/ppapi/cpp/dev/text_input_dev.cc
+++ b/ppapi/cpp/dev/text_input_dev.cc
@@ -4,6 +4,8 @@
#include "ppapi/cpp/dev/text_input_dev.h"
+#include "ppapi/c/dev/ppp_text_input_dev.h"
+#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/instance_handle.h"
#include "ppapi/cpp/module_impl.h"
#include "ppapi/cpp/rect.h"
@@ -12,40 +14,95 @@ namespace pp {
namespace {
-template <> const char* interface_name<PPB_TextInput_Dev>() {
- return PPB_TEXTINPUT_DEV_INTERFACE;
+static const char kPPPTextInputInterface[] = PPP_TEXTINPUT_DEV_INTERFACE;
+
+void RequestSurroundingText(PP_Instance instance,
+ uint32_t desired_number_of_characters) {
+ void* object = Instance::GetPerInstanceObject(instance,
+ kPPPTextInputInterface);
+ if (!object)
+ return;
+ static_cast<TextInput_Dev*>(object)->RequestSurroundingText(
+ desired_number_of_characters);
+}
+
+const PPP_TextInput_Dev ppp_text_input = {
+ &RequestSurroundingText
+};
+
+template <> const char* interface_name<PPB_TextInput_Dev_0_2>() {
+ return PPB_TEXTINPUT_DEV_INTERFACE_0_2;
+}
+
+template <> const char* interface_name<PPB_TextInput_Dev_0_1>() {
+ return PPB_TEXTINPUT_DEV_INTERFACE_0_1;
}
} // namespace
-TextInput_Dev::TextInput_Dev(const InstanceHandle& instance)
+TextInput_Dev::TextInput_Dev(Instance* instance)
: instance_(instance) {
+ Module::Get()->AddPluginInterface(kPPPTextInputInterface,
+ &ppp_text_input);
+ instance->AddPerInstanceObject(kPPPTextInputInterface, this);
}
TextInput_Dev::~TextInput_Dev() {
+ Instance::RemovePerInstanceObject(instance_, kPPPTextInputInterface, this);
+}
+
+void TextInput_Dev::RequestSurroundingText(uint32_t) {
+ // Default implementation. Send a null range.
+ UpdateSurroundingText("", 0, 0);
}
void TextInput_Dev::SetTextInputType(PP_TextInput_Type type) {
- if (!has_interface<PPB_TextInput_Dev>())
- return;
- get_interface<PPB_TextInput_Dev>()->SetTextInputType(
- instance_.pp_instance(), type);
+ if (has_interface<PPB_TextInput_Dev_0_2>()) {
+ get_interface<PPB_TextInput_Dev_0_2>()->SetTextInputType(
+ instance_.pp_instance(), type);
+ } else if (has_interface<PPB_TextInput_Dev_0_1>()) {
+ get_interface<PPB_TextInput_Dev_0_1>()->SetTextInputType(
+ instance_.pp_instance(), type);
+ }
}
void TextInput_Dev::UpdateCaretPosition(const Rect& caret,
const Rect& bounding_box) {
- if (!has_interface<PPB_TextInput_Dev>())
- return;
- get_interface<PPB_TextInput_Dev>()->UpdateCaretPosition(
- instance_.pp_instance(), &caret.pp_rect(), &bounding_box.pp_rect());
+ if (has_interface<PPB_TextInput_Dev_0_2>()) {
+ get_interface<PPB_TextInput_Dev_0_2>()->UpdateCaretPosition(
+ instance_.pp_instance(), &caret.pp_rect(), &bounding_box.pp_rect());
+ } else if (has_interface<PPB_TextInput_Dev_0_1>()) {
+ get_interface<PPB_TextInput_Dev_0_1>()->UpdateCaretPosition(
+ instance_.pp_instance(), &caret.pp_rect(), &bounding_box.pp_rect());
+ }
}
void TextInput_Dev::CancelCompositionText() {
- if (!has_interface<PPB_TextInput_Dev>())
- return;
- get_interface<PPB_TextInput_Dev>()->CancelCompositionText(
- instance_.pp_instance());
+ if (has_interface<PPB_TextInput_Dev_0_2>()) {
+ get_interface<PPB_TextInput_Dev_0_2>()->CancelCompositionText(
+ instance_.pp_instance());
+ } else if (has_interface<PPB_TextInput_Dev_0_1>()) {
+ get_interface<PPB_TextInput_Dev_0_1>()->CancelCompositionText(
+ instance_.pp_instance());
+ }
+}
+
+void TextInput_Dev::SelectionChanged() {
+ if (has_interface<PPB_TextInput_Dev_0_2>()) {
+ get_interface<PPB_TextInput_Dev_0_2>()->SelectionChanged(
+ instance_.pp_instance());
+ }
+}
+
+void TextInput_Dev::UpdateSurroundingText(const std::string& text,
+ uint32_t caret,
+ uint32_t anchor) {
+ if (has_interface<PPB_TextInput_Dev_0_2>()) {
+ get_interface<PPB_TextInput_Dev_0_2>()->UpdateSurroundingText(
+ instance_.pp_instance(), text.c_str(), caret, anchor);
+ }
}
+
} // namespace pp
« no previous file with comments | « ppapi/cpp/dev/text_input_dev.h ('k') | ppapi/examples/ime/ime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698