From: Bowon Ryu Date: Wed, 24 Mar 2021 10:17:05 +0000 (+0900) Subject: [Tizen] Add parameter (bool immediate) to TextChanged signal in interface X-Git-Tag: submit/tizen/20210330.021548^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0250415b791ea823d1f63d32644b194396ca500e;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git [Tizen] 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 --- diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp index 06d3307..4a0c12d 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp @@ -964,36 +964,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 0795816..e81752e 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp @@ -1034,36 +1034,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 3d48333..9f70e6a 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp @@ -1450,9 +1450,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(); } } @@ -1667,9 +1665,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 131cc73..f15f137 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp @@ -1403,9 +1403,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(); } } @@ -1714,9 +1712,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 ad5c6b8..75b6f99 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.h @@ -198,7 +198,7 @@ private: // From Control /** * @copydoc Text::EditableControlInterface::TextChanged() */ - void TextChanged() override; + void TextChanged(bool immediate) override; /** * @copydoc Text::EditableControlInterface::MaxLengthReached() @@ -300,6 +300,11 @@ private: // Implementation void OnIdleSignal(); /** + * @brief Emits TextChanged signal. + */ + void EmitTextChangedSignal(); + + /** * Construct a new TextField. */ TextField(); @@ -359,7 +364,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