OLD | NEW |
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 |
| 17 static const char kPPPTextInputInterface[] = PPP_TEXTINPUT_DEV_INTERFACE; |
| 18 |
| 19 void RequestSurroundingText(PP_Instance instance, |
| 20 uint32_t desired_number_of_chanracetes) { |
| 21 void* object = Instance::GetPerInstanceObject(instance, |
| 22 kPPPTextInputInterface); |
| 23 if (!object) |
| 24 return; |
| 25 static_cast<TextInput_Dev*>(object)->RequestSurroundingText( |
| 26 desired_number_of_chanracetes); |
| 27 } |
| 28 |
| 29 const PPP_TextInput_Dev ppp_text_input = { |
| 30 &RequestSurroundingText |
| 31 }; |
| 32 |
15 template <> const char* interface_name<PPB_TextInput_Dev>() { | 33 template <> const char* interface_name<PPB_TextInput_Dev>() { |
16 return PPB_TEXTINPUT_DEV_INTERFACE; | 34 return PPB_TEXTINPUT_DEV_INTERFACE; |
17 } | 35 } |
18 | 36 |
19 } // namespace | 37 } // namespace |
20 | 38 |
21 | 39 |
22 TextInput_Dev::TextInput_Dev(const InstanceHandle& instance) | 40 TextInput_Dev::TextInput_Dev(Instance* instance) |
23 : instance_(instance) { | 41 : instance_(instance) { |
| 42 Module::Get()->AddPluginInterface(kPPPTextInputInterface, |
| 43 &ppp_text_input); |
| 44 instance->AddPerInstanceObject(kPPPTextInputInterface, this); |
24 } | 45 } |
25 | 46 |
26 TextInput_Dev::~TextInput_Dev() { | 47 TextInput_Dev::~TextInput_Dev() { |
| 48 Instance::RemovePerInstanceObject(instance_, kPPPTextInputInterface, this); |
| 49 } |
| 50 |
| 51 void TextInput_Dev::RequestSurroundingText(uint32_t) { |
| 52 // Default implementation. Send a null range. |
| 53 UpdateSurroundingText("", 0, 0); |
27 } | 54 } |
28 | 55 |
29 void TextInput_Dev::SetTextInputType(PP_TextInput_Type type) { | 56 void TextInput_Dev::SetTextInputType(PP_TextInput_Type type) { |
30 if (!has_interface<PPB_TextInput_Dev>()) | 57 if (!has_interface<PPB_TextInput_Dev>()) |
31 return; | 58 return; |
32 get_interface<PPB_TextInput_Dev>()->SetTextInputType( | 59 get_interface<PPB_TextInput_Dev>()->SetTextInputType( |
33 instance_.pp_instance(), type); | 60 instance_.pp_instance(), type); |
34 } | 61 } |
35 | 62 |
36 void TextInput_Dev::UpdateCaretPosition(const Rect& caret, | 63 void TextInput_Dev::UpdateCaretPosition(const Rect& caret, |
37 const Rect& bounding_box) { | 64 const Rect& bounding_box) { |
38 if (!has_interface<PPB_TextInput_Dev>()) | 65 if (!has_interface<PPB_TextInput_Dev>()) |
39 return; | 66 return; |
40 get_interface<PPB_TextInput_Dev>()->UpdateCaretPosition( | 67 get_interface<PPB_TextInput_Dev>()->UpdateCaretPosition( |
41 instance_.pp_instance(), &caret.pp_rect(), &bounding_box.pp_rect()); | 68 instance_.pp_instance(), &caret.pp_rect(), &bounding_box.pp_rect()); |
42 } | 69 } |
43 | 70 |
44 void TextInput_Dev::CancelCompositionText() { | 71 void TextInput_Dev::CancelCompositionText() { |
45 if (!has_interface<PPB_TextInput_Dev>()) | 72 if (!has_interface<PPB_TextInput_Dev>()) |
46 return; | 73 return; |
47 get_interface<PPB_TextInput_Dev>()->CancelCompositionText( | 74 get_interface<PPB_TextInput_Dev>()->CancelCompositionText( |
48 instance_.pp_instance()); | 75 instance_.pp_instance()); |
49 } | 76 } |
50 | 77 |
| 78 void TextInput_Dev::SelectionChanged() { |
| 79 if (!has_interface<PPB_TextInput_Dev>()) |
| 80 return; |
| 81 get_interface<PPB_TextInput_Dev>()->SelectionChanged( |
| 82 instance_.pp_instance()); |
| 83 } |
| 84 |
| 85 void TextInput_Dev::UpdateSurroundingText(const std::string& text, |
| 86 uint32_t caret, |
| 87 uint32_t anchor) { |
| 88 if (!has_interface<PPB_TextInput_Dev>()) |
| 89 return; |
| 90 get_interface<PPB_TextInput_Dev>()->UpdateSurroundingText( |
| 91 instance_.pp_instance(), text.c_str(), caret, anchor); |
| 92 } |
| 93 |
| 94 |
51 } // namespace pp | 95 } // namespace pp |
OLD | NEW |