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