blob: a59146bd1f7b98ed18896231d7697af696087b06 [file] [log] [blame]
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001// 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 Murdochbb1529c2013-08-08 10:24:53 +01005#include "base/basictypes.h"
6#include "ppapi/c/dev/ppb_text_input_dev.h"
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +01007#include "ppapi/c/ppb_text_input_controller.h"
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +01008#include "ppapi/shared_impl/var.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +00009#include "ppapi/thunk/enter.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000010#include "ppapi/thunk/ppb_instance_api.h"
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +010011#include "ppapi/thunk/thunk.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000012
13namespace ppapi {
14namespace thunk {
15
16namespace {
17
Ben Murdochbb1529c2013-08-08 10:24:53 +010018COMPILE_ASSERT(int(PP_TEXTINPUT_TYPE_DEV_NONE) == int(PP_TEXTINPUT_TYPE_NONE),
19 mismatching_enums);
20COMPILE_ASSERT(int(PP_TEXTINPUT_TYPE_DEV_TEXT) == int(PP_TEXTINPUT_TYPE_TEXT),
21 mismatching_enums);
22COMPILE_ASSERT(
23 int(PP_TEXTINPUT_TYPE_DEV_PASSWORD) == int(PP_TEXTINPUT_TYPE_PASSWORD),
24 mismatching_enums);
25COMPILE_ASSERT(
26 int(PP_TEXTINPUT_TYPE_DEV_SEARCH) == int(PP_TEXTINPUT_TYPE_SEARCH),
27 mismatching_enums);
28COMPILE_ASSERT(int(PP_TEXTINPUT_TYPE_DEV_EMAIL) == int(PP_TEXTINPUT_TYPE_EMAIL),
29 mismatching_enums);
30COMPILE_ASSERT(
31 int(PP_TEXTINPUT_TYPE_DEV_NUMBER) == int(PP_TEXTINPUT_TYPE_NUMBER),
32 mismatching_enums);
33COMPILE_ASSERT(
34 int(PP_TEXTINPUT_TYPE_DEV_TELEPHONE) == int(PP_TEXTINPUT_TYPE_TELEPHONE),
35 mismatching_enums);
36COMPILE_ASSERT(int(PP_TEXTINPUT_TYPE_DEV_URL) == int(PP_TEXTINPUT_TYPE_URL),
37 mismatching_enums);
38
Torne (Richard Coles)58218062012-11-14 11:43:16 +000039void 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 Murdochbb1529c2013-08-08 10:24:53 +010045void 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)a36e5922013-08-05 13:57:33 +010052void UpdateCaretPosition_0_2(PP_Instance instance,
Torne (Richard Coles)58218062012-11-14 11:43:16 +000053 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)a36e5922013-08-05 13:57:33 +010060void 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)58218062012-11-14 11:43:16 +000067void CancelCompositionText(PP_Instance instance) {
68 EnterInstance enter(instance);
69 if (enter.succeeded())
70 enter.functions()->CancelCompositionText(instance);
71}
72
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +010073void UpdateSurroundingText_0_2(PP_Instance instance, const char* text,
74 uint32_t caret, uint32_t anchor) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +000075 EnterInstance enter(instance);
76 if (enter.succeeded())
77 enter.functions()->UpdateSurroundingText(instance, text, caret, anchor);
78}
79
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +010080void 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)58218062012-11-14 11:43:16 +000091void SelectionChanged(PP_Instance instance) {
92 EnterInstance enter(instance);
93 if (enter.succeeded())
94 enter.functions()->SelectionChanged(instance);
95}
96
97const PPB_TextInput_Dev_0_1 g_ppb_textinput_0_1_thunk = {
Ben Murdochbb1529c2013-08-08 10:24:53 +010098 &SetTextInputType_0_2,
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +010099 &UpdateCaretPosition_0_2,
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000100 &CancelCompositionText,
101};
102
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +0100103const PPB_TextInput_Dev_0_2 g_ppb_textinput_0_2_thunk = {
Ben Murdochbb1529c2013-08-08 10:24:53 +0100104 &SetTextInputType_0_2,
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +0100105 &UpdateCaretPosition_0_2,
106 &CancelCompositionText,
107 &UpdateSurroundingText_0_2,
108 &SelectionChanged,
109};
110
111const PPB_TextInputController_1_0 g_ppb_textinputcontroller_1_0_thunk = {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000112 &SetTextInputType,
113 &UpdateCaretPosition,
114 &CancelCompositionText,
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +0100115 &UpdateSurroundingText_1_0,
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000116};
117
118} // namespace
119
120const PPB_TextInput_Dev_0_1* GetPPB_TextInput_Dev_0_1_Thunk() {
121 return &g_ppb_textinput_0_1_thunk;
122}
123
124const PPB_TextInput_Dev_0_2* GetPPB_TextInput_Dev_0_2_Thunk() {
125 return &g_ppb_textinput_0_2_thunk;
126}
127
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +0100128const PPB_TextInputController_1_0* GetPPB_TextInputController_1_0_Thunk() {
129 return &g_ppb_textinputcontroller_1_0_thunk;
130}
131
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000132} // namespace thunk
133} // namespace ppapi