summaryrefslogtreecommitdiffstats
path: root/ppapi/cpp
diff options
context:
space:
mode:
authorkinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-15 07:34:52 +0000
committerkinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-15 07:34:52 +0000
commit3c8c74c98b54130795812527b5b3eb6c569123c2 (patch)
tree880d846d4d98dfd57c7f5a0fc7f30879fde2a993 /ppapi/cpp
parent8cdb650a50c6d00099d030e4dbbba7eca82379cd (diff)
downloadchromium_src-3c8c74c98b54130795812527b5b3eb6c569123c2.zip
chromium_src-3c8c74c98b54130795812527b5b3eb6c569123c2.tar.gz
chromium_src-3c8c74c98b54130795812527b5b3eb6c569123c2.tar.bz2
Pepper IME API for surrounding text retrieval.
IME benefits from knowing what portion of text is selected inside a text editing plugin. This change is to implement a Pepper API for doing it. It consists of three API functions: 1. Browser asks plugins by PPP_TextInput_Dev::RequestSurroundingText() to send such info. 2. Plugin must reply the query by PPB_TextInput_Dev::UpdateSurroundingText(). 3. Additionally, plugin notifies the browser by PPB_TextInput_Dev::SelectionChanged() that the selection is changed. Typically triggers the steps 1->2. Intention of the API design is (1) to avoid synchronous IPC, and (2) to keep the room to implement it in an optimal and right way, that is, expensive send of selection text happens only when needed (= "IME requiring the info is on" + "selection indeed changed in the plugin"), though the current impl in the patch is not necessary like that (for sake of simplicity). The changes in the API is in: * ppapi/c/dev/ppb_text_input_dev.h * ppapi/c/dev/ppp_text_input_dev.h The browser side implementation mostly resides in: * content/renderer/render_view_impl.cc * content/renderer/pepper/pepper_plugin_delegate_impl.{h,cc} * webkit/plugins/ppapi/ppapi_plugin_instance.{h,cc} The other files are for wiring necessary cables. BUG=101101 TEST=Manual: make ppapi_example_ime and run ./your/chrome --register-pepper-plugins=\ "/path/to/ppapi_example_ime.plugin;application/x-ppapi-example-ime" \ --ppapi-out-of-process \ file:///path/to/ppapi/examples/ime/ime.html Try some IME that supports reconversion (e.g., Google Japanese Input on Windows). Review URL: http://codereview.chromium.org/8769003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126862 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/cpp')
-rw-r--r--ppapi/cpp/dev/text_input_dev.cc89
-rw-r--r--ppapi/cpp/dev/text_input_dev.h39
2 files changed, 107 insertions, 21 deletions
diff --git a/ppapi/cpp/dev/text_input_dev.cc b/ppapi/cpp/dev/text_input_dev.cc
index 6783892..3b38df8 100644
--- a/ppapi/cpp/dev/text_input_dev.cc
+++ b/ppapi/cpp/dev/text_input_dev.cc
@@ -1,9 +1,11 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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/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
diff --git a/ppapi/cpp/dev/text_input_dev.h b/ppapi/cpp/dev/text_input_dev.h
index af21a90..ea75597 100644
--- a/ppapi/cpp/dev/text_input_dev.h
+++ b/ppapi/cpp/dev/text_input_dev.h
@@ -1,27 +1,56 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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_DEV_TEXT_INPUT_DEV_H_
#define PPAPI_CPP_DEV_TEXT_INPUT_DEV_H_
+#include <string>
+
#include "ppapi/c/dev/ppb_text_input_dev.h"
#include "ppapi/cpp/instance_handle.h"
-/// @file
-/// This file defines the API for controlling text input methods.
namespace pp {
class Rect;
-
+class Instance;
+
+// This class allows you to associate the PPP_TextInput_Dev and
+// PPB_TextInput_Dev C-based interfaces with an object. It associates itself
+// with the given instance, and registers as the global handler for handling the
+// PPP_TextInput_Dev interface that the browser calls.
+//
+// You would typically use this either via inheritance on your instance:
+// class MyInstance : public pp::Instance, public pp::TextInput_Dev {
+// MyInstance() : pp::TextInput_Dev(this) {
+// }
+// ...
+// };
+//
+// or by composition:
+// class MyTextInput : public pp::TextInput_Dev {
+// ...
+// };
+//
+// class MyInstance : public pp::Instance {
+// MyInstance() : text_input_(this) {
+// }
+//
+// MyTextInput text_input_;
+// };
class TextInput_Dev {
public:
- explicit TextInput_Dev(const InstanceHandle& instance);
+ explicit TextInput_Dev(Instance* instance);
virtual ~TextInput_Dev();
+ virtual void RequestSurroundingText(uint32_t desired_number_of_characters);
+
void SetTextInputType(PP_TextInput_Type type);
void UpdateCaretPosition(const Rect& caret, const Rect& bounding_box);
void CancelCompositionText();
+ void SelectionChanged();
+ void UpdateSurroundingText(const std::string& text,
+ uint32_t caret, uint32_t anchor);
private:
InstanceHandle instance_;