2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali-toolkit/internal/text/decorator/text-decorator.h>
22 #include <dali/integration-api/debug.h>
24 #include <dali/public-api/adaptor-framework/timer.h>
25 #include <dali/public-api/actors/layer.h>
26 #include <dali/public-api/common/stage.h>
27 #include <dali/public-api/events/touch-event.h>
28 #include <dali/public-api/events/pan-gesture.h>
29 #include <dali/public-api/images/resource-image.h>
30 #include <dali/public-api/object/property-notification.h>
32 #include <dali/devel-api/rendering/geometry.h>
33 #include <dali/devel-api/rendering/renderer.h>
36 #include <dali-toolkit/public-api/controls/control-depth-index-ranges.h>
37 #include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
40 #define DECORATOR_DEBUG
44 #define MAKE_SHADER(A)#A
48 const char* VERTEX_SHADER = MAKE_SHADER(
49 attribute mediump vec2 aPosition;
50 uniform mediump mat4 uMvpMatrix;
51 uniform mediump vec3 uSize;
55 mediump vec4 position = vec4( aPosition, 0.0, 1.0 );
56 position.xyz *= uSize;
57 gl_Position = uMvpMatrix * position;
61 const char* FRAGMENT_SHADER = MAKE_SHADER(
62 uniform lowp vec4 uColor;
66 gl_FragColor = uColor;
77 #ifdef DECORATOR_DEBUG
78 Integration::Log::Filter* gLogFilter( Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_TEXT_DECORATOR") );
89 const char* DEFAULT_GRAB_HANDLE_IMAGE_RELEASED( DALI_IMAGE_DIR "cursor_handler_center.png" );
91 const int DEFAULT_POPUP_OFFSET( -100.0f ); // Vertical offset of Popup from cursor or handles position.
93 const Dali::Vector3 DEFAULT_GRAB_HANDLE_RELATIVE_SIZE( 1.25f, 1.5f, 1.0f );
94 const Dali::Vector3 DEFAULT_SELECTION_HANDLE_RELATIVE_SIZE( 1.25f, 1.5f, 1.0f );
96 const Dali::Vector4 LIGHT_BLUE( 0.75f, 0.96f, 1.f, 1.f ); // The text highlight color. TODO: due some problems, maybe with the blending function in the text clipping, the color is fully opaque.
98 const Dali::Vector4 HANDLE_COLOR( 0.0f, (183.0f / 255.0f), (229.0f / 255.0f), 1.0f );
100 const unsigned int CURSOR_BLINK_INTERVAL = 500u; // Cursor blink interval
101 const float TO_MILLISECONDS = 1000.f;
102 const float TO_SECONDS = 1.f / TO_MILLISECONDS;
104 const unsigned int SCROLL_TICK_INTERVAL = 50u;
106 const float SCROLL_THRESHOLD = 10.f;
107 const float SCROLL_SPEED = 300.f;
108 const float SCROLL_DISTANCE = SCROLL_SPEED * SCROLL_TICK_INTERVAL * TO_SECONDS;
110 const float CURSOR_WIDTH = 1.f;
113 * structure to hold coordinates of each quad, which will make up the mesh.
115 struct QuadCoordinates
118 * Default constructor
126 * @param[in] x1 left co-ordinate
127 * @param[in] y1 top co-ordinate
128 * @param[in] x2 right co-ordinate
129 * @param[in] y2 bottom co-ordinate
131 QuadCoordinates(float x1, float y1, float x2, float y2)
137 Dali::Vector2 min; ///< top-left (minimum) position of quad
138 Dali::Vector2 max; ///< bottom-right (maximum) position of quad
141 typedef std::vector<QuadCoordinates> QuadContainer;
144 * @brief Takes a bounding rectangle in the local coordinates of an actor and returns the world coordinates Bounding Box.
145 * @param[in] boundingRectangle local bounding
146 * @param[out] Vector4 World coordinate bounding Box.
148 void LocalToWorldCoordinatesBoundingBox( const Dali::Rect<int>& boundingRectangle, Dali::Vector4& boundingBox )
150 // Convert to world coordinates and store as a Vector4 to be compatible with Property Notifications.
151 Dali::Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
153 const float originX = boundingRectangle.x - 0.5f * stageSize.width;
154 const float originY = boundingRectangle.y - 0.5f * stageSize.height;
156 boundingBox = Dali::Vector4( originX,
158 originX + boundingRectangle.width,
159 originY + boundingRectangle.height );
163 } // end of namespace
174 struct Decorator::Impl : public ConnectionTracker
188 : color( Dali::Color::BLACK ),
190 cursorHeight( 0.0f ),
206 grabDisplacementX( 0.f ),
207 grabDisplacementY( 0.f ),
217 ImageActor markerActor;
220 float lineHeight; ///< Not the handle height
221 float grabDisplacementX;
222 float grabDisplacementY;
233 offset( DEFAULT_POPUP_OFFSET )
237 TextSelectionPopup actor;
242 Impl( ControllerInterface& controller,
243 TextSelectionPopupCallbackInterface& callbackInterface )
244 : mController( controller ),
245 mEnabledPopupButtons( TextSelectionPopup::NONE ),
246 mTextSelectionPopupCallbackInterface( callbackInterface ),
247 mHandleColor( HANDLE_COLOR ),
248 mBoundingBox( Rect<int>() ),
249 mHighlightColor( LIGHT_BLUE ),
250 mHighlightPosition( Vector2::ZERO ),
251 mActiveCursor( ACTIVE_CURSOR_NONE ),
252 mCursorBlinkInterval( CURSOR_BLINK_INTERVAL ),
253 mCursorBlinkDuration( 0.0f ),
254 mCursorWidth( CURSOR_WIDTH ),
255 mHandleScrolling( HANDLE_TYPE_COUNT ),
256 mScrollDirection( SCROLL_NONE ),
257 mScrollThreshold( SCROLL_THRESHOLD ),
258 mScrollSpeed( SCROLL_SPEED ),
259 mScrollDistance( SCROLL_DISTANCE ),
261 mActiveCopyPastePopup( false ),
262 mCursorBlinkStatus( true ),
263 mDelayCursorBlink( false ),
264 mPrimaryCursorVisible( false ),
265 mSecondaryCursorVisible( false ),
266 mSwapSelectionHandles( false ),
267 mNotifyEndOfScroll( false )
269 mQuadVertexFormat[ "aPosition" ] = Property::VECTOR2;
270 mQuadIndexFormat[ "indices" ] = Property::INTEGER;
271 mHighlightMaterial = Material::New( Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ) );
275 * Relayout of the decorations owned by the decorator.
276 * @param[in] size The Size of the UI control the decorator is adding it's decorations to.
278 void Relayout( const Vector2& size )
280 // TODO - Remove this if nothing is active
283 // Show or hide the cursors
288 const CursorImpl& cursor = mCursor[PRIMARY_CURSOR];
289 mPrimaryCursorVisible = ( cursor.position.x <= size.width ) && ( cursor.position.x >= 0.f );
290 if( mPrimaryCursorVisible )
292 Vector2 position = cursor.position;
294 mPrimaryCursor.SetPosition( position.x,
296 mPrimaryCursor.SetSize( Size( mCursorWidth, cursor.cursorHeight ) );
298 mPrimaryCursor.SetVisible( mPrimaryCursorVisible && mCursorBlinkStatus );
300 if( mSecondaryCursor )
302 const CursorImpl& cursor = mCursor[SECONDARY_CURSOR];
303 mSecondaryCursorVisible = ( cursor.position.x <= size.width ) && ( cursor.position.x >= 0.f );
304 if( mSecondaryCursorVisible )
306 mSecondaryCursor.SetPosition( cursor.position.x,
308 mSecondaryCursor.SetSize( Size( mCursorWidth, cursor.cursorHeight ) );
310 mSecondaryCursor.SetVisible( mSecondaryCursorVisible && mCursorBlinkStatus );
313 // Show or hide the grab handle
314 HandleImpl& grabHandle = mHandle[GRAB_HANDLE];
315 if( grabHandle.active )
317 Vector2 position = grabHandle.position;
319 const bool isVisible = ( position.x <= size.width ) && ( position.x >= 0.f );
327 grabHandle.actor.SetPosition( position.x - floor( 0.5f * mCursorWidth ),
328 position.y + grabHandle.lineHeight ); // TODO : Fix for multiline.
330 grabHandle.actor.SetVisible( isVisible );
332 else if( grabHandle.actor )
334 grabHandle.actor.Unparent();
337 // Show or hide the selection handles/highlight
338 HandleImpl& primary = mHandle[ LEFT_SELECTION_HANDLE ];
339 HandleImpl& secondary = mHandle[ RIGHT_SELECTION_HANDLE ];
340 if( primary.active || secondary.active )
342 Vector2 primaryPosition = primary.position;
343 Vector2 secondaryPosition = secondary.position;
345 const bool isPrimaryVisible = ( primaryPosition.x <= size.width ) && ( primaryPosition.x >= 0.f );
346 const bool isSecondaryVisible = ( secondaryPosition.x <= size.width ) && ( secondaryPosition.x >= 0.f );
348 if( isPrimaryVisible || isSecondaryVisible )
352 CreateSelectionHandles();
354 if( isPrimaryVisible )
356 primary.actor.SetPosition( primaryPosition.x,
357 primaryPosition.y + primary.lineHeight ); // TODO : Fix for multiline.
359 SetSelectionHandleMarkerSize( primary );
362 if( isSecondaryVisible )
364 secondary.actor.SetPosition( secondaryPosition.x,
365 secondaryPosition.y + secondary.lineHeight ); // TODO : Fix for multiline.
367 SetSelectionHandleMarkerSize( secondary );
370 primary.actor.SetVisible( isPrimaryVisible );
371 secondary.actor.SetVisible( isSecondaryVisible );
380 primary.actor.Unparent();
382 if( secondary.actor )
384 secondary.actor.Unparent();
386 if( mHighlightActor )
388 mHighlightActor.Unparent();
392 if( mActiveCopyPastePopup )
398 if( mCopyPastePopup.actor )
400 mCopyPastePopup.actor.HidePopup();
405 void UpdatePositions( const Vector2& scrollOffset )
407 mCursor[PRIMARY_CURSOR].position += scrollOffset;
408 mCursor[SECONDARY_CURSOR].position += scrollOffset;
409 mHandle[ GRAB_HANDLE ].position += scrollOffset;
410 mHandle[ LEFT_SELECTION_HANDLE ].position += scrollOffset;
411 mHandle[ RIGHT_SELECTION_HANDLE ].position += scrollOffset;
412 mHighlightPosition += scrollOffset;
413 DeterminePositionPopup();
418 if ( !mCopyPastePopup.actor )
423 if( !mCopyPastePopup.actor.GetParent() )
425 mActiveLayer.Add( mCopyPastePopup.actor );
428 mCopyPastePopup.actor.RaiseAbove( mActiveLayer );
429 mCopyPastePopup.actor.ShowPopup();
432 void DeterminePositionPopup()
434 if ( !mActiveCopyPastePopup )
439 if ( mHandle[LEFT_SELECTION_HANDLE].active || mHandle[RIGHT_SELECTION_HANDLE].active )
441 float minHandleXPosition = std::min ( mHandle[LEFT_SELECTION_HANDLE].position.x, mHandle[RIGHT_SELECTION_HANDLE].position.x );
442 float maxHandleXPosition = std::max ( mHandle[LEFT_SELECTION_HANDLE].position.x, mHandle[RIGHT_SELECTION_HANDLE].position.x );
444 float minHandleYPosition = std::min ( mHandle[LEFT_SELECTION_HANDLE].position.y, mHandle[RIGHT_SELECTION_HANDLE].position.y );
446 mCopyPastePopup.position.x = minHandleXPosition + ( ( maxHandleXPosition - minHandleXPosition ) *0.5f );
447 mCopyPastePopup.position.y = minHandleYPosition + mCopyPastePopup.offset;
451 mCopyPastePopup.position = Vector3( mCursor[PRIMARY_CURSOR].position.x, mCursor[PRIMARY_CURSOR].position.y -100.0f , 0.0f ); //todo 100 to be an offset Property
454 Vector3 popupSize = Vector3( mCopyPastePopup.actor.GetRelayoutSize( Dimension::WIDTH ), mCopyPastePopup.actor.GetRelayoutSize( Dimension::HEIGHT ), 0.0f );
456 GetConstrainedPopupPosition( mCopyPastePopup.position, popupSize, AnchorPoint::CENTER, mActiveLayer, mBoundingBox );
458 SetUpPopupPositionNotifications();
460 mCopyPastePopup.actor.SetPosition( mCopyPastePopup.position );
463 void PopupRelayoutComplete( Actor actor )
465 // Size negotiation for CopyPastePopup complete so can get the size and constrain position within bounding box.
467 DeterminePositionPopup();
470 void CreateCursor( ImageActor& cursor, const Vector4& color )
472 cursor = CreateSolidColorActor( color );
473 cursor.SetSortModifier( DECORATION_DEPTH_INDEX );
474 cursor.SetParentOrigin( ParentOrigin::TOP_LEFT ); // Need to set the default parent origin as CreateSolidColorActor() sets a different one.
475 cursor.SetAnchorPoint( AnchorPoint::TOP_RIGHT );
478 // Add or Remove cursor(s) from parent
481 if( mActiveCursor == ACTIVE_CURSOR_NONE )
485 mPrimaryCursor.Unparent();
487 if( mSecondaryCursor )
489 mSecondaryCursor.Unparent();
494 // Create Primary and or Secondary Cursor(s) if active and add to parent
495 if ( mActiveCursor == ACTIVE_CURSOR_PRIMARY ||
496 mActiveCursor == ACTIVE_CURSOR_BOTH )
498 if ( !mPrimaryCursor )
500 CreateCursor( mPrimaryCursor, mCursor[PRIMARY_CURSOR].color );
501 #ifdef DECORATOR_DEBUG
502 mPrimaryCursor.SetName( "PrimaryCursorActor" );
506 if( !mPrimaryCursor.GetParent() )
508 mActiveLayer.Add( mPrimaryCursor );
512 if ( mActiveCursor == ACTIVE_CURSOR_BOTH )
514 if ( !mSecondaryCursor )
516 CreateCursor( mSecondaryCursor, mCursor[SECONDARY_CURSOR].color );
517 #ifdef DECORATOR_DEBUG
518 mSecondaryCursor.SetName( "SecondaryCursorActor" );
522 if( !mSecondaryCursor.GetParent() )
524 mActiveLayer.Add( mSecondaryCursor );
529 if( mSecondaryCursor )
531 mSecondaryCursor.Unparent();
537 bool OnCursorBlinkTimerTick()
539 if( !mDelayCursorBlink )
542 if ( mPrimaryCursor )
544 mPrimaryCursor.SetVisible( mPrimaryCursorVisible && mCursorBlinkStatus );
546 if ( mSecondaryCursor )
548 mSecondaryCursor.SetVisible( mSecondaryCursorVisible && mCursorBlinkStatus );
551 mCursorBlinkStatus = !mCursorBlinkStatus;
556 mDelayCursorBlink = false;
562 void SetupTouchEvents()
566 mTapDetector = TapGestureDetector::New();
567 mTapDetector.DetectedSignal().Connect( this, &Decorator::Impl::OnTap );
570 if ( !mPanGestureDetector )
572 mPanGestureDetector = PanGestureDetector::New();
573 mPanGestureDetector.DetectedSignal().Connect( this, &Decorator::Impl::OnPan );
577 void CreateActiveLayer()
581 mActiveLayer = Layer::New();
582 #ifdef DECORATOR_DEBUG
583 mActiveLayer.SetName ( "ActiveLayerActor" );
586 mActiveLayer.SetParentOrigin( ParentOrigin::CENTER );
587 mActiveLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
588 mActiveLayer.SetPositionInheritanceMode( USE_PARENT_POSITION );
590 // Add the active layer telling the controller it doesn't need clipping.
591 mController.AddDecoration( mActiveLayer, false );
594 mActiveLayer.RaiseToTop();
597 void SetSelectionHandleMarkerSize( HandleImpl& handle )
599 if ( handle.markerActor )
601 handle.markerActor.SetResizePolicy ( ResizePolicy::FIXED, Dimension::HEIGHT );
602 handle.markerActor.SetSize( 0, handle.lineHeight );
606 void CreateGrabHandle()
608 HandleImpl& grabHandle = mHandle[GRAB_HANDLE];
609 if( !grabHandle.actor )
611 if( !mHandleImages[GRAB_HANDLE][HANDLE_IMAGE_RELEASED] )
613 mHandleImages[GRAB_HANDLE][HANDLE_IMAGE_RELEASED] = ResourceImage::New( DEFAULT_GRAB_HANDLE_IMAGE_RELEASED );
616 grabHandle.actor = ImageActor::New( mHandleImages[GRAB_HANDLE][HANDLE_IMAGE_RELEASED] );
617 grabHandle.actor.SetSortModifier( DECORATION_DEPTH_INDEX );
618 grabHandle.actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
619 // Area that Grab handle responds to, larger than actual handle so easier to move
620 #ifdef DECORATOR_DEBUG
621 grabHandle.actor.SetName( "GrabHandleActor" );
622 if ( Dali::Internal::gLogFilter->IsEnabledFor( Debug::Verbose ) )
624 grabHandle.grabArea = Toolkit::CreateSolidColorActor( Vector4(0.0f, 0.0f, 0.0f, 0.0f), true, Color::RED, 1 );
625 grabHandle.grabArea.SetName( "GrabArea" );
629 grabHandle.grabArea = Actor::New();
630 grabHandle.grabArea.SetName( "GrabArea" );
633 grabHandle.grabArea = Actor::New();
636 grabHandle.grabArea.SetParentOrigin( ParentOrigin::TOP_CENTER );
637 grabHandle.grabArea.SetAnchorPoint( AnchorPoint::TOP_CENTER );
638 grabHandle.grabArea.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
639 grabHandle.grabArea.SetSizeModeFactor( DEFAULT_GRAB_HANDLE_RELATIVE_SIZE );
640 grabHandle.actor.Add( grabHandle.grabArea );
641 grabHandle.actor.SetColor( mHandleColor );
643 grabHandle.grabArea.TouchedSignal().Connect( this, &Decorator::Impl::OnGrabHandleTouched );
644 mTapDetector.Attach( grabHandle.grabArea );
645 mPanGestureDetector.Attach( grabHandle.grabArea );
647 mActiveLayer.Add( grabHandle.actor );
650 if( !grabHandle.actor.GetParent() )
652 mActiveLayer.Add( grabHandle.actor );
656 void CreateHandleMarker( HandleImpl& handle, Image& image, HandleType handleType )
660 handle.markerActor = ImageActor::New( image );
661 handle.markerActor.SetColor( mHandleColor );
662 handle.actor.Add( handle.markerActor );
664 if ( LEFT_SELECTION_HANDLE == handleType )
666 handle.markerActor.SetAnchorPoint( AnchorPoint::BOTTOM_RIGHT );
667 handle.markerActor.SetParentOrigin( ParentOrigin::TOP_RIGHT );
669 else if ( RIGHT_SELECTION_HANDLE == handleType )
671 handle.markerActor.SetAnchorPoint( AnchorPoint::BOTTOM_LEFT );
672 handle.markerActor.SetParentOrigin( ParentOrigin::TOP_LEFT );
677 void CreateSelectionHandles()
679 HandleImpl& primary = mHandle[ LEFT_SELECTION_HANDLE ];
682 primary.actor = ImageActor::New( mHandleImages[LEFT_SELECTION_HANDLE][HANDLE_IMAGE_RELEASED] );
683 #ifdef DECORATOR_DEBUG
684 primary.actor.SetName("SelectionHandleOne");
686 primary.actor.SetAnchorPoint( AnchorPoint::TOP_RIGHT ); // Change to BOTTOM_RIGHT if Look'n'Feel requires handle above text.
687 primary.actor.SetSortModifier( DECORATION_DEPTH_INDEX );
688 primary.flipped = false;
689 primary.actor.SetColor( mHandleColor );
691 primary.grabArea = Actor::New(); // Area that Grab handle responds to, larger than actual handle so easier to move
692 #ifdef DECORATOR_DEBUG
693 primary.grabArea.SetName("SelectionHandleOneGrabArea");
695 primary.grabArea.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
696 primary.grabArea.SetParentOrigin( ParentOrigin::TOP_CENTER );
697 primary.grabArea.SetAnchorPoint( AnchorPoint::TOP_CENTER );
698 primary.grabArea.SetSizeModeFactor( DEFAULT_SELECTION_HANDLE_RELATIVE_SIZE );
700 mTapDetector.Attach( primary.grabArea );
701 mPanGestureDetector.Attach( primary.grabArea );
702 primary.grabArea.TouchedSignal().Connect( this, &Decorator::Impl::OnHandleOneTouched );
704 primary.actor.Add( primary.grabArea );
706 CreateHandleMarker( primary, mHandleImages[LEFT_SELECTION_HANDLE_MARKER][HANDLE_IMAGE_RELEASED], LEFT_SELECTION_HANDLE );
709 if( !primary.actor.GetParent() )
711 mActiveLayer.Add( primary.actor );
714 HandleImpl& secondary = mHandle[ RIGHT_SELECTION_HANDLE ];
715 if( !secondary.actor )
717 secondary.actor = ImageActor::New( mHandleImages[RIGHT_SELECTION_HANDLE][HANDLE_IMAGE_RELEASED] );
718 #ifdef DECORATOR_DEBUG
719 secondary.actor.SetName("SelectionHandleTwo");
721 secondary.actor.SetAnchorPoint( AnchorPoint::TOP_LEFT ); // Change to BOTTOM_LEFT if Look'n'Feel requires handle above text.
722 secondary.actor.SetSortModifier( DECORATION_DEPTH_INDEX );
723 secondary.flipped = false;
724 secondary.actor.SetColor( mHandleColor );
726 secondary.grabArea = Actor::New(); // Area that Grab handle responds to, larger than actual handle so easier to move
727 #ifdef DECORATOR_DEBUG
728 secondary.grabArea.SetName("SelectionHandleTwoGrabArea");
730 secondary.grabArea.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
731 secondary.grabArea.SetParentOrigin( ParentOrigin::TOP_CENTER );
732 secondary.grabArea.SetAnchorPoint( AnchorPoint::TOP_CENTER );
733 secondary.grabArea.SetSizeModeFactor( DEFAULT_SELECTION_HANDLE_RELATIVE_SIZE );
735 mTapDetector.Attach( secondary.grabArea );
736 mPanGestureDetector.Attach( secondary.grabArea );
737 secondary.grabArea.TouchedSignal().Connect( this, &Decorator::Impl::OnHandleTwoTouched );
739 secondary.actor.Add( secondary.grabArea );
741 CreateHandleMarker( secondary, mHandleImages[RIGHT_SELECTION_HANDLE_MARKER][HANDLE_IMAGE_RELEASED], RIGHT_SELECTION_HANDLE );
744 if( !secondary.actor.GetParent() )
746 mActiveLayer.Add( secondary.actor );
750 void CreateHighlight()
752 if( !mHighlightActor )
754 mHighlightActor = Actor::New();
756 #ifdef DECORATOR_DEBUG
757 mHighlightActor.SetName( "HighlightActor" );
759 mHighlightActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
760 mHighlightActor.SetSize( 1.0f, 1.0f );
761 mHighlightActor.SetColor( mHighlightColor );
762 mHighlightActor.SetColorMode( USE_OWN_COLOR );
765 // Add the highlight box telling the controller it needs clipping.
766 mController.AddDecoration( mHighlightActor, true );
769 void UpdateHighlight()
771 if ( mHighlightActor )
773 if( !mHighlightQuadList.empty() )
775 Vector< Vector2 > vertices;
776 Vector< unsigned int> indices;
779 std::vector<QuadCoordinates>::iterator iter = mHighlightQuadList.begin();
780 std::vector<QuadCoordinates>::iterator endIter = mHighlightQuadList.end();
782 for( std::size_t v = 0; iter != endIter; ++iter,v+=4 )
784 QuadCoordinates& quad = *iter;
787 vertex.x = quad.min.x;
788 vertex.y = quad.min.y;
789 vertices.PushBack( vertex );
792 vertex.x = quad.max.x;
793 vertex.y = quad.min.y;
794 vertices.PushBack( vertex );
797 vertex.x = quad.min.x;
798 vertex.y = quad.max.y;
799 vertices.PushBack( vertex );
801 // bottom-right (v+3)
802 vertex.x = quad.max.x;
803 vertex.y = quad.max.y;
804 vertices.PushBack( vertex );
806 // triangle A (3, 1, 0)
807 indices.PushBack( v + 3 );
808 indices.PushBack( v + 1 );
809 indices.PushBack( v );
811 // triangle B (0, 2, 3)
812 indices.PushBack( v );
813 indices.PushBack( v + 2 );
814 indices.PushBack( v + 3 );
819 mQuadVertices.SetSize( vertices.Size() );
823 mQuadVertices = PropertyBuffer::New( mQuadVertexFormat, vertices.Size() );
828 mQuadIndices.SetSize( indices.Size() );
832 mQuadIndices = PropertyBuffer::New( mQuadIndexFormat, indices.Size() );
835 mQuadVertices.SetData( &vertices[ 0 ] );
836 mQuadIndices.SetData( &indices[ 0 ] );
840 mQuadGeometry = Geometry::New();
841 mQuadGeometry.AddVertexBuffer( mQuadVertices );
843 mQuadGeometry.SetIndexBuffer( mQuadIndices );
845 if( !mHighlightRenderer )
847 mHighlightRenderer = Dali::Renderer::New( mQuadGeometry, mHighlightMaterial );
848 mHighlightActor.AddRenderer( mHighlightRenderer );
852 mHighlightActor.SetPosition( mHighlightPosition.x,
853 mHighlightPosition.y );
855 mHighlightQuadList.clear();
857 if( mHighlightRenderer )
859 mHighlightRenderer.SetDepthIndex( mTextDepth - 2u ); // text is rendered at mTextDepth and text's shadow at mTextDepth -1u.
864 void OnTap( Actor actor, const TapGesture& tap )
866 if( actor == mHandle[GRAB_HANDLE].actor )
872 void DoPan( HandleImpl& handle, HandleType type, const PanGesture& gesture )
874 if( Gesture::Started == gesture.state )
876 handle.grabDisplacementX = handle.grabDisplacementY = 0;
879 handle.grabDisplacementX += gesture.displacement.x;
880 handle.grabDisplacementY += gesture.displacement.y;
882 const float x = handle.position.x + handle.grabDisplacementX;
883 const float y = handle.position.y + handle.lineHeight*0.5f + handle.grabDisplacementY;
885 if( Gesture::Started == gesture.state ||
886 Gesture::Continuing == gesture.state )
889 mController.GetTargetSize( targetSize );
891 if( x < mScrollThreshold )
893 mScrollDirection = SCROLL_RIGHT;
894 mHandleScrolling = type;
897 else if( x > targetSize.width - mScrollThreshold )
899 mScrollDirection = SCROLL_LEFT;
900 mHandleScrolling = type;
905 mHandleScrolling = HANDLE_TYPE_COUNT;
907 mController.DecorationEvent( type, HANDLE_PRESSED, x, y );
910 else if( Gesture::Finished == gesture.state ||
911 Gesture::Cancelled == gesture.state )
914 ( mScrollTimer.IsRunning() || mNotifyEndOfScroll ) )
916 mNotifyEndOfScroll = false;
917 mHandleScrolling = HANDLE_TYPE_COUNT;
919 mController.DecorationEvent( type, HANDLE_STOP_SCROLLING, x, y );
923 mController.DecorationEvent( type, HANDLE_RELEASED, x, y );
926 if( GRAB_HANDLE == type )
928 handle.actor.SetImage( mHandleImages[type][HANDLE_IMAGE_RELEASED] );
932 HandleType selectionHandleType = type;
934 if( mSwapSelectionHandles != handle.flipped )
936 selectionHandleType = ( LEFT_SELECTION_HANDLE == type ) ? RIGHT_SELECTION_HANDLE : LEFT_SELECTION_HANDLE;
939 handle.actor.SetImage( mHandleImages[selectionHandleType][HANDLE_IMAGE_RELEASED] );
941 handle.pressed = false;
945 void OnPan( Actor actor, const PanGesture& gesture )
947 HandleImpl& grabHandle = mHandle[GRAB_HANDLE];
948 HandleImpl& primarySelectionHandle = mHandle[LEFT_SELECTION_HANDLE];
949 HandleImpl& secondarySelectionHandle = mHandle[RIGHT_SELECTION_HANDLE];
951 if( actor == grabHandle.grabArea )
953 DoPan( grabHandle, GRAB_HANDLE, gesture );
955 else if( actor == primarySelectionHandle.grabArea )
957 DoPan( primarySelectionHandle, LEFT_SELECTION_HANDLE, gesture );
959 else if( actor == secondarySelectionHandle.grabArea )
961 DoPan( secondarySelectionHandle, RIGHT_SELECTION_HANDLE, gesture );
965 bool OnGrabHandleTouched( Actor actor, const TouchEvent& event )
967 // Switch between pressed/release grab-handle images
968 if( event.GetPointCount() > 0 &&
969 mHandle[GRAB_HANDLE].actor )
971 const TouchPoint& point = event.GetPoint(0);
973 if( TouchPoint::Down == point.state )
975 mHandle[GRAB_HANDLE].pressed = true;
976 Image imagePressed = mHandleImages[GRAB_HANDLE][HANDLE_IMAGE_PRESSED];
979 mHandle[GRAB_HANDLE].actor.SetImage( imagePressed );
982 else if( ( TouchPoint::Up == point.state ) ||
983 ( TouchPoint::Interrupted == point.state ) )
985 mHandle[GRAB_HANDLE].pressed = false;
986 Image imageReleased = mHandleImages[GRAB_HANDLE][HANDLE_IMAGE_RELEASED];
989 mHandle[GRAB_HANDLE].actor.SetImage( imageReleased );
994 // Consume to avoid pop-ups accidentally closing, when handle is outside of pop-up area
998 bool OnHandleOneTouched( Actor actor, const TouchEvent& event )
1000 // Switch between pressed/release selection handle images
1001 if( event.GetPointCount() > 0 &&
1002 mHandle[LEFT_SELECTION_HANDLE].actor )
1004 const TouchPoint& point = event.GetPoint(0);
1006 const bool flip = mSwapSelectionHandles != mHandle[LEFT_SELECTION_HANDLE].flipped;
1007 if( TouchPoint::Down == point.state )
1009 mHandle[LEFT_SELECTION_HANDLE].pressed = true;
1010 Image imagePressed = mHandleImages[flip ? RIGHT_SELECTION_HANDLE : LEFT_SELECTION_HANDLE][HANDLE_IMAGE_PRESSED];
1013 mHandle[LEFT_SELECTION_HANDLE].actor.SetImage( imagePressed );
1016 else if( ( TouchPoint::Up == point.state ) ||
1017 ( TouchPoint::Interrupted == point.state ) )
1019 mHandle[LEFT_SELECTION_HANDLE].pressed = false;
1020 Image imageReleased = mHandleImages[flip ? RIGHT_SELECTION_HANDLE : LEFT_SELECTION_HANDLE][HANDLE_IMAGE_RELEASED];
1023 mHandle[LEFT_SELECTION_HANDLE].actor.SetImage( imageReleased );
1028 // Consume to avoid pop-ups accidentally closing, when handle is outside of pop-up area
1032 bool OnHandleTwoTouched( Actor actor, const TouchEvent& event )
1034 // Switch between pressed/release selection handle images
1035 if( event.GetPointCount() > 0 &&
1036 mHandle[RIGHT_SELECTION_HANDLE].actor )
1038 const TouchPoint& point = event.GetPoint(0);
1040 const bool flip = mSwapSelectionHandles != mHandle[RIGHT_SELECTION_HANDLE].flipped;
1041 if( TouchPoint::Down == point.state )
1043 Image imagePressed = mHandleImages[flip ? LEFT_SELECTION_HANDLE : RIGHT_SELECTION_HANDLE][HANDLE_IMAGE_PRESSED];
1044 mHandle[RIGHT_SELECTION_HANDLE].pressed = true;
1047 mHandle[RIGHT_SELECTION_HANDLE].actor.SetImage( imagePressed );
1050 else if( ( TouchPoint::Up == point.state ) ||
1051 ( TouchPoint::Interrupted == point.state ) )
1053 Image imageReleased = mHandleImages[flip ? LEFT_SELECTION_HANDLE : RIGHT_SELECTION_HANDLE][HANDLE_IMAGE_RELEASED];
1054 mHandle[RIGHT_SELECTION_HANDLE].pressed = false;
1057 mHandle[RIGHT_SELECTION_HANDLE].actor.SetImage( imageReleased );
1062 // Consume to avoid pop-ups accidentally closing, when handle is outside of pop-up area
1068 float AlternatePopUpPositionRelativeToCursor()
1070 float alternativePosition=0.0f;;
1072 if ( mPrimaryCursor ) // Secondary cursor not used for paste
1074 Cursor cursor = PRIMARY_CURSOR;
1075 alternativePosition = mCursor[cursor].position.y;
1078 const float popupHeight = 120.0f; // todo Set as a MaxSize Property in Control or retrieve from CopyPastePopup class.
1080 if( mHandle[GRAB_HANDLE].active )
1082 // If grab handle enabled then position pop-up below the grab handle.
1083 const Vector2 grabHandleSize( 59.0f, 56.0f ); // todo
1084 const float BOTTOM_HANDLE_BOTTOM_OFFSET = 1.5; //todo Should be a property
1085 alternativePosition += grabHandleSize.height + popupHeight + BOTTOM_HANDLE_BOTTOM_OFFSET ;
1089 alternativePosition += popupHeight;
1092 return alternativePosition;
1095 void PopUpLeavesVerticalBoundary( PropertyNotification& source )
1097 float alternativeYPosition=0.0f;
1098 // todo use AlternatePopUpPositionRelativeToSelectionHandles() if text is highlighted
1099 // if can't be positioned above, then position below row.
1100 alternativeYPosition = AlternatePopUpPositionRelativeToCursor();
1102 mCopyPastePopup.actor.SetY( alternativeYPosition );
1106 void SetUpPopupPositionNotifications( )
1108 // Note Property notifications ignore any set anchor point so conditions must allow for this. Default is Top Left.
1110 // Exceeding vertical boundary
1112 Vector4 worldCoordinatesBoundingBox;
1113 LocalToWorldCoordinatesBoundingBox( mBoundingBox, worldCoordinatesBoundingBox );
1115 float popupHeight = mCopyPastePopup.actor.GetRelayoutSize( Dimension::HEIGHT);
1117 PropertyNotification verticalExceedNotification = mCopyPastePopup.actor.AddPropertyNotification( Actor::Property::WORLD_POSITION_Y,
1118 OutsideCondition( worldCoordinatesBoundingBox.y + popupHeight * 0.5f,
1119 worldCoordinatesBoundingBox.w - popupHeight * 0.5f ) );
1121 verticalExceedNotification.NotifySignal().Connect( this, &Decorator::Impl::PopUpLeavesVerticalBoundary );
1124 void GetConstrainedPopupPosition( Vector3& requiredPopupPosition, Vector3& popupSize, Vector3 anchorPoint, Actor& parent, Rect<int>& boundingBox )
1126 DALI_ASSERT_DEBUG ( "Popup parent not on stage" && parent.OnStage() )
1128 // Parent must already by added to Stage for these Get calls to work
1129 Vector3 parentAnchorPoint = parent.GetCurrentAnchorPoint();
1130 Vector3 parentWorldPositionLeftAnchor = parent.GetCurrentWorldPosition() - parent.GetCurrentSize()*parentAnchorPoint;
1131 Vector3 popupWorldPosition = parentWorldPositionLeftAnchor + requiredPopupPosition; // Parent World position plus popup local position gives World Position
1132 Vector3 popupDistanceFromAnchorPoint = popupSize*anchorPoint;
1134 // Bounding rectangle is supplied as screen coordinates, bounding will be done in world coordinates.
1135 Vector4 boundingRectangleWorld;
1136 LocalToWorldCoordinatesBoundingBox( boundingBox, boundingRectangleWorld );
1138 // Calculate distance to move popup (in local space) so fits within the boundary
1139 float xOffSetToKeepWithinBounds = 0.0f;
1140 if( popupWorldPosition.x - popupDistanceFromAnchorPoint.x < boundingRectangleWorld.x )
1142 xOffSetToKeepWithinBounds = boundingRectangleWorld.x - ( popupWorldPosition.x - popupDistanceFromAnchorPoint.x );
1144 else if ( popupWorldPosition.x + popupDistanceFromAnchorPoint.x > boundingRectangleWorld.z )
1146 xOffSetToKeepWithinBounds = boundingRectangleWorld.z - ( popupWorldPosition.x + popupDistanceFromAnchorPoint.x );
1149 // Ensure initial display of Popup is in alternative position if can not fit above. As Property notification will be a frame behind.
1150 if ( popupWorldPosition.y - popupDistanceFromAnchorPoint.y < boundingRectangleWorld.y )
1152 requiredPopupPosition.y = AlternatePopUpPositionRelativeToCursor();
1155 requiredPopupPosition.x = requiredPopupPosition.x + xOffSetToKeepWithinBounds;
1157 // Prevent pixel mis-alignment by rounding down.
1158 requiredPopupPosition.x = static_cast<int>( requiredPopupPosition.x );
1159 requiredPopupPosition.y = static_cast<int>( requiredPopupPosition.y );
1163 void FlipSelectionHandleImages()
1167 CreateSelectionHandles();
1169 HandleImpl& leftHandle = mHandle[LEFT_SELECTION_HANDLE];
1170 HandleImpl& rightHandle = mHandle[RIGHT_SELECTION_HANDLE];
1172 // If handle pressed and pressed image exists then use pressed image else stick with released image
1173 const HandleImageType leftImageType = ( leftHandle.pressed && mHandleImages[LEFT_SELECTION_HANDLE][HANDLE_IMAGE_PRESSED] ) ? HANDLE_IMAGE_PRESSED : HANDLE_IMAGE_RELEASED;
1174 const HandleImageType rightImageType = ( rightHandle.pressed && mHandleImages[RIGHT_SELECTION_HANDLE][HANDLE_IMAGE_PRESSED] ) ? HANDLE_IMAGE_PRESSED : HANDLE_IMAGE_RELEASED;
1176 const bool leftFlipped = mSwapSelectionHandles != leftHandle.flipped;
1177 const bool rightFlipped = mSwapSelectionHandles != rightHandle.flipped;
1179 leftHandle.actor.SetImage( leftFlipped ? mHandleImages[RIGHT_SELECTION_HANDLE][leftImageType] : mHandleImages[LEFT_SELECTION_HANDLE][leftImageType] );
1181 leftHandle.actor.SetAnchorPoint( leftFlipped ? AnchorPoint::TOP_LEFT : AnchorPoint::TOP_RIGHT );
1183 rightHandle.actor.SetImage( rightFlipped ? mHandleImages[LEFT_SELECTION_HANDLE][rightImageType] : mHandleImages[RIGHT_SELECTION_HANDLE][rightImageType] );
1185 rightHandle.actor.SetAnchorPoint( rightFlipped ? AnchorPoint::TOP_RIGHT : AnchorPoint::TOP_LEFT );
1187 if ( leftHandle.markerActor )
1189 leftHandle.markerActor.SetImage( leftFlipped ? mHandleImages[RIGHT_SELECTION_HANDLE_MARKER][leftImageType] : mHandleImages[LEFT_SELECTION_HANDLE_MARKER][leftImageType] );
1191 if ( rightHandle.markerActor )
1193 rightHandle.markerActor.SetImage( rightFlipped ? mHandleImages[LEFT_SELECTION_HANDLE_MARKER][rightImageType] : mHandleImages[RIGHT_SELECTION_HANDLE_MARKER][rightImageType] );
1197 void SetScrollThreshold( float threshold )
1199 mScrollThreshold = threshold;
1202 float GetScrollThreshold() const
1204 return mScrollThreshold;
1207 void SetScrollSpeed( float speed )
1209 mScrollSpeed = speed;
1210 mScrollDistance = speed * SCROLL_TICK_INTERVAL * TO_SECONDS;
1213 float GetScrollSpeed() const
1215 return mScrollSpeed;
1218 void NotifyEndOfScroll()
1224 mNotifyEndOfScroll = true;
1229 * Creates and starts a timer to scroll the text when handles are close to the edges of the text.
1231 * It only starts the timer if it's already created.
1233 void StartScrollTimer()
1237 mScrollTimer = Timer::New( SCROLL_TICK_INTERVAL );
1238 mScrollTimer.TickSignal().Connect( this, &Decorator::Impl::OnScrollTimerTick );
1241 if( !mScrollTimer.IsRunning() )
1243 mScrollTimer.Start();
1248 * Stops the timer used to scroll the text.
1250 void StopScrollTimer()
1254 mScrollTimer.Stop();
1259 * Callback called by the timer used to scroll the text.
1261 * It calculates and sets a new scroll position.
1263 bool OnScrollTimerTick()
1265 if( HANDLE_TYPE_COUNT != mHandleScrolling )
1267 mController.DecorationEvent( mHandleScrolling,
1269 mScrollDirection == SCROLL_RIGHT ? mScrollDistance : -mScrollDistance,
1276 ControllerInterface& mController;
1278 TapGestureDetector mTapDetector;
1279 PanGestureDetector mPanGestureDetector;
1280 Timer mCursorBlinkTimer; ///< Timer to signal cursor to blink
1281 Timer mScrollTimer; ///< Timer used to scroll the text when the grab handle is moved close to the edges.
1283 Layer mActiveLayer; ///< Layer for active handles and alike that ensures they are above all else.
1284 ImageActor mPrimaryCursor;
1285 ImageActor mSecondaryCursor;
1287 Actor mHighlightActor; ///< Actor to display highlight
1288 Renderer mHighlightRenderer;
1289 Material mHighlightMaterial; ///< Material used for highlight
1290 Property::Map mQuadVertexFormat;
1291 Property::Map mQuadIndexFormat;
1292 PopupImpl mCopyPastePopup;
1293 TextSelectionPopup::Buttons mEnabledPopupButtons; /// Bit mask of currently enabled Popup buttons
1294 TextSelectionPopupCallbackInterface& mTextSelectionPopupCallbackInterface;
1296 Image mHandleImages[HANDLE_TYPE_COUNT][HANDLE_IMAGE_TYPE_COUNT];
1297 Vector4 mHandleColor;
1299 CursorImpl mCursor[CURSOR_COUNT];
1300 HandleImpl mHandle[HANDLE_TYPE_COUNT];
1302 PropertyBuffer mQuadVertices;
1303 PropertyBuffer mQuadIndices;
1304 Geometry mQuadGeometry;
1305 QuadContainer mHighlightQuadList; ///< Sub-selections that combine to create the complete selection highlight
1307 Rect<int> mBoundingBox;
1308 Vector4 mHighlightColor; ///< Color of the highlight
1309 Vector2 mHighlightPosition; ///< The position of the highlight actor.
1311 unsigned int mActiveCursor;
1312 unsigned int mCursorBlinkInterval;
1313 float mCursorBlinkDuration;
1314 float mCursorWidth; ///< The width of the cursors in pixels.
1315 HandleType mHandleScrolling; ///< The handle which is scrolling.
1316 ScrollDirection mScrollDirection; ///< The direction of the scroll.
1317 float mScrollThreshold; ///< Defines a square area inside the control, close to the edge. A cursor entering this area will trigger scroll events.
1318 float mScrollSpeed; ///< The scroll speed in pixels per second.
1319 float mScrollDistance; ///< Distance the text scrolls during a scroll interval.
1320 int mTextDepth; ///< The depth used to render the text.
1322 bool mActiveCopyPastePopup : 1;
1323 bool mCursorBlinkStatus : 1; ///< Flag to switch between blink on and blink off.
1324 bool mDelayCursorBlink : 1; ///< Used to avoid cursor blinking when entering text.
1325 bool mPrimaryCursorVisible : 1; ///< Whether the primary cursor is visible.
1326 bool mSecondaryCursorVisible : 1; ///< Whether the secondary cursor is visible.
1327 bool mSwapSelectionHandles : 1; ///< Whether to swap the selection handle images.
1328 bool mNotifyEndOfScroll : 1; ///< Whether to notify the end of the scroll.
1331 DecoratorPtr Decorator::New( ControllerInterface& controller,
1332 TextSelectionPopupCallbackInterface& callbackInterface )
1334 return DecoratorPtr( new Decorator( controller,
1335 callbackInterface ) );
1338 void Decorator::SetBoundingBox( const Rect<int>& boundingBox )
1340 mImpl->mBoundingBox = boundingBox;
1343 const Rect<int>& Decorator::GetBoundingBox() const
1345 return mImpl->mBoundingBox;
1348 void Decorator::Relayout( const Vector2& size )
1350 mImpl->Relayout( size );
1353 void Decorator::UpdatePositions( const Vector2& scrollOffset )
1355 mImpl->UpdatePositions( scrollOffset );
1360 void Decorator::SetActiveCursor( ActiveCursor activeCursor )
1362 mImpl->mActiveCursor = activeCursor;
1365 unsigned int Decorator::GetActiveCursor() const
1367 return mImpl->mActiveCursor;
1370 void Decorator::SetPosition( Cursor cursor, float x, float y, float cursorHeight, float lineHeight )
1372 mImpl->mCursor[cursor].position.x = x;
1373 mImpl->mCursor[cursor].position.y = y;
1374 mImpl->mCursor[cursor].cursorHeight = cursorHeight;
1375 mImpl->mCursor[cursor].lineHeight = lineHeight;
1378 void Decorator::GetPosition( Cursor cursor, float& x, float& y, float& cursorHeight, float& lineHeight ) const
1380 x = mImpl->mCursor[cursor].position.x;
1381 y = mImpl->mCursor[cursor].position.y;
1382 cursorHeight = mImpl->mCursor[cursor].cursorHeight;
1383 lineHeight = mImpl->mCursor[cursor].lineHeight;
1386 const Vector2& Decorator::GetPosition( Cursor cursor ) const
1388 return mImpl->mCursor[cursor].position;
1391 void Decorator::SetCursorColor( Cursor cursor, const Dali::Vector4& color )
1393 mImpl->mCursor[cursor].color = color;
1396 const Dali::Vector4& Decorator::GetColor( Cursor cursor ) const
1398 return mImpl->mCursor[cursor].color;
1401 void Decorator::StartCursorBlink()
1403 if ( !mImpl->mCursorBlinkTimer )
1405 mImpl->mCursorBlinkTimer = Timer::New( mImpl->mCursorBlinkInterval );
1406 mImpl->mCursorBlinkTimer.TickSignal().Connect( mImpl, &Decorator::Impl::OnCursorBlinkTimerTick );
1409 if ( !mImpl->mCursorBlinkTimer.IsRunning() )
1411 mImpl->mCursorBlinkTimer.Start();
1415 void Decorator::StopCursorBlink()
1417 if ( mImpl->mCursorBlinkTimer )
1419 mImpl->mCursorBlinkTimer.Stop();
1422 mImpl->mCursorBlinkStatus = true; // Keep cursor permanently shown
1425 void Decorator::DelayCursorBlink()
1427 mImpl->mCursorBlinkStatus = true; // Show cursor for a bit longer
1428 mImpl->mDelayCursorBlink = true;
1431 void Decorator::SetCursorBlinkInterval( float seconds )
1433 mImpl->mCursorBlinkInterval = static_cast<unsigned int>( seconds * TO_MILLISECONDS ); // Convert to milliseconds
1436 float Decorator::GetCursorBlinkInterval() const
1438 return static_cast<float>( mImpl->mCursorBlinkInterval ) * TO_SECONDS;
1441 void Decorator::SetCursorBlinkDuration( float seconds )
1443 mImpl->mCursorBlinkDuration = seconds;
1446 float Decorator::GetCursorBlinkDuration() const
1448 return mImpl->mCursorBlinkDuration;
1451 void Decorator::SetCursorWidth( int width )
1453 mImpl->mCursorWidth = static_cast<float>( width );
1456 int Decorator::GetCursorWidth() const
1458 return static_cast<int>( mImpl->mCursorWidth );
1463 void Decorator::SetHandleActive( HandleType handleType, bool active )
1465 mImpl->mHandle[handleType].active = active;
1469 // TODO: this is a work-around.
1470 // The problem is the handle actor does not receive the touch event with the Interrupt
1471 // state when the power button is pressed and the application goes to background.
1472 mImpl->mHandle[handleType].pressed = false;
1473 Image imageReleased = mImpl->mHandleImages[handleType][HANDLE_IMAGE_RELEASED];
1474 ImageActor imageActor = mImpl->mHandle[handleType].actor;
1475 if( imageReleased && imageActor )
1477 imageActor.SetImage( imageReleased );
1482 bool Decorator::IsHandleActive( HandleType handleType ) const
1484 return mImpl->mHandle[handleType].active ;
1487 void Decorator::SetHandleImage( HandleType handleType, HandleImageType handleImageType, Dali::Image image )
1489 mImpl->mHandleImages[handleType][handleImageType] = image;
1492 Dali::Image Decorator::GetHandleImage( HandleType handleType, HandleImageType handleImageType ) const
1494 return mImpl->mHandleImages[handleType][handleImageType];
1497 void Decorator::SetHandleColor( const Vector4& color )
1499 mImpl->mHandleColor = color;
1502 const Vector4& Decorator::GetHandleColor() const
1504 return mImpl->mHandleColor;
1507 void Decorator::SetPosition( HandleType handleType, float x, float y, float height )
1509 // Adjust grab handle displacement
1510 Impl::HandleImpl& handle = mImpl->mHandle[handleType];
1512 handle.grabDisplacementX -= x - handle.position.x;
1513 handle.grabDisplacementY -= y - handle.position.y;
1515 handle.position.x = x;
1516 handle.position.y = y;
1517 handle.lineHeight = height;
1520 void Decorator::GetPosition( HandleType handleType, float& x, float& y, float& height ) const
1522 Impl::HandleImpl& handle = mImpl->mHandle[handleType];
1524 x = handle.position.x;
1525 y = handle.position.y;
1526 height = handle.lineHeight;
1529 const Vector2& Decorator::GetPosition( HandleType handleType ) const
1531 return mImpl->mHandle[handleType].position;
1534 void Decorator::SwapSelectionHandlesEnabled( bool enable )
1536 mImpl->mSwapSelectionHandles = enable;
1538 mImpl->FlipSelectionHandleImages();
1541 void Decorator::AddHighlight( float x1, float y1, float x2, float y2 )
1543 mImpl->mHighlightQuadList.push_back( QuadCoordinates(x1, y1, x2, y2) );
1546 void Decorator::ClearHighlights()
1548 mImpl->mHighlightQuadList.clear();
1549 mImpl->mHighlightPosition = Vector2::ZERO;
1552 void Decorator::SetHighlightColor( const Vector4& color )
1554 mImpl->mHighlightColor = color;
1557 const Vector4& Decorator::GetHighlightColor() const
1559 return mImpl->mHighlightColor;
1562 void Decorator::SetTextDepth( int textDepth )
1564 mImpl->mTextDepth = textDepth;
1567 void Decorator::SetPopupActive( bool active )
1569 mImpl->mActiveCopyPastePopup = active;
1572 bool Decorator::IsPopupActive() const
1574 return mImpl->mActiveCopyPastePopup ;
1577 void Decorator::SetEnabledPopupButtons( TextSelectionPopup::Buttons& enabledButtonsBitMask )
1579 mImpl->mEnabledPopupButtons = enabledButtonsBitMask;
1581 if ( !mImpl->mCopyPastePopup.actor )
1583 mImpl->mCopyPastePopup.actor = TextSelectionPopup::New( &mImpl->mTextSelectionPopupCallbackInterface );
1584 #ifdef DECORATOR_DEBUG
1585 mImpl->mCopyPastePopup.actor.SetName("mCopyPastePopup");
1587 mImpl->mCopyPastePopup.actor.SetAnchorPoint( AnchorPoint::CENTER );
1588 mImpl->mCopyPastePopup.actor.OnRelayoutSignal().Connect( mImpl, &Decorator::Impl::PopupRelayoutComplete ); // Position popup after size negotiation
1591 mImpl->mCopyPastePopup.actor.EnableButtons( mImpl->mEnabledPopupButtons );
1594 TextSelectionPopup::Buttons& Decorator::GetEnabledPopupButtons()
1596 return mImpl->mEnabledPopupButtons;
1601 void Decorator::SetScrollThreshold( float threshold )
1603 mImpl->SetScrollThreshold( threshold );
1606 float Decorator::GetScrollThreshold() const
1608 return mImpl->GetScrollThreshold();
1611 void Decorator::SetScrollSpeed( float speed )
1613 mImpl->SetScrollSpeed( speed );
1616 float Decorator::GetScrollSpeed() const
1618 return mImpl->GetScrollSpeed();
1621 void Decorator::NotifyEndOfScroll()
1623 mImpl->NotifyEndOfScroll();
1626 Decorator::~Decorator()
1631 Decorator::Decorator( ControllerInterface& controller,
1632 TextSelectionPopupCallbackInterface& callbackInterface )
1635 mImpl = new Decorator::Impl( controller, callbackInterface );
1640 } // namespace Toolkit