Chromium Code Reviews| 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..83237911a625b1cf26bf8a7083d9d1a821033527 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,6 +14,22 @@ namespace pp { |
| namespace { |
| +static const char kPPPTextInputInterface[] = PPP_TEXTINPUT_DEV_INTERFACE; |
| + |
| +void RequestSurroundingText(PP_Instance instance, |
| + uint32_t desired_number_of_chanracetes) { |
|
yzshen1
2012/03/08 07:51:43
Is it "characters"? :)
kinaba
2012/03/14 04:28:54
Yes... what's happened to my keyboard?!!
yzshen1
2012/03/14 06:48:08
I am pretty sure that we have the same kind of key
|
| + void* object = Instance::GetPerInstanceObject(instance, |
| + kPPPTextInputInterface); |
| + if (!object) |
| + return; |
| + static_cast<TextInput_Dev*>(object)->RequestSurroundingText( |
| + desired_number_of_chanracetes); |
| +} |
| + |
| +const PPP_TextInput_Dev ppp_text_input = { |
| + &RequestSurroundingText |
| +}; |
| + |
| template <> const char* interface_name<PPB_TextInput_Dev>() { |
|
yzshen1
2012/03/08 07:51:43
You should consider backward compatibility.
Using
kinaba
2012/03/14 04:28:54
Done.
|
| return PPB_TEXTINPUT_DEV_INTERFACE; |
| } |
| @@ -19,11 +37,20 @@ template <> const char* interface_name<PPB_TextInput_Dev>() { |
| } // 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) { |
| @@ -48,4 +75,21 @@ void TextInput_Dev::CancelCompositionText() { |
| instance_.pp_instance()); |
| } |
| +void TextInput_Dev::SelectionChanged() { |
| + if (!has_interface<PPB_TextInput_Dev>()) |
| + return; |
| + get_interface<PPB_TextInput_Dev>()->SelectionChanged( |
| + instance_.pp_instance()); |
| +} |
| + |
| +void TextInput_Dev::UpdateSurroundingText(const std::string& text, |
| + uint32_t caret, |
| + uint32_t anchor) { |
| + if (!has_interface<PPB_TextInput_Dev>()) |
| + return; |
| + get_interface<PPB_TextInput_Dev>()->UpdateSurroundingText( |
| + instance_.pp_instance(), text.c_str(), caret, anchor); |
| +} |
| + |
| + |
| } // namespace pp |