From 3d28744e61ba8b68daa957827a55224f11bbf2f0 Mon Sep 17 00:00:00 2001 From: Bowon Ryu Date: Wed, 24 Mar 2021 19:17:05 +0900 Subject: [PATCH] Add parameter (bool immediate) to TextChanged signal in interface virtual void TextChanged(bool immediate) = 0; using immediate, can decide whether we only emit the signal when OnRelayout() is called next time, otherwise emits it immediately. * there is a issue that the timing of callback calls has been delayed due to a recent patch that limits unnecessary callbacks. (33ccee79d16a90d5f7ab427de1503ccc5bee4324) Because of this, there is a problem that the TC like example below fails. This patch can prevents the following issues. /* example */ bool textChanged; ... static void OnTextChanged(TextField control) { textChanged = true; } ... field.TextChangedSignal().Connect(&OnTextChanged); textChanged = false; field.SetProperty(TextField::Property::TEXT, "hello"); DALI_TEST_CHECK(textChanged); // At this point, textChanged is false, so TC Fail occurs. /* example */ Change-Id: If0a331c56f35eae931b34d128b4fe4282fc686b6 Signed-off-by: Bowon Ryu --- .../src/dali-toolkit/utc-Dali-TextEditor.cpp | 11 +---------- .../src/dali-toolkit/utc-Dali-TextField.cpp | 11 +---------- .../controls/text-controls/text-editor-impl.cpp | 22 +++++++++++++++++----- .../controls/text-controls/text-editor-impl.h | 9 +++++++-- .../controls/text-controls/text-field-impl.cpp | 22 +++++++++++++++++----- .../controls/text-controls/text-field-impl.h | 9 +++++++-- .../text/text-controller-event-handler.cpp | 6 +++--- .../internal/text/text-controller-text-updater.cpp | 4 ++-- .../text/text-editable-control-interface.h | 4 +++- 9 files changed, 58 insertions(+), 40 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp index b76a850..af5a453 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp @@ -970,36 +970,27 @@ int utcDaliTextEditorTextChangedP(void) gTextChangedCallBackCalled = false; editor.SetProperty( TextEditor::Property::TEXT, "ABC" ); - application.SendNotification(); - application.Render(); DALI_TEST_CHECK( gTextChangedCallBackCalled ); DALI_TEST_CHECK( textChangedSignal ); + application.SendNotification(); editor.SetKeyInputFocus(); gTextChangedCallBackCalled = false; application.ProcessEvent( GenerateKey( "D", "", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "D", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); - application.SendNotification(); - application.Render(); DALI_TEST_CHECK( gTextChangedCallBackCalled ); // Remove all text editor.SetProperty( TextField::Property::TEXT, "" ); - application.SendNotification(); - application.Render(); // Pressing backspace key: TextChangedCallback should not be called when there is no text in texteditor. gTextChangedCallBackCalled = false; application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); - application.SendNotification(); - application.Render(); DALI_TEST_CHECK( !gTextChangedCallBackCalled ); // Pressing delete key: TextChangedCallback should not be called when there is no text in texteditor. gTextChangedCallBackCalled = false; application.ProcessEvent( GenerateKey( "", "", "", Dali::DevelKey::DALI_KEY_DELETE, 0, 0, Integration::KeyEvent::DOWN, "Delete", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); - application.SendNotification(); - application.Render(); DALI_TEST_CHECK( !gTextChangedCallBackCalled ); END_TEST; diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp index 4808f00..05d0009 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp @@ -1040,36 +1040,27 @@ int utcDaliTextFieldTextChangedP(void) gTextChangedCallBackCalled = false; field.SetProperty( TextField::Property::TEXT, "ABC" ); - application.SendNotification(); - application.Render(); DALI_TEST_CHECK( gTextChangedCallBackCalled ); DALI_TEST_CHECK( textChangedSignal ); + application.SendNotification(); field.SetKeyInputFocus(); gTextChangedCallBackCalled = false; application.ProcessEvent( GenerateKey( "D", "", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "D", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); - application.SendNotification(); - application.Render(); DALI_TEST_CHECK( gTextChangedCallBackCalled ); // Remove all text field.SetProperty( TextField::Property::TEXT, "" ); - application.SendNotification(); - application.Render(); // Pressing backspace key: TextChangedCallback should not be called when there is no text in textfield. gTextChangedCallBackCalled = false; application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); - application.SendNotification(); - application.Render(); DALI_TEST_CHECK( !gTextChangedCallBackCalled ); // Pressing delete key: TextChangedCallback should not be called when there is no text in textfield. gTextChangedCallBackCalled = false; application.ProcessEvent( GenerateKey( "", "", "", Dali::DevelKey::DALI_KEY_DELETE, 0, 0, Integration::KeyEvent::DOWN, "Delete", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); - application.SendNotification(); - application.Render(); DALI_TEST_CHECK( !gTextChangedCallBackCalled ); END_TEST; 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 19c26c5..82f6975 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp @@ -1465,9 +1465,7 @@ void TextEditor::OnRelayout(const Vector2& size, RelayoutContainer& container) // If there is text changed, callback is called. if(mTextChanged) { - Dali::Toolkit::TextEditor handle(GetOwner()); - mTextChangedSignal.Emit(handle); - mTextChanged = false; + EmitTextChangedSignal(); } } @@ -1682,9 +1680,23 @@ void TextEditor::CaretMoved(unsigned int position) } } -void TextEditor::TextChanged() +void TextEditor::TextChanged(bool immediate) { - mTextChanged = true; + if(immediate) // Emits TextChangedSignal immediately + { + EmitTextChangedSignal(); + } + else + { + mTextChanged = true; + } +} + +void TextEditor::EmitTextChangedSignal() +{ + Dali::Toolkit::TextEditor handle(GetOwner()); + mTextChangedSignal.Emit(handle); + mTextChanged = false; } void TextEditor::MaxLengthReached() diff --git a/dali-toolkit/internal/controls/text-controls/text-editor-impl.h b/dali-toolkit/internal/controls/text-controls/text-editor-impl.h index 4c408ca..a8b9a0c 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.h @@ -205,7 +205,7 @@ private: // From Control /** * @copydoc Text::EditableControlInterface::TextChanged() */ - void TextChanged() override; + void TextChanged(bool immediate) override; /** * @copydoc Text::EditableControlInterface::MaxLengthReached() @@ -329,6 +329,11 @@ private: // Implementation void OnIdleSignal(); /** + * @brief Emits TextChanged signal. + */ + void EmitTextChangedSignal(); + + /** * @brief set RenderActor's position with new scrollPosition * * Apply updated scroll position or start scroll animation if VerticalScrollAnimation is enabled @@ -402,7 +407,7 @@ private: // Data bool mScrollAnimationEnabled : 1; bool mScrollBarEnabled : 1; bool mScrollStarted : 1; - bool mTextChanged : 1; + bool mTextChanged : 1; ///< If true, emits TextChangedSignal in next OnRelayout(). struct AccessibleImpl : public DevelControl::AccessibleImpl, public virtual Dali::Accessibility::Text, 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 d29bfad..d12a708 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp @@ -1416,9 +1416,7 @@ void TextField::OnRelayout(const Vector2& size, RelayoutContainer& container) // If there is text changed, callback is called. if(mTextChanged) { - Dali::Toolkit::TextField handle(GetOwner()); - mTextChangedSignal.Emit(handle); - mTextChanged = false; + EmitTextChangedSignal(); } } @@ -1710,9 +1708,23 @@ void TextField::CaretMoved(unsigned int position) } } -void TextField::TextChanged() +void TextField::TextChanged(bool immediate) { - mTextChanged = true; + if(immediate) // Emits TextChangedSignal immediately + { + EmitTextChangedSignal(); + } + else + { + mTextChanged = true; + } +} + +void TextField::EmitTextChangedSignal() +{ + Dali::Toolkit::TextField handle(GetOwner()); + mTextChangedSignal.Emit(handle); + mTextChanged = false; } void TextField::MaxLengthReached() diff --git a/dali-toolkit/internal/controls/text-controls/text-field-impl.h b/dali-toolkit/internal/controls/text-controls/text-field-impl.h index 07a7a37..8ddc227 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.h @@ -197,7 +197,7 @@ private: // From Control /** * @copydoc Text::EditableControlInterface::TextChanged() */ - void TextChanged() override; + void TextChanged(bool immediate) override; /** * @copydoc Text::EditableControlInterface::MaxLengthReached() @@ -299,6 +299,11 @@ private: // Implementation void OnIdleSignal(); /** + * @brief Emits TextChanged signal. + */ + void EmitTextChangedSignal(); + + /** * Construct a new TextField. */ TextField(); @@ -357,7 +362,7 @@ private: // Data int mRenderingBackend; int mExceedPolicy; bool mHasBeenStaged : 1; - bool mTextChanged : 1; + bool mTextChanged : 1; ///< If true, emits TextChangedSignal in next OnRelayout(). protected: struct AccessibleImpl : public DevelControl::AccessibleImpl, diff --git a/dali-toolkit/internal/text/text-controller-event-handler.cpp b/dali-toolkit/internal/text/text-controller-event-handler.cpp index c6c4058..ce0bf59 100644 --- a/dali-toolkit/internal/text/text-controller-event-handler.cpp +++ b/dali-toolkit/internal/text/text-controller-event-handler.cpp @@ -287,7 +287,7 @@ bool Controller::EventHandler::KeyEvent(Controller& controller, const Dali::KeyE (NULL != controller.mImpl->mEditableControlInterface)) { // Do this last since it provides callbacks into application code - controller.mImpl->mEditableControlInterface->TextChanged(); + controller.mImpl->mEditableControlInterface->TextChanged(false); } return true; @@ -742,7 +742,7 @@ InputMethodContext::CallbackData Controller::EventHandler::OnInputMethodContextE (NULL != controller.mImpl->mEditableControlInterface)) { // Do this last since it provides callbacks into application code - controller.mImpl->mEditableControlInterface->TextChanged(); + controller.mImpl->mEditableControlInterface->TextChanged(false); } return callbackData; @@ -852,7 +852,7 @@ void Controller::EventHandler::TextPopupButtonTouched(Controller& controller, Da if(NULL != controller.mImpl->mEditableControlInterface) { - controller.mImpl->mEditableControlInterface->TextChanged(); + controller.mImpl->mEditableControlInterface->TextChanged(true); } break; } diff --git a/dali-toolkit/internal/text/text-controller-text-updater.cpp b/dali-toolkit/internal/text/text-controller-text-updater.cpp index c22e207..6fb472e 100644 --- a/dali-toolkit/internal/text/text-controller-text-updater.cpp +++ b/dali-toolkit/internal/text/text-controller-text-updater.cpp @@ -153,7 +153,7 @@ void Controller::TextUpdater::SetText(Controller& controller, const std::string& // Do this last since it provides callbacks into application code. if(NULL != impl.mEditableControlInterface) { - impl.mEditableControlInterface->TextChanged(); + impl.mEditableControlInterface->TextChanged(true); } } @@ -433,7 +433,7 @@ void Controller::TextUpdater::PasteText(Controller& controller, const std::strin if(NULL != impl.mEditableControlInterface) { // Do this last since it provides callbacks into application code - impl.mEditableControlInterface->TextChanged(); + impl.mEditableControlInterface->TextChanged(true); } } diff --git a/dali-toolkit/internal/text/text-editable-control-interface.h b/dali-toolkit/internal/text/text-editable-control-interface.h index 0f55494..4bd0de0 100644 --- a/dali-toolkit/internal/text/text-editable-control-interface.h +++ b/dali-toolkit/internal/text/text-editable-control-interface.h @@ -59,8 +59,10 @@ public: /** * @brief Called to signal that text has been inserted or deleted. + * + * @param[in] immediate If true, it immediately emits the signal, if false, only emits once the signal when OnRelayout() is called next time. */ - virtual void TextChanged() = 0; + virtual void TextChanged(bool immediate) = 0; /** * @brief Called when the number of characters to be inserted exceeds the maximum limit -- 2.7.4