Dali-Text: Keyboard Shortcuts
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-controller-impl.cpp
old mode 100755 (executable)
new mode 100644 (file)
index fa48e52..0a8fe4b
@@ -98,6 +98,12 @@ struct BackgroundMesh
   Vector< unsigned short > mIndices;       ///< container of indices
 };
 
+const Dali::Vector4 LIGHT_BLUE( 0.75f, 0.96f, 1.f, 1.f );
+const Dali::Vector4 BACKGROUND_SUB4( 0.58f, 0.87f, 0.96f, 1.f );
+const Dali::Vector4 BACKGROUND_SUB5( 0.83f, 0.94f, 0.98f, 1.f );
+const Dali::Vector4 BACKGROUND_SUB6( 1.f, 0.5f, 0.5f, 1.f );
+const Dali::Vector4 BACKGROUND_SUB7( 1.f, 0.8f, 0.8f, 1.f );
+
 } // namespace
 
 namespace Dali
@@ -215,6 +221,11 @@ bool Controller::Impl::ProcessInputEvents()
           OnSelectAllEvent();
           break;
         }
+        case Event::SELECT_NONE:
+        {
+          OnSelectNoneEvent();
+          break;
+        }
       }
     }
   }
@@ -1080,35 +1091,130 @@ bool Controller::Impl::UpdateModel( OperationsMask operationsRequired )
       mEventData->mPreEditFlag &&
       ( 0u != mModel->mVisualModel->mCharactersToGlyph.Count() ) )
   {
-    Dali::InputMethodContext::PreeditStyle type = mEventData->mInputMethodContext.GetPreeditStyle();
+    Dali::InputMethodContext::PreEditAttributeDataContainer attrs;
+    mEventData->mInputMethodContext.GetPreeditStyle( attrs );
+    Dali::InputMethodContext::PreeditStyle type = Dali::InputMethodContext::PreeditStyle::NONE;
 
-    switch( type )
+    // Check the type of preedit and run it.
+    for( Dali::InputMethodContext::PreEditAttributeDataContainer::Iterator it = attrs.Begin(), endIt = attrs.End(); it != endIt; it++ )
     {
-      case Dali::InputMethodContext::PreeditStyle::UNDERLINE:
-      {
-        // Add the underline for the pre-edit text.
-        const GlyphIndex* const charactersToGlyphBuffer = mModel->mVisualModel->mCharactersToGlyph.Begin();
-        const Length* const glyphsPerCharacterBuffer = mModel->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 );
+      Dali::InputMethodContext::PreeditAttributeData attrData = *it;
+      DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::UpdateModel PreeditStyle type : %d  start %d end %d \n", attrData.preeditType, attrData.startIndex, attrData.endIndex  );
+      type = attrData.preeditType;
 
-        GlyphRun underlineRun;
-        underlineRun.glyphIndex = glyphStart;
-        underlineRun.numberOfGlyphs = 1u + glyphEnd - glyphStart;
+      // Check the number of commit characters for the start position.
+      unsigned int numberOfCommit = mEventData->mPrimaryCursorPosition - mEventData->mPreEditLength;
+      Length numberOfIndices = attrData.endIndex - attrData.startIndex;
 
-        mModel->mVisualModel->mUnderlineRuns.PushBack( underlineRun );
-        break;
+      switch( type )
+      {
+        case Dali::InputMethodContext::PreeditStyle::UNDERLINE:
+        {
+          // Add the underline for the pre-edit text.
+          GlyphRun underlineRun;
+          underlineRun.glyphIndex = attrData.startIndex + numberOfCommit;
+          underlineRun.numberOfGlyphs = numberOfIndices;
+          mModel->mVisualModel->mUnderlineRuns.PushBack( underlineRun );
+          break;
+        }
+        case Dali::InputMethodContext::PreeditStyle::REVERSE:
+        {
+          Vector4 textColor = mModel->mVisualModel->GetTextColor();
+          ColorRun backgroundColorRun;
+          backgroundColorRun.characterRun.characterIndex = attrData.startIndex + numberOfCommit;
+          backgroundColorRun.characterRun.numberOfCharacters = numberOfIndices;
+          backgroundColorRun.color = textColor;
+          mModel->mLogicalModel->mBackgroundColorRuns.PushBack( backgroundColorRun );
+
+          Vector4 backgroundColor = mModel->mVisualModel->GetBackgroundColor();
+          Vector<ColorRun>  colorRuns;
+          colorRuns.Resize( 1u );
+          ColorRun& colorRun = *( colorRuns.Begin() );
+          colorRun.color = backgroundColor;
+          colorRun.characterRun.characterIndex = attrData.startIndex + numberOfCommit;
+          colorRun.characterRun.numberOfCharacters = numberOfIndices;
+
+          mModel->mLogicalModel->mColorRuns.PushBack( colorRun );
+          break;
+        }
+        case Dali::InputMethodContext::PreeditStyle::HIGHLIGHT:
+        {
+          ColorRun backgroundColorRun;
+          backgroundColorRun.characterRun.characterIndex = attrData.startIndex + numberOfCommit;
+          backgroundColorRun.characterRun.numberOfCharacters = numberOfIndices;
+          backgroundColorRun.color = LIGHT_BLUE;
+          mModel->mLogicalModel->mBackgroundColorRuns.PushBack( backgroundColorRun );
+          break;
+        }
+        case Dali::InputMethodContext::PreeditStyle::CUSTOM_PLATFORM_STYLE_1:
+        {
+          // CUSTOM_PLATFORM_STYLE_1 should be drawn with background and underline together.
+          ColorRun backgroundColorRun;
+          backgroundColorRun.characterRun.characterIndex = attrData.startIndex + numberOfCommit;
+          backgroundColorRun.characterRun.numberOfCharacters = numberOfIndices;
+          backgroundColorRun.color = BACKGROUND_SUB4;
+          mModel->mLogicalModel->mBackgroundColorRuns.PushBack( backgroundColorRun );
+
+          GlyphRun underlineRun;
+          underlineRun.glyphIndex = attrData.startIndex + numberOfCommit;
+          underlineRun.numberOfGlyphs = numberOfIndices;
+          mModel->mVisualModel->mUnderlineRuns.PushBack( underlineRun );
+          break;
+        }
+        case Dali::InputMethodContext::PreeditStyle::CUSTOM_PLATFORM_STYLE_2:
+        {
+          // CUSTOM_PLATFORM_STYLE_2 should be drawn with background and underline together.
+          ColorRun backgroundColorRun;
+          backgroundColorRun.characterRun.characterIndex = attrData.startIndex + numberOfCommit;
+          backgroundColorRun.characterRun.numberOfCharacters = numberOfIndices;
+          backgroundColorRun.color = BACKGROUND_SUB5;
+          mModel->mLogicalModel->mBackgroundColorRuns.PushBack( backgroundColorRun );
+
+          GlyphRun underlineRun;
+          underlineRun.glyphIndex = attrData.startIndex + numberOfCommit;
+          underlineRun.numberOfGlyphs = numberOfIndices;
+          mModel->mVisualModel->mUnderlineRuns.PushBack( underlineRun );
+          break;
+        }
+        case Dali::InputMethodContext::PreeditStyle::CUSTOM_PLATFORM_STYLE_3:
+        {
+          // CUSTOM_PLATFORM_STYLE_3 should be drawn with background and underline together.
+          ColorRun backgroundColorRun;
+          backgroundColorRun.characterRun.characterIndex = attrData.startIndex + numberOfCommit;
+          backgroundColorRun.characterRun.numberOfCharacters = numberOfIndices;
+          backgroundColorRun.color = BACKGROUND_SUB6;
+          mModel->mLogicalModel->mBackgroundColorRuns.PushBack( backgroundColorRun );
+
+          GlyphRun underlineRun;
+          underlineRun.glyphIndex = attrData.startIndex + numberOfCommit;
+          underlineRun.numberOfGlyphs = numberOfIndices;
+          mModel->mVisualModel->mUnderlineRuns.PushBack( underlineRun );
+          break;
+        }
+        case Dali::InputMethodContext::PreeditStyle::CUSTOM_PLATFORM_STYLE_4:
+        {
+          // CUSTOM_PLATFORM_STYLE_4 should be drawn with background and underline together.
+          ColorRun backgroundColorRun;
+          backgroundColorRun.characterRun.characterIndex = attrData.startIndex + numberOfCommit;
+          backgroundColorRun.characterRun.numberOfCharacters = numberOfIndices;
+          backgroundColorRun.color = BACKGROUND_SUB7;
+          mModel->mLogicalModel->mBackgroundColorRuns.PushBack( backgroundColorRun );
+
+          GlyphRun underlineRun;
+          underlineRun.glyphIndex = attrData.startIndex + numberOfCommit;
+          underlineRun.numberOfGlyphs = numberOfIndices;
+          mModel->mVisualModel->mUnderlineRuns.PushBack( underlineRun );
+          break;
+        }
+        case Dali::InputMethodContext::PreeditStyle::NONE:
+        default:
+        {
+          break;
+        }
       }
-      // TODO :  At this moment, other styles for preedit are not implemented yet.
-      case Dali::InputMethodContext::PreeditStyle::REVERSE:
-      case Dali::InputMethodContext::PreeditStyle::HIGHLIGHT:
-      case Dali::InputMethodContext::PreeditStyle::NONE:
-      default:
-        break;
     }
+    attrs.Clear();
+    updated = true;
   }
 
   if( NO_OPERATION != ( COLOR & operations ) )
