From 924b0441302cfe73dbb2b2a991017be4826e2b2b Mon Sep 17 00:00:00 2001 From: Bowon Ryu Date: Mon, 5 Jul 2021 20:12:31 +0900 Subject: [PATCH] Fix SetPrimaryCursorPosition() behaviour when no focus 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 --- .../src/dali-toolkit/utc-Dali-TextEditor.cpp | 1 + .../src/dali-toolkit/utc-Dali-TextField.cpp | 1 + .../controls/text-controls/text-editor-impl.cpp | 2 +- .../controls/text-controls/text-field-impl.cpp | 2 +- .../internal/text/text-controller-impl.cpp | 14 +++++++++----- dali-toolkit/internal/text/text-controller-impl.h | 2 +- dali-toolkit/internal/text/text-controller.cpp | 4 ++-- dali-toolkit/internal/text/text-controller.h | 3 ++- 8 files changed, 18 insertions(+), 11 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp index b518743420..66d16caa23 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp @@ -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 ) ); diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp index f6e24e67eb..eec0857edb 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp @@ -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 ) ); diff --git a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp index f74a28d5fc..75b90f3586 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp @@ -766,7 +766,7 @@ void TextEditor::SetProperty(BaseObject* object, Property::Index index, const Pr { uint32_t position = static_cast(value.Get()); 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(); } diff --git a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp index 2cce4d2b2a..07afb0e595 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp @@ -752,7 +752,7 @@ void TextField::SetProperty(BaseObject* object, Property::Index index, const Pro { uint32_t position = static_cast(value.Get()); 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(); } diff --git a/dali-toolkit/internal/text/text-controller-impl.cpp b/dali-toolkit/internal/text/text-controller-impl.cpp index 279f23bf1f..c31fc934b1 100644 --- a/dali-toolkit/internal/text/text-controller-impl.cpp +++ b/dali-toolkit/internal/text/text-controller-impl.cpp @@ -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(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; } diff --git a/dali-toolkit/internal/text/text-controller-impl.h b/dali-toolkit/internal/text/text-controller-impl.h index f6681bddb7..d3ed77acb1 100644 --- a/dali-toolkit/internal/text/text-controller-impl.h +++ b/dali-toolkit/internal/text/text-controller-impl.h @@ -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() diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index 7e0410df87..61071b169e 100644 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -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; diff --git a/dali-toolkit/internal/text/text-controller.h b/dali-toolkit/internal/text/text-controller.h index 63a77a4459..4824813458 100644 --- a/dali-toolkit/internal/text/text-controller.h +++ b/dali-toolkit/internal/text/text-controller.h @@ -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. -- 2.34.1