Fixed popup label properties
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / decorator / text-decorator.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali-toolkit/internal/text/decorator/text-decorator.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/actors/actor.h>
23 #include <dali/public-api/adaptor-framework/timer.h>
24 #include <dali/public-api/actors/image-actor.h>
25 #include <dali/public-api/actors/layer.h>
26 #include <dali/public-api/actors/mesh-actor.h>
27 #include <dali/public-api/common/constants.h>
28 #include <dali/public-api/events/tap-gesture.h>
29 #include <dali/public-api/events/tap-gesture-detector.h>
30 #include <dali/public-api/events/pan-gesture.h>
31 #include <dali/public-api/events/pan-gesture-detector.h>
32 #include <dali/public-api/geometry/mesh.h>
33 #include <dali/public-api/geometry/mesh-data.h>
34 #include <dali/public-api/images/resource-image.h>
35 #include <dali/public-api/math/vector2.h>
36 #include <dali/public-api/math/vector4.h>
37 //#include <dali/public-api/images/nine-patch-image.h>
38 #include <dali/public-api/signals/connection-tracker.h>
39
40 // INTERNAL INCLUDES
41 #include <dali-toolkit/public-api/controls/control.h>
42 #include <dali-toolkit/public-api/controls/control-impl.h>
43 #include <dali-toolkit/public-api/controls/buttons/push-button.h>
44 #include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
45 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
46 #include <dali-toolkit/public-api/controls/text-controls/text-selection-popup.h>
47
48 #ifdef DEBUG_ENABLED
49 #define DECORATOR_DEBUG
50 #endif
51
52 // Local Data
53 namespace
54 {
55
56 const char* DEFAULT_GRAB_HANDLE_IMAGE( DALI_IMAGE_DIR "insertpoint-icon.png" );
57 const char* DEFAULT_SELECTION_HANDLE_ONE( DALI_IMAGE_DIR "text-input-selection-handle-left.png" );
58 const char* DEFAULT_SELECTION_HANDLE_TWO( DALI_IMAGE_DIR "text-input-selection-handle-right.png" );
59 //const char* DEFAULT_SELECTION_HANDLE_ONE_PRESSED( DALI_IMAGE_DIR "text-input-selection-handle-left-press.png" );
60 //const char* DEFAULT_SELECTION_HANDLE_TWO_PRESSED( DALI_IMAGE_DIR "text-input-selection-handle-right-press.png" );
61
62 const Dali::Vector3 DEFAULT_GRAB_HANDLE_RELATIVE_SIZE( 1.5f, 2.0f, 1.0f );
63 const Dali::Vector3 DEFAULT_SELECTION_HANDLE_RELATIVE_SIZE( 1.5f, 1.5f, 1.0f );
64
65 const std::size_t CURSOR_BLINK_INTERVAL = 500; // Cursor blink interval
66 const std::size_t MILLISECONDS = 1000;
67
68 const float DISPLAYED_HIGHLIGHT_Z_OFFSET( -0.05f );
69
70 /**
71  * structure to hold coordinates of each quad, which will make up the mesh.
72  */
73 struct QuadCoordinates
74 {
75   /**
76    * Default constructor
77    */
78   QuadCoordinates()
79   {
80   }
81
82   /**
83    * Constructor
84    * @param[in] x1 left co-ordinate
85    * @param[in] y1 top co-ordinate
86    * @param[in] x2 right co-ordinate
87    * @param[in] y2 bottom co-ordinate
88    */
89   QuadCoordinates(float x1, float y1, float x2, float y2)
90   : min(x1, y1),
91     max(x2, y2)
92   {
93   }
94
95   Dali::Vector2 min;                          ///< top-left (minimum) position of quad
96   Dali::Vector2 max;                          ///< bottom-right (maximum) position of quad
97 };
98
99 typedef std::vector<QuadCoordinates> QuadContainer;
100
101 } // end of namespace
102
103 namespace Dali
104 {
105
106 namespace Toolkit
107 {
108
109 namespace Text
110 {
111
112 struct Decorator::Impl : public ConnectionTracker
113 {
114   struct CursorImpl
115   {
116     CursorImpl()
117     : x(0.0f),
118       y(0.0f),
119       height(0.0f),
120       color(Dali::Color::WHITE)
121     {
122     }
123
124     float x;
125     float y;
126     float height;
127
128     Vector4 color;
129   };
130
131   struct SelectionHandleImpl
132   {
133     SelectionHandleImpl()
134     : x(0.0f),
135       y(0.0f),
136       cursorHeight(0.0f),
137       flipped(false)
138     {
139     }
140
141     float x;
142     float y;
143     float cursorHeight; ///< Not the handle height
144     bool flipped;
145
146     ImageActor actor;
147     Actor grabArea;
148
149     Image pressedImage;
150     Image releasedImage;
151   };
152
153   Impl( Dali::Toolkit::Internal::Control& parent, Observer& observer )
154   : mTextControlParent(parent),
155     mObserver(observer),
156     mActiveCursor(ACTIVE_CURSOR_NONE),
157     mActiveGrabHandle(false),
158     mActiveSelection( false ),
159     mActiveCopyPastePopup( false ),
160     mCursorBlinkInterval( CURSOR_BLINK_INTERVAL ),
161     mCursorBlinkDuration( 0.0f ),
162     mCursorBlinkStatus( true ),
163     mGrabDisplacementX( 0.0f ),
164     mGrabDisplacementY( 0.0f ),
165     mHighlightColor( 0.07f, 0.41f, 0.59f, 1.0f ), // light blue
166     mBoundingBox( Rect<int>() )
167   {
168   }
169
170   /**
171    * Relayout of the decorations owned by the decorator.
172    * @param[in] size The Size of the UI control the decorater is adding it's decorations to.
173    */
174   void Relayout( const Vector2& size, const Vector2& scrollPosition )
175   {
176     // TODO - Remove this if nothing is active
177     CreateActiveLayer();
178
179     // Show or hide the cursors
180     CreateCursors();
181     if( mPrimaryCursor )
182     {
183       mPrimaryCursor.SetPosition( mCursor[PRIMARY_CURSOR].x + scrollPosition.x,
184                                   mCursor[PRIMARY_CURSOR].y + scrollPosition.y );
185       mPrimaryCursor.SetSize( Vector2( 1.0f, mCursor[PRIMARY_CURSOR].height ) );
186     }
187     if( mSecondaryCursor )
188     {
189       mSecondaryCursor.SetPosition( mCursor[SECONDARY_CURSOR].x + scrollPosition.x,
190                                     mCursor[SECONDARY_CURSOR].y + scrollPosition.y );
191       mSecondaryCursor.SetSize( Vector2( 1.0f, mCursor[SECONDARY_CURSOR].height ) );
192     }
193
194     // Show or hide the grab handle
195     if( mActiveGrabHandle )
196     {
197       SetupTouchEvents();
198
199       CreateGrabHandle();
200
201       mGrabHandle.SetPosition( mCursor[PRIMARY_CURSOR].x + scrollPosition.x,
202                                mCursor[PRIMARY_CURSOR].y + scrollPosition.y + mCursor[PRIMARY_CURSOR].height );
203     }
204     else if( mGrabHandle )
205     {
206       UnparentAndReset( mGrabHandle );
207     }
208
209     // Show or hide the selection handles/highlight
210     if( mActiveSelection )
211     {
212       SetupTouchEvents();
213
214       CreateSelectionHandles();
215
216       SelectionHandleImpl& primary = mSelectionHandle[ PRIMARY_SELECTION_HANDLE ];
217       primary.actor.SetPosition( primary.x + scrollPosition.x,
218                                  primary.y + scrollPosition.y + primary.cursorHeight );
219
220       SelectionHandleImpl& secondary = mSelectionHandle[ SECONDARY_SELECTION_HANDLE ];
221       secondary.actor.SetPosition( secondary.x + scrollPosition.x,
222                                    secondary.y + scrollPosition.y + secondary.cursorHeight );
223
224       CreateHighlight();
225       UpdateHighlight();
226     }
227     else
228     {
229       UnparentAndReset( mSelectionHandle[ PRIMARY_SELECTION_HANDLE ].actor );
230       UnparentAndReset( mSelectionHandle[ SECONDARY_SELECTION_HANDLE ].actor );
231       UnparentAndReset( mHighlightMeshActor );
232     }
233
234     if ( mActiveCopyPastePopup )
235     {
236       if ( !mCopyPastePopup )
237       {
238         mCopyPastePopup = TextSelectionPopup::New();
239         mActiveLayer.Add ( mCopyPastePopup );
240       }
241       mCopyPastePopup.SetPosition( Vector3( 200.0f, -100.0f, 0.0f ) ); //todo grabhandle or selection handle positions to be used
242     }
243     else
244     {
245      if ( mCopyPastePopup )
246      {
247        UnparentAndReset( mCopyPastePopup );
248      }
249     }
250   }
251
252   void CreateCursor( ImageActor& cursor )
253   {
254     cursor = CreateSolidColorActor( Color::WHITE );
255     cursor.SetParentOrigin( ParentOrigin::TOP_LEFT ); // Need to set the default parent origin as CreateSolidColorActor() sets a different one.
256     cursor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
257     cursor.SetRelayoutEnabled( false );
258   }
259
260   // Add or Remove cursor(s) from parent
261   void CreateCursors()
262   {
263     if( mActiveCursor == ACTIVE_CURSOR_NONE )
264     {
265       UnparentAndReset( mPrimaryCursor );
266       UnparentAndReset( mSecondaryCursor );
267     }
268     else
269     {
270       /* Create Primary and or Secondary Cursor(s) if active and add to parent */
271       if ( mActiveCursor == ACTIVE_CURSOR_PRIMARY ||
272            mActiveCursor == ACTIVE_CURSOR_BOTH )
273       {
274         if ( !mPrimaryCursor )
275         {
276           CreateCursor( mPrimaryCursor );
277 #ifdef DECORATOR_DEBUG
278           mPrimaryCursor.SetName( "PrimaryCursorActor" );
279 #endif
280           mActiveLayer.Add( mPrimaryCursor);
281         }
282       }
283
284       if ( mActiveCursor == ACTIVE_CURSOR_BOTH )
285       {
286         if ( !mSecondaryCursor )
287         {
288           CreateCursor( mSecondaryCursor );
289 #ifdef DECORATOR_DEBUG
290           mSecondaryCursor.SetName( "SecondaryCursorActor" );
291 #endif
292           mActiveLayer.Add( mSecondaryCursor);
293         }
294       }
295     }
296   }
297
298   bool OnCursorBlinkTimerTick()
299   {
300     // Cursor blinking
301     if ( mPrimaryCursor )
302     {
303       mPrimaryCursor.SetVisible( mCursorBlinkStatus );
304     }
305     if ( mSecondaryCursor )
306     {
307       mSecondaryCursor.SetVisible( mCursorBlinkStatus );
308     }
309
310     mCursorBlinkStatus = !mCursorBlinkStatus;
311
312     return true;
313   }
314
315   void SetupTouchEvents()
316   {
317     if ( !mTapDetector )
318     {
319       mTapDetector = TapGestureDetector::New();
320       mTapDetector.DetectedSignal().Connect( this, &Decorator::Impl::OnTap );
321     }
322
323     if ( !mPanGestureDetector )
324     {
325       mPanGestureDetector = PanGestureDetector::New();
326       mPanGestureDetector.DetectedSignal().Connect( this, &Decorator::Impl::OnPan );
327     }
328   }
329
330   void CreateActiveLayer()
331   {
332     if( !mActiveLayer )
333     {
334       Actor parent = mTextControlParent.Self();
335
336       mActiveLayer = Layer::New();
337 #ifdef DECORATOR_DEBUG
338       mActiveLayer.SetName ( "ActiveLayerActor" );
339 #endif
340
341       mActiveLayer.SetParentOrigin( ParentOrigin::CENTER );
342       mActiveLayer.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
343       mActiveLayer.SetPositionInheritanceMode( USE_PARENT_POSITION );
344
345       parent.Add( mActiveLayer );
346     }
347
348     mActiveLayer.RaiseToTop();
349   }
350
351   void CreateGrabHandle()
352   {
353     if( !mGrabHandle )
354     {
355       if ( !mGrabHandleImage )
356       {
357         mGrabHandleImage = ResourceImage::New( DEFAULT_GRAB_HANDLE_IMAGE );
358       }
359
360       mGrabHandle = ImageActor::New( mGrabHandleImage );
361 #ifdef DECORATOR_DEBUG
362       mGrabHandle.SetName( "GrabHandleActor" );
363 #endif
364       mGrabHandle.SetAnchorPoint( AnchorPoint::TOP_CENTER );
365       mGrabHandle.SetDrawMode( DrawMode::OVERLAY );
366       // Area that Grab handle responds to, larger than actual handle so easier to move
367 #ifdef DECORATOR_DEBUG
368      mGrabArea = Toolkit::CreateSolidColorActor( Vector4(0.0f, 0.0f, 0.0f, 0.0f), true, Color::RED, 1 );
369      mGrabArea.SetName( "GrabArea" );
370 #else
371       mGrabArea = Actor::New();
372       mGrabArea.SetRelayoutEnabled( true );
373 #endif
374       mGrabArea.SetParentOrigin( ParentOrigin::TOP_CENTER );
375       mGrabArea.SetAnchorPoint( AnchorPoint::TOP_CENTER );
376       mGrabArea.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
377       mGrabArea.SetSizeMode( SIZE_RELATIVE_TO_PARENT );
378       mGrabArea.SetSizeModeFactor( DEFAULT_GRAB_HANDLE_RELATIVE_SIZE );
379       mGrabHandle.Add( mGrabArea );
380
381       mTapDetector.Attach( mGrabArea );
382       mPanGestureDetector.Attach( mGrabArea );
383
384       mActiveLayer.Add(mGrabHandle);
385     }
386   }
387
388   void CreateSelectionHandles()
389   {
390     SelectionHandleImpl& primary = mSelectionHandle[ PRIMARY_SELECTION_HANDLE ];
391     if ( !primary.actor )
392     {
393       if ( !primary.releasedImage )
394       {
395         primary.releasedImage = ResourceImage::New( DEFAULT_SELECTION_HANDLE_ONE );
396       }
397
398       primary.actor = ImageActor::New( primary.releasedImage );
399 #ifdef DECORATOR_DEBUG
400       primary.actor.SetName("SelectionHandleOne");
401 #endif
402       primary.actor.SetAnchorPoint( AnchorPoint::TOP_RIGHT ); // Change to BOTTOM_RIGHT if Look'n'Feel requires handle above text.
403       primary.actor.SetDrawMode( DrawMode::OVERLAY ); // ensure grab handle above text
404       primary.flipped = false;
405
406       primary.grabArea = Actor::New(); // Area that Grab handle responds to, larger than actual handle so easier to move
407       primary.grabArea.SetRelayoutEnabled( true );
408 #ifdef DECORATOR_DEBUG
409       primary.grabArea.SetName("SelectionHandleOneGrabArea");
410 #endif
411       primary.grabArea.SetSizeMode( SIZE_RELATIVE_TO_PARENT );
412       primary.grabArea.SetSizeModeFactor( DEFAULT_SELECTION_HANDLE_RELATIVE_SIZE );
413       primary.grabArea.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION );
414
415       mTapDetector.Attach( primary.grabArea );
416       mPanGestureDetector.Attach( primary.grabArea );
417       primary.grabArea.TouchedSignal().Connect( this, &Decorator::Impl::OnHandleOneTouched );
418
419       primary.actor.Add( primary.grabArea );
420       mActiveLayer.Add( primary.actor );
421     }
422
423     SelectionHandleImpl& secondary = mSelectionHandle[ SECONDARY_SELECTION_HANDLE ];
424     if ( !secondary.actor )
425     {
426       if ( !secondary.releasedImage )
427       {
428         secondary.releasedImage = ResourceImage::New( DEFAULT_SELECTION_HANDLE_TWO );
429       }
430
431       secondary.actor = ImageActor::New( secondary.releasedImage );
432 #ifdef DECORATOR_DEBUG
433       secondary.actor.SetName("SelectionHandleTwo");
434 #endif
435       secondary.actor.SetAnchorPoint( AnchorPoint::TOP_LEFT ); // Change to BOTTOM_LEFT if Look'n'Feel requires handle above text.
436       secondary.actor.SetDrawMode( DrawMode::OVERLAY ); // ensure grab handle above text
437       secondary.flipped = false;
438
439       secondary.grabArea = Actor::New(); // Area that Grab handle responds to, larger than actual handle so easier to move
440       secondary.grabArea.SetRelayoutEnabled( true );
441 #ifdef DECORATOR_DEBUG
442       secondary.grabArea.SetName("SelectionHandleTwoGrabArea");
443 #endif
444       secondary.grabArea.SetSizeMode( SIZE_RELATIVE_TO_PARENT );
445       secondary.grabArea.SetSizeModeFactor( DEFAULT_SELECTION_HANDLE_RELATIVE_SIZE );
446       secondary.grabArea.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION );
447
448       mTapDetector.Attach( secondary.grabArea );
449       mPanGestureDetector.Attach( secondary.grabArea );
450       secondary.grabArea.TouchedSignal().Connect( this, &Decorator::Impl::OnHandleTwoTouched );
451
452       secondary.actor.Add( secondary.grabArea );
453       mActiveLayer.Add( secondary.actor );
454     }
455
456     //SetUpHandlePropertyNotifications(); TODO
457   }
458
459   void CreateHighlight()
460   {
461     if ( !mHighlightMeshActor )
462     {
463       mHighlightMaterial = Material::New( "HighlightMaterial" );
464       mHighlightMaterial.SetDiffuseColor( mHighlightColor );
465
466       mHighlightMeshData.SetMaterial( mHighlightMaterial );
467       mHighlightMeshData.SetHasNormals( true );
468
469       mHighlightMesh = Mesh::New( mHighlightMeshData );
470
471       mHighlightMeshActor = MeshActor::New( mHighlightMesh );
472 #ifdef DECORATOR_DEBUG
473       mHighlightMeshActor.SetName( "HighlightMeshActor" );
474 #endif
475       mHighlightMeshActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
476       mHighlightMeshActor.SetPosition( 0.0f, 0.0f, DISPLAYED_HIGHLIGHT_Z_OFFSET );
477
478       Actor parent = mTextControlParent.Self();
479       parent.Add( mHighlightMeshActor );
480     }
481   }
482
483   void UpdateHighlight()
484   {
485     //  Construct a Mesh with a texture to be used as the highlight 'box' for selected text
486     //
487     //  Example scenarios where mesh is made from 3, 1, 2, 2 ,3 or 3 quads.
488     //
489     //   [ TOP   ]  [ TOP ]      [TOP ]  [ TOP    ]      [ TOP  ]      [ TOP  ]
490     //  [ MIDDLE ]             [BOTTOM]  [BOTTOM]      [ MIDDLE ]   [ MIDDLE  ]
491     //  [ BOTTOM]                                      [ MIDDLE ]   [ MIDDLE  ]
492     //                                                 [BOTTOM]     [ MIDDLE  ]
493     //                                                              [BOTTOM]
494     //
495     //  Each quad is created as 2 triangles.
496     //  Middle is just 1 quad regardless of its size.
497     //
498     //  (0,0)         (0,0)
499     //     0*    *2     0*       *2
500     //     TOP          TOP
501     //     3*    *1     3*       *1
502     //  4*       *1     4*     *6
503     //     MIDDLE         BOTTOM
504     //  6*       *5     7*     *5
505     //  6*    *8
506     //   BOTTOM
507     //  9*    *7
508     //
509
510     if ( mHighlightMesh && mHighlightMaterial && !mHighlightQuadList.empty() )
511     {
512       MeshData::VertexContainer vertices;
513       Dali::MeshData::FaceIndices faceIndices;
514
515       std::vector<QuadCoordinates>::iterator iter = mHighlightQuadList.begin();
516       std::vector<QuadCoordinates>::iterator endIter = mHighlightQuadList.end();
517
518       // vertex position defaults to (0 0 0)
519       MeshData::Vertex vertex;
520       // set normal for all vertices as (0 0 1) pointing outward from TextInput Actor.
521       vertex.nZ = 1.0f;
522
523       for(std::size_t v = 0; iter != endIter; ++iter,v+=4 )
524       {
525         // Add each quad geometry (a sub-selection) to the mesh data.
526
527         // 0-----1
528         // |\    |
529         // | \ A |
530         // |  \  |
531         // | B \ |
532         // |    \|
533         // 2-----3
534
535         QuadCoordinates& quad = *iter;
536         // top-left (v+0)
537         vertex.x = quad.min.x;
538         vertex.y = quad.min.y;
539         vertices.push_back( vertex );
540
541         // top-right (v+1)
542         vertex.x = quad.max.x;
543         vertex.y = quad.min.y;
544         vertices.push_back( vertex );
545
546         // bottom-left (v+2)
547         vertex.x = quad.min.x;
548         vertex.y = quad.max.y;
549         vertices.push_back( vertex );
550
551         // bottom-right (v+3)
552         vertex.x = quad.max.x;
553         vertex.y = quad.max.y;
554         vertices.push_back( vertex );
555
556         // triangle A (3, 1, 0)
557         faceIndices.push_back( v + 3 );
558         faceIndices.push_back( v + 1 );
559         faceIndices.push_back( v );
560
561         // triangle B (0, 2, 3)
562         faceIndices.push_back( v );
563         faceIndices.push_back( v + 2 );
564         faceIndices.push_back( v + 3 );
565
566         mHighlightMeshData.SetFaceIndices( faceIndices );
567       }
568
569       BoneContainer bones(0); // passed empty as bones not required
570       mHighlightMeshData.SetData( vertices, faceIndices, bones, mHighlightMaterial );
571       mHighlightMesh.UpdateMeshData( mHighlightMeshData );
572     }
573   }
574
575   void OnTap( Actor actor, const TapGesture& tap )
576   {
577     if( actor == mGrabHandle )
578     {
579       // TODO
580     }
581   }
582
583   void OnPan( Actor actor, const PanGesture& gesture )
584   {
585     if( actor == mGrabArea )
586     {
587       if( Gesture::Started == gesture.state )
588       {
589         mGrabDisplacementX = mGrabDisplacementY = 0;
590       }
591
592       mGrabDisplacementX += gesture.displacement.x;
593       mGrabDisplacementY += gesture.displacement.y;
594
595       float x = mCursor[PRIMARY_CURSOR].x + mGrabDisplacementX;
596       float y = mCursor[PRIMARY_CURSOR].y + mCursor[PRIMARY_CURSOR].height*0.5f + mGrabDisplacementY;
597
598       if( Gesture::Started    == gesture.state ||
599           Gesture::Continuing == gesture.state )
600       {
601         mObserver.GrabHandleEvent( GRAB_HANDLE_PRESSED, x, y );
602       }
603       else if( Gesture::Finished  == gesture.state ||
604                Gesture::Cancelled == gesture.state )
605       {
606         mObserver.GrabHandleEvent( GRAB_HANDLE_RELEASED, x, y );
607       }
608     }
609   }
610
611   bool OnHandleOneTouched( Actor actor, const TouchEvent& touch )
612   {
613     // TODO
614     return false;
615   }
616
617   bool OnHandleTwoTouched( Actor actor, const TouchEvent& touch )
618   {
619     // TODO
620     return false;
621   }
622
623
624   Internal::Control& mTextControlParent;
625   Observer& mObserver;
626
627   Layer mActiveLayer; // Layer for active handles and alike that ensures they are above all else.
628
629   unsigned int mActiveCursor;
630   bool         mActiveGrabHandle;
631   bool         mActiveSelection;
632   bool         mActiveCopyPastePopup;
633
634   CursorImpl mCursor[CURSOR_COUNT];
635
636   Timer mCursorBlinkTimer; // Timer to signal cursor to blink
637   unsigned int mCursorBlinkInterval;
638   float mCursorBlinkDuration;
639   bool mCursorBlinkStatus; // Flag to switch between blink on and blink off
640
641   ImageActor mPrimaryCursor;
642   ImageActor mSecondaryCursor;
643
644   ImageActor mGrabHandle;
645   Actor mGrabArea;
646   float mGrabDisplacementX;
647   float mGrabDisplacementY;
648
649   SelectionHandleImpl mSelectionHandle[SELECTION_HANDLE_COUNT];
650
651   MeshActor         mHighlightMeshActor;        ///< Mesh Actor to display highlight
652   Mesh              mHighlightMesh;             ///< Mesh for highlight
653   MeshData          mHighlightMeshData;         ///< Mesh Data for highlight
654   Material          mHighlightMaterial;         ///< Material used for highlight
655   Vector4           mHighlightColor;            ///< Color of the highlight
656   QuadContainer     mHighlightQuadList;         ///< Sub-selections that combine to create the complete selection highlight
657
658   TextSelectionPopup mCopyPastePopup;
659
660   Image mCursorImage;
661   Image mGrabHandleImage;
662
663   TapGestureDetector mTapDetector;
664   PanGestureDetector mPanGestureDetector;
665
666   Rect<int> mBoundingBox;
667 };
668
669 DecoratorPtr Decorator::New( Internal::Control& parent, Observer& observer )
670 {
671   return DecoratorPtr( new Decorator(parent, observer) );
672 }
673
674 void Decorator::SetBoundingBox( const Rect<int>& boundingBox )
675 {
676   mImpl->mBoundingBox = boundingBox;
677 }
678
679 const Rect<int>& Decorator::GetBoundingBox() const
680 {
681   return mImpl->mBoundingBox;
682 }
683
684 void Decorator::Relayout( const Vector2& size, const Vector2& scrollPosition )
685 {
686   mImpl->Relayout( size, scrollPosition );
687 }
688
689 /** Cursor **/
690
691 void Decorator::SetActiveCursor( ActiveCursor activeCursor )
692 {
693   mImpl->mActiveCursor = activeCursor;
694 }
695
696 unsigned int Decorator::GetActiveCursor() const
697 {
698   return mImpl->mActiveCursor;
699 }
700
701 void Decorator::SetPosition( Cursor cursor, float x, float y, float height )
702 {
703   // Adjust grab handle displacement
704   mImpl->mGrabDisplacementX -= x - mImpl->mCursor[cursor].x;
705   mImpl->mGrabDisplacementY -= y - mImpl->mCursor[cursor].y;
706
707   mImpl->mCursor[cursor].x = x;
708   mImpl->mCursor[cursor].y = y;
709   mImpl->mCursor[cursor].height = height;
710 }
711
712 void Decorator::GetPosition( Cursor cursor, float& x, float& y, float& height ) const
713 {
714   x = mImpl->mCursor[cursor].x;
715   y = mImpl->mCursor[cursor].y;
716   height = mImpl->mCursor[cursor].height;
717 }
718
719 void Decorator::SetColor( Cursor cursor, const Dali::Vector4& color )
720 {
721   mImpl->mCursor[cursor].color = color;
722 }
723
724 const Dali::Vector4& Decorator::GetColor( Cursor cursor ) const
725 {
726   return mImpl->mCursor[cursor].color;
727 }
728
729 void Decorator::StartCursorBlink()
730 {
731   if ( !mImpl->mCursorBlinkTimer )
732   {
733     mImpl->mCursorBlinkTimer = Timer::New( mImpl->mCursorBlinkInterval );
734     mImpl->mCursorBlinkTimer.TickSignal().Connect( mImpl, &Decorator::Impl::OnCursorBlinkTimerTick );
735   }
736
737   if ( !mImpl->mCursorBlinkTimer.IsRunning() )
738   {
739     mImpl->mCursorBlinkTimer.Start();
740   }
741 }
742
743 void Decorator::StopCursorBlink()
744 {
745   if ( mImpl->mCursorBlinkTimer )
746   {
747     mImpl->mCursorBlinkTimer.Stop();
748   }
749 }
750
751 void Decorator::SetCursorBlinkInterval( float seconds )
752 {
753   mImpl->mCursorBlinkInterval = seconds*MILLISECONDS; // Convert to milliseconds
754 }
755
756 float Decorator::GetCursorBlinkInterval() const
757 {
758   return mImpl->mCursorBlinkInterval;
759 }
760
761 void Decorator::SetCursorBlinkDuration( float seconds )
762 {
763   mImpl->mCursorBlinkDuration = seconds;
764 }
765
766 float Decorator::GetCursorBlinkDuration() const
767 {
768   return mImpl->mCursorBlinkDuration;
769 }
770
771 /** GrabHandle **/
772
773 void Decorator::SetGrabHandleActive( bool active )
774 {
775   mImpl->mActiveGrabHandle = active;
776 }
777
778 bool Decorator::IsGrabHandleActive() const
779 {
780   return mImpl->mActiveGrabHandle;
781 }
782
783 void Decorator::SetGrabHandleImage( Dali::Image image )
784 {
785   mImpl->mGrabHandleImage = image;
786 }
787
788 Dali::Image Decorator::GetGrabHandleImage() const
789 {
790   return mImpl->mGrabHandleImage;
791 }
792
793 /** Selection **/
794
795 void Decorator::SetSelectionActive( bool active )
796 {
797   mImpl->mActiveSelection = active;
798 }
799
800 bool Decorator::IsSelectionActive() const
801 {
802   return mImpl->mActiveSelection;
803 }
804
805 void Decorator::SetPosition( SelectionHandle handle, float x, float y, float height )
806 {
807   mImpl->mSelectionHandle[handle].x = x;
808   mImpl->mSelectionHandle[handle].y = y;
809   mImpl->mSelectionHandle[handle].cursorHeight = height;
810 }
811
812 void Decorator::GetPosition( SelectionHandle handle, float& x, float& y, float& height ) const
813 {
814   x = mImpl->mSelectionHandle[handle].x;
815   y = mImpl->mSelectionHandle[handle].y;
816   height = mImpl->mSelectionHandle[handle].cursorHeight;
817 }
818
819 void Decorator::SetImage( SelectionHandle handle, SelectionHandleState state, Dali::Image image )
820 {
821   if( SELECTION_HANDLE_PRESSED == state )
822   {
823     mImpl->mSelectionHandle[handle].pressedImage = image;
824   }
825   else
826   {
827     mImpl->mSelectionHandle[handle].releasedImage = image;
828   }
829 }
830
831 Dali::Image Decorator::GetImage( SelectionHandle handle, SelectionHandleState state ) const
832 {
833   if( SELECTION_HANDLE_PRESSED == state )
834   {
835     return mImpl->mSelectionHandle[handle].pressedImage;
836   }
837
838   return mImpl->mSelectionHandle[handle].releasedImage;
839 }
840
841 void Decorator::AddHighlight( float x1, float y1, float x2, float y2 )
842 {
843   mImpl->mHighlightQuadList.push_back( QuadCoordinates(x1, y1, x2, y2) );
844 }
845
846 void Decorator::ClearHighlights()
847 {
848   mImpl->mHighlightQuadList.clear();
849 }
850
851 void Decorator::SetPopupActive( bool active )
852 {
853   mImpl->mActiveCopyPastePopup = active;
854 }
855
856 bool Decorator::IsPopupActive() const
857 {
858   return mImpl->mActiveCopyPastePopup ;
859 }
860
861 Decorator::~Decorator()
862 {
863   delete mImpl;
864 }
865
866 Decorator::Decorator( Dali::Toolkit::Internal::Control& parent, Observer& observer )
867 : mImpl( NULL )
868 {
869   mImpl = new Decorator::Impl( parent, observer );
870 }
871
872 } // namespace Text
873
874 } // namespace Toolkit
875
876 } // namespace Dali