/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
#endif
// INTERNAL INCLUDES
-#include <dali/public-api/actors/renderable-actor.h>
+#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>
#include <dali/integration-api/events/touch-event-integ.h>
#include <dali/internal/event/actors/actor-impl.h>
#include <dali/internal/event/actors/layer-impl.h>
-#include <dali/internal/event/common/stage-impl.h>
+#include <dali/internal/event/common/scene-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
#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;
// 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 )
(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 );
}
}
}
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
-TouchEventProcessor::TouchEventProcessor( Stage& stage )
-: mStage( stage ),
- mLastPrimaryHitActor(),
+TouchEventProcessor::TouchEventProcessor( Scene& scene )
+: mScene( scene ),
+ mLastPrimaryHitActor( MakeCallback( this, &TouchEventProcessor::OnObservedActorDisconnected ) ),
mLastConsumedActor(),
mTouchDownConsumedActor(),
mLastRenderTask()
void TouchEventProcessor::ProcessTouchEvent( const Integration::TouchEvent& event )
{
DALI_LOG_TRACE_METHOD( gLogFilter );
-
DALI_ASSERT_ALWAYS( !event.points.empty() && "Empty TouchEvent sent from Integration\n" );
- Stage& stage = mStage;
-
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).
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
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 );
mTouchDownConsumedActor.SetActor( NULL );
mLastRenderTask.Reset();
- touchEvent.points[0].hitActor = NULL;
- 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 );
+ mScene.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;
+ RenderTaskPtr 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( mScene.GetSize(), mScene.GetRenderTaskList(), mScene.GetLayerList(), 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 );
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() ) )
{
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 )
+ if( mLastRenderTask )
{
Dali::Actor leaveEventConsumer;
- RenderTask& lastRenderTaskImpl( GetImplementation( mLastRenderTask ) );
+ RenderTask& lastRenderTaskImpl = *mLastRenderTask.Get();
if( lastPrimaryHitActor &&
lastPrimaryHitActor != primaryHitActor &&
{
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 );
}
}
{
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 );
}
}
}
// 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 );
{
switch ( primaryPointState )
{
- case TouchPoint::Up:
+ case PointState::UP:
{
Actor* touchDownConsumedActor( mTouchDownConsumedActor.GetActor() );
if ( touchDownConsumedActor &&
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 );
+ mScene.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;
}
}
+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( point.GetTouchPoint() );
+
+ Dali::Actor eventConsumer = EmitTouchSignals( handle, touchEvent, touchDataHandle );
+
+ if ( mLastConsumedActor.GetActor() != eventConsumer )
+ {
+ EmitTouchSignals( Dali::Actor( mLastConsumedActor.GetActor() ), touchEvent, touchDataHandle );
+ }
+
+ // Do not set mLastPrimaryHitActor to NULL we may be iterating through its observers
+
+ mLastConsumedActor.SetActor( NULL );
+ mLastRenderTask.Reset();
+ }
+}
+
} // namespace Internal
} // namespace Dali