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