Add UserInteractionEnabled property on actor for controlling user interaction.
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-TouchProcessing.cpp
old mode 100755 (executable)
new mode 100644 (file)
index e0c7b80..d39266a
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -944,6 +944,41 @@ int UtcDaliTouchEventActorBecomesInsensitiveParentConsumer(void)
   END_TEST;
 }
 
+int UtcDaliTouchEventActorBecomesUserInteractionDisabled(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();
+
+  // Connect to actor's touched signal
+  SignalData        data;
+  TouchEventFunctor functor(data);
+  actor.TouchedSignal().Connect(&application, functor);
+
+  // Emit a down signal
+  application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
+  DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
+  DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
+  data.Reset();
+
+  // Change actor to disable user interaction.
+  actor.SetProperty(DevelActor::Property::USER_INTERACTION_ENABLED, false);
+
+  // Emit a motion signal, signalled with an interrupted
+  application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(200.0f, 200.0f)));
+  DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
+  DALI_TEST_EQUALS(PointState::INTERRUPTED, data.receivedTouch.points[0].state, TEST_LOCATION);
+  data.Reset();
+  END_TEST;
+}
+
 int UtcDaliTouchEventMultipleLayers(void)
 {
   TestApplication application;
@@ -1501,22 +1536,40 @@ int UtcDaliTouchEventClippedActor(void)
   TouchEventFunctor functor(data);
   actor.TouchedSignal().Connect(&application, functor);
 
-  // Emit an event within clipped area - no hit.
+  // Emit an event within clipped area - we should have a hit.
   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
+  DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
+  data.Reset();
+
+  // Emit an event within clipped child area - we should still have a hit.
+  application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(40.0f, 40.0f)));
+  DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
+  data.Reset();
+
+  // Now connect to the clippingChild's touch signal
+  SignalData        clippingChildData;
+  TouchEventFunctor clippingChildFunctor(clippingChildData);
+  clippingChild.TouchedSignal().Connect(&application, clippingChildFunctor);
+
+  // Emit an event within clipped child area - no hit on actor, but hit on clipped child.
+  application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(40.0f, 40.0f)));
+  DALI_TEST_EQUALS(true, clippingChildData.functorCalled, TEST_LOCATION);
   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
   data.Reset();
+  clippingChildData.Reset();
 
   // Emit an event outside the clipped area but within the actor area, we should have a hit.
   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(60.0f, 60.0f)));
   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
   data.Reset();
+  clippingChildData.Reset();
 
-  clippingChild.TouchedSignal().Connect(&application, functor);
-
-  // Emit an event inside part of the child which is within the clipped area, we should have a hit.
+  // Emit an event inside part of the child which is within the clipped area, we should have a hit on the clipped child but not the actor.
   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(30.0f, 30.0f)));
-  DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
+  DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
+  DALI_TEST_EQUALS(true, clippingChildData.functorCalled, TEST_LOCATION);
   data.Reset();
+  clippingChildData.Reset();
 
   END_TEST;
 }
@@ -2069,8 +2122,38 @@ int UtcDaliTouchEventIntegNewTouchEvent(void)
   END_TEST;
 }
 
