[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) 2021 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/devel-api/controls/control-devel.h>
28 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
29 #include <dali-toolkit/internal/text/decorator/text-decorator.h>
30 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
31 #include <dali-toolkit/internal/text/text-control-interface.h>
32 #include <dali-toolkit/internal/text/text-controller.h>
33 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
34 #include <dali-toolkit/internal/text/text-selectable-control-interface.h>
35 #include <dali-toolkit/public-api/controls/control-impl.h>
36 #include <dali-toolkit/public-api/controls/text-controls/text-field.h>
37
38 namespace Dali
39 {
40 namespace Toolkit
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    * @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   Text::ControllerPtr getController();
107
108 private: // From Control
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::OnAccessibilityActivated()
146    */
147   bool OnAccessibilityActivated() override;
148
149   /**
150    * @copydoc Control::OnTap()
151    */
152   void OnTap(const TapGesture& tap) override;
153
154   /**
155    * @copydoc Control::OnPan()
156    */
157   void OnPan(const PanGesture& gesture) override;
158
159   /**
160    * @copydoc Control::OnLongPress()
161    */
162   void OnLongPress(const LongPressGesture& gesture) override;
163
164   /**
165    * @copydoc Control::OnSceneConnection()
166    */
167   void OnSceneConnection(int depth) override;
168
169   /**
170    * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
171    */
172   bool OnKeyEvent(const KeyEvent& event) override;
173
174   // From ControlInterface
175
176   /**
177    * @copydoc Text::ControlInterface::RequestTextRelayout()
178    */
179   void RequestTextRelayout() override;
180
181   // From EditableControlInterface
182
183   /**
184    * @copydoc Text::EditableControlInterface::TextChanged()
185    */
186   void TextInserted(unsigned int position, unsigned int length, const std::string& content) override;
187
188   /**
189    * @copydoc Text::EditableControlInterface::TextDeleted()
190    */
191   void TextDeleted(unsigned int position, unsigned int length, const std::string& content) override;
192
193   /**
194    * @copydoc Text::EditableControlInterface::CaretMoved()
195    */
196   void CaretMoved(unsigned int position) override;
197
198   /**
199    * @copydoc Text::EditableControlInterface::TextChanged()
200    */
201   void TextChanged(bool immediate) override;
202
203   /**
204    * @copydoc Text::EditableControlInterface::MaxLengthReached()
205    */
206   void MaxLengthReached() override;
207
208   /**
209    * @copydoc Text::EditableControlInterface::InputStyleChanged()
210    */
211   void InputStyleChanged(Text::InputStyle::Mask inputStyleMask) override;
212
213   /**
214    * @copydoc Text::EditableControlInterface::AddDecoration()
215    */
216   void AddDecoration(Actor& actor, bool needsClipping) override;
217
218   // From SelectableControlInterface
219 public:
220   /**
221    * @copydoc Text::SelectableControlInterface::SetTextSelectionRange()
222    */
223   void SetTextSelectionRange(const uint32_t* start, const uint32_t* end) override;
224
225   /**
226    * @copydoc Text::SelectableControlInterface::GetTextSelectionRange()
227    */
228   Uint32Pair GetTextSelectionRange() const override;
229
230   /**
231    * @copydoc Text::SelectableControlInterface::SelectWholeText()
232    */
233   void SelectWholeText() override;
234
235   /**
236    * @copydoc Text::SelectableControlInterface::SelectNone()
237    */
238   void SelectNone() override;
239
240   /**
241    * @copydoc Text::SelectableControlInterface::GetSelectedText()
242    */
243   string GetSelectedText() const override;
244
245   /**
246    * @copydoc Text::EditableControlInterface::IsEditable()
247    */
248   bool IsEditable() const override;
249
250   /**
251    * @copydoc Text::EditableControlInterface::SetEditable()
252    */
253   void SetEditable(bool editable) override;
254
255 private: // Implementation
256   /**
257    * @copydoc Dali::Toolkit::Text::Controller::(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
258    */
259   InputMethodContext::CallbackData OnInputMethodContextEvent(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent);
260
261   /**
262    * @brief Callback when Clipboard signals an item should be pasted
263    * @param[in] clipboard handle to Clipboard Event Notifier
264    */
265   void OnClipboardTextSelected(ClipboardEventNotifier& clipboard);
266
267   /**
268    * @brief Get a Property Map for the image used for the required Handle Image
269    * @param[out] value the returned image property
270    * @param[in] handleType the type of handle
271    * @param[in] handleImageType the type of image for the given handleType
272    */
273   void GetHandleImagePropertyValue(Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType);
274
275   /**
276    * @brief Enable or disable clipping.
277    */
278   void EnableClipping();
279
280   /**
281    * @brief Callback when keyboard is shown/hidden.
282    *
283    * @param[in] keyboardShown True if keyboard is shown.
284    */
285   void KeyboardStatusChanged(bool keyboardShown);
286
287   /**
288    * @brief Callback when TextField is touched
289    *
290    * @param[in] actor TextField touched
291    * @param[in] touch Touch information
292    */
293   bool OnTouched(Actor actor, const TouchEvent& touch);
294
295   /**
296    * @brief Callbacks called on idle.
297    *
298    * If there are notifications of change of input style on the queue, Toolkit::TextField::InputStyleChangedSignal() are emitted.
299    */
300   void OnIdleSignal();
301
302   /**
303    * @brief Emits TextChanged signal.
304    */
305   void EmitTextChangedSignal();
306
307   /**
308    * Construct a new TextField.
309    */
310   TextField();
311
312   /**
313    * A reference counted object may only be deleted by calling Unreference()
314    */
315   virtual ~TextField();
316
317   // Undefined copy constructor and assignment operators
318   TextField(const TextField&);
319   TextField& operator=(const TextField& rhs);
320
321   /**
322    * @brief Resize actor to the given size.
323    *
324    * @param[in] actor The actor to be resized.
325    * @param[in] size Size to change.
326    */
327   void ResizeActor(Actor& actor, const Vector2& size);
328
329   /**
330    * @brief Render view, create and attach actor(s) to this Text Field.
331    */
332   void RenderText(Text::Controller::UpdateTextType updateTextType);
333
334   // Connection needed to re-render text, when a Text Field returns to the scene.
335   void OnSceneConnect(Dali::Actor actor);
336
337 public: // For UTC only
338   Text::ControllerPtr GetTextController()
339   {
340     return mController;
341   }
342
343 private: // Data
344   // Signals
345   Toolkit::TextField::TextChangedSignalType       mTextChangedSignal;
346   Toolkit::TextField::MaxLengthReachedSignalType  mMaxLengthReachedSignal;
347   Toolkit::TextField::InputStyleChangedSignalType mInputStyleChangedSignal;
348
349   InputMethodContext       mInputMethodContext;
350   Text::ControllerPtr      mController;
351   Text::RendererPtr        mRenderer;
352   Text::DecoratorPtr       mDecorator;
353   Toolkit::Control         mStencil;                  ///< For EXCEED_POLICY_CLIP
354   std::vector<Actor>       mClippingDecorationActors; ///< Decoration actors which need clipping.
355   Dali::InputMethodOptions mInputMethodOptions;
356   Dali::AutofillItem mAutofillItem;
357
358   Actor         mRenderableActor;
359   Actor         mActiveLayer;
360   Actor         mBackgroundActor;
361   CallbackBase* mIdleCallback;
362
363   float mAlignmentOffset;
364   int   mRenderingBackend;
365   int   mExceedPolicy;
366   bool  mHasBeenStaged : 1;
367   bool  mTextChanged : 1; ///< If true, emits TextChangedSignal in next OnRelayout().
368
369 protected:
370   struct AccessibleImpl : public DevelControl::AccessibleImpl,
371                           public virtual Dali::Accessibility::Text,
372                           public virtual Dali::Accessibility::EditableText
373   {
374     using DevelControl::AccessibleImpl::AccessibleImpl;
375
376     std::string           GetName() override;
377     std::string           GetText(size_t startOffset, size_t endOffset) override;
378     size_t                GetCharacterCount() override;
379     size_t                GetCaretOffset() override;
380     bool                  SetCaretOffset(size_t offset) override;
381     Accessibility::Range  GetTextAtOffset(size_t offset, Accessibility::TextBoundary boundary) override;
382     Accessibility::Range  GetSelection(size_t selectionNum) override;
383     bool                  RemoveSelection(size_t selectionNum) override;
384     bool                  SetSelection(size_t selectionNum, size_t startOffset, size_t endOffset) override;
385     bool                  CopyText(size_t startPosition, size_t endPosition) override;
386     bool                  CutText(size_t startPosition, size_t endPosition) override;
387     Accessibility::States CalculateStates() override;
388   };
389 };
390
391 } // namespace Internal
392
393 // Helpers for public-api forwarding methods
394
395 inline Toolkit::Internal::TextField& GetImpl(Toolkit::TextField& textField)
396 {
397   DALI_ASSERT_ALWAYS(textField);
398
399   Dali::RefObject& handle = textField.GetImplementation();
400
401   return static_cast<Toolkit::Internal::TextField&>(handle);
402 }
403
404 inline const Toolkit::Internal::TextField& GetImpl(const Toolkit::TextField& textField)
405 {
406   DALI_ASSERT_ALWAYS(textField);
407
408   const Dali::RefObject& handle = textField.GetImplementation();
409
410   return static_cast<const Toolkit::Internal::TextField&>(handle);
411 }
412
413 } // namespace Toolkit
414
415 } // namespace Dali
416
417 #endif // DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H