X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Ftext-controller-impl.cpp;h=95115da001a76129bfae64c33e72b15aedb7844a;hb=70fc16a3cea274c6c5c56e5dee0bd5347a6c9389;hp=6cf26fc5ad930cd6951352070160b87cb3d862a9;hpb=12fe9741661d0fefaabddd959d04566a0a2d2233;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/text/text-controller-impl.cpp b/dali-toolkit/internal/text/text-controller-impl.cpp index 6cf26fc..95115da 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 ) { @@ -1759,6 +1788,14 @@ void Controller::Impl::RepositionSelectionHandles() const Length numberOfCharactersEnd = *( charactersPerGlyphBuffer + glyphEnd ); bool splitEndGlyph = ( glyphStart != glyphEnd ) && ( numberOfCharactersEnd > 1u ) && HasLigatureMustBreak( mLogicalModel->GetScript( selectionEndMinusOne ) ); + // The number of quads of the selection box. + const unsigned int numberOfQuads = 1u + ( glyphEnd - glyphStart ) + ( ( numberOfLines > 1u ) ? 2u * numberOfLines : 0u ); + mEventData->mDecorator->ResizeHighlightQuads( numberOfQuads ); + + // Count the actual number of quads. + unsigned int actualNumberOfQuads = 0u; + Vector4 quad; + // Traverse the glyphs. for( GlyphIndex index = glyphStart; index <= glyphEnd; ++index ) { @@ -1782,18 +1819,17 @@ void Controller::Impl::RepositionSelectionHandles() // Calculate the number of characters selected. const Length numberOfCharacters = ( glyphStart == glyphEnd ) ? ( selectionEnd - selectionStart ) : ( numberOfCharactersStart - interGlyphIndex ); - const float xPosition = lineRun->alignmentOffset + position.x - glyph.xBearing + mScrollPosition.x + glyphAdvance * static_cast( isCurrentRightToLeft ? ( numberOfCharactersStart - interGlyphIndex - numberOfCharacters ) : interGlyphIndex ); - const float xPositionAdvance = xPosition + static_cast( numberOfCharacters ) * glyphAdvance; - const float yPosition = selectionBoxInfo->lineOffset; + quad.x = lineRun->alignmentOffset + position.x - glyph.xBearing + mScrollPosition.x + glyphAdvance * static_cast( isCurrentRightToLeft ? ( numberOfCharactersStart - interGlyphIndex - numberOfCharacters ) : interGlyphIndex ); + quad.y = selectionBoxInfo->lineOffset; + quad.z = quad.x + static_cast( numberOfCharacters ) * glyphAdvance; + quad.w = selectionBoxInfo->lineOffset + selectionBoxInfo->lineHeight; // Store the min and max 'x' for each line. - selectionBoxInfo->minX = std::min( selectionBoxInfo->minX, xPosition ); - selectionBoxInfo->maxX = std::max( selectionBoxInfo->maxX, xPositionAdvance ); + selectionBoxInfo->minX = std::min( selectionBoxInfo->minX, quad.x ); + selectionBoxInfo->maxX = std::max( selectionBoxInfo->maxX, quad.z ); - mEventData->mDecorator->AddHighlight( xPosition, - yPosition, - xPositionAdvance, - yPosition + selectionBoxInfo->lineHeight ); + mEventData->mDecorator->AddHighlight( actualNumberOfQuads, quad ); + ++actualNumberOfQuads; splitStartGlyph = false; continue; @@ -1814,35 +1850,35 @@ void Controller::Impl::RepositionSelectionHandles() const Length numberOfCharacters = numberOfCharactersEnd - interGlyphIndex; - const float xPosition = lineRun->alignmentOffset + position.x - glyph.xBearing + mScrollPosition.x + ( isCurrentRightToLeft ? ( glyphAdvance * static_cast( numberOfCharacters ) ) : 0.f ); - const float xPositionAdvance = xPosition + static_cast( interGlyphIndex ) * glyphAdvance; - const float yPosition = selectionBoxInfo->lineOffset; + quad.x = lineRun->alignmentOffset + position.x - glyph.xBearing + mScrollPosition.x + ( isCurrentRightToLeft ? ( glyphAdvance * static_cast( numberOfCharacters ) ) : 0.f ); + quad.y = selectionBoxInfo->lineOffset; + quad.z = quad.x + static_cast( interGlyphIndex ) * glyphAdvance; + quad.w = quad.y + selectionBoxInfo->lineHeight; // Store the min and max 'x' for each line. - selectionBoxInfo->minX = std::min( selectionBoxInfo->minX, xPosition ); - selectionBoxInfo->maxX = std::max( selectionBoxInfo->maxX, xPositionAdvance ); + selectionBoxInfo->minX = std::min( selectionBoxInfo->minX, quad.x ); + selectionBoxInfo->maxX = std::max( selectionBoxInfo->maxX, quad.z ); - mEventData->mDecorator->AddHighlight( xPosition, - yPosition, - xPositionAdvance, - yPosition + selectionBoxInfo->lineHeight ); + mEventData->mDecorator->AddHighlight( actualNumberOfQuads, + quad ); + ++actualNumberOfQuads; splitEndGlyph = false; continue; } - const float xPosition = lineRun->alignmentOffset + position.x - glyph.xBearing + mScrollPosition.x; - const float xPositionAdvance = xPosition + glyph.advance; - const float yPosition = selectionBoxInfo->lineOffset; + quad.x = lineRun->alignmentOffset + position.x - glyph.xBearing + mScrollPosition.x; + quad.y = selectionBoxInfo->lineOffset; + quad.z = quad.x + glyph.advance; + quad.w = quad.y + selectionBoxInfo->lineHeight; // Store the min and max 'x' for each line. - selectionBoxInfo->minX = std::min( selectionBoxInfo->minX, xPosition ); - selectionBoxInfo->maxX = std::max( selectionBoxInfo->maxX, xPositionAdvance ); + selectionBoxInfo->minX = std::min( selectionBoxInfo->minX, quad.x ); + selectionBoxInfo->maxX = std::max( selectionBoxInfo->maxX, quad.z ); - mEventData->mDecorator->AddHighlight( xPosition, - yPosition, - xPositionAdvance, - yPosition + selectionBoxInfo->lineHeight ); + mEventData->mDecorator->AddHighlight( actualNumberOfQuads, + quad ); + ++actualNumberOfQuads; // Whether to retrieve the next line. if( index == lastGlyphOfLine ) @@ -1886,7 +1922,7 @@ void Controller::Impl::RepositionSelectionHandles() const SelectionBoxInfo& info = *it; // Update the size of the highlighted text. - highLightSize.height += selectionBoxInfo->lineHeight; + highLightSize.height += info.lineHeight; minHighlightX = std::min( minHighlightX, info.minX ); maxHighlightX = std::max( maxHighlightX, info.maxX ); } @@ -1904,11 +1940,15 @@ void Controller::Impl::RepositionSelectionHandles() if( boxifyBegin ) { + quad.x = 0.f; + quad.y = firstSelectionBoxLineInfo.lineOffset; + quad.z = firstSelectionBoxLineInfo.minX; + quad.w = firstSelectionBoxLineInfo.lineOffset + firstSelectionBoxLineInfo.lineHeight; + // Boxify at the beginning of the line. - mEventData->mDecorator->AddHighlight( 0.f, - firstSelectionBoxLineInfo.lineOffset, - firstSelectionBoxLineInfo.minX, - firstSelectionBoxLineInfo.lineOffset + firstSelectionBoxLineInfo.lineHeight ); + mEventData->mDecorator->AddHighlight( actualNumberOfQuads, + quad ); + ++actualNumberOfQuads; // Update the size of the highlighted text. minHighlightX = 0.f; @@ -1916,11 +1956,15 @@ void Controller::Impl::RepositionSelectionHandles() if( boxifyEnd ) { + quad.x = firstSelectionBoxLineInfo.maxX; + quad.y = firstSelectionBoxLineInfo.lineOffset; + quad.z = mVisualModel->mControlSize.width; + quad.w = firstSelectionBoxLineInfo.lineOffset + firstSelectionBoxLineInfo.lineHeight; + // Boxify at the end of the line. - mEventData->mDecorator->AddHighlight( firstSelectionBoxLineInfo.maxX, - firstSelectionBoxLineInfo.lineOffset, - mVisualModel->mControlSize.width, - firstSelectionBoxLineInfo.lineOffset + firstSelectionBoxLineInfo.lineHeight ); + mEventData->mDecorator->AddHighlight( actualNumberOfQuads, + quad ); + ++actualNumberOfQuads; // Update the size of the highlighted text. maxHighlightX = mVisualModel->mControlSize.width; @@ -1936,15 +1980,23 @@ void Controller::Impl::RepositionSelectionHandles() { const SelectionBoxInfo& info = *it; - mEventData->mDecorator->AddHighlight( 0.f, - info.lineOffset, - info.minX, - info.lineOffset + info.lineHeight ); + quad.x = 0.f; + quad.y = info.lineOffset; + quad.z = info.minX; + quad.w = info.lineOffset + info.lineHeight; + + mEventData->mDecorator->AddHighlight( actualNumberOfQuads, + quad ); + ++actualNumberOfQuads; + + quad.x = info.maxX; + quad.y = info.lineOffset; + quad.z = mVisualModel->mControlSize.width; + quad.w = info.lineOffset + info.lineHeight; - mEventData->mDecorator->AddHighlight( info.maxX, - info.lineOffset, - mVisualModel->mControlSize.width, - info.lineOffset + info.lineHeight ); + mEventData->mDecorator->AddHighlight( actualNumberOfQuads, + quad ); + ++actualNumberOfQuads; } // Update the size of the highlighted text. @@ -1961,11 +2013,15 @@ void Controller::Impl::RepositionSelectionHandles() if( boxifyBegin ) { + quad.x = 0.f; + quad.y = lastSelectionBoxLineInfo.lineOffset; + quad.z = lastSelectionBoxLineInfo.minX; + quad.w = lastSelectionBoxLineInfo.lineOffset + lastSelectionBoxLineInfo.lineHeight; + // Boxify at the beginning of the line. - mEventData->mDecorator->AddHighlight( 0.f, - lastSelectionBoxLineInfo.lineOffset, - lastSelectionBoxLineInfo.minX, - lastSelectionBoxLineInfo.lineOffset + lastSelectionBoxLineInfo.lineHeight ); + mEventData->mDecorator->AddHighlight( actualNumberOfQuads, + quad ); + ++actualNumberOfQuads; // Update the size of the highlighted text. minHighlightX = 0.f; @@ -1973,17 +2029,24 @@ void Controller::Impl::RepositionSelectionHandles() if( boxifyEnd ) { + quad.x = lastSelectionBoxLineInfo.maxX; + quad.y = lastSelectionBoxLineInfo.lineOffset; + quad.z = mVisualModel->mControlSize.width; + quad.w = lastSelectionBoxLineInfo.lineOffset + lastSelectionBoxLineInfo.lineHeight; + // Boxify at the end of the line. - mEventData->mDecorator->AddHighlight( lastSelectionBoxLineInfo.maxX, - lastSelectionBoxLineInfo.lineOffset, - mVisualModel->mControlSize.width, - lastSelectionBoxLineInfo.lineOffset + lastSelectionBoxLineInfo.lineHeight ); + mEventData->mDecorator->AddHighlight( actualNumberOfQuads, + quad ); + ++actualNumberOfQuads; // Update the size of the highlighted text. maxHighlightX = mVisualModel->mControlSize.width; } } + // Set the actual number of quads. + mEventData->mDecorator->ResizeHighlightQuads( actualNumberOfQuads ); + // Sets the highlight's size and position. In decorator's coords. // The highlight's height has been calculated above (before 'boxifying' the highlight). highLightSize.width = maxHighlightX - minHighlightX; @@ -2152,6 +2215,7 @@ void Controller::Impl::ChangeState( EventData::State newState ) if( mEventData->mState != newState ) { + mEventData->mPreviousState = mEventData->mState; mEventData->mState = newState; switch( mEventData->mState ) @@ -2163,6 +2227,7 @@ void Controller::Impl::ChangeState( EventData::State newState ) 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(); @@ -2173,6 +2238,7 @@ void Controller::Impl::ChangeState( EventData::State newState ) 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(); @@ -2185,6 +2251,7 @@ void Controller::Impl::ChangeState( EventData::State newState ) 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(); @@ -2204,6 +2271,7 @@ void Controller::Impl::ChangeState( EventData::State newState ) 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 ); @@ -2225,6 +2293,7 @@ void Controller::Impl::ChangeState( EventData::State newState ) { mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false ); mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false ); + mEventData->mDecorator->SetHighlightActive( false ); } else { @@ -2252,6 +2321,7 @@ void Controller::Impl::ChangeState( EventData::State newState ) 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 ); @@ -2267,6 +2337,7 @@ void Controller::Impl::ChangeState( EventData::State newState ) 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 ); @@ -2286,6 +2357,7 @@ void Controller::Impl::ChangeState( EventData::State newState ) 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 ); @@ -2306,6 +2378,7 @@ void Controller::Impl::ChangeState( EventData::State newState ) 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 ) { @@ -2316,6 +2389,27 @@ void Controller::Impl::ChangeState( EventData::State newState ) mEventData->mDecoratorUpdated = true; break; } + case EventData::TEXT_PANNING: + { + 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; + } } } }