+int UtcDaliTouchEventIntercept01(void)
+{
+  TestApplication application;
 
-int UtcDaliTouchEventIntercept(void)
+  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();
+
+  // Connect to actor's intercept touched signal
+  SignalData        data;
+  TouchEventFunctor functor(data, false /* Do not consume */);
+  Dali::DevelActor::InterceptTouchedSignal(actor).Connect(&application, functor);
+
+  // Emit a down signal
+  application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
+
+  // It should be able to receive touch events by registering only InterceptTouchEvent.
+  DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
+  DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
+  DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
+  DALI_TEST_CHECK(actor == data.touchedActor);
+  data.Reset();
+
+  END_TEST;
+}
+
+int UtcDaliTouchEventIntercept02(void)
 {
   TestApplication application;
 
@@ -2093,11 +2176,19 @@ int UtcDaliTouchEventIntercept(void)
   TouchEventFunctor functor(data, false /* Do not consume */);
   actor.TouchedSignal().Connect(&application, functor);
 
-
   // Connect to parent's touched signal
   SignalData        parentData;
   TouchEventFunctor parentFunctor(parentData, false /* Do not consume */);
   parent.TouchedSignal().Connect(&application, parentFunctor);
+
+  // Emit a down signal
+  application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
+  DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
+  DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
+
+  data.Reset();
+  parentData.Reset();
+
   // Connect to parent's intercept touched signal
   SignalData        interceptData;
   TouchEventFunctor interceptFunctor(interceptData, true /* Do intercept */);
@@ -2105,8 +2196,10 @@ int UtcDaliTouchEventIntercept(void)
 
   // Emit a down signal
   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
-  // The actor touched signal is not called because the touch is intercepted in the parent.
-  DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
+
+  // The actor gets interrupted. Because touch is intercepted by parent.
+  DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
+  DALI_TEST_EQUALS(PointState::INTERRUPTED, data.receivedTouch.points[0].state, TEST_LOCATION);
   DALI_TEST_EQUALS(true, interceptData.functorCalled, TEST_LOCATION);
   DALI_TEST_EQUALS(PointState::DOWN, interceptData.receivedTouch.points[0].state, TEST_LOCATION);
   DALI_TEST_CHECK(actor == interceptData.receivedTouch.points[0].hitActor);
@@ -2121,7 +2214,7 @@ int UtcDaliTouchEventIntercept(void)
   END_TEST;
 }
 
-int UtcDaliTouchDelegateArea(void)
+int UtcDaliTouchAreaOffset(void)
 {
   TestApplication application;
 
@@ -2146,37 +2239,52 @@ int UtcDaliTouchDelegateArea(void)
   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
   data.Reset();
 
-  // set a bigger touch delegate area
-  actor.SetProperty(DevelActor::Property::TOUCH_DELEGATE_AREA, Vector2(200.0f, 200.0f));
+  // set a bigger touch area
+  actor.SetProperty(DevelActor::Property::TOUCH_AREA_OFFSET, Rect<int>(-70, 70, 70, -70)); // left, right, bottom, top
 
   // Render and notify
   application.SendNotification();
   application.Render();
 
   // Emit a down signal
-  application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(110.0f, 110.0f)));
-  // The actor touched signal is called because the touch area is inside touchDelegateArea.
+  application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(150.0f, 150.0f)));
+  // The actor touched signal is called because the touch area is inside touchArea.
   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
   DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
   DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
   data.Reset();
 
-  // set a smaller touch delegate area
-  actor.SetProperty(DevelActor::Property::TOUCH_DELEGATE_AREA, Vector2(50.0f, 50.0f));
+  // set a offset touch area
+  actor.SetProperty(DevelActor::Property::TOUCH_AREA_OFFSET, Rect<int>(50, 100, -50, 0)); // left, right, bottom, top
 
   // Render and notify
   application.SendNotification();
   application.Render();
 
   // Emit a down signal
-  application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(80.0f, 80.0f)));
-  // The actor touched signal is not called because the touch area is outside touchDelegateArea.
+  application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(190.0f, 25.0f)));
+  // The actor touched signal is called because the touch area is inside touchArea.
+  DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
+  DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
+  DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
+  data.Reset();
+
+  // set a smaller touch area
+  actor.SetProperty(DevelActor::Property::TOUCH_AREA_OFFSET, Rect<int>(50, 0, 0, 50));
+
+  // Render and notify
+  application.SendNotification();
+  application.Render();
+
+  // Emit a down signal
+  application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(40.0f, 40.0f)));
+  // The actor touched signal is not called because the touch area is outside touchArea.
   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
   data.Reset();
 
   // Emit a down signal
-  application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(30.0f, 30.0f)));
-  // The actor touched signal is called because the touch area is inside touchDelegateArea.
+  application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(90.0f, 90.0f)));
+  // The actor touched signal is called because the touch area is inside touchArea.
   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
   DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
   DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);