Merge "Fix SetPrimaryCursorPosition() behaviour when no focus" into devel/master
authorBowon Ryu <bowon.ryu@samsung.com>
Mon, 9 Aug 2021 04:38:20 +0000 (04:38 +0000)
committerGerrit Code Review <gerrit@review>
Mon, 9 Aug 2021 04:38:20 +0000 (04:38 +0000)
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 b518743..66d16ca 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 f6e24e6..eec0857 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 f74a28d..75b90f3 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 2cce4d2..07afb0e 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 279f23b..c31fc93 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 f6681bd..d3ed77a 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 7e0410d..61071b1 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 63a77a4..4824813 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.