[Tizen] Add DALi Autofill implementation
[platform/core/uifw/dali-adaptor.git] / dali / internal / input / tizen-wayland / autofill-item-impl-ecore-wl.cpp
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/input/tizen-wayland/autofill-item-impl-ecore-wl.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/object/type-registry.h>
23 #include <dali/integration-api/debug.h>
24
25 namespace Dali
26 {
27
28 namespace Internal
29 {
30
31 namespace Adaptor
32 {
33
34 namespace
35 {
36 #if defined(DEBUG_ENABLED)
37 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_AUTOFILL");
38 #endif
39
40 BaseHandle Create()
41 {
42   return Dali::Internal::Adaptor::AutofillItem::New( "", "", Dali::AutofillItem::Hint::ID, false );
43 }
44
45 Dali::TypeRegistration type( typeid(Dali::AutofillItem), typeid(Dali::BaseHandle), Create );
46
47 } // unnamed namespace
48
49
50 AutofillItemEcorewWl::AutofillItemEcorewWl( const std::string& id, const std::string& label, Dali::AutofillItem::Hint hint, bool sensitiveData )
51 : mId( id ),
52   mLabel( label ),
53   mHint( hint ),
54   mSensitiveData( sensitiveData ),
55   mValue(""),
56   mPresentationTextList(),
57   mValueList()
58 {
59 #ifdef CAPI_AUTOFILL_SUPPORT
60   mAutofillItemHandle = NULL;
61   mAutofillSaveItemHandle = NULL;
62 #endif // CAPI_AUTOFILL_SUPPORT
63 }
64
65 AutofillItemEcorewWl::~AutofillItemEcorewWl()
66 {
67 #ifdef CAPI_AUTOFILL_SUPPORT
68   if( mAutofillItemHandle )
69   {
70     autofill_item_destroy( mAutofillItemHandle );
71     mAutofillItemHandle = NULL;
72   }
73
74   if( mAutofillSaveItemHandle )
75   {
76     autofill_save_item_destroy( mAutofillSaveItemHandle );
77     mAutofillSaveItemHandle = NULL;
78   }
79 #endif // CAPI_AUTOFILL_SUPPORT
80 }
81
82
83 Dali::AutofillItem AutofillItemEcorewWl::New( const std::string& id, const std::string& label, Dali::AutofillItem::Hint hint, bool sensitiveData )
84 {
85   Dali::Internal::Adaptor::AutofillItem* item = new Dali::Internal::Adaptor::AutofillItemEcorewWl( id, label, hint, sensitiveData );
86   Dali::AutofillItem handle = Dali::AutofillItem( item );
87   item->Initialize();
88
89   return handle;
90 }
91
92 void AutofillItemEcorewWl::Initialize()
93 {
94 #ifdef CAPI_AUTOFILL_SUPPORT
95   int ret = autofill_item_create( &mAutofillItemHandle );
96   if( ret != AUTOFILL_ERROR_NONE )
97   {
98     DALI_LOG_ERROR( "Failed to create autofill item handle : %d \n", ret );
99     return;
100   }
101
102   autofill_item_set_id( mAutofillItemHandle, mId.c_str() );
103   autofill_item_set_label( mAutofillItemHandle, mLabel.c_str() );
104   autofill_item_set_sensitive_data( mAutofillItemHandle, mSensitiveData );
105
106   // Create autofill save item handle for save.
107   autofill_save_item_create( &mAutofillSaveItemHandle );
108   autofill_save_item_set_id( mAutofillSaveItemHandle, mId.c_str() );
109   autofill_save_item_set_label( mAutofillSaveItemHandle, mLabel.c_str() );
110   autofill_save_item_set_sensitive_data( mAutofillSaveItemHandle, mSensitiveData );
111
112   autofill_hint_e value = static_cast<autofill_hint_e>(mHint);
113   autofill_item_set_autofill_hint( mAutofillItemHandle, value );
114   autofill_save_item_set_autofill_hint( mAutofillSaveItemHandle, value);
115 #endif // CAPI_AUTOFILL_SUPPORT
116 }
117
118 const std::string& AutofillItemEcorewWl::GetId() const
119 {
120   DALI_LOG_INFO( gLogFilter, Debug::General, "AutofillItemEcorewWl::GetId \n" );
121   return mId;
122 }
123
124 const std::string& AutofillItemEcorewWl::GetLabel() const
125 {
126   DALI_LOG_INFO( gLogFilter, Debug::General, "AutofillItemEcorewWl::GetLabel \n" );
127   return mLabel;
128 }
129
130
131 Dali::AutofillItem::Hint AutofillItemEcorewWl::GetHint() const
132 {
133   DALI_LOG_INFO( gLogFilter, Debug::General, "AutofillItemEcorewWl::GetHint \n" );
134   return mHint;
135 }
136
137 bool AutofillItemEcorewWl::IsSensitiveData() const
138 {
139   DALI_LOG_INFO( gLogFilter, Debug::General, "AutofillItemEcorewWl::IsSensitiveData \n" );
140   return mSensitiveData;
141 }
142
143 void AutofillItemEcorewWl::SetSaveValue( const std::string& value )
144 {
145   mValue = value;
146 #ifdef CAPI_AUTOFILL_SUPPORT
147   autofill_save_item_set_value( mAutofillSaveItemHandle, mValue.c_str() );
148 #endif // CAPI_AUTOFILL_SUPPORT
149 }
150
151 const std::string& AutofillItemEcorewWl::GetSaveValue() const
152 {
153   return mValue;
154 }
155
156 #ifdef CAPI_AUTOFILL_SUPPORT
157 autofill_item_h AutofillItemEcorewWl::GetAutofillItemHandle()
158 {
159   return mAutofillItemHandle;
160 }
161
162 autofill_save_item_h AutofillItemEcorewWl::GetAutofillSaveItemHandle()
163 {
164   return mAutofillSaveItemHandle;
165 }
166 #endif // CAPI_AUTOFILL_SUPPORT
167
168 void AutofillItemEcorewWl::AddPresentationList( const std::string& presentationText )
169 {
170   mPresentationTextList.push_back( presentationText );
171 }
172
173 void AutofillItemEcorewWl::AddFillValueList( const std::string& fillValue )
174 {
175   mValueList.push_back( fillValue );
176 }
177
178 const std::string& AutofillItemEcorewWl::GetPresentationText( int index ) const
179 {
180   return mPresentationTextList[index];
181 }
182
183 const std::string& AutofillItemEcorewWl::GetFillValue( int index ) const
184 {
185   return mValueList[index];
186 }
187
188 void AutofillItemEcorewWl::ClearPresentationTextList()
189 {
190   mPresentationTextList.clear();
191 }
192
193 void AutofillItemEcorewWl::ClearFillValueList()
194 {
195   mValueList.clear();
196 }
197
198 unsigned int AutofillItemEcorewWl::GetFillValueCount()
199 {
200   return mValueList.size();
201 }
202
203 } // Adaptor
204
205 } // Internal
206
207 } // Dali