@@ -1495,17 +1601,16 @@ void Controller::Impl::OnPanEvent( const Event& event )
     return;
   }
 
-  const int state = event.p1.mInt;
-
+  const GestureState state = static_cast<GestureState>( event.p1.mInt );
   switch( state )
   {
-    case Gesture::Started:
+    case GestureState::STARTED:
     {
       // Will remove the cursor, handles or text's popup, ...
       ChangeState( EventData::TEXT_PANNING );
       break;
     }
-    case Gesture::Continuing:
+    case GestureState::CONTINUING:
     {
       const Vector2& layoutSize = mModel->mVisualModel->GetLayoutSize();
       const Vector2 currentScroll = mModel->mScrollPosition;
@@ -1529,8 +1634,8 @@ void Controller::Impl::OnPanEvent( const Event& event )
       mEventData->mDecorator->UpdatePositions( mModel->mScrollPosition - currentScroll );
       break;
     }
-    case Gesture::Finished:
-    case Gesture::Cancelled: // FALLTHROUGH
+    case GestureState::FINISHED:
+    case GestureState::CANCELLED: // FALLTHROUGH
     {
       // Will go back to the previous state to show the cursor, handles, the text's popup, ...
       ChangeState( mEventData->mPreviousState );
@@ -1914,6 +2019,27 @@ void Controller::Impl::OnSelectAllEvent()
   }
 }
 
