Fix SetPrimaryCursorPosition() behaviour when no focus 37/260837/8
authorBowon Ryu <bowon.ryu@samsung.com>
Mon, 5 Jul 2021 11:12:31 +0000 (20:12 +0900)
committerBowon Ryu <bowon.ryu@samsung.com>
Thu, 5 Aug 2021 04:42:31 +0000 (13:42 +0900)
If TextField does SetPrimaryCursorPosition() before CONNECTED_TO_SCENE,
there is an issue that the caret renders regardless of focus.

Also, SetPrimaryCursorPosition() always sets focus to the Text Control regardless of the user's intent.
This creates unintended bugs in the app.

This patch only updates the value of PrimaryCursorPosition when there is no focus.
When there is focus, the behaviour is the same.

Change-Id: I2bc5851c36e2c08976e7ca4656bfe38f6afe0653
Signed-off-by: Bowon Ryu <bowon.ryu@samsung.com>
automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp
automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp
dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp
dali-toolkit/internal/controls/text-controls/text-field-impl.cpp
dali-toolkit/internal/text/text-controller-impl.cpp
dali-toolkit/internal/text/text-controller-impl.h
dali-toolkit/internal/text/text-controller.cpp
dali-toolkit/internal/text/text-controller.h

index b518743420dbd49a224bcd68acdc8e71cefb31c4..66d16caa2399a6eab41a8f925482aba80e4780b3 100644 (file)
@@ -3465,6 +3465,7 @@ int UtcDaliTextEditorPrimaryCursorPosition(void)
   textEditor.SetProperty( DevelTextEditor::Property::PRIMARY_CURSOR_POSITION, 3);
   application.SendNotification();
   application.Render();
