Fix hidden input issue 35/284735/7
authorBowon Ryu <bowon.ryu@samsung.com>
Thu, 24 Nov 2022 10:56:16 +0000 (19:56 +0900)
committerBowon Ryu <bowon.ryu@samsung.com>
Fri, 25 Nov 2022 05:30:41 +0000 (14:30 +0900)
Fixed issues with SHOW_LAST_CHARACTER mode
- After all text is deleted, the first input character is not visible.
- The last character is always visible regardless of the position of the cursor.

Change-Id: I48689bf7e38b05c655d416c4e2df1d4553dca992
Signed-off-by: Bowon Ryu <bowon.ryu@samsung.com>
automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp
dali-toolkit/internal/text/controller/text-controller-impl-model-updater.cpp
dali-toolkit/internal/text/hidden-text.cpp
dali-toolkit/internal/text/hidden-text.h

index df1c60b..94855ca 100644 (file)
@@ -3012,6 +3012,7 @@ int utcDaliTextFieldEvent09(void)
   application.Render();
 
   field.SetProperty(TextField::Property::TEXT, "Hello");
+  field.SetProperty(TextField::Property::PLACEHOLDER_TEXT, "Placeholder text");
   field.SetProperty(TextField::Property::POINT_SIZE, 10.f);
   field.SetProperty(Actor::Property::SIZE, Vector2(300.f, 50.f));
   field.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
@@ -3031,6 +3032,12 @@ int utcDaliTextFieldEvent09(void)
   application.ProcessEvent(GenerateKey("d", "", "d", 0, 0, 0, Integration::KeyEvent::DOWN, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE));
   application.SendNotification();
   application.Render();
+  for(unsigned int index = 0u; index < 6u; ++index)
+  {
+    application.ProcessEvent(GenerateKey("", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE));
+    application.SendNotification();
+    application.Render();
+  }
 
   map[HiddenInput::Property::MODE]                 = HiddenInput::Mode::HIDE_ALL;
   map[HiddenInput::Property::SUBSTITUTE_CHARACTER] = 0x23;
index adf1af0..ff4697b 100644 (file)
@@ -70,10 +70,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;
index ab2aba5..5259350 100644 (file)
@@ -42,7 +42,8 @@ HiddenText::HiddenText(Observer* observer)
   mSubstituteText(STAR),
   mDisplayDuration(DEFAULT_SHOW_DURATION),
   mSubstituteCount(0),
-  mPreviousTextCount(0)
+  mPreviousTextCount(0u),
+  mIsLastCharacterShow(false)
 {
   mTimer = Timer::New(mDisplayDuration);
   mTimer.TickSignal().Connect(this, &HiddenText::OnTick);
@@ -85,7 +86,7 @@ void HiddenText::GetProperties(Property::Map& map)
   map[Toolkit::HiddenInput::Property::SHOW_LAST_CHARACTER_DURATION] = mDisplayDuration;
 }
 
-void HiddenText::Substitute(const Vector<Character>& source, Vector<Character>& destination)
+void HiddenText::Substitute(const Vector<Character>& source, Vector<Character>& destination, Length cursorPos)
 {
   const Length characterCount = source.Count();
 
@@ -125,14 +126,15 @@ void HiddenText::Substitute(const Vector<Character>& source, Vector<Character>&
     }
     case Toolkit::HiddenInput::Mode::SHOW_LAST_CHARACTER:
     {
+      hideStart = begin;
+      hideEnd   = end;
       if(mPreviousTextCount < characterCount)
       {
-        hideStart = begin;
-        hideEnd   = end - 1;
         if(mDisplayDuration > 0)
         {
           mTimer.SetInterval(mDisplayDuration);
           mTimer.Start();
+          mIsLastCharacterShow = true;
         }
         else
         {
@@ -141,34 +143,60 @@ void HiddenText::Substitute(const Vector<Character>& source, Vector<Character>&
       }
       else
       {
-        hideStart = begin;
-        hideEnd   = end;
+        mIsLastCharacterShow = false;
       }
       break;
     }
   }
-  for(; begin < end; ++begin)
+
+
+  if(mHideMode == Toolkit::HiddenInput::Mode::SHOW_LAST_CHARACTER)
   {
-    if(begin >= hideStart && begin < hideEnd)
+    Length currentPos = 0u;
+    for(; begin < end; ++begin)
     {
-      *begin = static_cast<uint32_t>(mSubstituteText);
+      if(begin >= hideStart && begin < hideEnd && cursorPos > 0u && currentPos != cursorPos - 1u)
+      {
+        *begin = static_cast<uint32_t>(mSubstituteText);
+      }
+      else
+      {
+        *begin = mIsLastCharacterShow ? *sourcePos : static_cast<uint32_t>(mSubstituteText);
+      }
       sourcePos++;
+      currentPos++;
     }
-    else
+  }
+  else
+  {
+    for(; begin < end; ++begin)
     {
-      *begin = *sourcePos++;
+      if(begin >= hideStart && begin < hideEnd)
+      {
+        *begin = static_cast<uint32_t>(mSubstituteText);
+        sourcePos++;
+      }
+      else
+      {
+        *begin = *sourcePos++;
+      }
     }
   }
   mPreviousTextCount = characterCount;
 }
 
+void HiddenText::InitPreviousTextCount()
+{
+  mPreviousTextCount = 0u;
+}
+
 bool HiddenText::OnTick()
 {
   if(mObserver != NULL)
   {
     mObserver->DisplayTimeExpired();
   }
-
+  mIsLastCharacterShow = false;
   return false;
 }
 
index b13c263..6dcf0c9 100644 (file)
@@ -74,7 +74,12 @@ public: // Intended for internal use
    * @param[in] source The original text
    * @param[out] destination The applied text
    */
-  void Substitute(const Vector<Character>& source, Vector<Character>& destination);
+  void Substitute(const Vector<Character>& source, Vector<Character>& destination, Length currentCursorIndex);
+
+  /**
+   * @brief Initialize the value of PreviousTextCount
+   */
+  void InitPreviousTextCount();
 
   /**
    * @brief Invoked when the timer is expired
@@ -89,6 +94,7 @@ private:
   int       mDisplayDuration;
   int       mSubstituteCount;
   Length    mPreviousTextCount;
+  bool      mIsLastCharacterShow;
 };
 
 } // namespace Text