[dali_1.2.40] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / internal / event / events / touch-event-processor.cpp
index 0e58e54..871d851 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@
 #endif
 
 // INTERNAL INCLUDES
+#include <dali/public-api/events/touch-data.h>
 #include <dali/public-api/math/vector2.h>
 #include <dali/public-api/signals/callback.h>
 #include <dali/integration-api/debug.h>
@@ -32,6 +33,7 @@
 #include <dali/internal/event/common/stage-impl.h>
 #include <dali/internal/event/events/hit-test-algorithm-impl.h>
 #include <dali/internal/event/events/multi-point-event-util.h>
+#include <dali/internal/event/events/touch-data-impl.h>
 #include <dali/internal/event/render-tasks/render-task-impl.h>
 
 namespace Dali
@@ -46,22 +48,23 @@ namespace
 #if defined(DEBUG_ENABLED)
 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_TOUCH_PROCESSOR" );
 
-const char * TOUCH_POINT_STATE[TouchPoint::Last] =
+const char * TOUCH_POINT_STATE[ 6 ] =
 {
-  "Down",
-  "Up",
-  "Motion",
-  "Leave",
-  "Stationary",
-  "Interrupted",
+  "DOWN",
+  "UP",
+  "MOTION",
+  "LEAVE",
+  "STATIONARY",
+  "INTERRUPTED",
 };
 
 #endif // defined(DEBUG_ENABLED)
 
+
 /**
  *  Recursively deliver events to the actor and its parents, until the event is consumed or the stage is reached.
  */
-Dali::Actor EmitTouchSignals( Dali::Actor actor, const TouchEvent& event )
+Dali::Actor EmitTouchSignals( Dali::Actor actor, const TouchEvent& event, const Dali::TouchData& touchData )
 {
   Dali::Actor consumedActor;
 
@@ -76,7 +79,7 @@ Dali::Actor EmitTouchSignals( Dali::Actor actor, const TouchEvent& event )
     // Only emit the signal if the actor's touch signal has connections (or derived actor implementation requires touch).
     if ( actorImpl.GetTouchRequired() )
     {
-      consumed = actorImpl.EmitTouchEventSignal( event );
+      consumed = actorImpl.EmitTouchEventSignal( event, touchData );
     }
 
     if ( consumed )
@@ -93,7 +96,7 @@ Dali::Actor EmitTouchSignals( Dali::Actor actor, const TouchEvent& event )
            (parent == oldParent) )
       {
         // One of the actor's parents may consumed the event and they should be set as the consumed actor.
-        consumedActor = EmitTouchSignals( parent, event );
+        consumedActor = EmitTouchSignals( parent, event, touchData );
       }
     }
   }
@@ -101,25 +104,47 @@ Dali::Actor EmitTouchSignals( Dali::Actor actor, const TouchEvent& event )
   return consumedActor;
 }
 
+Dali::Actor AllocAndEmitTouchSignals( unsigned long time,  Dali::Actor actor, const Integration::Point& point )
+{
+  TouchEvent touchEvent( time );
+  TouchDataPtr touchData( new TouchData( time ) );
+  Dali::TouchData touchDataHandle( touchData.Get() );
+
+  touchEvent.points.push_back( point.GetTouchPoint() );
+  touchData->AddPoint( point );
+
+  return EmitTouchSignals( actor, touchEvent, touchDataHandle );
+}
+
+
 /**
  * Changes the state of the primary point to leave and emits the touch signals
  */
-Dali::Actor EmitTouchSignals( Actor* actor, RenderTask& renderTask, const TouchEvent& originalEvent, TouchPoint::State state )
+Dali::Actor EmitTouchSignals( Actor* actor, RenderTask& renderTask, const TouchEvent& originalEvent, const TouchDataPtr& originalTouchData, PointState::Type state )
 {
-  TouchEvent touchEvent( originalEvent );
+  Dali::Actor consumingActor;
 
-  DALI_ASSERT_DEBUG( NULL != actor && "NULL actor pointer" );
   if( actor )
   {
-    TouchPoint& primaryPoint = touchEvent.points[0];
+    TouchDataPtr touchData = TouchData::Clone( *originalTouchData.Get() );
+
+    Integration::Point& primaryPoint = touchData->GetPoint( 0 );
+
+    const Vector2& screenPosition = primaryPoint.GetScreenPosition();
+    Vector2 localPosition;
+    actor->ScreenToLocal( renderTask, localPosition.x, localPosition.y, screenPosition.x, screenPosition.y );
 
-    actor->ScreenToLocal( renderTask, primaryPoint.local.x, primaryPoint.local.y, primaryPoint.screen.x, primaryPoint.screen.y );
+    primaryPoint.SetLocalPosition( localPosition );
+    primaryPoint.SetHitActor( Dali::Actor( actor ) );
+    primaryPoint.SetState( state );
 
-    primaryPoint.hitActor = Dali::Actor(actor);
-    primaryPoint.state = state;
+    TouchEvent touchEvent( originalEvent );
+    touchEvent.points[0] = primaryPoint.GetTouchPoint();
+
+    consumingActor = EmitTouchSignals( Dali::Actor(actor), touchEvent, Dali::TouchData( touchData.Get() ) );
   }
 
-  return EmitTouchSignals( Dali::Actor(actor), touchEvent );
+  return consumingActor;
 }
 
 } // unnamed namespace
