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 "base/basictypes.h"
6 #include "ppapi/c/dev/ppb_text_input_dev.h"
7 #include "ppapi/c/ppb_text_input_controller.h"
8 #include "ppapi/shared_impl/var.h"
9 #include "ppapi/thunk/enter.h"
10 #include "ppapi/thunk/ppb_instance_api.h"
11 #include "ppapi/thunk/thunk.h"
12
13 namespace ppapi {
14 namespace thunk {
15
16 namespace {
17
18 COMPILE_ASSERT(int(PP_TEXTINPUT_TYPE_DEV_NONE) == int(PP_TEXTINPUT_TYPE_NONE),
19 mismatching_enums);
20 COMPILE_ASSERT(int(PP_TEXTINPUT_TYPE_DEV_TEXT) == int(PP_TEXTINPUT_TYPE_TEXT),
21 mismatching_enums);
22 COMPILE_ASSERT(
23 int(PP_TEXTINPUT_TYPE_DEV_PASSWORD) == int(PP_TEXTINPUT_TYPE_PASSWORD),
24 mismatching_enums);
25 COMPILE_ASSERT(
26 int(PP_TEXTINPUT_TYPE_DEV_SEARCH) == int(PP_TEXTINPUT_TYPE_SEARCH),
27 mismatching_enums);
28 COMPILE_ASSERT(int(PP_TEXTINPUT_TYPE_DEV_EMAIL) == int(PP_TEXTINPUT_TYPE_EMAIL),
29 mismatching_enums);
30 COMPILE_ASSERT(
31 int(PP_TEXTINPUT_TYPE_DEV_NUMBER) == int(PP_TEXTINPUT_TYPE_NUMBER),
32 mismatching_enums);
33 COMPILE_ASSERT(
34 int(PP_TEXTINPUT_TYPE_DEV_TELEPHONE) == int(PP_TEXTINPUT_TYPE_TELEPHONE),
35 mismatching_enums);
36 COMPILE_ASSERT(int(PP_TEXTINPUT_TYPE_DEV_URL) == int(PP_TEXTINPUT_TYPE_URL),
37 mismatching_enums);
38
SetTextInputType(PP_Instance instance,PP_TextInput_Type type)39 void SetTextInputType(PP_Instance instance, PP_TextInput_Type type) {
40 EnterInstance enter(instance);
41 if (enter.succeeded())
42 enter.functions()->SetTextInputType(instance, type);
43 }
44
SetTextInputType_0_2(PP_Instance instance,PP_TextInput_Type_Dev type)45 void SetTextInputType_0_2(PP_Instance instance, PP_TextInput_Type_Dev type) {
46 EnterInstance enter(instance);
47 if (enter.succeeded())
48 enter.functions()->SetTextInputType(instance,
49 static_cast<PP_TextInput_Type>(type));
50 }
51
UpdateCaretPosition_0_2(PP_Instance instance,const PP_Rect * caret,const PP_Rect * bounding_box)52 void UpdateCaretPosition_0_2(PP_Instance instance,
53 const PP_Rect* caret,
54 const PP_Rect* bounding_box) {
55 EnterInstance enter(instance);
56 if (enter.succeeded() && caret && bounding_box)
57 enter.functions()->UpdateCaretPosition(instance, *caret, *bounding_box);
58 }
59
UpdateCaretPosition(PP_Instance instance,const PP_Rect * caret)60 void UpdateCaretPosition(PP_Instance instance,
61 const PP_Rect* caret) {
62 EnterInstance enter(instance);
63 if (enter.succeeded() && caret)
64 enter.functions()->UpdateCaretPosition(instance, *caret, PP_Rect());
65 }
66
CancelCompositionText(PP_Instance instance)67 void CancelCompositionText(PP_Instance instance) {
68 EnterInstance enter(instance);
69 if (enter.succeeded())
70 enter.functions()->CancelCompositionText(instance);
71 }
72
UpdateSurroundingText_0_2(PP_Instance instance,const char * text,uint32_t caret,uint32_t anchor)73 void UpdateSurroundingText_0_2(PP_Instance instance, const char* text,
74 uint32_t caret, uint32_t anchor) {
75 EnterInstance enter(instance);
76 if (enter.succeeded())
77 enter.functions()->UpdateSurroundingText(instance, text, caret, anchor);
78 }
79
UpdateSurroundingText_1_0(PP_Instance instance,PP_Var text,uint32_t caret,uint32_t anchor)80 void UpdateSurroundingText_1_0(PP_Instance instance, PP_Var text,
81 uint32_t caret, uint32_t anchor) {
82 EnterInstance enter(instance);
83 StringVar* var = StringVar::FromPPVar(text);
84 if (enter.succeeded() && var)
85 enter.functions()->UpdateSurroundingText(instance,
86 var->value().c_str(),
87 caret,
88 anchor);
89 }
90
SelectionChanged(PP_Instance instance)91 void SelectionChanged(PP_Instance instance) {
92 EnterInstance enter(instance);
93 if (enter.succeeded())
94 enter.functions()->SelectionChanged(instance);
95 }
96
97 const PPB_TextInput_Dev_0_1 g_ppb_textinput_0_1_thunk = {
98 &SetTextInputType_0_2,
99 &UpdateCaretPosition_0_2,
100 &CancelCompositionText,
101 };
102
103 const PPB_TextInput_Dev_0_2 g_ppb_textinput_0_2_thunk = {
104 &SetTextInputType_0_2,
105 &UpdateCaretPosition_0_2,
106 &CancelCompositionText,
107 &UpdateSurroundingText_0_2,
108 &SelectionChanged,
109 };
110
111 const PPB_TextInputController_1_0 g_ppb_textinputcontroller_1_0_thunk = {
112 &SetTextInputType,
113 &UpdateCaretPosition,
114 &CancelCompositionText,
115 &UpdateSurroundingText_1_0,
116 };
117
118 } // namespace
119
GetPPB_TextInput_Dev_0_1_Thunk()120 const PPB_TextInput_Dev_0_1* GetPPB_TextInput_Dev_0_1_Thunk() {
121 return &g_ppb_textinput_0_1_thunk;
122 }
123
GetPPB_TextInput_Dev_0_2_Thunk()124 const PPB_TextInput_Dev_0_2* GetPPB_TextInput_Dev_0_2_Thunk() {
125 return &g_ppb_textinput_0_2_thunk;
126 }
127
GetPPB_TextInputController_1_0_Thunk()128 const PPB_TextInputController_1_0* GetPPB_TextInputController_1_0_Thunk() {
129 return &g_ppb_textinputcontroller_1_0_thunk;
130 }
131
132 } // namespace thunk
133 } // namespace ppapi
134