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