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>
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/public-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/pan-gesture.h>
34 #include <dali/public-api/events/pan-gesture-detector.h>
35 #include <dali/public-api/geometry/mesh.h>
36 #include <dali/public-api/geometry/mesh-data.h>
37 #include <dali/public-api/images/resource-image.h>
38 #include <dali/public-api/math/rect.h>
39 #include <dali/public-api/math/vector2.h>
40 #include <dali/public-api/math/vector4.h>
41 #include <dali/public-api/object/property-notification.h>
42 #include <dali/public-api/signals/connection-tracker.h>
45 #include <dali-toolkit/public-api/controls/control.h>
46 #include <dali-toolkit/public-api/controls/control-impl.h>
47 #include <dali-toolkit/public-api/controls/buttons/push-button.h>
48 #include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
49 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
50 #include <dali-toolkit/public-api/controls/text-controls/text-selection-popup.h>
53 #define DECORATOR_DEBUG
63 #ifdef DECORATOR_DEBUG
64 Integration::Log::Filter* gLogFilter( Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_TEXT_DECORATOR") );
75 const char* DEFAULT_GRAB_HANDLE_IMAGE( DALI_IMAGE_DIR "insertpoint-icon.png" );
76 const char* DEFAULT_SELECTION_HANDLE_ONE( DALI_IMAGE_DIR "text-input-selection-handle-left.png" );
77 const char* DEFAULT_SELECTION_HANDLE_TWO( DALI_IMAGE_DIR "text-input-selection-handle-right.png" );
78 //const char* DEFAULT_SELECTION_HANDLE_ONE_PRESSED( DALI_IMAGE_DIR "text-input-selection-handle-left-press.png" );
79 //const char* DEFAULT_SELECTION_HANDLE_TWO_PRESSED( DALI_IMAGE_DIR "text-input-selection-handle-right-press.png" );
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 );
84 const unsigned int CURSOR_BLINK_INTERVAL = 500u; // Cursor blink interval
85 const float TO_MILLISECONDS = 1000.f;
86 const float TO_SECONDS = 1.f / 1000.f;
88 const float DISPLAYED_HIGHLIGHT_Z_OFFSET( -0.05f );
91 * structure to hold coordinates of each quad, which will make up the mesh.
93 struct QuadCoordinates
104 * @param[in] x1 left co-ordinate
105 * @param[in] y1 top co-ordinate
106 * @param[in] x2 right co-ordinate
107 * @param[in] y2 bottom co-ordinate
109 QuadCoordinates(float x1, float y1, float x2, float y2)
115 Dali::Vector2 min; ///< top-left (minimum) position of quad
116 Dali::Vector2 max; ///< bottom-right (maximum) position of quad
119 typedef std::vector<QuadCoordinates> QuadContainer;
122 * @brief Takes a bounding rectangle in the local coordinates of an actor and returns the world coordinates Bounding Box.
123 * @param[in] boundingRectangle local bounding
124 * @param[out] Vector4 World coordinate bounding Box.
126 void LocalToWorldCoordinatesBoundingBox( const Dali::Rect<int>& boundingRectangle, Dali::Vector4& boundingBox )
128 // Convert to world coordinates and store as a Vector4 to be compatible with Property Notifications.
129 Dali::Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
131 const float originX = boundingRectangle.x - 0.5f * stageSize.width;
132 const float originY = boundingRectangle.y - 0.5f * stageSize.height;
134 boundingBox = Dali::Vector4( originX,
136 originX + boundingRectangle.width,
137 originY + boundingRectangle.height );
141 } // end of namespace
152 struct Decorator::Impl : public ConnectionTracker
157 : color( Dali::Color::WHITE ),
159 cursorHeight( 0.0f ),
170 struct SelectionHandleImpl
172 SelectionHandleImpl()
186 float lineHeight; ///< Not the handle height
190 Impl( Dali::Toolkit::Internal::Control& parent, Observer& observer )
191 : mTextControlParent( parent ),
192 mObserver( observer ),
193 mBoundingBox( Rect<int>() ),
194 mHighlightColor( 0.07f, 0.41f, 0.59f, 1.0f ), // light blue
195 mActiveCursor( ACTIVE_CURSOR_NONE ),
196 mCursorBlinkInterval( CURSOR_BLINK_INTERVAL ),
197 mCursorBlinkDuration( 0.0f ),
198 mGrabDisplacementX( 0.0f ),
199 mGrabDisplacementY( 0.0f ),
200 mActiveGrabHandle( false ),
201 mActiveSelection( false ),
202 mActiveCopyPastePopup( false ),
203 mCursorBlinkStatus( true )
208 * Relayout of the decorations owned by the decorator.
209 * @param[in] size The Size of the UI control the decorator is adding it's decorations to.
211 void Relayout( const Vector2& size, const Vector2& scrollPosition )
213 // TODO - Remove this if nothing is active
216 // Show or hide the cursors
220 mPrimaryCursor.SetPosition( mCursor[PRIMARY_CURSOR].position.x + scrollPosition.x,
221 mCursor[PRIMARY_CURSOR].position.y + scrollPosition.y );
222 mPrimaryCursor.SetSize( Size( 1.0f, mCursor[PRIMARY_CURSOR].cursorHeight ) );
224 if( mSecondaryCursor )
226 mSecondaryCursor.SetPosition( mCursor[SECONDARY_CURSOR].position.x + scrollPosition.x,
227 mCursor[SECONDARY_CURSOR].position.y + scrollPosition.y );
228 mSecondaryCursor.SetSize( Size( 1.0f, mCursor[SECONDARY_CURSOR].cursorHeight ) );
231 // Show or hide the grab handle
232 if( mActiveGrabHandle )
238 mGrabHandle.SetPosition( mCursor[PRIMARY_CURSOR].position.x + scrollPosition.x,
239 mCursor[PRIMARY_CURSOR].position.y + mCursor[PRIMARY_CURSOR].lineHeight + scrollPosition.y );
241 else if( mGrabHandle )
243 UnparentAndReset( mGrabHandle );
246 // Show or hide the selection handles/highlight
247 if( mActiveSelection )
251 CreateSelectionHandles();
253 SelectionHandleImpl& primary = mSelectionHandle[ PRIMARY_SELECTION_HANDLE ];
254 primary.actor.SetPosition( primary.position.x + scrollPosition.x,
255 primary.position.y + primary.lineHeight + scrollPosition.y );
257 SelectionHandleImpl& secondary = mSelectionHandle[ SECONDARY_SELECTION_HANDLE ];
258 secondary.actor.SetPosition( secondary.position.x + scrollPosition.x,
259 secondary.position.y + secondary.lineHeight + scrollPosition.y );
266 UnparentAndReset( mSelectionHandle[ PRIMARY_SELECTION_HANDLE ].actor );
267 UnparentAndReset( mSelectionHandle[ SECONDARY_SELECTION_HANDLE ].actor );
268 UnparentAndReset( mHighlightMeshActor );
271 if ( mActiveCopyPastePopup )
273 if ( !mCopyPastePopup )
275 mCopyPastePopup = TextSelectionPopup::New();
276 #ifdef DECORATOR_DEBUG
277 mCopyPastePopup.SetName("mCopyPastePopup");
279 mCopyPastePopup.SetAnchorPoint( AnchorPoint::CENTER );
280 mCopyPastePopup.OnRelayoutSignal().Connect( this, &Decorator::Impl::PopUpRelayoutComplete ); // Position popup after size negotiation
281 mActiveLayer.Add ( mCopyPastePopup );
286 if ( mCopyPastePopup )
288 UnparentAndReset( mCopyPastePopup );
293 void PopUpRelayoutComplete( Actor actor )
295 // Size negotiation for CopyPastePopup complete so can get the size and constrain position within bounding box.
297 mCopyPastePopup.OnRelayoutSignal().Disconnect( this, &Decorator::Impl::PopUpRelayoutComplete );
299 Vector3 popupPosition( mCursor[PRIMARY_CURSOR].position.x, mCursor[PRIMARY_CURSOR].position.y -100.0f , 0.0f); //todo 100 to be an offset Property
301 Vector3 popupSize = Vector3( mCopyPastePopup.GetRelayoutSize( Dimension::WIDTH ), mCopyPastePopup.GetRelayoutSize( Dimension::HEIGHT ), 0.0f );
303 GetConstrainedPopupPosition( popupPosition, popupSize, AnchorPoint::CENTER, mActiveLayer, mBoundingBox );
305 SetUpPopUpPositionNotifications();
307 mCopyPastePopup.SetPosition( popupPosition ); //todo grabhandle(cursor) or selection handle positions to be used
310 void CreateCursor( ImageActor& cursor )
312 cursor = CreateSolidColorActor( Color::WHITE );
313 cursor.SetParentOrigin( ParentOrigin::TOP_LEFT ); // Need to set the default parent origin as CreateSolidColorActor() sets a different one.
314 cursor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
317 // Add or Remove cursor(s) from parent
320 if( mActiveCursor == ACTIVE_CURSOR_NONE )
322 UnparentAndReset( mPrimaryCursor );
323 UnparentAndReset( mSecondaryCursor );
327 /* Create Primary and or Secondary Cursor(s) if active and add to parent */
328 if ( mActiveCursor == ACTIVE_CURSOR_PRIMARY ||
329 mActiveCursor == ACTIVE_CURSOR_BOTH )
331 if ( !mPrimaryCursor )
333 CreateCursor( mPrimaryCursor );
334 #ifdef DECORATOR_DEBUG
335 mPrimaryCursor.SetName( "PrimaryCursorActor" );
337 mActiveLayer.Add( mPrimaryCursor );
341 if ( mActiveCursor == ACTIVE_CURSOR_BOTH )
343 if ( !mSecondaryCursor )
345 CreateCursor( mSecondaryCursor );
346 #ifdef DECORATOR_DEBUG
347 mSecondaryCursor.SetName( "SecondaryCursorActor" );
349 mActiveLayer.Add( mSecondaryCursor );
354 UnparentAndReset( mSecondaryCursor );
359 bool OnCursorBlinkTimerTick()
362 if ( mPrimaryCursor )
364 mPrimaryCursor.SetVisible( mCursorBlinkStatus );
366 if ( mSecondaryCursor )
368 mSecondaryCursor.SetVisible( mCursorBlinkStatus );
371 mCursorBlinkStatus = !mCursorBlinkStatus;
376 void SetupTouchEvents()
380 mTapDetector = TapGestureDetector::New();
381 mTapDetector.DetectedSignal().Connect( this, &Decorator::Impl::OnTap );
384 if ( !mPanGestureDetector )
386 mPanGestureDetector = PanGestureDetector::New();
387 mPanGestureDetector.DetectedSignal().Connect( this, &Decorator::Impl::OnPan );
391 void CreateActiveLayer()
395 Actor parent = mTextControlParent.Self();
397 mActiveLayer = Layer::New();
398 #ifdef DECORATOR_DEBUG
399 mActiveLayer.SetName ( "ActiveLayerActor" );
402 mActiveLayer.SetParentOrigin( ParentOrigin::CENTER );
403 mActiveLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
404 mActiveLayer.SetPositionInheritanceMode( USE_PARENT_POSITION );
406 parent.Add( mActiveLayer );
409 mActiveLayer.RaiseToTop();
412 void CreateGrabHandle()
416 if ( !mGrabHandleImage )
418 mGrabHandleImage = ResourceImage::New( DEFAULT_GRAB_HANDLE_IMAGE );
421 mGrabHandle = ImageActor::New( mGrabHandleImage );
422 mGrabHandle.SetAnchorPoint( AnchorPoint::TOP_CENTER );
423 mGrabHandle.SetDrawMode( DrawMode::OVERLAY );
424 // Area that Grab handle responds to, larger than actual handle so easier to move
425 #ifdef DECORATOR_DEBUG
426 mGrabHandle.SetName( "GrabHandleActor" );
427 if ( Dali::Internal::gLogFilter->IsEnabledFor( Debug::Verbose ) )
429 mGrabArea = Toolkit::CreateSolidColorActor( Vector4(0.0f, 0.0f, 0.0f, 0.0f), true, Color::RED, 1 );
430 mGrabArea.SetName( "GrabArea" );
434 mGrabArea = Actor::New();
435 mGrabArea.SetName( "GrabArea" );
438 mGrabArea = Actor::New();
441 mGrabArea.SetParentOrigin( ParentOrigin::TOP_CENTER );
442 mGrabArea.SetAnchorPoint( AnchorPoint::TOP_CENTER );
443 mGrabArea.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
444 mGrabArea.SetSizeModeFactor( DEFAULT_GRAB_HANDLE_RELATIVE_SIZE );
445 mGrabHandle.Add( mGrabArea );
447 mTapDetector.Attach( mGrabArea );
448 mPanGestureDetector.Attach( mGrabArea );
450 mActiveLayer.Add( mGrabHandle );
454 void CreateSelectionHandles()
456 SelectionHandleImpl& primary = mSelectionHandle[ PRIMARY_SELECTION_HANDLE ];
457 if ( !primary.actor )
459 if ( !primary.releasedImage )
461 primary.releasedImage = ResourceImage::New( DEFAULT_SELECTION_HANDLE_ONE );
464 primary.actor = ImageActor::New( primary.releasedImage );
465 #ifdef DECORATOR_DEBUG
466 primary.actor.SetName("SelectionHandleOne");
468 primary.actor.SetAnchorPoint( AnchorPoint::TOP_RIGHT ); // Change to BOTTOM_RIGHT if Look'n'Feel requires handle above text.
469 primary.actor.SetDrawMode( DrawMode::OVERLAY ); // ensure grab handle above text
470 primary.flipped = false;
472 primary.grabArea = Actor::New(); // Area that Grab handle responds to, larger than actual handle so easier to move
473 #ifdef DECORATOR_DEBUG
474 primary.grabArea.SetName("SelectionHandleOneGrabArea");
476 primary.grabArea.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
477 primary.grabArea.SetSizeModeFactor( DEFAULT_SELECTION_HANDLE_RELATIVE_SIZE );
478 primary.grabArea.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION );
480 mTapDetector.Attach( primary.grabArea );
481 mPanGestureDetector.Attach( primary.grabArea );
482 primary.grabArea.TouchedSignal().Connect( this, &Decorator::Impl::OnHandleOneTouched );
484 primary.actor.Add( primary.grabArea );
485 mActiveLayer.Add( primary.actor );
488 SelectionHandleImpl& secondary = mSelectionHandle[ SECONDARY_SELECTION_HANDLE ];
489 if ( !secondary.actor )
491 if ( !secondary.releasedImage )
493 secondary.releasedImage = ResourceImage::New( DEFAULT_SELECTION_HANDLE_TWO );
496 secondary.actor = ImageActor::New( secondary.releasedImage );
497 #ifdef DECORATOR_DEBUG
498 secondary.actor.SetName("SelectionHandleTwo");
500 secondary.actor.SetAnchorPoint( AnchorPoint::TOP_LEFT ); // Change to BOTTOM_LEFT if Look'n'Feel requires handle above text.
501 secondary.actor.SetDrawMode( DrawMode::OVERLAY ); // ensure grab handle above text
502 secondary.flipped = false;
504 secondary.grabArea = Actor::New(); // Area that Grab handle responds to, larger than actual handle so easier to move
505 #ifdef DECORATOR_DEBUG
506 secondary.grabArea.SetName("SelectionHandleTwoGrabArea");
508 secondary.grabArea.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
509 secondary.grabArea.SetSizeModeFactor( DEFAULT_SELECTION_HANDLE_RELATIVE_SIZE );
510 secondary.grabArea.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION );
512 mTapDetector.Attach( secondary.grabArea );
513 mPanGestureDetector.Attach( secondary.grabArea );
514 secondary.grabArea.TouchedSignal().Connect( this, &Decorator::Impl::OnHandleTwoTouched );
516 secondary.actor.Add( secondary.grabArea );
517 mActiveLayer.Add( secondary.actor );
520 //SetUpHandlePropertyNotifications(); TODO
523 void CreateHighlight()
525 if ( !mHighlightMeshActor )
527 mHighlightMaterial = Material::New( "HighlightMaterial" );
528 mHighlightMaterial.SetDiffuseColor( mHighlightColor );
530 mHighlightMeshData.SetMaterial( mHighlightMaterial );
531 mHighlightMeshData.SetHasNormals( true );
533 mHighlightMesh = Mesh::New( mHighlightMeshData );
535 mHighlightMeshActor = MeshActor::New( mHighlightMesh );
536 #ifdef DECORATOR_DEBUG
537 mHighlightMeshActor.SetName( "HighlightMeshActor" );
539 mHighlightMeshActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
540 mHighlightMeshActor.SetPosition( 0.0f, 0.0f, DISPLAYED_HIGHLIGHT_Z_OFFSET );
542 Actor parent = mTextControlParent.Self();
543 parent.Add( mHighlightMeshActor );
547 void UpdateHighlight()
549 // Construct a Mesh with a texture to be used as the highlight 'box' for selected text
551 // Example scenarios where mesh is made from 3, 1, 2, 2 ,3 or 3 quads.
553 // [ TOP ] [ TOP ] [TOP ] [ TOP ] [ TOP ] [ TOP ]
554 // [ MIDDLE ] [BOTTOM] [BOTTOM] [ MIDDLE ] [ MIDDLE ]
555 // [ BOTTOM] [ MIDDLE ] [ MIDDLE ]
556 // [BOTTOM] [ MIDDLE ]
559 // Each quad is created as 2 triangles.
560 // Middle is just 1 quad regardless of its size.
574 if ( mHighlightMesh && mHighlightMaterial && !mHighlightQuadList.empty() )
576 MeshData::VertexContainer vertices;
577 Dali::MeshData::FaceIndices faceIndices;
579 std::vector<QuadCoordinates>::iterator iter = mHighlightQuadList.begin();
580 std::vector<QuadCoordinates>::iterator endIter = mHighlightQuadList.end();
582 // vertex position defaults to (0 0 0)
583 MeshData::Vertex vertex;
584 // set normal for all vertices as (0 0 1) pointing outward from TextInput Actor.
587 for(std::size_t v = 0; iter != endIter; ++iter,v+=4 )
589 // Add each quad geometry (a sub-selection) to the mesh data.
599 QuadCoordinates& quad = *iter;
601 vertex.x = quad.min.x;
602 vertex.y = quad.min.y;
603 vertices.push_back( vertex );
606 vertex.x = quad.max.x;
607 vertex.y = quad.min.y;
608 vertices.push_back( vertex );
611 vertex.x = quad.min.x;
612 vertex.y = quad.max.y;
613 vertices.push_back( vertex );
615 // bottom-right (v+3)
616 vertex.x = quad.max.x;
617 vertex.y = quad.max.y;
618 vertices.push_back( vertex );
620 // triangle A (3, 1, 0)
621 faceIndices.push_back( v + 3 );
622 faceIndices.push_back( v + 1 );
623 faceIndices.push_back( v );
625 // triangle B (0, 2, 3)
626 faceIndices.push_back( v );
627 faceIndices.push_back( v + 2 );
628 faceIndices.push_back( v + 3 );
630 mHighlightMeshData.SetFaceIndices( faceIndices );
633 BoneContainer bones(0); // passed empty as bones not required
634 mHighlightMeshData.SetData( vertices, faceIndices, bones, mHighlightMaterial );
635 mHighlightMesh.UpdateMeshData( mHighlightMeshData );
639 void OnTap( Actor actor, const TapGesture& tap )
641 if( actor == mGrabHandle )
647 void OnPan( Actor actor, const PanGesture& gesture )
649 if( actor == mGrabArea )
651 if( Gesture::Started == gesture.state )
653 mGrabDisplacementX = mGrabDisplacementY = 0;
656 mGrabDisplacementX += gesture.displacement.x;
657 mGrabDisplacementY += gesture.displacement.y;
659 const float x = mCursor[PRIMARY_CURSOR].position.x + mGrabDisplacementX;
660 const float y = mCursor[PRIMARY_CURSOR].position.y + mCursor[PRIMARY_CURSOR].lineHeight*0.5f + mGrabDisplacementY;
662 if( Gesture::Started == gesture.state ||
663 Gesture::Continuing == gesture.state )
665 mObserver.GrabHandleEvent( GRAB_HANDLE_PRESSED, x, y );
667 else if( Gesture::Finished == gesture.state ||
668 Gesture::Cancelled == gesture.state )
670 mObserver.GrabHandleEvent( GRAB_HANDLE_RELEASED, x, y );
675 bool OnHandleOneTouched( Actor actor, const TouchEvent& touch )
681 bool OnHandleTwoTouched( Actor actor, const TouchEvent& touch )
689 float AlternatePopUpPositionRelativeToCursor()
691 float alternativePosition=0.0f;;
693 if ( mPrimaryCursor ) // Secondary cursor not used for paste
695 Cursor cursor = PRIMARY_CURSOR;
696 alternativePosition = mCursor[cursor].position.y;
699 const float popupHeight = 120.0f; // todo Set as a MaxSize Property in Control or retrieve from CopyPastePopup class.
701 if( mActiveGrabHandle )
703 // If grab handle enabled then position pop-up below the grab handle.
704 const Vector2 grabHandleSize( 59.0f, 56.0f ); // todo
705 const float BOTTOM_HANDLE_BOTTOM_OFFSET = 1.5; //todo Should be a property
706 alternativePosition += grabHandleSize.height + popupHeight + BOTTOM_HANDLE_BOTTOM_OFFSET ;
710 alternativePosition += popupHeight;
713 return alternativePosition;
716 void PopUpLeavesVerticalBoundary( PropertyNotification& source )
718 float alternativeYPosition=0.0f;
720 // if( mHighlightMeshActor ) // Text Selection mode
722 // alternativePosition = AlternatePopUpPositionRelativeToSelectionHandles();
724 // else // Not in Text Selection mode
726 // if can't be positioned above, then position below row.
727 alternativeYPosition = AlternatePopUpPositionRelativeToCursor();
729 mCopyPastePopup.SetY( alternativeYPosition );
733 void SetUpPopUpPositionNotifications( )
735 // Note Property notifications ignore any set anchor point so conditions must allow for this. Default is Top Left.
737 // Exceeding vertical boundary
739 Vector4 worldCoordinatesBoundingBox;
740 LocalToWorldCoordinatesBoundingBox( mBoundingBox, worldCoordinatesBoundingBox );
742 float popupHeight = mCopyPastePopup.GetRelayoutSize( Dimension::HEIGHT);
744 PropertyNotification verticalExceedNotification = mCopyPastePopup.AddPropertyNotification( Actor::Property::WORLD_POSITION_Y,
745 OutsideCondition( worldCoordinatesBoundingBox.y + popupHeight/2,
746 worldCoordinatesBoundingBox.w - popupHeight/2 ) );
748 verticalExceedNotification.NotifySignal().Connect( this, &Decorator::Impl::PopUpLeavesVerticalBoundary );
751 void GetConstrainedPopupPosition( Vector3& requiredPopupPosition, Vector3& popupSize, Vector3 anchorPoint, Actor& parent, Rect<int>& boundingBox )
753 DALI_ASSERT_DEBUG ( "Popup parent not on stage" && parent.OnStage() )
755 // Parent must already by added to Stage for these Get calls to work
756 Vector3 parentAnchorPoint = parent.GetCurrentAnchorPoint();
757 Vector3 parentWorldPositionLeftAnchor = parent.GetCurrentWorldPosition() - parent.GetCurrentSize()*parentAnchorPoint;
758 Vector3 popupWorldPosition = parentWorldPositionLeftAnchor + requiredPopupPosition; // Parent World position plus popup local position gives World Position
759 Vector3 popupDistanceFromAnchorPoint = popupSize*anchorPoint;
761 // Bounding rectangle is supplied as screen coordinates, bounding will be done in world coordinates.
762 Vector4 boundingRectangleWorld;
763 LocalToWorldCoordinatesBoundingBox( boundingBox, boundingRectangleWorld );
765 // Calculate distance to move popup (in local space) so fits within the boundary
766 float xOffSetToKeepWithinBounds = 0.0f;
767 if( popupWorldPosition.x - popupDistanceFromAnchorPoint.x < boundingRectangleWorld.x )
769 xOffSetToKeepWithinBounds = boundingRectangleWorld.x - ( popupWorldPosition.x - popupDistanceFromAnchorPoint.x );
771 else if ( popupWorldPosition.x + popupDistanceFromAnchorPoint.x > boundingRectangleWorld.z )
773 xOffSetToKeepWithinBounds = boundingRectangleWorld.z - ( popupWorldPosition.x + popupDistanceFromAnchorPoint.x );
776 // Ensure initial display of Popup is in alternative position if can not fit above. As Property notification will be a frame behind.
777 if ( popupWorldPosition.y - popupDistanceFromAnchorPoint.y < boundingRectangleWorld.y )
779 requiredPopupPosition.y = AlternatePopUpPositionRelativeToCursor();
782 requiredPopupPosition.x = requiredPopupPosition.x + xOffSetToKeepWithinBounds;
785 Internal::Control& mTextControlParent;
788 TapGestureDetector mTapDetector;
789 PanGestureDetector mPanGestureDetector;
790 Timer mCursorBlinkTimer; ///< Timer to signal cursor to blink
792 Layer mActiveLayer; ///< Layer for active handles and alike that ensures they are above all else.
793 ImageActor mPrimaryCursor;
794 ImageActor mSecondaryCursor;
795 ImageActor mGrabHandle;
797 MeshActor mHighlightMeshActor; ///< Mesh Actor to display highlight
798 TextSelectionPopup mCopyPastePopup;
801 Image mGrabHandleImage;
802 Mesh mHighlightMesh; ///< Mesh for highlight
803 MeshData mHighlightMeshData; ///< Mesh Data for highlight
804 Material mHighlightMaterial; ///< Material used for highlight
806 CursorImpl mCursor[CURSOR_COUNT];
807 SelectionHandleImpl mSelectionHandle[SELECTION_HANDLE_COUNT];
808 QuadContainer mHighlightQuadList; ///< Sub-selections that combine to create the complete selection highlight
810 Rect<int> mBoundingBox;
811 Vector4 mHighlightColor; ///< Color of the highlight
813 unsigned int mActiveCursor;
814 unsigned int mCursorBlinkInterval;
815 float mCursorBlinkDuration;
816 float mGrabDisplacementX;
817 float mGrabDisplacementY;
819 bool mActiveGrabHandle:1;
820 bool mActiveSelection:1;
821 bool mActiveCopyPastePopup:1;
822 bool mCursorBlinkStatus:1; ///< Flag to switch between blink on and blink off
825 DecoratorPtr Decorator::New( Internal::Control& parent, Observer& observer )
827 return DecoratorPtr( new Decorator(parent, observer) );
830 void Decorator::SetBoundingBox( const Rect<int>& boundingBox )
832 mImpl->mBoundingBox = boundingBox;
835 const Rect<int>& Decorator::GetBoundingBox() const
837 return mImpl->mBoundingBox;
840 void Decorator::Relayout( const Vector2& size, const Vector2& scrollPosition )
842 mImpl->Relayout( size, scrollPosition );
847 void Decorator::SetActiveCursor( ActiveCursor activeCursor )
849 mImpl->mActiveCursor = activeCursor;
852 unsigned int Decorator::GetActiveCursor() const
854 return mImpl->mActiveCursor;
857 void Decorator::SetPosition( Cursor cursor, float x, float y, float cursorHeight, float lineHeight )
859 // Adjust grab handle displacement
860 mImpl->mGrabDisplacementX -= x - mImpl->mCursor[cursor].position.x;
861 mImpl->mGrabDisplacementY -= y - mImpl->mCursor[cursor].position.y;
863 mImpl->mCursor[cursor].position.x = x;
864 mImpl->mCursor[cursor].position.y = y;
865 mImpl->mCursor[cursor].cursorHeight = cursorHeight;
866 mImpl->mCursor[cursor].lineHeight = lineHeight;
869 void Decorator::GetPosition( Cursor cursor, float& x, float& y, float& cursorHeight, float& lineHeight ) const
871 x = mImpl->mCursor[cursor].position.x;
872 y = mImpl->mCursor[cursor].position.y;
873 cursorHeight = mImpl->mCursor[cursor].cursorHeight;
874 lineHeight = mImpl->mCursor[cursor].lineHeight;
877 void Decorator::SetColor( Cursor cursor, const Dali::Vector4& color )
879 mImpl->mCursor[cursor].color = color;
882 const Dali::Vector4& Decorator::GetColor( Cursor cursor ) const
884 return mImpl->mCursor[cursor].color;
887 void Decorator::StartCursorBlink()
889 if ( !mImpl->mCursorBlinkTimer )
891 mImpl->mCursorBlinkTimer = Timer::New( mImpl->mCursorBlinkInterval );
892 mImpl->mCursorBlinkTimer.TickSignal().Connect( mImpl, &Decorator::Impl::OnCursorBlinkTimerTick );
895 if ( !mImpl->mCursorBlinkTimer.IsRunning() )
897 mImpl->mCursorBlinkTimer.Start();
901 void Decorator::StopCursorBlink()
903 if ( mImpl->mCursorBlinkTimer )
905 mImpl->mCursorBlinkTimer.Stop();
909 void Decorator::SetCursorBlinkInterval( float seconds )
911 mImpl->mCursorBlinkInterval = static_cast<unsigned int>( seconds * TO_MILLISECONDS ); // Convert to milliseconds
914 float Decorator::GetCursorBlinkInterval() const
916 return static_cast<float>( mImpl->mCursorBlinkInterval ) * TO_SECONDS;
919 void Decorator::SetCursorBlinkDuration( float seconds )
921 mImpl->mCursorBlinkDuration = seconds;
924 float Decorator::GetCursorBlinkDuration() const
926 return mImpl->mCursorBlinkDuration;
931 void Decorator::SetGrabHandleActive( bool active )
933 mImpl->mActiveGrabHandle = active;
936 bool Decorator::IsGrabHandleActive() const
938 return mImpl->mActiveGrabHandle;
941 void Decorator::SetGrabHandleImage( Dali::Image image )
943 mImpl->mGrabHandleImage = image;
946 Dali::Image Decorator::GetGrabHandleImage() const
948 return mImpl->mGrabHandleImage;
953 void Decorator::SetSelectionActive( bool active )
955 mImpl->mActiveSelection = active;
958 bool Decorator::IsSelectionActive() const
960 return mImpl->mActiveSelection;
963 void Decorator::SetPosition( SelectionHandle handle, float x, float y, float height )
965 mImpl->mSelectionHandle[handle].position.x = x;
966 mImpl->mSelectionHandle[handle].position.y = y;
967 mImpl->mSelectionHandle[handle].lineHeight = height;
970 void Decorator::GetPosition( SelectionHandle handle, float& x, float& y, float& height ) const
972 x = mImpl->mSelectionHandle[handle].position.x;
973 y = mImpl->mSelectionHandle[handle].position.y;
974 height = mImpl->mSelectionHandle[handle].lineHeight;
977 void Decorator::SetImage( SelectionHandle handle, SelectionHandleState state, Dali::Image image )
979 if( SELECTION_HANDLE_PRESSED == state )
981 mImpl->mSelectionHandle[handle].pressedImage = image;
985 mImpl->mSelectionHandle[handle].releasedImage = image;
989 Dali::Image Decorator::GetImage( SelectionHandle handle, SelectionHandleState state ) const
991 if( SELECTION_HANDLE_PRESSED == state )
993 return mImpl->mSelectionHandle[handle].pressedImage;
996 return mImpl->mSelectionHandle[handle].releasedImage;
999 void Decorator::AddHighlight( float x1, float y1, float x2, float y2 )
1001 mImpl->mHighlightQuadList.push_back( QuadCoordinates(x1, y1, x2, y2) );
1004 void Decorator::ClearHighlights()
1006 mImpl->mHighlightQuadList.clear();
1009 void Decorator::SetPopupActive( bool active )
1011 mImpl->mActiveCopyPastePopup = active;
1014 bool Decorator::IsPopupActive() const
1016 return mImpl->mActiveCopyPastePopup ;
1019 Decorator::~Decorator()
1024 Decorator::Decorator( Dali::Toolkit::Internal::Control& parent, Observer& observer )
1027 mImpl = new Decorator::Impl( parent, observer );
1032 } // namespace Toolkit