[Tizen] Add AutofillContainer class and autofill implementation
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-field-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H
3
4 /*
5  * Copyright (c) 2017 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/devel-api/adaptor-framework/clipboard-event-notifier.h>
23 #include <dali/devel-api/adaptor-framework/input-method-context.h>
24 #include <dali/devel-api/adaptor-framework/autofill-item.h>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/public-api/controls/control-impl.h>
28 #include <dali-toolkit/public-api/controls/text-controls/text-field.h>
29 #include <dali-toolkit/internal/text/decorator/text-decorator.h>
30 #include <dali-toolkit/internal/text/text-control-interface.h>
31 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
32 #include <dali-toolkit/internal/text/text-controller.h>
33 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
34
35 namespace Dali
36 {
37
38 namespace Toolkit
39 {
40
41 namespace Internal
42 {
43 /**
44  * @brief A control which renders a short text string.
45  */
46 class TextField : public Control, public Text::ControlInterface, public Text::EditableControlInterface
47 {
48 public:
49
50   /**
51    * @copydoc Dali::Toollkit::TextField::New()
52    */
53   static Toolkit::TextField New();
54
55   // Properties
56
57   /**
58    * @brief Called when a property of an object of this type is set.
59    *
60    * @param[in] object The object whose property is set.
61    * @param[in] index The property index.
62    * @param[in] value The new property value.
63    */
64   static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
65
66   /**
67    * @brief Called to retrieve a property of an object of this type.
68    *
69    * @param[in] object The object whose property is to be retrieved.
70    * @param[in] index The property index.
71    * @return The current value of the property.
72    */
73   static Property::Value GetProperty( BaseObject* object, Property::Index index );
74
75   /**
76    * @copydoc Dali::Toollkit::TextField::GetInputMethodContext()
77    */
78   InputMethodContext GetInputMethodContext();
79
80   /**
81    * Connects a callback function with the object's signals.
82    * @param[in] object The object providing the signal.
83    * @param[in] tracker Used to disconnect the signal.
84    * @param[in] signalName The signal to connect to.
85    * @param[in] functor A newly allocated FunctorDelegate.
86    * @return True if the signal was connected.
87    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
88    */
89   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
90
91   /**
92    * @copydoc TextField::TextChangedSignal()
93    */
94   Toolkit::TextField::TextChangedSignalType&  TextChangedSignal();
95
96   /**
97    * @copydoc TextField::MaxLengthReachedSignal()
98    */
99   Toolkit::TextField::MaxLengthReachedSignalType&  MaxLengthReachedSignal();
100
101   /**
102    * @copydoc TextField::TextChangedSignal()
103    */
104   Toolkit::TextField::InputStyleChangedSignalType& InputStyleChangedSignal();
105
106   /**
107    * @brief Called to select the whole texts.
108    */
109   void SelectWholeText();
110
111     /**
112    * @brief Called to unselect the whole texts.
113    */
114   void SelectNone();
115
116     /**
117    * @brief Called to get selected text.
118    * @return Selected text in the TextField.
119    */
120   std::string SelectedText();
121
122 private: // From Control
123
124   /**
125    * @copydoc Control::OnInitialize()
126    */
127   virtual void OnInitialize();
128
129   /**
130    * @copydoc Control::OnStyleChange()
131    */
132   virtual void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change );
133
134   /**
135    * @copydoc Control::GetNaturalSize()
136    */
137   virtual Vector3 GetNaturalSize();
138
139   /**
140    * @copydoc Control::GetHeightForWidth()
141    */
142   virtual float GetHeightForWidth( float width );
143
144   /**
145    * @copydoc Control::OnInitialize()
146    */
147   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
148
149   /**
150    * @copydoc Control::OnKeyInputFocusGained()
151    */
152   virtual void OnKeyInputFocusGained();
153
154   /**
155    * @copydoc Control::OnKeyInputFocusLost()
156    */
157   virtual void OnKeyInputFocusLost();
158
159   /**
160    * @copydoc Control::OnTap()
161    */
162   virtual void OnTap( const TapGesture& tap );
163
164   /**
165    * @copydoc Control::OnPan()
166    */
167   virtual void OnPan( const PanGesture& gesture );
168
169   /**
170    * @copydoc Control::OnLongPress()
171    */
172   virtual void OnLongPress( const LongPressGesture& gesture );
173
174   /**
175    * @copydoc Control::OnStageConnection()
176    */
177   virtual void OnStageConnection( int depth );
178
179   /**
180    * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
181    */
182   virtual bool OnKeyEvent(const KeyEvent& event);
183
184 // From ControlInterface
185
186   /**
187    * @copydoc Text::ControlInterface::RequestTextRelayout()
188    */
189   virtual void RequestTextRelayout();
190
191 // From EditableControlInterface
192
193   /**
194    * @copydoc Text::ControlInterface::TextChanged()
195    */
196   virtual void TextChanged();
197
198   /**
199    * @copydoc Text::ControlInterface::MaxLengthReached()
200    */
201   virtual void MaxLengthReached();
202
203   /**
204    * @copydoc Text::ControlInterface::InputStyleChanged()
205    */
206   virtual void InputStyleChanged( Text::InputStyle::Mask inputStyleMask );
207
208   /**
209    * @copydoc Text::ControlInterface::AddDecoration()
210    */
211   virtual void AddDecoration( Actor& actor, bool needsClipping );
212
213 private: // Implementation
214
215   /**
216    * @copydoc Dali::Toolkit::Text::Controller::(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
217    */
218   InputMethodContext::CallbackData OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent );
219
220   /**
221    * @brief Callback when Clipboard signals an item should be pasted
222    * @param[in] clipboard handle to Clipboard Event Notifier
223    */
224   void OnClipboardTextSelected( ClipboardEventNotifier& clipboard );
225
226   /**
227    * @brief Get a Property Map for the image used for the required Handle Image
228    * @param[out] value the returned image property
229    * @param[in] handleType the type of handle
230    * @param[in] handleImageType the type of image for the given handleType
231    */
232   void GetHandleImagePropertyValue(  Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType );
233
234   /**
235    * @brief Enable or disable clipping.
236    */
237   void EnableClipping();
238
239   /**
240    * @brief Callback when keyboard is shown/hidden.
241    *
242    * @param[in] keyboardShown True if keyboard is shown.
243    */
244   void KeyboardStatusChanged( bool keyboardShown );
245
246   /**
247    * @brief Callback when TextField is touched
248    *
249    * @param[in] actor TextField touched
250    * @param[in] touch Touch information
251    */
252   bool OnTouched( Actor actor, const TouchData& touch );
253
254   /**
255    * @brief Callbacks called on idle.
256    *
257    * If there are notifications of change of input style on the queue, Toolkit::TextField::InputStyleChangedSignal() are emitted.
258    */
259   void OnIdleSignal();
260
261   /**
262    * Construct a new TextField.
263    */
264   TextField();
265
266   /**
267    * A reference counted object may only be deleted by calling Unreference()
268    */
269   virtual ~TextField();
270
271   // Undefined copy constructor and assignment operators
272   TextField(const TextField&);
273   TextField& operator=(const TextField& rhs);
274
275   /**
276    * @brief Render view, create and attach actor(s) to this Text Field.
277    */
278   void RenderText( Text::Controller::UpdateTextType updateTextType );
279
280   // Connection needed to re-render text, when a Text Field returns to the stage.
281   void OnStageConnect( Dali::Actor actor );
282
283 public: // For UTC only
284
285   Text::ControllerPtr GetTextController() { return mController; }
286
287 private: // Data
288
289   // Signals
290   Toolkit::TextField::TextChangedSignalType mTextChangedSignal;
291   Toolkit::TextField::MaxLengthReachedSignalType mMaxLengthReachedSignal;
292   Toolkit::TextField::InputStyleChangedSignalType mInputStyleChangedSignal;
293
294   InputMethodContext mInputMethodContext;
295   Text::ControllerPtr mController;
296   Text::RendererPtr mRenderer;
297   Text::DecoratorPtr mDecorator;
298   Toolkit::Control mStencil; ///< For EXCEED_POLICY_CLIP
299   std::vector<Actor> mClippingDecorationActors;   ///< Decoration actors which need clipping.
300   Dali::InputMethodOptions mInputMethodOptions;
301   Dali::AutofillItem mAutofillItem;
302
303   Actor mRenderableActor;
304   Actor mActiveLayer;
305   Actor mBackgroundActor;
306   CallbackBase* mIdleCallback;
307
308   float mAlignmentOffset;
309   int mRenderingBackend;
310   int mExceedPolicy;
311   bool mHasBeenStaged:1;
312 };
313
314 } // namespace Internal
315
316 // Helpers for public-api forwarding methods
317
318 inline Toolkit::Internal::TextField& GetImpl( Toolkit::TextField& textField )
319 {
320   DALI_ASSERT_ALWAYS(textField);
321
322   Dali::RefObject& handle = textField.GetImplementation();
323
324   return static_cast<Toolkit::Internal::TextField&>(handle);
325 }
326
327 inline const Toolkit::Internal::TextField& GetImpl( const Toolkit::TextField& textField )
328 {
329   DALI_ASSERT_ALWAYS(textField);
330
331   const Dali::RefObject& handle = textField.GetImplementation();
332
333   return static_cast<const Toolkit::Internal::TextField&>(handle);
334 }
335
336 } // namespace Toolkit
337
338 } // namespace Dali
339
340 #endif // DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H