Reduce Cyclomatic Complexity of some methods in text-typesetter, transtion-data ...
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-editor-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_EDITOR_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_EDITOR_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/public-api/animation/animation.h>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/public-api/controls/control-impl.h>
28 #include <dali-toolkit/devel-api/controls/scroll-bar/scroll-bar.h>
29 #include <dali-toolkit/public-api/controls/text-controls/text-editor.h>
30 #include <dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h>
31 #include <dali-toolkit/internal/text/decorator/text-decorator.h>
32 #include <dali-toolkit/internal/text/text-control-interface.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/internal/text/text-controller.h>
36 #include <dali-toolkit/internal/text/text-vertical-scroller.h>
37 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
38
39 namespace Dali
40 {
41
42 namespace Toolkit
43 {
44
45 namespace Internal
46 {
47 /**
48  * @brief A control which renders a long text string with styles.
49  */
50 class TextEditor : public Control, public Text::ControlInterface, public Text::EditableControlInterface, public Text::SelectableControlInterface
51 {
52 public:
53
54   /**
55    * @copydoc Dali::Toollkit::TextEditor::New()
56    */
57   static Toolkit::TextEditor New();
58
59   // Properties
60
61   /**
62    * @brief Called when a property of an object of this type is set.
63    *
64    * @param[in] object The object whose property is set.
65    * @param[in] index The property index.
66    * @param[in] value The new property value.
67    */
68   static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
69
70   /**
71    * @brief Called to retrieve a property of an object of this type.
72    *
73    * @param[in] object The object whose property is to be retrieved.
74    * @param[in] index The property index.
75    * @return The current value of the property.
76    */
77   static Property::Value GetProperty( BaseObject* object, Property::Index index );
78
79   /**
80    * @copydoc Dali::Toollkit::TextEditor::GetInputMethodContext()
81    */
82   InputMethodContext GetInputMethodContext();
83
84   /**
85    * @copydoc Dali::Toollkit::TextEditor::MaxLengthReachedSignal()
86    */
87   DevelTextEditor::MaxLengthReachedSignalType&  MaxLengthReachedSignal();
88
89   /**
90    * Connects a callback function with the object's signals.
91    * @param[in] object The object providing the signal.
92    * @param[in] tracker Used to disconnect the signal.
93    * @param[in] signalName The signal to connect to.
94    * @param[in] functor A newly allocated FunctorDelegate.
95    * @return True if the signal was connected.
96    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
97    */
98   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
99
100   /**
101    * @copydoc TextEditor::TextChangedSignal()
102    */
103   Toolkit::TextEditor::TextChangedSignalType&  TextChangedSignal();
104
105   /**
106    * @copydoc TextEditor::TextChangedSignal()
107    */
108   Toolkit::TextEditor::InputStyleChangedSignalType& InputStyleChangedSignal();
109
110   /**
111    * @copydoc TextEditor::ScrollStateChangedSignal()
112    */
113   Toolkit::TextEditor::ScrollStateChangedSignalType& ScrollStateChangedSignal();
114
115 private: // From Control
116
117   /**
118    * @copydoc Control::OnInitialize()
119    */
120   void OnInitialize() override;
121
122   /**
123    * @copydoc Control::OnStyleChange()
124    */
125   void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change ) override;
126
127   /**
128    * @copydoc Control::GetNaturalSize()
129    */
130   Vector3 GetNaturalSize() override;
131
132   /**
133    * @copydoc Control::GetHeightForWidth()
134    */
135   float GetHeightForWidth( float width ) override;
136
137   /**
138    * @copydoc Control::OnInitialize()
139    */
140   void OnRelayout( const Vector2& size, RelayoutContainer& container ) override;
141
142   /**
143    * @copydoc Control::OnKeyInputFocusGained()
144    */
145   void OnKeyInputFocusGained() override;
146
147   /**
148    * @copydoc Control::OnKeyInputFocusLost()
149    */
150   void OnKeyInputFocusLost() 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 TextChanged() override;
190
191   /**
192    * @copydoc Text::EditableControlInterface::MaxLengthReached()
193    */
194   void MaxLengthReached() override;
195
196   /**
197    * @copydoc Text::EditableControlInterface::InputStyleChanged()
198    */
199   void InputStyleChanged( Text::InputStyle::Mask inputStyleMask ) override;
200
201   /**
202    * @copydoc Text::EditableControlInterface::AddDecoration()
203    */
204   void AddDecoration( Actor& actor, bool needsClipping ) override;
205
206 // From SelectableControlInterface
207 public:
208   /**
209    * @copydoc Text::SelectableControlInterface::SetTextSelectionRange()
210    */
211   void SetTextSelectionRange(const uint32_t *start, const uint32_t *end) override;
212
213   /**
214    * @copydoc Text::SelectableControlInterface::GetTextSelectionRange()
215    */
216   Uint32Pair GetTextSelectionRange() const override;
217
218   /**
219    * @copydoc Text::SelectableControlInterface::SelectWholeText()
220    */
221   void SelectWholeText() override;
222
223   /**
224    * @copydoc Text::SelectableControlInterface::SelectNone()
225    */
226   void SelectNone() override;
227
228   /**
229    * @copydoc Text::SelectableControlInterface::GetSelectedText()
230    */
231   string GetSelectedText() const override;
232
233   /**
234    * @copydoc Text::EditableControlInterface::IsEditable()
235    */
236   bool IsEditable() const override;
237
238   /**
239    * @copydoc Text::EditableControlInterface::SetEditable()
240    */
241   void SetEditable( bool editable ) override;
242
243 private: // Implementation
244
245   /**
246    * @copydoc Dali::Toolkit::Text::Controller::(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
247    */
248   InputMethodContext::CallbackData OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent );
249
250   /**
251    * @brief Callback when Clipboard signals an item should be pasted
252    * @param[in] clipboard handle to Clipboard Event Notifier
253    */
254   void OnClipboardTextSelected( ClipboardEventNotifier& clipboard );
255
256   /**
257    * @brief Get a Property Map for the image used for the required Handle Image
258    * @param[out] value the returned image property
259    * @param[in] handleType the type of handle
260    * @param[in] handleImageType the type of image for the given handleType
261    */
262   void GetHandleImagePropertyValue(  Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType );
263
264   /**
265    * @brief Callback when keyboard is shown/hidden.
266    *
267    * @param[in] keyboardShown True if keyboard is shown.
268    */
269   void KeyboardStatusChanged( bool keyboardShown );
270
271   /**
272    * @brief update scroll bar position
273    *
274    * If text scroll is occurred, create or update scroll bar position
275    */
276   void UpdateScrollBar();
277
278   /**
279    * @brief Callback when TextEditor is touched
280    *
281    * @param[in] actor TextEditor touched
282    * @param[in] touch Touch information
283    */
284   bool OnTouched( Actor actor, const TouchEvent& touch );
285
286   /**
287    * @brief Callbacks called on idle.
288    *
289    * If there are notifications of change of input style on the queue, Toolkit::TextEditor::InputStyleChangedSignal() are emitted.
290    */
291   void OnIdleSignal();
292
293   /**
294    * @brief set RenderActor's position with new scrollPosition
295    *
296    * Apply updated scroll position or start scroll animation if VerticalScrollAnimation is enabled
297    */
298   void ApplyScrollPosition();
299
300   /**
301    * @brief Callback function for ScrollBar indicator animation finished signal
302    *
303    * Emit ScrollBarStateChanged Signal and toggle mScrollStarted flag to false
304    */
305   void OnScrollIndicatorAnimationFinished( Animation& animation );
306
307   /**
308    * Construct a new TextEditor.
309    */
310   TextEditor();
311
312   /**
313    * A reference counted object may only be deleted by calling Unreference()
314    */
315   virtual ~TextEditor();
316
317   // Undefined copy constructor and assignment operators
318   TextEditor(const TextEditor&);
319   TextEditor& operator=(const TextEditor& rhs);
320
321   /**
322    * @brief Render view, create and attach actor(s) to this text editor.
323    */
324   void RenderText( Text::Controller::UpdateTextType updateTextType );
325
326   // Connection needed to re-render text, when a text editor returns to the scene.
327   void OnSceneConnect( Dali::Actor actor );
328
329 private: // Data
330   // Signals
331   Toolkit::TextEditor::TextChangedSignalType mTextChangedSignal;
332   Toolkit::TextEditor::InputStyleChangedSignalType mInputStyleChangedSignal;
333   Toolkit::TextEditor::ScrollStateChangedSignalType mScrollStateChangedSignal;
334   Toolkit::DevelTextEditor::MaxLengthReachedSignalType mMaxLengthReachedSignal;
335
336   InputMethodContext mInputMethodContext;
337   Text::ControllerPtr mController;
338   Text::RendererPtr mRenderer;
339   Text::DecoratorPtr mDecorator;
340   Text::TextVerticalScrollerPtr mTextVerticalScroller;
341   Toolkit::Control mStencil;
342   Toolkit::ScrollBar mScrollBar;
343   Dali::Animation mAnimation;                                              ///< Scroll indicator Show/Hide Animation.
344   Dali::TimePeriod mAnimationPeriod;
345   std::vector<Actor> mClippingDecorationActors;   ///< Decoration actors which need clipping.
346
347   Actor mRenderableActor;
348   Actor mActiveLayer;
349   CallbackBase* mIdleCallback;
350
351   float mAlignmentOffset;
352   float mScrollAnimationDuration;
353   float mLineSpacing;
354   int mRenderingBackend;
355   bool mHasBeenStaged:1;
356   bool mScrollAnimationEnabled:1;
357   bool mScrollBarEnabled:1;
358   bool mScrollStarted:1;
359 };
360
361 } // namespace Internal
362
363 // Helpers for public-api forwarding methods
364
365 inline Toolkit::Internal::TextEditor& GetImpl( Toolkit::TextEditor& textEditor )
366 {
367   DALI_ASSERT_ALWAYS(textEditor);
368
369   Dali::RefObject& handle = textEditor.GetImplementation();
370
371   return static_cast<Toolkit::Internal::TextEditor&>(handle);
372 }
373
374 inline const Toolkit::Internal::TextEditor& GetImpl( const Toolkit::TextEditor& textEditor )
375 {
376   DALI_ASSERT_ALWAYS(textEditor);
377
378   const Dali::RefObject& handle = textEditor.GetImplementation();
379
380   return static_cast<const Toolkit::Internal::TextEditor&>(handle);
381 }
382
383 } // namespace Toolkit
384
385 } // namespace Dali
386
387 #endif // DALI_TOOLKIT_INTERNAL_TEXT_EDITOR_H