Added Drop Shadow properties and initial effect with Text Atlas Renderer
[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( 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( 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 );
256     cursor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
257   }
258
259   // Add or Remove cursor(s) from parent
260   void CreateCursors()
261   {
262     if( mActiveCursor == ACTIVE_CURSOR_NONE )
263     {
264       UnparentAndReset( mPrimaryCursor );
265       UnparentAndReset( mSecondaryCursor );
266     }
267     else
268     {
269       /* Create Primary and or Secondary Cursor(s) if active and add to parent */
270       if ( mActiveCursor == ACTIVE_CURSOR_PRIMARY ||
271            mActiveCursor == ACTIVE_CURSOR_BOTH )
272       {
273         if ( !mPrimaryCursor )
274         {
275           CreateCursor( mPrimaryCursor );
276 #ifdef DECORATOR_DEBUG
277           mPrimaryCursor.SetName( "PrimaryCursorActor" );
278 #endif
279           mActiveLayer.Add( mPrimaryCursor);
280         }
281       }
282
283       if ( mActiveCursor == ACTIVE_CURSOR_BOTH )
284       {
285         if ( !mSecondaryCursor )
286         {
287           CreateCursor( mSecondaryCursor );
288 #ifdef DECORATOR_DEBUG
289           mSecondaryCursor.SetName( "SecondaryCursorActor" );
290 #endif
291           mActiveLayer.Add( mSecondaryCursor);
292         }
293       }
294     }
295   }
296
297   bool OnCursorBlinkTimerTick()
298   {
299     // Cursor blinking
300     if ( mPrimaryCursor )
301     {
302       mPrimaryCursor.SetVisible( mCursorBlinkStatus );
303     }
304     if ( mSecondaryCursor )
305     {
306       mSecondaryCursor.SetVisible( mCursorBlinkStatus );
307     }
308
309     mCursorBlinkStatus = !mCursorBlinkStatus;
310
311     return true;
312   }
313
314   void SetupTouchEvents()
315   {
316     if ( !mTapDetector )
317     {
318       mTapDetector = TapGestureDetector::New();
319       mTapDetector.DetectedSignal().Connect( this, &Decorator::Impl::OnTap );
320     }
321
322     if ( !mPanGestureDetector )
323     {
324       mPanGestureDetector = PanGestureDetector::New();
325       mPanGestureDetector.DetectedSignal().Connect( this, &Decorator::Impl::OnPan );
326     }
327   }
328
329   void CreateActiveLayer()
330   {
331     if( !mActiveLayer )
332     {
333       Actor parent = mTextControlParent.Self();
334
335       mActiveLayer = Layer::New();
336 #ifdef DECORATOR_DEBUG
337       mActiveLayer.SetName ( "ActiveLayerActor" );
338 #endif
339
340       mActiveLayer.SetAnchorPoint( AnchorPoint::CENTER);
341       mActiveLayer.SetParentOrigin( ParentOrigin::CENTER);
342       mActiveLayer.SetSizeMode( SIZE_EQUAL_TO_PARENT );
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.SetParentOrigin( ParentOrigin::TOP_LEFT );
365       mGrabHandle.SetAnchorPoint( AnchorPoint::TOP_CENTER );
366       mGrabHandle.SetDrawMode( DrawMode::OVERLAY );
367
368       // Area that Grab handle responds to, larger than actual handle so easier to move
369 #ifdef DECORATOR_DEBUG
370       mGrabArea = Toolkit::CreateSolidColorActor( Vector4(1.0f, 0.0f, 0.0f, 0.5f) );
371       mGrabArea.SetName( "GrabArea" );
372 #else
373       mGrabArea = Actor::New();
374 #endif
375       mGrabArea.SetParentOrigin( ParentOrigin::TOP_CENTER );
376       mGrabArea.SetAnchorPoint( AnchorPoint::TOP_CENTER );
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.SetParentOrigin( ParentOrigin::TOP_LEFT );
403       primary.actor.SetAnchorPoint( AnchorPoint::TOP_RIGHT ); // Change to BOTTOM_RIGHT if Look'n'Feel requires handle above text.
404       primary.actor.SetDrawMode( DrawMode::OVERLAY ); // ensure grab handle above text
405       primary.flipped = false;
406
407       primary.grabArea = Actor::New(); // Area that Grab handle responds to, larger than actual handle so easier to move
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.SetParentOrigin( ParentOrigin::TOP_LEFT );
436       secondary.actor.SetAnchorPoint( AnchorPoint::TOP_LEFT ); // Change to BOTTOM_LEFT if Look'n'Feel requires handle above text.
437       secondary.actor.SetDrawMode( DrawMode::OVERLAY ); // ensure grab handle above text
438       secondary.flipped = false;
439
440       secondary.grabArea = Actor::New(); // Area that Grab handle responds to, larger than actual handle so easier to move
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.SetParentOrigin( ParentOrigin::TOP_LEFT );
476       mHighlightMeshActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
477       mHighlightMeshActor.SetPosition( 0.0f, 0.0f, DISPLAYED_HIGHLIGHT_Z_OFFSET );
478
479       Actor parent = mTextControlParent.Self();
480       parent.Add( mHighlightMeshActor );
481     }
482   }
483
484   void UpdateHighlight()
485   {
486     //  Construct a Mesh with a texture to be used as the highlight 'box' for selected text
487     //
488     //  Example scenarios where mesh is made from 3, 1, 2, 2 ,3 or 3 quads.
489     //
490     //   [ TOP   ]  [ TOP ]      [TOP ]  [ TOP    ]      [ TOP  ]      [ TOP  ]
491     //  [ MIDDLE ]             [BOTTOM]  [BOTTOM]      [ MIDDLE ]   [ MIDDLE  ]
492     //  [ BOTTOM]                                      [ MIDDLE ]   [ MIDDLE  ]
493     //                                                 [BOTTOM]     [ MIDDLE  ]
494     //                                                              [BOTTOM]
495     //
496     //  Each quad is created as 2 triangles.
497     //  Middle is just 1 quad regardless of its size.
498     //
499     //  (0,0)         (0,0)
500     //     0*    *2     0*       *2
501     //     TOP          TOP
502     //     3*    *1     3*       *1
503     //  4*       *1     4*     *6
504     //     MIDDLE         BOTTOM
505     //  6*       *5     7*     *5
506     //  6*    *8
507     //   BOTTOM
508     //  9*    *7
509     //
510
511     if ( mHighlightMesh && mHighlightMaterial && !mHighlightQuadList.empty() )
512     {
513       MeshData::VertexContainer vertices;
514       Dali::MeshData::FaceIndices faceIndices;
515
516       std::vector<QuadCoordinates>::iterator iter = mHighlightQuadList.begin();
517       std::vector<QuadCoordinates>::iterator endIter = mHighlightQuadList.end();
518
519       // vertex position defaults to (0 0 0)
520       MeshData::Vertex vertex;
521       // set normal for all vertices as (0 0 1) pointing outward from TextInput Actor.
522       vertex.nZ = 1.0f;
523
524       for(std::size_t v = 0; iter != endIter; ++iter,v+=4 )
525       {
526         // Add each quad geometry (a sub-selection) to the mesh data.
527
528         // 0-----1
529         // |\    |
530         // | \ A |
531         // |  \  |
532         // | B \ |
533         // |    \|
534         // 2-----3
535
536         QuadCoordinates& quad = *iter;
537         // top-left (v+0)
538         vertex.x = quad.min.x;
539         vertex.y = quad.min.y;
540         vertices.push_back( vertex );
541
542         // top-right (v+1)
543         vertex.x = quad.max.x;
544         vertex.y = quad.min.y;
545         vertices.push_back( vertex );
546
547         // bottom-left (v+2)
548         vertex.x = quad.min.x;
549         vertex.y = quad.max.y;
550         vertices.push_back( vertex );
551
552         // bottom-right (v+3)
553         vertex.x = quad.max.x;
554         vertex.y = quad.max.y;
555         vertices.push_back( vertex );
556
557         // triangle A (3, 1, 0)
558         faceIndices.push_back( v + 3 );
559         faceIndices.push_back( v + 1 );
560         faceIndices.push_back( v );
561
562         // triangle B (0, 2, 3)
563         faceIndices.push_back( v );
564         faceIndices.push_back( v + 2 );
565         faceIndices.push_back( v + 3 );
566
567         mHighlightMeshData.SetFaceIndices( faceIndices );
568       }
569
570       BoneContainer bones(0); // passed empty as bones not required
571       mHighlightMeshData.SetData( vertices, faceIndices, bones, mHighlightMaterial );
572       mHighlightMesh.UpdateMeshData( mHighlightMeshData );
573     }
574   }
575
576   void OnTap( Actor actor, const TapGesture& tap )
577   {
578     if( actor == mGrabHandle )
579     {
580       // TODO
581     }
582   }
583
584   void OnPan( Actor actor, const PanGesture& gesture )
585   {
586     if( actor == mGrabArea )
587     {
588       if( Gesture::Started == gesture.state )
589       {
590         mGrabDisplacementX = mGrabDisplacementY = 0;
591       }
592
593       mGrabDisplacementX += gesture.displacement.x;
594       mGrabDisplacementY += gesture.displacement.y;
595
596       float x = mCursor[PRIMARY_CURSOR].x + mGrabDisplacementX;
597       float y = mCursor[PRIMARY_CURSOR].y + mCursor[PRIMARY_CURSOR].height*0.5f + mGrabDisplacementY;
598
599       if( Gesture::Started    == gesture.state ||
600           Gesture::Continuing == gesture.state )
601       {
602         mObserver.GrabHandleEvent( GRAB_HANDLE_PRESSED, x, y );
603       }
604       else if( Gesture::Finished  == gesture.state ||
605                Gesture::Cancelled == gesture.state )
606       {
607         mObserver.GrabHandleEvent( GRAB_HANDLE_RELEASED, x, y );
608       }
609     }
610   }
611
612   bool OnHandleOneTouched( Actor actor, const TouchEvent& touch )
613   {
614     // TODO
615     return false;
616   }
617
618   bool OnHandleTwoTouched( Actor actor, const TouchEvent& touch )
619   {
620     // TODO
621     return false;
622   }
623
624
625   Internal::Control& mTextControlParent;
626   Observer& mObserver;
627
628   Layer mActiveLayer; // Layer for active handles and alike that ensures they are above all else.
629
630   unsigned int mActiveCursor;
631   bool         mActiveGrabHandle;
632   bool         mActiveSelection;
633   bool         mActiveCopyPastePopup;
634
635   CursorImpl mCursor[CURSOR_COUNT];
636
637   Timer mCursorBlinkTimer; // Timer to signal cursor to blink
638   unsigned int mCursorBlinkInterval;
639   float mCursorBlinkDuration;
640   bool mCursorBlinkStatus; // Flag to switch between blink on and blink off
641
642   ImageActor mPrimaryCursor;
643   ImageActor mSecondaryCursor;
644
645   ImageActor mGrabHandle;
646   Actor mGrabArea;
647   float mGrabDisplacementX;
648   float mGrabDisplacementY;
649
650   SelectionHandleImpl mSelectionHandle[SELECTION_HANDLE_COUNT];
651
652   MeshActor         mHighlightMeshActor;        ///< Mesh Actor to display highlight
653   Mesh              mHighlightMesh;             ///< Mesh for highlight
654   MeshData          mHighlightMeshData;         ///< Mesh Data for highlight
655   Material          mHighlightMaterial;         ///< Material used for highlight
656   Vector4           mHighlightColor;            ///< Color of the highlight
657   QuadContainer     mHighlightQuadList;         ///< Sub-selections that combine to create the complete selection highlight
658
659   TextSelectionPopup mCopyPastePopup;
660
661   Image mCursorImage;
662   Image mGrabHandleImage;
663
664   TapGestureDetector mTapDetector;
665   PanGestureDetector mPanGestureDetector;
666
667   Rect<int> mBoundingBox;
668 };
669
670 DecoratorPtr Decorator::New( Internal::Control& parent, Observer& observer )
671 {
672   return DecoratorPtr( new Decorator(parent, observer) );
673 }
674
675 void Decorator::SetBoundingBox( const Rect<int>& boundingBox )
676 {
677   mImpl->mBoundingBox = boundingBox;
678 }
679
680 const Rect<int>& Decorator::GetBoundingBox() const
681 {
682   return mImpl->mBoundingBox;
683 }
684
685 void Decorator::Relayout( const Vector2& size, const Vector2& scrollPosition )
686 {
687   mImpl->Relayout( size, scrollPosition );
688 }
689
690 /** Cursor **/
691
692 void Decorator::SetActiveCursor( ActiveCursor activeCursor )
693 {
694   mImpl->mActiveCursor = activeCursor;
695 }
696
697 unsigned int Decorator::GetActiveCursor() const
698 {
699   return mImpl->mActiveCursor;
700 }
701
702 void Decorator::SetPosition( Cursor cursor, float x, float y, float height )
703 {
704   // Adjust grab handle displacement
705   mImpl->mGrabDisplacementX -= x - mImpl->mCursor[cursor].x;
706   mImpl->mGrabDisplacementY -= y - mImpl->mCursor[cursor].y;
707
708   mImpl->mCursor[cursor].x = x;
709   mImpl->mCursor[cursor].y = y;
710   mImpl->mCursor[cursor].height = height;
711 }
712
713 void Decorator::GetPosition( Cursor cursor, float& x, float& y, float& height ) const
714 {
715   x = mImpl->mCursor[cursor].x;
716   y = mImpl->mCursor[cursor].y;
717   height = mImpl->mCursor[cursor].height;
718 }
719
720 void Decorator::SetColor( Cursor cursor, const Dali::Vector4& color )
721 {
722   mImpl->mCursor[cursor].color = color;
723 }
724
725 const Dali::Vector4& Decorator::GetColor( Cursor cursor ) const
726 {
727   return mImpl->mCursor[cursor].color;
728 }
729
730 void Decorator::StartCursorBlink()
731 {
732   if ( !mImpl->mCursorBlinkTimer )
733   {
734     mImpl->mCursorBlinkTimer = Timer::New( mImpl->mCursorBlinkInterval );
735     mImpl->mCursorBlinkTimer.TickSignal().Connect( mImpl, &Decorator::Impl::OnCursorBlinkTimerTick );
736   }
737
738   if ( !mImpl->mCursorBlinkTimer.IsRunning() )
739   {
740     mImpl->mCursorBlinkTimer.Start();
741   }
742 }
743
744 void Decorator::StopCursorBlink()
745 {
746   if ( mImpl->mCursorBlinkTimer )
747   {
748     mImpl->mCursorBlinkTimer.Stop();
749   }
750 }
751
752 void Decorator::SetCursorBlinkInterval( float seconds )
753 {
754   mImpl->mCursorBlinkInterval = seconds*MILLISECONDS; // Convert to milliseconds
755 }
756
757 float Decorator::GetCursorBlinkInterval() const
758 {
759   return mImpl->mCursorBlinkInterval;
760 }
761
762 void Decorator::SetCursorBlinkDuration( float seconds )
763 {
764   mImpl->mCursorBlinkDuration = seconds;
765 }
766
767 float Decorator::GetCursorBlinkDuration() const
768 {
769   return mImpl->mCursorBlinkDuration;
770 }
771
772 /** GrabHandle **/
773
774 void Decorator::SetGrabHandleActive( bool active )
775 {
776   mImpl->mActiveGrabHandle = active;
777 }
778
779 bool Decorator::IsGrabHandleActive() const
780 {
781   return mImpl->mActiveGrabHandle;
782 }
783
784 void Decorator::SetGrabHandleImage( Dali::Image image )
785 {
786   mImpl->mGrabHandleImage = image;
787 }
788
789 Dali::Image Decorator::GetGrabHandleImage() const
790 {
791   return mImpl->mGrabHandleImage;
792 }
793
794 /** Selection **/
795
796 void Decorator::SetSelectionActive( bool active )
797 {
798   mImpl->mActiveSelection = active;
799 }
800
801 bool Decorator::IsSelectionActive() const
802 {
803   return mImpl->mActiveSelection;
804 }
805
806 void Decorator::SetPosition( SelectionHandle handle, float x, float y, float height )
807 {
808   mImpl->mSelectionHandle[handle].x = x;
809   mImpl->mSelectionHandle[handle].y = y;
810   mImpl->mSelectionHandle[handle].cursorHeight = height;
811 }
812
813 void Decorator::GetPosition( SelectionHandle handle, float& x, float& y, float& height ) const
814 {
815   x = mImpl->mSelectionHandle[handle].x;
816   y = mImpl->mSelectionHandle[handle].y;
817   height = mImpl->mSelectionHandle[handle].cursorHeight;
818 }
819
820 void Decorator::SetImage( SelectionHandle handle, SelectionHandleState state, Dali::Image image )
821 {
822   if( SELECTION_HANDLE_PRESSED == state )
823   {
824     mImpl->mSelectionHandle[handle].pressedImage = image;
825   }
826   else
827   {
828     mImpl->mSelectionHandle[handle].releasedImage = image;
829   }
830 }
831
832 Dali::Image Decorator::GetImage( SelectionHandle handle, SelectionHandleState state ) const
833 {
834   if( SELECTION_HANDLE_PRESSED == state )
835   {
836     return mImpl->mSelectionHandle[handle].pressedImage;
837   }
838
839   return mImpl->mSelectionHandle[handle].releasedImage;
840 }
841
842 void Decorator::AddHighlight( float x1, float y1, float x2, float y2 )
843 {
844   mImpl->mHighlightQuadList.push_back( QuadCoordinates(x1, y1, x2, y2) );
845 }
846
847 void Decorator::ClearHighlights()
848 {
849   mImpl->mHighlightQuadList.clear();
850 }
851
852 void Decorator::SetPopupActive( bool active )
853 {
854   mImpl->mActiveCopyPastePopup = active;
855 }
856
857 bool Decorator::IsPopupActive() const
858 {
859   return mImpl->mActiveCopyPastePopup ;
860 }
861
862 Decorator::~Decorator()
863 {
864   delete mImpl;
865 }
866
867 Decorator::Decorator( Dali::Toolkit::Internal::Control& parent, Observer& observer )
868 : mImpl( NULL )
869 {
870   mImpl = new Decorator::Impl( parent, observer );
871 }
872
873 } // namespace Text
874
875 } // namespace Toolkit
876
877 } // namespace Dali