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

Unified Diff: ppapi/cpp/text_input.cc

Issue 18671004: PPAPI: Move IMEInputEvent and TextInput to stable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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
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

Powered by Google App Engine
This is Rietveld 408576698