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

Side by Side Diff: ppapi/cpp/dev/text_input_dev.cc

Issue 8769003: Pepper IME API for surrounding text retrieval. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge master. Created 8 years, 9 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
« no previous file with comments | « ppapi/cpp/dev/text_input_dev.h ('k') | ppapi/examples/ime/ime.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/cpp/dev/text_input_dev.h" 5 #include "ppapi/cpp/dev/text_input_dev.h"
6 6
7 #include "ppapi/c/dev/ppp_text_input_dev.h"
8 #include "ppapi/cpp/instance.h"
7 #include "ppapi/cpp/instance_handle.h" 9 #include "ppapi/cpp/instance_handle.h"
8 #include "ppapi/cpp/module_impl.h" 10 #include "ppapi/cpp/module_impl.h"
9 #include "ppapi/cpp/rect.h" 11 #include "ppapi/cpp/rect.h"
10 12
11 namespace pp { 13 namespace pp {
12 14
13 namespace { 15 namespace {
14 16
15 template <> const char* interface_name<PPB_TextInput_Dev>() { 17 static const char kPPPTextInputInterface[] = PPP_TEXTINPUT_DEV_INTERFACE;
16 return PPB_TEXTINPUT_DEV_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_Dev*>(object)->RequestSurroundingText(
26 desired_number_of_characters);
27 }
28
29 const PPP_TextInput_Dev ppp_text_input = {
30 &RequestSurroundingText
31 };
32
33 template <> const char* interface_name<PPB_TextInput_Dev_0_2>() {
34 return PPB_TEXTINPUT_DEV_INTERFACE_0_2;
35 }
36
37 template <> const char* interface_name<PPB_TextInput_Dev_0_1>() {
38 return PPB_TEXTINPUT_DEV_INTERFACE_0_1;
17 } 39 }
18 40
19 } // namespace 41 } // namespace
20 42
21 43
22 TextInput_Dev::TextInput_Dev(const InstanceHandle& instance) 44 TextInput_Dev::TextInput_Dev(Instance* instance)
23 : instance_(instance) { 45 : instance_(instance) {
46 Module::Get()->AddPluginInterface(kPPPTextInputInterface,
47 &ppp_text_input);
48 instance->AddPerInstanceObject(kPPPTextInputInterface, this);
24 } 49 }
25 50
26 TextInput_Dev::~TextInput_Dev() { 51 TextInput_Dev::~TextInput_Dev() {
52 Instance::RemovePerInstanceObject(instance_, kPPPTextInputInterface, this);
53 }
54
55 void TextInput_Dev::RequestSurroundingText(uint32_t) {
56 // Default implementation. Send a null range.
57 UpdateSurroundingText("", 0, 0);
27 } 58 }
28 59
29 void TextInput_Dev::SetTextInputType(PP_TextInput_Type type) { 60 void TextInput_Dev::SetTextInputType(PP_TextInput_Type type) {
30 if (!has_interface<PPB_TextInput_Dev>()) 61 if (has_interface<PPB_TextInput_Dev_0_2>()) {
31 return; 62 get_interface<PPB_TextInput_Dev_0_2>()->SetTextInputType(
32 get_interface<PPB_TextInput_Dev>()->SetTextInputType( 63 instance_.pp_instance(), type);
33 instance_.pp_instance(), type); 64 } else if (has_interface<PPB_TextInput_Dev_0_1>()) {
65 get_interface<PPB_TextInput_Dev_0_1>()->SetTextInputType(
66 instance_.pp_instance(), type);
67 }
34 } 68 }
35 69
36 void TextInput_Dev::UpdateCaretPosition(const Rect& caret, 70 void TextInput_Dev::UpdateCaretPosition(const Rect& caret,
37 const Rect& bounding_box) { 71 const Rect& bounding_box) {
38 if (!has_interface<PPB_TextInput_Dev>()) 72 if (has_interface<PPB_TextInput_Dev_0_2>()) {
39 return; 73 get_interface<PPB_TextInput_Dev_0_2>()->UpdateCaretPosition(
40 get_interface<PPB_TextInput_Dev>()->UpdateCaretPosition( 74 instance_.pp_instance(), &caret.pp_rect(), &bounding_box.pp_rect());
41 instance_.pp_instance(), &caret.pp_rect(), &bounding_box.pp_rect()); 75 } else if (has_interface<PPB_TextInput_Dev_0_1>()) {
76 get_interface<PPB_TextInput_Dev_0_1>()->UpdateCaretPosition(
77 instance_.pp_instance(), &caret.pp_rect(), &bounding_box.pp_rect());
78 }
42 } 79 }
43 80
44 void TextInput_Dev::CancelCompositionText() { 81 void TextInput_Dev::CancelCompositionText() {
45 if (!has_interface<PPB_TextInput_Dev>()) 82 if (has_interface<PPB_TextInput_Dev_0_2>()) {
46 return; 83 get_interface<PPB_TextInput_Dev_0_2>()->CancelCompositionText(
47 get_interface<PPB_TextInput_Dev>()->CancelCompositionText( 84 instance_.pp_instance());
48 instance_.pp_instance()); 85 } else if (has_interface<PPB_TextInput_Dev_0_1>()) {
86 get_interface<PPB_TextInput_Dev_0_1>()->CancelCompositionText(
87 instance_.pp_instance());
88 }
49 } 89 }
50 90
91 void TextInput_Dev::SelectionChanged() {
92 if (has_interface<PPB_TextInput_Dev_0_2>()) {
93 get_interface<PPB_TextInput_Dev_0_2>()->SelectionChanged(
94 instance_.pp_instance());
95 }
96 }
97
98 void TextInput_Dev::UpdateSurroundingText(const std::string& text,
99 uint32_t caret,
100 uint32_t anchor) {
101 if (has_interface<PPB_TextInput_Dev_0_2>()) {
102 get_interface<PPB_TextInput_Dev_0_2>()->UpdateSurroundingText(
103 instance_.pp_instance(), text.c_str(), caret, anchor);
104 }
105 }
106
107
51 } // namespace pp 108 } // namespace pp
OLDNEW
« no previous file with comments | « ppapi/cpp/dev/text_input_dev.h ('k') | ppapi/examples/ime/ime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698