Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 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 | |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 5 | #include "base/basictypes.h" |
| 6 | #include "ppapi/c/dev/ppb_text_input_dev.h" |
Torne (Richard Coles) | a36e592 | 2013-08-05 13:57:33 +0100 | [diff] [blame] | 7 | #include "ppapi/c/ppb_text_input_controller.h" |
Torne (Richard Coles) | a36e592 | 2013-08-05 13:57:33 +0100 | [diff] [blame] | 8 | #include "ppapi/shared_impl/var.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 9 | #include "ppapi/thunk/enter.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 10 | #include "ppapi/thunk/ppb_instance_api.h" |
Torne (Richard Coles) | a36e592 | 2013-08-05 13:57:33 +0100 | [diff] [blame] | 11 | #include "ppapi/thunk/thunk.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 12 | |
| 13 | namespace ppapi { |
| 14 | namespace thunk { |
| 15 | |
| 16 | namespace { |
| 17 | |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 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 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 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 | |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 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 | |
Torne (Richard Coles) | a36e592 | 2013-08-05 13:57:33 +0100 | [diff] [blame] | 52 | void UpdateCaretPosition_0_2(PP_Instance instance, |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 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 | |
Torne (Richard Coles) | a36e592 | 2013-08-05 13:57:33 +0100 | [diff] [blame] | 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 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 67 | void CancelCompositionText(PP_Instance instance) { |
| 68 | EnterInstance enter(instance); |
| 69 | if (enter.succeeded()) |
| 70 | enter.functions()->CancelCompositionText(instance); |
| 71 | } |
| 72 | |
Torne (Richard Coles) | a36e592 | 2013-08-05 13:57:33 +0100 | [diff] [blame] | 73 | void UpdateSurroundingText_0_2(PP_Instance instance, const char* text, |
| 74 | uint32_t caret, uint32_t anchor) { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 75 | EnterInstance enter(instance); |
| 76 | if (enter.succeeded()) |
| 77 | enter.functions()->UpdateSurroundingText(instance, text, caret, anchor); |
| 78 | } |
| 79 | |
Torne (Richard Coles) | a36e592 | 2013-08-05 13:57:33 +0100 | [diff] [blame] | 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 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 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 = { |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 98 | &SetTextInputType_0_2, |
Torne (Richard Coles) | a36e592 | 2013-08-05 13:57:33 +0100 | [diff] [blame] | 99 | &UpdateCaretPosition_0_2, |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 100 | &CancelCompositionText, |
| 101 | }; |
| 102 | |
Torne (Richard Coles) | a36e592 | 2013-08-05 13:57:33 +0100 | [diff] [blame] | 103 | const PPB_TextInput_Dev_0_2 g_ppb_textinput_0_2_thunk = { |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 104 | &SetTextInputType_0_2, |
Torne (Richard Coles) | a36e592 | 2013-08-05 13:57:33 +0100 | [diff] [blame] | 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 = { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 112 | &SetTextInputType, |
| 113 | &UpdateCaretPosition, |
| 114 | &CancelCompositionText, |
Torne (Richard Coles) | a36e592 | 2013-08-05 13:57:33 +0100 | [diff] [blame] | 115 | &UpdateSurroundingText_1_0, |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | } // namespace |
| 119 | |
| 120 | const PPB_TextInput_Dev_0_1* GetPPB_TextInput_Dev_0_1_Thunk() { |
| 121 | return &g_ppb_textinput_0_1_thunk; |
| 122 | } |
| 123 | |
| 124 | const PPB_TextInput_Dev_0_2* GetPPB_TextInput_Dev_0_2_Thunk() { |
| 125 | return &g_ppb_textinput_0_2_thunk; |
| 126 | } |
| 127 | |
Torne (Richard Coles) | a36e592 | 2013-08-05 13:57:33 +0100 | [diff] [blame] | 128 | const PPB_TextInputController_1_0* GetPPB_TextInputController_1_0_Thunk() { |
| 129 | return &g_ppb_textinputcontroller_1_0_thunk; |
| 130 | } |
| 131 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 132 | } // namespace thunk |
| 133 | } // namespace ppapi |