+  textEditor.SetKeyInputFocus();
 
   application.ProcessEvent( GenerateKey( "D", "", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "D", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
 
index f6e24e67ebb8ed0ada0d2d0dc1eec1cd3043adf8..eec0857edb93d52028dfffbf667774cd50c2b967 100644 (file)
@@ -3675,6 +3675,7 @@ int UtcDaliTextFieldPrimaryCursorPosition(void)
   textField.SetProperty( DevelTextField::Property::PRIMARY_CURSOR_POSITION, 3);
   application.SendNotification();
   application.Render();
+  textField.SetKeyInputFocus();
 
   application.ProcessEvent( GenerateKey( "D", "", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "D", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
 
index f74a28d5fcdf1f3593b21e8e4e4eb885fa841a4c..75b90f3586af8bf9547263c063cb00661c9a4a24 100644 (file)
@@ -766,7 +766,7 @@ void TextEditor::SetProperty(BaseObject* object, Property::Index index, const Pr
       {
         uint32_t position = static_cast<uint32_t>(value.Get<int>());
         DALI_LOG_INFO(gLogFilter, Debug::General, "TextEditor %p PRIMARY_CURSOR_POSITION %d\n", impl.mController.Get(), position);
-        if(impl.mController->SetPrimaryCursorPosition(position))
+        if(impl.mController->SetPrimaryCursorPosition(position, impl.HasKeyInputFocus()))
         {
           impl.SetKeyInputFocus();
         }
index 2cce4d2b2a98488e105fcfdec71b8a5baaf9ffbf..07afb0e595668bde41004fcdef45378b08df43fc 100644 (file)
@@ -752,7 +752,7 @@ void TextField::SetProperty(BaseObject* object, Property::Index index, const Pro
       {
         uint32_t position = static_cast<uint32_t>(value.Get<int>());
         DALI_LOG_INFO(gLogFilter, Debug::General, "TextField %p PRIMARY_CURSOR_POSITION %d\n", impl.mController.Get(), position);
-        if(impl.mController->SetPrimaryCursorPosition(position))
+        if(impl.mController->SetPrimaryCursorPosition(position, impl.HasKeyInputFocus()))
         {
           impl.SetKeyInputFocus();
         }
index 279f23bf1fa88c8ba74caf467a79ccbc7edfef00..c31fc934b1b2136ac6aff396a0d9c9914ee4b991 100644 (file)
@@ -1245,7 +1245,7 @@ CharacterIndex Controller::Impl::GetPrimaryCursorPosition() const
   return mEventData->mPrimaryCursorPosition;
 }
 
-bool Controller::Impl::SetPrimaryCursorPosition(CharacterIndex index)
+bool Controller::Impl::SetPrimaryCursorPosition(CharacterIndex index, bool focused)
 {
   if(nullptr == mEventData)
   {
@@ -1261,10 +1261,14 @@ bool Controller::Impl::SetPrimaryCursorPosition(CharacterIndex index)
 
   uint32_t length                    = static_cast<uint32_t>(mModel->mLogicalModel->mText.Count());
   mEventData->mPrimaryCursorPosition = std::min(index, length);
-  ChangeState(EventData::EDITING);
-  mEventData->mLeftSelectionPosition = mEventData->mRightSelectionPosition = mEventData->mPrimaryCursorPosition;
-  mEventData->mUpdateCursorPosition                                        = true;
-  ScrollTextToMatchCursor();
+  // If there is no focus, only the value is updated.
+  if(focused)
+  {
+    ChangeState(EventData::EDITING);
+    mEventData->mLeftSelectionPosition = mEventData->mRightSelectionPosition = mEventData->mPrimaryCursorPosition;
+    mEventData->mUpdateCursorPosition                                        = true;
+    ScrollTextToMatchCursor();
+  }
   return true;
 }
 
index f6681bddb79cee5d58b41b322cf9a1388fae58b5..d3ed77acb1ace4f261182e84e1859b8741b30daf 100644 (file)
@@ -625,7 +625,7 @@ struct Controller::Impl
   /**
    * @copydoc Text::Controller::SetPrimaryCursorPosition()
    */
-  bool SetPrimaryCursorPosition(CharacterIndex index);
+  bool SetPrimaryCursorPosition(CharacterIndex index, bool focused);
 
   /**
    * @copydoc Text::SelectableControlInterface::SetTextSelectionRange()
index 7e0410df8746144148b2900ce851094dd256e974..61071b169e63d0e1b526e1a9dec1542cfd535fe6 100644 (file)
@@ -1845,7 +1845,7 @@ CharacterIndex Controller::GetPrimaryCursorPosition() const
   return mImpl->GetPrimaryCursorPosition();
 }
 
-bool Controller::SetPrimaryCursorPosition(CharacterIndex index)
+bool Controller::SetPrimaryCursorPosition(CharacterIndex index, bool focused)
 {
   if(mImpl->mEventData)
   {
@@ -1853,7 +1853,7 @@ bool Controller::SetPrimaryCursorPosition(CharacterIndex index)
     mImpl->mEventData->mIsLeftHandleSelected  = true;
     mImpl->mEventData->mIsRightHandleSelected = true;
     mImpl->mEventData->mCheckScrollAmount     = true;
-    if(mImpl->SetPrimaryCursorPosition(index))
+    if(mImpl->SetPrimaryCursorPosition(index, focused) && focused)
     {
       KeyboardFocusGainEvent();
       return true;
index 63a77a4459f540c42f5a898c921965ddff365c2f..482481345884a6281796e068ea37d62c48045f44 100644 (file)
@@ -1588,9 +1588,10 @@ public: // Text-input Event Queuing.
    * @brief Used to set the Primary cursor position.
    *
    * @param[in] index for the Primary cursor position.
+   * @param[in] focused true if UI control has gained focus to receive key event, false otherwise.
    * @return[in] true if cursor position changed, false otherwise.
    */
-  bool SetPrimaryCursorPosition(CharacterIndex index);
+  bool SetPrimaryCursorPosition(CharacterIndex index, bool focused);
 
   /**
    * @brief Creates a selection event.