Merge "Fixes cursor status when editing with popup or grab handle." into devel/master
authorPaul Wisbey <p.wisbey@samsung.com>
Thu, 20 Aug 2015 15:09:53 +0000 (08:09 -0700)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Thu, 20 Aug 2015 15:09:54 +0000 (08:09 -0700)
1  2 
dali-toolkit/internal/text/text-controller-impl.cpp
dali-toolkit/internal/text/text-controller.cpp

@@@ -1053,9 -1053,6 +1053,9 @@@ void Controller::Impl::RepositionSelect
  
    mEventData->mDecorator->SetPosition( RIGHT_SELECTION_HANDLE, secondaryPosition.x, secondaryPosition.y, secondaryCursorInfo.lineHeight );
  
 +  // Cursor to be positioned at end of selection so if selection interrupted and edit mode restarted the cursor will be at end of selection
 +  mEventData->mPrimaryCursorPosition = (indicesSwapped)?mEventData->mLeftSelectionPosition:mEventData->mRightSelectionPosition;
 +
    // Set the flag to update the decorator.
    mEventData->mDecoratorUpdated = true;
  }
@@@ -1712,7 -1709,7 +1712,7 @@@ void Controller::Impl::UpdateCursorPosi
      return;
    }
  
 -  if( IsShowingPlaceholderText() )
 +  if( IsShowingPlaceholderText() || ( 0u == mLogicalModel->mText.Count() ) )
    {
      // Do not want to use the place-holder text to set the cursor position.
  
@@@ -1957,8 -1954,9 +1957,9 @@@ void Controller::Impl::ScrollTextToMatc
    }
  
    // Set which cursors are active according the state.
