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