@@ -149,23 +174,21 @@ void TouchEventProcessor::ProcessTouchEvent( const Integration::TouchEvent& even
 
   PRINT_HIERARCHY(gLogFilter);
 
-  // Copy so we can add the results of a hit-test.
-  TouchEvent touchEvent( event.time );
-
   // 1) Check if it is an interrupted event - we should inform our last primary hit actor about this
   //    and emit the stage signal as well.
 
-  if ( event.points[0].state == TouchPoint::Interrupted )
+  if ( event.points[0].GetState() == PointState::INTERRUPTED )
   {
     Dali::Actor consumingActor;
-    touchEvent.points.push_back(event.points[0]);
+    Integration::Point currentPoint( event.points[0] );
 
     Actor* lastPrimaryHitActor( mLastPrimaryHitActor.GetActor() );
     if ( lastPrimaryHitActor )
     {
       Dali::Actor lastPrimaryHitActorHandle( lastPrimaryHitActor );
-      touchEvent.points[0].hitActor = lastPrimaryHitActorHandle;
-      consumingActor = EmitTouchSignals( lastPrimaryHitActorHandle, touchEvent );
+      currentPoint.SetHitActor( lastPrimaryHitActorHandle );
+
+      consumingActor = AllocAndEmitTouchSignals( event.time, lastPrimaryHitActorHandle, currentPoint );
     }
 
     // If the last consumed actor was different to the primary hit actor then inform it as well (if it has not already been informed).
@@ -175,8 +198,8 @@ void TouchEventProcessor::ProcessTouchEvent( const Integration::TouchEvent& even
          lastConsumedActor != consumingActor )
     {
       Dali::Actor lastConsumedActorHandle( lastConsumedActor );
-      touchEvent.points[0].hitActor = lastConsumedActorHandle;
-      EmitTouchSignals( lastConsumedActorHandle, touchEvent );
+      currentPoint.SetHitActor( lastConsumedActorHandle );
+      AllocAndEmitTouchSignals( event.time, lastConsumedActorHandle, currentPoint );
     }
 
     // Tell the touch-down consuming actor as well, if required
@@ -187,8 +210,9 @@ void TouchEventProcessor::ProcessTouchEvent( const Integration::TouchEvent& even
          touchDownConsumedActor != consumingActor )
     {
       Dali::Actor touchDownConsumedActorHandle( touchDownConsumedActor );
-      touchEvent.points[0].hitActor = touchDownConsumedActorHandle;
-      EmitTouchSignals( touchDownConsumedActorHandle, touchEvent );
+
+      currentPoint.SetHitActor( touchDownConsumedActorHandle );
+      AllocAndEmitTouchSignals( event.time, touchDownConsumedActorHandle, currentPoint );
     }
 
     mLastPrimaryHitActor.SetActor( NULL );
@@ -196,33 +220,45 @@ void TouchEventProcessor::ProcessTouchEvent( const Integration::TouchEvent& even
     mTouchDownConsumedActor.SetActor( NULL );
     mLastRenderTask.Reset();
 
-    touchEvent.points[0].hitActor.Reset();
-    mStage.EmitTouchedSignal( touchEvent );
+    currentPoint.SetHitActor( Dali::Actor() );
+
+    TouchEvent touchEvent( event.time );
+    TouchDataPtr touchData( new TouchData( event.time ) );
+    Dali::TouchData touchDataHandle( touchData.Get() );
+
+    touchEvent.points.push_back( currentPoint.GetTouchPoint() );
+    touchData->AddPoint( currentPoint );
+
+    mStage.EmitTouchedSignal( touchEvent, touchDataHandle );
 
     return; // No need for hit testing
   }
 
   // 2) Hit Testing.
+  TouchEvent touchEvent( event.time );
+  TouchDataPtr touchData( new TouchData( event.time ) );
+  Dali::TouchData touchDataHandle( touchData.Get() );
 
   DALI_LOG_INFO( gLogFilter, Debug::Concise, "\n" );
   DALI_LOG_INFO( gLogFilter, Debug::General, "Point(s): %d\n", event.GetPointCount() );
 
   Dali::RenderTask currentRenderTask;
 
-  for ( TouchPointContainerConstIterator iter = event.points.begin(), beginIter = event.points.begin(), endIter = event.points.end(); iter != endIter; ++iter )
+  for ( Integration::PointContainerConstIterator iter = event.points.begin(), beginIter = event.points.begin(), endIter = event.points.end(); iter != endIter; ++iter )
   {
     HitTestAlgorithm::Results hitTestResults;
-    HitTestAlgorithm::HitTest( stage, iter->screen, hitTestResults );
+    HitTestAlgorithm::HitTest( stage, iter->GetScreenPosition(), hitTestResults );
 
-    TouchPoint newPoint( iter->deviceId, iter->state, iter->screen.x, iter->screen.y );
-    newPoint.hitActor = hitTestResults.actor;
-    newPoint.local = hitTestResults.actorCoordinates;
+    Integration::Point newPoint( *iter );
+    newPoint.SetHitActor( hitTestResults.actor );
+    newPoint.SetLocalPosition( hitTestResults.actorCoordinates );
 
-    touchEvent.points.push_back( newPoint );
+    touchEvent.points.push_back( newPoint.GetTouchPoint() );
+    touchData->AddPoint( newPoint );
 
     DALI_LOG_INFO( gLogFilter, Debug::General, "  State(%s), Screen(%.0f, %.0f), HitActor(%p, %s), Local(%.2f, %.2f)\n",
-                   TOUCH_POINT_STATE[iter->state], iter->screen.x, iter->screen.y,
-                   ( hitTestResults.actor ? (void*)&hitTestResults.actor.GetBaseObject() : NULL ),
+                   TOUCH_POINT_STATE[iter->GetState()], iter->GetScreenPosition().x, iter->GetScreenPosition().y,
+                   ( hitTestResults.actor ? reinterpret_cast< void* >( &hitTestResults.actor.GetBaseObject() ) : NULL ),
                    ( hitTestResults.actor ? hitTestResults.actor.GetName().c_str() : "" ),
                    hitTestResults.actorCoordinates.x, hitTestResults.actorCoordinates.y );
 
@@ -239,17 +275,17 @@ void TouchEventProcessor::ProcessTouchEvent( const Integration::TouchEvent& even
   Dali::Actor consumedActor;
   if ( currentRenderTask )
   {
-    consumedActor = EmitTouchSignals( touchEvent.points[0].hitActor, touchEvent );
+    consumedActor = EmitTouchSignals( touchData->GetPoint( 0 ).GetHitActor(), touchEvent, touchDataHandle );
   }
 
-  TouchPoint& primaryPoint = touchEvent.points[0];
-  Dali::Actor primaryHitActor = primaryPoint.hitActor;
-  TouchPoint::State primaryPointState = primaryPoint.state;
+  Integration::Point& primaryPoint = touchData->GetPoint( 0 );
+  Dali::Actor primaryHitActor = primaryPoint.GetHitActor();
+  PointState::Type primaryPointState = primaryPoint.GetState();
 
-  DALI_LOG_INFO( gLogFilter, Debug::Concise, "PrimaryHitActor:     (%p) %s\n", primaryPoint.hitActor ? (void*)&primaryPoint.hitActor.GetBaseObject() : NULL, primaryPoint.hitActor ? primaryPoint.hitActor.GetName().c_str() : "" );
-  DALI_LOG_INFO( gLogFilter, Debug::Concise, "ConsumedActor:       (%p) %s\n", consumedActor ? (void*)&consumedActor.GetBaseObject() : NULL, consumedActor ? consumedActor.GetName().c_str() : "" );
+  DALI_LOG_INFO( gLogFilter, Debug::Concise, "PrimaryHitActor:     (%p) %s\n", primaryHitActor ? reinterpret_cast< void* >( &primaryHitActor.GetBaseObject() ) : NULL, primaryHitActor ? primaryHitActor.GetName().c_str() : "" );
+  DALI_LOG_INFO( gLogFilter, Debug::Concise, "ConsumedActor:       (%p) %s\n", consumedActor ? reinterpret_cast< void* >( &consumedActor.GetBaseObject() ) : NULL, consumedActor ? consumedActor.GetName().c_str() : "" );
 
-  if ( ( primaryPointState == TouchPoint::Down ) &&
+  if ( ( primaryPointState == PointState::DOWN ) &&
        ( touchEvent.GetPointCount() == 1 ) &&
        ( consumedActor && consumedActor.OnStage() ) )
   {
@@ -261,7 +297,7 @@ void TouchEventProcessor::ProcessTouchEvent( const Integration::TouchEvent& even
 
   Actor* lastPrimaryHitActor( mLastPrimaryHitActor.GetActor() );
   Actor* lastConsumedActor( mLastConsumedActor.GetActor() );
-  if( (primaryPointState == TouchPoint::Motion) || (primaryPointState == TouchPoint::Up) || (primaryPointState == TouchPoint::Stationary) )
+  if( ( primaryPointState == PointState::MOTION ) || ( primaryPointState == PointState::UP ) || ( primaryPointState == PointState::STATIONARY ) )
   {
     if ( mLastRenderTask )
     {
@@ -276,16 +312,16 @@ void TouchEventProcessor::ProcessTouchEvent( const Integration::TouchEvent& even
         {
           if ( lastPrimaryHitActor->GetLeaveRequired() )
           {
-            DALI_LOG_INFO( gLogFilter, Debug::Concise, "LeaveActor(Hit):     (%p) %s\n", (void*)lastPrimaryHitActor, lastPrimaryHitActor->GetName().c_str() );
-            leaveEventConsumer = EmitTouchSignals( mLastPrimaryHitActor.GetActor(), lastRenderTaskImpl, touchEvent, TouchPoint::Leave );
+            DALI_LOG_INFO( gLogFilter, Debug::Concise, "LeaveActor(Hit):     (%p) %s\n", reinterpret_cast< void* >( lastPrimaryHitActor ), lastPrimaryHitActor->GetName().c_str() );
+            leaveEventConsumer = EmitTouchSignals( mLastPrimaryHitActor.GetActor(), lastRenderTaskImpl, touchEvent, touchData, PointState::LEAVE );
           }
         }
         else
         {
           // At this point mLastPrimaryHitActor was touchable and sensitive in the previous touch event process but is not in the current one.
           // An interrupted event is send to allow some actors to go back to their original state (i.e. Button controls)
-          DALI_LOG_INFO( gLogFilter, Debug::Concise, "InterruptedActor(Hit):     (%p) %s\n", (void*)lastPrimaryHitActor, lastPrimaryHitActor->GetName().c_str() );
-          leaveEventConsumer = EmitTouchSignals( mLastPrimaryHitActor.GetActor(), lastRenderTaskImpl, touchEvent, TouchPoint::Interrupted );
+          DALI_LOG_INFO( gLogFilter, Debug::Concise, "InterruptedActor(Hit):     (%p) %s\n", reinterpret_cast< void* >( lastPrimaryHitActor ), lastPrimaryHitActor->GetName().c_str() );
+          leaveEventConsumer = EmitTouchSignals( mLastPrimaryHitActor.GetActor(), lastRenderTaskImpl, touchEvent, touchData, PointState::INTERRUPTED );
         }
       }
 
@@ -302,16 +338,16 @@ void TouchEventProcessor::ProcessTouchEvent( const Integration::TouchEvent& even
         {
           if( lastConsumedActor->GetLeaveRequired() )
           {
-            DALI_LOG_INFO( gLogFilter, Debug::Concise, "LeaveActor(Consume): (%p) %s\n", (void*)lastConsumedActor, lastConsumedActor->GetName().c_str() );
-            EmitTouchSignals( lastConsumedActor, lastRenderTaskImpl, touchEvent, TouchPoint::Leave );
+            DALI_LOG_INFO( gLogFilter, Debug::Concise, "LeaveActor(Consume): (%p) %s\n", reinterpret_cast< void* >( lastConsumedActor ), lastConsumedActor->GetName().c_str() );
+            EmitTouchSignals( lastConsumedActor, lastRenderTaskImpl, touchEvent, touchData, PointState::LEAVE );
           }
         }
         else
         {
           // At this point mLastConsumedActor was touchable and sensitive in the previous touch event process but is not in the current one.
           // An interrupted event is send to allow some actors to go back to their original state (i.e. Button controls)
-          DALI_LOG_INFO( gLogFilter, Debug::Concise, "InterruptedActor(Consume):     (%p) %s\n", (void*)lastConsumedActor, lastConsumedActor->GetName().c_str() );
-          EmitTouchSignals( mLastConsumedActor.GetActor(), lastRenderTaskImpl, touchEvent, TouchPoint::Interrupted );
+          DALI_LOG_INFO( gLogFilter, Debug::Concise, "InterruptedActor(Consume):     (%p) %s\n", reinterpret_cast< void* >( lastConsumedActor ), lastConsumedActor->GetName().c_str() );
+          EmitTouchSignals( mLastConsumedActor.GetActor(), lastRenderTaskImpl, touchEvent, touchData, PointState::INTERRUPTED );
         }
       }
     }
@@ -320,7 +356,7 @@ void TouchEventProcessor::ProcessTouchEvent( const Integration::TouchEvent& even
   // 5) If our primary point is an Up event, then the primary point (in multi-touch) will change next
   //    time so set our last primary actor to NULL.  Do the same to the last consumed actor as well.
 
-  if ( primaryPointState == TouchPoint::Up )
+  if ( primaryPointState == PointState::UP )
   {
     mLastPrimaryHitActor.SetActor( NULL );
     mLastConsumedActor.SetActor( NULL );
@@ -360,7 +396,7 @@ void TouchEventProcessor::ProcessTouchEvent( const Integration::TouchEvent& even
   {
     switch ( primaryPointState )
     {
-      case TouchPoint::Up:
+      case PointState::UP:
       {
         Actor* touchDownConsumedActor( mTouchDownConsumedActor.GetActor() );
         if ( touchDownConsumedActor &&
@@ -369,30 +405,28 @@ void TouchEventProcessor::ProcessTouchEvent( const Integration::TouchEvent& even
              touchDownConsumedActor != lastConsumedActor )
         {
           Dali::Actor touchDownConsumedActorHandle( touchDownConsumedActor );
-          touchEvent.points[0].hitActor = touchDownConsumedActorHandle;
-          touchEvent.points[0].state = TouchPoint::Interrupted;
-          EmitTouchSignals( touchDownConsumedActorHandle, touchEvent );
 
-          // Restore touch-event to original state
-          touchEvent.points[0].hitActor = primaryHitActor;
-          touchEvent.points[0].state = primaryPointState;
+          Integration::Point currentPoint = touchData->GetPoint( 0 );
+          currentPoint.SetHitActor( touchDownConsumedActorHandle );
+          currentPoint.SetState( PointState::INTERRUPTED );
+
+          AllocAndEmitTouchSignals( event.time, touchDownConsumedActorHandle, currentPoint );
         }
 
         mTouchDownConsumedActor.SetActor( NULL );
       }
       // No break, Fallthrough
 
-      case TouchPoint::Down:
+      case PointState::DOWN:
       {
-        mStage.EmitTouchedSignal( touchEvent );
+        mStage.EmitTouchedSignal( touchEvent, touchDataHandle );
         break;
       }
 
-      case TouchPoint::Motion:
-      case TouchPoint::Leave:
-      case TouchPoint::Stationary:
-      case TouchPoint::Interrupted:
-      case TouchPoint::Last:
+      case PointState::MOTION:
+      case PointState::LEAVE:
+      case PointState::STATIONARY:
+      case PointState::INTERRUPTED:
       {
         // Ignore
         break;
@@ -406,15 +440,23 @@ void TouchEventProcessor::OnObservedActorDisconnected( Actor* actor )
   if ( actor == mLastPrimaryHitActor.GetActor() )
   {
     Dali::Actor handle( actor );
+
+    Integration::Point point;
+    point.SetState( PointState::INTERRUPTED );
+    point.SetHitActor( handle );
+
+    TouchDataPtr touchData( new TouchData );
+    touchData->AddPoint( point );
+    Dali::TouchData touchDataHandle( touchData.Get() );
+
     TouchEvent touchEvent( 0 );
-    touchEvent.points.push_back( TouchPoint( 0, TouchPoint::Interrupted, 0.0f, 0.0f ) );
-    touchEvent.points[0].hitActor = handle;
+    touchEvent.points.push_back( point.GetTouchPoint() );
 
-    Dali::Actor eventConsumer = EmitTouchSignals( handle, touchEvent );
+    Dali::Actor eventConsumer = EmitTouchSignals( handle, touchEvent, touchDataHandle );
 
     if ( mLastConsumedActor.GetActor() != eventConsumer )
     {
-      EmitTouchSignals( Dali::Actor( mLastConsumedActor.GetActor() ), touchEvent );
+      EmitTouchSignals( Dali::Actor( mLastConsumedActor.GetActor() ), touchEvent, touchDataHandle );
     }
 
     // Do not set mLastPrimaryHitActor to NULL we may be iterating through its observers