[Tizen] We also need to change the cursor position when the layout direction changes.
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-controller.cpp
index e660591..a3e122e 100755 (executable)
@@ -23,6 +23,8 @@
 #include <cmath>
 #include <memory.h>
 #include <dali/public-api/adaptor-framework/key.h>
+#include <dali/public-api/actors/layer.h>
+#include <dali/public-api/common/stage.h>
 #include <dali/integration-api/debug.h>
 #include <dali/devel-api/adaptor-framework/clipboard-event-notifier.h>
 #include <dali/devel-api/text-abstraction/font-client.h>
@@ -80,7 +82,6 @@ int ConvertPixelToPint( float pixel )
   return ( pixel * 72.f ) / static_cast< float >( horizontalDpi );
 }
 
-
 } // namespace
 
 namespace Dali
@@ -2144,7 +2145,7 @@ bool Controller::CheckForTextFit( float pointSize, Size& layoutSize )
 void Controller::FitPointSizeforLayout( Size layoutSize )
 {
   const OperationsMask operations  = mImpl->mOperationsPending;
-  if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
+  if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) || mImpl->mTextFitContentSize != layoutSize )
   {
     bool actualellipsis = mImpl->mModel->mElideEnabled;
     float minPointSize = mImpl->mTextFitMinSize;
@@ -2455,6 +2456,9 @@ Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
     // Clear the update info. This info will be set the next time the text is updated.
     mImpl->mTextUpdateInfo.Clear();
 
+    // FullRelayoutNeeded should be true because DoRelayout is MAX_FLOAT, MAX_FLOAT.
+    mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
+
     mImpl->mUpdateTextDirection = false;
   }
 
@@ -2473,7 +2477,7 @@ void Controller::SetVerticalLineAlignment( Toolkit::DevelText::VerticalLineAlign
 
 // public : Relayout.
 
-Controller::UpdateTextType Controller::Relayout( const Size& size, Dali::LayoutDirection::Type layoutDirection )
+Controller::UpdateTextType Controller::Relayout( const Size& size )
 {
   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false"  );
 
@@ -2546,20 +2550,31 @@ Controller::UpdateTextType Controller::Relayout( const Size& size, Dali::LayoutD
     mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
   }
 
-  if( mImpl->mModel->mMatchSystemLanguageDirection  && mImpl->mLayoutDirection != layoutDirection )
+  if( mImpl->mModel->mMatchSystemLanguageDirection )
   {
-    // Clear the update info. This info will be set the next time the text is updated.
-    mImpl->mTextUpdateInfo.mClearAll = true;
-    // Apply modifications to the model
-    // Shape the text again is needed because characters like '()[]{}' have to be mirrored and the glyphs generated again.
-    mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
-                                                             GET_GLYPH_METRICS         |
-                                                             SHAPE_TEXT                |
-                                                             UPDATE_DIRECTION          |
-                                                             LAYOUT                    |
-                                                             BIDI_INFO                 |
-                                                             REORDER );
-    mImpl->mLayoutDirection = layoutDirection;
+    Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Dali::Stage::GetCurrent().GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
+
+    if( mImpl->mLayoutDirection != layoutDirection )
+    {
+      // Clear the update info. This info will be set the next time the text is updated.
+      mImpl->mTextUpdateInfo.mClearAll = true;
+      // Apply modifications to the model
+      // Shape the text again is needed because characters like '()[]{}' have to be mirrored and the glyphs generated again.
+      mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
+                                                              GET_GLYPH_METRICS         |
+                                                              SHAPE_TEXT                |
+                                                              UPDATE_DIRECTION          |
+                                                              LAYOUT                    |
+                                                              BIDI_INFO                 |
+                                                              REORDER                   |
+                                                              ALIGN );
+      mImpl->mLayoutDirection = layoutDirection;
+      if( mImpl->mEventData )
+      {
+        mImpl->mEventData->mUpdateAlignment = true;
+        mImpl->mEventData->mUpdateCursorPosition = true;
+      }
+    }
   }
 
   // Make sure the model is up-to-date before layouting.
