diff options
author | kinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-15 07:34:52 +0000 |
---|---|---|
committer | kinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-15 07:34:52 +0000 |
commit | 3c8c74c98b54130795812527b5b3eb6c569123c2 (patch) | |
tree | 880d846d4d98dfd57c7f5a0fc7f30879fde2a993 /ppapi/examples | |
parent | 8cdb650a50c6d00099d030e4dbbba7eca82379cd (diff) | |
download | chromium_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/examples')
-rw-r--r-- | ppapi/examples/ime/ime.cc | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/ppapi/examples/ime/ime.cc b/ppapi/examples/ime/ime.cc index 2c3ee0b..e217145 100644 --- a/ppapi/examples/ime/ime.cc +++ b/ppapi/examples/ime/ime.cc @@ -1,4 +1,4 @@ -// 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. @@ -92,15 +92,17 @@ class TextFieldStatusHandler { virtual ~TextFieldStatusHandler() {} virtual void FocusIn(const pp::Rect& caret, const pp::Rect& bounding_box) {} virtual void FocusOut() {} + virtual void UpdateSelection(const std::string& text) {} }; -class TextFieldStatusNotifyingHanlder : public TextFieldStatusHandler { +class TextFieldStatusNotifyingHandler : public TextFieldStatusHandler { public: - explicit TextFieldStatusNotifyingHanlder(pp::Instance* instance) - : instance_(instance), - textinput_control_(instance) {} + explicit TextFieldStatusNotifyingHandler(pp::Instance* instance) + : textinput_control_(instance) { + } protected: + // Implement TextFieldStatusHandler. virtual void FocusIn(const pp::Rect& caret, const pp::Rect& bounding_box) { textinput_control_.SetTextInputType(PP_TEXTINPUT_TYPE_TEXT); textinput_control_.UpdateCaretPosition(caret, bounding_box); @@ -109,10 +111,22 @@ class TextFieldStatusNotifyingHanlder : public TextFieldStatusHandler { textinput_control_.CancelCompositionText(); textinput_control_.SetTextInputType(PP_TEXTINPUT_TYPE_NONE); } + virtual void UpdateSelection(const std::string& text) { + textinput_control_.SetSelectionText(text); + textinput_control_.SelectionChanged(); + } private: - pp::Instance* instance_; - pp::TextInput_Dev textinput_control_; + class MyTextInput : public pp::TextInput_Dev { + public: + MyTextInput(pp::Instance* instance) : pp::TextInput_Dev(instance) {} + virtual void RequestSurroundingText(uint32_t characters) { + UpdateSurroundingText(selection_text_, 0, selection_text_.size()); + } + void SetSelectionText(const std::string& text) { selection_text_ = text; } + std::string selection_text_; + }; + MyTextInput textinput_control_; }; // Hand-made text field for demonstrating text input API. @@ -361,6 +375,9 @@ class MyTextField { int px = font_.MeasureSimpleText(str); pp::Rect caret(area_.x() + px, area_.y(), 0, area_.height() + 2); status_handler_->FocusIn(caret, area_); + status_handler_->UpdateSelection( + utf8_text_.substr(SelectionLeft(), + SelectionRight() - SelectionLeft())); } } size_t SelectionLeft() const { @@ -430,14 +447,14 @@ class MyInstance : public pp::Instance { // say, show virtual keyboards or IMEs only at appropriate timing // that the plugin does need to accept text input. delete status_handler_; - status_handler_ = new TextFieldStatusNotifyingHanlder(this); + status_handler_ = new TextFieldStatusNotifyingHandler(this); } else if (argv[i] == std::string("full")) { // Demonstrating the behavior of plugins fully supporting IME. // // It notifies updates of caret positions to the browser, // and handles all text input events by itself. delete status_handler_; - status_handler_ = new TextFieldStatusNotifyingHanlder(this); + status_handler_ = new TextFieldStatusNotifyingHandler(this); RequestInputEvents(PP_INPUTEVENT_CLASS_IME); } break; |