/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali-test-suite-utils.h>
#include <dali/devel-api/actors/actor-devel.h>
#include <dali/integration-api/events/touch-event-integ.h>
+#include <dali/integration-api/events/touch-integ.h>
#include <dali/integration-api/render-task-list-integ.h>
+#include <dali/internal/event/events/touch-event-impl.h>
+#include <dali/internal/event/render-tasks/render-task-impl.h>
#include <dali/public-api/dali-core.h>
#include <stdlib.h>
#include <test-touch-event-utils.h>
///////////////////////////////////////////////////////////////////////////////
namespace
{
+bool gHitTestTouchCallBackCalled = false;
+static bool TestHitTestTouchCallback(Actor, const TouchEvent&)
+{
+ gHitTestTouchCallBackCalled = true;
+ return false;
+ END_TEST;
+}
// Stores data that is populated in the callback and will be read by the TET cases
struct SignalData
{
return touchEvent;
}
+Integration::TouchEvent GenerateSingleMouse(PointState::Type state, const Vector2& screenPosition, int source, uint32_t time)
+{
+ Integration::TouchEvent touchEvent;
+ Integration::Point point;
+ point.SetState(state);
+ point.SetDeviceId(4);
+ point.SetScreenPosition(screenPosition);
+ point.SetDeviceClass(Device::Class::MOUSE);
+ point.SetDeviceSubclass(Device::Subclass::NONE);
+ point.SetMouseButton(static_cast<MouseButton::Type>(source));
+ touchEvent.points.push_back(point);
+ touchEvent.time = time;
+ return touchEvent;
+}
+
} // namespace
///////////////////////////////////////////////////////////////////////////////
TestApplication application;
TapGestureDetector detector = TapGestureDetector::New();
- ;
TapGestureDetector assign;
assign = detector;
END_TEST;
}
+int UtcDaliRTapGestureDetectorMoveConstructorP(void)
+{
+ TestApplication application;
+
+ TapGestureDetector detector = TapGestureDetector::New();
+ DALI_TEST_CHECK(detector);
+
+ TapGestureDetector moved = std::move(detector);
+ DALI_TEST_CHECK(moved);
+ DALI_TEST_CHECK(!detector);
+ END_TEST;
+}
+
+int UtcDaliTapGestureDetectorMoveAssignmentOperatorP(void)
+{
+ TestApplication application;
+
+ TapGestureDetector detector;
+ detector = TapGestureDetector::New();
+ DALI_TEST_CHECK(detector);
+
+ TapGestureDetector moved;
+ moved = std::move(detector);
+ DALI_TEST_CHECK(moved);
+ DALI_TEST_CHECK(!detector);
+ END_TEST;
+}
+
int UtcDaliTapGestureDetectorNew(void)
{
TestApplication application;
application.SendNotification();
application.Render();
- // Set the minimum to be greater than the maximum, should Assert
+ SignalData data;
+ GestureReceivedFunctor functor(data);
- try
- {
- TapGestureDetector detector = TapGestureDetector::New();
- detector.SetMinimumTapsRequired(7u);
- detector.SetMaximumTapsRequired(3u);
- detector.Attach(actor);
- DALI_TEST_CHECK(false); // Should not get here
- }
- catch(DaliException& e)
- {
- DALI_TEST_CHECK(true);
- }
+ // Set the minimum to be greater than the maximum, should not receive the tap event.
+ TapGestureDetector detector = TapGestureDetector::New();
+ detector.SetMinimumTapsRequired(2u);
+ detector.SetMaximumTapsRequired(1u);
+ detector.Attach(actor);
+ detector.DetectedSignal().Connect(&application, functor);
+
+ TestGenerateTap(application, 50.0f, 50.0f, 100);
+ // detector don't get the tap event.
+ DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
+ data.Reset();
+
+ // detector don't get the tap event.
+ TestGenerateTap(application, 50.0f, 50.0f, 120);
+ DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
END_TEST;
}
END_TEST;
}
-int UtcDaliTapGestureInterruptedWhenTouchConsumed(void)
-{
- TestApplication application;
-
- 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);
-
- bool consume = false;
- TouchEventFunctorConsumeSetter touchFunctor(consume);
- actor.TouchedSignal().Connect(&application, touchFunctor);
-
- // Render and notify
- application.SendNotification();
- application.Render();
-
- SignalData data;
- GestureReceivedFunctor functor(data);
-
- TapGestureDetector detector = TapGestureDetector::New();
- detector.Attach(actor);
- detector.DetectedSignal().Connect(&application, functor);
-
- // Start gesture within the actor's area, we should receive the gesture as the touch is NOT being consumed
- TestGenerateTap(application, 50.0f, 50.0f);
- DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
- data.Reset();
-
- // Another gesture in the same location, this time we will not receive it as touch is being consumed
- consume = true;
- TestGenerateTap(application, 50.0f, 50.0f);
- DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
- data.Reset();
-
- END_TEST;
-}
-
int UtcDaliTapGestureDisableDetectionDuringTapN(void)
{
// Crash sometimes occurred when gesture-recognizer was deleted internally during a signal when the attached actor was detached
END_TEST;
}
-int UtcDaliTapGestureGetSourceType(void)
+int UtcDaliTapGestureGetSourceTypeWithMouse(void)
{
TestApplication application;
detector.DetectedSignal().Connect(&application, functor);
// Emit a down signal with MouseButton
- application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 0, 100));
- application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 0, 120));
+ application.ProcessEvent(GenerateSingleMouse(PointState::DOWN, Vector2(20.0f, 20.0f), 1, 100));
+ application.ProcessEvent(GenerateSingleMouse(PointState::UP, Vector2(20.0f, 20.0f), 1, 120));
application.SendNotification();
DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
- DALI_TEST_EQUALS(data.receivedGesture.GetSourceType(), GestureSourceType::INVALID, TEST_LOCATION);
+ DALI_TEST_EQUALS(data.receivedGesture.GetSourceType(), GestureSourceType::MOUSE, TEST_LOCATION);
+ DALI_TEST_EQUALS(data.receivedGesture.GetSourceData(), GestureSourceData::MOUSE_PRIMARY, TEST_LOCATION);
data.Reset();
// Emit a down signal with MouseButton
- application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 1, 700));
- application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 1, 720));
+ application.ProcessEvent(GenerateSingleMouse(PointState::DOWN, Vector2(20.0f, 20.0f), 3, 1300));
+ application.ProcessEvent(GenerateSingleMouse(PointState::UP, Vector2(20.0f, 20.0f), 3, 1320));
application.SendNotification();
DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
- DALI_TEST_EQUALS(data.receivedGesture.GetSourceType(), GestureSourceType::PRIMARY, TEST_LOCATION);
+ DALI_TEST_EQUALS(data.receivedGesture.GetSourceType(), GestureSourceType::MOUSE, TEST_LOCATION);
+ DALI_TEST_EQUALS(data.receivedGesture.GetSourceData(), GestureSourceData::MOUSE_SECONDARY, TEST_LOCATION);
data.Reset();
// Emit a down signal with MouseButton
- application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 3, 1300));
- application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 3, 1320));
+ application.ProcessEvent(GenerateSingleMouse(PointState::DOWN, Vector2(20.0f, 20.0f), 2, 1900));
+ application.ProcessEvent(GenerateSingleMouse(PointState::UP, Vector2(20.0f, 20.0f), 2, 1920));
+ application.SendNotification();
+
+ DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
+ DALI_TEST_EQUALS(data.receivedGesture.GetSourceType(), GestureSourceType::MOUSE, TEST_LOCATION);
+ DALI_TEST_EQUALS(data.receivedGesture.GetSourceData(), GestureSourceData::MOUSE_TERTIARY, TEST_LOCATION);
+
+ END_TEST;
+}
+
+int UtcDaliTapGestureGetSourceTypeWithTouch(void)
+{
+ TestApplication application;
+
+ 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);
+
+ // Render and notify
+ application.SendNotification();
+ application.Render();
+
+ SignalData data;
+ GestureReceivedFunctor functor(data);
+
+ TapGestureDetector detector = TapGestureDetector::New();
+ detector.Attach(actor);
+ detector.DetectedSignal().Connect(&application, functor);
+
+ // Emit a down signal with touch
+ application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 1, 100));
+ application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 1, 120));
application.SendNotification();
DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
- DALI_TEST_EQUALS(data.receivedGesture.GetSourceType(), GestureSourceType::SECONDARY, TEST_LOCATION);
+ DALI_TEST_EQUALS(data.receivedGesture.GetSourceType(), GestureSourceType::TOUCH, TEST_LOCATION);
data.Reset();
- // Emit a down signal with MouseButton
- application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 2, 1900));
- application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 2, 1920));
+ END_TEST;
+}
+
+int UtcDaliTapGestureReceiveAllTapEvents(void)
+{
+ TestApplication application;
+
+ 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);
+
+ // Render and notify
+ application.SendNotification();
+ application.Render();
+
+ SignalData data;
+ GestureReceivedFunctor functor(data);
+
+ TapGestureDetector detector = TapGestureDetector::New();
+ detector.SetMaximumTapsRequired(2u);
+ detector.Attach(actor);
+ detector.DetectedSignal().Connect(&application, functor);
+
+ // Emit signals, Because MaximumTapsRequired is 2, a timer that checks whether it is a single tap or a double tap operates internally.
+ application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(50.0f, 50.0f), 0, 100));
+ application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(50.0f, 50.0f), 0, 120));
+ application.SendNotification();
+
+ // So detector don't get the tap event yet.
+ DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
+ data.Reset();
+
+ // Emit signals, Send the second tab.
+ application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 0, 130));
+ application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 0, 150));
+ application.SendNotification();
+ application.GetPlatform().TriggerTimer();
+
+ // It find out to be a double tap. Detector receives events.
+ DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
+ data.Reset();
+
+ // Detector want to receive all tap events.
+ detector.ReceiveAllTapEvents(true);
+
+ // Emit signals, should receive
+ application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(50.0f, 50.0f), 0, 500));
+ application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(50.0f, 50.0f), 0, 520));
+ application.SendNotification();
+
+ DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
+ data.Reset();
+
+ // Emit signals, should receive
+ application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 0, 530));
+ application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 0, 550));
+ application.SendNotification();
+
+ DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
+ data.Reset();
+
+ END_TEST;
+}
+
+int UtcDaliTapGestureDoesWantedHitTest(void)
+{
+ TestApplication application;
+
+ Actor blue = Actor::New();
+ blue.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
+ blue.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+
+ Actor green = Actor::New();
+ green.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
+ green.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+
+ application.GetScene().Add(blue);
+ application.GetScene().Add(green);
+
+ // Render and notify
+ application.SendNotification();
+ application.Render();
+
+ SignalData blueData;
+ GestureReceivedFunctor blueFunctor(blueData);
+
+ TapGestureDetector blueDetector = TapGestureDetector::New();
+ blueDetector.Attach(blue);
+ blueDetector.DetectedSignal().Connect(&application, blueFunctor);
+
+ SignalData greenData;
+ GestureReceivedFunctor greenFunctor(greenData);
+
+ TapGestureDetector greenDetector = TapGestureDetector::New();
+ greenDetector.Attach(green);
+ greenDetector.DetectedSignal().Connect(&application, greenFunctor);
+
+ // connect to its hit-test signal
+ gHitTestTouchCallBackCalled = false;
+ Dali::DevelActor::HitTestResultSignal(green).Connect(TestHitTestTouchCallback);
+
+ // Emit a down signal
+ application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(20.0f, 20.0f), 0, 100));
+ application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(20.0f, 20.0f), 0, 120));
+ application.SendNotification();
+
+ // check hit-test events
+ // The green actor received an event that the green actor was hit.
+ DALI_TEST_EQUALS(true, gHitTestTouchCallBackCalled, TEST_LOCATION);
+
+ // The green actor passed the hit-test. So blue was the final hit.
+ DALI_TEST_EQUALS(false, greenData.functorCalled, TEST_LOCATION);
+ DALI_TEST_EQUALS(true, blueData.functorCalled, TEST_LOCATION);
+
+ blueData.Reset();
+ greenData.Reset();
+
+ END_TEST;
+}
+
+int UtcDaliTapGestureDetectorCheck(void)
+{
+ TestApplication application;
+
+ 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);
+
+ Actor actor2 = Actor::New();
+ actor2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
+ actor2.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 100.0f));
+ actor2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+ application.GetScene().Add(actor2);
+
+ // Render and notify
+ application.SendNotification();
+ application.Render();
+
+ SignalData data;
+ GestureReceivedFunctor functor(data);
+ TapGestureDetector detector1 = TapGestureDetector::New();
+ detector1.SetMaximumTapsRequired(1u);
+ detector1.Attach(actor);
+ detector1.DetectedSignal().Connect(&application, functor);
+
+ TapGestureDetector detector2 = TapGestureDetector::New();
+ detector2.SetMaximumTapsRequired(2u);
+ detector2.Attach(actor2);
+
+ // Emit signals, Send the single tab.
+ application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(50.0f, 50.0f), 0, 100));
+ application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(50.0f, 50.0f), 0, 120));
application.SendNotification();
+ // The detector1 get the tap event.
DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
- DALI_TEST_EQUALS(data.receivedGesture.GetSourceType(), GestureSourceType::TERTIARY, TEST_LOCATION);
+ data.Reset();
+
+ // Emit signals, Send the second tab.
+ application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(50.0f, 50.0f), 0, 130));
+ application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(50.0f, 50.0f), 0, 150));
+ application.SendNotification();
+
+ // The detector1 must get the tap event. SetMaximumTapsRequired(2u) of detector2 should not affect detector1.
+ DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
+ data.Reset();
+
+ END_TEST;
+}
+
+int UtcDaliTapGestureFeedTouch(void)
+{
+ TestApplication application;
+ Integration::Scene scene = application.GetScene();
+ RenderTaskList taskList = scene.GetRenderTaskList();
+ Dali::RenderTask task = taskList.GetTask(0);
+
+ Actor parentActor = Actor::New();
+ parentActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
+ parentActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+
+ Actor childActor = Actor::New();
+ childActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
+ childActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+
+ parentActor.Add(childActor);
+ application.GetScene().Add(parentActor);
+
+ // Render and notify
+ application.SendNotification();
+ application.Render();
+
+ SignalData pData;
+ GestureReceivedFunctor pFunctor(pData);
+
+ TapGestureDetector parentDetector = TapGestureDetector::New();
+ parentDetector.DetectedSignal().Connect(&application, pFunctor);
+
+ Integration::TouchEvent tp = GenerateSingleTouch(PointState::DOWN, Vector2(50.0f, 50.0f), 1, 100);
+ Internal::TouchEventPtr touchEventImpl(new Internal::TouchEvent(100));
+ touchEventImpl->AddPoint(tp.GetPoint(0));
+ touchEventImpl->SetRenderTask(task);
+ Dali::TouchEvent touchEventHandle(touchEventImpl.Get());
+ parentDetector.FeedTouch(parentActor, touchEventHandle);
+
+ tp = GenerateSingleTouch(PointState::UP, Vector2(50.0f, 50.0f), 1, 150);
+ touchEventImpl = new Internal::TouchEvent(150);
+ touchEventImpl->AddPoint(tp.GetPoint(0));
+ touchEventImpl->SetRenderTask(task);
+ touchEventHandle = Dali::TouchEvent(touchEventImpl.Get());
+ parentDetector.FeedTouch(parentActor, touchEventHandle);
+
+ DALI_TEST_EQUALS(true, pData.functorCalled, TEST_LOCATION);
+ pData.Reset();
END_TEST;
-}
\ No newline at end of file
+}