X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Fdecorator%2Ftext-decorator.cpp;h=3a6d7dad5d36929478e6be9325b6153028611785;hp=b4a0705737e2b4298ee94375f8529f7476c17910;hb=8e4860da0bed4e33e1d248ce40d5e5e5f8d28347;hpb=56d412791a44c2a79135d2293c13fddb135c9d54 diff --git a/dali-toolkit/internal/text/decorator/text-decorator.cpp b/dali-toolkit/internal/text/decorator/text-decorator.cpp index b4a0705..3a6d7da 100644 --- a/dali-toolkit/internal/text/decorator/text-decorator.cpp +++ b/dali-toolkit/internal/text/decorator/text-decorator.cpp @@ -19,12 +19,15 @@ #include // EXTERNAL INCLUDES +#include #include #include #include #include #include +#include #include +#include #include #include #include @@ -32,9 +35,10 @@ #include #include #include +#include #include #include -//#include +#include #include // INTERNAL INCLUDES @@ -47,8 +51,24 @@ #ifdef DEBUG_ENABLED #define DECORATOR_DEBUG + #endif + +namespace Dali +{ +namespace Internal +{ +namespace +{ +#ifdef DECORATOR_DEBUG +Integration::Log::Filter* gLogFilter( Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_TEXT_DECORATOR") ); +#endif +} +} +} + + // Local Data namespace { @@ -98,6 +118,26 @@ struct QuadCoordinates typedef std::vector QuadContainer; +/** + * @brief Takes a bounding rectangle in the local coordinates of an actor and returns the world coordinates Bounding Box. + * @param[in] boundingRectangle local bounding + * @param[out] Vector4 World coordinate bounding Box. + */ +void LocalToWorldCoordinatesBoundingBox( const Dali::Rect& boundingRectangle, Dali::Vector4& boundingBox ) +{ + // Convert to world coordinates and store as a Vector4 to be compatible with Property Notifications. + Dali::Vector2 stageSize = Dali::Stage::GetCurrent().GetSize(); + + const float originX = boundingRectangle.x - 0.5f * stageSize.width; + const float originY = boundingRectangle.y - 0.5f * stageSize.height; + + boundingBox = Dali::Vector4( originX, + originY, + originX + boundingRectangle.width, + originY + boundingRectangle.height ); +} + + } // end of namespace namespace Dali @@ -116,14 +156,16 @@ struct Decorator::Impl : public ConnectionTracker CursorImpl() : x(0.0f), y(0.0f), - height(0.0f), + cursorHeight(0.0f), + lineHeight(0.0f), color(Dali::Color::WHITE) { } float x; float y; - float height; + float cursorHeight; + float lineHeight; Vector4 color; }; @@ -133,14 +175,14 @@ struct Decorator::Impl : public ConnectionTracker SelectionHandleImpl() : x(0.0f), y(0.0f), - cursorHeight(0.0f), + lineHeight(0.0f), flipped(false) { } float x; float y; - float cursorHeight; ///< Not the handle height + float lineHeight; ///< Not the handle height bool flipped; ImageActor actor; @@ -182,13 +224,13 @@ struct Decorator::Impl : public ConnectionTracker { mPrimaryCursor.SetPosition( mCursor[PRIMARY_CURSOR].x + scrollPosition.x, mCursor[PRIMARY_CURSOR].y + scrollPosition.y ); - mPrimaryCursor.SetSize( Vector2( 1.0f, mCursor[PRIMARY_CURSOR].height ) ); + mPrimaryCursor.SetSize( Size( 1.0f, mCursor[PRIMARY_CURSOR].cursorHeight ) ); } if( mSecondaryCursor ) { mSecondaryCursor.SetPosition( mCursor[SECONDARY_CURSOR].x + scrollPosition.x, mCursor[SECONDARY_CURSOR].y + scrollPosition.y ); - mSecondaryCursor.SetSize( Vector2( 1.0f, mCursor[SECONDARY_CURSOR].height ) ); + mSecondaryCursor.SetSize( Size( 1.0f, mCursor[SECONDARY_CURSOR].cursorHeight ) ); } // Show or hide the grab handle @@ -199,7 +241,7 @@ struct Decorator::Impl : public ConnectionTracker CreateGrabHandle(); mGrabHandle.SetPosition( mCursor[PRIMARY_CURSOR].x + scrollPosition.x, - mCursor[PRIMARY_CURSOR].y + scrollPosition.y + mCursor[PRIMARY_CURSOR].height ); + mCursor[PRIMARY_CURSOR].lineHeight + scrollPosition.y ); } else if( mGrabHandle ) { @@ -215,11 +257,11 @@ struct Decorator::Impl : public ConnectionTracker SelectionHandleImpl& primary = mSelectionHandle[ PRIMARY_SELECTION_HANDLE ]; primary.actor.SetPosition( primary.x + scrollPosition.x, - primary.y + scrollPosition.y + primary.cursorHeight ); + primary.lineHeight + scrollPosition.y ); SelectionHandleImpl& secondary = mSelectionHandle[ SECONDARY_SELECTION_HANDLE ]; secondary.actor.SetPosition( secondary.x + scrollPosition.x, - secondary.y + scrollPosition.y + secondary.cursorHeight ); + secondary.lineHeight + scrollPosition.y ); CreateHighlight(); UpdateHighlight(); @@ -236,9 +278,13 @@ struct Decorator::Impl : public ConnectionTracker if ( !mCopyPastePopup ) { mCopyPastePopup = TextSelectionPopup::New(); +#ifdef DECORATOR_DEBUG + mCopyPastePopup.SetName("mCopyPastePopup"); +#endif + mCopyPastePopup.SetAnchorPoint( AnchorPoint::CENTER ); + mCopyPastePopup.OnRelayoutSignal().Connect( this, &Decorator::Impl::PopUpRelayoutComplete ); // Position popup after size negotiation mActiveLayer.Add ( mCopyPastePopup ); } - mCopyPastePopup.SetPosition( Vector3( 200.0f, -100.0f, 0.0f ) ); //todo grabhandle or selection handle positions to be used } else { @@ -249,6 +295,23 @@ struct Decorator::Impl : public ConnectionTracker } } + void PopUpRelayoutComplete( Actor actor ) + { + // Size negotiation for CopyPastePopup complete so can get the size and constrain position within bounding box. + + mCopyPastePopup.OnRelayoutSignal().Disconnect( this, &Decorator::Impl::PopUpRelayoutComplete ); + + Vector3 popupPosition( mCursor[PRIMARY_CURSOR].x, mCursor[PRIMARY_CURSOR].y -100.0f , 0.0f); //todo 100 to be an offset Property + + Vector3 popupSize = Vector3( mCopyPastePopup.GetRelayoutSize( Dimension::WIDTH ), mCopyPastePopup.GetRelayoutSize( Dimension::HEIGHT ), 0.0f ); + + GetConstrainedPopupPosition( popupPosition, popupSize, AnchorPoint::CENTER, mActiveLayer, mBoundingBox ); + + SetUpPopUpPositionNotifications(); + + mCopyPastePopup.SetPosition( popupPosition ); //todo grabhandle(cursor) or selection handle positions to be used + } + void CreateCursor( ImageActor& cursor ) { cursor = CreateSolidColorActor( Color::WHITE ); @@ -292,6 +355,10 @@ struct Decorator::Impl : public ConnectionTracker mActiveLayer.Add( mSecondaryCursor); } } + else + { + UnparentAndReset( mSecondaryCursor ); + } } } @@ -339,7 +406,7 @@ struct Decorator::Impl : public ConnectionTracker #endif mActiveLayer.SetParentOrigin( ParentOrigin::CENTER ); - mActiveLayer.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + mActiveLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); mActiveLayer.SetPositionInheritanceMode( USE_PARENT_POSITION ); parent.Add( mActiveLayer ); @@ -358,29 +425,37 @@ struct Decorator::Impl : public ConnectionTracker } mGrabHandle = ImageActor::New( mGrabHandleImage ); -#ifdef DECORATOR_DEBUG - mGrabHandle.SetName( "GrabHandleActor" ); -#endif mGrabHandle.SetAnchorPoint( AnchorPoint::TOP_CENTER ); mGrabHandle.SetDrawMode( DrawMode::OVERLAY ); // Area that Grab handle responds to, larger than actual handle so easier to move #ifdef DECORATOR_DEBUG - mGrabArea = Toolkit::CreateSolidColorActor( Vector4(0.0f, 0.0f, 0.0f, 0.0f), true, Color::RED, 1 ); - mGrabArea.SetName( "GrabArea" ); + mGrabHandle.SetName( "GrabHandleActor" ); + if ( Dali::Internal::gLogFilter->IsEnabledFor( Debug::Verbose ) ) + { + mGrabArea = Toolkit::CreateSolidColorActor( Vector4(0.0f, 0.0f, 0.0f, 0.0f), true, Color::RED, 1 ); + mGrabArea.SetName( "GrabArea" ); + } + else + { + mGrabArea = Actor::New(); + mGrabArea.SetRelayoutEnabled( true ); + mGrabArea.SetName( "GrabArea" ); + } #else mGrabArea = Actor::New(); mGrabArea.SetRelayoutEnabled( true ); #endif + mGrabArea.SetParentOrigin( ParentOrigin::TOP_CENTER ); mGrabArea.SetAnchorPoint( AnchorPoint::TOP_CENTER ); - mGrabArea.SetResizePolicy( SIZE_RELATIVE_TO_PARENT, ALL_DIMENSIONS ); + mGrabArea.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); mGrabArea.SetSizeModeFactor( DEFAULT_GRAB_HANDLE_RELATIVE_SIZE ); mGrabHandle.Add( mGrabArea ); mTapDetector.Attach( mGrabArea ); mPanGestureDetector.Attach( mGrabArea ); - mActiveLayer.Add(mGrabHandle); + mActiveLayer.Add( mGrabHandle ); } } @@ -407,7 +482,7 @@ struct Decorator::Impl : public ConnectionTracker #ifdef DECORATOR_DEBUG primary.grabArea.SetName("SelectionHandleOneGrabArea"); #endif - primary.grabArea.SetResizePolicy( SIZE_RELATIVE_TO_PARENT, ALL_DIMENSIONS ); + primary.grabArea.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); primary.grabArea.SetSizeModeFactor( DEFAULT_SELECTION_HANDLE_RELATIVE_SIZE ); primary.grabArea.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION ); @@ -440,7 +515,7 @@ struct Decorator::Impl : public ConnectionTracker #ifdef DECORATOR_DEBUG secondary.grabArea.SetName("SelectionHandleTwoGrabArea"); #endif - secondary.grabArea.SetResizePolicy( SIZE_RELATIVE_TO_PARENT, ALL_DIMENSIONS ); + secondary.grabArea.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); secondary.grabArea.SetSizeModeFactor( DEFAULT_SELECTION_HANDLE_RELATIVE_SIZE ); secondary.grabArea.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION ); @@ -592,7 +667,7 @@ struct Decorator::Impl : public ConnectionTracker mGrabDisplacementY += gesture.displacement.y; float x = mCursor[PRIMARY_CURSOR].x + mGrabDisplacementX; - float y = mCursor[PRIMARY_CURSOR].y + mCursor[PRIMARY_CURSOR].height*0.5f + mGrabDisplacementY; + float y = mCursor[PRIMARY_CURSOR].y + mCursor[PRIMARY_CURSOR].lineHeight*0.5f + mGrabDisplacementY; if( Gesture::Started == gesture.state || Gesture::Continuing == gesture.state ) @@ -619,6 +694,103 @@ struct Decorator::Impl : public ConnectionTracker return false; } + // 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& 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; Observer& mObserver; @@ -697,7 +869,7 @@ unsigned int Decorator::GetActiveCursor() const return mImpl->mActiveCursor; } -void Decorator::SetPosition( Cursor cursor, float x, float y, float height ) +void Decorator::SetPosition( Cursor cursor, float x, float y, float cursorHeight, float lineHeight ) { // Adjust grab handle displacement mImpl->mGrabDisplacementX -= x - mImpl->mCursor[cursor].x; @@ -705,14 +877,16 @@ void Decorator::SetPosition( Cursor cursor, float x, float y, float height ) mImpl->mCursor[cursor].x = x; mImpl->mCursor[cursor].y = y; - mImpl->mCursor[cursor].height = height; + mImpl->mCursor[cursor].cursorHeight = cursorHeight; + mImpl->mCursor[cursor].lineHeight = lineHeight; } -void Decorator::GetPosition( Cursor cursor, float& x, float& y, float& height ) const +void Decorator::GetPosition( Cursor cursor, float& x, float& y, float& cursorHeight, float& lineHeight ) const { x = mImpl->mCursor[cursor].x; y = mImpl->mCursor[cursor].y; - height = mImpl->mCursor[cursor].height; + cursorHeight = mImpl->mCursor[cursor].cursorHeight; + lineHeight = mImpl->mCursor[cursor].lineHeight; } void Decorator::SetColor( Cursor cursor, const Dali::Vector4& color ) @@ -805,14 +979,14 @@ void Decorator::SetPosition( SelectionHandle handle, float x, float y, float hei { mImpl->mSelectionHandle[handle].x = x; mImpl->mSelectionHandle[handle].y = y; - mImpl->mSelectionHandle[handle].cursorHeight = height; + mImpl->mSelectionHandle[handle].lineHeight = height; } void Decorator::GetPosition( SelectionHandle handle, float& x, float& y, float& height ) const { x = mImpl->mSelectionHandle[handle].x; y = mImpl->mSelectionHandle[handle].y; - height = mImpl->mSelectionHandle[handle].cursorHeight; + height = mImpl->mSelectionHandle[handle].lineHeight; } void Decorator::SetImage( SelectionHandle handle, SelectionHandleState state, Dali::Image image )