From: Victor Cebollada Date: Thu, 9 Jul 2015 10:38:00 +0000 (+0100) Subject: Fix for grab and selection handles. X-Git-Tag: dali_1.0.49~12 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=71ad84e7d5907b0627aa99093bfd55c502ffc2b0 Fix for grab and selection handles. * Was difficult/imposible to drag the handle to the beginning/end of the text. Change-Id: I80e9a0f7c2cc2c9e2262bb2238e00debc9b37138 Signed-off-by: Victor Cebollada --- diff --git a/dali-toolkit/internal/text/decorator/text-decorator.cpp b/dali-toolkit/internal/text/decorator/text-decorator.cpp index c6e826c..d75df7b 100644 --- a/dali-toolkit/internal/text/decorator/text-decorator.cpp +++ b/dali-toolkit/internal/text/decorator/text-decorator.cpp @@ -296,6 +296,7 @@ struct Decorator::Impl : public ConnectionTracker // Show or hide the cursors CreateCursors(); + if( mPrimaryCursor ) { const CursorImpl& cursor = mCursor[PRIMARY_CURSOR]; @@ -367,13 +368,13 @@ struct Decorator::Impl : public ConnectionTracker if( isPrimaryVisible ) { primary.actor.SetPosition( primaryPosition.x, - primaryPosition.y + primary.lineHeight ); + primary.lineHeight ); // TODO : Fix for multiline. } if( isSecondaryVisible ) { secondary.actor.SetPosition( secondaryPosition.x, - secondaryPosition.y + secondary.lineHeight ); + secondary.lineHeight ); // TODO : Fix for multiline. } } primary.actor.SetVisible( isPrimaryVisible ); diff --git a/dali-toolkit/internal/text/text-controller-impl.cpp b/dali-toolkit/internal/text/text-controller-impl.cpp index 455330a..12fbb2f 100644 --- a/dali-toolkit/internal/text/text-controller-impl.cpp +++ b/dali-toolkit/internal/text/text-controller-impl.cpp @@ -81,8 +81,8 @@ namespace Text * @param[in] glyphIndex The index to the first glyph. * @param[in] numberOfGlyphs The number of glyphs. * @param[out] glyphMetrics Some glyph metrics (font height, advance, ascender and x bearing). - * @param[in] - * @param[in] + * @param[in] visualModel The visual model. + * @param[in] fontClient The font client. */ void GetGlyphsMetrics( GlyphIndex glyphIndex, Length numberOfGlyphs, @@ -663,7 +663,7 @@ void Controller::Impl::OnHandleEvent( const Event& event ) if( handleStopScrolling ) { - mEventData->mUpdateLeftSelectionPosition = ( mEventData->mLeftSelectionPosition != handlePosition ) && ( mEventData->mRightSelectionPosition != handlePosition); + mEventData->mUpdateLeftSelectionPosition = ( mEventData->mRightSelectionPosition != handlePosition ); mEventData->mScrollAfterUpdatePosition = mEventData->mUpdateLeftSelectionPosition; if( mEventData->mUpdateLeftSelectionPosition ) @@ -681,9 +681,8 @@ void Controller::Impl::OnHandleEvent( const Event& event ) if( handleStopScrolling ) { - mEventData->mUpdateRightSelectionPosition = ( mEventData->mRightSelectionPosition != handlePosition ) && ( mEventData->mLeftSelectionPosition != handlePosition ); + mEventData->mUpdateRightSelectionPosition = ( mEventData->mLeftSelectionPosition != handlePosition ); mEventData->mScrollAfterUpdatePosition = mEventData->mUpdateRightSelectionPosition; - if( mEventData->mUpdateRightSelectionPosition ) { mEventData->mRightSelectionPosition = handlePosition; @@ -705,74 +704,84 @@ void Controller::Impl::OnHandleEvent( const Event& event ) ClampHorizontalScroll( actualSize ); + bool endOfScroll = false; if( Vector2::ZERO == ( currentScrollPosition - mEventData->mScrollPosition ) ) { // Notify the decorator there is no more text to scroll. // The decorator won't send more scroll events. mEventData->mDecorator->NotifyEndOfScroll(); + // Still need to set the position of the handle. + endOfScroll = true; } - else - { - const bool scrollRightDirection = xSpeed > 0.f; - const bool leftSelectionHandleEvent = Event::LEFT_SELECTION_HANDLE_EVENT == event.type; - const bool rightSelectionHandleEvent = Event::RIGHT_SELECTION_HANDLE_EVENT == event.type; - if( Event::GRAB_HANDLE_EVENT == event.type ) - { - ChangeState( EventData::GRAB_HANDLE_PANNING ); + // Set the position of the handle. + const bool scrollRightDirection = xSpeed > 0.f; + const bool leftSelectionHandleEvent = Event::LEFT_SELECTION_HANDLE_EVENT == event.type; + const bool rightSelectionHandleEvent = Event::RIGHT_SELECTION_HANDLE_EVENT == event.type; - Vector2 position = mEventData->mDecorator->GetPosition( GRAB_HANDLE ); + if( Event::GRAB_HANDLE_EVENT == event.type ) + { + ChangeState( EventData::GRAB_HANDLE_PANNING ); - // Position the grag handle close to either the left or right edge. - position.x = scrollRightDirection ? 0.f : mControlSize.width; + Vector2 position = mEventData->mDecorator->GetPosition( GRAB_HANDLE ); - // Get the new handle position. - // The grab handle's position is in decorator coords. Need to transforms to text coords. - const CharacterIndex handlePosition = GetClosestCursorIndex( position.x - mEventData->mScrollPosition.x - mAlignmentOffset.x, - position.y - mEventData->mScrollPosition.y - mAlignmentOffset.y ); + // Position the grag handle close to either the left or right edge. + position.x = scrollRightDirection ? 0.f : mControlSize.width; - mEventData->mUpdateCursorPosition = mEventData->mPrimaryCursorPosition != handlePosition; - mEventData->mScrollAfterUpdatePosition = mEventData->mUpdateCursorPosition; - mEventData->mPrimaryCursorPosition = handlePosition; - } - else if( leftSelectionHandleEvent || rightSelectionHandleEvent ) - { - // TODO: This is recalculating the selection box every time the text is scrolled with the selection handles. - // Think if something can be done to save power. + // Get the new handle position. + // The grab handle's position is in decorator coords. Need to transforms to text coords. + const CharacterIndex handlePosition = GetClosestCursorIndex( position.x - mEventData->mScrollPosition.x - mAlignmentOffset.x, + position.y - mEventData->mScrollPosition.y - mAlignmentOffset.y ); + + mEventData->mUpdateCursorPosition = mEventData->mPrimaryCursorPosition != handlePosition; + mEventData->mScrollAfterUpdatePosition = mEventData->mUpdateCursorPosition; + mEventData->mPrimaryCursorPosition = handlePosition; + } + else if( leftSelectionHandleEvent || rightSelectionHandleEvent ) + { + // TODO: This is recalculating the selection box every time the text is scrolled with the selection handles. + // Think if something can be done to save power. - ChangeState( EventData::SELECTION_HANDLE_PANNING ); + ChangeState( EventData::SELECTION_HANDLE_PANNING ); - Vector2 position = mEventData->mDecorator->GetPosition( leftSelectionHandleEvent ? Text::LEFT_SELECTION_HANDLE : Text::RIGHT_SELECTION_HANDLE ); + Vector2 position = mEventData->mDecorator->GetPosition( leftSelectionHandleEvent ? Text::LEFT_SELECTION_HANDLE : Text::RIGHT_SELECTION_HANDLE ); - // Position the selection handle close to either the left or right edge. - position.x = scrollRightDirection ? 0.f : mControlSize.width; + // Position the selection handle close to either the left or right edge. + position.x = scrollRightDirection ? 0.f : mControlSize.width; - // Get the new handle position. - // The selection handle's position is in decorator coords. Need to transforms to text coords. - const CharacterIndex handlePosition = GetClosestCursorIndex( position.x - mEventData->mScrollPosition.x - mAlignmentOffset.x, - position.y - mEventData->mScrollPosition.y - mAlignmentOffset.y ); + // Get the new handle position. + // The selection handle's position is in decorator coords. Need to transforms to text coords. + const CharacterIndex handlePosition = GetClosestCursorIndex( position.x - mEventData->mScrollPosition.x - mAlignmentOffset.x, + position.y - mEventData->mScrollPosition.y - mAlignmentOffset.y ); - if( leftSelectionHandleEvent ) + if( leftSelectionHandleEvent ) + { + const bool differentHandles = ( mEventData->mLeftSelectionPosition != handlePosition ) && ( mEventData->mRightSelectionPosition != handlePosition ); + mEventData->mUpdateLeftSelectionPosition = endOfScroll || differentHandles; + if( differentHandles ) { - mEventData->mUpdateLeftSelectionPosition = handlePosition != mEventData->mLeftSelectionPosition; mEventData->mLeftSelectionPosition = handlePosition; } - else + } + else + { + const bool differentHandles = ( mEventData->mRightSelectionPosition != handlePosition ) && ( mEventData->mLeftSelectionPosition != handlePosition ); + mEventData->mUpdateRightSelectionPosition = endOfScroll || differentHandles; + if( differentHandles ) { - mEventData->mUpdateRightSelectionPosition = handlePosition != mEventData->mRightSelectionPosition; mEventData->mRightSelectionPosition = handlePosition; } + } - if( mEventData->mUpdateLeftSelectionPosition || mEventData->mUpdateRightSelectionPosition ) - { - RepositionSelectionHandles( mEventData->mLeftSelectionPosition, - mEventData->mRightSelectionPosition ); + if( mEventData->mUpdateLeftSelectionPosition || mEventData->mUpdateRightSelectionPosition ) + { + RepositionSelectionHandles( mEventData->mLeftSelectionPosition, + mEventData->mRightSelectionPosition ); - mEventData->mScrollAfterUpdatePosition = true; - } + mEventData->mScrollAfterUpdatePosition = true; } - mEventData->mDecoratorUpdated = true; } + mEventData->mDecoratorUpdated = true; } // end ( HANDLE_SCROLLING == state ) } @@ -928,8 +937,9 @@ void Controller::Impl::RepositionSelectionHandles( CharacterIndex selectionStart std::swap( selectionStart, selectionEnd ); } - GlyphIndex glyphStart = *( charactersToGlyphBuffer + selectionStart ); - GlyphIndex glyphEnd = *( charactersToGlyphBuffer + ( selectionEnd - 1u ) ) + *( glyphsPerCharacterBuffer + ( selectionEnd - 1u ) ) - 1u; + const GlyphIndex glyphStart = *( charactersToGlyphBuffer + selectionStart ); + const Length numberOfGlyphs = *( glyphsPerCharacterBuffer + ( selectionEnd - 1u ) ); + const GlyphIndex glyphEnd = *( charactersToGlyphBuffer + ( selectionEnd - 1u ) ) + ( ( numberOfGlyphs > 0 ) ? numberOfGlyphs - 1u : 0u ); mEventData->mDecorator->SwapSelectionHandlesEnabled( firstLine.direction != indicesSwapped ); @@ -937,6 +947,7 @@ void Controller::Impl::RepositionSelectionHandles( CharacterIndex selectionStart for( GlyphIndex index = glyphStart; index <= glyphEnd; ++index ) { + // TODO: Fix the LATIN ligatures. i.e ff, fi, etc... const GlyphInfo& glyph = *( glyphsBuffer + index ); const Vector2& position = *( positionsBuffer + index );