+void Controller::Impl::OnSelectNoneEvent()
+{
+  DALI_LOG_INFO( gLogFilter, Debug::Verbose, "OnSelectNoneEvent mEventData->mSelectionEnabled%s \n", mEventData->mSelectionEnabled?"true":"false");
+
+  if( NULL == mEventData )
+  {
+    // Nothing to do if there is no text.
+    return;
+  }
+
+  if( mEventData->mSelectionEnabled && mEventData->mState == EventData::SELECTING)
+  {
+    mEventData->mPrimaryCursorPosition = 0u;
+    mEventData->mLeftSelectionPosition = mEventData->mRightSelectionPosition = mEventData->mPrimaryCursorPosition;
+    ChangeState( EventData::INACTIVE );
+    mEventData->mUpdateCursorPosition = true;
+    mEventData->mUpdateInputStyle = true;
+    mEventData->mScrollAfterUpdatePosition = true;
+  }
+}
+
 void Controller::Impl::RetrieveSelection( std::string& selectedText, bool deleteAfterRetrieval )
 {
   if( mEventData->mLeftSelectionPosition == mEventData->mRightSelectionPosition )
@@ -3165,6 +3291,7 @@ Actor Controller::Impl::CreateBackgroundActor()
 
     const Vector4* const backgroundColorsBuffer = mView.GetBackgroundColors();
     const ColorIndex* const backgroundColorIndicesBuffer = mView.GetBackgroundColorIndices();
+    const Vector4& defaultBackgroundColor = mModel->mVisualModel->IsBackgroundEnabled() ? mModel->mVisualModel->GetBackgroundColor() : Color::TRANSPARENT;
 
     Vector4 quad;
     uint32_t numberOfQuads = 0u;
@@ -3176,7 +3303,7 @@ Actor Controller::Impl::CreateBackgroundActor()
       // Get the background color of the character.
       // The color index zero is reserved for the default background color (i.e. Color::TRANSPARENT)
       const ColorIndex backgroundColorIndex = ( nullptr == backgroundColorsBuffer ) ? 0u : *( backgroundColorIndicesBuffer + i );
-      const Vector4& backgroundColor = ( 0u == backgroundColorIndex ) ? Color::TRANSPARENT : *( backgroundColorsBuffer + backgroundColorIndex - 1u );
+      const Vector4& backgroundColor = ( 0u == backgroundColorIndex ) ? defaultBackgroundColor : *( backgroundColorsBuffer + backgroundColorIndex - 1u );
 
       // Only create quads for glyphs with a background color
       if ( backgroundColor != Color::TRANSPARENT )
@@ -3257,7 +3384,7 @@ Actor Controller::Impl::CreateBackgroundActor()
       quadVertexFormat[ "aPosition" ] = Property::VECTOR2;
       quadVertexFormat[ "aColor" ] = Property::VECTOR4;
 
-      PropertyBuffer quadVertices = PropertyBuffer::New( quadVertexFormat );
+      VertexBuffer quadVertices = VertexBuffer::New( quadVertexFormat );
       quadVertices.SetData( &mesh.mVertices[ 0 ], mesh.mVertices.Size() );
 
       Geometry quadGeometry = Geometry::New();
@@ -3274,11 +3401,11 @@ Actor Controller::Impl::CreateBackgroundActor()
       renderer.SetProperty( Dali::Renderer::Property::DEPTH_INDEX, DepthIndex::CONTENT );
 
       actor = Actor::New();
-      actor.SetName( "TextBackgroundColorActor" );
-      actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
-      actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
-      actor.SetSize( textSize );
-      actor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
+      actor.SetProperty( Dali::Actor::Property::NAME, "TextBackgroundColorActor" );
+      actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+      actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+      actor.SetProperty( Actor::Property::SIZE, textSize );
+      actor.SetProperty( Actor::Property::COLOR_MODE, USE_OWN_MULTIPLY_PARENT_COLOR );
       actor.AddRenderer( renderer );
     }
   }