Merge "Underline predictive text after updating the model." into devel/master
authorPaul Wisbey <p.wisbey@samsung.com>
Fri, 21 Aug 2015 10:43:00 +0000 (03:43 -0700)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Fri, 21 Aug 2015 10:43:01 +0000 (03:43 -0700)
1  2 
dali-toolkit/internal/text/text-controller-impl.cpp

@@@ -436,6 -436,27 +436,27 @@@ void Controller::Impl::UpdateModel( Ope
        glyph.advance = 0.f;
      }
    }
+   if( mEventData &&
+       mEventData->mPreEditFlag &&
+       ( 0u != mVisualModel->mCharactersToGlyph.Count() ) )
+   {
+     // Add the underline for the pre-edit text.
+     const GlyphIndex* const charactersToGlyphBuffer = mVisualModel->mCharactersToGlyph.Begin();
+     const Length* const glyphsPerCharacterBuffer = mVisualModel->mGlyphsPerCharacter.Begin();
+     const GlyphIndex glyphStart = *( charactersToGlyphBuffer + mEventData->mPreEditStartPosition );
+     const CharacterIndex lastPreEditCharacter = mEventData->mPreEditStartPosition + ( ( mEventData->mPreEditLength > 0u ) ? mEventData->mPreEditLength - 1u : 0u );
+     const Length numberOfGlyphsLastCharacter = *( glyphsPerCharacterBuffer + lastPreEditCharacter );
+     const GlyphIndex glyphEnd = *( charactersToGlyphBuffer + lastPreEditCharacter ) + ( numberOfGlyphsLastCharacter > 1u ? numberOfGlyphsLastCharacter - 1u : 0u );
+     GlyphRun underlineRun;
+     underlineRun.glyphIndex = glyphStart;
+     underlineRun.numberOfGlyphs = 1u + glyphEnd - glyphStart;
+     // TODO: At the moment the underline runs are only for pre-edit.
+     mVisualModel->mUnderlineRuns.PushBack( underlineRun );
+   }
  }
  
  void Controller::Impl::GetDefaultFonts( Vector<FontRun>& fonts, Length numberOfCharacters )
@@@ -1320,25 -1341,10 +1341,25 @@@ LineIndex Controller::Impl::GetClosestL
  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;
  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.
    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;
  }