Add UserInteractionEnabled property on actor for controlling user interaction.
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-TouchProcessing.cpp
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <dali-test-suite-utils.h>
19 #include <dali/devel-api/actors/actor-devel.h>
20 #include <dali/integration-api/events/touch-event-integ.h>
21 #include <dali/integration-api/events/touch-integ.h>
22 #include <dali/integration-api/render-task-list-integ.h>
23 #include <dali/public-api/dali-core.h>
24 #include <stdlib.h>
25
26 #include <iostream>
27
28 using namespace Dali;
29
30 void utc_dali_touch_processing_startup(void)
31 {
32   test_return_value = TET_UNDEF;
33 }
34
35 void utc_dali_touch_processing_cleanup(void)
36 {
37   test_return_value = TET_PASS;
38 }
39
40 ///////////////////////////////////////////////////////////////////////////////
41
42 namespace
43 {
44 struct TestPoint
45 {
46   int32_t                deviceId{-1};
47   PointState::Type       state{PointState::FINISHED};
48   Actor                  hitActor;
49   Vector2                local;
50   Vector2                screen;
51   float                  radius{0};
52   Vector2                ellipseRadius;
53   float                  pressure{0};
54   Degree                 angle;
55   Device::Class::Type    deviceClass{Device::Class::NONE};
56   Device::Subclass::Type deviceSubclass{Device::Subclass::NONE};
57
58   TestPoint() = default;
59   static const TestPoint ZERO;
60 };
61
62 const TestPoint TestPoint::ZERO;
63
64 // Stores data that is populated in the callback and will be read by the TET cases
65 struct SignalData
66 {
67   SignalData()
68   : functorCalled(false),
69     receivedTouch(),
70     touchedActor()
71   {
72   }
73
74   struct TestTouchEvent
75   {
76     unsigned long          time;
77     std::vector<TestPoint> points;
78
79     const TestPoint& GetPoint(size_t i)
80     {
81       if(i < points.size())
82       {
83         return points[i];
84       }
85       return TestPoint::ZERO;
86     }
87     size_t GetPointCount()
88     {
89       return points.size();
90     }
91   };
92
93   void Reset()
94   {
95     functorCalled = false;
96
97     receivedTouch.time = 0u;
98     receivedTouch.points.clear();
99
100     touchedActor.Reset();
101   }
102
103   bool           functorCalled;
104   TestTouchEvent receivedTouch;
105   Actor          touchedActor;
106 };
107
108 // Functor that sets the data when called
109 struct TouchEventFunctor
110 {
111   /**
112    * Constructor.
113    * @param[in]  data         Reference to the data to store callback information.
114    * @param[in]  returnValue  What the functor should return.
115    */
116   TouchEventFunctor(SignalData& data, bool returnValue = true)
117   : signalData(data),
118     returnValue(returnValue)
119   {
120   }
121
122   bool operator()(Actor actor, const TouchEvent& touch)
123   {
124     signalData.functorCalled = true;
125     signalData.touchedActor  = actor;
126
127     signalData.receivedTouch.time = touch.GetTime();
128     signalData.receivedTouch.points.clear();
129
130     for(size_t i = 0; i < touch.GetPointCount(); ++i)
131     {
132       TestPoint p;
133       p.deviceId       = touch.GetDeviceId(i);
134       p.state          = touch.GetState(i);
135       p.hitActor       = touch.GetHitActor(i);
136       p.local          = touch.GetLocalPosition(i);
137       p.screen         = touch.GetScreenPosition(i);
138       p.radius         = touch.GetRadius(i);
139       p.ellipseRadius  = touch.GetEllipseRadius(i);
140       p.pressure       = touch.GetPressure(i);
141       p.angle          = touch.GetAngle(i);
142       p.deviceClass    = touch.GetDeviceClass(i);
143       p.deviceSubclass = touch.GetDeviceSubclass(i);
144       signalData.receivedTouch.points.push_back(p);
145     }
146
147     return returnValue;
148   }
149
150   SignalData& signalData;
151   bool        returnValue;
152 };
153
154 struct HandleData
155 {
156   bool       signalReceived;
157   TouchEvent receivedTouchHandle;
158
159   HandleData()
160   : signalReceived(false)
161   {
162   }
163 };
164
165 struct TouchEventHandleFunctor
166 {
167   /**
168    * Constructor.
169    * @param[in]  data         Reference to the data to store callback information.
170    * @param[in]  returnValue  What the functor should return.
171    */
172   TouchEventHandleFunctor(HandleData& handleData, bool returnValue = true)
173   : handleData(handleData),
174     returnValue(returnValue)
175   {
176   }
177
178   bool operator()(Actor actor, const TouchEvent& someTouchEvent)
179   {
180     handleData.signalReceived      = true;
181     handleData.receivedTouchHandle = someTouchEvent;
182     return returnValue;
183   }
184
185   HandleData& handleData;
186   bool        returnValue;
187 };
188
189 // Functor that removes the actor when called.
190 struct RemoveActorFunctor : public TouchEventFunctor
191 {
192   /**
193    * Constructor.
194    * @param[in]  data         Reference to the data to store callback information.
195    * @param[in]  returnValue  What the functor should return.
196    */
197   RemoveActorFunctor(SignalData& data, bool returnValue = true)
198   : TouchEventFunctor(data, returnValue)
199   {
200   }
201
202   bool operator()(Actor actor, const TouchEvent& touch)
203   {
204     Actor parent(actor.GetParent());
205     if(parent)
206     {
207       parent.Remove(actor);
208     }
209
210     return TouchEventFunctor::operator()(actor, touch);
211   }
212 };
213
214 struct OutOfBoundsData
215 {
216   TestPoint point;
217   bool      functorCalled;
218
219   OutOfBoundsData()
220   : functorCalled(false)
221   {
222   }
223 };
224
225 // Functor that reads out of bounds data when called
226 struct OutOfBoundsFunctor
227 {
228   /**
229    * Constructor.
230    * @param[in]  data         Reference to the data to store callback information.
231    * @param[in]  returnValue  What the functor should return.
232    */
233   OutOfBoundsFunctor(OutOfBoundsData& data, bool returnValue = true)
234   : outOfBoundsData(data),
235     returnValue(returnValue)
236   {
237   }
238
239   bool operator()(Actor actor, const TouchEvent& touch)
240   {
241     outOfBoundsData.functorCalled = true;
242     size_t count                  = touch.GetPointCount();
243
244     // Read out of bounds data
245     outOfBoundsData.point.deviceId = touch.GetDeviceId(count + 1);
246     outOfBoundsData.point.state    = touch.GetState(count + 1);
247     outOfBoundsData.point.hitActor = touch.GetHitActor(count + 1);
248     outOfBoundsData.point.local    = touch.GetLocalPosition(count + 1);
249     outOfBoundsData.point.screen   = touch.GetScreenPosition(count + 1);
250
251     return returnValue;
252   }
253
254   OutOfBoundsData& outOfBoundsData;
255   bool             returnValue;
256 };
257
258 Integration::TouchEvent GenerateSingleTouch(PointState::Type state, const Vector2& screenPosition)
259 {
260   Integration::TouchEvent touchEvent;
261   Integration::Point      point;
262   point.SetState(state);
263   point.SetScreenPosition(screenPosition);
264   point.SetDeviceClass(Device::Class::TOUCH);
265   point.SetDeviceSubclass(Device::Subclass::NONE);
266   touchEvent.points.push_back(point);
267   return touchEvent;
268 }
269
270 } // namespace
271
272 ///////////////////////////////////////////////////////////////////////////////
273
274 int UtcDaliTouchEventNormalProcessing01(void)
275 {
276   TestApplication application;
277
278   Actor actor = Actor::New();
279   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
280   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
281   application.GetScene().Add(actor);
282
283   // Render and notify
284   application.SendNotification();
285   application.Render();
286
287   // Connect to actor's touch signal
288   SignalData        data;
289   TouchEventFunctor functor(data);
290   actor.TouchedSignal().Connect(&application, functor);
291
292   Vector2 screenCoordinates(10.0f, 10.0f);
293   Vector2 localCoordinates;
294   actor.ScreenToLocal(localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y);
295
296   // Emit a down signal
297   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, screenCoordinates));
298   const TestPoint* point1 = &data.receivedTouch.GetPoint(0);
299   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
300   DALI_TEST_EQUALS(1u, data.receivedTouch.GetPointCount(), TEST_LOCATION);
301   DALI_TEST_EQUALS(PointState::DOWN, point1->state, TEST_LOCATION);
302   DALI_TEST_EQUALS(screenCoordinates, point1->screen, TEST_LOCATION);
303   DALI_TEST_EQUALS(localCoordinates, point1->local, 0.1f, TEST_LOCATION);
304   data.Reset();
305
306   // Emit a motion signal
307   screenCoordinates.x = screenCoordinates.y = 11.0f;
308   actor.ScreenToLocal(localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y);
309   application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, screenCoordinates));
310   const TestPoint* point2 = &data.receivedTouch.GetPoint(0);
311   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
312   DALI_TEST_EQUALS(1u, data.receivedTouch.GetPointCount(), TEST_LOCATION);
313   DALI_TEST_EQUALS(PointState::MOTION, point2->state, TEST_LOCATION);
314   DALI_TEST_EQUALS(screenCoordinates, point2->screen, TEST_LOCATION);
315   DALI_TEST_EQUALS(localCoordinates, point2->local, 0.1f, TEST_LOCATION);
316   data.Reset();
317
318   // Emit an up signal
319   screenCoordinates.x = screenCoordinates.y = 12.0f;
320   actor.ScreenToLocal(localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y);
321   application.ProcessEvent(GenerateSingleTouch(PointState::UP, screenCoordinates));
322   const TestPoint* point3 = &data.receivedTouch.GetPoint(0);
323   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
324   DALI_TEST_EQUALS(1u, data.receivedTouch.GetPointCount(), TEST_LOCATION);
325   DALI_TEST_EQUALS(PointState::UP, point3->state, TEST_LOCATION);
326   DALI_TEST_EQUALS(screenCoordinates, point3->screen, TEST_LOCATION);
327   DALI_TEST_EQUALS(localCoordinates, point3->local, 0.1f, TEST_LOCATION);
328   data.Reset();
329
330   // Emit a down signal where the actor is not present
331   screenCoordinates.x = screenCoordinates.y = 200.0f;
332   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, screenCoordinates));
333   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
334   END_TEST;
335 }
336
337 int UtcDaliTouchEventNormalProcessing02(void)
338 {
339   TestApplication application;
340
341   Actor actor = Actor::New();
342   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
343   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
344   application.GetScene().Add(actor);
345
346   // Render and notify
347   application.SendNotification();
348   application.Render();
349
350   // Connect to actor's touched signal
351   HandleData              handleData;
352   TouchEventHandleFunctor functor(handleData);
353   actor.TouchedSignal().Connect(&application, functor);
354
355   Vector2 screenCoordinates(10.0f, 10.0f);
356   Vector2 localCoordinates;
357   actor.ScreenToLocal(localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y);
358
359   // Emit a down signal
360   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, screenCoordinates));
361   DALI_TEST_EQUALS(true, handleData.signalReceived, TEST_LOCATION);
362   DALI_TEST_EQUALS(1u, handleData.receivedTouchHandle.GetPointCount(), TEST_LOCATION);
363   DALI_TEST_EQUALS(PointState::DOWN, handleData.receivedTouchHandle.GetState(0), TEST_LOCATION);
364   DALI_TEST_EQUALS(screenCoordinates, handleData.receivedTouchHandle.GetScreenPosition(0), TEST_LOCATION);
365   DALI_TEST_EQUALS(localCoordinates, handleData.receivedTouchHandle.GetLocalPosition(0), 0.1f, TEST_LOCATION);
366
367   END_TEST;
368 }
369
370 int UtcDaliTouchEventAPINegative(void)
371 {
372   TestApplication application;
373
374   Actor actor = Actor::New();
375   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
376   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
377   application.GetScene().Add(actor);
378
379   // Render and notify
380   application.SendNotification();
381   application.Render();
382
383   // Connect to actor's touched signal
384   OutOfBoundsData    data;
385   OutOfBoundsFunctor functor(data, true);
386   actor.TouchedSignal().Connect(&application, functor);
387
388   Vector2 screenCoordinates(10.0f, 10.0f);
389   Vector2 localCoordinates;
390   actor.ScreenToLocal(localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y);
391
392   // Emit a down signal
393   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, screenCoordinates));
394
395   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
396   DALI_TEST_EQUALS(-1, data.point.deviceId, TEST_LOCATION);
397   DALI_TEST_EQUALS(PointState::FINISHED, data.point.state, TEST_LOCATION);
398   DALI_TEST_EQUALS(Vector2::ZERO, data.point.screen, TEST_LOCATION);
399   DALI_TEST_EQUALS(Vector2::ZERO, data.point.local, 0.1f, TEST_LOCATION);
400   DALI_TEST_CHECK(!data.point.hitActor);
401
402   END_TEST;
403 }
404
405 int UtcDaliTouchEventOutsideCameraNearFarPlanes(void)
406 {
407   TestApplication application;
408
409   Integration::Scene scene     = application.GetScene();
410   Vector2            sceneSize = scene.GetSize();
411
412   Actor actor = Actor::New();
413   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
414   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
415   actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
416   scene.Add(actor);
417
418   // Render and notify
419   application.SendNotification();
420   application.Render();
421
422   // Get the camera's near and far planes
423   RenderTaskList   taskList  = scene.GetRenderTaskList();
424   Dali::RenderTask task      = taskList.GetTask(0);
425   CameraActor      camera    = task.GetCameraActor();
426   float            nearPlane = camera.GetNearClippingPlane();
427   float            farPlane  = camera.GetFarClippingPlane();
428
429   // Calculate the current distance of the actor from the camera
430   float tanHalfFov = tanf(camera.GetFieldOfView() * 0.5f);
431   float distance   = (sceneSize.y * 0.5f) / tanHalfFov;
432
433   // Connect to actor's touched signal
434   SignalData        data;
435   TouchEventFunctor functor(data);
436   actor.TouchedSignal().Connect(&application, functor);
437
438   Vector2 screenCoordinates(sceneSize.x * 0.5f, sceneSize.y * 0.5f);
439
440   // Emit a down signal
441   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, screenCoordinates));
442   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
443   data.Reset();
444
445   // Emit a down signal where actor is just at the camera's near plane
446   actor.SetProperty(Actor::Property::POSITION_Z, distance - nearPlane);
447
448   // Render and notify
449   application.SendNotification();
450   application.Render();
451
452   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, screenCoordinates));
453   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
454   data.Reset();
455
456   // Emit a down signal where actor is closer than the camera's near plane
457   actor.SetProperty(Actor::Property::POSITION_Z, (distance - nearPlane) + 1.0f);
458
459   // Render and notify
460   application.SendNotification();
461   application.Render();
462
463   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, screenCoordinates));
464   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
465   data.Reset();
466
467   // Emit a down signal where actor is just at the camera's far plane
468   actor.SetProperty(Actor::Property::POSITION_Z, distance - farPlane);
469
470   // Render and notify
471   application.SendNotification();
472   application.Render();
473
474   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, screenCoordinates));
475   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
476   data.Reset();
477
478   // Emit a down signal where actor is further than the camera's far plane
479   actor.SetProperty(Actor::Property::POSITION_Z, (distance - farPlane) - 1.0f);
480
481   // Render and notify
482   application.SendNotification();
483   application.Render();
484
485   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, screenCoordinates));
486   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
487   data.Reset();
488   END_TEST;
489 }
490
491 int UtcDaliTouchEventEmitEmpty(void)
492 {
493   TestApplication application;
494
495   try
496   {
497     // Emit an empty TouchEvent
498     Integration::TouchEvent event;
499     application.ProcessEvent(event);
500     tet_result(TET_FAIL);
501   }
502   catch(Dali::DaliException& e)
503   {
504     DALI_TEST_ASSERT(e, "!event.points.empty()", TEST_LOCATION);
505   }
506   END_TEST;
507 }
508
509 int UtcDaliTouchEventInterrupted(void)
510 {
511   TestApplication application;
512
513   Actor actor = Actor::New();
514   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
515   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
516   application.GetScene().Add(actor);
517
518   // Render and notify
519   application.SendNotification();
520   application.Render();
521
522   // Connect to actor's touched signal
523   SignalData        data;
524   TouchEventFunctor functor(data);
525   actor.TouchedSignal().Connect(&application, functor);
526
527   // Emit a down signal
528   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
529   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
530   DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
531   data.Reset();
532
533   // Emit an interrupted signal, we should be signalled regardless of whether there is a hit or not.
534   application.ProcessEvent(GenerateSingleTouch(PointState::INTERRUPTED, Vector2(200.0f, 200.0f /* Outside actor */)));
535   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
536   DALI_TEST_EQUALS(PointState::INTERRUPTED, data.receivedTouch.points[0].state, TEST_LOCATION);
537   data.Reset();
538
539   // Emit another interrupted signal, our signal handler should not be called.
540   application.ProcessEvent(GenerateSingleTouch(PointState::INTERRUPTED, Vector2(200.0f, 200.0f)));
541   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
542   END_TEST;
543 }
544
545 int UtcDaliTouchEventParentConsumer(void)
546 {
547   TestApplication application;
548   Actor           rootActor(application.GetScene().GetRootLayer());
549
550   Actor actor = Actor::New();
551   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
552   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
553   application.GetScene().Add(actor);
554
555   // Render and notify
556   application.SendNotification();
557   application.Render();
558
559   // Connect to actor's touched signal
560   SignalData        data;
561   TouchEventFunctor functor(data, false);
562   actor.TouchedSignal().Connect(&application, functor);
563
564   // Connect to root actor's touched signal
565   SignalData        rootData;
566   TouchEventFunctor rootFunctor(rootData); // Consumes signal
567   rootActor.TouchedSignal().Connect(&application, rootFunctor);
568
569   Vector2 screenCoordinates(10.0f, 10.0f);
570   Vector2 actorCoordinates, rootCoordinates;
571   actor.ScreenToLocal(actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y);
572   rootActor.ScreenToLocal(rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y);
573
574   // Emit a down signal
575   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, screenCoordinates));
576   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
577   DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
578   DALI_TEST_EQUALS(1u, data.receivedTouch.GetPointCount(), TEST_LOCATION);
579   DALI_TEST_EQUALS(1u, rootData.receivedTouch.GetPointCount(), TEST_LOCATION);
580   DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
581   DALI_TEST_EQUALS(PointState::DOWN, rootData.receivedTouch.points[0].state, TEST_LOCATION);
582   DALI_TEST_EQUALS(screenCoordinates, data.receivedTouch.points[0].screen, TEST_LOCATION);
583   DALI_TEST_EQUALS(screenCoordinates, rootData.receivedTouch.points[0].screen, TEST_LOCATION);
584   DALI_TEST_EQUALS(actorCoordinates, data.receivedTouch.points[0].local, 0.1f, TEST_LOCATION);
585   DALI_TEST_EQUALS(rootCoordinates, rootData.receivedTouch.points[0].local, 0.1f, TEST_LOCATION);
586   DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
587   DALI_TEST_CHECK(actor == rootData.receivedTouch.points[0].hitActor);
588   data.Reset();
589   rootData.Reset();
590
591   // Emit a motion signal
592   screenCoordinates.x = screenCoordinates.y = 11.0f;
593   actor.ScreenToLocal(actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y);
594   rootActor.ScreenToLocal(rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y);
595   application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, screenCoordinates));
596   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
597   DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
598   DALI_TEST_EQUALS(1u, data.receivedTouch.GetPointCount(), TEST_LOCATION);
599   DALI_TEST_EQUALS(1u, rootData.receivedTouch.GetPointCount(), TEST_LOCATION);
600   DALI_TEST_EQUALS(PointState::MOTION, data.receivedTouch.points[0].state, TEST_LOCATION);
601   DALI_TEST_EQUALS(PointState::MOTION, rootData.receivedTouch.points[0].state, TEST_LOCATION);
602   DALI_TEST_EQUALS(screenCoordinates, data.receivedTouch.points[0].screen, TEST_LOCATION);
603   DALI_TEST_EQUALS(screenCoordinates, rootData.receivedTouch.points[0].screen, TEST_LOCATION);
604   DALI_TEST_EQUALS(actorCoordinates, data.receivedTouch.points[0].local, 0.1f, TEST_LOCATION);
605   DALI_TEST_EQUALS(rootCoordinates, rootData.receivedTouch.points[0].local, 0.1f, TEST_LOCATION);
606   DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
607   DALI_TEST_CHECK(actor == rootData.receivedTouch.points[0].hitActor);
608   data.Reset();
609   rootData.Reset();
610
611   // Emit an up signal
612   screenCoordinates.x = screenCoordinates.y = 12.0f;
613   actor.ScreenToLocal(actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y);
614   rootActor.ScreenToLocal(rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y);
615   application.ProcessEvent(GenerateSingleTouch(PointState::UP, screenCoordinates));
616   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
617   DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
618   DALI_TEST_EQUALS(1u, data.receivedTouch.GetPointCount(), TEST_LOCATION);
619   DALI_TEST_EQUALS(1u, rootData.receivedTouch.GetPointCount(), TEST_LOCATION);
620   DALI_TEST_EQUALS(PointState::UP, data.receivedTouch.points[0].state, TEST_LOCATION);
621   DALI_TEST_EQUALS(PointState::UP, rootData.receivedTouch.points[0].state, TEST_LOCATION);
622   DALI_TEST_EQUALS(screenCoordinates, data.receivedTouch.points[0].screen, TEST_LOCATION);
623   DALI_TEST_EQUALS(screenCoordinates, rootData.receivedTouch.points[0].screen, TEST_LOCATION);
624   DALI_TEST_EQUALS(actorCoordinates, data.receivedTouch.points[0].local, 0.1f, TEST_LOCATION);
625   DALI_TEST_EQUALS(rootCoordinates, rootData.receivedTouch.points[0].local, 0.1f, TEST_LOCATION);
626   DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
627   DALI_TEST_CHECK(actor == rootData.receivedTouch.points[0].hitActor);
628   data.Reset();
629   rootData.Reset();
630
631   // Emit a down signal where the actor is not present, will hit the root actor though
632   screenCoordinates.x = screenCoordinates.y = 200.0f;
633   rootActor.ScreenToLocal(rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y);
634   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, screenCoordinates));
635   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
636   DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
637   DALI_TEST_EQUALS(1u, rootData.receivedTouch.GetPointCount(), TEST_LOCATION);
638   DALI_TEST_EQUALS(PointState::DOWN, rootData.receivedTouch.points[0].state, TEST_LOCATION);
639   DALI_TEST_EQUALS(screenCoordinates, rootData.receivedTouch.points[0].screen, TEST_LOCATION);
640   DALI_TEST_EQUALS(rootCoordinates, rootData.receivedTouch.points[0].local, 0.1f, TEST_LOCATION);
641   DALI_TEST_CHECK(rootActor == rootData.receivedTouch.points[0].hitActor);
642   END_TEST;
643 }
644
645 int UtcDaliTouchEventInterruptedParentConsumer(void)
646 {
647   TestApplication application;
648   Actor           rootActor(application.GetScene().GetRootLayer());
649
650   Actor actor = Actor::New();
651   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
652   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
653   application.GetScene().Add(actor);
654
655   // Render and notify
656   application.SendNotification();
657   application.Render();
658
659   // Connect to actor's touched signal
660   SignalData        data;
661   TouchEventFunctor functor(data, false);
662   actor.TouchedSignal().Connect(&application, functor);
663
664   // Connect to root actor's touched signal
665   SignalData        rootData;
666   TouchEventFunctor rootFunctor(rootData); // Consumes signal
667   rootActor.TouchedSignal().Connect(&application, rootFunctor);
668
669   // Emit a down signal
670   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
671   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
672   DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
673   DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
674   DALI_TEST_EQUALS(PointState::DOWN, rootData.receivedTouch.points[0].state, TEST_LOCATION);
675   DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
676   DALI_TEST_CHECK(actor == rootData.receivedTouch.points[0].hitActor);
677   data.Reset();
678   rootData.Reset();
679
680   // Emit an interrupted signal
681   application.ProcessEvent(GenerateSingleTouch(PointState::INTERRUPTED, Vector2(200.0f, 200.0f)));
682   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
683   DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
684   DALI_TEST_EQUALS(PointState::INTERRUPTED, data.receivedTouch.points[0].state, TEST_LOCATION);
685   DALI_TEST_EQUALS(PointState::INTERRUPTED, rootData.receivedTouch.points[0].state, TEST_LOCATION);
686   DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
687   DALI_TEST_CHECK(actor == rootData.receivedTouch.points[0].hitActor);
688   data.Reset();
689   rootData.Reset();
690
691   // Emit another down signal
692   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
693   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
694   DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
695   DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
696   DALI_TEST_EQUALS(PointState::DOWN, rootData.receivedTouch.points[0].state, TEST_LOCATION);
697   data.Reset();
698   rootData.Reset();
699
700   // Remove actor from scene
701   application.GetScene().Remove(actor);
702   data.Reset();
703   rootData.Reset();
704
705   // Render and notify
706   application.SendNotification();
707   application.Render();
708
709   // Emit an interrupted signal, only root actor's signal should be called.
710   application.ProcessEvent(GenerateSingleTouch(PointState::INTERRUPTED, Vector2(200.0f, 200.0f /* Outside actor */)));
711   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
712   DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
713   DALI_TEST_EQUALS(PointState::INTERRUPTED, rootData.receivedTouch.points[0].state, TEST_LOCATION);
714   DALI_TEST_CHECK(rootActor == rootData.receivedTouch.points[0].hitActor);
715   data.Reset();
716   rootData.Reset();
717
718   // Emit another interrupted state, none of the signal's should be called.
719   application.ProcessEvent(GenerateSingleTouch(PointState::INTERRUPTED, Vector2(200.0f, 200.0f)));
720   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
721   DALI_TEST_EQUALS(false, rootData.functorCalled, TEST_LOCATION);
722   END_TEST;
723 }
724
725 int UtcDaliTouchEventLeave(void)
726 {
727   TestApplication application;
728
729   Actor actor = Actor::New();
730   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
731   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
732   application.GetScene().Add(actor);
733
734   // Render and notify
735   application.SendNotification();
736   application.Render();
737
738   // Connect to actor's touched signal
739   SignalData        data;
740   TouchEventFunctor functor(data);
741   actor.TouchedSignal().Connect(&application, functor);
742
743   // Set actor to require leave events
744   actor.SetProperty(Actor::Property::LEAVE_REQUIRED, true);
745
746   // Emit a down signal
747   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
748   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
749   DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
750   data.Reset();
751
752   // Emit a motion signal outside of actor, should be signalled with a Leave
753   application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(200.0f, 200.0f)));
754   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
755   DALI_TEST_EQUALS(PointState::LEAVE, data.receivedTouch.points[0].state, TEST_LOCATION);
756   data.Reset();
757
758   // Another motion outside of actor, no signalling
759   application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(201.0f, 201.0f)));
760   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
761   data.Reset();
762
763   // Another motion event inside actor, signalled with motion
764   application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(10.0f, 10.0f)));
765   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
766   DALI_TEST_EQUALS(PointState::MOTION, data.receivedTouch.points[0].state, TEST_LOCATION);
767   data.Reset();
768
769   // We do not want to listen to leave events anymore
770   actor.SetProperty(Actor::Property::LEAVE_REQUIRED, false);
771
772   // Another motion event outside of actor, no signalling
773   application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(200.0f, 200.0f)));
774   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
775   data.Reset();
776   END_TEST;
777 }
778
779 int UtcDaliTouchEventLeaveParentConsumer(void)
780 {
781   TestApplication application;
782   Actor           rootActor(application.GetScene().GetRootLayer());
783
784   Actor actor = Actor::New();
785   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
786   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
787   application.GetScene().Add(actor);
788
789   // Render and notify
790   application.SendNotification();
791   application.Render();
792
793   // Connect to actor's touched signal
794   SignalData        data;
795   TouchEventFunctor functor(data, false);
796   actor.TouchedSignal().Connect(&application, functor);
797
798   // Connect to root actor's touched signal
799   SignalData        rootData;
800   TouchEventFunctor rootFunctor(rootData); // Consumes signal
801   rootActor.TouchedSignal().Connect(&application, rootFunctor);
802
803   // Set actor to require leave events
804   actor.SetProperty(Actor::Property::LEAVE_REQUIRED, true);
805   rootActor.SetProperty(Actor::Property::LEAVE_REQUIRED, true);
806
807   // Emit a down signal
808   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
809   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
810   DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
811   DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
812   DALI_TEST_EQUALS(PointState::DOWN, rootData.receivedTouch.points[0].state, TEST_LOCATION);
813   DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
814   DALI_TEST_CHECK(actor == rootData.receivedTouch.points[0].hitActor);
815   data.Reset();
816   rootData.Reset();
817
818   // Emit a motion signal outside of actor, should be signalled with a Leave
819   application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(200.0f, 200.0f)));
820   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
821   DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
822   DALI_TEST_EQUALS(PointState::LEAVE, data.receivedTouch.points[0].state, TEST_LOCATION);
823   DALI_TEST_EQUALS(PointState::LEAVE, rootData.receivedTouch.points[0].state, TEST_LOCATION);
824   DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
825   DALI_TEST_CHECK(actor == rootData.receivedTouch.points[0].hitActor);
826   data.Reset();
827   rootData.Reset();
828
829   // Another motion outside of actor, only rootActor signalled
830   application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(201.0f, 201.0f)));
831   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
832   DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
833   DALI_TEST_EQUALS(PointState::MOTION, rootData.receivedTouch.points[0].state, TEST_LOCATION);
834   DALI_TEST_CHECK(rootActor == rootData.receivedTouch.points[0].hitActor);
835   data.Reset();
836   rootData.Reset();
837
838   // Another motion event inside actor, signalled with motion
839   application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(10.0f, 10.0f)));
840   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
841   DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
842   DALI_TEST_EQUALS(PointState::MOTION, data.receivedTouch.points[0].state, TEST_LOCATION);
843   DALI_TEST_EQUALS(PointState::MOTION, rootData.receivedTouch.points[0].state, TEST_LOCATION);
844   DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
845   DALI_TEST_CHECK(actor == rootData.receivedTouch.points[0].hitActor);
846   data.Reset();
847   rootData.Reset();
848
849   // We do not want to listen to leave events of actor anymore
850   actor.SetProperty(Actor::Property::LEAVE_REQUIRED, false);
851
852   // Another motion event outside of root actor, only root signalled
853   Vector2 sceneSize(application.GetScene().GetSize());
854   application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(sceneSize.width + 10.0f, sceneSize.height + 10.0f)));
855   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
856   DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
857   DALI_TEST_EQUALS(PointState::LEAVE, rootData.receivedTouch.points[0].state, TEST_LOCATION);
858   END_TEST;
859 }
860
861 int UtcDaliTouchEventActorBecomesInsensitive(void)
862 {
863   TestApplication application;
864
865   Actor actor = Actor::New();
866   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
867   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
868   application.GetScene().Add(actor);
869
870   // Render and notify
871   application.SendNotification();
872   application.Render();
873
874   // Connect to actor's touched signal
875   SignalData        data;
876   TouchEventFunctor functor(data);
877   actor.TouchedSignal().Connect(&application, functor);
878
879   // Emit a down signal
880   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
881   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
882   DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
883   data.Reset();
884
885   // Change actor to insensitive
886   actor.SetProperty(Actor::Property::SENSITIVE, false);
887
888   // Emit a motion signal, signalled with an interrupted
889   application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(200.0f, 200.0f)));
890   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
891   DALI_TEST_EQUALS(PointState::INTERRUPTED, data.receivedTouch.points[0].state, TEST_LOCATION);
892   data.Reset();
893   END_TEST;
894 }
895
896 int UtcDaliTouchEventActorBecomesInsensitiveParentConsumer(void)
897 {
898   TestApplication application;
899   Actor           rootActor(application.GetScene().GetRootLayer());
900
901   Actor actor = Actor::New();
902   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
903   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
904   application.GetScene().Add(actor);
905
906   // Render and notify
907   application.SendNotification();
908   application.Render();
909
910   // Connect to actor's touched signal
911   SignalData        data;
912   TouchEventFunctor functor(data, false);
913   actor.TouchedSignal().Connect(&application, functor);
914
915   // Connect to root actor's touched signal
916   SignalData        rootData;
917   TouchEventFunctor rootFunctor(rootData); // Consumes signal
918   rootActor.TouchedSignal().Connect(&application, rootFunctor);
919
920   // Emit a down signal
921   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
922   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
923   DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
924   DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
925   DALI_TEST_EQUALS(PointState::DOWN, rootData.receivedTouch.points[0].state, TEST_LOCATION);
926   DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
927   DALI_TEST_CHECK(actor == rootData.receivedTouch.points[0].hitActor);
928   data.Reset();
929   rootData.Reset();
930
931   // Render and notify
932   application.SendNotification();
933   application.Render();
934
935   // Make root actor insensitive
936   rootActor.SetProperty(Actor::Property::SENSITIVE, false);
937
938   // Emit a motion signal, signalled with an interrupted (should get interrupted even if within root actor)
939   application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(200.0f, 200.0f)));
940   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
941   DALI_TEST_EQUALS(PointState::INTERRUPTED, data.receivedTouch.points[0].state, TEST_LOCATION);
942   DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
943   DALI_TEST_EQUALS(PointState::INTERRUPTED, rootData.receivedTouch.points[0].state, TEST_LOCATION);
944   END_TEST;
945 }
946
947 int UtcDaliTouchEventActorBecomesUserInteractionDisabled(void)
948 {
949   TestApplication application;
950
951   Actor actor = Actor::New();
952   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
953   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
954   application.GetScene().Add(actor);
955
956   // Render and notify
957   application.SendNotification();
958   application.Render();
959
960   // Connect to actor's touched signal
961   SignalData        data;
962   TouchEventFunctor functor(data);
963   actor.TouchedSignal().Connect(&application, functor);
964
965   // Emit a down signal
966   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
967   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
968   DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
969   data.Reset();
970
971   // Change actor to disable user interaction.
972   actor.SetProperty(DevelActor::Property::USER_INTERACTION_ENABLED, false);
973
974   // Emit a motion signal, signalled with an interrupted
975   application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(200.0f, 200.0f)));
976   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
977   DALI_TEST_EQUALS(PointState::INTERRUPTED, data.receivedTouch.points[0].state, TEST_LOCATION);
978   data.Reset();
979   END_TEST;
980 }
981
982 int UtcDaliTouchEventMultipleLayers(void)
983 {
984   TestApplication application;
985   Actor           rootActor(application.GetScene().GetRootLayer());
986
987   // Connect to actor's touched signal
988   SignalData        data;
989   TouchEventFunctor functor(data);
990
991   Layer layer1(Layer::New());
992   layer1.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
993   layer1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
994   application.GetScene().Add(layer1);
995
996   Actor actor1(Actor::New());
997   actor1.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
998   actor1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
999   actor1.SetProperty(Actor::Property::POSITION_Z, 1.0f); // Should hit actor1 in this layer
1000   layer1.Add(actor1);
1001
1002   // Render and notify
1003   application.SendNotification();
1004   application.Render();
1005
1006   // Connect to layer1 and actor1
1007   layer1.TouchedSignal().Connect(&application, functor);
1008   actor1.TouchedSignal().Connect(&application, functor);
1009
1010   // Hit in hittable area, actor1 should be hit
1011   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1012   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1013   DALI_TEST_CHECK(data.touchedActor == actor1);
1014   data.Reset();
1015
1016   // Make layer1 insensitive, nothing should be hit
1017   layer1.SetProperty(Actor::Property::SENSITIVE, false);
1018   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1019   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1020   data.Reset();
1021
1022   // Make layer1 sensitive again, again actor1 will be hit
1023   layer1.SetProperty(Actor::Property::SENSITIVE, true);
1024   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1025   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1026   DALI_TEST_CHECK(data.touchedActor == actor1);
1027   data.Reset();
1028
1029   // Make rootActor insensitive, nothing should be hit
1030   rootActor.SetProperty(Actor::Property::SENSITIVE, false);
1031   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1032   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1033   data.Reset();
1034
1035   // Make rootActor sensitive
1036   rootActor.SetProperty(Actor::Property::SENSITIVE, true);
1037
1038   // Add another layer
1039   Layer layer2(Layer::New());
1040   layer2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1041   layer2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1042   layer2.SetProperty(Actor::Property::POSITION_Z, 10.0f); // Should hit layer2 in this layer rather than actor2
1043   application.GetScene().Add(layer2);
1044
1045   Actor actor2(Actor::New());
1046   actor2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1047   actor2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1048   layer2.Add(actor2);
1049
1050   // Render and notify
1051   application.SendNotification();
1052   application.Render();
1053
1054   // Connect to layer2 and actor2
1055   layer2.TouchedSignal().Connect(&application, functor);
1056   actor2.TouchedSignal().Connect(&application, functor);
1057
1058   // Emit an event, should hit layer2
1059   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1060   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1061   //DALI_TEST_CHECK( data.touchedActor == layer2 ); // TODO: Uncomment this after removing renderable hack!
1062   data.Reset();
1063
1064   // Make layer2 insensitive, should hit actor1
1065   layer2.SetProperty(Actor::Property::SENSITIVE, false);
1066   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1067   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1068   DALI_TEST_CHECK(data.touchedActor == actor1);
1069   data.Reset();
1070
1071   // Make layer2 sensitive again, should hit layer2
1072   layer2.SetProperty(Actor::Property::SENSITIVE, true);
1073   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1074   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1075   //DALI_TEST_CHECK( data.touchedActor == layer2 ); // TODO: Uncomment this after removing renderable hack!
1076   data.Reset();
1077
1078   // Make layer2 invisible, render and notify
1079   layer2.SetProperty(Actor::Property::VISIBLE, false);
1080   application.SendNotification();
1081   application.Render();
1082
1083   // Should hit actor1
1084   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1085   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1086   DALI_TEST_CHECK(data.touchedActor == actor1);
1087   data.Reset();
1088
1089   // Make rootActor invisible, render and notify
1090   rootActor.SetProperty(Actor::Property::VISIBLE, false);
1091   application.SendNotification();
1092   application.Render();
1093
1094   // Should not hit anything
1095   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1096   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1097   data.Reset();
1098   END_TEST;
1099 }
1100
1101 int UtcDaliTouchEventMultipleRenderTasks(void)
1102 {
1103   TestApplication    application;
1104   Integration::Scene scene(application.GetScene());
1105   Vector2            sceneSize(scene.GetSize());
1106
1107   Actor actor = Actor::New();
1108   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1109   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1110   scene.Add(actor);
1111
1112   // Create render task
1113   Viewport   viewport(sceneSize.width * 0.5f, sceneSize.height * 0.5f, sceneSize.width * 0.5f, sceneSize.height * 0.5f);
1114   RenderTask renderTask(application.GetScene().GetRenderTaskList().CreateTask());
1115   renderTask.SetViewport(viewport);
1116   renderTask.SetInputEnabled(true);
1117
1118   // Render and notify
1119   application.SendNotification();
1120   application.Render();
1121
1122   // Connect to actor's touched signal
1123   SignalData        data;
1124   TouchEventFunctor functor(data);
1125   actor.TouchedSignal().Connect(&application, functor);
1126
1127   // Emit a down signal
1128   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1129   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1130   data.Reset();
1131
1132   // Ensure renderTask actor can be hit too.
1133   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(viewport.x + 5.0f, viewport.y + 5.0f)));
1134   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1135   data.Reset();
1136
1137   // Disable input on renderTask, should not be hittable
1138   renderTask.SetInputEnabled(false);
1139   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(viewport.x + 5.0f, viewport.y + 5.0f)));
1140   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1141   data.Reset();
1142   END_TEST;
1143 }
1144
1145 int UtcDaliTouchEventMultipleRenderTasksWithChildLayer(void)
1146 {
1147   TestApplication    application;
1148   Integration::Scene scene(application.GetScene());
1149   Vector2            sceneSize(scene.GetSize());
1150
1151   Actor actor = Actor::New();
1152   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1153   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1154   scene.Add(actor);
1155
1156   Layer layer = Layer::New();
1157   layer.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1158   layer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1159   actor.Add(layer);
1160
1161   // Create render task
1162   Viewport   viewport(sceneSize.width * 0.5f, sceneSize.height * 0.5f, sceneSize.width * 0.5f, sceneSize.height * 0.5f);
1163   RenderTask renderTask(application.GetScene().GetRenderTaskList().CreateTask());
1164   renderTask.SetViewport(viewport);
1165   renderTask.SetInputEnabled(true);
1166   renderTask.SetSourceActor(actor);
1167
1168   // Render and notify
1169   application.SendNotification();
1170   application.Render();
1171
1172   // Connect to layer's touched signal
1173   SignalData        data;
1174   TouchEventFunctor functor(data);
1175   actor.TouchedSignal().Connect(&application, functor);
1176   layer.TouchedSignal().Connect(&application, functor);
1177
1178   // Emit a down signal
1179   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1180   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1181   data.Reset();
1182
1183   // Ensure renderTask actor can be hit too.
1184   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(viewport.x + 5.0f, viewport.y + 5.0f)));
1185   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1186   data.Reset();
1187
1188   // Disable input on renderTask, should not be hittable
1189   renderTask.SetInputEnabled(false);
1190   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(viewport.x + 5.0f, viewport.y + 5.0f)));
1191   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1192   data.Reset();
1193   END_TEST;
1194 }
1195
1196 int UtcDaliTouchEventOffscreenRenderTasks(void)
1197 {
1198   TestApplication    application;
1199   Integration::Scene scene(application.GetScene());
1200   Vector2            sceneSize(scene.GetSize());
1201
1202   // FrameBufferImage for offscreen RenderTask
1203   FrameBuffer frameBuffer = FrameBuffer::New(sceneSize.width, sceneSize.height);
1204
1205   // Create a renderable actor to display the FrameBufferImage
1206   Actor renderableActor = CreateRenderableActor(frameBuffer.GetColorTexture());
1207   renderableActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1208   renderableActor.SetProperty(Actor::Property::SIZE, Vector2(sceneSize.x, sceneSize.y));
1209   renderableActor.ScaleBy(Vector3(1.0f, -1.0f, 1.0f)); // FIXME
1210   scene.Add(renderableActor);
1211
1212   Actor actor = Actor::New();
1213   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1214   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1215   scene.Add(actor);
1216   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE); // Ensure framebuffer connects
1217
1218   scene.GetRenderTaskList().GetTask(0u).SetScreenToFrameBufferFunction(RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION);
1219
1220   // Create a RenderTask
1221   RenderTask renderTask = scene.GetRenderTaskList().CreateTask();
1222   renderTask.SetSourceActor(actor);
1223   renderTask.SetFrameBuffer(frameBuffer);
1224   renderTask.SetInputEnabled(true);
1225
1226   // Create another RenderTask
1227   RenderTask renderTask2(scene.GetRenderTaskList().CreateTask());
1228   renderTask2.SetInputEnabled(true);
1229
1230   // Render and notify
1231   application.SendNotification();
1232   application.Render();
1233
1234   // Connect to actor's touched signal
1235   SignalData        data;
1236   TouchEventFunctor functor(data);
1237   actor.TouchedSignal().Connect(&application, functor);
1238
1239   // Emit a down signal
1240   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1241   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1242   data.Reset();
1243   END_TEST;
1244 }
1245
1246 int UtcDaliTouchEventMultipleRenderableActors(void)
1247 {
1248   TestApplication    application;
1249   Integration::Scene scene(application.GetScene());
1250   Vector2            sceneSize(scene.GetSize());
1251
1252   Actor parent = CreateRenderableActor();
1253   parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1254   parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1255   scene.Add(parent);
1256
1257   Actor actor = CreateRenderableActor();
1258   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1259   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1260   parent.Add(actor);
1261
1262   // Render and notify
1263   application.SendNotification();
1264   application.Render();
1265
1266   // Connect to layer's touched signal
1267   SignalData        data;
1268   TouchEventFunctor functor(data);
1269   parent.TouchedSignal().Connect(&application, functor);
1270   actor.TouchedSignal().Connect(&application, functor);
1271
1272   // Emit a down signal
1273   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1274   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1275   DALI_TEST_CHECK(actor == data.touchedActor);
1276   END_TEST;
1277 }
1278
1279 int UtcDaliTouchEventActorRemovedInSignal(void)
1280 {
1281   TestApplication application;
1282
1283   Actor actor = Actor::New();
1284   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1285   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1286   application.GetScene().Add(actor);
1287
1288   // Render and notify
1289   application.SendNotification();
1290   application.Render();
1291
1292   // Connect to actor's touched signal
1293   SignalData         data;
1294   RemoveActorFunctor functor(data);
1295   actor.TouchedSignal().Connect(&application, functor);
1296
1297   // Register for leave events
1298   actor.SetProperty(Actor::Property::LEAVE_REQUIRED, true);
1299
1300   // Emit a down signal
1301   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1302   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1303   data.Reset();
1304
1305   // Re-add, render and notify
1306   application.GetScene().Add(actor);
1307   application.SendNotification();
1308   application.Render();
1309
1310   // Emit another signal outside of actor's area, should not get anything as the scene has changed.
1311   application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(210.0f, 210.0f)));
1312   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1313   data.Reset();
1314
1315   // Emit a down signal
1316   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1317   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1318   data.Reset();
1319
1320   // Render and notify
1321   application.SendNotification();
1322   application.Render();
1323
1324   // Emit another signal outside of actor's area, should not get anything as the scene has changed.
1325   application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(210.0f, 210.0f)));
1326   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1327   data.Reset();
1328
1329   // Re-add actor back to scene, render and notify
1330   application.GetScene().Add(actor);
1331   application.SendNotification();
1332   application.Render();
1333
1334   // Emit another down event
1335   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1336   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1337   data.Reset();
1338
1339   // Completely delete the actor
1340   actor.Reset();
1341
1342   // Emit event, should not crash and should not receive an event.
1343   application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(210.0f, 210.0f)));
1344   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1345   END_TEST;
1346 }
1347
1348 int UtcDaliTouchEventActorSignalNotConsumed(void)
1349 {
1350   TestApplication application;
1351
1352   Actor actor = Actor::New();
1353   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1354   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1355   application.GetScene().Add(actor);
1356
1357   // Render and notify
1358   application.SendNotification();
1359   application.Render();
1360
1361   // Connect to actor's touched signal
1362   SignalData        data;
1363   TouchEventFunctor functor(data, false);
1364   actor.TouchedSignal().Connect(&application, functor);
1365
1366   // Emit a down signal
1367   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1368   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1369   END_TEST;
1370 }
1371
1372 int UtcDaliTouchEventActorRemovedFromScene(void)
1373 {
1374   TestApplication application;
1375
1376   Actor actor = Actor::New();
1377   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1378   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1379   application.GetScene().Add(actor);
1380
1381   // Render and notify
1382   application.SendNotification();
1383   application.Render();
1384
1385   // Connect to actor's touched signal
1386   SignalData        data;
1387   TouchEventFunctor functor(data);
1388   actor.TouchedSignal().Connect(&application, functor);
1389
1390   // Emit a down signal
1391   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1392   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1393   data.Reset();
1394
1395   // Remove actor from scene
1396   application.GetScene().Remove(actor);
1397   data.Reset();
1398
1399   // Render and notify
1400   application.SendNotification();
1401   application.Render();
1402
1403   // Emit a move at the same point, we should not be signalled.
1404   application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(10.0f, 10.0f)));
1405   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1406   data.Reset();
1407   END_TEST;
1408 }
1409
1410 int UtcDaliTouchEventLayerConsumesTouch(void)
1411 {
1412   TestApplication application;
1413
1414   Actor actor = Actor::New();
1415   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1416   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1417   application.GetScene().Add(actor);
1418
1419   // Render and notify
1420   application.SendNotification();
1421   application.Render();
1422
1423   // Connect to actor's touched signal
1424   SignalData        data;
1425   TouchEventFunctor functor(data);
1426   actor.TouchedSignal().Connect(&application, functor);
1427
1428   // Add a layer to overlap the actor
1429   Layer layer = Layer::New();
1430   layer.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1431   layer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1432   application.GetScene().Add(layer);
1433   layer.RaiseToTop();
1434
1435   // Render and notify
1436   application.SendNotification();
1437   application.Render();
1438
1439   // Emit a few touch signals
1440   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1441   application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(10.0f, 10.0f)));
1442   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1443   data.Reset();
1444
1445   // Set layer to consume all touch
1446   layer.SetProperty(Layer::Property::CONSUMES_TOUCH, true);
1447
1448   // Render and notify
1449   application.SendNotification();
1450   application.Render();
1451
1452   // Emit the same signals again, should not receive
1453   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1454   application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(10.0f, 10.0f)));
1455   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1456   data.Reset();
1457
1458   END_TEST;
1459 }
1460
1461 int UtcDaliTouchEventLeaveActorReadded(void)
1462 {
1463   TestApplication    application;
1464   Integration::Scene scene = application.GetScene();
1465
1466   Actor actor = Actor::New();
1467   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1468   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1469   scene.Add(actor);
1470
1471   // Set actor to receive touch-events
1472   actor.SetProperty(Actor::Property::LEAVE_REQUIRED, true);
1473
1474   // Render and notify
1475   application.SendNotification();
1476   application.Render();
1477
1478   // Connect to actor's touched signal
1479   SignalData        data;
1480   TouchEventFunctor functor(data);
1481   actor.TouchedSignal().Connect(&application, functor);
1482
1483   // Emit a down and motion
1484   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1485   application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(11.0f, 10.0f)));
1486   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1487   data.Reset();
1488
1489   // Remove actor from scene and add again
1490   scene.Remove(actor);
1491   scene.Add(actor);
1492
1493   // Emit a motion within the actor's bounds
1494   application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(12.0f, 10.0f)));
1495   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1496   data.Reset();
1497
1498   // Emit a motion outside the actor's bounds
1499   application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(200.0f, 200.0f)));
1500   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1501   DALI_TEST_EQUALS(PointState::LEAVE, data.receivedTouch.points[0].state, TEST_LOCATION);
1502   data.Reset();
1503
1504   END_TEST;
1505 }
1506
1507 int UtcDaliTouchEventClippedActor(void)
1508 {
1509   TestApplication    application;
1510   Integration::Scene scene = application.GetScene();
1511
1512   Actor actor = Actor::New();
1513   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1514   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1515   scene.Add(actor);
1516
1517   Actor clippingActor = Actor::New();
1518   clippingActor.SetProperty(Actor::Property::SIZE, Vector2(50.0f, 50.0f));
1519   clippingActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1520   clippingActor.SetProperty(Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN);
1521   scene.Add(clippingActor);
1522
1523   // Add a child to the clipped region.
1524   Actor clippingChild = Actor::New();
1525   clippingChild.SetProperty(Actor::Property::SIZE, Vector2(50.0f, 50.0f));
1526   clippingChild.SetProperty(Actor::Property::POSITION, Vector2(25.0f, 25.0f));
1527   clippingChild.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1528   clippingActor.Add(clippingChild);
1529
1530   // Render and notify.
1531   application.SendNotification();
1532   application.Render();
1533
1534   // Connect to actor's touch signal.
1535   SignalData        data;
1536   TouchEventFunctor functor(data);
1537   actor.TouchedSignal().Connect(&application, functor);
1538
1539   // Emit an event within clipped area - we should have a hit.
1540   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1541   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1542   data.Reset();
1543
1544   // Emit an event within clipped child area - we should still have a hit.
1545   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(40.0f, 40.0f)));
1546   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1547   data.Reset();
1548
1549   // Now connect to the clippingChild's touch signal
1550   SignalData        clippingChildData;
1551   TouchEventFunctor clippingChildFunctor(clippingChildData);
1552   clippingChild.TouchedSignal().Connect(&application, clippingChildFunctor);
1553
1554   // Emit an event within clipped child area - no hit on actor, but hit on clipped child.
1555   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(40.0f, 40.0f)));
1556   DALI_TEST_EQUALS(true, clippingChildData.functorCalled, TEST_LOCATION);
1557   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1558   data.Reset();
1559   clippingChildData.Reset();
1560
1561   // Emit an event outside the clipped area but within the actor area, we should have a hit.
1562   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(60.0f, 60.0f)));
1563   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1564   data.Reset();
1565   clippingChildData.Reset();
1566
1567   // 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.
1568   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(30.0f, 30.0f)));
1569   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1570   DALI_TEST_EQUALS(true, clippingChildData.functorCalled, TEST_LOCATION);
1571   data.Reset();
1572   clippingChildData.Reset();
1573
1574   END_TEST;
1575 }
1576
1577 int UtcDaliTouchEventActorUnparented(void)
1578 {
1579   TestApplication application;
1580
1581   Actor actor = Actor::New();
1582   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1583   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1584   application.GetScene().Add(actor);
1585
1586   // Render and notify
1587   application.SendNotification();
1588   application.Render();
1589
1590   // Connect to actor's touched signal
1591   SignalData        data;
1592   TouchEventFunctor functor(data);
1593   actor.TouchedSignal().Connect(&application, functor);
1594
1595   // Emit a down signal
1596   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1597   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1598   DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
1599   DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
1600   data.Reset();
1601
1602   // Render and notify
1603   application.SendNotification();
1604   application.Render();
1605
1606   // Unparent the actor
1607   actor.Unparent();
1608
1609   // Should receive an interrupted event
1610   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1611   DALI_TEST_EQUALS(PointState::INTERRUPTED, data.receivedTouch.points[0].state, TEST_LOCATION);
1612   END_TEST;
1613 }
1614
1615 int UtcDaliTouchEventParentRemovedFromScene(void)
1616 {
1617   TestApplication application;
1618
1619   Actor parent = Actor::New();
1620   parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1621   parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1622   application.GetScene().Add(parent);
1623
1624   Actor actor = Actor::New();
1625   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1626   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1627   parent.Add(actor);
1628
1629   // Render and notify
1630   application.SendNotification();
1631   application.Render();
1632
1633   // Connect to actor's touched signal
1634   SignalData        data;
1635   TouchEventFunctor functor(data);
1636   actor.TouchedSignal().Connect(&application, functor);
1637
1638   // Emit a down signal
1639   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1640   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1641   DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
1642   DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
1643   data.Reset();
1644
1645   // Render and notify
1646   application.SendNotification();
1647   application.Render();
1648
1649   // Unparent the parent of the touchable actor
1650   parent.Unparent();
1651
1652   // Should receive an interrupted event
1653   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1654   DALI_TEST_EQUALS(PointState::INTERRUPTED, data.receivedTouch.points[0].state, TEST_LOCATION);
1655   END_TEST;
1656 }
1657
1658 int UtcDaliTouchEventActorRemovedFromSceneDifferentConsumer(void)
1659 {
1660   TestApplication application;
1661
1662   Actor parent = Actor::New();
1663   parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1664   parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1665   application.GetScene().Add(parent);
1666
1667   Actor actor = Actor::New();
1668   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1669   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1670   parent.Add(actor);
1671
1672   // Render and notify
1673   application.SendNotification();
1674   application.Render();
1675
1676   // Connect to actor's touched signal
1677   SignalData        data;
1678   TouchEventFunctor functor(data, false /* Do not consume */);
1679   actor.TouchedSignal().Connect(&application, functor);
1680
1681   // Connect to parent's touched signal
1682   SignalData        parentData;
1683   TouchEventFunctor parentFunctor(parentData);
1684   parent.TouchedSignal().Connect(&application, parentFunctor);
1685
1686   // Emit a down signal
1687   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1688   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1689   DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
1690   DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
1691   DALI_TEST_CHECK(actor == data.touchedActor);
1692   DALI_TEST_EQUALS(true, parentData.functorCalled, TEST_LOCATION);
1693   DALI_TEST_EQUALS(PointState::DOWN, parentData.receivedTouch.points[0].state, TEST_LOCATION);
1694   DALI_TEST_CHECK(actor == parentData.receivedTouch.points[0].hitActor);
1695   DALI_TEST_CHECK(parent == parentData.touchedActor);
1696   data.Reset();
1697   parentData.Reset();
1698
1699   // Render and notify
1700   application.SendNotification();
1701   application.Render();
1702
1703   // Unparent the actor
1704   actor.Unparent();
1705
1706   // Should receive an interrupted event for both actor & parent
1707   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1708   DALI_TEST_EQUALS(PointState::INTERRUPTED, data.receivedTouch.points[0].state, TEST_LOCATION);
1709   DALI_TEST_EQUALS(true, parentData.functorCalled, TEST_LOCATION);
1710   DALI_TEST_EQUALS(PointState::INTERRUPTED, parentData.receivedTouch.points[0].state, TEST_LOCATION);
1711   data.Reset();
1712   parentData.Reset();
1713
1714   // Readd actor to parent
1715   parent.Add(actor);
1716
1717   // Render and notify
1718   application.SendNotification();
1719   application.Render();
1720
1721   // Emit a motion signal
1722   application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(10.0f, 10.0f)));
1723   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1724   DALI_TEST_EQUALS(true, parentData.functorCalled, TEST_LOCATION);
1725   data.Reset();
1726   parentData.Reset();
1727
1728   // Parent is now consumer, connect again to the touched signal of the actor so that it becomes the consumer
1729   SignalData        secondData;
1730   TouchEventFunctor secondFunctor(secondData /* Consume */);
1731   actor.TouchedSignal().Connect(&application, secondFunctor);
1732
1733   // Unparent the actor
1734   actor.Unparent();
1735
1736   // Should receive an interrupted event for both actor functors & the parent as well as it was last consumer
1737   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1738   DALI_TEST_EQUALS(PointState::INTERRUPTED, data.receivedTouch.points[0].state, TEST_LOCATION);
1739   DALI_TEST_EQUALS(true, parentData.functorCalled, TEST_LOCATION);
1740   DALI_TEST_EQUALS(PointState::INTERRUPTED, parentData.receivedTouch.points[0].state, TEST_LOCATION);
1741   DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1742   DALI_TEST_EQUALS(PointState::INTERRUPTED, secondData.receivedTouch.points[0].state, TEST_LOCATION);
1743   data.Reset();
1744   parentData.Reset();
1745   secondData.Reset();
1746
1747   END_TEST;
1748 }
1749
1750 int UtcDaliTouchEventInterruptedDifferentConsumer(void)
1751 {
1752   TestApplication application;
1753   Actor           rootActor(application.GetScene().GetRootLayer());
1754
1755   Actor parent = Actor::New();
1756   parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1757   parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1758   application.GetScene().Add(parent);
1759
1760   Actor actor = Actor::New();
1761   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1762   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1763   parent.Add(actor);
1764
1765   // Render and notify
1766   application.SendNotification();
1767   application.Render();
1768
1769   // Connect to actor's touched signal
1770   SignalData        data;
1771   TouchEventFunctor functor(data, false /* Do not consume */);
1772   actor.TouchedSignal().Connect(&application, functor);
1773
1774   // Connect to parent's touched signal
1775   SignalData        parentData;
1776   TouchEventFunctor parentFunctor(parentData, false /* Do not consume */);
1777   parent.TouchedSignal().Connect(&application, parentFunctor);
1778
1779   // Connect to root's touched signal and consume
1780   SignalData        rootData;
1781   TouchEventFunctor rootFunctor(rootData);
1782   rootActor.TouchedSignal().Connect(&application, rootFunctor);
1783
1784   // Emit a down signal
1785   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1786   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1787   DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
1788   DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
1789   DALI_TEST_CHECK(actor == data.touchedActor);
1790   DALI_TEST_EQUALS(true, parentData.functorCalled, TEST_LOCATION);
1791   DALI_TEST_EQUALS(PointState::DOWN, parentData.receivedTouch.points[0].state, TEST_LOCATION);
1792   DALI_TEST_CHECK(actor == parentData.receivedTouch.points[0].hitActor);
1793   DALI_TEST_CHECK(parent == parentData.touchedActor);
1794   DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
1795   DALI_TEST_EQUALS(PointState::DOWN, rootData.receivedTouch.points[0].state, TEST_LOCATION);
1796   DALI_TEST_CHECK(actor == rootData.receivedTouch.points[0].hitActor);
1797   DALI_TEST_CHECK(rootActor == rootData.touchedActor);
1798   data.Reset();
1799   parentData.Reset();
1800   rootData.Reset();
1801
1802   // Root is now consumer, connect to the touched signal of the parent so that it becomes the consumer
1803   SignalData        secondData;
1804   TouchEventFunctor secondFunctor(secondData /* Consume */);
1805   parent.TouchedSignal().Connect(&application, secondFunctor);
1806
1807   // Emit an interrupted signal, all three should STILL be called
1808   application.ProcessEvent(GenerateSingleTouch(PointState::INTERRUPTED, Vector2(10.0f, 10.0f)));
1809   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1810   DALI_TEST_EQUALS(PointState::INTERRUPTED, data.receivedTouch.points[0].state, TEST_LOCATION);
1811   DALI_TEST_EQUALS(true, parentData.functorCalled, TEST_LOCATION);
1812   DALI_TEST_EQUALS(PointState::INTERRUPTED, parentData.receivedTouch.points[0].state, TEST_LOCATION);
1813   DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
1814   DALI_TEST_EQUALS(PointState::INTERRUPTED, rootData.receivedTouch.points[0].state, TEST_LOCATION);
1815   data.Reset();
1816   parentData.Reset();
1817   rootData.Reset();
1818
1819   END_TEST;
1820 }
1821
1822 int UtcDaliTouchEventGetRadius(void)
1823 {
1824   TestApplication application;
1825
1826   Actor actor = Actor::New();
1827   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1828   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1829   application.GetScene().Add(actor);
1830
1831   // Render and notify
1832   application.SendNotification();
1833   application.Render();
1834
1835   // Connect to actor's touched signal
1836   SignalData        data;
1837   TouchEventFunctor functor(data);
1838   actor.TouchedSignal().Connect(&application, functor);
1839
1840   // Emit a down signal with an angle
1841   Integration::TouchEvent touchEvent = GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f));
1842   touchEvent.points[0].SetRadius(100.0f);
1843   application.ProcessEvent(touchEvent);
1844   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1845   DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
1846   DALI_TEST_EQUALS(100.0f, data.receivedTouch.points[0].radius, TEST_LOCATION);
1847   DALI_TEST_EQUALS(100.0f, data.receivedTouch.points[0].ellipseRadius.x, TEST_LOCATION);
1848   DALI_TEST_EQUALS(100.0f, data.receivedTouch.points[0].ellipseRadius.y, TEST_LOCATION);
1849
1850   END_TEST;
1851 }
1852
1853 int UtcDaliTouchEventGetEllipseRadius(void)
1854 {
1855   TestApplication application;
1856
1857   Actor actor = Actor::New();
1858   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1859   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1860   application.GetScene().Add(actor);
1861
1862   // Render and notify
1863   application.SendNotification();
1864   application.Render();
1865
1866   // Connect to actor's touched signal
1867   SignalData        data;
1868   TouchEventFunctor functor(data);
1869   actor.TouchedSignal().Connect(&application, functor);
1870
1871   // Emit a down signal with an angle
1872   Integration::TouchEvent touchEvent = GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f));
1873   touchEvent.points[0].SetRadius(100.0f, Vector2(20.0f, 10.0f));
1874   application.ProcessEvent(touchEvent);
1875   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1876   DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
1877   DALI_TEST_EQUALS(100.0f, data.receivedTouch.points[0].radius, TEST_LOCATION);
1878   DALI_TEST_EQUALS(20.0f, data.receivedTouch.points[0].ellipseRadius.x, TEST_LOCATION);
1879   DALI_TEST_EQUALS(10.0f, data.receivedTouch.points[0].ellipseRadius.y, TEST_LOCATION);
1880
1881   END_TEST;
1882 }
1883
1884 int UtcDaliTouchEventGetAngle(void)
1885 {
1886   TestApplication application;
1887
1888   Actor actor = Actor::New();
1889   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1890   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1891   application.GetScene().Add(actor);
1892
1893   // Render and notify
1894   application.SendNotification();
1895   application.Render();
1896
1897   // Connect to actor's touched signal
1898   SignalData        data;
1899   TouchEventFunctor functor(data);
1900   actor.TouchedSignal().Connect(&application, functor);
1901
1902   // Emit a down signal with an angle
1903   Integration::TouchEvent touchEvent = GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f));
1904   touchEvent.points[0].SetAngle(Degree(90.0f));
1905   application.ProcessEvent(touchEvent);
1906   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1907   DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
1908   DALI_TEST_EQUALS(Degree(90.0f), data.receivedTouch.points[0].angle, TEST_LOCATION);
1909
1910   END_TEST;
1911 }
1912
1913 int UtcDaliTouchEventGetPressure(void)
1914 {
1915   TestApplication application;
1916
1917   Actor actor = Actor::New();
1918   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1919   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1920   application.GetScene().Add(actor);
1921
1922   // Render and notify
1923   application.SendNotification();
1924   application.Render();
1925
1926   // Connect to actor's touched signal
1927   SignalData        data;
1928   TouchEventFunctor functor(data);
1929   actor.TouchedSignal().Connect(&application, functor);
1930
1931   // Emit a down signal with an angle
1932   Integration::TouchEvent touchEvent = GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f));
1933   touchEvent.points[0].SetPressure(10.0f);
1934   application.ProcessEvent(touchEvent);
1935   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1936   DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
1937   DALI_TEST_EQUALS(10.0f, data.receivedTouch.points[0].pressure, TEST_LOCATION);
1938
1939   END_TEST;
1940 }
1941
1942 int UtcDaliTouchEventUsage(void)
1943 {
1944   TestApplication application;
1945
1946   Actor actor = Actor::New();
1947   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1948   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1949   application.GetScene().Add(actor);
1950
1951   // Render and notify
1952   application.SendNotification();
1953   application.Render();
1954
1955   // Connect to actor's touched signal
1956   SignalData        data;
1957   TouchEventFunctor functor(data);
1958   actor.TouchedSignal().Connect(&application, functor);
1959
1960   // Emit a down signal with an angle
1961   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1962   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1963
1964   END_TEST;
1965 }
1966
1967 int UtcDaliTouchEventGetDeviceAPINegative(void)
1968 {
1969   TestApplication application;
1970
1971   Actor actor = Actor::New();
1972   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1973   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1974   application.GetScene().Add(actor);
1975
1976   // Render and notify
1977   application.SendNotification();
1978   application.Render();
1979
1980   // Connect to actor's touched signal
1981   HandleData              handleData;
1982   TouchEventHandleFunctor functor(handleData);
1983   actor.TouchedSignal().Connect(&application, functor);
1984
1985   Vector2 screenCoordinates(10.0f, 10.0f);
1986   Vector2 localCoordinates;
1987   actor.ScreenToLocal(localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y);
1988
1989   // Emit a down signal
1990   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, screenCoordinates));
1991
1992   TouchEvent data = handleData.receivedTouchHandle;
1993   DALI_TEST_EQUALS(data.GetDeviceClass(-1), Device::Class::NONE, TEST_LOCATION);
1994   DALI_TEST_EQUALS(data.GetDeviceSubclass(-1), Device::Subclass::NONE, TEST_LOCATION);
1995   END_TEST;
1996 }
1997
1998 int UtcDaliTouchEventGetMouseButtonPositive(void)
1999 {
2000   TestApplication application;
2001
2002   Actor actor = Actor::New();
2003   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2004   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2005   application.GetScene().Add(actor);
2006
2007   // Render and notify
2008   application.SendNotification();
2009   application.Render();
2010
2011   // Connect to actor's touched signal
2012   HandleData              handleData;
2013   TouchEventHandleFunctor functor(handleData);
2014   actor.TouchedSignal().Connect(&application, functor);
2015
2016   // Emit a down signal with MouseButton
2017   Integration::TouchEvent touchEvent = GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f));
2018   touchEvent.points[0].SetMouseButton(static_cast<MouseButton::Type>(3));
2019   application.ProcessEvent(touchEvent);
2020
2021   TouchEvent data = handleData.receivedTouchHandle;
2022   DALI_TEST_EQUALS(data.GetMouseButton(0), MouseButton::SECONDARY, TEST_LOCATION);
2023
2024   END_TEST;
2025 }
2026
2027 int UtcDaliTouchEventGetMouseButtonNagative(void)
2028 {
2029   TestApplication application;
2030
2031   Actor actor = Actor::New();
2032   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2033   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2034   application.GetScene().Add(actor);
2035
2036   // Render and notify
2037   application.SendNotification();
2038   application.Render();
2039
2040   // Connect to actor's touched signal
2041   HandleData              handleData;
2042   TouchEventHandleFunctor functor(handleData);
2043   actor.TouchedSignal().Connect(&application, functor);
2044
2045   // Emit a down signal with MouseButton
2046   Integration::TouchEvent touchEvent = GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f));
2047   touchEvent.points[0].SetMouseButton(static_cast<MouseButton::Type>(2));
2048   application.ProcessEvent(touchEvent);
2049
2050   TouchEvent data = handleData.receivedTouchHandle;
2051   DALI_TEST_EQUALS(data.GetMouseButton(0), MouseButton::TERTIARY, TEST_LOCATION);
2052   DALI_TEST_EQUALS(data.GetMouseButton(3), MouseButton::INVALID, TEST_LOCATION);
2053
2054   END_TEST;
2055 }
2056
2057 int UtcDaliTouchEventCapturePropertySet(void)
2058 {
2059   TestApplication application;
2060
2061   Actor actor = Actor::New();
2062   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2063   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2064   application.GetScene().Add(actor);
2065
2066   // Render and notify
2067   application.SendNotification();
2068   application.Render();
2069
2070   // Connect to actor's touched signal
2071   SignalData        data;
2072   TouchEventFunctor functor(data);
2073   actor.TouchedSignal().Connect(&application, functor);
2074
2075   // Emit a down signal
2076   application.ProcessEvent(GenerateSingleTouch(PointState::STARTED, Vector2(10.0f, 10.0f)));
2077   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2078   data.Reset();
2079
2080   // Now motion outside of actor, we should not receive the event
2081   application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(110.0f, 110.0f)));
2082   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2083   data.Reset();
2084
2085   // Up event, should receive an interrupted
2086   application.ProcessEvent(GenerateSingleTouch(PointState::FINISHED, Vector2(110.0f, 110.0f)));
2087   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2088   DALI_TEST_EQUALS(data.receivedTouch.GetPoint(0).state, PointState::INTERRUPTED, TEST_LOCATION);
2089
2090   // Now set the capture property
2091   actor.SetProperty(DevelActor::Property::CAPTURE_ALL_TOUCH_AFTER_START, true);
2092
2093   // Emit a down signal
2094   application.ProcessEvent(GenerateSingleTouch(PointState::STARTED, Vector2(10.0f, 10.0f)));
2095   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2096   data.Reset();
2097
2098   // Now motion outside of actor, we now SHOULD receive the event
2099   application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(110.0f, 110.0f)));
2100   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2101   data.Reset();
2102
2103   // Up event, we should receive it again, but as ended rather than interrupted
2104   application.ProcessEvent(GenerateSingleTouch(PointState::FINISHED, Vector2(110.0f, 110.0f)));
2105   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2106   DALI_TEST_EQUALS(data.receivedTouch.GetPoint(0).state, PointState::FINISHED, TEST_LOCATION);
2107
2108   END_TEST;
2109 }
2110
2111 int UtcDaliTouchEventIntegNewTouchEvent(void)
2112 {
2113   uint32_t         timestamp = 92858u;
2114   TouchPoint       tp(1, PointState::STARTED, 34.4f, 123.89f, 5.0f, 7.0f);
2115   Dali::TouchEvent touchEvent = Integration::NewTouchEvent(timestamp, tp);
2116
2117   DALI_TEST_EQUALS(touchEvent.GetPointCount(), 1u, TEST_LOCATION);
2118   DALI_TEST_EQUALS(touchEvent.GetState(0), PointState::STARTED, TEST_LOCATION);
2119   DALI_TEST_EQUALS(touchEvent.GetLocalPosition(0), Vector2(5.0f, 7.0f), TEST_LOCATION);
2120   DALI_TEST_EQUALS(touchEvent.GetScreenPosition(0), Vector2(34.4f, 123.89f), TEST_LOCATION);
2121
2122   END_TEST;
2123 }
2124
2125 int UtcDaliTouchEventIntercept01(void)
2126 {
2127   TestApplication application;
2128
2129   Actor actor = Actor::New();
2130   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2131   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2132   application.GetScene().Add(actor);
2133
2134   // Render and notify
2135   application.SendNotification();
2136   application.Render();
2137
2138   // Connect to actor's intercept touched signal
2139   SignalData        data;
2140   TouchEventFunctor functor(data, false /* Do not consume */);
2141   Dali::DevelActor::InterceptTouchedSignal(actor).Connect(&application, functor);
2142
2143   // Emit a down signal
2144   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
2145
2146   // It should be able to receive touch events by registering only InterceptTouchEvent.
2147   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2148   DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
2149   DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
2150   DALI_TEST_CHECK(actor == data.touchedActor);
2151   data.Reset();
2152
2153   END_TEST;
2154 }
2155
2156 int UtcDaliTouchEventIntercept02(void)
2157 {
2158   TestApplication application;
2159
2160   Actor parent = Actor::New();
2161   parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2162   parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2163   application.GetScene().Add(parent);
2164
2165   Actor actor = Actor::New();
2166   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2167   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2168   parent.Add(actor);
2169
2170   // Render and notify
2171   application.SendNotification();
2172   application.Render();
2173
2174   // Connect to actor's touched signal
2175   SignalData        data;
2176   TouchEventFunctor functor(data, false /* Do not consume */);
2177   actor.TouchedSignal().Connect(&application, functor);
2178
2179   // Connect to parent's touched signal
2180   SignalData        parentData;
2181   TouchEventFunctor parentFunctor(parentData, false /* Do not consume */);
2182   parent.TouchedSignal().Connect(&application, parentFunctor);
2183
2184   // Emit a down signal
2185   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
2186   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2187   DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
2188
2189   data.Reset();
2190   parentData.Reset();
2191
2192   // Connect to parent's intercept touched signal
2193   SignalData        interceptData;
2194   TouchEventFunctor interceptFunctor(interceptData, true /* Do intercept */);
2195   Dali::DevelActor::InterceptTouchedSignal(parent).Connect(&application, interceptFunctor);
2196
2197   // Emit a down signal
2198   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
2199
2200   // The actor gets interrupted. Because touch is intercepted by parent.
2201   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2202   DALI_TEST_EQUALS(PointState::INTERRUPTED, data.receivedTouch.points[0].state, TEST_LOCATION);
2203   DALI_TEST_EQUALS(true, interceptData.functorCalled, TEST_LOCATION);
2204   DALI_TEST_EQUALS(PointState::DOWN, interceptData.receivedTouch.points[0].state, TEST_LOCATION);
2205   DALI_TEST_CHECK(actor == interceptData.receivedTouch.points[0].hitActor);
2206   DALI_TEST_CHECK(parent == interceptData.touchedActor);
2207   DALI_TEST_EQUALS(true, parentData.functorCalled, TEST_LOCATION);
2208   DALI_TEST_EQUALS(PointState::DOWN, parentData.receivedTouch.points[0].state, TEST_LOCATION);
2209   DALI_TEST_CHECK(actor == parentData.receivedTouch.points[0].hitActor);
2210   DALI_TEST_CHECK(parent == parentData.touchedActor);
2211   data.Reset();
2212   parentData.Reset();
2213
2214   END_TEST;
2215 }
2216
2217 int UtcDaliTouchAreaOffset(void)
2218 {
2219   TestApplication application;
2220
2221   Actor actor = Actor::New();
2222   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2223   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2224
2225   application.GetScene().Add(actor);
2226
2227   // Render and notify
2228   application.SendNotification();
2229   application.Render();
2230
2231   // Connect to actor's touched signal
2232   SignalData        data;
2233   TouchEventFunctor functor(data, false /* Do not consume */);
2234   actor.TouchedSignal().Connect(&application, functor);
2235
2236   // Emit a down signal
2237   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(110.0f, 110.0f)));
2238   // The actor touched signal is not called because the touch area is outside actor.
2239   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2240   data.Reset();
2241
2242   // set a bigger touch area
2243   actor.SetProperty(DevelActor::Property::TOUCH_AREA_OFFSET, Rect<int>(-70, 70, 70, -70)); // left, right, bottom, top
2244
2245   // Render and notify
2246   application.SendNotification();
2247   application.Render();
2248
2249   // Emit a down signal
2250   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(150.0f, 150.0f)));
2251   // The actor touched signal is called because the touch area is inside touchArea.
2252   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2253   DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
2254   DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
2255   data.Reset();
2256
2257   // set a offset touch area
2258   actor.SetProperty(DevelActor::Property::TOUCH_AREA_OFFSET, Rect<int>(50, 100, -50, 0)); // left, right, bottom, top
2259
2260   // Render and notify
2261   application.SendNotification();
2262   application.Render();
2263
2264   // Emit a down signal
2265   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(190.0f, 25.0f)));
2266   // The actor touched signal is called because the touch area is inside touchArea.
2267   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2268   DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
2269   DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
2270   data.Reset();
2271
2272   // set a smaller touch area
2273   actor.SetProperty(DevelActor::Property::TOUCH_AREA_OFFSET, Rect<int>(50, 0, 0, 50));
2274
2275   // Render and notify
2276   application.SendNotification();
2277   application.Render();
2278
2279   // Emit a down signal
2280   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(40.0f, 40.0f)));
2281   // The actor touched signal is not called because the touch area is outside touchArea.
2282   DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2283   data.Reset();
2284
2285   // Emit a down signal
2286   application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(90.0f, 90.0f)));
2287   // The actor touched signal is called because the touch area is inside touchArea.
2288   DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2289   DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
2290   DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
2291   data.Reset();
2292
2293   END_TEST;
2294 }