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
64 #ifdef DECORATOR_DEBUG
65 Integration::Log::Filter* gLogFilter( Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_TEXT_DECORATOR") );
76 const char* DEFAULT_GRAB_HANDLE_IMAGE( DALI_IMAGE_DIR "insertpoint-icon.png" );
77 const char* DEFAULT_SELECTION_HANDLE_ONE( DALI_IMAGE_DIR "text-input-selection-handle-left.png" );
78 const char* DEFAULT_SELECTION_HANDLE_TWO( DALI_IMAGE_DIR "text-input-selection-handle-right.png" );
79 //const char* DEFAULT_SELECTION_HANDLE_ONE_PRESSED( DALI_IMAGE_DIR "text-input-selection-handle-left-press.png" );
80 //const char* DEFAULT_SELECTION_HANDLE_TWO_PRESSED( DALI_IMAGE_DIR "text-input-selection-handle-right-press.png" );
82 const Dali::Vector3 DEFAULT_GRAB_HANDLE_RELATIVE_SIZE( 1.5f, 2.0f, 1.0f );
83 const Dali::Vector3 DEFAULT_SELECTION_HANDLE_RELATIVE_SIZE( 1.5f, 1.5f, 1.0f );
85 const std::size_t CURSOR_BLINK_INTERVAL = 500; // Cursor blink interval
86 const std::size_t MILLISECONDS = 1000;
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
161 color(Dali::Color::WHITE)
173 struct SelectionHandleImpl
175 SelectionHandleImpl()
185 float lineHeight; ///< Not the handle height
195 Impl( Dali::Toolkit::Internal::Control& parent, Observer& observer )
196 : mTextControlParent(parent),
198 mActiveCursor(ACTIVE_CURSOR_NONE),
199 mActiveGrabHandle(false),
200 mActiveSelection( false ),
201 mActiveCopyPastePopup( false ),
202 mCursorBlinkInterval( CURSOR_BLINK_INTERVAL ),
203 mCursorBlinkDuration( 0.0f ),
204 mCursorBlinkStatus( true ),
205 mGrabDisplacementX( 0.0f ),
206 mGrabDisplacementY( 0.0f ),
207 mHighlightColor( 0.07f, 0.41f, 0.59f, 1.0f ), // light blue
208 mBoundingBox( Rect<int>() )
213 * Relayout of the decorations owned by the decorator.
214 * @param[in] size The Size of the UI control the decorater is adding it's decorations to.
216 void Relayout( const Vector2& size, const Vector2& scrollPosition )
218 // TODO - Remove this if nothing is active
221 // Show or hide the cursors
225 mPrimaryCursor.SetPosition( mCursor[PRIMARY_CURSOR].x + scrollPosition.x,
226 mCursor[PRIMARY_CURSOR].y + scrollPosition.y );
227 mPrimaryCursor.SetSize( Size( 1.0f, mCursor[PRIMARY_CURSOR].cursorHeight ) );
229 if( mSecondaryCursor )
231 mSecondaryCursor.SetPosition( mCursor[SECONDARY_CURSOR].x + scrollPosition.x,
232 mCursor[SECONDARY_CURSOR].y + scrollPosition.y );
233 mSecondaryCursor.SetSize( Size( 1.0f, mCursor[SECONDARY_CURSOR].cursorHeight ) );
236 // Show or hide the grab handle
237 if( mActiveGrabHandle )
243 mGrabHandle.SetPosition( mCursor[PRIMARY_CURSOR].x + scrollPosition.x,
244 mCursor[PRIMARY_CURSOR].lineHeight + scrollPosition.y );
246 else if( mGrabHandle )
248 UnparentAndReset( mGrabHandle );
251 // Show or hide the selection handles/highlight
252 if( mActiveSelection )
256 CreateSelectionHandles();
258 SelectionHandleImpl& primary = mSelectionHandle[ PRIMARY_SELECTION_HANDLE ];
259 primary.actor.SetPosition( primary.x + scrollPosition.x,
260 primary.lineHeight + scrollPosition.y );
262 SelectionHandleImpl& secondary = mSelectionHandle[ SECONDARY_SELECTION_HANDLE ];
263 secondary.actor.SetPosition( secondary.x + scrollPosition.x,
264 secondary.lineHeight + scrollPosition.y );
271 UnparentAndReset( mSelectionHandle[ PRIMARY_SELECTION_HANDLE ].actor );
272 UnparentAndReset( mSelectionHandle[ SECONDARY_SELECTION_HANDLE ].actor );
273 UnparentAndReset( mHighlightMeshActor );
276 if ( mActiveCopyPastePopup )
278 if ( !mCopyPastePopup )
280 mCopyPastePopup = TextSelectionPopup::New();
281 #ifdef DECORATOR_DEBUG
282 mCopyPastePopup.SetName("mCopyPastePopup");
284 mCopyPastePopup.SetAnchorPoint( AnchorPoint::CENTER );
285 mCopyPastePopup.OnRelayoutSignal().Connect( this, &Decorator::Impl::PopUpRelayoutComplete ); // Position popup after size negotiation
286 mActiveLayer.Add ( mCopyPastePopup );
291 if ( mCopyPastePopup )
293 UnparentAndReset( mCopyPastePopup );
298 void PopUpRelayoutComplete( Actor actor )
300 // Size negotiation for CopyPastePopup complete so can get the size and constrain position within bounding box.
302 mCopyPastePopup.OnRelayoutSignal().Disconnect( this, &Decorator::Impl::PopUpRelayoutComplete );
304 Vector3 popupPosition( mCursor[PRIMARY_CURSOR].x, mCursor[PRIMARY_CURSOR].y -100.0f , 0.0f); //todo 100 to be an offset Property
306 Vector3 popupSize = Vector3( mCopyPastePopup.GetRelayoutSize( Dimension::WIDTH ), mCopyPastePopup.GetRelayoutSize( Dimension::HEIGHT ), 0.0f );
308 GetConstrainedPopupPosition( popupPosition, popupSize, AnchorPoint::CENTER, mActiveLayer, mBoundingBox );
310 SetUpPopUpPositionNotifications();
312 mCopyPastePopup.SetPosition( popupPosition ); //todo grabhandle(cursor) or selection handle positions to be used
315 void CreateCursor( ImageActor& cursor )
317 cursor = CreateSolidColorActor( Color::WHITE );
318 cursor.SetParentOrigin( ParentOrigin::TOP_LEFT ); // Need to set the default parent origin as CreateSolidColorActor() sets a different one.
319 cursor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
320 cursor.SetRelayoutEnabled( false );
323 // Add or Remove cursor(s) from parent
326 if( mActiveCursor == ACTIVE_CURSOR_NONE )
328 UnparentAndReset( mPrimaryCursor );
329 UnparentAndReset( mSecondaryCursor );
333 /* Create Primary and or Secondary Cursor(s) if active and add to parent */
334 if ( mActiveCursor == ACTIVE_CURSOR_PRIMARY ||
335 mActiveCursor == ACTIVE_CURSOR_BOTH )
337 if ( !mPrimaryCursor )
339 CreateCursor( mPrimaryCursor );
340 #ifdef DECORATOR_DEBUG
341 mPrimaryCursor.SetName( "PrimaryCursorActor" );
343 mActiveLayer.Add( mPrimaryCursor);
347 if ( mActiveCursor == ACTIVE_CURSOR_BOTH )
349 if ( !mSecondaryCursor )
351 CreateCursor( mSecondaryCursor );
352 #ifdef DECORATOR_DEBUG
353 mSecondaryCursor.SetName( "SecondaryCursorActor" );
355 mActiveLayer.Add( mSecondaryCursor);
360 UnparentAndReset( mSecondaryCursor );
365 bool OnCursorBlinkTimerTick()
368 if ( mPrimaryCursor )
370 mPrimaryCursor.SetVisible( mCursorBlinkStatus );
372 if ( mSecondaryCursor )
374 mSecondaryCursor.SetVisible( mCursorBlinkStatus );
377 mCursorBlinkStatus = !mCursorBlinkStatus;
382 void SetupTouchEvents()
386 mTapDetector = TapGestureDetector::New();
387 mTapDetector.DetectedSignal().Connect( this, &Decorator::Impl::OnTap );
390 if ( !mPanGestureDetector )
392 mPanGestureDetector = PanGestureDetector::New();
393 mPanGestureDetector.DetectedSignal().Connect( this, &Decorator::Impl::OnPan );
397 void CreateActiveLayer()
401 Actor parent = mTextControlParent.Self();
403 mActiveLayer = Layer::New();
404 #ifdef DECORATOR_DEBUG
405 mActiveLayer.SetName ( "ActiveLayerActor" );
408 mActiveLayer.SetParentOrigin( ParentOrigin::CENTER );
409 mActiveLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
410 mActiveLayer.SetPositionInheritanceMode( USE_PARENT_POSITION );
412 parent.Add( mActiveLayer );
415 mActiveLayer.RaiseToTop();
418 void CreateGrabHandle()
422 if ( !mGrabHandleImage )
424 mGrabHandleImage = ResourceImage::New( DEFAULT_GRAB_HANDLE_IMAGE );
427 mGrabHandle = ImageActor::New( mGrabHandleImage );
428 mGrabHandle.SetAnchorPoint( AnchorPoint::TOP_CENTER );
429 mGrabHandle.SetDrawMode( DrawMode::OVERLAY );
430 // Area that Grab handle responds to, larger than actual handle so easier to move
431 #ifdef DECORATOR_DEBUG
432 mGrabHandle.SetName( "GrabHandleActor" );
433 if ( Dali::Internal::gLogFilter->IsEnabledFor( Debug::Verbose ) )
435 mGrabArea = Toolkit::CreateSolidColorActor( Vector4(0.0f, 0.0f, 0.0f, 0.0f), true, Color::RED, 1 );
436 mGrabArea.SetName( "GrabArea" );
440 mGrabArea = Actor::New();
441 mGrabArea.SetRelayoutEnabled( true );
442 mGrabArea.SetName( "GrabArea" );
445 mGrabArea = Actor::New();
446 mGrabArea.SetRelayoutEnabled( true );
449 mGrabArea.SetParentOrigin( ParentOrigin::TOP_CENTER );
450 mGrabArea.SetAnchorPoint( AnchorPoint::TOP_CENTER );
451 mGrabArea.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
452 mGrabArea.SetSizeModeFactor( DEFAULT_GRAB_HANDLE_RELATIVE_SIZE );
453 mGrabHandle.Add( mGrabArea );
455 mTapDetector.Attach( mGrabArea );
456 mPanGestureDetector.Attach( mGrabArea );
458 mActiveLayer.Add( mGrabHandle );
462 void CreateSelectionHandles()
464 SelectionHandleImpl& primary = mSelectionHandle[ PRIMARY_SELECTION_HANDLE ];
465 if ( !primary.actor )
467 if ( !primary.releasedImage )
469 primary.releasedImage = ResourceImage::New( DEFAULT_SELECTION_HANDLE_ONE );
472 primary.actor = ImageActor::New( primary.releasedImage );
473 #ifdef DECORATOR_DEBUG
474 primary.actor.SetName("SelectionHandleOne");
476 primary.actor.SetAnchorPoint( AnchorPoint::TOP_RIGHT ); // Change to BOTTOM_RIGHT if Look'n'Feel requires handle above text.
477 primary.actor.SetDrawMode( DrawMode::OVERLAY ); // ensure grab handle above text
478 primary.flipped = false;
480 primary.grabArea = Actor::New(); // Area that Grab handle responds to, larger than actual handle so easier to move
481 primary.grabArea.SetRelayoutEnabled( true );
482 #ifdef DECORATOR_DEBUG
483 primary.grabArea.SetName("SelectionHandleOneGrabArea");
485 primary.grabArea.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
486 primary.grabArea.SetSizeModeFactor( DEFAULT_SELECTION_HANDLE_RELATIVE_SIZE );
487 primary.grabArea.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION );
489 mTapDetector.Attach( primary.grabArea );
490 mPanGestureDetector.Attach( primary.grabArea );
491 primary.grabArea.TouchedSignal().Connect( this, &Decorator::Impl::OnHandleOneTouched );
493 primary.actor.Add( primary.grabArea );
494 mActiveLayer.Add( primary.actor );
497 SelectionHandleImpl& secondary = mSelectionHandle[ SECONDARY_SELECTION_HANDLE ];
498 if ( !secondary.actor )
500 if ( !secondary.releasedImage )
502 secondary.releasedImage = ResourceImage::New( DEFAULT_SELECTION_HANDLE_TWO );
505 secondary.actor = ImageActor::New( secondary.releasedImage );
506 #ifdef DECORATOR_DEBUG
507 secondary.actor.SetName("SelectionHandleTwo");
509 secondary.actor.SetAnchorPoint( AnchorPoint::TOP_LEFT ); // Change to BOTTOM_LEFT if Look'n'Feel requires handle above text.
510 secondary.actor.SetDrawMode( DrawMode::OVERLAY ); // ensure grab handle above text
511 secondary.flipped = false;
513 secondary.grabArea = Actor::New(); // Area that Grab handle responds to, larger than actual handle so easier to move
514 secondary.grabArea.SetRelayoutEnabled( true );
515 #ifdef DECORATOR_DEBUG
516 secondary.grabArea.SetName("SelectionHandleTwoGrabArea");
518 secondary.grabArea.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
519 secondary.grabArea.SetSizeModeFactor( DEFAULT_SELECTION_HANDLE_RELATIVE_SIZE );
520 secondary.grabArea.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION );
522 mTapDetector.Attach( secondary.grabArea );
523 mPanGestureDetector.Attach( secondary.grabArea );
524 secondary.grabArea.TouchedSignal().Connect( this, &Decorator::Impl::OnHandleTwoTouched );
526 secondary.actor.Add( secondary.grabArea );
527 mActiveLayer.Add( secondary.actor );
530 //SetUpHandlePropertyNotifications(); TODO
533 void CreateHighlight()
535 if ( !mHighlightMeshActor )
537 mHighlightMaterial = Material::New( "HighlightMaterial" );
538 mHighlightMaterial.SetDiffuseColor( mHighlightColor );
540 mHighlightMeshData.SetMaterial( mHighlightMaterial );
541 mHighlightMeshData.SetHasNormals( true );
543 mHighlightMesh = Mesh::New( mHighlightMeshData );
545 mHighlightMeshActor = MeshActor::New( mHighlightMesh );
546 #ifdef DECORATOR_DEBUG
547 mHighlightMeshActor.SetName( "HighlightMeshActor" );
549 mHighlightMeshActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
550 mHighlightMeshActor.SetPosition( 0.0f, 0.0f, DISPLAYED_HIGHLIGHT_Z_OFFSET );
552 Actor parent = mTextControlParent.Self();
553 parent.Add( mHighlightMeshActor );
557 void UpdateHighlight()
559 // Construct a Mesh with a texture to be used as the highlight 'box' for selected text
561 // Example scenarios where mesh is made from 3, 1, 2, 2 ,3 or 3 quads.
563 // [ TOP ] [ TOP ] [TOP ] [ TOP ] [ TOP ] [ TOP ]
564 // [ MIDDLE ] [BOTTOM] [BOTTOM] [ MIDDLE ] [ MIDDLE ]
565 // [ BOTTOM] [ MIDDLE ] [ MIDDLE ]
566 // [BOTTOM] [ MIDDLE ]
569 // Each quad is created as 2 triangles.
570 // Middle is just 1 quad regardless of its size.
584 if ( mHighlightMesh && mHighlightMaterial && !mHighlightQuadList.empty() )
586 MeshData::VertexContainer vertices;
587 Dali::MeshData::FaceIndices faceIndices;
589 std::vector<QuadCoordinates>::iterator iter = mHighlightQuadList.begin();
590 std::vector<QuadCoordinates>::iterator endIter = mHighlightQuadList.end();
592 // vertex position defaults to (0 0 0)
593 MeshData::Vertex vertex;
594 // set normal for all vertices as (0 0 1) pointing outward from TextInput Actor.
597 for(std::size_t v = 0; iter != endIter; ++iter,v+=4 )
599 // Add each quad geometry (a sub-selection) to the mesh data.
609 QuadCoordinates& quad = *iter;
611 vertex.x = quad.min.x;
612 vertex.y = quad.min.y;
613 vertices.push_back( vertex );
616 vertex.x = quad.max.x;
617 vertex.y = quad.min.y;
618 vertices.push_back( vertex );
621 vertex.x = quad.min.x;
622 vertex.y = quad.max.y;
623 vertices.push_back( vertex );
625 // bottom-right (v+3)
626 vertex.x = quad.max.x;
627 vertex.y = quad.max.y;
628 vertices.push_back( vertex );
630 // triangle A (3, 1, 0)
631 faceIndices.push_back( v + 3 );
632 faceIndices.push_back( v + 1 );
633 faceIndices.push_back( v );
635 // triangle B (0, 2, 3)
636 faceIndices.push_back( v );
637 faceIndices.push_back( v + 2 );
638 faceIndices.push_back( v + 3 );
640 mHighlightMeshData.SetFaceIndices( faceIndices );
643 BoneContainer bones(0); // passed empty as bones not required
644 mHighlightMeshData.SetData( vertices, faceIndices, bones, mHighlightMaterial );
645 mHighlightMesh.UpdateMeshData( mHighlightMeshData );
649 void OnTap( Actor actor, const TapGesture& tap )
651 if( actor == mGrabHandle )
657 void OnPan( Actor actor, const PanGesture& gesture )
659 if( actor == mGrabArea )
661 if( Gesture::Started == gesture.state )
663 mGrabDisplacementX = mGrabDisplacementY = 0;
666 mGrabDisplacementX += gesture.displacement.x;
667 mGrabDisplacementY += gesture.displacement.y;
669 float x = mCursor[PRIMARY_CURSOR].x + mGrabDisplacementX;
670 float y = mCursor[PRIMARY_CURSOR].y + mCursor[PRIMARY_CURSOR].lineHeight*0.5f + mGrabDisplacementY;
672 if( Gesture::Started == gesture.state ||
673 Gesture::Continuing == gesture.state )
675 mObserver.GrabHandleEvent( GRAB_HANDLE_PRESSED, x, y );
677 else if( Gesture::Finished == gesture.state ||
678 Gesture::Cancelled == gesture.state )
680 mObserver.GrabHandleEvent( GRAB_HANDLE_RELEASED, x, y );
685 bool OnHandleOneTouched( Actor actor, const TouchEvent& touch )
691 bool OnHandleTwoTouched( Actor actor, const TouchEvent& touch )
699 float AlternatePopUpPositionRelativeToCursor()
701 float alternativePosition=0.0f;;
703 if ( mPrimaryCursor ) // Secondary cursor not used for paste
705 Cursor cursor = PRIMARY_CURSOR;
706 alternativePosition = mCursor[cursor].y;
709 const float popupHeight = 120.0f; // todo Set as a MaxSize Property in Control or retrieve from CopyPastePopup class.
711 if ( mActiveGrabHandle )
713 // If grab handle enabled then position pop-up below the grab handle.
714 const Vector2 grabHandleSize( 59.0f, 56.0f ); // todo
715 const float BOTTOM_HANDLE_BOTTOM_OFFSET = 1.5; //todo Should be a property
716 alternativePosition += grabHandleSize.height + popupHeight + BOTTOM_HANDLE_BOTTOM_OFFSET ;
720 alternativePosition += popupHeight;
723 return alternativePosition;
726 void PopUpLeavesVerticalBoundary( PropertyNotification& source )
728 float alternativeYPosition=0.0f;
730 // if( mHighlightMeshActor ) // Text Selection mode
732 // alternativePosition = AlternatePopUpPositionRelativeToSelectionHandles();
734 // else // Not in Text Selection mode
736 // if can't be positioned above, then position below row.
737 alternativeYPosition = AlternatePopUpPositionRelativeToCursor();
739 mCopyPastePopup.SetY( alternativeYPosition );
743 void SetUpPopUpPositionNotifications( )
745 // Note Property notifications ignore any set anchor point so conditions must allow for this. Default is Top Left.
747 // Exceeding vertical boundary
749 Vector4 worldCoordinatesBoundingBox;
750 LocalToWorldCoordinatesBoundingBox( mBoundingBox, worldCoordinatesBoundingBox );
752 float popupHeight = mCopyPastePopup.GetRelayoutSize( Dimension::HEIGHT);
754 PropertyNotification verticalExceedNotification = mCopyPastePopup.AddPropertyNotification( Actor::Property::WORLD_POSITION_Y,
755 OutsideCondition( worldCoordinatesBoundingBox.y + popupHeight/2,
756 worldCoordinatesBoundingBox.w - popupHeight/2 ) );
758 verticalExceedNotification.NotifySignal().Connect( this, &Decorator::Impl::PopUpLeavesVerticalBoundary );
761 void GetConstrainedPopupPosition( Vector3& requiredPopupPosition, Vector3& popupSize, Vector3 anchorPoint, Actor& parent, Rect<int>& boundingBox )
763 DALI_ASSERT_DEBUG ( "Popup parent not on stage" && parent.OnStage() )
765 // Parent must already by added to Stage for these Get calls to work
766 Vector3 parentAnchorPoint = parent.GetCurrentAnchorPoint();
767 Vector3 parentWorldPositionLeftAnchor = parent.GetCurrentWorldPosition() - parent.GetCurrentSize()*parentAnchorPoint;
768 Vector3 popupWorldPosition = parentWorldPositionLeftAnchor + requiredPopupPosition; // Parent World position plus popup local position gives World Position
769 Vector3 popupDistanceFromAnchorPoint = popupSize*anchorPoint;
771 // Bounding rectangle is supplied as screen coordinates, bounding will be done in world coordinates.
772 Vector4 boundingRectangleWorld;
773 LocalToWorldCoordinatesBoundingBox( boundingBox, boundingRectangleWorld );
775 // Calculate distance to move popup (in local space) so fits within the boundary
776 float xOffSetToKeepWithinBounds = 0.0f;
777 if( popupWorldPosition.x - popupDistanceFromAnchorPoint.x < boundingRectangleWorld.x )
779 xOffSetToKeepWithinBounds = boundingRectangleWorld.x - ( popupWorldPosition.x - popupDistanceFromAnchorPoint.x );
781 else if ( popupWorldPosition.x + popupDistanceFromAnchorPoint.x > boundingRectangleWorld.z )
783 xOffSetToKeepWithinBounds = boundingRectangleWorld.z - ( popupWorldPosition.x + popupDistanceFromAnchorPoint.x );
786 // Ensure initial display of Popup is in alternative position if can not fit above. As Property notification will be a frame behind.
787 if ( popupWorldPosition.y - popupDistanceFromAnchorPoint.y < boundingRectangleWorld.y )
789 requiredPopupPosition.y = AlternatePopUpPositionRelativeToCursor();
792 requiredPopupPosition.x = requiredPopupPosition.x + xOffSetToKeepWithinBounds;
795 Internal::Control& mTextControlParent;
798 Layer mActiveLayer; // Layer for active handles and alike that ensures they are above all else.
800 unsigned int mActiveCursor;
801 bool mActiveGrabHandle;
802 bool mActiveSelection;
803 bool mActiveCopyPastePopup;
805 CursorImpl mCursor[CURSOR_COUNT];
807 Timer mCursorBlinkTimer; // Timer to signal cursor to blink
808 unsigned int mCursorBlinkInterval;
809 float mCursorBlinkDuration;
810 bool mCursorBlinkStatus; // Flag to switch between blink on and blink off
812 ImageActor mPrimaryCursor;
813 ImageActor mSecondaryCursor;
815 ImageActor mGrabHandle;
817 float mGrabDisplacementX;
818 float mGrabDisplacementY;
820 SelectionHandleImpl mSelectionHandle[SELECTION_HANDLE_COUNT];
822 MeshActor mHighlightMeshActor; ///< Mesh Actor to display highlight
823 Mesh mHighlightMesh; ///< Mesh for highlight
824 MeshData mHighlightMeshData; ///< Mesh Data for highlight
825 Material mHighlightMaterial; ///< Material used for highlight
826 Vector4 mHighlightColor; ///< Color of the highlight
827 QuadContainer mHighlightQuadList; ///< Sub-selections that combine to create the complete selection highlight
829 TextSelectionPopup mCopyPastePopup;
832 Image mGrabHandleImage;
834 TapGestureDetector mTapDetector;
835 PanGestureDetector mPanGestureDetector;
837 Rect<int> mBoundingBox;
840 DecoratorPtr Decorator::New( Internal::Control& parent, Observer& observer )
842 return DecoratorPtr( new Decorator(parent, observer) );
845 void Decorator::SetBoundingBox( const Rect<int>& boundingBox )
847 mImpl->mBoundingBox = boundingBox;
850 const Rect<int>& Decorator::GetBoundingBox() const
852 return mImpl->mBoundingBox;
855 void Decorator::Relayout( const Vector2& size, const Vector2& scrollPosition )
857 mImpl->Relayout( size, scrollPosition );
862 void Decorator::SetActiveCursor( ActiveCursor activeCursor )
864 mImpl->mActiveCursor = activeCursor;
867 unsigned int Decorator::GetActiveCursor() const
869 return mImpl->mActiveCursor;
872 void Decorator::SetPosition( Cursor cursor, float x, float y, float cursorHeight, float lineHeight )
874 // Adjust grab handle displacement
875 mImpl->mGrabDisplacementX -= x - mImpl->mCursor[cursor].x;
876 mImpl->mGrabDisplacementY -= y - mImpl->mCursor[cursor].y;
878 mImpl->mCursor[cursor].x = x;
879 mImpl->mCursor[cursor].y = y;
880 mImpl->mCursor[cursor].cursorHeight = cursorHeight;
881 mImpl->mCursor[cursor].lineHeight = lineHeight;
884 void Decorator::GetPosition( Cursor cursor, float& x, float& y, float& cursorHeight, float& lineHeight ) const
886 x = mImpl->mCursor[cursor].x;
887 y = mImpl->mCursor[cursor].y;
888 cursorHeight = mImpl->mCursor[cursor].cursorHeight;
889 lineHeight = mImpl->mCursor[cursor].lineHeight;
892 void Decorator::SetColor( Cursor cursor, const Dali::Vector4& color )
894 mImpl->mCursor[cursor].color = color;
897 const Dali::Vector4& Decorator::GetColor( Cursor cursor ) const
899 return mImpl->mCursor[cursor].color;
902 void Decorator::StartCursorBlink()
904 if ( !mImpl->mCursorBlinkTimer )
906 mImpl->mCursorBlinkTimer = Timer::New( mImpl->mCursorBlinkInterval );
907 mImpl->mCursorBlinkTimer.TickSignal().Connect( mImpl, &Decorator::Impl::OnCursorBlinkTimerTick );
910 if ( !mImpl->mCursorBlinkTimer.IsRunning() )
912 mImpl->mCursorBlinkTimer.Start();
916 void Decorator::StopCursorBlink()
918 if ( mImpl->mCursorBlinkTimer )
920 mImpl->mCursorBlinkTimer.Stop();
924 void Decorator::SetCursorBlinkInterval( float seconds )
926 mImpl->mCursorBlinkInterval = seconds*MILLISECONDS; // Convert to milliseconds
929 float Decorator::GetCursorBlinkInterval() const
931 return mImpl->mCursorBlinkInterval;
934 void Decorator::SetCursorBlinkDuration( float seconds )
936 mImpl->mCursorBlinkDuration = seconds;
939 float Decorator::GetCursorBlinkDuration() const
941 return mImpl->mCursorBlinkDuration;
946 void Decorator::SetGrabHandleActive( bool active )
948 mImpl->mActiveGrabHandle = active;
951 bool Decorator::IsGrabHandleActive() const
953 return mImpl->mActiveGrabHandle;
956 void Decorator::SetGrabHandleImage( Dali::Image image )
958 mImpl->mGrabHandleImage = image;
961 Dali::Image Decorator::GetGrabHandleImage() const
963 return mImpl->mGrabHandleImage;
968 void Decorator::SetSelectionActive( bool active )
970 mImpl->mActiveSelection = active;
973 bool Decorator::IsSelectionActive() const
975 return mImpl->mActiveSelection;
978 void Decorator::SetPosition( SelectionHandle handle, float x, float y, float height )
980 mImpl->mSelectionHandle[handle].x = x;
981 mImpl->mSelectionHandle[handle].y = y;
982 mImpl->mSelectionHandle[handle].lineHeight = height;
985 void Decorator::GetPosition( SelectionHandle handle, float& x, float& y, float& height ) const
987 x = mImpl->mSelectionHandle[handle].x;
988 y = mImpl->mSelectionHandle[handle].y;
989 height = mImpl->mSelectionHandle[handle].lineHeight;
992 void Decorator::SetImage( SelectionHandle handle, SelectionHandleState state, Dali::Image image )
994 if( SELECTION_HANDLE_PRESSED == state )
996 mImpl->mSelectionHandle[handle].pressedImage = image;
1000 mImpl->mSelectionHandle[handle].releasedImage = image;
1004 Dali::Image Decorator::GetImage( SelectionHandle handle, SelectionHandleState state ) const
1006 if( SELECTION_HANDLE_PRESSED == state )
1008 return mImpl->mSelectionHandle[handle].pressedImage;
1011 return mImpl->mSelectionHandle[handle].releasedImage;
1014 void Decorator::AddHighlight( float x1, float y1, float x2, float y2 )
1016 mImpl->mHighlightQuadList.push_back( QuadCoordinates(x1, y1, x2, y2) );
1019 void Decorator::ClearHighlights()
1021 mImpl->mHighlightQuadList.clear();
1024 void Decorator::SetPopupActive( bool active )
1026 mImpl->mActiveCopyPastePopup = active;
1029 bool Decorator::IsPopupActive() const
1031 return mImpl->mActiveCopyPastePopup ;
1034 Decorator::~Decorator()
1039 Decorator::Decorator( Dali::Toolkit::Internal::Control& parent, Observer& observer )
1042 mImpl = new Decorator::Impl( parent, observer );
1047 } // namespace Toolkit