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