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=55b5893f376b39ad1aef39eaa124ffdfc0853c4d;hp=14844672f90652d6a588b641d2d8da0e9e448079;hb=2047844bb3b4a84231905c8c540d34d4c468e5ad;hpb=b8dec7134bf61ca6b9e47efce907131cb326cc64 diff --git a/dali-toolkit/internal/text/text-controller-impl.cpp b/dali-toolkit/internal/text/text-controller-impl.cpp index 1484467..55b5893 100644 --- a/dali-toolkit/internal/text/text-controller-impl.cpp +++ b/dali-toolkit/internal/text/text-controller-impl.cpp @@ -78,20 +78,20 @@ namespace Text * @param[in] numberOfGlyphs The number of glyphs. * @param[out] glyphMetrics Some glyph metrics (font height, advance, ascender and x bearing). * @param[in] visualModel The visual model. - * @param[in] fontClient The font client. + * @param[in] metrics Used to access metrics from FontClient. */ void GetGlyphsMetrics( GlyphIndex glyphIndex, Length numberOfGlyphs, GlyphMetrics& glyphMetrics, - VisualModelPtr visualModel, - TextAbstraction::FontClient& fontClient ) + VisualModelPtr& visualModel, + MetricsPtr& metrics ) { const GlyphInfo* glyphsBuffer = visualModel->mGlyphs.Begin(); const GlyphInfo& firstGlyph = *( glyphsBuffer + glyphIndex ); Text::FontMetrics fontMetrics; - fontClient.GetFontMetrics( firstGlyph.fontId, fontMetrics ); + metrics->GetFontMetrics( firstGlyph.fontId, fontMetrics ); glyphMetrics.fontHeight = fontMetrics.height; glyphMetrics.advance = firstGlyph.advance; @@ -423,7 +423,7 @@ void Controller::Impl::UpdateModel( OperationsMask operationsRequired ) if( GET_GLYPH_METRICS & operations ) { GlyphInfo* glyphsBuffer = glyphs.Begin(); - mFontClient.GetGlyphMetrics( glyphsBuffer, numberOfGlyphs ); + mMetrics->GetGlyphMetrics( glyphsBuffer, numberOfGlyphs ); // Update the width and advance of all new paragraph characters. for( Vector::ConstIterator it = newParagraphGlyphs.Begin(), endIt = newParagraphGlyphs.End(); it != endIt; ++it ) @@ -487,7 +487,7 @@ float Controller::Impl::GetDefaultFontLineHeight() } Text::FontMetrics fontMetrics; - mFontClient.GetFontMetrics( defaultFontId, fontMetrics ); + mMetrics->GetFontMetrics( defaultFontId, fontMetrics ); return( fontMetrics.ascender - fontMetrics.descender ); } @@ -537,13 +537,16 @@ void Controller::Impl::OnTapEvent( const Event& event ) if( 1u == tapCount ) { - if( ! IsShowingPlaceholderText() ) + if( IsShowingRealText() ) { const float xPosition = event.p2.mFloat - mEventData->mScrollPosition.x - mAlignmentOffset.x; const float yPosition = event.p3.mFloat - mEventData->mScrollPosition.y - mAlignmentOffset.y; mEventData->mPrimaryCursorPosition = GetClosestCursorIndex( xPosition, yPosition ); + + // When the cursor position is changing, delay cursor blinking + mEventData->mDecorator->DelayCursorBlink(); } else { @@ -878,7 +881,7 @@ void Controller::Impl::RetrieveSelection( std::string& selectedText, bool delete uint32_t lengthOfSelectedText = mEventData->mRightSelectionPosition - startOfSelectedText; // Validate the start and end selection points - if( ( startOfSelectedText >= 0 ) && ( ( startOfSelectedText + lengthOfSelectedText ) <= mLogicalModel->mText.Count() ) ) + if( ( startOfSelectedText + lengthOfSelectedText ) <= mLogicalModel->mText.Count() ) { //Get text as a UTF8 string Vector& utf32Characters = mLogicalModel->mText; @@ -1341,10 +1344,25 @@ LineIndex Controller::Impl::GetClosestLine( float y ) const void Controller::Impl::FindSelectionIndices( float visualX, float visualY, CharacterIndex& startIndex, CharacterIndex& endIndex ) { CharacterIndex hitCharacter = GetClosestCursorIndex( visualX, visualY ); + DALI_ASSERT_DEBUG( hitCharacter <= mLogicalModel->mText.Count() && "GetClosestCursorIndex returned out of bounds index" ); + + if ( mLogicalModel->mText.Count() == 0 ) + { + return; // if model empty + } + if( hitCharacter >= mLogicalModel->mText.Count() ) { - // Selection out of bounds. - return; + // Closest hit character is the last character. + if ( hitCharacter == mLogicalModel->mText.Count() ) + { + hitCharacter--; //Hit character index set to last character in logical model + } + else + { + // hitCharacter is out of bounds + return; + } } startIndex = hitCharacter; @@ -1376,6 +1394,8 @@ void Controller::Impl::FindSelectionIndices( float visualX, float visualY, Chara CharacterIndex Controller::Impl::GetClosestCursorIndex( float visualX, float visualY ) { + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "GetClosestCursorIndex %p closest visualX %f visualY %f\n", this, visualX, visualY ); + if( NULL == mEventData ) { // Nothing to do if there is no text input. @@ -1442,7 +1462,7 @@ CharacterIndex Controller::Impl::GetClosestCursorIndex( float visualX, numberOfGlyphs, glyphMetrics, mVisualModel, - mFontClient ); + mMetrics ); const Vector2& position = *( positionsBuffer + glyphLogicalOrderIndex ); @@ -1479,6 +1499,8 @@ CharacterIndex Controller::Impl::GetClosestCursorIndex( float visualX, logicalIndex = hasRightToLeftCharacters ? *( visualToLogicalCursorBuffer + visualIndex ) : visualIndex; DALI_LOG_INFO( gLogFilter, Debug::Verbose, "%p closest visualIndex %d logicalIndex %d\n", this, visualIndex, logicalIndex ); + DALI_ASSERT_DEBUG( ( logicalIndex <= mLogicalModel->mText.Count() && logicalIndex >= 0 ) && "GetClosestCursorIndex - Out of bounds index" ); + return logicalIndex; } @@ -1579,7 +1601,7 @@ void Controller::Impl::GetCursorPosition( CharacterIndex logical, primaryNumberOfGlyphs, glyphMetrics, mVisualModel, - mFontClient ); + mMetrics ); // Whether to add the glyph's advance to the cursor position. // i.e if the paragraph is left to right and the logical cursor is zero, the position is the position of the first glyph and the advance is not added, @@ -1669,7 +1691,7 @@ void Controller::Impl::GetCursorPosition( CharacterIndex logical, secondaryNumberOfGlyphs, glyphMetrics, mVisualModel, - mFontClient ); + mMetrics ); // Set the secondary cursor's position. cursorInfo.secondaryPosition.x = -glyphMetrics.xBearing + secondaryPosition.x + ( isCurrentRightToLeft ? 0.f : glyphMetrics.advance ); @@ -1755,7 +1777,7 @@ void Controller::Impl::UpdateCursorPosition() } Text::FontMetrics fontMetrics; - mFontClient.GetFontMetrics( defaultFontId, fontMetrics ); + mMetrics->GetFontMetrics( defaultFontId, fontMetrics ); lineHeight = fontMetrics.ascender - fontMetrics.descender;