@@ -3712,11 +3727,7 @@ bool Controller::RemoveText( int cursorOffset,
       // it means all texts should be removed and all Preedit variables should be initialized.
       if( ( currentText.Count() - numberOfCharacters == 0 ) && ( cursorIndex == 0 ) )
       {
-        if( mImpl->mEventData )
-        {
-          mImpl->mEventData->mPreEditStartPosition = 0;
-          mImpl->mEventData->mPreEditLength = 0;
-        }
+        mImpl->ClearPreEditFlag();
       }
 
       // Updates the text style runs by removing characters. Runs with no characters are removed.
@@ -3733,6 +3744,11 @@ bool Controller::RemoveText( int cursorOffset,
 
       mImpl->mEventData->mScrollAfterDelete = true;
 
+      if( EventData::INACTIVE == mImpl->mEventData->mState )
+      {
+        mImpl->ChangeState( EventData::EDITING );
+      }
+
       DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
       removed = true;
     }
@@ -3825,17 +3841,16 @@ bool Controller::DoRelayout( const Size& size,
       return true;
     }
 
-    const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
-
     // Set the layout parameters.
     Layout::Parameters layoutParameters( size,
-                                         mImpl->mModel );
+                                         mImpl->mModel);
 
     // Resize the vector of positions to have the same size than the vector of glyphs.
     Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
     glyphPositions.Resize( totalNumberOfGlyphs );
 
     // Whether the last character is a new paragraph character.
+    const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
     mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph =  TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
     layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
 
@@ -3871,8 +3886,6 @@ bool Controller::DoRelayout( const Size& size,
     bool isAutoScrollEnabled = mImpl->mIsAutoScrollEnabled;
     Size newLayoutSize;
     viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
-                                                   glyphPositions,
-                                                   mImpl->mModel->mVisualModel->mLines,
                                                    newLayoutSize,
                                                    elideTextEnabled,
                                                    isAutoScrollEnabled );
@@ -3889,46 +3902,10 @@ bool Controller::DoRelayout( const Size& size,
         mImpl->mIsTextDirectionRTL = false;
       }
 
-      // Reorder the lines
-      if( NO_OPERATION != ( REORDER & operations ) )
+      if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && !mImpl->mModel->mVisualModel->mLines.Empty() )
       {
-        Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
-        Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
-
-        // Check first if there are paragraphs with bidirectional info.
-        if( 0u != bidirectionalInfo.Count() )
-        {
-          // Get the lines
-          const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
-
-          // Reorder the lines.
-          bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
-          ReorderLines( bidirectionalInfo,
-                        startIndex,
-                        requestedNumberOfCharacters,
-                        mImpl->mModel->mVisualModel->mLines,
-                        bidirectionalLineInfo );
-
-          // Set the bidirectional info per line into the layout parameters.
-          layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
-          layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
-
-          // Re-layout the text. Reorder those lines with right to left characters.
-          mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
-                                                         startIndex,
-                                                         requestedNumberOfCharacters,
-                                                         glyphPositions );
-
-          if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
-          {
-            const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
-            if ( firstline )
-            {
-              mImpl->mIsTextDirectionRTL = firstline->direction;
-            }
-          }
-        }
-      } // REORDER
+        mImpl->mIsTextDirectionRTL = mImpl->mModel->mVisualModel->mLines[0u].direction;
+      }
 
       // Sets the layout size.
       if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
@@ -4337,6 +4314,11 @@ bool Controller::ShouldClearFocusOnEscape() const
   return mImpl->mShouldClearFocusOnEscape;
 }
 
+Actor Controller::CreateBackgroundActor()
+{
+  return mImpl->CreateBackgroundActor();
+}
+
 // private : Private contructors & copy operator.
 
 Controller::Controller()