[Tizen] Add AutofillContainer class and autofill implementation
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / autofill-container-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_AUTOFILL_CONTAINER_H
2 #define DALI_TOOLKIT_INTERNAL_AUTOFILL_CONTAINER_H
3
4 /*
5  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/object/base-object.h>
23 #include <dali/devel-api/adaptor-framework/autofill-manager.h>
24 #include <map>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/public-api/controls/control-impl.h>
28 #include <dali-toolkit/devel-api/controls/text-controls/autofill-container.h>
29
30
31 namespace Dali
32 {
33
34 namespace Toolkit
35 {
36
37 namespace Internal
38 {
39
40 /**
41  * @copydoc Toolkit::AutofillContainer
42  */
43 class AutofillContainer : public Dali::BaseObject
44 {
45 public:
46
47   /**
48    * @copydoc Dali::Toollkit::AutofillContainer::New()
49    */
50   static Toolkit::AutofillContainer New( const std::string& name );
51
52   /**
53    * @brief Initialize AutofillContainer
54    */
55   void Initialize( const std::string& name );
56
57   /**
58    * @copydoc Dali::Toollkit::AutofillContainer::AddAutofillItem()
59    */
60   void AddAutofillItem( Dali::Toolkit::Control control, Dali::Property::Index propertyIndex, const std::string& id, const std::string& label, Dali::AutofillItem::Hint hint, bool isSensitive );
61
62   /**
63    * @copydoc Dali::Toollkit::AutofillContainer::RemoveAutofillItem()
64    */
65   void RemoveAutofillItem( Dali::Toolkit::Control control );
66
67   /**
68    * @brief Gets AutofillGroup setting to AutofillContainer.
69    *
70    * @return The AutofillGroup instance
71    */
72   Dali::AutofillGroup GetAutofillGroup();
73
74   /**
75    * @copydoc Dali::Toollkit::AutofillContainer::SetFocusedControl()
76    */
77   void SetFocusedControl( Toolkit::Control focused );
78
79   /**
80    * @copydoc Dali::Toollkit::AutofillContainer::GetFocusedControl()
81    */
82   Toolkit::Control GetFocusedControl();
83
84   /**
85    * @copydoc Dali::Toollkit::AutofillContainer::SaveAutofillData()
86    */
87   void SaveAutofillData();
88
89   /**
90    * @copydoc Dali::Toollkit::AutofillContainer::RequestFillData()
91    */
92   void RequestFillData();
93
94   /**
95    * @brief Sets the Autofill Service Name
96    *
97    * @param serviceName Autofill Service Name
98    */
99   void SetAutofillServiceName( const std::string& serviceName );
100
101   /**
102    * @copydoc Dali::Toollkit::AutofillContainer::GetAutofillServiceName()
103    */
104   const std::string& GetAutofillServiceName() const;
105
106   /**
107    * @brief Sets the Autofill Service Message
108    *
109    * @param serviceMessage Autofill Service Message
110    */
111   void SetAutofillServiceMessage( const std::string& serviceMessage );
112
113   /**
114    * @copydoc Dali::Toollkit::AutofillContainer::GetAutofillServiceMessage()
115    */
116   const std::string& GetAutofillServiceMessage() const;
117
118   /**
119    * @brief Sets the Autofill Service Image Path
120    *
121    * @param serviceImagePath Autofill Service Image Path
122    */
123   void SetAutofillServiceImagePath( const std::string& serviceImagePath );
124
125   /**
126    * @copydoc Dali::Toollkit::AutofillContainer::GetAutofillServiceImagePath()
127    */
128   const std::string& GetAutofillServiceImagePath() const;
129
130   /**
131    * @copydoc Dali::Toollkit::AutofillContainer::GetListCount()
132    */
133   unsigned int GetListCount();
134
135   /**
136    * @copydoc Dali::Toollkit::AutofillContainer::GetListItem()
137    */
138   const std::string& GetListItem( unsigned int index ) const;
139
140   /**
141    * @copydoc Dali::Toollkit::AutofillContainer::SetSelectedItem()
142    */
143   void SetSelectedItem( const std::string& selected );
144
145   /**
146    * @brief Callback when Autofill Authentication information is recieved.
147    */
148   void OnAutofillAuthReceived();
149
150   /**
151    * @brief Callback when Autofill Fill Response is recieved.
152    * @param[in] item The callback parameter
153    */
154   void OnDataFillReceived( Dali::AutofillItem item );
155
156   /**
157    * @brief Callback when the values to be filled are multiple.
158    */
159   void OnListReceived();
160
161   /**
162    * @copydoc Dali::Toollkit::AutofillContainer::AutofillServiceShownSignal()
163    */
164   Toolkit::AutofillContainer::AuthenticationSignalType& AutofillServiceShownSignal();
165
166   /**
167    * @copydoc Dali::Toollkit::AutofillContainer::AutofillListShownSignal()
168    */
169   Toolkit::AutofillContainer::ListShownSignalType& AutofillListShownSignal();
170
171   /**
172    * Connects a callback function with the object's signals.
173    * @param[in] object The object providing the signal.
174    * @param[in] tracker Used to disconnect the signal.
175    * @param[in] signalName The signal to connect to.
176    * @param[in] functor A newly allocated FunctorDelegate.
177    * @return True if the signal was connected.
178    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
179    */
180   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
181
182
183 private: // Implementation
184
185   /**
186    * Construct a new AutofillContainer.
187    */
188   AutofillContainer();
189
190   /**
191    * A reference counted object may only be deleted by calling Unreference()
192    */
193   virtual ~AutofillContainer();
194
195 private:
196
197   // Undefined copy constructor and assignment operators
198   AutofillContainer(const AutofillContainer&);
199   AutofillContainer& operator=(const AutofillContainer& rhs);
200
201 private: // Data
202
203   Dali::AutofillManager mAutofillManager;
204   Dali::AutofillGroup mAutofillGroup;
205   std::vector<Dali::Toolkit::Control> mControlItemList; ///< The List of Control adding to AutofillContainer
206   //std::map<Dali::Toolkit::Control, Dali::AutofillItem> mControlList;
207   std::vector< std::pair< Dali::Toolkit::Control, Dali::AutofillItem > > mControlList;
208
209   SlotDelegate< AutofillContainer > mSlotDelegate;
210
211   Property::Index mPropertyIndex;  ///< The index of property registered by each control
212
213   Toolkit::AutofillContainer::AuthenticationSignalType mAuthenticationEventSignal;
214   Toolkit::AutofillContainer::ListShownSignalType mListEventSignal;
215
216   std::string mAutofillServiceName;
217   std::string mAutofillServiceMessage;
218   std::string mAutofillServiceImagePath;
219
220   Toolkit::Control mCurrentFocused;
221 };
222
223 } // namespace Internal
224
225 // Helpers for public-api forwarding methods
226
227 inline Toolkit::Internal::AutofillContainer& GetImpl( Toolkit::AutofillContainer& autofillContainer )
228 {
229   DALI_ASSERT_ALWAYS(autofillContainer);
230
231   Dali::BaseObject& handle = autofillContainer.GetBaseObject();
232
233   return static_cast<Toolkit::Internal::AutofillContainer&>(handle);
234 }
235
236 inline const Toolkit::Internal::AutofillContainer& GetImpl( const Toolkit::AutofillContainer& autofillContainer )
237 {
238   DALI_ASSERT_ALWAYS(autofillContainer);
239
240   const Dali::BaseObject& handle = autofillContainer.GetBaseObject();
241
242   return static_cast<const Toolkit::Internal::AutofillContainer&>(handle);
243 }
244
245 } // namespace Toolkit
246
247 } // namespace Dali
248
249 #endif // DALI_TOOLKIT_INTERNAL_AUTOFILL_CONTAINER_H