X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fevent%2Fevents%2Flong-press-gesture%2Flong-press-gesture-processor.cpp;h=19b772db844712ccfca75ca603c6ecc6e1f09e7c;hb=HEAD;hp=961b1baf7286ea108d3d67f633aaff821e2f3299;hpb=995a0901d56c687ea085bf86c103cfbc4c19ad23;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/event/events/long-press-gesture/long-press-gesture-processor.cpp b/dali/internal/event/events/long-press-gesture/long-press-gesture-processor.cpp index 961b1ba..32535ec 100644 --- a/dali/internal/event/events/long-press-gesture/long-press-gesture-processor.cpp +++ b/dali/internal/event/events/long-press-gesture/long-press-gesture-processor.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -22,26 +22,25 @@ #include // INTERNAL INCLUDES -#include -#include -#include -#include #include +#include #include #include -#include -#include #include +#include +#include +#include +#include +#include +#include namespace Dali { - namespace Internal { - namespace { - +DALI_INIT_TRACE_FILTER(gTraceFilter, DALI_TRACE_PERFORMANCE_MARKER, false); const unsigned long DEFAULT_MINIMUM_HOLDING_TIME = 500u; /** @@ -52,23 +51,33 @@ const unsigned long DEFAULT_MINIMUM_HOLDING_TIME = 500u; * @param[in] localPoint Relative to the actor attached to the detector. */ void EmitLongPressSignal( - Actor* actor, - const GestureDetectorContainer& gestureDetectors, - const LongPressGestureEvent& longPressEvent, - Vector2 localPoint) + Actor* actor, + const GestureDetectorContainer& gestureDetectors, + const LongPressGestureEvent& longPressEvent, + Vector2 localPoint) { - LongPressGesture longPress(longPressEvent.state); - longPress.time = longPressEvent.time; - longPress.numberOfTouches = longPressEvent.numberOfTouches; - longPress.screenPoint = longPressEvent.point; - longPress.localPoint = localPoint; - - Dali::Actor actorHandle( actor ); + Internal::LongPressGesturePtr longPress(new Internal::LongPressGesture(longPressEvent.state)); + longPress->SetTime(longPressEvent.time); + longPress->SetNumberOfTouches(longPressEvent.numberOfTouches); + longPress->SetScreenPoint(longPressEvent.point); + longPress->SetLocalPoint(localPoint); + longPress->SetSourceType(longPressEvent.sourceType); + longPress->SetSourceData(longPressEvent.sourceData); + + DALI_TRACE_BEGIN_WITH_MESSAGE_GENERATOR(gTraceFilter, "DALI_EMIT_LONG_PRESS_GESTURE_SIGNAL", [&](std::ostringstream& oss) { + oss << "[" << gestureDetectors.size() << "]"; + }); + + Dali::Actor actorHandle(actor); const GestureDetectorContainer::const_iterator endIter = gestureDetectors.end(); - for ( GestureDetectorContainer::const_iterator iter = gestureDetectors.begin(); iter != endIter; ++iter ) + for(GestureDetectorContainer::const_iterator iter = gestureDetectors.begin(); iter != endIter; ++iter) { - static_cast< LongPressGestureDetector* >( *iter )->EmitLongPressGestureSignal( actorHandle, longPress ); + static_cast(*iter)->EmitLongPressGestureSignal(actorHandle, Dali::LongPressGesture(longPress.Get())); } + + DALI_TRACE_END_WITH_MESSAGE_GENERATOR(gTraceFilter, "DALI_EMIT_LONG_PRESS_GESTURE_SIGNAL", [&](std::ostringstream& oss) { + oss << "[" << gestureDetectors.size() << "]"; + }); } /** @@ -81,8 +90,8 @@ struct IsNotAttachedFunctor * Constructor * @param[in] actor The actor to check whether it is attached. */ - IsNotAttachedFunctor( Actor* actor ) - : actorToCheck( actor ) + IsNotAttachedFunctor(Actor* actor) + : actorToCheck(actor) { } @@ -91,9 +100,9 @@ struct IsNotAttachedFunctor * @param[in] detector The detector to check. * @return true, if not attached, false otherwise. */ - bool operator()( const GestureDetector* detector ) const + bool operator()(const GestureDetector* detector) const { - return !detector->IsAttached( *actorToCheck ); + return !detector->IsAttached(*actorToCheck); } Actor* actorToCheck; ///< The actor to check whether it is attached or not. @@ -102,55 +111,54 @@ struct IsNotAttachedFunctor } // unnamed namespace LongPressGestureProcessor::LongPressGestureProcessor() -: GestureProcessor( Gesture::LongPress ), +: GestureProcessor(GestureType::LONG_PRESS), mLongPressGestureDetectors(), mCurrentEmitters(), mCurrentRenderTask(), - mMinTouchesRequired( 1 ), - mMaxTouchesRequired( 1 ), - mCurrentLongPressEvent( NULL ), - mMinimumHoldingTime( DEFAULT_MINIMUM_HOLDING_TIME ) + mMinTouchesRequired(1), + mMaxTouchesRequired(1), + mCurrentLongPressEvent(nullptr), + mMinimumHoldingTime(DEFAULT_MINIMUM_HOLDING_TIME) { } -LongPressGestureProcessor::~LongPressGestureProcessor() -{ -} +LongPressGestureProcessor::~LongPressGestureProcessor() = default; -void LongPressGestureProcessor::Process( Scene& scene, const LongPressGestureEvent& longPressEvent ) +void LongPressGestureProcessor::Process(Scene& scene, const LongPressGestureEvent& longPressEvent) { - switch ( longPressEvent.state ) + DALI_TRACE_SCOPE(gTraceFilter, "DALI_PROCESS_LONG_PRESS_GESTURE"); + switch(longPressEvent.state) { - case Gesture::Possible: + case GestureState::POSSIBLE: { mCurrentEmitters.clear(); ResetActor(); HitTestAlgorithm::Results hitTestResults; - if( HitTest( scene, longPressEvent.point, hitTestResults ) ) + if(HitTest(scene, longPressEvent.point, hitTestResults)) { - SetActor( &GetImplementation( hitTestResults.actor ) ); + SetActor(&GetImplementation(hitTestResults.actor)); } break; } - case Gesture::Started: + case GestureState::STARTED: { Actor* currentGesturedActor = GetCurrentGesturedActor(); - if ( currentGesturedActor ) + if(currentGesturedActor) { HitTestAlgorithm::Results hitTestResults; - HitTest( scene, longPressEvent.point, hitTestResults ); + HitTest(scene, longPressEvent.point, hitTestResults); - if ( hitTestResults.actor && ( currentGesturedActor == &GetImplementation( hitTestResults.actor ) ) ) + if(hitTestResults.actor && (currentGesturedActor == &GetImplementation(hitTestResults.actor))) { // Record the current render-task for Screen->Actor coordinate conversions mCurrentRenderTask = hitTestResults.renderTask; // Set mCurrentLongPressEvent to use inside overridden methods called from ProcessAndEmit() mCurrentLongPressEvent = &longPressEvent; - ProcessAndEmit( hitTestResults ); - mCurrentLongPressEvent = NULL; + ProcessAndEmit(hitTestResults); + mCurrentLongPressEvent = nullptr; } else { @@ -161,7 +169,7 @@ void LongPressGestureProcessor::Process( Scene& scene, const LongPressGestureEve break; } - case Gesture::Finished: + case GestureState::FINISHED: { // The gesture should only be sent to the gesture detector which first received it so that it // can be told when the gesture ends as well. @@ -170,21 +178,21 @@ void LongPressGestureProcessor::Process( Scene& scene, const LongPressGestureEve // Check if actor is still touchable. Actor* currentGesturedActor = GetCurrentGesturedActor(); - if ( currentGesturedActor ) + if(currentGesturedActor) { - if ( currentGesturedActor->IsHittable() && !mCurrentEmitters.empty() && mCurrentRenderTask ) + if(currentGesturedActor->IsHittable() && !mCurrentEmitters.empty() && mCurrentRenderTask) { // Ensure actor is still attached to the emitters, if it is not then remove the emitter. - GestureDetectorContainer::iterator endIter = std::remove_if( mCurrentEmitters.begin(), mCurrentEmitters.end(), IsNotAttachedFunctor(currentGesturedActor) ); - mCurrentEmitters.erase( endIter, mCurrentEmitters.end() ); + GestureDetectorContainer::iterator endIter = std::remove_if(mCurrentEmitters.begin(), mCurrentEmitters.end(), IsNotAttachedFunctor(currentGesturedActor)); + mCurrentEmitters.erase(endIter, mCurrentEmitters.end()); - if ( !mCurrentEmitters.empty() ) + if(!mCurrentEmitters.empty()) { - Vector2 actorCoords; + Vector2 actorCoords; RenderTask& renderTaskImpl = *mCurrentRenderTask.Get(); - currentGesturedActor->ScreenToLocal( renderTaskImpl, actorCoords.x, actorCoords.y, longPressEvent.point.x, longPressEvent.point.y ); + currentGesturedActor->ScreenToLocal(renderTaskImpl, actorCoords.x, actorCoords.y, longPressEvent.point.x, longPressEvent.point.y); - EmitLongPressSignal( currentGesturedActor, mCurrentEmitters, longPressEvent, actorCoords ); + EmitLongPressSignal(currentGesturedActor, mCurrentEmitters, longPressEvent, actorCoords); } } @@ -195,34 +203,34 @@ void LongPressGestureProcessor::Process( Scene& scene, const LongPressGestureEve break; } - case Gesture::Cancelled: + case GestureState::CANCELLED: { mCurrentEmitters.clear(); ResetActor(); break; } - case Gesture::Continuing: + case GestureState::CONTINUING: { - DALI_ABORT( "Incorrect state received from Integration layer: Continuing\n" ); + DALI_ABORT("Incorrect state received from Integration layer: CONTINUING\n"); break; } - case Gesture::Clear: + case GestureState::CLEAR: { - DALI_ABORT( "Incorrect state received from Integration layer: Clear\n" ); + DALI_ABORT("Incorrect state received from Integration layer: CLEAR\n"); break; } } } -void LongPressGestureProcessor::AddGestureDetector( LongPressGestureDetector* gestureDetector, Scene& scene ) +void LongPressGestureProcessor::AddGestureDetector(LongPressGestureDetector* gestureDetector, Scene& scene) { bool firstRegistration(mLongPressGestureDetectors.empty()); mLongPressGestureDetectors.push_back(gestureDetector); - if (firstRegistration) + if(firstRegistration) { mMinTouchesRequired = gestureDetector->GetMinimumTouchesRequired(); mMaxTouchesRequired = gestureDetector->GetMaximumTouchesRequired(); @@ -233,7 +241,7 @@ void LongPressGestureProcessor::AddGestureDetector( LongPressGestureDetector* ge Size size = scene.GetSize(); - mGestureRecognizer = new LongPressGestureRecognizer(*this, Vector2(size.width, size.height), static_cast(request), mMinimumHoldingTime ); + mGestureRecognizer = new LongPressGestureRecognizer(*this, Vector2(size.width, size.height), static_cast(request), mMinimumHoldingTime); } else { @@ -241,16 +249,16 @@ void LongPressGestureProcessor::AddGestureDetector( LongPressGestureDetector* ge } } -void LongPressGestureProcessor::RemoveGestureDetector( LongPressGestureDetector* gestureDetector ) +void LongPressGestureProcessor::RemoveGestureDetector(LongPressGestureDetector* gestureDetector) { // Find detector ... - LongPressGestureDetectorContainer::iterator endIter = std::remove( mLongPressGestureDetectors.begin(), mLongPressGestureDetectors.end(), gestureDetector ); - DALI_ASSERT_DEBUG( endIter != mLongPressGestureDetectors.end() ); + LongPressGestureDetectorContainer::iterator endIter = std::remove(mLongPressGestureDetectors.begin(), mLongPressGestureDetectors.end(), gestureDetector); + DALI_ASSERT_DEBUG(endIter != mLongPressGestureDetectors.end()); // ... and remove it - mLongPressGestureDetectors.erase( endIter, mLongPressGestureDetectors.end() ); + mLongPressGestureDetectors.erase(endIter, mLongPressGestureDetectors.end()); - if ( mLongPressGestureDetectors.empty() ) + if(mLongPressGestureDetectors.empty()) { mGestureRecognizer = nullptr; } @@ -260,25 +268,25 @@ void LongPressGestureProcessor::RemoveGestureDetector( LongPressGestureDetector* } } -void LongPressGestureProcessor::GestureDetectorUpdated( LongPressGestureDetector* gestureDetector ) +void LongPressGestureProcessor::GestureDetectorUpdated(LongPressGestureDetector* gestureDetector) { - DALI_ASSERT_DEBUG( find( mLongPressGestureDetectors.begin(), mLongPressGestureDetectors.end(), gestureDetector ) != mLongPressGestureDetectors.end() ); + DALI_ASSERT_DEBUG(find(mLongPressGestureDetectors.begin(), mLongPressGestureDetectors.end(), gestureDetector) != mLongPressGestureDetectors.end()); UpdateDetection(); } -void LongPressGestureProcessor::SetMinimumHoldingTime( uint32_t time ) +void LongPressGestureProcessor::SetMinimumHoldingTime(uint32_t time) { - if( time > 0u && mMinimumHoldingTime != time ) + if(time > 0u && mMinimumHoldingTime != time) { mMinimumHoldingTime = time; - if( mGestureRecognizer ) + if(mGestureRecognizer) { - LongPressGestureRecognizer* longPressRecognizer = dynamic_cast( mGestureRecognizer.Get() ); - if( longPressRecognizer ) + LongPressGestureRecognizer* longPressRecognizer = dynamic_cast(mGestureRecognizer.Get()); + if(longPressRecognizer) { - longPressRecognizer->SetMinimumHoldingTime( time ); + longPressRecognizer->SetMinimumHoldingTime(time); } } } @@ -296,27 +304,27 @@ void LongPressGestureProcessor::UpdateDetection() unsigned int minimumRequired = UINT_MAX; unsigned int maximumRequired = 0; - for ( LongPressGestureDetectorContainer::iterator iter = mLongPressGestureDetectors.begin(), endIter = mLongPressGestureDetectors.end(); iter != endIter; ++iter ) + for(LongPressGestureDetectorContainer::iterator iter = mLongPressGestureDetectors.begin(), endIter = mLongPressGestureDetectors.end(); iter != endIter; ++iter) { LongPressGestureDetector* current(*iter); - if( current ) + if(current) { unsigned int minimum = current->GetMinimumTouchesRequired(); - if (minimum < minimumRequired) + if(minimum < minimumRequired) { minimumRequired = minimum; } unsigned int maximum = current->GetMaximumTouchesRequired(); - if ( maximum > maximumRequired ) + if(maximum > maximumRequired) { maximumRequired = maximum; } } } - if ( (minimumRequired != mMinTouchesRequired) || (maximumRequired != mMaxTouchesRequired) ) + if((minimumRequired != mMinTouchesRequired) || (maximumRequired != mMaxTouchesRequired)) { mMinTouchesRequired = minimumRequired; mMaxTouchesRequired = maximumRequired; @@ -333,29 +341,30 @@ void LongPressGestureProcessor::OnGesturedActorStageDisconnection() mCurrentEmitters.clear(); } -bool LongPressGestureProcessor::CheckGestureDetector( GestureDetector* detector, Actor* actor ) +bool LongPressGestureProcessor::CheckGestureDetector(GestureDetector* detector, Actor* actor) { - DALI_ASSERT_DEBUG( mCurrentLongPressEvent ); - - LongPressGestureDetector* longPressDetector ( static_cast< LongPressGestureDetector* >( detector ) ); - - return ( longPressDetector->GetMinimumTouchesRequired() <= mCurrentLongPressEvent->numberOfTouches ) && - ( longPressDetector->GetMaximumTouchesRequired() >= mCurrentLongPressEvent->numberOfTouches ); + DALI_ASSERT_DEBUG(mCurrentLongPressEvent); + bool ret = false; + if(detector) + { + ret = detector->CheckGestureDetector(mCurrentLongPressEvent, actor, mCurrentRenderTask); + } + return ret; } -void LongPressGestureProcessor::EmitGestureSignal( Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates ) +void LongPressGestureProcessor::EmitGestureSignal(Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates) { - DALI_ASSERT_DEBUG( mCurrentLongPressEvent ); + DALI_ASSERT_DEBUG(mCurrentLongPressEvent); mCurrentEmitters.clear(); ResetActor(); - EmitLongPressSignal( actor, gestureDetectors, *mCurrentLongPressEvent, actorCoordinates ); + EmitLongPressSignal(actor, gestureDetectors, *mCurrentLongPressEvent, actorCoordinates); - if ( actor->OnStage() ) + if(actor->OnScene()) { mCurrentEmitters = gestureDetectors; - SetActor( actor ); + SetActor(actor); } }