Selection implementation.
[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/integration-api/debug.h>
23 #include <dali/public-api/actors/actor.h>
24 #include <dali/public-api/adaptor-framework/timer.h>
25 #include <dali/public-api/actors/image-actor.h>
26 #include <dali/public-api/actors/layer.h>
27 #include <dali/devel-api/actors/mesh-actor.h>
28 #include <dali/public-api/animation/constraint.h>
29 #include <dali/public-api/common/constants.h>
30 #include <dali/public-api/common/stage.h>
31 #include <dali/public-api/events/tap-gesture.h>
32 #include <dali/public-api/events/tap-gesture-detector.h>
33 #include <dali/public-api/events/touch-event.h>
34 #include <dali/public-api/events/pan-gesture.h>
35 #include <dali/public-api/events/pan-gesture-detector.h>
36 #include <dali/devel-api/geometry/mesh.h>
37 #include <dali/devel-api/geometry/mesh-data.h>
38 #include <dali/public-api/images/resource-image.h>
39 #include <dali/public-api/math/rect.h>
40 #include <dali/public-api/math/vector2.h>
41 #include <dali/public-api/math/vector4.h>
42 #include <dali/public-api/object/property-notification.h>
43 #include <dali/public-api/signals/connection-tracker.h>
44
45 // INTERNAL INCLUDES
46 #include <dali-toolkit/public-api/controls/control.h>
47 #include <dali-toolkit/public-api/controls/control-impl.h>
48 #include <dali-toolkit/public-api/controls/buttons/push-button.h>
49 #include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
50 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
51 #include <dali-toolkit/devel-api/controls/text-controls/text-selection-popup.h>
52
53 #ifdef DEBUG_ENABLED
54 #define DECORATOR_DEBUG
55
56 #endif
57
58 namespace Dali
59 {
60 namespace Internal
61 {
62 namespace
63 {
64 #ifdef DECORATOR_DEBUG
65 Integration::Log::Filter* gLogFilter( Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_TEXT_DECORATOR") );
66 #endif
67 }
68 }
69 }
70
71
72 // Local Data
73 namespace
74 {
75
76 const char* DEFAULT_GRAB_HANDLE_IMAGE_RELEASED( DALI_IMAGE_DIR "insertpoint-icon.png" );
77 const char* DEFAULT_GRAB_HANDLE_IMAGE_PRESSED( DALI_IMAGE_DIR "insertpoint-icon-pressed.png" );
78 const char* DEFAULT_SELECTION_HANDLE_ONE( DALI_IMAGE_DIR "text-input-selection-handle-left.png" );
79 const char* DEFAULT_SELECTION_HANDLE_TWO( DALI_IMAGE_DIR "text-input-selection-handle-right.png" );
80
81 const Dali::Vector3 DEFAULT_GRAB_HANDLE_RELATIVE_SIZE( 1.5f, 2.0f, 1.0f );
82 const Dali::Vector3 DEFAULT_SELECTION_HANDLE_RELATIVE_SIZE( 1.5f, 1.5f, 1.0f );
83
84 const Dali::Vector4 LIGHT_BLUE( (0xb2 / 255.0f), (0xeb / 255.0f), (0xf2 / 255.0f), 0.5f ); // The text highlight color.
85
86 const unsigned int CURSOR_BLINK_INTERVAL = 500u; // Cursor blink interval
87 const float TO_MILLISECONDS = 1000.f;
88 const float TO_SECONDS = 1.f / TO_MILLISECONDS;
89
90 const float DISPLAYED_HIGHLIGHT_Z_OFFSET( -0.05f );
91
92 const unsigned int SCROLL_TICK_INTERVAL = 50u;
93
94 const float SCROLL_THRESHOLD = 10.f;
95 const float SCROLL_SPEED = 300.f;
96 const float SCROLL_DISTANCE = SCROLL_SPEED * SCROLL_TICK_INTERVAL * TO_SECONDS;
97
98 /**
99  * structure to hold coordinates of each quad, which will make up the mesh.
100  */
101 struct QuadCoordinates
102 {
103   /**
104    * Default constructor
105    */
106   QuadCoordinates()
107   {
108   }
109
110   /**
111    * Constructor
112    * @param[in] x1 left co-ordinate
113    * @param[in] y1 top co-ordinate
114    * @param[in] x2 right co-ordinate
115    * @param[in] y2 bottom co-ordinate
116    */
117   QuadCoordinates(float x1, float y1, float x2, float y2)
118   : min(x1, y1),
119     max(x2, y2)
120   {
121   }
122
123   Dali::Vector2 min;                          ///< top-left (minimum) position of quad
124   Dali::Vector2 max;                          ///< bottom-right (maximum) position of quad
125 };
126
127 typedef std::vector<QuadCoordinates> QuadContainer;
128
129 /**
130  * @brief Takes a bounding rectangle in the local coordinates of an actor and returns the world coordinates Bounding Box.
131  * @param[in] boundingRectangle local bounding
132  * @param[out] Vector4 World coordinate bounding Box.
133  */
134 void LocalToWorldCoordinatesBoundingBox( const Dali::Rect<int>& boundingRectangle, Dali::Vector4& boundingBox )
135 {
136   // Convert to world coordinates and store as a Vector4 to be compatible with Property Notifications.
137   Dali::Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
138
139   const float originX = boundingRectangle.x - 0.5f * stageSize.width;
140   const float originY = boundingRectangle.y - 0.5f * stageSize.height;
141
142   boundingBox = Dali::Vector4( originX,
143                                originY,
144                                originX + boundingRectangle.width,
145                                originY + boundingRectangle.height );
146 }
147
148
149 } // end of namespace
150
151 namespace Dali
152 {
153
154 namespace Toolkit
155 {
156
157 namespace Text
158 {
159
160 struct Decorator::Impl : public ConnectionTracker
161 {
162   enum ScrollDirection
163   {
164     SCROLL_NONE,
165     SCROLL_RIGHT,
166     SCROLL_LEFT,
167     SCROLL_TOP,
168     SCROLL_BOTTOM
169   };
170
171   struct CursorImpl
172   {
173     CursorImpl()
174     : color( Dali::Color::BLACK ),
175       position(),
176       cursorHeight( 0.0f ),
177       lineHeight( 0.0f )
178     {
179     }
180
181     Vector4 color;
182     Vector2 position;
183     float cursorHeight;
184     float lineHeight;
185   };
186
187   struct HandleImpl
188   {
189     HandleImpl()
190     : position(),
191       lineHeight( 0.0f ),
192       grabDisplacementX( 0.f ),
193       grabDisplacementY( 0.f ),
194       active( false ),
195       visible( false ),
196       flipped( false )
197     {
198     }
199
200     ImageActor actor;
201     Actor grabArea;
202
203     Vector2 position;
204     float lineHeight; ///< Not the handle height
205     float grabDisplacementX;
206     float grabDisplacementY;
207     bool active  : 1;
208     bool visible : 1;
209     bool flipped : 1;
210   };
211
212   Impl( ControllerInterface& controller )
213   : mController( controller ),
214     mBoundingBox( Rect<int>() ),
215     mHighlightColor( LIGHT_BLUE ),
216     mActiveCursor( ACTIVE_CURSOR_NONE ),
217     mCursorBlinkInterval( CURSOR_BLINK_INTERVAL ),
218     mCursorBlinkDuration( 0.0f ),
219     mHandleScrolling( HANDLE_TYPE_COUNT ),
220     mScrollDirection( SCROLL_NONE ),
221     mScrollThreshold( SCROLL_THRESHOLD ),
222     mScrollSpeed( SCROLL_SPEED ),
223     mScrollDistance( SCROLL_DISTANCE ),
224     mActiveCopyPastePopup( false ),
225     mCursorBlinkStatus( true ),
226     mPrimaryCursorVisible( false ),
227     mSecondaryCursorVisible( false ),
228     mSwapSelectionHandles( false )
229   {
230   }
231
232   /**
233    * Relayout of the decorations owned by the decorator.
234    * @param[in] size The Size of the UI control the decorator is adding it's decorations to.
235    */
236   void Relayout( const Vector2& size )
237   {
238     // TODO - Remove this if nothing is active
239     CreateActiveLayer();
240
241     // Show or hide the cursors
242     CreateCursors();
243     if( mPrimaryCursor )
244     {
245       const CursorImpl& cursor = mCursor[PRIMARY_CURSOR];
246       mPrimaryCursorVisible = ( cursor.position.x <= size.width ) && ( cursor.position.x >= 0.f );
247       if( mPrimaryCursorVisible )
248       {
249         Vector2 position = cursor.position;
250         if( GRAB_HANDLE == mHandleScrolling )
251         {
252           if( mScrollDirection == SCROLL_RIGHT )
253           {
254             position.x = 0.f;
255           }
256           else
257           {
258             position.x = size.width;
259           }
260         }
261
262         mPrimaryCursor.SetPosition( position.x,
263                                     position.y );
264         mPrimaryCursor.SetSize( Size( 1.0f, cursor.cursorHeight ) );
265       }
266       mPrimaryCursor.SetVisible( mPrimaryCursorVisible );
267     }
268     if( mSecondaryCursor )
269     {
270       const CursorImpl& cursor = mCursor[SECONDARY_CURSOR];
271       mSecondaryCursorVisible = ( cursor.position.x <= size.width ) && ( cursor.position.x >= 0.f );
272       if( mSecondaryCursorVisible )
273       {
274         mSecondaryCursor.SetPosition( cursor.position.x,
275                                       cursor.position.y );
276         mSecondaryCursor.SetSize( Size( 1.0f, cursor.cursorHeight ) );
277       }
278       mSecondaryCursor.SetVisible( mSecondaryCursorVisible );
279     }
280
281     // Show or hide the grab handle
282     HandleImpl& grabHandle = mHandle[GRAB_HANDLE];
283     if( grabHandle.active )
284     {
285       Vector2 position = grabHandle.position;
286
287       if( GRAB_HANDLE == mHandleScrolling )
288       {
289         if( mScrollDirection == SCROLL_RIGHT )
290         {
291           position.x = 0.f;
292         }
293         else
294         {
295           position.x = size.width;
296         }
297       }
298
299       const bool isVisible = ( position.x <= size.width ) && ( position.x >= 0.f );
300
301       if( isVisible )
302       {
303         SetupTouchEvents();
304
305         CreateGrabHandle();
306
307         grabHandle.actor.SetPosition( position.x,
308                                       position.y + grabHandle.lineHeight );
309       }
310       grabHandle.actor.SetVisible( isVisible );
311     }
312     else if( grabHandle.actor )
313     {
314       UnparentAndReset( grabHandle.actor );
315     }
316
317     // Show or hide the selection handles/highlight
318     HandleImpl& primary = mHandle[ LEFT_SELECTION_HANDLE ];
319     HandleImpl& secondary = mHandle[ RIGHT_SELECTION_HANDLE ];
320     if( primary.active || secondary.active )
321     {
322       Vector2 primaryPosition = primary.position;
323       Vector2 secondaryPosition = secondary.position;
324
325       if( LEFT_SELECTION_HANDLE == mHandleScrolling )
326       {
327         if( mScrollDirection == SCROLL_RIGHT )
328         {
329           primaryPosition.x = 0.f;
330         }
331         else
332         {
333           primaryPosition.x = size.width;
334         }
335       }
336       else if( RIGHT_SELECTION_HANDLE == mHandleScrolling )
337       {
338         if( mScrollDirection == SCROLL_RIGHT )
339         {
340           secondaryPosition.x = 0.f;
341         }
342         else
343         {
344           secondaryPosition.x = size.width;
345         }
346       }
347
348       const bool isPrimaryVisible = ( primaryPosition.x <= size.width ) && ( primaryPosition.x >= 0.f );
349       const bool isSecondaryVisible = ( secondaryPosition.x <= size.width ) && ( secondaryPosition.x >= 0.f );
350
351       if( isPrimaryVisible || isSecondaryVisible )
352       {
353         SetupTouchEvents();
354
355         CreateSelectionHandles();
356
357         if( isPrimaryVisible )
358         {
359           primary.actor.SetPosition( primaryPosition.x,
360                                      primaryPosition.y + primary.lineHeight );
361
362           const bool flip = mSwapSelectionHandles ^ primary.flipped;
363           primary.actor.SetImage( flip ? mHandleImages[RIGHT_SELECTION_HANDLE][HANDLE_IMAGE_RELEASED] : mHandleImages[LEFT_SELECTION_HANDLE][HANDLE_IMAGE_RELEASED] );
364
365           primary.actor.SetAnchorPoint( flip ? AnchorPoint::TOP_LEFT : AnchorPoint::TOP_RIGHT );
366         }
367
368         if( isSecondaryVisible )
369         {
370           secondary.actor.SetPosition( secondaryPosition.x,
371                                        secondaryPosition.y + secondary.lineHeight );
372
373           const bool flip = mSwapSelectionHandles ^ secondary.flipped;
374
375           secondary.actor.SetImage( ( mSwapSelectionHandles ^ secondary.flipped ) ? mHandleImages[LEFT_SELECTION_HANDLE][HANDLE_IMAGE_RELEASED] : mHandleImages[RIGHT_SELECTION_HANDLE][HANDLE_IMAGE_RELEASED] );
376           secondary.actor.SetAnchorPoint( flip ? AnchorPoint::TOP_RIGHT : AnchorPoint::TOP_LEFT );
377         }
378       }
379       primary.actor.SetVisible( isPrimaryVisible );
380       secondary.actor.SetVisible( isSecondaryVisible );
381
382       CreateHighlight();
383       UpdateHighlight();
384     }
385     else
386     {
387       UnparentAndReset( primary.actor );
388       UnparentAndReset( secondary.actor );
389       UnparentAndReset( mHighlightMeshActor );
390     }
391
392     if ( mActiveCopyPastePopup )
393     {
394       if ( !mCopyPastePopup )
395       {
396         mCopyPastePopup = TextSelectionPopup::New();
397 #ifdef DECORATOR_DEBUG
398         mCopyPastePopup.SetName("mCopyPastePopup");
399 #endif
400         mCopyPastePopup.SetAnchorPoint( AnchorPoint::CENTER );
401         mCopyPastePopup.OnRelayoutSignal().Connect( this,  &Decorator::Impl::PopUpRelayoutComplete  ); // Position popup after size negotiation
402         mActiveLayer.Add ( mCopyPastePopup );
403       }
404     }
405     else
406     {
407      if ( mCopyPastePopup )
408      {
409        UnparentAndReset( mCopyPastePopup );
410      }
411     }
412   }
413
414   void UpdatePositions( const Vector2& scrollOffset )
415   {
416     mCursor[PRIMARY_CURSOR].position += scrollOffset;
417     mCursor[SECONDARY_CURSOR].position += scrollOffset;
418     mHandle[ GRAB_HANDLE ].position += scrollOffset;
419     mHandle[ LEFT_SELECTION_HANDLE ].position += scrollOffset;
420     mHandle[ RIGHT_SELECTION_HANDLE ].position += scrollOffset;
421     mHighlightPosition += scrollOffset;
422   }
423
424   void PopUpRelayoutComplete( Actor actor )
425   {
426     // Size negotiation for CopyPastePopup complete so can get the size and constrain position within bounding box.
427
428     mCopyPastePopup.OnRelayoutSignal().Disconnect( this, &Decorator::Impl::PopUpRelayoutComplete  );
429
430     Vector3 popupPosition( mCursor[PRIMARY_CURSOR].position.x, mCursor[PRIMARY_CURSOR].position.y -100.0f , 0.0f); //todo 100 to be an offset Property
431
432     Vector3 popupSize = Vector3( mCopyPastePopup.GetRelayoutSize( Dimension::WIDTH ), mCopyPastePopup.GetRelayoutSize( Dimension::HEIGHT ), 0.0f );
433
434     GetConstrainedPopupPosition( popupPosition, popupSize, AnchorPoint::CENTER, mActiveLayer, mBoundingBox );
435
436     SetUpPopUpPositionNotifications();
437
438     mCopyPastePopup.SetPosition( popupPosition ); //todo grabhandle(cursor) or selection handle positions to be used
439   }
440
441   void CreateCursor( ImageActor& cursor, const Vector4& color )
442   {
443     cursor = CreateSolidColorActor( color );
444     cursor.SetParentOrigin( ParentOrigin::TOP_LEFT ); // Need to set the default parent origin as CreateSolidColorActor() sets a different one.
445     cursor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
446   }
447
448   // Add or Remove cursor(s) from parent
449   void CreateCursors()
450   {
451     if( mActiveCursor == ACTIVE_CURSOR_NONE )
452     {
453       UnparentAndReset( mPrimaryCursor );
454       UnparentAndReset( mSecondaryCursor );
455     }
456     else
457     {
458       /* Create Primary and or Secondary Cursor(s) if active and add to parent */
459       if ( mActiveCursor == ACTIVE_CURSOR_PRIMARY ||
460            mActiveCursor == ACTIVE_CURSOR_BOTH )
461       {
462         if ( !mPrimaryCursor )
463         {
464           CreateCursor( mPrimaryCursor, mCursor[PRIMARY_CURSOR].color );
465 #ifdef DECORATOR_DEBUG
466           mPrimaryCursor.SetName( "PrimaryCursorActor" );
467 #endif
468           mActiveLayer.Add( mPrimaryCursor );
469         }
470       }
471
472       if ( mActiveCursor == ACTIVE_CURSOR_BOTH )
473       {
474         if ( !mSecondaryCursor )
475         {
476           CreateCursor( mSecondaryCursor, mCursor[SECONDARY_CURSOR].color );
477 #ifdef DECORATOR_DEBUG
478           mSecondaryCursor.SetName( "SecondaryCursorActor" );
479 #endif
480           mActiveLayer.Add( mSecondaryCursor );
481         }
482       }
483       else
484       {
485         UnparentAndReset( mSecondaryCursor );
486       }
487     }
488   }
489
490   bool OnCursorBlinkTimerTick()
491   {
492     // Cursor blinking
493     if ( mPrimaryCursor )
494     {
495       mPrimaryCursor.SetVisible( mPrimaryCursorVisible && mCursorBlinkStatus );
496     }
497     if ( mSecondaryCursor )
498     {
499       mSecondaryCursor.SetVisible( mSecondaryCursorVisible && mCursorBlinkStatus );
500     }
501
502     mCursorBlinkStatus = !mCursorBlinkStatus;
503
504     return true;
505   }
506
507   void SetupTouchEvents()
508   {
509     if ( !mTapDetector )
510     {
511       mTapDetector = TapGestureDetector::New();
512       mTapDetector.DetectedSignal().Connect( this, &Decorator::Impl::OnTap );
513     }
514
515     if ( !mPanGestureDetector )
516     {
517       mPanGestureDetector = PanGestureDetector::New();
518       mPanGestureDetector.DetectedSignal().Connect( this, &Decorator::Impl::OnPan );
519     }
520   }
521
522   void CreateActiveLayer()
523   {
524     if( !mActiveLayer )
525     {
526       mActiveLayer = Layer::New();
527 #ifdef DECORATOR_DEBUG
528       mActiveLayer.SetName ( "ActiveLayerActor" );
529 #endif
530
531       mActiveLayer.SetParentOrigin( ParentOrigin::CENTER );
532       mActiveLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
533       mActiveLayer.SetPositionInheritanceMode( USE_PARENT_POSITION );
534
535       // Add the active layer telling the controller it doesn't need clipping.
536       mController.AddDecoration( mActiveLayer, false );
537     }
538
539     mActiveLayer.RaiseToTop();
540   }
541
542   void CreateGrabHandle()
543   {
544     HandleImpl& grabHandle = mHandle[GRAB_HANDLE];
545     if( !grabHandle.actor )
546     {
547       if( !mHandleImages[GRAB_HANDLE][HANDLE_IMAGE_RELEASED] )
548       {
549         mHandleImages[GRAB_HANDLE][HANDLE_IMAGE_RELEASED] = ResourceImage::New( DEFAULT_GRAB_HANDLE_IMAGE_RELEASED );
550       }
551       if( !mHandleImages[GRAB_HANDLE][HANDLE_IMAGE_PRESSED] )
552       {
553         mHandleImages[GRAB_HANDLE][HANDLE_IMAGE_PRESSED] = ResourceImage::New( DEFAULT_GRAB_HANDLE_IMAGE_PRESSED );
554       }
555
556       grabHandle.actor = ImageActor::New( mHandleImages[GRAB_HANDLE][HANDLE_IMAGE_RELEASED] );
557       grabHandle.actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
558       grabHandle.actor.SetDrawMode( DrawMode::OVERLAY );
559       // Area that Grab handle responds to, larger than actual handle so easier to move
560 #ifdef DECORATOR_DEBUG
561       grabHandle.actor.SetName( "GrabHandleActor" );
562       if ( Dali::Internal::gLogFilter->IsEnabledFor( Debug::Verbose ) )
563       {
564         grabHandle.grabArea = Toolkit::CreateSolidColorActor( Vector4(0.0f, 0.0f, 0.0f, 0.0f), true, Color::RED, 1 );
565         grabHandle.grabArea.SetName( "GrabArea" );
566       }
567       else
568       {
569         grabHandle.grabArea = Actor::New();
570         grabHandle.grabArea.SetName( "GrabArea" );
571       }
572 #else
573       grabHandle.grabArea = Actor::New();
574 #endif
575
576       grabHandle.grabArea.SetParentOrigin( ParentOrigin::TOP_CENTER );
577       grabHandle.grabArea.SetAnchorPoint( AnchorPoint::TOP_CENTER );
578       grabHandle.grabArea.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
579       grabHandle.grabArea.SetSizeModeFactor( DEFAULT_GRAB_HANDLE_RELATIVE_SIZE );
580       grabHandle.actor.Add( grabHandle.grabArea );
581
582       grabHandle.grabArea.TouchedSignal().Connect( this, &Decorator::Impl::OnGrabHandleTouched );
583       mTapDetector.Attach( grabHandle.grabArea );
584       mPanGestureDetector.Attach( grabHandle.grabArea );
585
586       mActiveLayer.Add( grabHandle.actor );
587     }
588   }
589
590   void CreateSelectionHandles()
591   {
592     HandleImpl& primary = mHandle[ LEFT_SELECTION_HANDLE ];
593     if( !primary.actor )
594     {
595       if( !mHandleImages[LEFT_SELECTION_HANDLE][HANDLE_IMAGE_RELEASED] )
596       {
597         mHandleImages[LEFT_SELECTION_HANDLE][HANDLE_IMAGE_RELEASED] = ResourceImage::New( DEFAULT_SELECTION_HANDLE_ONE );
598       }
599
600       primary.actor = ImageActor::New( mHandleImages[LEFT_SELECTION_HANDLE][HANDLE_IMAGE_RELEASED] );
601 #ifdef DECORATOR_DEBUG
602       primary.actor.SetName("SelectionHandleOne");
603 #endif
604       primary.actor.SetAnchorPoint( AnchorPoint::TOP_RIGHT ); // Change to BOTTOM_RIGHT if Look'n'Feel requires handle above text.
605       primary.actor.SetDrawMode( DrawMode::OVERLAY ); // ensure grab handle above text
606       primary.flipped = false;
607
608       primary.grabArea = Actor::New(); // Area that Grab handle responds to, larger than actual handle so easier to move
609 #ifdef DECORATOR_DEBUG
610       primary.grabArea.SetName("SelectionHandleOneGrabArea");
611 #endif
612       primary.grabArea.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
613       primary.grabArea.SetSizeModeFactor( DEFAULT_SELECTION_HANDLE_RELATIVE_SIZE );
614       primary.grabArea.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION );
615
616       mTapDetector.Attach( primary.grabArea );
617       mPanGestureDetector.Attach( primary.grabArea );
618       primary.grabArea.TouchedSignal().Connect( this, &Decorator::Impl::OnHandleOneTouched );
619
620       primary.actor.Add( primary.grabArea );
621       mActiveLayer.Add( primary.actor );
622     }
623
624     HandleImpl& secondary = mHandle[ RIGHT_SELECTION_HANDLE ];
625     if( !secondary.actor )
626     {
627       if( !mHandleImages[RIGHT_SELECTION_HANDLE][HANDLE_IMAGE_RELEASED] )
628       {
629         mHandleImages[RIGHT_SELECTION_HANDLE][HANDLE_IMAGE_RELEASED] = ResourceImage::New( DEFAULT_SELECTION_HANDLE_TWO );
630       }
631
632       secondary.actor = ImageActor::New( mHandleImages[RIGHT_SELECTION_HANDLE][HANDLE_IMAGE_RELEASED] );
633 #ifdef DECORATOR_DEBUG
634       secondary.actor.SetName("SelectionHandleTwo");
635 #endif
636       secondary.actor.SetAnchorPoint( AnchorPoint::TOP_LEFT ); // Change to BOTTOM_LEFT if Look'n'Feel requires handle above text.
637       secondary.actor.SetDrawMode( DrawMode::OVERLAY ); // ensure grab handle above text
638       secondary.flipped = false;
639
640       secondary.grabArea = Actor::New(); // Area that Grab handle responds to, larger than actual handle so easier to move
641 #ifdef DECORATOR_DEBUG
642       secondary.grabArea.SetName("SelectionHandleTwoGrabArea");
643 #endif
644       secondary.grabArea.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
645       secondary.grabArea.SetSizeModeFactor( DEFAULT_SELECTION_HANDLE_RELATIVE_SIZE );
646       secondary.grabArea.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION );
647
648       mTapDetector.Attach( secondary.grabArea );
649       mPanGestureDetector.Attach( secondary.grabArea );
650       secondary.grabArea.TouchedSignal().Connect( this, &Decorator::Impl::OnHandleTwoTouched );
651
652       secondary.actor.Add( secondary.grabArea );
653       mActiveLayer.Add( secondary.actor );
654     }
655   }
656
657   void CreateHighlight()
658   {
659     if ( !mHighlightMeshActor )
660     {
661       mHighlightMaterial = Material::New( "HighlightMaterial" );
662       mHighlightMaterial.SetDiffuseColor( mHighlightColor );
663
664       mHighlightMeshData.SetMaterial( mHighlightMaterial );
665       mHighlightMeshData.SetHasNormals( true );
666
667       mHighlightMesh = Mesh::New( mHighlightMeshData );
668
669       mHighlightMeshActor = MeshActor::New( mHighlightMesh );
670 #ifdef DECORATOR_DEBUG
671       mHighlightMeshActor.SetName( "HighlightMeshActor" );
672 #endif
673       mHighlightMeshActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
674
675       // Add the highlight box telling the controller it needs clipping.
676       mController.AddDecoration( mHighlightMeshActor, true );
677     }
678
679     mHighlightMeshActor.SetPosition( mHighlightPosition.x, mHighlightPosition.y, DISPLAYED_HIGHLIGHT_Z_OFFSET );
680   }
681
682   void UpdateHighlight()
683   {
684     //  Construct a Mesh with a texture to be used as the highlight 'box' for selected text
685     //
686     //  Example scenarios where mesh is made from 3, 1, 2, 2 ,3 or 3 quads.
687     //
688     //   [ TOP   ]  [ TOP ]      [TOP ]  [ TOP    ]      [ TOP  ]      [ TOP  ]
689     //  [ MIDDLE ]             [BOTTOM]  [BOTTOM]      [ MIDDLE ]   [ MIDDLE  ]
690     //  [ BOTTOM]                                      [ MIDDLE ]   [ MIDDLE  ]
691     //                                                 [BOTTOM]     [ MIDDLE  ]
692     //                                                              [BOTTOM]
693     //
694     //  Each quad is created as 2 triangles.
695     //  Middle is just 1 quad regardless of its size.
696     //
697     //  (0,0)         (0,0)
698     //     0*    *2     0*       *2
699     //     TOP          TOP
700     //     3*    *1     3*       *1
701     //  4*       *1     4*     *6
702     //     MIDDLE         BOTTOM
703     //  6*       *5     7*     *5
704     //  6*    *8
705     //   BOTTOM
706     //  9*    *7
707     //
708
709     if ( mHighlightMesh && mHighlightMaterial && !mHighlightQuadList.empty() )
710     {
711       MeshData::VertexContainer vertices;
712       Dali::MeshData::FaceIndices faceIndices;
713
714       std::vector<QuadCoordinates>::iterator iter = mHighlightQuadList.begin();
715       std::vector<QuadCoordinates>::iterator endIter = mHighlightQuadList.end();
716
717       // vertex position defaults to (0 0 0)
718       MeshData::Vertex vertex;
719       // set normal for all vertices as (0 0 1) pointing outward from TextInput Actor.
720       vertex.nZ = 1.0f;
721
722       for(std::size_t v = 0; iter != endIter; ++iter,v+=4 )
723       {
724         // Add each quad geometry (a sub-selection) to the mesh data.
725
726         // 0-----1
727         // |\    |
728         // | \ A |
729         // |  \  |
730         // | B \ |
731         // |    \|
732         // 2-----3
733
734         QuadCoordinates& quad = *iter;
735         // top-left (v+0)
736         vertex.x = quad.min.x;
737         vertex.y = quad.min.y;
738         vertices.push_back( vertex );
739
740         // top-right (v+1)
741         vertex.x = quad.max.x;
742         vertex.y = quad.min.y;
743         vertices.push_back( vertex );
744
745         // bottom-left (v+2)
746         vertex.x = quad.min.x;
747         vertex.y = quad.max.y;
748         vertices.push_back( vertex );
749
750         // bottom-right (v+3)
751         vertex.x = quad.max.x;
752         vertex.y = quad.max.y;
753         vertices.push_back( vertex );
754
755         // triangle A (3, 1, 0)
756         faceIndices.push_back( v + 3 );
757         faceIndices.push_back( v + 1 );
758         faceIndices.push_back( v );
759
760         // triangle B (0, 2, 3)
761         faceIndices.push_back( v );
762         faceIndices.push_back( v + 2 );
763         faceIndices.push_back( v + 3 );
764
765         mHighlightMeshData.SetFaceIndices( faceIndices );
766       }
767
768       BoneContainer bones(0); // passed empty as bones not required
769       mHighlightMeshData.SetData( vertices, faceIndices, bones, mHighlightMaterial );
770       mHighlightMesh.UpdateMeshData( mHighlightMeshData );
771     }
772   }
773
774   void OnTap( Actor actor, const TapGesture& tap )
775   {
776     if( actor == mHandle[GRAB_HANDLE].actor )
777     {
778       // TODO
779     }
780   }
781
782   void DoPan( HandleImpl& handle, HandleType type, const PanGesture& gesture )
783   {
784     if( Gesture::Started == gesture.state )
785     {
786       handle.grabDisplacementX = handle.grabDisplacementY = 0;
787     }
788
789     handle.grabDisplacementX += gesture.displacement.x;
790     handle.grabDisplacementY += gesture.displacement.y;
791
792     const float x = handle.position.x + handle.grabDisplacementX;
793     const float y = handle.position.y + handle.lineHeight*0.5f + handle.grabDisplacementY;
794
795     if( Gesture::Started    == gesture.state ||
796         Gesture::Continuing == gesture.state )
797     {
798       Vector2 targetSize;
799       mController.GetTargetSize( targetSize );
800
801       if( x < mScrollThreshold )
802       {
803         mScrollDirection = SCROLL_RIGHT;
804         mHandleScrolling = type;
805         StartScrollTimer();
806       }
807       else if( x > targetSize.width - mScrollThreshold )
808       {
809         mScrollDirection = SCROLL_LEFT;
810         mHandleScrolling = type;
811         StartScrollTimer();
812       }
813       else
814       {
815         mHandleScrolling = HANDLE_TYPE_COUNT;
816         StopScrollTimer();
817         mController.DecorationEvent( type, HANDLE_PRESSED, x, y );
818       }
819     }
820     else if( Gesture::Finished  == gesture.state ||
821              Gesture::Cancelled == gesture.state )
822     {
823       if( mScrollTimer && mScrollTimer.IsRunning() )
824       {
825         mHandleScrolling = HANDLE_TYPE_COUNT;
826         StopScrollTimer();
827         mController.DecorationEvent( type, HANDLE_STOP_SCROLLING, x, y );
828       }
829       else
830       {
831         mController.DecorationEvent( type, HANDLE_RELEASED, x, y );
832       }
833       handle.actor.SetImage( mHandleImages[type][HANDLE_IMAGE_RELEASED] );
834     }
835   }
836
837   void OnPan( Actor actor, const PanGesture& gesture )
838   {
839     HandleImpl& grabHandle = mHandle[GRAB_HANDLE];
840     HandleImpl& primarySelectionHandle = mHandle[LEFT_SELECTION_HANDLE];
841     HandleImpl& secondarySelectionHandle = mHandle[RIGHT_SELECTION_HANDLE];
842
843     if( actor == grabHandle.grabArea )
844     {
845       DoPan( grabHandle, GRAB_HANDLE, gesture );
846     }
847     else if( actor == primarySelectionHandle.grabArea )
848     {
849       DoPan( primarySelectionHandle, LEFT_SELECTION_HANDLE, gesture );
850     }
851     else if( actor == secondarySelectionHandle.grabArea )
852     {
853       DoPan( secondarySelectionHandle, RIGHT_SELECTION_HANDLE, gesture );
854     }
855   }
856
857   bool OnGrabHandleTouched( Actor actor, const TouchEvent& event )
858   {
859     // Switch between pressed/release grab-handle images
860     if( event.GetPointCount() > 0 &&
861         mHandle[GRAB_HANDLE].actor )
862     {
863       const TouchPoint& point = event.GetPoint(0);
864
865       if( TouchPoint::Down == point.state &&
866           mHandleImages[GRAB_HANDLE][HANDLE_IMAGE_PRESSED] )
867       {
868         mHandle[GRAB_HANDLE].actor.SetImage( mHandleImages[GRAB_HANDLE][HANDLE_IMAGE_PRESSED] );
869       }
870       else if( TouchPoint::Up == point.state &&
871                mHandleImages[GRAB_HANDLE][HANDLE_IMAGE_RELEASED] )
872       {
873         mHandle[GRAB_HANDLE].actor.SetImage( mHandleImages[GRAB_HANDLE][HANDLE_IMAGE_RELEASED] );
874       }
875     }
876
877     // Consume to avoid pop-ups accidentally closing, when handle is outside of pop-up area
878     return true;
879   }
880
881   bool OnHandleOneTouched( Actor actor, const TouchEvent& touch )
882   {
883     // TODO
884     // Consume to avoid pop-ups accidentally closing, when handle is outside of pop-up area
885     return true;
886   }
887
888   bool OnHandleTwoTouched( Actor actor, const TouchEvent& touch )
889   {
890     // TODO
891     // Consume to avoid pop-ups accidentally closing, when handle is outside of pop-up area
892     return true;
893   }
894
895   // Popup
896
897   float AlternatePopUpPositionRelativeToCursor()
898   {
899     float alternativePosition=0.0f;;
900
901     if ( mPrimaryCursor ) // Secondary cursor not used for paste
902     {
903       Cursor cursor = PRIMARY_CURSOR;
904       alternativePosition = mCursor[cursor].position.y;
905     }
906
907     const float popupHeight = 120.0f; // todo Set as a MaxSize Property in Control or retrieve from CopyPastePopup class.
908
909     if( mHandle[GRAB_HANDLE].active )
910     {
911       // If grab handle enabled then position pop-up below the grab handle.
912       const Vector2 grabHandleSize( 59.0f, 56.0f ); // todo
913       const float BOTTOM_HANDLE_BOTTOM_OFFSET = 1.5; //todo Should be a property
914       alternativePosition +=  grabHandleSize.height  + popupHeight + BOTTOM_HANDLE_BOTTOM_OFFSET ;
915     }
916     else
917     {
918       alternativePosition += popupHeight;
919     }
920
921     return alternativePosition;
922   }
923
924   void PopUpLeavesVerticalBoundary( PropertyNotification& source )
925   {
926     float alternativeYPosition=0.0f;
927     // todo use AlternatePopUpPositionRelativeToSelectionHandles() if text is highlighted
928     // if can't be positioned above, then position below row.
929     alternativeYPosition = AlternatePopUpPositionRelativeToCursor();
930
931     mCopyPastePopup.SetY( alternativeYPosition );
932   }
933
934
935   void SetUpPopUpPositionNotifications( )
936   {
937     // Note Property notifications ignore any set anchor point so conditions must allow for this.  Default is Top Left.
938
939     // Exceeding vertical boundary
940
941     Vector4 worldCoordinatesBoundingBox;
942     LocalToWorldCoordinatesBoundingBox( mBoundingBox, worldCoordinatesBoundingBox );
943
944     float popupHeight = mCopyPastePopup.GetRelayoutSize( Dimension::HEIGHT);
945
946     PropertyNotification verticalExceedNotification = mCopyPastePopup.AddPropertyNotification( Actor::Property::WORLD_POSITION_Y,
947                                                       OutsideCondition( worldCoordinatesBoundingBox.y + popupHeight/2,
948                                                                         worldCoordinatesBoundingBox.w - popupHeight/2 ) );
949
950     verticalExceedNotification.NotifySignal().Connect( this, &Decorator::Impl::PopUpLeavesVerticalBoundary );
951   }
952
953   void GetConstrainedPopupPosition( Vector3& requiredPopupPosition, Vector3& popupSize, Vector3 anchorPoint, Actor& parent, Rect<int>& boundingBox )
954   {
955     DALI_ASSERT_DEBUG ( "Popup parent not on stage" && parent.OnStage() )
956
957     // Parent must already by added to Stage for these Get calls to work
958     Vector3 parentAnchorPoint = parent.GetCurrentAnchorPoint();
959     Vector3 parentWorldPositionLeftAnchor = parent.GetCurrentWorldPosition() - parent.GetCurrentSize()*parentAnchorPoint;
960     Vector3 popupWorldPosition = parentWorldPositionLeftAnchor + requiredPopupPosition;  // Parent World position plus popup local position gives World Position
961     Vector3 popupDistanceFromAnchorPoint = popupSize*anchorPoint;
962
963     // Bounding rectangle is supplied as screen coordinates, bounding will be done in world coordinates.
964     Vector4 boundingRectangleWorld;
965     LocalToWorldCoordinatesBoundingBox( boundingBox, boundingRectangleWorld );
966
967     // Calculate distance to move popup (in local space) so fits within the boundary
968     float xOffSetToKeepWithinBounds = 0.0f;
969     if( popupWorldPosition.x - popupDistanceFromAnchorPoint.x < boundingRectangleWorld.x )
970     {
971       xOffSetToKeepWithinBounds = boundingRectangleWorld.x - ( popupWorldPosition.x - popupDistanceFromAnchorPoint.x );
972     }
973     else if ( popupWorldPosition.x +  popupDistanceFromAnchorPoint.x > boundingRectangleWorld.z )
974     {
975       xOffSetToKeepWithinBounds = boundingRectangleWorld.z - ( popupWorldPosition.x +  popupDistanceFromAnchorPoint.x );
976     }
977
978     // Ensure initial display of Popup is in alternative position if can not fit above. As Property notification will be a frame behind.
979     if ( popupWorldPosition.y - popupDistanceFromAnchorPoint.y < boundingRectangleWorld.y )
980     {
981       requiredPopupPosition.y = AlternatePopUpPositionRelativeToCursor();
982     }
983
984     requiredPopupPosition.x = requiredPopupPosition.x + xOffSetToKeepWithinBounds;
985   }
986
987   void SetScrollThreshold( float threshold )
988   {
989     mScrollThreshold = threshold;
990   }
991
992   float GetScrollThreshold() const
993   {
994     return mScrollThreshold;
995   }
996
997   void SetScrollSpeed( float speed )
998   {
999     mScrollSpeed = speed;
1000     mScrollDistance = speed * SCROLL_TICK_INTERVAL * TO_SECONDS;
1001   }
1002
1003   float GetScrollSpeed() const
1004   {
1005     return mScrollSpeed;
1006   }
1007
1008   /**
1009    * Creates and starts a timer to scroll the text when handles are close to the edges of the text.
1010    *
1011    * It only starts the timer if it's already created.
1012    */
1013   void StartScrollTimer()
1014   {
1015     if( !mScrollTimer )
1016     {
1017       mScrollTimer = Timer::New( SCROLL_TICK_INTERVAL );
1018       mScrollTimer.TickSignal().Connect( this, &Decorator::Impl::OnScrollTimerTick );
1019     }
1020
1021     if( !mScrollTimer.IsRunning() )
1022     {
1023       mScrollTimer.Start();
1024     }
1025   }
1026
1027   /**
1028    * Stops the timer used to scroll the text.
1029    */
1030   void StopScrollTimer()
1031   {
1032     if( mScrollTimer )
1033     {
1034       mScrollTimer.Stop();
1035     }
1036   }
1037
1038   /**
1039    * Callback called by the timer used to scroll the text.
1040    *
1041    * It calculates and sets a new scroll position.
1042    */
1043   bool OnScrollTimerTick()
1044   {
1045     if( HANDLE_TYPE_COUNT != mHandleScrolling )
1046     {
1047       mController.DecorationEvent( mHandleScrolling,
1048                                    HANDLE_SCROLLING,
1049                                    mScrollDirection == SCROLL_RIGHT ? mScrollDistance : -mScrollDistance,
1050                                    0.f );
1051     }
1052
1053     return true;
1054   }
1055
1056   ControllerInterface& mController;
1057
1058   TapGestureDetector  mTapDetector;
1059   PanGestureDetector  mPanGestureDetector;
1060   Timer               mCursorBlinkTimer;          ///< Timer to signal cursor to blink
1061   Timer               mScrollTimer;               ///< Timer used to scroll the text when the grab handle is moved close to the edges.
1062
1063   Layer               mActiveLayer;               ///< Layer for active handles and alike that ensures they are above all else.
1064   ImageActor          mPrimaryCursor;
1065   ImageActor          mSecondaryCursor;
1066   MeshActor           mHighlightMeshActor;        ///< Mesh Actor to display highlight
1067   TextSelectionPopup  mCopyPastePopup;
1068
1069   Image               mHandleImages[HANDLE_TYPE_COUNT][HANDLE_IMAGE_TYPE_COUNT];
1070   Image               mCursorImage;
1071   Mesh                mHighlightMesh;             ///< Mesh for highlight
1072   MeshData            mHighlightMeshData;         ///< Mesh Data for highlight
1073   Material            mHighlightMaterial;         ///< Material used for highlight
1074
1075   CursorImpl          mCursor[CURSOR_COUNT];
1076   HandleImpl          mHandle[HANDLE_TYPE_COUNT];
1077   QuadContainer       mHighlightQuadList;         ///< Sub-selections that combine to create the complete selection highlight
1078   Vector2             mHighlightPosition;         ///< The position of the highlight actor.
1079
1080   Rect<int>           mBoundingBox;
1081   Vector4             mHighlightColor;            ///< Color of the highlight
1082
1083   unsigned int        mActiveCursor;
1084   unsigned int        mCursorBlinkInterval;
1085   float               mCursorBlinkDuration;
1086   HandleType          mHandleScrolling;         ///< The handle which is scrolling.
1087   ScrollDirection     mScrollDirection;         ///< The direction of the scroll.
1088   float               mScrollThreshold;         ///< Defines a square area inside the control, close to the edge. A cursor entering this area will trigger scroll events.
1089   float               mScrollSpeed;             ///< The scroll speed in pixels per second.
1090   float               mScrollDistance;          ///< Distance the text scrolls during a scroll interval.
1091   unsigned int        mScrollInterval;          ///< Time in milliseconds of a scroll interval.
1092
1093   bool                mActiveCopyPastePopup   : 1;
1094   bool                mCursorBlinkStatus      : 1; ///< Flag to switch between blink on and blink off.
1095   bool                mPrimaryCursorVisible   : 1; ///< Whether the primary cursor is visible.
1096   bool                mSecondaryCursorVisible : 1; ///< Whether the secondary cursor is visible.
1097   bool                mSwapSelectionHandles   : 1; ///< Whether to swap the selection handle images.
1098 };
1099
1100 DecoratorPtr Decorator::New( ControllerInterface& controller )
1101 {
1102   return DecoratorPtr( new Decorator(controller) );
1103 }
1104
1105 void Decorator::SetBoundingBox( const Rect<int>& boundingBox )
1106 {
1107   mImpl->mBoundingBox = boundingBox;
1108 }
1109
1110 const Rect<int>& Decorator::GetBoundingBox() const
1111 {
1112   return mImpl->mBoundingBox;
1113 }
1114
1115 void Decorator::Relayout( const Vector2& size )
1116 {
1117   mImpl->Relayout( size );
1118 }
1119
1120 void Decorator::UpdatePositions( const Vector2& scrollOffset )
1121 {
1122   mImpl->UpdatePositions( scrollOffset );
1123 }
1124
1125 /** Cursor **/
1126
1127 void Decorator::SetActiveCursor( ActiveCursor activeCursor )
1128 {
1129   mImpl->mActiveCursor = activeCursor;
1130 }
1131
1132 unsigned int Decorator::GetActiveCursor() const
1133 {
1134   return mImpl->mActiveCursor;
1135 }
1136
1137 void Decorator::SetPosition( Cursor cursor, float x, float y, float cursorHeight, float lineHeight )
1138 {
1139   mImpl->mCursor[cursor].position.x = x;
1140   mImpl->mCursor[cursor].position.y = y;
1141   mImpl->mCursor[cursor].cursorHeight = cursorHeight;
1142   mImpl->mCursor[cursor].lineHeight = lineHeight;
1143 }
1144
1145 void Decorator::GetPosition( Cursor cursor, float& x, float& y, float& cursorHeight, float& lineHeight ) const
1146 {
1147   x = mImpl->mCursor[cursor].position.x;
1148   y = mImpl->mCursor[cursor].position.y;
1149   cursorHeight = mImpl->mCursor[cursor].cursorHeight;
1150   lineHeight = mImpl->mCursor[cursor].lineHeight;
1151 }
1152
1153 const Vector2& Decorator::GetPosition( Cursor cursor ) const
1154 {
1155   return mImpl->mCursor[cursor].position;
1156 }
1157
1158 void Decorator::SetColor( Cursor cursor, const Dali::Vector4& color )
1159 {
1160   mImpl->mCursor[cursor].color = color;
1161 }
1162
1163 const Dali::Vector4& Decorator::GetColor( Cursor cursor ) const
1164 {
1165   return mImpl->mCursor[cursor].color;
1166 }
1167
1168 void Decorator::StartCursorBlink()
1169 {
1170   if ( !mImpl->mCursorBlinkTimer )
1171   {
1172     mImpl->mCursorBlinkTimer = Timer::New( mImpl->mCursorBlinkInterval );
1173     mImpl->mCursorBlinkTimer.TickSignal().Connect( mImpl, &Decorator::Impl::OnCursorBlinkTimerTick );
1174   }
1175
1176   if ( !mImpl->mCursorBlinkTimer.IsRunning() )
1177   {
1178     mImpl->mCursorBlinkTimer.Start();
1179   }
1180 }
1181
1182 void Decorator::StopCursorBlink()
1183 {
1184   if ( mImpl->mCursorBlinkTimer )
1185   {
1186     mImpl->mCursorBlinkTimer.Stop();
1187   }
1188 }
1189
1190 void Decorator::SetCursorBlinkInterval( float seconds )
1191 {
1192   mImpl->mCursorBlinkInterval = static_cast<unsigned int>( seconds * TO_MILLISECONDS ); // Convert to milliseconds
1193 }
1194
1195 float Decorator::GetCursorBlinkInterval() const
1196 {
1197   return static_cast<float>( mImpl->mCursorBlinkInterval ) * TO_SECONDS;
1198 }
1199
1200 void Decorator::SetCursorBlinkDuration( float seconds )
1201 {
1202   mImpl->mCursorBlinkDuration = seconds;
1203 }
1204
1205 float Decorator::GetCursorBlinkDuration() const
1206 {
1207   return mImpl->mCursorBlinkDuration;
1208 }
1209
1210 /** Handles **/
1211
1212 void Decorator::SetHandleActive( HandleType handleType, bool active )
1213 {
1214   mImpl->mHandle[handleType].active = active;
1215 }
1216
1217 bool Decorator::IsHandleActive( HandleType handleType ) const
1218 {
1219   return mImpl->mHandle[handleType].active ;
1220 }
1221
1222 void Decorator::SetHandleImage( HandleType handleType, HandleImageType handleImageType, Dali::Image image )
1223 {
1224   mImpl->mHandleImages[handleType][handleImageType] = image;
1225 }
1226
1227 Dali::Image Decorator::GetHandleImage( HandleType handleType, HandleImageType handleImageType ) const
1228 {
1229   return mImpl->mHandleImages[handleType][handleImageType];
1230 }
1231
1232 void Decorator::SetPosition( HandleType handleType, float x, float y, float height )
1233 {
1234   // Adjust grab handle displacement
1235   Impl::HandleImpl& handle = mImpl->mHandle[handleType];
1236
1237   handle.grabDisplacementX -= x - handle.position.x;
1238   handle.grabDisplacementY -= y - handle.position.y;
1239
1240   handle.position.x = x;
1241   handle.position.y = y;
1242   handle.lineHeight = height;
1243 }
1244
1245 void Decorator::GetPosition( HandleType handleType, float& x, float& y, float& height ) const
1246 {
1247   Impl::HandleImpl& handle = mImpl->mHandle[handleType];
1248
1249   x = handle.position.x;
1250   y = handle.position.y;
1251   height = handle.lineHeight;
1252 }
1253
1254 const Vector2& Decorator::GetPosition( HandleType handleType ) const
1255 {
1256   return mImpl->mHandle[handleType].position;
1257 }
1258
1259 void Decorator::SwapSelectionHandlesEnabled( bool enable )
1260 {
1261   mImpl->mSwapSelectionHandles = enable;
1262 }
1263
1264 void Decorator::AddHighlight( float x1, float y1, float x2, float y2 )
1265 {
1266   mImpl->mHighlightQuadList.push_back( QuadCoordinates(x1, y1, x2, y2) );
1267 }
1268
1269 void Decorator::ClearHighlights()
1270 {
1271   mImpl->mHighlightQuadList.clear();
1272   mImpl->mHighlightPosition = Vector2::ZERO;
1273 }
1274
1275 void Decorator::SetHighlightColor( const Vector4& color )
1276 {
1277   mImpl->mHighlightColor = color;
1278 }
1279
1280 const Vector4& Decorator::GetHighlightColor() const
1281 {
1282   return mImpl->mHighlightColor;
1283 }
1284
1285 void Decorator::SetPopupActive( bool active )
1286 {
1287   mImpl->mActiveCopyPastePopup = active;
1288 }
1289
1290 bool Decorator::IsPopupActive() const
1291 {
1292   return mImpl->mActiveCopyPastePopup ;
1293 }
1294
1295 /** Scroll **/
1296
1297 void Decorator::SetScrollThreshold( float threshold )
1298 {
1299   mImpl->SetScrollThreshold( threshold );
1300 }
1301
1302 float Decorator::GetScrollThreshold() const
1303 {
1304   return mImpl->GetScrollThreshold();
1305 }
1306
1307 void Decorator::SetScrollSpeed( float speed )
1308 {
1309   mImpl->SetScrollSpeed( speed );
1310 }
1311
1312 float Decorator::GetScrollSpeed() const
1313 {
1314   return mImpl->GetScrollSpeed();
1315 }
1316
1317 Decorator::~Decorator()
1318 {
1319   delete mImpl;
1320 }
1321
1322 Decorator::Decorator( ControllerInterface& controller )
1323 : mImpl( NULL )
1324 {
1325   mImpl = new Decorator::Impl( controller );
1326 }
1327
1328 } // namespace Text
1329
1330 } // namespace Toolkit
1331
1332 } // namespace Dali