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