[Tizen] Add DALi Autofill implementation
[platform/core/uifw/dali-adaptor.git] / dali / internal / input / tizen-wayland / autofill-group-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-group-impl-ecore-wl.h>
20
21 // EXTERNAL INCLUDES
22 #include <cstring> // for strcmp
23 #include <dali/public-api/object/type-registry.h>
24 #include <dali/integration-api/debug.h>
25
26 // INTERNAL INCLUDES
27 #include <dali/internal/input/tizen-wayland/autofill-manager-impl-ecore-wl.h>
28
29 namespace Dali
30 {
31
32 namespace Internal
33 {
34
35 namespace Adaptor
36 {
37
38 namespace
39 {
40 #if defined(DEBUG_ENABLED)
41 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_AUTOFILL");
42 #endif
43
44 BaseHandle Create()
45 {
46   return Dali::Internal::Adaptor::AutofillGroup::New( "" );
47 }
48
49 Dali::TypeRegistration type( typeid(Dali::AutofillGroup), typeid(Dali::BaseHandle), Create );
50
51 } // unnamed namespace
52
53
54 AutofillGroupEcoreWl::AutofillGroupEcoreWl( const std::string groupId )
55 : mAutofillItemList(),
56   mGroupId( groupId )
57 {
58 #ifdef CAPI_AUTOFILL_SUPPORT
59   mAutofillGroupHandle =  NULL;
60   mAutofillSaveGroupHandle = NULL;
61 #endif // CAPI_AUTOFILL_SUPPORT
62 }
63
64 AutofillGroupEcoreWl::~AutofillGroupEcoreWl()
65 {
66 #ifdef CAPI_AUTOFILL_SUPPORT
67   if( mAutofillGroupHandle )
68   {
69     autofill_view_info_destroy( mAutofillGroupHandle );
70     mAutofillGroupHandle = NULL;
71   }
72   if( mAutofillSaveGroupHandle )
73   {
74     autofill_save_view_info_destroy( mAutofillSaveGroupHandle );
75     mAutofillSaveGroupHandle = NULL;
76   }
77 #endif // CAPI_AUTOFILL_SUPPORT
78 }
79
80
81 Dali::AutofillGroup AutofillGroupEcoreWl::New( const std::string& groupId )
82 {
83   Dali::Internal::Adaptor::AutofillGroup* group = new Dali::Internal::Adaptor::AutofillGroupEcoreWl( groupId );
84   Dali::AutofillGroup handle = Dali::AutofillGroup( group );
85   group->Initialize();
86
87   return handle;
88 }
89
90 void AutofillGroupEcoreWl::Initialize()
91 {
92 #ifdef CAPI_AUTOFILL_SUPPORT
93   int ret = autofill_view_info_create( &mAutofillGroupHandle );
94   if( ret != AUTOFILL_ERROR_NONE )
95   {
96     DALI_LOG_ERROR( "Failed to create autofill group info handle : %d \n", ret );
97     return;
98   }
99
100   autofill_view_info_set_view_id( mAutofillGroupHandle, mGroupId.c_str() );
101
102 #endif // CAPI_AUTOFILL_SUPPORT
103 }
104
105 const std::string& AutofillGroupEcoreWl::GetId() const
106 {
107   DALI_LOG_INFO( gLogFilter, Debug::General, "AutofillGroupEcoreWl::GetId \n" );
108   return mGroupId;
109 }
110
111 #ifdef CAPI_AUTOFILL_SUPPORT
112 autofill_view_info_h AutofillGroupEcoreWl::GetAutofillGroupHandle()
113 {
114   return mAutofillGroupHandle;
115 }
116
117 autofill_save_view_info_h AutofillGroupEcoreWl::GetAutofillSaveGroupHandle()
118 {
119   return mAutofillSaveGroupHandle;
120 }
121 #endif // CAPI_AUTOFILL_SUPPORT
122
123 void AutofillGroupEcoreWl::AddAutofillItem( Dali::AutofillItem item )
124 {
125 #ifdef CAPI_AUTOFILL_SUPPORT
126   Internal::Adaptor::AutofillItem& itemImpl = Internal::Adaptor::GetImplementation( item );
127   Internal::Adaptor::AutofillItemEcorewWl& itemImplWl = static_cast<Internal::Adaptor::AutofillItemEcorewWl&>( itemImpl );
128
129   if( mAutofillGroupHandle && itemImplWl.GetAutofillItemHandle() )
130   {
131     autofill_view_info_add_item( mAutofillGroupHandle, itemImplWl.GetAutofillItemHandle() );
132   }
133 #endif // CAPI_AUTOFILL_SUPPORT
134
135   // Pushes back an AutofillItem to the ItemList of AutofillGroup.
136   mAutofillItemList.push_back( item );
137 }
138
139 Dali::AutofillItem AutofillGroupEcoreWl::GetAutofillItem( const std::string& id )
140 {
141   Dali::AutofillItem item = Dali::AutofillItem();
142   for( std::vector<Dali::AutofillItem>::iterator iter = mAutofillItemList.begin(), endIter = mAutofillItemList.end(); iter !=  endIter; ++iter )
143   {
144     const std::string& itemId = ( *iter ).GetId();
145
146     if( itemId.compare( id ) == 0 )
147     {
148       item = ( *iter );
149     }
150   }
151   return item;
152 }
153
154 void AutofillGroupEcoreWl::ClearAutofillItemList()
155 {
156   for( std::vector<Dali::AutofillItem>::iterator iter = mAutofillItemList.begin(), endIter = mAutofillItemList.end(); iter !=  endIter; ++iter )
157   {
158     ( *iter ).ClearPresentationTextList();
159     ( *iter ).ClearFillValueList();
160   }
161 }
162
163 void AutofillGroupEcoreWl::SaveAutofillData()
164 {
165   DALI_LOG_INFO( gLogFilter, Debug::General, "AutofillGroupEcoreWl::SaveAutofillData\n" );
166 #ifdef CAPI_AUTOFILL_SUPPORT
167   // Creates autofill save view info handle.
168   autofill_save_view_info_create( &mAutofillSaveGroupHandle );
169   autofill_save_view_info_set_view_id( mAutofillSaveGroupHandle, mGroupId.c_str() );
170
171   for( std::vector<Dali::AutofillItem>::iterator iter = mAutofillItemList.begin(), endIter = mAutofillItemList.end(); iter !=  endIter; ++iter )
172   {
173     Internal::Adaptor::AutofillItem& itemImpl = Internal::Adaptor::GetImplementation( *iter );
174     Internal::Adaptor::AutofillItemEcorewWl& itemImplWl = static_cast<Internal::Adaptor::AutofillItemEcorewWl&>( itemImpl );
175
176     // Appends autofill save item in autofill save view.
177     autofill_save_view_info_add_item( mAutofillSaveGroupHandle, itemImplWl.GetAutofillSaveItemHandle() );
178   }
179 #endif // CAPI_AUTOFILL_SUPPORT
180 }
181
182 // If Autofill service sends authentication signal, AutofillManagerEcoreWl::ReceiveAuthInfo() would be called.
183 void AutofillGroupEcoreWl::RequestAuthentication()
184 {
185   DALI_LOG_INFO( gLogFilter, Debug::General, "AutofillGroupEcoreWl::RequestAuthentication\n" );
186
187 #ifdef CAPI_AUTOFILL_SUPPORT
188   Dali::AutofillManager manager = Dali::AutofillManager::Get();
189   Internal::Adaptor::AutofillManager& managerImpl = Internal::Adaptor::GetImplementation( manager );
190   Internal::Adaptor::AutofillManagerEcoreWl& managerImplWl = static_cast<Internal::Adaptor::AutofillManagerEcoreWl&>( managerImpl );
191
192   // Requests to invoke the authentication information.
193   // After requests of authentication, AutofillManagerEcoreWl::AuthInfoCallback would be called.
194   int ret = autofill_auth_info_request( managerImplWl.GetAutofillHandle(), mAutofillGroupHandle );
195   if( ret != AUTOFILL_ERROR_NONE )
196   {
197     DALI_LOG_ERROR( "Failed to request auth info. error : %d \n", ret );
198   }
199 #endif // CAPI_AUTOFILL_SUPPORT
200 }
201
202 // If Autofill service sends fill response signal, AutofillManagerEcoreWl::FillGroupItem() or
203 // AutofillManagerEcoreWl::FillMultipleGroupItem() would be called according to the number of group count.
204 void AutofillGroupEcoreWl::SendFillRequest()
205 {
206   DALI_LOG_INFO( gLogFilter, Debug::General, "AutofillGroupEcoreWl::SendFillRequest\n" );
207
208 #ifdef CAPI_AUTOFILL_SUPPORT
209   Dali::AutofillManager manager = Dali::AutofillManager::Get();
210   Internal::Adaptor::AutofillManager& managerImpl = Internal::Adaptor::GetImplementation( manager );
211   Internal::Adaptor::AutofillManagerEcoreWl& managerImplWl = static_cast<Internal::Adaptor::AutofillManagerEcoreWl&>( managerImpl );
212
213   // Removes all elements of each AutofillItem in AutofillGroup
214   ClearAutofillItemList();
215
216   // Sends fill request to fill out each input form.
217   // After request of fill data, AutofillManagerEcoreWl::FillResponseCallback would be called.
218   int ret = autofill_fill_request( managerImplWl.GetAutofillHandle(), mAutofillGroupHandle );
219   if( ret != AUTOFILL_ERROR_NONE )
220   {
221     DALI_LOG_ERROR( "Failed to request fill : %d \n", ret );
222   }
223 #endif // CAPI_AUTOFILL_SUPPORT
224 }
225
226 } // Adaptor
227
228 } // Internal
229
230 } // Dali