X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Ftext-controller-impl.cpp;h=9637245e9daff4e2ee855a145c6f820d47f92bae;hp=2c45d35b2f5dc70a316fd40af16b39b6ab60e4d8;hb=549dd9160d48572dcbfbae6ae87ae6d8f749aa83;hpb=9526fca4abb513608cbd7fa15df39c4a69c12e0d diff --git a/dali-toolkit/internal/text/text-controller-impl.cpp b/dali-toolkit/internal/text/text-controller-impl.cpp index 2c45d35..9637245 100644 --- a/dali-toolkit/internal/text/text-controller-impl.cpp +++ b/dali-toolkit/internal/text/text-controller-impl.cpp @@ -91,6 +91,7 @@ EventData::EventData( DecoratorPtr decorator ) mUpdateGrabHandlePosition( false ), mUpdateLeftSelectionPosition( false ), mUpdateRightSelectionPosition( false ), + mIsLeftHandleSelected( false ), mUpdateHighlightBox( false ), mScrollAfterUpdatePosition( false ), mScrollAfterDelete( false ), @@ -218,16 +219,12 @@ bool Controller::Impl::ProcessInputEvents() GetCursorPosition( mEventData->mRightSelectionPosition, rightHandleInfo ); - if( mEventData->mScrollAfterUpdatePosition && mEventData->mUpdateLeftSelectionPosition ) + if( mEventData->mScrollAfterUpdatePosition && ( mEventData->mIsLeftHandleSelected ? mEventData->mUpdateLeftSelectionPosition : mEventData->mUpdateRightSelectionPosition ) ) { - const Vector2 currentCursorPosition( leftHandleInfo.primaryPosition.x, leftHandleInfo.lineOffset ); - ScrollToMakePositionVisible( currentCursorPosition, leftHandleInfo.lineHeight ); - } + CursorInfo& info = mEventData->mIsLeftHandleSelected ? leftHandleInfo : rightHandleInfo; - if( mEventData->mScrollAfterUpdatePosition && mEventData->mUpdateRightSelectionPosition ) - { - const Vector2 currentCursorPosition( rightHandleInfo.primaryPosition.x, rightHandleInfo.lineOffset ); - ScrollToMakePositionVisible( currentCursorPosition, rightHandleInfo.lineHeight ); + const Vector2 currentCursorPosition( info.primaryPosition.x, info.lineOffset ); + ScrollToMakePositionVisible( currentCursorPosition, info.lineHeight ); } } @@ -1203,17 +1200,31 @@ void Controller::Impl::OnPanEvent( const Event& event ) return; } - int state = event.p1.mInt; + const bool isHorizontalScrollEnabled = mEventData->mDecorator->IsHorizontalScrollEnabled(); + const bool isVerticalScrollEnabled = mEventData->mDecorator->IsVerticalScrollEnabled(); + + if( !isHorizontalScrollEnabled && !isVerticalScrollEnabled ) + { + // Nothing to do if scrolling is not enabled. + return; + } + + const int state = event.p1.mInt; - if( ( Gesture::Started == state ) || - ( Gesture::Continuing == state ) ) + switch( state ) { - if( mEventData->mDecorator ) + case Gesture::Started: + { + // Will remove the cursor, handles or text's popup, ... + ChangeState( EventData::TEXT_PANNING ); + break; + } + case Gesture::Continuing: { const Vector2& layoutSize = mVisualModel->GetLayoutSize(); const Vector2 currentScroll = mScrollPosition; - if( mEventData->mDecorator->IsHorizontalScrollEnabled() ) + if( isHorizontalScrollEnabled ) { const float displacementX = event.p2.mFloat; mScrollPosition.x += displacementX; @@ -1221,7 +1232,7 @@ void Controller::Impl::OnPanEvent( const Event& event ) ClampHorizontalScroll( layoutSize ); } - if( mEventData->mDecorator->IsVerticalScrollEnabled() ) + if( isVerticalScrollEnabled ) { const float displacementY = event.p3.mFloat; mScrollPosition.y += displacementY; @@ -1230,7 +1241,17 @@ void Controller::Impl::OnPanEvent( const Event& event ) } mEventData->mDecorator->UpdatePositions( mScrollPosition - currentScroll ); + break; } + case Gesture::Finished: + case Gesture::Cancelled: // FALLTHROUGH + { + // Will go back to the previous state to show the cursor, handles, the text's popup, ... + ChangeState( mEventData->mPreviousState ); + break; + } + default: + break; } } @@ -1302,6 +1323,9 @@ void Controller::Impl::OnHandleEvent( const Event& event ) // Updates the decorator if the soft handle panning is enabled. It triggers a relayout in the decorator and the new position of the handle is set. mEventData->mDecoratorUpdated = isSmoothHandlePanEnabled; + + // Will define the order to scroll the text to match the handle position. + mEventData->mIsLeftHandleSelected = true; } else if( Event::RIGHT_SELECTION_HANDLE_EVENT == event.type ) { @@ -1319,6 +1343,9 @@ void Controller::Impl::OnHandleEvent( const Event& event ) // Updates the decorator if the soft handle panning is enabled. It triggers a relayout in the decorator and the new position of the handle is set. mEventData->mDecoratorUpdated = isSmoothHandlePanEnabled; + + // Will define the order to scroll the text to match the handle position. + mEventData->mIsLeftHandleSelected = false; } } // end ( HANDLE_PRESSED == state ) else if( ( HANDLE_RELEASED == state ) || @@ -1361,6 +1388,7 @@ void Controller::Impl::OnHandleEvent( const Event& event ) mEventData->mUpdateHighlightBox = true; mEventData->mUpdateLeftSelectionPosition = true; + mEventData->mUpdateRightSelectionPosition = true; if( handleStopScrolling || isSmoothHandlePanEnabled ) { @@ -1379,6 +1407,7 @@ void Controller::Impl::OnHandleEvent( const Event& event ) mEventData->mUpdateHighlightBox = true; mEventData->mUpdateRightSelectionPosition = true; + mEventData->mUpdateLeftSelectionPosition = true; if( handleStopScrolling || isSmoothHandlePanEnabled ) { @@ -2152,158 +2181,201 @@ void Controller::Impl::ChangeState( EventData::State newState ) if( mEventData->mState != newState ) { + mEventData->mPreviousState = mEventData->mState; mEventData->mState = newState; - if( EventData::INACTIVE == mEventData->mState ) - { - mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_NONE ); - mEventData->mDecorator->StopCursorBlink(); - mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false ); - mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false ); - mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false ); - mEventData->mDecorator->SetPopupActive( false ); - mEventData->mDecoratorUpdated = true; - HideClipboard(); - } - else if( EventData::INTERRUPTED == mEventData->mState) - { - mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false ); - mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false ); - mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false ); - mEventData->mDecorator->SetPopupActive( false ); - mEventData->mDecoratorUpdated = true; - HideClipboard(); - } - else if( EventData::SELECTING == mEventData->mState ) - { - mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_NONE ); - mEventData->mDecorator->StopCursorBlink(); - mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false ); - mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, true ); - mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, true ); - if( mEventData->mGrabHandlePopupEnabled ) - { - SetPopupButtons(); - mEventData->mDecorator->SetPopupActive( true ); - } - mEventData->mDecoratorUpdated = true; - } - else if( EventData::EDITING == mEventData->mState ) + switch( mEventData->mState ) { - mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_PRIMARY ); - if( mEventData->mCursorBlinkEnabled ) + case EventData::INACTIVE: { - mEventData->mDecorator->StartCursorBlink(); + mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_NONE ); + mEventData->mDecorator->StopCursorBlink(); + mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false ); + mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false ); + mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false ); + mEventData->mDecorator->SetHighlightActive( false ); + mEventData->mDecorator->SetPopupActive( false ); + mEventData->mDecoratorUpdated = true; + HideClipboard(); + break; } - // Grab handle is not shown until a tap is received whilst EDITING - mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false ); - mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false ); - mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false ); - if( mEventData->mGrabHandlePopupEnabled ) + case EventData::INTERRUPTED: { + mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false ); + mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false ); + mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false ); + mEventData->mDecorator->SetHighlightActive( false ); mEventData->mDecorator->SetPopupActive( false ); + mEventData->mDecoratorUpdated = true; + HideClipboard(); + break; } - mEventData->mDecoratorUpdated = true; - HideClipboard(); - } - else if( EventData::EDITING_WITH_POPUP == mEventData->mState ) - { - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "EDITING_WITH_POPUP \n", newState ); - - mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_PRIMARY ); - if( mEventData->mCursorBlinkEnabled ) + case EventData::SELECTING: { - mEventData->mDecorator->StartCursorBlink(); + mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_NONE ); + mEventData->mDecorator->StopCursorBlink(); + mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false ); + mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, true ); + mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, true ); + mEventData->mDecorator->SetHighlightActive( true ); + if( mEventData->mGrabHandlePopupEnabled ) + { + SetPopupButtons(); + mEventData->mDecorator->SetPopupActive( true ); + } + mEventData->mDecoratorUpdated = true; + break; } - if( mEventData->mSelectionEnabled ) + case EventData::EDITING: { + mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_PRIMARY ); + if( mEventData->mCursorBlinkEnabled ) + { + mEventData->mDecorator->StartCursorBlink(); + } + // Grab handle is not shown until a tap is received whilst EDITING + mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false ); mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false ); mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false ); + mEventData->mDecorator->SetHighlightActive( false ); + if( mEventData->mGrabHandlePopupEnabled ) + { + mEventData->mDecorator->SetPopupActive( false ); + } + mEventData->mDecoratorUpdated = true; + HideClipboard(); + break; } - else + case EventData::EDITING_WITH_POPUP: { - mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, true ); + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "EDITING_WITH_POPUP \n", newState ); + + mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_PRIMARY ); + if( mEventData->mCursorBlinkEnabled ) + { + mEventData->mDecorator->StartCursorBlink(); + } + if( mEventData->mSelectionEnabled ) + { + mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false ); + mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false ); + mEventData->mDecorator->SetHighlightActive( false ); + } + else + { + mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, true ); + } + if( mEventData->mGrabHandlePopupEnabled ) + { + SetPopupButtons(); + mEventData->mDecorator->SetPopupActive( true ); + } + HideClipboard(); + mEventData->mDecoratorUpdated = true; + break; } - if( mEventData->mGrabHandlePopupEnabled ) + case EventData::EDITING_WITH_GRAB_HANDLE: { - SetPopupButtons(); - mEventData->mDecorator->SetPopupActive( true ); - } - HideClipboard(); - mEventData->mDecoratorUpdated = true; - } - else if( EventData::EDITING_WITH_GRAB_HANDLE == mEventData->mState ) - { - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "EDITING_WITH_GRAB_HANDLE \n", newState ); + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "EDITING_WITH_GRAB_HANDLE \n", newState ); - mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_PRIMARY ); - if( mEventData->mCursorBlinkEnabled ) - { - mEventData->mDecorator->StartCursorBlink(); + mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_PRIMARY ); + if( mEventData->mCursorBlinkEnabled ) + { + mEventData->mDecorator->StartCursorBlink(); + } + // Grab handle is not shown until a tap is received whilst EDITING + mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, true ); + mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false ); + mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false ); + mEventData->mDecorator->SetHighlightActive( false ); + if( mEventData->mGrabHandlePopupEnabled ) + { + mEventData->mDecorator->SetPopupActive( false ); + } + mEventData->mDecoratorUpdated = true; + HideClipboard(); + break; } - // Grab handle is not shown until a tap is received whilst EDITING - mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, true ); - mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false ); - mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false ); - if( mEventData->mGrabHandlePopupEnabled ) + case EventData::SELECTION_HANDLE_PANNING: { - mEventData->mDecorator->SetPopupActive( false ); + mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_NONE ); + mEventData->mDecorator->StopCursorBlink(); + mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false ); + mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, true ); + mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, true ); + mEventData->mDecorator->SetHighlightActive( true ); + if( mEventData->mGrabHandlePopupEnabled ) + { + mEventData->mDecorator->SetPopupActive( false ); + } + mEventData->mDecoratorUpdated = true; + break; } - mEventData->mDecoratorUpdated = true; - HideClipboard(); - } - else if( EventData::SELECTION_HANDLE_PANNING == mEventData->mState ) - { - mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_NONE ); - mEventData->mDecorator->StopCursorBlink(); - mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false ); - mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, true ); - mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, true ); - if( mEventData->mGrabHandlePopupEnabled ) + case EventData::GRAB_HANDLE_PANNING: { - mEventData->mDecorator->SetPopupActive( false ); - } - mEventData->mDecoratorUpdated = true; - } - else if( EventData::GRAB_HANDLE_PANNING == mEventData->mState ) - { - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "GRAB_HANDLE_PANNING \n", newState ); + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "GRAB_HANDLE_PANNING \n", newState ); - mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_PRIMARY ); - if( mEventData->mCursorBlinkEnabled ) - { - mEventData->mDecorator->StartCursorBlink(); + mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_PRIMARY ); + if( mEventData->mCursorBlinkEnabled ) + { + mEventData->mDecorator->StartCursorBlink(); + } + mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, true ); + mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false ); + mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false ); + mEventData->mDecorator->SetHighlightActive( false ); + if( mEventData->mGrabHandlePopupEnabled ) + { + mEventData->mDecorator->SetPopupActive( false ); + } + mEventData->mDecoratorUpdated = true; + break; } - mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, true ); - mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false ); - mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false ); - if( mEventData->mGrabHandlePopupEnabled ) + case EventData::EDITING_WITH_PASTE_POPUP: { - mEventData->mDecorator->SetPopupActive( false ); - } - mEventData->mDecoratorUpdated = true; - } - else if( EventData::EDITING_WITH_PASTE_POPUP == mEventData->mState ) - { - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "EDITING_WITH_PASTE_POPUP \n", newState ); + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "EDITING_WITH_PASTE_POPUP \n", newState ); - mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_PRIMARY ); - if( mEventData->mCursorBlinkEnabled ) - { - mEventData->mDecorator->StartCursorBlink(); - } + mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_PRIMARY ); + if( mEventData->mCursorBlinkEnabled ) + { + mEventData->mDecorator->StartCursorBlink(); + } - mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, true ); - mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false ); - mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false ); + mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, true ); + mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false ); + mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false ); + mEventData->mDecorator->SetHighlightActive( false ); - if( mEventData->mGrabHandlePopupEnabled ) + if( mEventData->mGrabHandlePopupEnabled ) + { + SetPopupButtons(); + mEventData->mDecorator->SetPopupActive( true ); + } + HideClipboard(); + mEventData->mDecoratorUpdated = true; + break; + } + case EventData::TEXT_PANNING: { - SetPopupButtons(); - mEventData->mDecorator->SetPopupActive( true ); + mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_NONE ); + mEventData->mDecorator->StopCursorBlink(); + mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false ); + if( mEventData->mDecorator->IsHandleActive( LEFT_SELECTION_HANDLE ) || + mEventData->mDecorator->IsHandleActive( RIGHT_SELECTION_HANDLE ) ) + { + mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false ); + mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false ); + mEventData->mDecorator->SetHighlightActive( true ); + } + + if( mEventData->mGrabHandlePopupEnabled ) + { + mEventData->mDecorator->SetPopupActive( false ); + } + + mEventData->mDecoratorUpdated = true; + break; } - HideClipboard(); - mEventData->mDecoratorUpdated = true; } } }