+ // Popup
+
+ float AlternatePopUpPositionRelativeToCursor()
+ {
+ float alternativePosition=0.0f;;
+
+ if ( mPrimaryCursor ) // Secondary cursor not used for paste
+ {
+ Cursor cursor = PRIMARY_CURSOR;
+ alternativePosition = mCursor[cursor].y;
+ }
+
+ const float popupHeight = 120.0f; // todo Set as a MaxSize Property in Control or retrieve from CopyPastePopup class.
+
+ if ( mActiveGrabHandle )
+ {
+ // If grab handle enabled then position pop-up below the grab handle.
+ const Vector2 grabHandleSize( 59.0f, 56.0f ); // todo
+ const float BOTTOM_HANDLE_BOTTOM_OFFSET = 1.5; //todo Should be a property
+ alternativePosition += grabHandleSize.height + popupHeight + BOTTOM_HANDLE_BOTTOM_OFFSET ;
+ }
+ else
+ {
+ alternativePosition += popupHeight;
+ }
+
+ return alternativePosition;
+ }
+
+ void PopUpLeavesVerticalBoundary( PropertyNotification& source )
+ {
+ float alternativeYPosition=0.0f;
+ // todo
+ // if( mHighlightMeshActor ) // Text Selection mode
+ // {
+ // alternativePosition = AlternatePopUpPositionRelativeToSelectionHandles();
+ // }
+ // else // Not in Text Selection mode
+ // {
+ // if can't be positioned above, then position below row.
+ alternativeYPosition = AlternatePopUpPositionRelativeToCursor();
+ // }
+ mCopyPastePopup.SetY( alternativeYPosition );
+ }
+
+
+ void SetUpPopUpPositionNotifications( )
+ {
+ // Note Property notifications ignore any set anchor point so conditions must allow for this. Default is Top Left.
+
+ // Exceeding vertical boundary
+
+ Vector4 worldCoordinatesBoundingBox;
+ LocalToWorldCoordinatesBoundingBox( mBoundingBox, worldCoordinatesBoundingBox );
+
+ float popupHeight = mCopyPastePopup.GetRelayoutSize( Dimension::HEIGHT);
+
+ PropertyNotification verticalExceedNotification = mCopyPastePopup.AddPropertyNotification( Actor::Property::WORLD_POSITION_Y,
+ OutsideCondition( worldCoordinatesBoundingBox.y + popupHeight/2,
+ worldCoordinatesBoundingBox.w - popupHeight/2 ) );
+
+ verticalExceedNotification.NotifySignal().Connect( this, &Decorator::Impl::PopUpLeavesVerticalBoundary );
+ }
+
+ void GetConstrainedPopupPosition( Vector3& requiredPopupPosition, Vector3& popupSize, Vector3 anchorPoint, Actor& parent, Rect<int>& boundingBox )
+ {
+ DALI_ASSERT_DEBUG ( "Popup parent not on stage" && parent.OnStage() )
+
+ // Parent must already by added to Stage for these Get calls to work
+ Vector3 parentAnchorPoint = parent.GetCurrentAnchorPoint();
+ Vector3 parentWorldPositionLeftAnchor = parent.GetCurrentWorldPosition() - parent.GetCurrentSize()*parentAnchorPoint;
+ Vector3 popupWorldPosition = parentWorldPositionLeftAnchor + requiredPopupPosition; // Parent World position plus popup local position gives World Position
+ Vector3 popupDistanceFromAnchorPoint = popupSize*anchorPoint;
+
+ // Bounding rectangle is supplied as screen coordinates, bounding will be done in world coordinates.
+ Vector4 boundingRectangleWorld;
+ LocalToWorldCoordinatesBoundingBox( boundingBox, boundingRectangleWorld );
+
+ // Calculate distance to move popup (in local space) so fits within the boundary
+ float xOffSetToKeepWithinBounds = 0.0f;
+ if( popupWorldPosition.x - popupDistanceFromAnchorPoint.x < boundingRectangleWorld.x )
+ {
+ xOffSetToKeepWithinBounds = boundingRectangleWorld.x - ( popupWorldPosition.x - popupDistanceFromAnchorPoint.x );
+ }
+ else if ( popupWorldPosition.x + popupDistanceFromAnchorPoint.x > boundingRectangleWorld.z )
+ {
+ xOffSetToKeepWithinBounds = boundingRectangleWorld.z - ( popupWorldPosition.x + popupDistanceFromAnchorPoint.x );
+ }
+
+ // Ensure initial display of Popup is in alternative position if can not fit above. As Property notification will be a frame behind.
+ if ( popupWorldPosition.y - popupDistanceFromAnchorPoint.y < boundingRectangleWorld.y )
+ {
+ requiredPopupPosition.y = AlternatePopUpPositionRelativeToCursor();
+ }
+
+ requiredPopupPosition.x = requiredPopupPosition.x + xOffSetToKeepWithinBounds;
+ }
+
+ Internal::Control& mTextControlParent;