| Index: ppapi/cpp/text_input.cc
|
| diff --git a/ppapi/cpp/text_input.cc b/ppapi/cpp/text_input.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..a7f4003a410dd5b10ae67676569b2506a7106f31
|
| --- /dev/null
|
| +++ b/ppapi/cpp/text_input.cc
|
| @@ -0,0 +1,95 @@
|
| +// 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/text_input.h"
|
| +
|
| +#include "ppapi/c/ppp_text_input.h"
|
| +#include "ppapi/cpp/instance.h"
|
| +#include "ppapi/cpp/instance_handle.h"
|
| +#include "ppapi/cpp/module_impl.h"
|
| +#include "ppapi/cpp/rect.h"
|
| +
|
| +namespace pp {
|
| +
|
| +namespace {
|
| +
|
| +static const char kPPPTextInputInterface[] = PPP_TEXTINPUT_INTERFACE;
|
| +
|
| +void RequestSurroundingText(PP_Instance instance,
|
| + uint32_t desired_number_of_characters) {
|
| + void* object = Instance::GetPerInstanceObject(instance,
|
| + kPPPTextInputInterface);
|
| + if (!object)
|
| + return;
|
| + static_cast<TextInput*>(object)->RequestSurroundingText(
|
| + desired_number_of_characters);
|
| +}
|
| +
|
| +const PPP_TextInput ppp_text_input = {
|
| + &RequestSurroundingText
|
| +};
|
| +
|
| +template <> const char* interface_name<PPB_TextInput_1_0>() {
|
| + return PPB_TEXTINPUT_INTERFACE_1_0;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +
|
| +TextInput::TextInput(Instance* instance)
|
| + : instance_(instance) {
|
| + Module::Get()->AddPluginInterface(kPPPTextInputInterface,
|
| + &ppp_text_input);
|
| + instance->AddPerInstanceObject(kPPPTextInputInterface, this);
|
| +}
|
| +
|
| +TextInput::~TextInput() {
|
| + Instance::RemovePerInstanceObject(instance_, kPPPTextInputInterface, this);
|
| +}
|
| +
|
| +void TextInput::RequestSurroundingText(uint32_t) {
|
| + // Default implementation. Send a null range.
|
| + UpdateSurroundingText(std::string(), 0, 0);
|
| +}
|
| +
|
| +void TextInput::SetTextInputType(PP_TextInput_Type type) {
|
| + if (has_interface<PPB_TextInput_1_0>()) {
|
| + get_interface<PPB_TextInput_1_0>()->SetTextInputType(
|
| + instance_.pp_instance(), type);
|
| + }
|
| +}
|
| +
|
| +void TextInput::UpdateCaretPosition(const Rect& caret,
|
| + const Rect& bounding_box) {
|
| + if (has_interface<PPB_TextInput_1_0>()) {
|
| + get_interface<PPB_TextInput_1_0>()->UpdateCaretPosition(
|
| + instance_.pp_instance(), &caret.pp_rect(), &bounding_box.pp_rect());
|
| + }
|
| +}
|
| +
|
| +void TextInput::CancelCompositionText() {
|
| + if (has_interface<PPB_TextInput_1_0>()) {
|
| + get_interface<PPB_TextInput_1_0>()->CancelCompositionText(
|
| + instance_.pp_instance());
|
| + }
|
| +}
|
| +
|
| +void TextInput::SelectionChanged() {
|
| + if (has_interface<PPB_TextInput_1_0>()) {
|
| + get_interface<PPB_TextInput_1_0>()->SelectionChanged(
|
| + instance_.pp_instance());
|
| + }
|
| +}
|
| +
|
| +void TextInput::UpdateSurroundingText(const std::string& text,
|
| + uint32_t caret,
|
| + uint32_t anchor) {
|
| + if (has_interface<PPB_TextInput_1_0>()) {
|
| + get_interface<PPB_TextInput_1_0>()->UpdateSurroundingText(
|
| + instance_.pp_instance(), text.c_str(), caret, anchor);
|
| + }
|
| +}
|
| +
|
| +
|
| +} // namespace pp
|
|
|