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