Cursor fix.
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-controller-impl.cpp
index f39effe..4ce45eb 100644 (file)
@@ -20,6 +20,7 @@
 
 // EXTERNAL INCLUDES
 #include <dali/public-api/adaptor-framework/key.h>
+#include <dali/integration-api/debug.h>
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/internal/text/bidirectional-support.h>
 namespace
 {
 
+#if defined(DEBUG_ENABLED)
+  Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
+#endif
+
 /**
  * @brief Some characters can be shaped in more than one glyph.
  * This struct is used to retrieve metrics from these group of glyphs.
@@ -138,9 +143,11 @@ EventData::~EventData()
 
 bool Controller::Impl::ProcessInputEvents()
 {
+  DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::ProcessInputEvents\n" );
   if( NULL == mEventData )
   {
     // Nothing to do if there is no text input.
+    DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::ProcessInputEvents no event data\n" );
     return false;
   }
 
@@ -235,86 +242,10 @@ bool Controller::Impl::ProcessInputEvents()
 
   mEventData->mEventQueue.clear();
 
+  DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::ProcessInputEvents\n" );
   return mEventData->mDecoratorUpdated;
 }
 
-void Controller::Impl::ReplaceTextWithPlaceholder()
-{
-  DALI_ASSERT_DEBUG( mEventData && "No placeholder text available" );
-  if( !mEventData )
-  {
-    return;
-  }
-
-  // Disable handles when showing place-holder text
-  mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
-  mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
-  mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
-
-  const char* text( NULL );
-  size_t size( 0 );
-
-  if( EventData::INACTIVE != mEventData->mState &&
-      0u != mEventData->mPlaceholderTextActive.c_str() )
-  {
-    text = mEventData->mPlaceholderTextActive.c_str();
-    size = mEventData->mPlaceholderTextActive.size();
-  }
-
-  else
-  {
-    text = mEventData->mPlaceholderTextInactive.c_str();
-    size = mEventData->mPlaceholderTextInactive.size();
-  }
-
-  // Reset buffers.
-  mLogicalModel->mText.Clear();
-  mLogicalModel->mScriptRuns.Clear();
-  mLogicalModel->mFontRuns.Clear();
-  mLogicalModel->mLineBreakInfo.Clear();
-  mLogicalModel->mWordBreakInfo.Clear();
-  mLogicalModel->mBidirectionalParagraphInfo.Clear();
-  mLogicalModel->mCharacterDirections.Clear();
-  mLogicalModel->mBidirectionalLineInfo.Clear();
-  mLogicalModel->mLogicalToVisualMap.Clear();
-  mLogicalModel->mVisualToLogicalMap.Clear();
-  mVisualModel->mGlyphs.Clear();
-  mVisualModel->mGlyphsToCharacters.Clear();
-  mVisualModel->mCharactersToGlyph.Clear();
-  mVisualModel->mCharactersPerGlyph.Clear();
-  mVisualModel->mGlyphsPerCharacter.Clear();
-  mVisualModel->mGlyphPositions.Clear();
-  mVisualModel->mLines.Clear();
-  mVisualModel->ClearCaches();
-  mVisualModel->SetTextColor( mEventData->mPlaceholderTextColor );
-
-  //  Convert text into UTF-32
-  Vector<Character>& utf32Characters = mLogicalModel->mText;
-  utf32Characters.Resize( size );
-
-  // This is a bit horrible but std::string returns a (signed) char*
-  const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
-
-  // Transform a text array encoded in utf8 into an array encoded in utf32.
-  // It returns the actual number of characters.
-  Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
-  utf32Characters.Resize( characterCount );
-
-  // Reset the cursor position
-  mEventData->mPrimaryCursorPosition = 0;
-
-  // The natural size needs to be re-calculated.
-  mRecalculateNaturalSize = true;
-
-  // Apply modifications to the model
-  mOperationsPending = ALL_OPERATIONS;
-  UpdateModel( ALL_OPERATIONS );
-  mOperationsPending = static_cast<OperationsMask>( LAYOUT             |
-                                                    ALIGN              |
-                                                    UPDATE_ACTUAL_SIZE |
-                                                    REORDER );
-}
-
 void Controller::Impl::UpdateModel( OperationsMask operationsRequired )
 {
   // Calculate the operations to be done.
@@ -322,7 +253,7 @@ void Controller::Impl::UpdateModel( OperationsMask operationsRequired )
 
   Vector<Character>& utf32Characters = mLogicalModel->mText;
 
-  const Length numberOfCharacters = mLogicalModel->GetNumberOfCharacters();
+  const Length numberOfCharacters = utf32Characters.Count();
 
   Vector<LineBreakInfo>& lineBreakInfo = mLogicalModel->mLineBreakInfo;
   if( GET_LINE_BREAKS & operations )
@@ -532,44 +463,33 @@ void Controller::Impl::OnCursorKeyEvent( const Event& event )
 
 void Controller::Impl::OnTapEvent( const Event& event )
 {
-  if( NULL == mEventData )
+  if( NULL != mEventData )
   {
-    // Nothing to do if there is no text input.
-    return;
-  }
-
-  const unsigned int tapCount = event.p1.mUint;
+    const unsigned int tapCount = event.p1.mUint;
 
-  if( 1u == tapCount )
-  {
-    // Grab handle is not shown until a tap is received whilst EDITING
-    if( EventData::EDITING == mEventData->mState &&
-        !IsShowingPlaceholderText() )
+    if( 1u == tapCount )
     {
-      if( mEventData->mGrabHandleEnabled )
+      if( ! IsShowingPlaceholderText() )
       {
-        mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, true );
-      }
-      mEventData->mDecorator->SetPopupActive( false );
-    }
-
-    ChangeState( EventData::EDITING );
-
-    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 );
+        const float xPosition = event.p2.mFloat - mEventData->mScrollPosition.x - mAlignmentOffset.x;
+        const float yPosition = event.p3.mFloat - mEventData->mScrollPosition.y - mAlignmentOffset.y;
 
-    mEventData->mUpdateCursorPosition = true;
-    mEventData->mScrollAfterUpdateCursorPosition = true;
-  }
-  else if( mEventData->mSelectionEnabled &&
-           ( 2u == tapCount ) )
-  {
-    ChangeState( EventData::SELECTING );
+        mEventData->mPrimaryCursorPosition = GetClosestCursorIndex( xPosition,
+                                                                    yPosition );
+      }
+      else
+      {
+        mEventData->mPrimaryCursorPosition = 0u;
+      }
 
-    RepositionSelectionHandles( event.p2.mFloat, event.p3.mFloat );
+      mEventData->mUpdateCursorPosition = true;
+      mEventData->mScrollAfterUpdateCursorPosition = true;
+    }
+    else if( mEventData->mSelectionEnabled &&
+             ( 2u == tapCount ) )
+    {
+      RepositionSelectionHandles( event.p2.mFloat, event.p3.mFloat );
+    }
   }
 }
 
@@ -740,23 +660,8 @@ void Controller::Impl::ChangeState( EventData::State newState )
 
   if( mEventData->mState != newState )
   {
-    // Show different placeholder when switching between active & inactive
-    bool updatePlaceholder( false );
-    if( IsShowingPlaceholderText() &&
-        ( EventData::INACTIVE == newState ||
-          EventData::INACTIVE == mEventData->mState ) )
-    {
-      updatePlaceholder = true;
-    }
-
     mEventData->mState = newState;
 
-    if( updatePlaceholder )
-    {
-      ReplaceTextWithPlaceholder();
-      mEventData->mDecoratorUpdated = true;
-    }
-
     if( EventData::INACTIVE == mEventData->mState )
     {
       mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_NONE );
@@ -1155,9 +1060,11 @@ CharacterIndex Controller::Impl::CalculateNewCursorIndex( CharacterIndex index )
 
 void Controller::Impl::UpdateCursorPosition()
 {
+  DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::UpdateCursorPosition %p\n", this );
   if( NULL == mEventData )
   {
     // Nothing to do if there is no text input.
+    DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::UpdateCursorPosition no event data\n" );
     return;
   }
 
@@ -1174,6 +1081,7 @@ void Controller::Impl::UpdateCursorPosition()
                                        cursorPosition.y,
                                        cursorInfo.primaryCursorHeight,
                                        cursorInfo.lineHeight );
+  DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Primary cursor position: %f,%f\n", cursorPosition.x, cursorPosition.y );
 
   // Sets the grab handle position.
   mEventData->mDecorator->SetPosition( GRAB_HANDLE,
@@ -1189,11 +1097,13 @@ void Controller::Impl::UpdateCursorPosition()
                                          cursorInfo.secondaryPosition.y + offset.y,
                                          cursorInfo.secondaryCursorHeight,
                                          cursorInfo.lineHeight );
+    DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Secondary cursor position: %f,%f\n", cursorInfo.secondaryPosition.x + offset.x, cursorInfo.secondaryPosition.y + offset.y );
   }
   else
   {
     mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_PRIMARY );
   }
+  DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::UpdateCursorPosition\n" );
 }
 
 void Controller::Impl::UpdateSelectionHandle( HandleType handleType )