[Tizen](ATSPI) squashed implementation
[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/adaptor-framework/accessibility.h>
25 #include <dali/public-api/animation/animation.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 #include <dali-toolkit/internal/controls/control/control-data-impl.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
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    * Connects a callback function with the object's signals.
86    * @param[in] object The object providing the signal.
87    * @param[in] tracker Used to disconnect the signal.
88    * @param[in] signalName The signal to connect to.
89    * @param[in] functor A newly allocated FunctorDelegate.
90    * @return True if the signal was connected.
91    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
92    */
93   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
94
95   /**
96    * @copydoc TextEditor::TextChangedSignal()
97    */
98   Toolkit::TextEditor::TextChangedSignalType&  TextChangedSignal();
99
100   /**
101    * @copydoc TextEditor::TextChangedSignal()
102    */
103   Toolkit::TextEditor::InputStyleChangedSignalType& InputStyleChangedSignal();
104
105   /**
106    * @copydoc TextEditor::ScrollStateChangedSignal()
107    */
108   Toolkit::TextEditor::ScrollStateChangedSignalType& ScrollStateChangedSignal();
109
110 private: // From Control
111
112   /**
113    * @copydoc Control::OnInitialize()
114    */
115   virtual void OnInitialize();
116
117   /**
118    * @copydoc Control::OnStyleChange()
119    */
120   virtual void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change );
121
122   /**
123    * @copydoc Control::GetNaturalSize()
124    */
125   virtual Vector3 GetNaturalSize();
126
127   /**
128    * @copydoc Control::GetHeightForWidth()
129    */
130   virtual float GetHeightForWidth( float width );
131
132   /**
133    * @copydoc Control::OnInitialize()
134    */
135   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
136
137   /**
138    * @copydoc Control::OnKeyInputFocusGained()
139    */
140   virtual void OnKeyInputFocusGained();
141
142   /**
143    * @copydoc Control::OnKeyInputFocusLost()
144    */
145   virtual void OnKeyInputFocusLost();
146
147   /**
148    * @copydoc Control::OnTap()
149    */
150   virtual void OnTap( const TapGesture& tap );
151
152   /**
153    * @copydoc Control::OnPan()
154    */
155   virtual void OnPan( const PanGesture& gesture );
156
157   /**
158    * @copydoc Control::OnLongPress()
159    */
160   virtual void OnLongPress( const LongPressGesture& gesture );
161
162   /**
163    * @copydoc Control::OnStageConnection()
164    */
165   virtual void OnStageConnection( int depth );
166
167   /**
168    * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
169    */
170   virtual bool OnKeyEvent(const KeyEvent& event);
171
172 // From ControlInterface
173
174   /**
175    * @copydoc Text::ControlInterface::RequestTextRelayout()
176    */
177   virtual void RequestTextRelayout();
178
179 // From EditableControlInterface
180
181   /**
182    * @copydoc Text::ControlInterface::TextInserted()
183    */
184   virtual void TextInserted( unsigned int position, unsigned int length, const std::string &content );
185
186   /**
187    * @copydoc Text::ControlInterface::TextDeleted()
188    */
189   virtual void TextDeleted( unsigned int position, unsigned int length, const std::string &content );
190
191   /**
192    * @copydoc Text::ControlInterface::CaretMoved()
193    */
194   virtual void CaretMoved( unsigned int position );
195
196   /**
197    * @copydoc Text::ControlInterface::TextChanged()
198    */
199   virtual void TextChanged();
200
201   /**
202    * @copydoc Text::ControlInterface::MaxLengthReached()
203    */
204   virtual void MaxLengthReached();
205
206   /**
207    * @copydoc Text::ControlInterface::InputStyleChanged()
208    */
209   virtual void InputStyleChanged( Text::InputStyle::Mask inputStyleMask );
210
211   /**
212    * @copydoc Text::ControlInterface::AddDecoration()
213    */
214   virtual void AddDecoration( Actor& actor, bool needsClipping );
215
216   Text::ControllerPtr getController();
217
218 private: // Implementation
219
220   /**
221    * @copydoc Dali::Toolkit::Text::Controller::(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
222    */
223   InputMethodContext::CallbackData OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent );
224
225   /**
226    * @brief Callback when Clipboard signals an item should be pasted
227    * @param[in] clipboard handle to Clipboard Event Notifier
228    */
229   void OnClipboardTextSelected( ClipboardEventNotifier& clipboard );
230
231   /**
232    * @brief Get a Property Map for the image used for the required Handle Image
233    * @param[out] value the returned image property
234    * @param[in] handleType the type of handle
235    * @param[in] handleImageType the type of image for the given handleType
236    */
237   void GetHandleImagePropertyValue(  Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType );
238
239   /**
240    * @brief Callback when keyboard is shown/hidden.
241    *
242    * @param[in] keyboardShown True if keyboard is shown.
243    */
244   void KeyboardStatusChanged( bool keyboardShown );
245
246   /**
247    * @brief update scroll bar position
248    *
249    * If text scroll is occurred, create or update scroll bar position
250    */
251   void UpdateScrollBar();
252
253   /**
254    * @brief Callback when TextEditor is touched
255    *
256    * @param[in] actor TextEditor touched
257    * @param[in] touch Touch information
258    */
259   bool OnTouched( Actor actor, const TouchData& touch );
260
261   /**
262    * @brief Callbacks called on idle.
263    *
264    * If there are notifications of change of input style on the queue, Toolkit::TextEditor::InputStyleChangedSignal() are emitted.
265    */
266   void OnIdleSignal();
267
268   /**
269    * @brief set RenderActor's position with new scrollPosition
270    *
271    * Apply updated scroll position or start scroll animation if VerticalScrollAnimation is enabled
272    */
273   void ApplyScrollPosition();
274
275   /**
276    * @brief Callback function for ScrollBar indicator animation finished signal
277    *
278    * Emit ScrollBarStateChanged Signal and toggle mScrollStarted flag to false
279    */
280   void OnScrollIndicatorAnimationFinished( Animation& animation );
281
282   /**
283    * Construct a new TextEditor.
284    */
285   TextEditor();
286
287   /**
288    * A reference counted object may only be deleted by calling Unreference()
289    */
290   virtual ~TextEditor();
291
292   // Undefined copy constructor and assignment operators
293   TextEditor(const TextEditor&);
294   TextEditor& operator=(const TextEditor& rhs);
295
296   /**
297    * @brief Render view, create and attach actor(s) to this text editor.
298    */
299   void RenderText( Text::Controller::UpdateTextType updateTextType );
300
301   // Connection needed to re-render text, when a text editor returns to the stage.
302   void OnStageConnect( Dali::Actor actor );
303
304 private: // Data
305   // Signals
306   Toolkit::TextEditor::TextChangedSignalType mTextChangedSignal;
307   Toolkit::TextEditor::InputStyleChangedSignalType mInputStyleChangedSignal;
308   Toolkit::TextEditor::ScrollStateChangedSignalType mScrollStateChangedSignal;
309
310   InputMethodContext mInputMethodContext;
311   Text::ControllerPtr mController;
312   Text::RendererPtr mRenderer;
313   Text::DecoratorPtr mDecorator;
314   Text::TextVerticalScrollerPtr mTextVerticalScroller;
315   Toolkit::Control mStencil;
316   Toolkit::ScrollBar mScrollBar;
317   Dali::Animation mAnimation;                                              ///< Scroll indicator Show/Hide Animation.
318   Dali::TimePeriod mAnimationPeriod;
319   std::vector<Actor> mClippingDecorationActors;   ///< Decoration actors which need clipping.
320
321   Actor mRenderableActor;
322   Actor mActiveLayer;
323   CallbackBase* mIdleCallback;
324
325   float mAlignmentOffset;
326   float mScrollAnimationDuration;
327   float mLineSpacing;
328   int mRenderingBackend;
329   bool mHasBeenStaged:1;
330   bool mScrollAnimationEnabled:1;
331   bool mScrollBarEnabled:1;
332   bool mScrollStarted:1;
333
334   struct AccessibleImpl : public Control::Impl::AccessibleImpl,
335                           public virtual Dali::Accessibility::Text,
336                           public virtual Dali::Accessibility::EditableText
337   {
338     using Control::Impl::AccessibleImpl::AccessibleImpl;
339
340     std::string GetName() override;
341     std::string GetText( size_t startOffset, size_t endOffset ) override;
342     size_t GetCharacterCount() override;
343     size_t GetCaretOffset() override;
344     bool SetCaretOffset(size_t offset) override;
345     Dali::Accessibility::Range
346     GetTextAtOffset( size_t offset,
347                      Dali::Accessibility::TextBoundary boundary ) override;
348     Dali::Accessibility::Range GetSelection( size_t selectionNum ) override;
349     bool RemoveSelection( size_t selectionNum ) override;
350     bool SetSelection( size_t selectionNum, size_t startOffset,
351                        size_t endOffset ) override;
352     bool CopyText( size_t startPosition, size_t endPosition ) override;
353     bool CutText( size_t startPosition, size_t endPosition ) override;
354     Dali::Accessibility::States CalculateStates() override;
355   };
356 };
357
358 } // namespace Internal
359
360 // Helpers for public-api forwarding methods
361
362 inline Toolkit::Internal::TextEditor& GetImpl( Toolkit::TextEditor& textEditor )
363 {
364   DALI_ASSERT_ALWAYS(textEditor);
365
366   Dali::RefObject& handle = textEditor.GetImplementation();
367
368   return static_cast<Toolkit::Internal::TextEditor&>(handle);
369 }
370
371 inline const Toolkit::Internal::TextEditor& GetImpl( const Toolkit::TextEditor& textEditor )
372 {
373   DALI_ASSERT_ALWAYS(textEditor);
374
375   const Dali::RefObject& handle = textEditor.GetImplementation();
376
377   return static_cast<const Toolkit::Internal::TextEditor&>(handle);
378 }
379
380 } // namespace Toolkit
381
382 } // namespace Dali
383
384 #endif // DALI_TOOLKIT_INTERNAL_TEXT_EDITOR_H