/*
- * 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.
#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/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
namespace
{
-bool IsActuallySensitive( Actor* actor );
-
#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",
};
-static const Debug::LogLevel HIERARCHY_DEBUG_LOG_LEVEL( Debug::Verbose );
-
-static bool HIERARCHY_GEOMETRY( false );
-static bool HIERARCHY_SENSITIVITY( false );
-static bool HIERARCHY_TOUCH_REQUIRED( false );
-static bool HIERARCHY_HITTABLE( false );
-
-/**
- * Prints out all the children of the given actor when debug is enabled.
- *
- * @param[in] actor The actor whose children to print.
- * @param[in] level The number of " | " to put in front of the children.
- */
-void PrintChildren( Dali::Actor actor, int level )
-{
- std::ostringstream output;
-
- for ( int t = 0; t < level; ++t )
- {
- output << " | ";
- }
-
- output << actor.GetName() << "(" << actor.GetTypeName() << ", " << actor.GetObjectPtr() << ")";
-
- if ( HIERARCHY_GEOMETRY )
- {
- output << " Pos: " << actor.GetCurrentWorldPosition() << " Size: " << actor.GetCurrentSize() << " Scale: " << actor.GetCurrentWorldScale();
- }
-
- if ( HIERARCHY_SENSITIVITY )
- {
- output << " Sensitivity: " << ( IsActuallySensitive( &GetImplementation( actor ) ) ? "True " : "False " );
- }
-
- if ( HIERARCHY_TOUCH_REQUIRED )
- {
- output << " TouchRequired: " << ( GetImplementation(actor).GetTouchRequired() ? "True " : "False " );
- }
-
- if ( HIERARCHY_HITTABLE )
- {
- output << " Hittable: " << ( GetImplementation(actor).IsHittable() ? "True " : "False " );
- }
-
- output << std::endl;
-
- DALI_LOG_INFO( gLogFilter, HIERARCHY_DEBUG_LOG_LEVEL, output.str().c_str() );
-
- ++level;
- unsigned int numChildren=actor.GetChildCount();
- for ( unsigned int i=0; i<numChildren; ++i )
- {
- PrintChildren( actor.GetChildAt(i), level );
- }
- --level;
-}
-
-/**
- * Prints the entire hierarchy of the scene.
- */
-void PrintHierarchy()
-{
- if ( gLogFilter->IsEnabledFor( HIERARCHY_DEBUG_LOG_LEVEL ) )
- {
- PrintChildren( Dali::Stage().GetCurrent().GetRootLayer(), 0 );
- }
-}
-
-#define PRINT_HIERARCHY PrintHierarchy()
-
-#else // defined(DEBUG_ENABLED)
-
-#define PRINT_HIERARCHY
-
#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;
}
-/**
- * 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 AllocAndEmitTouchSignals( unsigned long time, Dali::Actor actor, const Integration::Point& point )
{
- TouchEvent touchEvent( originalEvent );
- TouchPoint& primaryPoint = touchEvent.points[0];
-
- actor->ScreenToLocal( renderTask, primaryPoint.local.x, primaryPoint.local.y, primaryPoint.screen.x, primaryPoint.screen.y );
+ TouchEvent touchEvent( time );
+ TouchDataPtr touchData( new TouchData( time ) );
+ Dali::TouchData touchDataHandle( touchData.Get() );
- primaryPoint.hitActor = actor;
- primaryPoint.state = state;
+ touchEvent.points.push_back( point.GetTouchPoint() );
+ touchData->AddPoint( point );
- return EmitTouchSignals( Dali::Actor(actor), touchEvent );
+ return EmitTouchSignals( actor, touchEvent, touchDataHandle );
}
+
/**
- * In the hit test algorithm above we do not descend actor tree if it is insensitive, so here, we
- * should also check if any of the actor's parents has become insensitive since we last processed
- * it.
+ * Changes the state of the primary point to leave and emits the touch signals
*/
-bool IsActuallySensitive( Actor* actor )
+Dali::Actor EmitTouchSignals( Actor* actor, RenderTask& renderTask, const TouchEvent& originalEvent, const TouchDataPtr& originalTouchData, PointState::Type state )
{
- bool sensitive = true;
+ Dali::Actor consumingActor;
- while ( actor && sensitive )
+ if( actor )
{
- sensitive = actor->IsSensitive();
- actor = actor->GetParent();
+ 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 );
+
+ primaryPoint.SetLocalPosition( localPosition );
+ primaryPoint.SetHitActor( Dali::Actor( actor ) );
+ primaryPoint.SetState( state );
+
+ TouchEvent touchEvent( originalEvent );
+ touchEvent.points[0] = primaryPoint.GetTouchPoint();
+
+ consumingActor = EmitTouchSignals( Dali::Actor(actor), touchEvent, Dali::TouchData( touchData.Get() ) );
}
- return sensitive;
+ return consumingActor;
}
} // unnamed namespace
TouchEventProcessor::TouchEventProcessor( Stage& stage )
: mStage( stage ),
- mLastPrimaryHitActor(),
+ mLastPrimaryHitActor( MakeCallback( this, &TouchEventProcessor::OnObservedActorDisconnected ) ),
mLastConsumedActor(),
mTouchDownConsumedActor(),
mLastRenderTask()
Stage& stage = mStage;
- PRINT_HIERARCHY;
-
- // Copy so we can add the results of a hit-test.
- TouchEvent touchEvent( event.time );
+ PRINT_HIERARCHY(gLogFilter);
// 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 );
+
+ 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 );
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 ( 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 );
+
+ 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;
}
}
-TouchEventProcessor::ActorObserver::ActorObserver()
-: mActor ( NULL ),
- mActorDisconnected(false)
+void TouchEventProcessor::OnObservedActorDisconnected( Actor* actor )
{
- DALI_LOG_TRACE_METHOD( gLogFilter );
-}
-
-TouchEventProcessor::ActorObserver::~ActorObserver()
-{
- DALI_LOG_TRACE_METHOD( gLogFilter );
- SetActor( NULL );
-}
+ if ( actor == mLastPrimaryHitActor.GetActor() )
+ {
+ Dali::Actor handle( actor );
-Actor* TouchEventProcessor::ActorObserver::GetActor()
-{
- return mActorDisconnected ? NULL : mActor;
-}
+ Integration::Point point;
+ point.SetState( PointState::INTERRUPTED );
+ point.SetHitActor( handle );
-void TouchEventProcessor::ActorObserver::SetActor( Actor* actor )
-{
- DALI_LOG_TRACE_METHOD( gLogFilter );
+ TouchDataPtr touchData( new TouchData );
+ touchData->AddPoint( point );
+ Dali::TouchData touchDataHandle( touchData.Get() );
- if ( mActor != actor )
- {
- ResetActor();
+ TouchEvent touchEvent( 0 );
+ touchEvent.points.push_back( point.GetTouchPoint() );
- mActor = actor;
+ Dali::Actor eventConsumer = EmitTouchSignals( handle, touchEvent, touchDataHandle );
- if ( mActor )
+ if ( mLastConsumedActor.GetActor() != eventConsumer )
{
- mActor->AddObserver( *this );
- DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Start Observing: %p\n", mActor);
+ EmitTouchSignals( Dali::Actor( mLastConsumedActor.GetActor() ), touchEvent, touchDataHandle );
}
- }
-}
-void TouchEventProcessor::ActorObserver::ResetActor()
-{
- if ( mActor )
- {
- DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Stop Observing: %p\n", mActor);
- mActor->RemoveObserver( *this );
- mActor = NULL;
- mActorDisconnected = false;
- }
-}
+ // Do not set mLastPrimaryHitActor to NULL we may be iterating through its observers
-void TouchEventProcessor::ActorObserver::SceneObjectRemoved( ProxyObject& proxy )
-{
- DALI_LOG_TRACE_METHOD( gLogFilter );
-
- if ( mActor == &proxy )
- {
- // do not call proxy.RemoveObserver here, proxy is currently iterating through observers... you wouldnt want to upset proxy now would you?
- mActorDisconnected = true;
- }
-}
-
-void TouchEventProcessor::ActorObserver::ProxyDestroyed(ProxyObject& proxy)
-{
- DALI_LOG_TRACE_METHOD( gLogFilter );
-
- if ( mActor == &proxy )
- {
- DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Stop Observing: %p\n", mActor);
- mActor = NULL;
+ mLastConsumedActor.SetActor( NULL );
+ mLastRenderTask.Reset();
}
}