New size negotiation
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-input / text-input-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_TEXT_INPUT_H__
2 #define __DALI_TOOLKIT_INTERNAL_TEXT_INPUT_H__
3
4 /*
5  * Copyright (c) 2014 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/public-api/actors/mesh-actor.h>
23 #include <dali/public-api/adaptor-framework/clipboard.h>
24 #include <dali/public-api/adaptor-framework/clipboard-event-notifier.h>
25 #include <dali/public-api/adaptor-framework/imf-manager.h>
26 #include <dali/public-api/adaptor-framework/timer.h>
27 #include <dali/public-api/common/dali-vector.h>
28 #include <dali/public-api/geometry/mesh.h>
29
30 // INTERNAL INCLUDES
31 #include <dali-toolkit/public-api/controls/control-impl.h>
32 #include <dali-toolkit/public-api/controls/text-input/text-input.h>
33 #include <dali-toolkit/public-api/controls/text-view/text-view.h>
34 #include <dali-toolkit/public-api/controls/buttons/push-button.h>
35 #include <dali-toolkit/internal/controls/text-input/text-input-popup-impl.h>
36
37 namespace Dali
38 {
39
40 namespace Toolkit
41 {
42
43 namespace Internal
44 {
45
46 class TextInput;
47 class TextView;
48
49 typedef IntrusivePtr<TextInput> TextInputPtr;
50
51 class TextInput : public Control
52 {
53 public:
54
55   /**
56    * Create a new TextInput
57    * @return instrusive ptr to a TextInput
58    */
59   static Dali::Toolkit::TextInput New();
60
61   /**
62    * @copydoc Toolkit::TextInput::GetText
63    */
64   std::string GetText() const;
65
66   /**
67    * @copydoc Toolkit::TextInput::GetMarkupText()
68    */
69   std::string GetMarkupText() const;
70
71   /**
72    * @copydoc Toolkit::TextInput::SetPlaceholderText
73    */
74   void SetPlaceholderText( const std::string& placeHolderText );
75
76   /**
77    * @copydoc Toolkit::TextInput::SetPlaceholderText
78    */
79   std::string GetPlaceholderText();
80
81   /**
82    * @copydoc Toolkit::TextInput::SetInitialText
83    */
84   void SetInitialText(const std::string& initialText);
85
86   /**
87    *  set the text to be displayed in text-input, will overwrite any existing text.
88    *  can be used to clear the text-input by passing an empty string.
89    *  @param [in] initialText text to be initially displayed
90    */
91   void SetText(const std::string& initialText);
92
93   /**
94    * @copydoc Toolkit::TextInput::SetMaxCharacterLength
95    */
96   void SetMaxCharacterLength(std::size_t maxChars);
97
98   /**
99    * @copydoc Toolkit::TextInput::SetNumberOfLinesLimit
100    */
101   void SetNumberOfLinesLimit(std::size_t maxLines);
102
103   /**
104    * @copydoc Toolkit::TextInput::GetNumberOfLinesLimit
105    */
106   std::size_t GetNumberOfLinesLimit() const;
107
108   /**
109    * @copydoc Toolkit::TextInput::GetFont
110    */
111   Font GetFont() const;
112
113   /**
114    * @copydoc Toolkit::TextInput::SetFont
115    */
116   void SetFont(Font font);
117
118   /**
119    * @copydoc Toolkit::TextInput::InputStartedSignal()
120    */
121   Toolkit::TextInput::InputSignalType& InputStartedSignal();
122
123   /**
124    * @copydoc Toolkit::TextInput::InputFinishedSignal()
125    */
126   Toolkit::TextInput::InputSignalType& InputFinishedSignal();
127
128   /**
129    * @copydoc Toolkit::TextInput::CutAndPasteToolBarDisplayedSignal()
130    */
131   Toolkit::TextInput::InputSignalType& CutAndPasteToolBarDisplayedSignal();
132
133   /**
134    * @copydoc Toolkit::TextInput::StyleChangedSignal()
135    */
136   Toolkit::TextInput::StyleChangedSignalType& StyleChangedSignal();
137
138   /**
139    * @copydoc Toolkit::TextInput::TextModifiedSignal()
140    */
141   Toolkit::TextInput::TextModifiedSignalType& TextModifiedSignal();
142
143   /**
144    * @copydoc Toolkit::TextInput::MaxInputCharactersReachedSignal()
145    */
146   Toolkit::TextInput::MaxInputCharactersReachedSignalType& MaxInputCharactersReachedSignal();
147
148   /**
149    * @copydoc Toolkit::TextInput::InputTextExceedBoundariesSignal()
150    */
151   Toolkit::TextInput::InputTextExceedBoundariesSignalType& InputTextExceedBoundariesSignal();
152
153   /**
154    * Connects a callback function with the object's signals.
155    * @param[in] object The object providing the signal.
156    * @param[in] tracker Used to disconnect the signal.
157    * @param[in] signalName The signal to connect to.
158    * @param[in] functor A newly allocated FunctorDelegate.
159    * @return True if the signal was connected.
160    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
161    */
162   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
163
164   /**
165    * @see Toolkit::TextInput::SetEditMode(bool editMode)
166    * @see Toolkit::TextInput::SetEditMode(bool editMode, const Vector2& touchPoint)
167    *
168    * @param[in] editMode true or false to indicate editMode on or off.
169    * @param[in] setCursorOnTouchPoint Whether to use the touch point to set the cursor position.
170    * @param[in] touchPoint A position in actor coordinates within the text-input.
171    */
172   void SetEditable(bool editMode, bool setCursorOnTouchPoint, const Vector2& touchPoint = Vector2::ZERO);
173
174   /**
175    * @copydoc Toolkit::TextInput::GetEditMode
176    */
177   bool IsEditable() const;
178
179   /**
180    * @copydoc Toolkit::TextInput::SetTextSelectable
181    */
182   void SetTextSelectable(bool textSelectable = true);
183
184   /**
185    * @copydoc Toolkit::TextInput::IsTextSelectable
186    */
187   bool IsTextSelectable() const;
188
189   /**
190    * @copydoc Toolkit::TextInput::IsTextSelected
191    */
192   bool IsTextSelected() const;
193
194   /**
195    * @copydoc Toolkit::TextInput::DeSelectText
196    */
197   void DeSelectText();
198
199   /**
200    * @copydoc Toolkit::TextInput::SetEditOnTouch
201    */
202   void SetEditOnTouch(bool editOnTouch);
203
204   /**
205    * @copydoc Toolkit::TextInput::IsEditOnTouch
206    */
207   bool IsEditOnTouch() const;
208
209   /**
210    * @copydoc Toolkit::TextInput::SetGrabHandleImage
211    */
212   void SetGrabHandleImage(Dali::Image image);
213
214   /**
215    * @copydoc Toolkit::TextInput::SetCursorImage
216    */
217   void SetCursorImage(Dali::Image image, const Vector4& border );
218
219   /**
220    * @copydoc Toolkit::TextInput::GetSelectionHandleSize
221    */
222   Vector3 GetSelectionHandleSize();
223
224   /**
225    * @copydoc Toolkit::TextInput::SetRTLCursorImage
226    */
227   void SetRTLCursorImage(Dali::Image image, const Vector4& border );
228
229   /**
230    * @copydoc Toolkit::TextInput::EnableGrabHandle
231    */
232   void EnableGrabHandle(bool toggle);
233
234   /**
235    * @copydoc Toolkit::TextInput::IsGrabHandleEnabled
236    */
237   bool IsGrabHandleEnabled();
238
239   /**
240    * @copydoc Toolkit::TextInput::EnableSelectionHandleFlip
241    */
242   void EnableSelectionHandleFlip( bool toggle );
243
244   /**
245    * @copydoc Toolkit::TextInput::IsSelectionHandleFlipEnabled
246    */
247   bool IsSelectionHandleFlipEnabled();
248
249   /**
250    * @copydoc Toolkit::TextInput::SetSelectionHandleFlipMargin
251    */
252   void SetSelectionHandleFlipMargin( const Vector4& margin );
253
254   /**
255    * @copydoc Toolkit::TextInput::SetBoundingRectangle
256    */
257   void SetBoundingRectangle( const Rect<float>& boundingRectangle );
258
259   /**
260    * @copydoc Toolkit::TextInput::GetBoundingRectangle
261    */
262   const Rect<float> GetBoundingRectangle() const;
263
264   /**
265    * @copydoc Toolkit::TextInput::GetSelectionHandleFlipMargin
266    */
267   const Vector4& GetSelectionHandleFlipMargin();
268
269   /**
270    * @copydoc Toolkit::TextInput::SetTextColor
271    */
272   void SetTextColor( const Vector4& color );
273
274   /**
275    * @copydoc Toolkit::TextInput::SetActiveStyle
276    */
277   void SetActiveStyle( const TextStyle& style, const TextStyle::Mask mask );
278
279   /**
280    * @copydoc Toolkit::TextInput::ApplyStyle
281    */
282   void ApplyStyle( const TextStyle& style, const TextStyle::Mask mask );
283
284   /**
285    * @copydoc Toolkit::TextInput::ApplyStyleToAll
286    */
287   void ApplyStyleToAll( const TextStyle& style, const TextStyle::Mask mask );
288
289   /**
290    * @copydoc Toolkit::TextInput::GetStyleAtCursor
291    */
292   TextStyle GetStyleAtCursor() const;
293
294   /**
295    * Retrieves the character style for the given position.
296    * @param[in] position The character position which style is required.
297    * @return The style for the given position.
298    */
299   TextStyle GetStyleAt( std::size_t position ) const;
300
301   /**
302    * @copydoc Toolkit::TextInput::SetTextAlignment()
303    */
304   void SetTextAlignment( Toolkit::Alignment::Type align );
305
306   /**
307    * @copydoc Toolkit::TextInput::SetTextLineJustification()
308    */
309   void SetTextLineJustification( Toolkit::TextView::LineJustification justification );
310
311   /**
312    * @copydoc Toolkit::TextInput::SetFadeBoundary()
313    */
314   void SetFadeBoundary( const Toolkit::TextView::FadeBoundary& fadeBoundary );
315
316   /**
317    * @copydoc Toolkit::TextInput::GetFadeBoundary()
318    */
319   const Toolkit::TextView::FadeBoundary& GetFadeBoundary() const;
320
321   /**
322    * @copydoc Toolkit::TextInput::GetTextAlignment()
323    */
324   Toolkit::Alignment::Type GetTextAlignment() const;
325
326   /**
327    * @copydoc Toolkit::TextInput::SetMultilinePolicy()
328    */
329   void SetMultilinePolicy( Toolkit::TextView::MultilinePolicy policy );
330
331   /**
332    * @copydoc Toolkit::TextInput::GetMultilinePolicy()
333    */
334   Toolkit::TextView::MultilinePolicy GetMultilinePolicy() const;
335
336   /**
337    * @copydoc Toolkit::TextInput::SetWidthExceedPolicy()
338    */
339   void SetWidthExceedPolicy( Toolkit::TextView::ExceedPolicy policy );
340
341   /**
342    * @copydoc Toolkit::TextInput::GetWidthExceedPolicy()
343    */
344   Toolkit::TextView::ExceedPolicy GetWidthExceedPolicy() const;
345
346   /**
347    * @copydoc Toolkit::TextInput::SetHeightExceedPolicy()
348    */
349   void SetHeightExceedPolicy( Toolkit::TextView::ExceedPolicy policy );
350
351   /**
352    * @copydoc Toolkit::TextInput::GetHeightExceedPolicy()
353    */
354   Toolkit::TextView::ExceedPolicy GetHeightExceedPolicy() const;
355
356   /**
357    * @copydoc Toolkit::TextInput::SetExceedEnabled()
358    */
359   void SetExceedEnabled( bool enable );
360
361   /**
362    * @copydoc Toolkit::TextInput::GetExceedEnabled()
363    */
364   bool GetExceedEnabled() const;
365
366   /**
367    * @copydoc Toolkit::TextInput::SetBackground
368    */
369   void SetBackground(Dali::Image image );
370
371   /**
372    * @copydoc Toolkit::TextInput::SetNumberOfLines
373    */
374   void SetNumberOfLines(std::size_t lines);
375
376   /**
377    * @copydoc Toolkit::TextInput::GetNumberOfLines
378    */
379   std::size_t GetNumberOfLines();
380
381   /**
382    * @copydoc Toolkit::TextInput::GetNumberOfCharacters
383    */
384   std::size_t GetNumberOfCharacters() const;
385
386   /**
387    * Styling
388    */
389
390   /**
391    * Set the diffuse color for the highlight
392    * @param[in] color color to use
393    */
394   void SetMaterialDiffuseColor( const Vector4& color );
395
396   /**
397    * Get the diffuse color used by the highlight
398    * @return color
399    */
400   const Vector4& GetMaterialDiffuseColor() const;
401
402 private:
403
404   /**
405    * structure to hold each highlight box needed for text selection
406    */
407   struct HighlightBox
408   {
409     Vector3 size;                         ///< size of the highlight box
410     Vector3 position;                     ///< position of highlight box
411     ImageActor highlightBoxActor;         ///< as actor that is the highlight box
412   };
413
414   /**
415    * structure to hold each character in displayed string and its position from the left
416    */
417   struct CharPositions
418   {
419     char character;   ///< todo change to UTF to aid multi-language support
420     Vector3 position;
421     Vector2 size;
422   };
423
424   /**
425    * structure to hold coordinates of each quad, which will make up the mesh.
426    */
427   struct QuadCoordinates
428   {
429     /**
430      * Default constructor
431      */
432     QuadCoordinates()
433     {
434     }
435
436     /**
437      * Constructor
438      * @param[in] x1 left co-ordinate
439      * @param[in] y1 top co-ordinate
440      * @param[in] x2 right co-ordinate
441      * @param[in] y2 bottom co-ordinate
442      */
443     QuadCoordinates(float x1, float y1, float x2, float y2)
444     : min(x1, y1),
445       max(x2, y2)
446     {
447     }
448
449     Vector2 min;                          ///< top-left (minimum) position of quad
450     Vector2 max;                          ///< bottom-right (maximum) position of quad
451   };
452
453   typedef std::vector<QuadCoordinates> QuadContainer;
454
455   /**
456    * structure for information required to build the highlight mesh
457    */
458   struct HighlightInfo
459   {
460     /**
461      * Adds a Quad (2D rectangular sub-selection)
462      * @param[in] x1 left co-ordinate
463      * @param[in] y1 top co-ordinate
464      * @param[in] x2 right co-ordinate
465      * @param[in] y2 bottom co-ordinate
466      */
467     void AddQuad( float x1, float y1, float x2, float y2 );
468
469     /**
470      * Clamps all quads to fit within a min -> max 2D boundary.
471      */
472     void Clamp2D(const Vector2& min, const Vector2& max);
473
474     QuadContainer mQuadList;                                 ///< List of quads (sub-selections that form to create complete selection)
475   };
476
477   /**
478    * Holds requested selection start and end points for highlighted text.
479    */
480   struct SelectionParameters
481   {
482     SelectionParameters( size_t start, size_t end )
483     : mStartOfSelection( start ), mEndOfSelection( end )
484     {
485
486     }
487
488     size_t mStartOfSelection;
489     size_t mEndOfSelection;
490   };
491
492   enum State
493   {
494     StateEdit,
495     StateDraggingHandle
496   };
497
498   enum SelectionHandleId
499   {
500     HandleOne,   ///< Selection handle one which is on the left
501     HandleTwo    ///< Selection handle two which is on the right
502   };
503
504   /**
505    * Two different behaviours are needed to convert a touch point into a character index.
506    * When a tap is received and the touch point doesn't hit any character, the final character selected might
507    * be different than the one selected if the event is a pan.
508    * i.e. If a tap is received and the touch point doesn't hit any character the expected position of the cursor
509    * would be the end or the beginning of a line. However, this behaviour would be weird while panning.
510    */
511   enum TouchToIndex
512   {
513     TapMode,  ///< Touch point to character index conversion mode used for Tap events.
514     DragMode  ///< Touch point to character index conversion mode used for Pan events.
515   };
516
517   /**
518    * Used to set the direction when find the next visible character.
519    */
520   enum FindVisibleCharacterDirection
521   {
522     Left,  ///< Find visible characters on the left.
523     Right, ///< Find visible characters on the right.
524     ByEnd  ///< Start finding visible characters by the end.
525   };
526
527   /**
528    *
529    */
530   virtual bool OnTouchEvent(const TouchEvent& event);
531
532   /**
533    * From CustomActorImpl; called after the Text Input actor is touched
534    * @param[in] event The KeyEvent event.
535    * @return True if the event should be consumed.
536    */
537   virtual bool OnKeyEvent(const KeyEvent& event);
538
539   /**
540    * From CustomActorImpl; called when this actor gains keyboard focus.
541    */
542   virtual void OnKeyInputFocusGained();
543
544   /**
545    * From CustomActorImpl; called when this actor loses keyboard focus.
546    */
547   virtual void OnKeyInputFocusLost();
548
549   /**
550    * From Control; called whenever the control is added to the stage.
551    */
552   virtual void OnControlStageConnection();
553
554 private: // From Control
555
556   /**
557    * Creation of the layer that is used by top level active parts of the TextInput like handles
558    */
559   void CreateActiveLayer();
560
561   /**
562    * @copydoc Control::OnInitialize()
563    */
564   virtual void OnInitialize();
565
566   /**
567    * @copydoc Control::OnControlSizeSet()
568    */
569   virtual void OnControlSizeSet(const Vector3& targetSize);
570
571   /**
572    * @copydoc Control::OnRelayout()
573    */
574   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
575
576   /**
577    * Retrieves the text-input's natural size by calling TextView::GetNaturalSize().
578    *
579    * @return The natural size.
580    */
581   virtual Vector3 GetNaturalSize();
582
583   /**
584    * Retrieves the text-input's \e height for a given \e width by calling TextView::GetHeightForWidth().
585    *
586    * @param[in] width The given \e width.
587    *
588    * @return The \e height for the given \e width.
589    */
590   virtual float GetHeightForWidth( float width );
591
592 protected:
593
594   /**
595    * Construct a new TextInput.
596    */
597   TextInput();
598
599   /**
600    * A reference counted object may only be deleted by calling Unreference()
601    */
602   virtual ~TextInput();
603
604 private:
605
606   // Undefined
607   TextInput(const TextInput&);
608
609   // Undefined
610   TextInput& operator=(const TextInput& rhs);
611
612   /**
613     * Callback when a handle is panned/moved, either selection handles or grab handle
614     * @param actor Handle of the selection or grab handle.
615     * @param gesture Data structure with the parameters of the gesture.
616     */
617    void OnHandlePan(Actor actor, const PanGesture& gesture);
618
619    /**
620     * Callback for touch down on Grab handle
621     * @param[in] actor touched
622     * @param[in] touch touch event
623     */
624    bool OnPressDown(Dali::Actor actor, const TouchEvent& touch);
625
626    /**
627     * Callback for touch down on Selection handle one
628     * @param[in] actor touched
629     * @param[in] touch touch event, used to determine if down or up event
630     */
631    bool OnHandleOneTouched(Dali::Actor actor, const TouchEvent& touch);
632
633    /**
634     * Callback for touch down on Selection handle two
635     * @param[in] actor touched
636     * @param[in] touch touch event, used to determine if down or up event
637     */
638    bool OnHandleTwoTouched(Dali::Actor actor, const TouchEvent& touch);
639
640    /**
641     * Callback for tap on TextInput
642     * @param[in] actor
643     * @param[in] tap touch event
644     */
645    void OnTextTap(Dali::Actor actor, const Dali::TapGesture& tap);
646
647    /**
648     * Callback for double tap on TextInput
649     * @param[in] actor
650     * @param[in] tap touch event
651     */
652    void OnDoubleTap(Dali::Actor actor, const Dali::TapGesture& tap);
653
654     /**
655      * Callback for long press on TextInput
656      * @param[in] actor
657      * @param[in] longPress long press event
658      */
659    void OnLongPress(Dali::Actor actor, const Dali::LongPressGesture& longPress);
660
661    /**
662     * Callback for the ClipboardEventNotifier when text is selected in the clipboard window.
663     * @param[in] notifier The Clipboard Event Notifier.
664     */
665    void OnClipboardTextSelected( ClipboardEventNotifier& notifier );
666
667    /**
668     * Callback for when a button is pressed in popup panel
669     * @param[in] button handle to the button pressed.
670     */
671    bool OnPopupButtonPressed( Toolkit::Button button );
672
673    /**
674     * Callback when handle timer ticks.
675     *
676     * Cursor should become visible/invisible to simulate blinking.
677     *
678     * @return True if the timer should be keep running.
679     */
680    bool OnCursorBlinkTimerTick();
681
682    /**
683     * Invoked upon popup Hide animation completing.
684     * @note Only called for animating hide, not called for instantaneous (animate = false)
685     * @param[in] popup The popup which was hidden.
686     */
687    void OnPopupHideFinished(TextInputPopup& popup);
688
689    /**
690     * Called in OnKeyEvent to handle key down events.
691     * @param[in] event The KeyEvent event.
692     * @return True if the event should be consumed.
693     */
694    bool OnKeyDownEvent(const KeyEvent& event);
695
696    /**
697     * Called in OnKeyEvent to handle key up events.
698     * @param[in] event The KeyEvent event.
699     * @return True if the event should be consumed.
700     */
701    bool OnKeyUpEvent(const KeyEvent& event);
702
703    /**
704     * Chooses from all handle position and alternative handle positions where to set the position of the two selection handles.
705     *
706     * @param[in] cursorPositionOne The initial position of the first selection handle.
707     * @param[in] cursorPositionTwo The initial position of the second selection handle.
708     * @param[in] altPositionValidOne Whether there is an alternative position for the first selection handle.
709     * @param[in] altPositionValidTwo Whether there is an alternative position for the second selection handle.
710     * @param[in] altPositionOne The alternative position of the first selection handle.
711     * @param[in] altPositionTwo The alternative position of the second selection handle.
712     */
713    void ChooseRtlSelectionHandlePosition( const Vector3& cursorPositionOne,
714                                           const Vector3& cursorPositionTwo,
715                                           bool altPositionValidOne,
716                                           bool altPositionValidTwo,
717                                           const Vector3& altPositionOne,
718                                           const Vector3& altPositionTwo );
719    /**
720     * Callback called when the text-view is scrolled.
721     *
722     * Updates the selection and grab handles, and the highlighted text.
723     *
724     * @param[in] textView Handle of the text-view.
725     * @param[in] scrollPosition The difference with the previous scroll position.
726     */
727    void OnTextViewScrolled( Toolkit::TextView textView, Vector2 scrollPosition );
728
729    /**
730     * Scrolls the text-view to make the cursor visible.
731     *
732     * @param[in] cursorPosition The actual cursor position in actor coordinates.
733     */
734    void ScrollTextViewToMakeCursorVisible( const Vector3& cursorPosition );
735
736    /**
737     * Creates and starts a timer to scroll the text when handles are close to the edges of the text-input.
738     *
739     * It only starts the timer if it's already created.
740     */
741    void StartScrollTimer();
742
743    /**
744     * Stops the timer used to scroll the text.
745     */
746    void StopScrollTimer();
747
748    /**
749     * Callback called by the timer used to scroll the text.
750     *
751     * It calculates and sets a new scroll position.
752     */
753    bool OnScrollTimerTick();
754
755 public:  // Public to allow internal testing.
756
757   /**
758    * Register for touch events
759    */
760   void SetUpTouchEvents();
761
762   /**
763    * Sets up TextView Actor
764    */
765   void CreateTextViewActor();
766
767   /**
768    * Set Styled Text for text input.
769    * @param[in] styleText The new styled text for the text input.
770    */
771   void SetText( const MarkupProcessor::StyledTextArray& styleText );
772
773   /**
774    * Start a timer to signal cursor to blink.
775    */
776   void StartCursorBlinkTimer();
777
778   /**
779    * Stop the timer signalling the cursor to blink.
780    */
781   void StopCursorBlinkTimer();
782
783   /**
784    * Starts input, setting focus and showing keyboard..
785    */
786   void StartEditMode();
787
788   /**
789    * Called when End of input and focus no longer required, keyboard is hidden.
790    */
791   void EndEditMode();
792
793   /**
794    * Applies a style to the current pre-edit / predicted word to show it is being edited.
795    * @param[in] preEditStartPosition position in text array that the predicted word starts at
796    * @param[in] preEditStringLength used to calculate how many characters need their style changed.
797    */
798   void ApplyPreEditStyle( std::size_t preEditStartPosition, std::size_t preEditStringLength );
799
800   /**
801    * Restores style to value before applying Pre-Edit style.
802    */
803   void RemovePreEditStyle();
804
805   /**
806    * Event received from IMF manager
807    * @return ImfCallbackData data struture undicating if update is needed, cursor position and current text
808    */
809   ImfManager::ImfCallbackData ImfEventReceived( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& test );
810
811   /**
812    * Called when the OnKey event is a Pre-edit string
813    * @param[in] keyString String received in Pre-edit
814    * @param[in] cursorOffset the cursor offset from where the pre-edit word starts
815    * @return bool true if preedit reset is required.
816    */
817   bool PreEditReceived( const std::string& keyString, std::size_t cursorOffset  );
818
819  /**
820   * Called when the OnKey event is a Commit string
821   * @param[in] keyString String received in Comment
822   * @return update flag to trigger cursor update of TextInput only when needed.
823   */
824   bool CommitReceived( const std::string& keyString );
825
826   /**
827    * Deletes Pre-edit string
828    * By default it doesn't update the character's size and position table, which is a costly
829    * operation. As in many cases deletion and insertion (InsertAt) of text
830    * occurs in the same action i.e. preedit/commit. It makes sense to
831    * delete without updating, and then insert with updating.
832    *
833    * @return The number of characters to be deleted.
834    */
835   std::size_t DeletePreEdit();
836
837   /**
838    * Reset all pre-edit flag and signal IMF keyboard that the current pre-edit word has been comitted.
839    * This may be due to the cursor being moved by user or reached the max character limit.
840    * @param[in] preserveCursorPosition Set true to keep cursor in current position, eg. touch event caused cursor to move.
841    */
842   void PreEditReset( bool preserveCursorPosition );
843
844   /**
845    * Called after cursor position needs updating.
846    * Redraws cursor and notifies VirtualKeyboard
847    */
848   void CursorUpdate();
849
850   /**
851    * Delete highlighted characters
852    * @param[in] inheritStyle Whether style from previous character in the string should be inherited.
853    */
854   void DeleteHighlightedText( bool inheritStyle );
855
856   /*
857    * Delete range of characters
858    * @param[in] start position of characters to delete
859    * @param[in] ncharacters number of characters to delete
860    */
861   void DeleteRange(std::size_t start, std::size_t ncharacters);
862
863   /**
864    * Delete character at current cursor position and redisplay
865    * @param[in] positionToDelete position of character to delete
866    */
867   void DeleteCharacter( std::size_t positionToDelete );
868
869   /**
870    * Add or replaces characters to currently displayed string at cursor position
871    * By default it doesn't update the character's size and position table, which is a costly
872    * operation. As in many cases deletion and insertion (InsertAt) of text
873    * occurs in the same action i.e. preedit/commit. It makes sense to
874    * delete without updating, and then insert with updating.
875    * @param[in] newText string to add to TextInput display string.
876    * @param[in] insertionPosition position to insert at.
877    * @param[in] numberOfCharactersToReplace The number of characters to replace.
878    * @return number of characters to offset the cursor by.
879    */
880   std::size_t InsertAt( const Text& newText, const std::size_t insertionPosition, const std::size_t numberOfCharactersToReplace );
881
882   /**
883   * Creates a cursor.
884   * @param[in] color the cursor color.
885   * @return the image actor to be used as the cursor.
886   */
887   ImageActor CreateCursor( const Vector4 &color );
888
889   /**
890    * Moves cursor to the right
891    * param[in] reverse if true then cursor moves in the reverse direction (to the left)
892    * param[in] places number of character cursor should move.
893    */
894   void AdvanceCursor(bool reverse = false, std::size_t places = 1);
895
896   /**
897    * Draw a cursor / caret at position where new text should appear
898    */
899   void DrawCursor();
900
901   /**
902    * Sets cursor visibility
903    * This sets visibility of the cursor. Which is comprised of 2
904    * cursors. The conventional cursor, and the alternate (RTL) cursor,
905    * which only appears when the cursor is at a character that can have
906    * a character appended to different visual positions depending on whether that
907    * character to be appended is RTL or LTR.
908    * @param[in] visible true - enable visibility for cursor, false - disable visiblity for cursor
909    */
910   void SetCursorVisibility( bool visible );
911
912   /**
913    * Sets alternate cursor enable state
914    * @see SetCursorVisibility
915    * alternate cursor will only be visible if both SetCursorVisiblity
916    * and cursor enabled have been set to true.
917    */
918   void SetAltCursorEnabled( bool enabled );
919
920   /**
921    * Create the grab handle that positions the cursor
922    * @param[in] image to be used for grab handle
923    *
924    */
925   void CreateGrabHandle(Image image=Image());
926
927   /**
928    * Create Grab area to be used by Grab Handle
929    */
930   void CreateGrabArea( Actor& parent);
931
932   /**
933    * Move grab handle to the required character position
934    *
935    * @param[in] displacement Displacement of the grab handle in actor coordinates.
936    *
937    * @return The new actual position the handle has been set to.
938    */
939   Vector3 MoveGrabHandle( const Vector2& displacement );
940
941   /**
942    * Show or hide the grab handle without baking the visibility flag.
943    * Used when the Grab handle needs to be invisible due to text-view scrolling making it out of view
944    *
945    * @param[in] visible bool flag to set as true is grab handle should be shown, else false to hide.
946    */
947   void ShowGrabHandle( bool visible );
948
949   /**
950    * Show or hide the grab handle and bake the visibility flag.
951    * Used when the state of text-input changes to a state which the grabhandle is not required. E.g. Selection mode starts or edit mode ends.
952    * Calls ShowGrabHandle.
953    *
954    * @param[in] visible bool flag to set as true is grab handle should be shown, else false to hide.
955    */
956   void ShowGrabHandleAndSetVisibility( bool visible );
957
958   /* Boundary Property Notifications when handle exceed bounding box*/
959
960   /**
961    * PropertyNotification Callback when left boundary exceeded so handle can be flipped.
962    * @param[in] source PropertyNotification
963    */
964   void OnLeftBoundaryExceeded( PropertyNotification& source );
965   /**
966    * PropertyNotification Callback when within left boundary so handle can be flipped back.
967    * @param[in] source PropertyNotification
968    */
969   void OnReturnToLeftBoundary( PropertyNotification& source );
970   /**
971    * PropertyNotification Callback when right boundary exceeded so handle can be flipped.
972    * @param[in] source PropertyNotification
973    */
974   void OnRightBoundaryExceeded( PropertyNotification& source );
975   /**
976    * * PropertyNotification Callback when within right boundary so handle can be flipped back.
977    * @param[in] source PropertyNotification
978    */
979   void OnReturnToRightBoundary( PropertyNotification& source );
980
981   /**
982    * PropertyNotification Callbacks for hiding handle one when it exceeds boundary.
983    * @param[in] source PropertyNotification
984    */
985   void OnHandleOneLeavesBoundary( PropertyNotification& source );
986   /**
987    * PropertyNotification Callbacks for showing hidden handle one when returns within boundary
988    * @param[in] source PropertyNotification
989    */
990   void OnHandleOneWithinBoundary( PropertyNotification& source );
991   /**
992    * PropertyNotification Callbacks for hiding handle two it  when exceeds boundary.
993    * @param[in] source PropertyNotification
994    */
995   void OnHandleTwoLeavesBoundary( PropertyNotification& source );
996   /**
997    * PropertyNotification Callbacks for showing hidden handle two when returns within boundary
998    * * @param[in] source PropertyNotification
999    */
1000   void OnHandleTwoWithinBoundary( PropertyNotification& source );
1001
1002   /**
1003    * Set up property notifications on the position of the handles to facilitate flipping and hiding when at screen boundary.
1004    */
1005   void SetUpHandlePropertyNotifications();
1006
1007   /**
1008    * Create the selection handles that bound text to be selected for copy/cut.
1009    * @param[in] start initial position of start selection handle.
1010    * @param[in] end initial position of end selection handle.
1011    * @param[in] handleOneImage (optional) to be used for selection handle
1012    * @param[in] handleTwoImage (optional) to be used for selection handle
1013    */
1014   void CreateSelectionHandles( std::size_t start = 0, std::size_t end = std::numeric_limits<std::size_t>::max(), Dali::Image handleOneImage = Dali::Image(),  Dali::Image handleTwoImage = Dali::Image() );
1015
1016   /**
1017    * Move the selection handles to required positions in text.
1018    *
1019    * @param[in] handleId the handle to position
1020    * @param[in] displacement Displacement of the selection handle in actor coordinates.
1021    *
1022    * @return The new actual position the handle has been set to.
1023    */
1024   Vector3 MoveSelectionHandle(SelectionHandleId handleId, const Vector2& displacement);
1025
1026   /**
1027    * Calculate and position the specified selection handle the given index position
1028    *
1029    * @param[in] handleId the handle to position
1030    */
1031   void SetSelectionHandlePosition(SelectionHandleId handleId);
1032
1033   /**
1034    * Gets a table of the visual text positions which has a flag
1035    * for each Character. The flag is either true (character selected)
1036    * or false (character deselected)
1037    * @note startSelection can be greater or less than endSelection
1038    *
1039    * @param[in,out] selectedVisualText The vector to be resized and populated with the selected flags
1040    * @param[in] startSelection The start selection point for the text
1041    * @param[in] endSelection The end selection point for the text
1042    */
1043   void GetVisualTextSelection(std::vector<bool>& selectedVisualText, std::size_t startSelection, std::size_t endSelection);
1044
1045   /**
1046    *  Iterates between selection handles and computes the info required to build the highlight mesh
1047    */
1048   HighlightInfo CalculateHighlightInfo();
1049
1050   /**
1051    * This method was added to fix a PLM. it creates one quad per character so the mesh can show different selection boxes when a mix of right to left and left to right text is selected.
1052    */
1053   HighlightInfo CalculateHighlightInfoRtl();
1054
1055   /**
1056    * Calculates new Mesh data so highlight moves with selection handles.
1057    */
1058   void UpdateHighlight();
1059
1060   /**
1061    * Removes popup, and its options.
1062    */
1063   void ClearPopup();
1064
1065   /**
1066    * Adds Popup options which have been enabled.
1067    */
1068   void AddPopupOptions();
1069
1070   /**
1071    * Sets popup position
1072    * @param[in] position The actual position for this popup.
1073    * @param[in] alternativePosition Alternative popup position if no space in upper area.
1074    */
1075   void SetPopupPosition(const Vector3& position, const Vector2& alternativePosition );
1076
1077   /**
1078    * Hides the popup
1079    * @param[in] animate (optional) whether to animate popup to hide state over time (i.e. tween).
1080    * @param[in] signalFinished (optional) whether to perform an animation finish operation after the hide animation completes. Requires animate to be true.
1081    */
1082   void HidePopup( bool animate = true, bool signalFinished = true );
1083
1084   /**
1085    * Shows the popup
1086    * @param[in] animate (optional) whether to animate popup to show state over time (i.e. tween).
1087    */
1088   void ShowPopup(bool animate = true);
1089
1090   /**
1091    * Shows the cut-copy-paste popup
1092    */
1093   void ShowPopupCutCopyPaste();
1094
1095   /**
1096    * Setup the selection popup and clipboard if relevant so the correct options are shown when ShowPopup is called.
1097    * @param[in] showCutButton Flag to show or hide cut button, in some cases like whitespace we do not want to cut just select.
1098    * default is true.
1099    */
1100   void SetUpPopupSelection( bool showCutButton = true );
1101
1102   /**
1103    * Return the logical index containing the character position closest to the source.
1104    * Used for positioning the grab handle at characters when dragged along.
1105    * Two different behaviours are needed in case the source point doesn't actually touch a
1106    * character. @see TouchToIndex.
1107    * @param[in] source float to match against
1108    * @param[out] closestIndex index to the vector of character's size and position.
1109    * @return \e true if the source point is actually inside the geometry provided by TextView.
1110    */
1111   bool ReturnClosestIndex(const Vector2& source, std::size_t& closestIndex );
1112
1113   /**
1114    * Returns the X-position of the current line justification
1115    * (relative to left of text-view container)
1116    * @return X position for line justification
1117    */
1118   float GetLineJustificationPosition() const;
1119
1120   /**
1121    * Currently the cursor is positioned at the previous characters position plus it's width.
1122    * If the previous character is on a different line then this function returns the correct position.
1123    * @param[in] characterPosition the character position index that the cursor should be at
1124    * @return position of cursor/handle
1125    */
1126   Vector3 PositionCursorAfterWordWrap( std::size_t characterPosition ) const;
1127
1128
1129   /**
1130    * Return a vector which is the actual position for the given character position
1131    * The character position is where a cursor would be position for that character.
1132    * @param[in] characterPosition the logical (input) position in the 'string' of characters.
1133    *
1134    * @return Vector3 the actual x,y,z position
1135    */
1136   Vector3 GetActualPositionFromCharacterPosition(std::size_t characterPosition ) const;
1137
1138   /**
1139    * Return a vector which is the actual position for the given character position
1140    * The character position is where a cursor would be positioned for that character to be inserted.
1141    * An additional alternatePosition is also set in circumstances where the possible writing
1142    * of characters would be in the opposite direction.
1143    * e.g. "HelloشقشلاهؤEnglish"
1144    *            |     |
1145    *            *     +
1146    * [*] - Primary actual position for cursor i.e. continuing writing LTR (English)
1147    * [+] - Alternate actual position for cursor i.e. writing RTL (Arabic)
1148    *
1149    * @param[in] characterPosition the logical (input) position in the 'string' of characters.
1150    * @param[out] directionRTL Whether the actual x,y,z position is after LTR (false) or RTL (true) text.
1151    * @param[out] alternatePosition the actual x,y,z position of the cursor if user types
1152    * in alternate direction to current flow of text.
1153    * @param[out] alternatePositionValid whether this alternate position is valid.
1154    * @return Vector3 the actual x,y,z position
1155    */
1156   Vector3 GetActualPositionFromCharacterPosition(std::size_t characterPosition, bool& directionRTL, Vector3& alternatePosition, bool& alternatePositionValid ) const;
1157
1158   /**
1159    * Retrieve the character position of the first character on the row of text
1160    * that this character resides on.
1161    * @param[in] logicalPosition the position in the 'string' of characters.
1162    * @return logical character position of start of row.
1163    */
1164   std::size_t GetRowStartFromCharacterPosition(std::size_t logicalPosition) const;
1165
1166   /**
1167    * Retrieves the first character of a group of characters with the same direction.
1168    *
1169    * @param[in] logicalPosition Index to a character.
1170    *
1171    * @return Index to the character.
1172    */
1173   std::size_t GetFirstCharacterWithSameDirection( std::size_t logicalPosition ) const;
1174
1175   /**
1176    * Retrieve the dimensions of this row of text that the character resides on.
1177    * @param[in] characterPosition the position in the 'string' of characters.
1178    * @return The size of the rectangle representing this row
1179    */
1180   Size GetRowRectFromCharacterPosition(std::size_t characterPosition) const;
1181
1182   /**
1183    * Retrieve the dimensions (and min-max) of this row of text that the character resides on.
1184    * @param[in] characterPosition the position in the 'string' of characters.
1185    * @param[out] min the top-left position of the rectangle representing this row
1186    * @param[out] max the bottom-right position of the rectangle representing this row
1187    * @return The size of the rectangle representing this row (max - min)
1188    */
1189   Size GetRowRectFromCharacterPosition(std::size_t characterPosition, Vector2& min, Vector2& max) const;
1190
1191   /**
1192    * Checks if the provided touchedActor was this text-input
1193    * @param[in] touchedActor the touched actor that will be checked against this text-input
1194    * @return true if the touchActor was the text-input or one of its children
1195    */
1196   bool WasTouchedCheck( const Actor& touchedActor ) const;
1197
1198   /**
1199    * Connect to the stage touch event
1200    */
1201   void StartMonitoringStageForTouch();
1202
1203   /**
1204    * Disconnect from the stage touch event
1205    */
1206   void EndMonitoringStageForTouch();
1207
1208   /**
1209    * Callback for when the screen is touched, this will be connected when selection starts and disconnected when it ends.
1210    * @param[in] event The touch event
1211    */
1212   void OnStageTouched(const TouchEvent& event);
1213
1214
1215   /**
1216    * Select the text between the given values
1217    * @param[in] start position within array to start selection
1218    * @param[in] end position within array to end selection
1219    */
1220   void SelectText(std::size_t start, std::size_t end);
1221
1222   /**
1223    * Gets selected text and returns it as a StyleText vector
1224    * @return StyledText vector that is selected.
1225    */
1226   MarkupProcessor::StyledTextArray GetSelectedText();
1227
1228   /**
1229    * Applies the given style to all text, selected or not selected.
1230    * By default all style settings are applied but a bit mask could be used to modify only certain style settings.
1231    */
1232   void ApplyStyleToRange(const TextStyle& style, const TextStyle::Mask mask, const std::size_t begin, const std::size_t end);
1233
1234   /**
1235    * Callback for when the keyboard status changes
1236    * @param[in]  keyboardShown  Whether the keyboard has just been shown or not.
1237    */
1238   void KeyboardStatusChanged(bool keyboardShown);
1239
1240   /**
1241    * Hide highlight shown between selection handles.
1242    * @param[in] hidePopup flag to hide the popup too, default is to hide popup.
1243    */
1244   void RemoveHighlight( bool hidePopup = true );
1245
1246   /**
1247    * Highlights text that has been selected
1248    */
1249   void CreateHighlight();
1250
1251   /**
1252    * Copies selected text to clipboard
1253    * @return bool true if copy was successful.
1254    */
1255   bool CopySelectedTextToClipboard();
1256
1257   /**
1258    * Pastes the given text to currently displayed string at the current cursor position
1259    * @param[in] text Text to be pasted
1260    */
1261   void PasteText( const Text& text );
1262
1263   /**
1264    * Sets the direction of the text if it is empty.
1265    */
1266   void SetTextDirection();
1267
1268   /**
1269    * Updates the line height accordingly with the current text input style.
1270    */
1271   void UpdateLineHeight();
1272
1273   /**
1274    * Finds a visible character.
1275    *
1276    * The \e direction parameters specifies from where to start to look for a visible character. \e Left means start by characters in lower
1277    * positions than \e cursorPosition, \e Right means start by characters in greater positions than \e cursorPosition and \e ByEnd starts
1278    * by the last characters.
1279    *
1280    * If \e Left or \e Right is provided and any character is found, then looks in the other direction.
1281    *
1282    * @param[in] direction Direction used to find a visible character.
1283    * @param[in] cursorPosition Starting position.
1284    *
1285    * @return The found visible character.
1286    */
1287   std::size_t FindVisibleCharacter( const FindVisibleCharacterDirection direction , const std::size_t cursorPosition ) const;
1288
1289   /**
1290    * @copydoc SetSortModifier()
1291    */
1292   void SetSortModifier( float depthOffset );
1293
1294   /**
1295    * @copydoc SetSnapshotModeEnabled()
1296    */
1297   void SetSnapshotModeEnabled( bool enable );
1298
1299   /**
1300    * @copydoc IsSnapshotModeEnabled()
1301    */
1302   bool IsSnapshotModeEnabled() const;
1303
1304   /**
1305    * @copydoc SetScrollEnabled()
1306    */
1307   void SetScrollEnabled( bool enable );
1308
1309   /**
1310    * @copydoc IsScrollEnabled()
1311    */
1312   bool IsScrollEnabled() const;
1313
1314   /**
1315    * @copydoc SetScrollPosition()
1316    */
1317   void SetScrollPosition( const Vector2& position );
1318
1319   /**
1320    * @copydoc GetScrollPosition()
1321    */
1322   Vector2 GetScrollPosition() const;
1323
1324   /**
1325    * @brief Sets whether markup processing should be carried out.
1326    *
1327    * @param[in] enable whether markup processing is carried out or not.
1328    */
1329   void SetMarkupProcessingEnabled( bool enable );
1330
1331   /**
1332    * @brief Returns whether markup processing is enabled or not
1333    *
1334    * @return true is markup processing is enabled
1335    */
1336   bool IsMarkupProcessingEnabled() const;
1337
1338   /**
1339    * Insert or replaces the given text in the given position. It checks if the text exceeds the maximum allowed number of characters
1340    * and if it fits in the text-input's boundaries.
1341    *
1342    * @param[in] text Text to be inserted.
1343    * @param[in] position Position where the text is inserted.
1344    * @param[in] numberOfCharactersToReplace The number of characters to replace.
1345    * @param[out] textExceedsMaximunNumberOfCharacters The number of characters that have been inserted.
1346    * @param[out] textExceedsBoundary Whether the inserted text has exceeded the boundaries of the text-input.
1347    *
1348    * @return The number of characters that have been inserted.
1349    */
1350   std::size_t DoInsertAt( const Text& text, std::size_t position, std::size_t numberOfCharactersToReplace, bool& textExceedsMaximunNumberOfCharacters, bool& textExceedsBoundary );
1351
1352   /**
1353    *  Retrieve Text-view's layout info.
1354    */
1355   void GetTextLayoutInfo();
1356
1357   /**
1358    * Set the offset for positioning Popup from the TextInput
1359    * @param[in] offset in the order, left, top, right, bottom
1360    */
1361   void SetOffsetFromText( const Vector4& offset );
1362
1363   /**
1364    * Get the offset of the Popup from the TextInput
1365    * @return Vector4 with the offset in the order, left, top, right, bottom
1366    */
1367   const Vector4& GetOffsetFromText() const;
1368
1369   /**
1370    * Show the Placeholder text with an already created StyleTextArray
1371    * @param[in] stylePlaceHolderText Required placeholder text to be used
1372    */
1373   void ShowPlaceholderText( const MarkupProcessor::StyledTextArray& stylePlaceHolderText );
1374
1375   // Properties
1376
1377   /**
1378    * Called when a property of an object of this type is set.
1379    * @param[in] object The object whose property is set.
1380    * @param[in] index The property index.
1381    * @param[in] value The new property value.
1382    */
1383   static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
1384
1385   /**
1386    * Called to retrieve a property of an object of this type.
1387    * @param[in] object The object whose property is to be retrieved.
1388    * @param[in] index The property index.
1389    * @return The current value of the property.
1390    */
1391   static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
1392
1393   /**
1394    * Emits the style changed signal.
1395    */
1396   void EmitStyleChangedSignal();
1397
1398   /**
1399    * Emit signal when text is modified.
1400    */
1401   void EmitTextModified();
1402
1403   /**
1404    * Emits max input characters reached signal.
1405    */
1406   void EmitMaxInputCharactersReachedSignal();
1407
1408   /**
1409    * Emits a signal when the input text exceeds the boundaries of the text-input.
1410    */
1411   void EmitInputTextExceedsBoundariesSignal();
1412
1413 private:
1414
1415   State mState;                                 ///< Current State of Text input.
1416   MarkupProcessor::StyledTextArray mStyledText; ///< String currently displayed by TextView with style info.
1417   TextStyle mInputStyle;                        ///< Stores the current input style.
1418   float     mLineHeight;                        ///< Stores the current line height accordingly with the input style.
1419   Toolkit::TextView mDisplayedTextView;         ///< Actor which actually display text
1420
1421   MarkupProcessor::StyledTextArray mStyledPlaceHolderText; ///< Text used as place holder with style info.
1422
1423   std::size_t mMaxStringLength;                 ///< Max number of characters for string
1424   std::size_t mNumberOflinesLimit;              ///< Limit on the number of lines this TextInput will display.
1425
1426   ImageActor mCursor;                           ///< Cursor overlayed on Text to show where new text will be inserted
1427   ImageActor mCursorRTL;                        ///< Right To Left Cursor overlayed on Text (where new RTL text would be inserted)
1428   Animation mCursorAnimation;                   ///< animator for cursor blinking.
1429   std::size_t mCursorPosition;                  ///< position along string cursor is at.
1430   Timer mCursorBlinkTimer;                      ///< Timer to signal cursor to blink
1431
1432   Layer mActiveLayer;                           ///< Layer for active handles and alike that ensures they are above all else.
1433
1434   Image mGrabHandleImage;                       ///< image to be used for grab handle
1435   ImageActor mGrabHandle;                       ///< Handle used to move cursor for editing
1436
1437   Actor mGrabArea;                              ///< invisible actor that receives pans events for the grab handle.
1438   PanGestureDetector  mPanGestureDetector;      ///< Pan gesture for handles
1439   TapGestureDetector mTapDetector;              ///< used to start editing
1440   TapGestureDetector mDoubleTapDetector;        ///< double tap detector
1441
1442   Vector3 mActualGrabHandlePosition;            ///< actual position of grab handle, this might not be snapped to a character
1443
1444   LongPressGestureDetector mLongPressDetector;  ///< Gesture to start selection
1445
1446   /*Selection handles*/
1447   Image mSelectionHandleOneImage;               ///< image used for selection handle one
1448   Image mSelectionHandleOneImagePressed;        ///< image used for selection handle one pressed state
1449   Image mSelectionHandleTwoImage;               ///< image used for selection handle two
1450   Image mSelectionHandleTwoImagePressed;        ///< image used for selection handle two pressed state
1451
1452   bool mIsSelectionHandleOneFlipped:1;          ///< Flag to know whether the handle one is flipped or not.
1453   bool mIsSelectionHandleTwoFlipped:1;          ///< Flag to know whether the handle two is flipped or not.
1454   Vector3 mSelectionHandleOneOffset;            ///< Handle One's Offset
1455   Vector3 mSelectionHandleTwoOffset;            ///< Handle Two's Offset
1456   Vector3 mSelectionHandleOneActualPosition;    ///< Actual x y position of handle
1457   Vector3 mSelectionHandleTwoActualPosition;    ///< Actual x y position of handle
1458   std::size_t mSelectionHandleOnePosition;      ///< Position of handle along the string of text
1459   std::size_t mSelectionHandleTwoPosition;      ///< Position of handle along the string of text
1460   ImageActor mSelectionHandleOne;               ///< First selection handle used for selecting text to cut&paste
1461   ImageActor mSelectionHandleTwo;               ///< Second selection handle used for selecting text to cut&paste
1462   Actor mHandleOneGrabArea;                     ///< invisible actor that receives pans events for the selection handle.
1463   Actor mHandleTwoGrabArea;                     ///< invisible actor that receives pans events for the selection handle.
1464
1465   Mesh              mHighlightMesh;             ///< Mesh Data for highlight
1466   MeshActor         mHighlightMeshActor;        ///< Mesh Actor to display highlight
1467   MeshData          mMeshData;                  ///< Container to hold meshData for highlight
1468   Material          mCustomMaterial;            ///< Custom material used for highlight
1469   HighlightInfo     mNewHighlightInfo;          ///< Geometry info to create highlight.
1470
1471   Text mPreEditString;                          ///< Holds current input string prior to it being committed.
1472   std::size_t mPreEditStartPosition;            ///< Cursor position for start of pre-edit string
1473   std::size_t mPreEditLength;                   ///< Cursor position for length of current pre-edit string after purging characters that do not fit.
1474   std::size_t mNumberOfSurroundingCharactersDeleted; ///< Stores the number of surrounding characters deleted.
1475   unsigned long mTouchStartTime;                ///< Touch Start time (time in ms when down press began)
1476
1477   Toolkit::TextView::TextLayoutInfo                                 mTextLayoutInfo; ///< It contains a table layout info per character sorted by the character's visual index (retrieved from TextView),
1478                                                                                      ///< a reorder map that stores each character's visual (output) index according to its logical (input) index,
1479                                                                                      ///< a reorder map that stores each character's logical (input) index according to its visual (output) index,
1480                                                                                      ///< the text size after layout and the scroll offset.
1481
1482   MarkupProcessor::StyledTextArray mCurrentCopySelecton;                                              ///< Array to store copied text.
1483   TextInputPopup mPopupPanel;                                                                         ///< Panel to house cut and paste, select all buttons.
1484
1485   Timer mScrollTimer;
1486   Vector2 mScrollDisplacement;
1487   Vector3 mCurrentHandlePosition;
1488   SelectionHandleId mCurrentSelectionId;
1489   Vector3 mCurrentSelectionHandlePosition;
1490   SelectionParameters mRequestedSelection;
1491   Vector4 mSelectionHandleFlipMargin;
1492   Vector4 mBoundingRectangleWorldCoordinates;
1493
1494   Clipboard mClipboard;                   ///< Handle to clipboard
1495
1496   // Styling
1497   Vector4           mMaterialColor;       // Color of the highlight
1498   Vector4           mPopupOffsetFromText; // Offset of Popup from the TextInput.
1499
1500   bool mOverrideAutomaticAlignment:1;    ///< Whether to override the alignment automatically set by the text content (e.g. european LTR or arabic RTL)
1501   bool mCursorRTLEnabled:1;              ///< Enable state of Alternate RTL Cursor (need to keep track of this as it's not always enabled)
1502   bool mClosestCursorPositionEOL:1;      ///< closest cursor position is end of line.
1503   bool mCursorBlinkStatus:1;             ///< \e true shows the cursor, \e false hiddes it.
1504
1505   bool mCursorVisibility:1;              ///< Visibility status of Cursor
1506   bool mGrabHandleVisibility:1;          ///< Visibility status of the grab handle.
1507
1508   bool mIsCursorInScrollArea:1;          ///< Whether the cursor is inside the boundaries of the text-input.
1509   bool mIsGrabHandleInScrollArea:1;      ///< Whether the grab handle is inside the boundaries of the text-input.
1510
1511   bool mEditModeActive:1;                ///< true to indicate TextInput is in edit mode.
1512   bool mEditOnTouch:1;                   ///< true indicates edit mode starts by touching/tapping the TextInput
1513   bool mTextSelection:1;                 ///< true indicates text selection is enabled.
1514   bool mExceedEnabled:1;                 ///< Whether text-input editing text beyond its boundary is enabled or not. By default is enabled.
1515   bool mGrabHandleEnabled:1;             ///< Flag to enable the grab handle instead of the default magnifier.
1516   bool mIsSelectionHandleFlipEnabled:1;  ///< Flag to enable the selection handle flip
1517
1518   bool mPreEditFlag:1;                   ///< Flag to indicate if key string received is still in pre-edit mode (Ecore IMF keyboard)
1519   bool mIgnoreCommitFlag:1;              ///< Flag to indicate if the commit string should be ignored, maybe due to a keyboard reset.
1520   bool mIgnoreFirstCommitFlag:1;         ///< Whether to ignore the first commit.
1521   bool mSelectingText:1;                 ///< Ignore surrounding text as selecting text
1522
1523   bool mPreserveCursorPosition:1;        ///< Indicates that the commit message is from a reset and does not require the cursor to be moved
1524
1525   bool mSelectTextOnCommit:1;
1526
1527   bool mUnderlinedPriorToPreEdit:1;      ///< As predictive text adds underline style this flag enables us to revert back or keep underline.
1528
1529   bool mCommitByKeyInput:1;              ///< Set if a commit is done by key input rather than automatically (usually when a space bar or enter is pressed).
1530
1531   bool mPlaceHolderSet:1;                ///< Whether the place holder text is set.
1532   bool mMarkUpEnabled:1;                 ///< enable to scan for mark-up
1533
1534   Toolkit::TextInput::InputSignalType                      mInputStartedSignal;              ///< Signal emitted when input starts
1535   Toolkit::TextInput::InputSignalType                      mInputFinishedSignal;             ///< Signal emitted when input ends
1536   Toolkit::TextInput::StyleChangedSignalType               mStyleChangedSignal;              ///< Signal emitted when style changes.
1537   Toolkit::TextInput::TextModifiedSignalType             mTextModifiedSignal;                ///< Signal emitted when text modified.
1538   Toolkit::TextInput::MaxInputCharactersReachedSignalType  mMaxInputCharactersReachedSignal; ///< Signal emitted when max input characters is reached.
1539   Toolkit::TextInput::InputSignalType                      mCutAndPasteToolBarDisplayed;       ///< Signal emitted when toolbar displayed
1540   Toolkit::TextInput::InputTextExceedBoundariesSignalType  mInputTextExceedBoundariesSignal; ///< Signal emitted when input text exceeds the boundaries of the text-input.
1541 };
1542
1543 } // namespace Internal
1544
1545 // Helpers for public-api forwarding methods
1546
1547 inline Toolkit::Internal::TextInput& GetImpl(Toolkit::TextInput& textInput)
1548 {
1549   DALI_ASSERT_ALWAYS(textInput);
1550
1551   Dali::RefObject& handle = textInput.GetImplementation();
1552
1553   return static_cast<Toolkit::Internal::TextInput&>(handle);
1554 }
1555
1556 inline const Toolkit::Internal::TextInput& GetImpl(const Toolkit::TextInput& textInput)
1557 {
1558   DALI_ASSERT_ALWAYS(textInput);
1559
1560   const Dali::RefObject& handle = textInput.GetImplementation();
1561
1562   return static_cast<const Toolkit::Internal::TextInput&>(handle);
1563 }
1564
1565 } // namespace Toolkit
1566
1567 } // namespace Dali
1568
1569 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_INPUT_H__