From: joogab yun Date: Tue, 28 Jun 2022 01:06:30 +0000 (+0000) Subject: Merge "Allows TextField and TextEditor to propagate PanGestures." into devel/master X-Git-Tag: dali_2.1.29~4 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=f878d2e5cfbe3f3950b26d8d5967a30cee48a198;hp=da52430cd445300df2c37ee43388fef6bc338a7d Merge "Allows TextField and TextEditor to propagate PanGestures." into devel/master --- diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp index 6e72f04..b95f6c7 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -390,6 +391,57 @@ public: bool& mFinishedCalled; }; + +// Stores data that is populated in the callback and will be read by the test cases +struct SignalData +{ + SignalData() + : functorCalled(false), + voidFunctorCalled(false), + receivedGesture() + { + } + + void Reset() + { + functorCalled = false; + voidFunctorCalled = false; + + receivedGesture.Reset(); + + pannedActor.Reset(); + } + + bool functorCalled; + bool voidFunctorCalled; + PanGesture receivedGesture; + Actor pannedActor; +}; + +// Functor that sets the data when called +struct GestureReceivedFunctor +{ + GestureReceivedFunctor(SignalData& data) + : signalData(data) + { + } + + void operator()(Actor actor, const PanGesture& pan) + { + signalData.functorCalled = true; + signalData.receivedGesture = pan; + signalData.pannedActor = actor; + } + + void operator()() + { + signalData.voidFunctorCalled = true; + } + + SignalData& signalData; +}; + + } // namespace int UtcDaliToolkitTextEditorConstructorP(void) @@ -6233,4 +6285,76 @@ int utcDaliTextEditorClusteredEmojiDeletionDeleteKey(void) application.Render(); END_TEST; -} \ No newline at end of file +} + +int utcDaliTextEditorPanGesturePropagation(void) +{ + ToolkitTestApplication application; + tet_infoline(" utcDaliTextEditorPanGesturePropagation"); + + Actor actor = Actor::New(); + actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f)); + actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + application.GetScene().Add(actor); + + TextEditor editor = TextEditor::New(); + DALI_TEST_CHECK(editor); + + editor.SetProperty(TextEditor::Property::TEXT, "This is a long text for the size of the text-editor."); + editor.SetProperty(TextEditor::Property::POINT_SIZE, 10.f); + + editor.SetProperty(Actor::Property::SIZE, Vector2(30.f, 500.f)); + editor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + editor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + + actor.Add(editor); + + // Render and notify + application.SendNotification(); + application.Render(); + + SignalData data; + GestureReceivedFunctor functor(data); + + PanGestureDetector detector = PanGestureDetector::New(); + detector.Attach(actor); + detector.DetectedSignal().Connect(&application, functor); + + // Tap first to get the focus. + TestGenerateTap(application, 3.0f, 25.0f, 100); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Pan the text editor + uint32_t time = 100; + TestStartPan(application, Vector2(10.0f, 50.0f), Vector2(10.0f, 50.0f), time); + TestMovePan(application, Vector2(10.0f, 30.0f), time); + TestEndPan(application, Vector2(10.0f, 50.0f), time); + application.SendNotification(); + application.Render(); + + // The text scrolls because there is text that is scrolling. + DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); + data.Reset(); + + // Set the size large enough to prevent scrolling. + editor.SetProperty(Actor::Property::SIZE, Vector2(500.f, 500.f)); + + // Render and notify + application.SendNotification(); + application.Render(); + + time = 200; + TestStartPan(application, Vector2(10.0f, 50.0f), Vector2(10.0f, 50.0f), time); + TestMovePan(application, Vector2(10.0f, 30.0f), time); + TestEndPan(application, Vector2(10.0f, 50.0f), time); + + // Because scrolling is not possible, the pan gesture is propagated. + DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); + data.Reset(); + + + 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 5ec1035..f24108c 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp @@ -19,10 +19,6 @@ #include #include -#include -#include -#include -#include #include #include @@ -30,8 +26,13 @@ #include #include #include +#include #include +#include #include +#include +#include +#include #include "test-text-geometry-utils.h" #include "toolkit-clipboard.h" @@ -405,6 +406,56 @@ bool DaliTestCheckMaps(const Property::Map& fontStyleMapGet, const Property::Map return true; } + +// Stores data that is populated in the callback and will be read by the test cases +struct SignalData +{ + SignalData() + : functorCalled(false), + voidFunctorCalled(false), + receivedGesture() + { + } + + void Reset() + { + functorCalled = false; + voidFunctorCalled = false; + + receivedGesture.Reset(); + + pannedActor.Reset(); + } + + bool functorCalled; + bool voidFunctorCalled; + PanGesture receivedGesture; + Actor pannedActor; +}; + +// Functor that sets the data when called +struct GestureReceivedFunctor +{ + GestureReceivedFunctor(SignalData& data) + : signalData(data) + { + } + + void operator()(Actor actor, const PanGesture& pan) + { + signalData.functorCalled = true; + signalData.receivedGesture = pan; + signalData.pannedActor = actor; + } + + void operator()() + { + signalData.voidFunctorCalled = true; + } + + SignalData& signalData; +}; + } // namespace int UtcDaliToolkitTextFieldConstructorP(void) @@ -5566,4 +5617,76 @@ int utcDaliTextFieldClusteredEmojiDeletionDeleteKey(void) application.Render(); END_TEST; -} \ No newline at end of file +} + +int utcDaliTextFieldPanGesturePropagation(void) +{ + ToolkitTestApplication application; + tet_infoline(" utcDaliTextFieldPanGesturePropagation"); + + Actor actor = Actor::New(); + actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f)); + actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + application.GetScene().Add(actor); + + TextField field = TextField::New(); + DALI_TEST_CHECK(field); + + field.SetProperty(TextField::Property::TEXT, "This is a long text for the size of the text-field."); + field.SetProperty(TextField::Property::POINT_SIZE, 10.f); + + field.SetProperty(Actor::Property::SIZE, Vector2(50.f, 100.f)); + field.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + field.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + + actor.Add(field); + + // Render and notify + application.SendNotification(); + application.Render(); + + SignalData data; + GestureReceivedFunctor functor(data); + + PanGestureDetector detector = PanGestureDetector::New(); + detector.Attach(actor); + detector.DetectedSignal().Connect(&application, functor); + + // Tap first to get the focus. + TestGenerateTap(application, 3.0f, 25.0f, 100); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Pan the text field + uint32_t time = 100; + TestStartPan(application, Vector2(40.0f, 50.0f), Vector2(40.0f, 50.0f), time); + TestMovePan(application, Vector2(10.0f, 50.0f), time); + TestEndPan(application, Vector2(40.0f, 50.0f), time); + application.SendNotification(); + application.Render(); + + // The text scrolls because there is text that is scrolling. + DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION); + data.Reset(); + + // Set the size large enough to prevent scrolling. + field.SetProperty(Actor::Property::SIZE, Vector2(700.f, 100.f)); + + // Render and notify + application.SendNotification(); + application.Render(); + + time = 200; + TestStartPan(application, Vector2(40.0f, 50.0f), Vector2(40.0f, 50.0f), time); + TestMovePan(application, Vector2(10.0f, 50.0f), time); + TestEndPan(application, Vector2(40.0f, 50.0f), time); + + // Because scrolling is not possible, the pan gesture is propagated. + DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION); + data.Reset(); + + + 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 432ea08..7d0f2fe 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp @@ -904,6 +904,10 @@ void TextEditor::OnTap(const TapGesture& gesture) void TextEditor::OnPan(const PanGesture& gesture) { mController->PanEvent(gesture.GetState(), gesture.GetDisplacement()); + if(gesture.GetState() == GestureState::STARTED && !mController->IsScrollable(gesture.GetDisplacement())) + { + Dali::DevelActor::SetNeedGesturePropagation(Self(), true); + } } void TextEditor::OnLongPress(const LongPressGesture& gesture) 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 21c8d3d..15ea363 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp @@ -837,6 +837,10 @@ void TextField::OnTap(const TapGesture& gesture) void TextField::OnPan(const PanGesture& gesture) { mController->PanEvent(gesture.GetState(), gesture.GetDisplacement()); + if(gesture.GetState() == GestureState::STARTED && !mController->IsScrollable(gesture.GetDisplacement())) + { + Dali::DevelActor::SetNeedGesturePropagation(Self(), true); + } } void TextField::OnLongPress(const LongPressGesture& gesture) diff --git a/dali-toolkit/internal/text/text-controller-impl.cpp b/dali-toolkit/internal/text/text-controller-impl.cpp index 47877c4..7fac661 100644 --- a/dali-toolkit/internal/text/text-controller-impl.cpp +++ b/dali-toolkit/internal/text/text-controller-impl.cpp @@ -1581,6 +1581,43 @@ void Controller::Impl::ScrollBy(Vector2 scroll) } } +bool Controller::Impl::IsScrollable(const Vector2& displacement) +{ + bool isScrollable = false; + if(mEventData) + { + const bool isHorizontalScrollEnabled = mEventData->mDecorator->IsHorizontalScrollEnabled(); + const bool isVerticalScrollEnabled = mEventData->mDecorator->IsVerticalScrollEnabled(); + if(isHorizontalScrollEnabled ||isVerticalScrollEnabled) + { + const Vector2& targetSize = mModel->mVisualModel->mControlSize; + const Vector2& layoutSize = mModel->mVisualModel->GetLayoutSize(); + const Vector2& scrollPosition = mModel->mScrollPosition; + + if(isHorizontalScrollEnabled) + { + const float displacementX = displacement.x; + const float positionX = scrollPosition.x + displacementX; + if(layoutSize.width > targetSize.width && -positionX > 0.f && -positionX < layoutSize.width - targetSize.width) + { + isScrollable = true; + } + } + + if(isVerticalScrollEnabled) + { + const float displacementY = displacement.y; + const float positionY = scrollPosition.y + displacementY; + if(layoutSize.height > targetSize.height && -positionY > 0 && -positionY < layoutSize.height - targetSize.height) + { + isScrollable = true; + } + } + } + } + return isScrollable; +} + float Controller::Impl::GetHorizontalScrollPosition() { // Scroll values are negative internally so we convert them to positive numbers diff --git a/dali-toolkit/internal/text/text-controller-impl.h b/dali-toolkit/internal/text/text-controller-impl.h index 7eaf5ee..23b020c 100644 --- a/dali-toolkit/internal/text/text-controller-impl.h +++ b/dali-toolkit/internal/text/text-controller-impl.h @@ -832,6 +832,11 @@ struct Controller::Impl void ScrollBy(Vector2 scroll); /** + * @copydoc Controller::IsScrollable() + */ + bool IsScrollable(const Vector2& displacement); + + /** * @copydoc Controller::GetHorizontalScrollPosition() */ float GetHorizontalScrollPosition(); diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index 7cc8831..1a07af5 100644 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -1607,6 +1607,11 @@ void Controller::ScrollBy(Vector2 scroll) mImpl->ScrollBy(scroll); } +bool Controller::IsScrollable(const Vector2& displacement) +{ + return mImpl->IsScrollable(displacement); +} + float Controller::GetHorizontalScrollPosition() { return mImpl->GetHorizontalScrollPosition(); diff --git a/dali-toolkit/internal/text/text-controller.h b/dali-toolkit/internal/text/text-controller.h index 0def96f..09305d2 100644 --- a/dali-toolkit/internal/text/text-controller.h +++ b/dali-toolkit/internal/text/text-controller.h @@ -1922,6 +1922,12 @@ public: // Text-input Event Queuing. virtual void ScrollBy(Vector2 scroll); /** + * @brief Whether the text is scrollable. + * @return Returns true if the text is scrollable. + */ + bool IsScrollable(const Vector2& displacement); + + /** * @copydoc Dali::Toolkit::Internal::TextEditor::GetHorizontalScrollPosition() */ float GetHorizontalScrollPosition();