-   if( ( EventData::EDITING == mEventData->mState ) ||
-       ( EventData::EDITING_WITH_POPUP == mEventData->mState ) ||
+   if( ( EventData::EDITING == mEventData->mState )                  ||
+       ( EventData::EDITING_WITH_POPUP == mEventData->mState )       ||
+       ( EventData::EDITING_WITH_GRAB_HANDLE == mEventData->mState ) ||
        ( EventData::GRAB_HANDLE_PANNING == mEventData->mState ) )
    {
      if( cursorInfo.isSecondaryCursor )
@@@ -34,7 -34,7 +34,7 @@@ namespac
  {
  
  #if defined(DEBUG_ENABLED)
 -  Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
 +  Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
  #endif
  
  const float MAX_FLOAT = std::numeric_limits<float>::max();
@@@ -81,9 -81,10 +81,10 @@@ void Controller::SetText( const std::st
    if( mImpl->mEventData )
    {
      // If popup shown then hide it by switching to Editing state
-     if ( EventData::SELECTING == mImpl->mEventData->mState ||
-          EventData::SELECTION_CHANGED == mImpl->mEventData->mState ||
-          EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState )
+     if( ( EventData::SELECTING == mImpl->mEventData->mState )          ||
+         ( EventData::SELECTION_CHANGED == mImpl->mEventData->mState )  ||
+         ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
+         ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) )
      {
        mImpl->ChangeState( EventData::EDITING );
      }
@@@ -708,8 -709,9 +709,9 @@@ void Controller::ResetCursorPosition( C
      mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
  
      // Update the cursor if it's in editing mode.
-     if( ( EventData::EDITING == mImpl->mEventData->mState ) ||
-         ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) )
+     if( ( EventData::EDITING == mImpl->mEventData->mState )            ||
+         ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
+         ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) )
      {
        mImpl->mEventData->mUpdateCursorPosition = true;
      }
@@@ -762,8 -764,13 +764,13 @@@ void Controller::TextInsertedEvent(
                                                             REORDER );
  
    // Queue a cursor reposition event; this must wait until after DoRelayout()
-   mImpl->mEventData->mUpdateCursorPosition = true;
-   mImpl->mEventData->mScrollAfterUpdatePosition = true;
+   if( ( EventData::EDITING == mImpl->mEventData->mState )            ||
+       ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
+       ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) )
+   {
+     mImpl->mEventData->mUpdateCursorPosition = true;
+     mImpl->mEventData->mScrollAfterUpdatePosition = true;
+   }
  }
  
  void Controller::TextDeletedEvent()
                                                             REORDER );
  
    // Queue a cursor reposition event; this must wait until after DoRelayout()
 -  mImpl->mEventData->mScrollAfterDelete = true;
 +  if( 0u == mImpl->mLogicalModel->mText.Count() )
 +  {
 +    mImpl->mEventData->mUpdateCursorPosition = true;
 +  }
 +  else
 +  {
 +    mImpl->mEventData->mScrollAfterDelete = true;
 +  }
  }
  
  bool Controller::DoRelayout( const Size& size,
@@@ -1167,13 -1167,6 +1174,13 @@@ bool Controller::KeyEvent( const Dali::
        // Menu/Home key behaviour does not allow edit mode to resume like Power key
        // Avoids calling the InsertText() method which can delete selected text
      }
 +    else if( Dali::DALI_KEY_SHIFT_LEFT == keyCode )
 +    {
 +      // DALI_KEY_SHIFT_LEFT is the key code for the Left Shift. It's sent (by the imf?) when the predictive text is enabled
 +      // and a character is typed after the type of a upper case latin character.
 +
 +      // Do nothing.
 +    }
      else
      {
        DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
@@@ -1224,7 -1217,6 +1231,7 @@@ void Controller::InsertText( const std:
        0 != mImpl->mEventData->mPreEditLength )
    {
      CharacterIndex offset = mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition;
 +
      removedPrevious = RemoveText( -static_cast<int>(offset), mImpl->mEventData->mPreEditLength );
  
      mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
      removedPrevious = RemoveSelectedText();
    }
  
 -  if( ! text.empty() )
 +  if( !text.empty() )
    {
      //  Convert text into UTF-32
      utf32Characters.Resize( text.size() );
          mImpl->mEventData->mPreEditLength = utf32Characters.Count();
          mImpl->mEventData->mPreEditFlag = true;
  
 -        // Add the underline for the pre-edit text.
 -        const GlyphIndex* const charactersToGlyphBuffer = mImpl->mVisualModel->mCharactersToGlyph.Begin();
 -        const Length* const glyphsPerCharacterBuffer = mImpl->mVisualModel->mGlyphsPerCharacter.Begin();
 -
 -        const GlyphIndex glyphStart = *( charactersToGlyphBuffer + mImpl->mEventData->mPreEditStartPosition );
 -        const CharacterIndex lastPreEditCharacter = mImpl->mEventData->mPreEditStartPosition + ( ( mImpl->mEventData->mPreEditLength > 0u ) ? mImpl->mEventData->mPreEditLength - 1u : 0u );
 -        const Length numberOfGlyphsLastCharacter = *( glyphsPerCharacterBuffer + lastPreEditCharacter );
 -        const GlyphIndex glyphEnd = *( charactersToGlyphBuffer + lastPreEditCharacter ) + ( numberOfGlyphsLastCharacter > 1u ? numberOfGlyphsLastCharacter - 1u : 0u );
 +        if( 0u != mImpl->mVisualModel->mCharactersToGlyph.Count() )
 +        {
 +          // Add the underline for the pre-edit text.
 +          const GlyphIndex* const charactersToGlyphBuffer = mImpl->mVisualModel->mCharactersToGlyph.Begin();
 +          const Length* const glyphsPerCharacterBuffer = mImpl->mVisualModel->mGlyphsPerCharacter.Begin();
  
 -        GlyphRun underlineRun;
 -        underlineRun.glyphIndex = glyphStart;
 -        underlineRun.numberOfGlyphs = 1u + glyphEnd - glyphStart;
 +          const GlyphIndex glyphStart = *( charactersToGlyphBuffer + mImpl->mEventData->mPreEditStartPosition );
 +          const CharacterIndex lastPreEditCharacter = mImpl->mEventData->mPreEditStartPosition + ( ( mImpl->mEventData->mPreEditLength > 0u ) ? mImpl->mEventData->mPreEditLength - 1u : 0u );
 +          const Length numberOfGlyphsLastCharacter = *( glyphsPerCharacterBuffer + lastPreEditCharacter );
 +          const GlyphIndex glyphEnd = *( charactersToGlyphBuffer + lastPreEditCharacter ) + ( numberOfGlyphsLastCharacter > 1u ? numberOfGlyphsLastCharacter - 1u : 0u );
  
 -        // TODO: At the moment the underline runs are only for pre-edit.
 -        mImpl->mVisualModel->mUnderlineRuns.PushBack( underlineRun );
 +          GlyphRun underlineRun;
 +          underlineRun.glyphIndex = glyphStart;
 +          underlineRun.numberOfGlyphs = 1u + glyphEnd - glyphStart;
  
 +          // TODO: At the moment the underline runs are only for pre-edit.
 +          mImpl->mVisualModel->mUnderlineRuns.PushBack( underlineRun );
 +        }
          DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
        }
      }
@@@ -1656,21 -1646,7 +1663,21 @@@ ImfManager::ImfCallbackData Controller:
      }
      case ImfManager::DELETESURROUNDING:
      {
 -      RemoveText( imfEvent.cursorOffset, imfEvent.numberOfChars );
 +      update = RemoveText( imfEvent.cursorOffset, imfEvent.numberOfChars );
 +
 +      if( update )
 +      {
 +        if( 0u != mImpl->mLogicalModel->mText.Count() ||
 +            !mImpl->IsPlaceholderAvailable() )
 +        {
 +          mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
 +        }
 +        else
 +        {
 +          ShowPlaceholderText();
 +          mImpl->mEventData->mUpdateCursorPosition = true;
 +        }
 +      }
        requestRelayout = true;
        break;
      }