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