Spannable: Add StrikethroughSpan
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / controller / text-controller-impl-model-updater.cpp
index 8b6b639..91d7eaa 100644 (file)
@@ -20,6 +20,7 @@
 
 // EXTERNAL INCLUDES
 #include <dali/integration-api/debug.h>
+#include <dali/public-api/math/math-utils.h>
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/internal/text/bidirectional-support.h>
@@ -70,10 +71,17 @@ bool ControllerImplModelUpdater::Update(Controller::Impl& impl, OperationsMask o
   Vector<Character>& srcCharacters = impl.mModel->mLogicalModel->mText;
   Vector<Character>  displayCharacters;
   bool               useHiddenText = false;
-  if(impl.mHiddenInput && impl.mEventData != nullptr && !impl.mEventData->mIsShowingPlaceholderText)
+  if(impl.mHiddenInput && impl.mEventData != nullptr)
   {
-    impl.mHiddenInput->Substitute(srcCharacters, displayCharacters);
-    useHiddenText = true;
+    if(impl.mEventData->mIsShowingPlaceholderText)
+    {
+      impl.mHiddenInput->InitPreviousTextCount();
+    }
+    else
+    {
+      impl.mHiddenInput->Substitute(srcCharacters, displayCharacters, impl.mEventData->mPrimaryCursorPosition);
+      useHiddenText = true;
+    }
   }
 
   Vector<Character>& utf32Characters    = useHiddenText ? displayCharacters : srcCharacters;
@@ -330,7 +338,7 @@ bool ControllerImplModelUpdater::Update(Controller::Impl& impl, OperationsMask o
     updated = true;
   }
 
-  const Length numberOfGlyphs = glyphs.Count() - currentNumberOfGlyphs;
+  const Length numberOfGlyphs = static_cast<Length>(glyphs.Count()) - currentNumberOfGlyphs;
 
   if(Controller::NO_OPERATION != (Controller::GET_GLYPH_METRICS & operations))
   {
@@ -380,7 +388,8 @@ bool ControllerImplModelUpdater::Update(Controller::Impl& impl, OperationsMask o
           impl.mModel->mVisualModel->mUnderlineRuns.PushBack(underlineRun);
 
           //Mark-up processor case
-          if(impl.mModel->mVisualModel->IsMarkupProcessorEnabled())
+          if(impl.mModel->mVisualModel->IsMarkupProcessorEnabled() ||
+             impl.mModel->mLogicalModel->mUnderlineRunsUpdated)
           {
             impl.CopyUnderlinedFromLogicalToVisualModels(false);
           }
@@ -396,13 +405,13 @@ bool ControllerImplModelUpdater::Update(Controller::Impl& impl, OperationsMask o
           impl.mModel->mLogicalModel->mBackgroundColorRuns.PushBack(backgroundColorRun);
 
           Vector4 backgroundColor = impl.mModel->mVisualModel->GetBackgroundColor();
-          if(backgroundColor.a == 0) // There is no text background color.
+          if(Dali::EqualsZero(backgroundColor.a)) // There is no text background color.
           {
             // Try use the control's background color.
             if(nullptr != impl.mEditableControlInterface)
             {
               impl.mEditableControlInterface->GetControlBackgroundColor(backgroundColor);
-              if(backgroundColor.a == 0) // There is no control background color.
+              if(Dali::EqualsZero(backgroundColor.a)) // There is no control background color.
               {
                 // Determines black or white color according to text color.
                 // Based on W3C Recommendations (https://www.w3.org/TR/WCAG20/)
@@ -421,7 +430,8 @@ bool ControllerImplModelUpdater::Update(Controller::Impl& impl, OperationsMask o
           impl.mModel->mLogicalModel->mColorRuns.PushBack(colorRun);
 
           //Mark-up processor case
-          if(impl.mModel->mVisualModel->IsMarkupProcessorEnabled())
+          if(impl.mModel->mVisualModel->IsMarkupProcessorEnabled() ||
+             impl.mModel->mLogicalModel->mUnderlineRunsUpdated)
           {
             impl.CopyUnderlinedFromLogicalToVisualModels(false);
           }
@@ -436,7 +446,8 @@ bool ControllerImplModelUpdater::Update(Controller::Impl& impl, OperationsMask o
           impl.mModel->mLogicalModel->mBackgroundColorRuns.PushBack(backgroundColorRun);
 
           //Mark-up processor case
-          if(impl.mModel->mVisualModel->IsMarkupProcessorEnabled())
+          if(impl.mModel->mVisualModel->IsMarkupProcessorEnabled() ||
+             impl.mModel->mLogicalModel->mUnderlineRunsUpdated)
           {
             impl.CopyUnderlinedFromLogicalToVisualModels(false);
           }
@@ -457,7 +468,8 @@ bool ControllerImplModelUpdater::Update(Controller::Impl& impl, OperationsMask o
           impl.mModel->mVisualModel->mUnderlineRuns.PushBack(underlineRun);
 
           //Mark-up processor case
-          if(impl.mModel->mVisualModel->IsMarkupProcessorEnabled())
+          if(impl.mModel->mVisualModel->IsMarkupProcessorEnabled() ||
+             impl.mModel->mLogicalModel->mUnderlineRunsUpdated)
           {
             impl.CopyUnderlinedFromLogicalToVisualModels(false);
           }
@@ -478,7 +490,8 @@ bool ControllerImplModelUpdater::Update(Controller::Impl& impl, OperationsMask o
           impl.mModel->mVisualModel->mUnderlineRuns.PushBack(underlineRun);
 
           //Mark-up processor case
-          if(impl.mModel->mVisualModel->IsMarkupProcessorEnabled())
+          if(impl.mModel->mVisualModel->IsMarkupProcessorEnabled() ||
+             impl.mModel->mLogicalModel->mUnderlineRunsUpdated)
           {
             impl.CopyUnderlinedFromLogicalToVisualModels(false);
           }
@@ -499,7 +512,8 @@ bool ControllerImplModelUpdater::Update(Controller::Impl& impl, OperationsMask o
           impl.mModel->mVisualModel->mUnderlineRuns.PushBack(underlineRun);
 
           //Mark-up processor case
-          if(impl.mModel->mVisualModel->IsMarkupProcessorEnabled())
+          if(impl.mModel->mVisualModel->IsMarkupProcessorEnabled() ||
+             impl.mModel->mLogicalModel->mUnderlineRunsUpdated)
           {
             impl.CopyUnderlinedFromLogicalToVisualModels(false);
           }
@@ -520,7 +534,8 @@ bool ControllerImplModelUpdater::Update(Controller::Impl& impl, OperationsMask o
           impl.mModel->mVisualModel->mUnderlineRuns.PushBack(underlineRun);
 
           //Mark-up processor case
-          if(impl.mModel->mVisualModel->IsMarkupProcessorEnabled())
+          if(impl.mModel->mVisualModel->IsMarkupProcessorEnabled() ||
+             impl.mModel->mLogicalModel->mUnderlineRunsUpdated)
           {
             impl.CopyUnderlinedFromLogicalToVisualModels(false);
           }
@@ -568,7 +583,10 @@ bool ControllerImplModelUpdater::Update(Controller::Impl& impl, OperationsMask o
        (0u != impl.mModel->mVisualModel->mCharactersToGlyph.Count())))
   {
     //Mark-up processor case
-    if(impl.mModel->mVisualModel->IsMarkupProcessorEnabled())
+    if(impl.mModel->mVisualModel->IsMarkupProcessorEnabled() ||
+       impl.mModel->mLogicalModel->mUnderlineRunsUpdated ||
+       impl.mModel->mLogicalModel->mCharacterSpacingRunsUpdated ||
+       impl.mModel->mLogicalModel->mStrikethroughRunsUpdated)
     {
       impl.CopyUnderlinedFromLogicalToVisualModels(true);
       impl.CopyStrikethroughFromLogicalToVisualModels();