/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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/integration-api/render-task-list-integ.h>
#include <dali/devel-api/events/long-press-gesture-detector-devel.h>
#include <dali-test-suite-utils.h>
-#include <test-touch-utils.h>
+#include <test-touch-data-utils.h>
using namespace Dali;
// Functor that removes the gestured actor from stage
struct UnstageActorFunctor : public GestureReceivedFunctor
{
- UnstageActorFunctor( SignalData& data, Gesture::State& stateToUnstage )
+ UnstageActorFunctor( SignalData& data, Gesture::State& stateToUnstage, Integration::Scene scene )
: GestureReceivedFunctor( data ),
- stateToUnstage( stateToUnstage )
+ stateToUnstage( stateToUnstage ),
+ scene( scene )
{
}
if ( longPress.state == stateToUnstage )
{
- Stage::GetCurrent().Remove( actor );
+ scene.Remove( actor );
}
}
Gesture::State& stateToUnstage;
+ Integration::Scene scene;
};
// Functor for receiving a touch event
-struct TouchEventFunctor
+struct TouchDataFunctor
{
- bool operator()(Actor actor, const TouchEvent& touch)
+ bool operator()(Actor actor, Dali::TouchData touch)
{
//For line coverage
unsigned int points = touch.GetPointCount();
if( points > 0)
{
- const TouchPoint& touchPoint = touch.GetPoint(0);
- tet_printf("Touch Point state = %d\n", touchPoint.state);
+ tet_printf("Touch Point state = %d\n", touch.GetState(0));
}
return false;
}
Actor actor = Actor::New();
actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
- Stage::GetCurrent().Add(actor);
+ application.GetScene().Add(actor);
// Render and notify
application.SendNotification();
detector.Attach(actor);
- TouchEventFunctor touchFunctor;
- actor.TouchedSignal().Connect(&application, touchFunctor);
+ TouchDataFunctor touchFunctor;
+ actor.TouchSignal().Connect(&application, touchFunctor);
Integration::TouchEvent touchEvent(1);
Integration::Point point;
application.SendNotification();
application.Render();
- // For line coverage, Initialise default constructor
- TouchEvent touchEvent2;
END_TEST;
}
Actor actor = Actor::New();
actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
- Stage::GetCurrent().Add(actor);
+ application.GetScene().Add(actor);
// Render and notify
application.SendNotification();
Actor actor = Actor::New();
actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
- Stage::GetCurrent().Add(actor);
+ application.GetScene().Add(actor);
// Render and notify
application.SendNotification();
Actor actor = Actor::New();
actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
- Stage::GetCurrent().Add(actor);
+ application.GetScene().Add(actor);
// Render and notify
application.SendNotification();
Actor actor = Actor::New();
actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
- Stage::GetCurrent().Add(actor);
+ application.GetScene().Add(actor);
// Render and notify
application.SendNotification();
DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
// Remove the actor from stage and reset the data
- Stage::GetCurrent().Remove(actor);
+ application.GetScene().Remove(actor);
// Render and notify
application.SendNotification();
Actor actor = Actor::New();
actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
actor.SetProperty( Actor::Property::ORIENTATION, Quaternion( Dali::Degree(90.0f), Vector3::ZAXIS ) );
- Stage::GetCurrent().Add(actor);
+ application.GetScene().Add(actor);
// Render and notify
application.SendNotification();
Actor parent = Actor::New();
parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
- Stage::GetCurrent().Add(parent);
+ application.GetScene().Add(parent);
// Set child to completely cover parent.
// Change rotation of child to be different from parent so that we can check if our local coordinate
child.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS) );
parent.Add(child);
- TouchEventFunctor touchFunctor;
- child.TouchedSignal().Connect(&application, touchFunctor);
-
// Render and notify
application.SendNotification();
application.Render();
Actor first = Actor::New();
first.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
first.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
- Stage::GetCurrent().Add(first);
+ application.GetScene().Add(first);
Actor second = Actor::New();
second.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
second.SetProperty( Actor::Property::POSITION_X, 100.0f);
second.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
- Stage::GetCurrent().Add(second);
+ application.GetScene().Add(second);
// Render and notify
application.SendNotification();
Actor actor = Actor::New();
actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
- Stage::GetCurrent().Add(actor);
+ application.GetScene().Add(actor);
// Render and notify
application.SendNotification();
Actor actor = Actor::New();
actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
- Stage::GetCurrent().Add(actor);
+ application.GetScene().Add(actor);
// Render and notify
application.SendNotification();
Actor actor = Actor::New();
actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
- Stage::GetCurrent().Add(actor);
+ application.GetScene().Add(actor);
// Render and notify
application.SendNotification();
Actor actor = Actor::New();
actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
- Stage::GetCurrent().Add(actor);
+ application.GetScene().Add(actor);
// Render and notify
application.SendNotification();
Actor actor = Actor::New();
actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
- Stage::GetCurrent().Add(actor);
+ application.GetScene().Add(actor);
// Render and notify
application.SendNotification();
Actor actor = Actor::New();
actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
- Stage::GetCurrent().Add(actor);
+ application.GetScene().Add(actor);
// Render and notify
application.SendNotification();
// Attach actor to detector
SignalData data;
- UnstageActorFunctor functor( data, stateToUnstage );
+ UnstageActorFunctor functor( data, stateToUnstage, application.GetScene() );
LongPressGestureDetector detector = LongPressGestureDetector::New();
detector.Attach(actor);
detector.DetectedSignal().Connect( &application, functor );
application.Render();
// Re-add actor to stage
- Stage::GetCurrent().Add(actor);
+ application.GetScene().Add(actor);
// Render and notify
application.SendNotification();
Actor actor = Actor::New();
actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
- Stage::GetCurrent().Add(actor);
+ application.GetScene().Add(actor);
// Create and add a second actor so that GestureDetector destruction does not come into play.
Actor dummyActor( Actor::New() );
dummyActor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
dummyActor.SetProperty( Actor::Property::POSITION, Vector2( 100.0f, 100.0f ));
dummyActor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
- Stage::GetCurrent().Add(dummyActor);
+ application.GetScene().Add(dummyActor);
// Render and notify
application.SendNotification();
// Attach actor to detector
SignalData data;
- UnstageActorFunctor functor( data, stateToUnstage );
+ UnstageActorFunctor functor( data, stateToUnstage, application.GetScene() );
LongPressGestureDetector detector = LongPressGestureDetector::New();
detector.Attach(actor);
detector.Attach(dummyActor);
application.Render();
// Re add to the stage, we should not be signalled
- Stage::GetCurrent().Add(actor);
+ application.GetScene().Add(actor);
// Render and notify
application.SendNotification();
Actor actor = Actor::New();
actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
- Stage::GetCurrent().Add(actor);
+ application.GetScene().Add(actor);
// Add a detector
SignalData data;
Layer layer = Layer::New();
layer.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
layer.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
- Stage::GetCurrent().Add( layer );
+ application.GetScene().Add( layer );
layer.RaiseToTop();
// Render and notify
data.Reset();
// Set layer to consume all touch
- layer.SetTouchConsumed( true );
+ layer.SetProperty( Layer::Property::CONSUMES_TOUCH, true );
// Render and notify
application.SendNotification();
Actor actor = Actor::New();
actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
- Stage::GetCurrent().Add( actor );
+ application.GetScene().Add( actor );
// Render and notify
application.SendNotification();
END_TEST;
}
+
+int UtcDaliLongPressGestureInterruptedWhenTouchConsumed(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;
+ TouchDataFunctorConsumeSetter touchFunctor(consume);
+ actor.TouchSignal().Connect(&application,touchFunctor);
+
+ // Render and notify
+ application.SendNotification();
+ application.Render();
+
+ SignalData data;
+ GestureReceivedFunctor functor(data);
+
+ LongPressGestureDetector detector = LongPressGestureDetector::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
+ TestGenerateLongPress( application, 50.0f, 50.0f );
+ DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
+ data.Reset();
+ TestEndLongPress(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;
+ TestGenerateLongPress( application, 50.0f, 50.0f );
+ DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
+ data.Reset();
+ TestEndLongPress(application, 50.0f,50.0f);
+ DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
+
+ END_TEST;
+}
+
+int UtcDaliLongPressGestureDisableDetectionDuringLongPressN(void)
+{
+ // Crash occurred when gesture-recognizer was deleted internally during a signal when the attached actor was detached
+
+ 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);
+
+ // Add a detector
+ LongPressGestureDetector detector = LongPressGestureDetector::New();
+ bool functorCalled = false;
+ detector.Attach( actor );
+ detector.DetectedSignal().Connect(
+ &application,
+ [&detector, &functorCalled](Actor actor, const LongPressGesture& gesture)
+ {
+ if( gesture.state == Gesture::Finished )
+ {
+ detector.Detach(actor);
+ functorCalled = true;
+ }
+ });
+
+ // Render and notify
+ application.SendNotification();
+ application.Render();
+
+ // Try the gesture, should not crash
+ try
+ {
+ TestGenerateLongPress( application, 50.0f, 10.0f );
+ TestEndLongPress( application, 50.0f, 10.0f );
+
+ DALI_TEST_CHECK( true ); // No crash, test has passed
+ DALI_TEST_EQUALS(functorCalled, true, TEST_LOCATION);
+ }
+ catch(...)
+ {
+ DALI_TEST_CHECK( false ); // If we crash, the test has failed
+ }
+
+ END_TEST;
+}
+
+