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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ppapi/cpp/text_input.h"
6
7 #include "ppapi/c/ppp_text_input.h"
8 #include "ppapi/cpp/instance.h"
9 #include "ppapi/cpp/instance_handle.h"
10 #include "ppapi/cpp/module_impl.h"
11 #include "ppapi/cpp/rect.h"
12
13 namespace pp {
14
15 namespace {
16
17 static const char kPPPTextInputInterface[] = PPP_TEXTINPUT_INTERFACE;
18
19 void RequestSurroundingText(PP_Instance instance,
20 uint32_t desired_number_of_characters) {
21 void* object = Instance::GetPerInstanceObject(instance,
22 kPPPTextInputInterface);
23 if (!object)
24 return;
25 static_cast<TextInput*>(object)->RequestSurroundingText(
26 desired_number_of_characters);
27 }
28
29 const PPP_TextInput ppp_text_input = {
30 &RequestSurroundingText
31 };
32
33 template <> const char* interface_name<PPB_TextInput_1_0>() {
34 return PPB_TEXTINPUT_INTERFACE_1_0;
35 }
36
37 } // namespace
38
39
40 TextInput::TextInput(Instance* instance)
41 : instance_(instance) {
42 Module::Get()->AddPluginInterface(kPPPTextInputInterface,
43 &ppp_text_input);
44 instance->AddPerInstanceObject(kPPPTextInputInterface, this);
45 }
46
47 TextInput::~TextInput() {
48 Instance::RemovePerInstanceObject(instance_, kPPPTextInputInterface, this);
49 }
50
51 void TextInput::RequestSurroundingText(uint32_t) {
52 // Default implementation. Send a null range.
53 UpdateSurroundingText(std::string(), 0, 0);
54 }
55
56 void TextInput::SetTextInputType(PP_TextInput_Type type) {
57 if (has_interface<PPB_TextInput_1_0>()) {
58 get_interface<PPB_TextInput_1_0>()->SetTextInputType(
59 instance_.pp_instance(), type);
60 }
61 }
62
63 void TextInput::UpdateCaretPosition(const Rect& caret,
64 const Rect& bounding_box) {
65 if (has_interface<PPB_TextInput_1_0>()) {
66 get_interface<PPB_TextInput_1_0>()->UpdateCaretPosition(
67 instance_.pp_instance(), &caret.pp_rect(), &bounding_box.pp_rect());
68 }
69 }
70
71 void TextInput::CancelCompositionText() {
72 if (has_interface<PPB_TextInput_1_0>()) {
73 get_interface<PPB_TextInput_1_0>()->CancelCompositionText(
74 instance_.pp_instance());
75 }
76 }
77
78 void TextInput::SelectionChanged() {
79 if (has_interface<PPB_TextInput_1_0>()) {
80 get_interface<PPB_TextInput_1_0>()->SelectionChanged(
81 instance_.pp_instance());
82 }
83 }
84
85 void TextInput::UpdateSurroundingText(const std::string& text,
86 uint32_t caret,
87 uint32_t anchor) {
88 if (has_interface<PPB_TextInput_1_0>()) {
89 get_interface<PPB_TextInput_1_0>()->UpdateSurroundingText(
90 instance_.pp_instance(), text.c_str(), caret, anchor);
91 }
92 }
93
94
95 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698