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