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