/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
#include <cstring> // for strcmp
// INTERNAL INCLUDES
-#include <dali/public-api/events/tap-gesture.h>
-#include <dali/public-api/object/type-registry.h>
#include <dali/integration-api/debug.h>
+#include <dali/integration-api/platform-abstraction.h>
+#include <dali/internal/event/common/thread-local-storage.h>
#include <dali/internal/event/events/gesture-event-processor.h>
+#include <dali/internal/event/events/tap-gesture/tap-gesture-impl.h>
+#include <dali/public-api/events/tap-gesture.h>
+#include <dali/public-api/object/type-registry.h>
namespace Dali
{
-
namespace Internal
{
-
namespace
{
-
-const unsigned int DEFAULT_TAPS_REQUIRED = 1u;
-const unsigned int DEFAULT_TOUCHES_REQUIRED = 1u;
+constexpr uint32_t DEFAULT_TAPS_REQUIRED = 1u;
+constexpr uint32_t DEFAULT_TOUCHES_REQUIRED = 1u;
+constexpr uint32_t DEFAULT_TAP_WAIT_TIME = 330u;
// Signals
const char* const SIGNAL_TAP_DETECTED = "tapDetected";
return Dali::TapGestureDetector::New();
}
-TypeRegistration mType( typeid(Dali::TapGestureDetector), typeid(Dali::GestureDetector), Create );
+TypeRegistration mType(typeid(Dali::TapGestureDetector), typeid(Dali::GestureDetector), Create);
-SignalConnectorType signalConnector1( mType, SIGNAL_TAP_DETECTED, &TapGestureDetector::DoConnectSignal );
+SignalConnectorType signalConnector1(mType, SIGNAL_TAP_DETECTED, &TapGestureDetector::DoConnectSignal);
-}
+} // namespace
TapGestureDetectorPtr TapGestureDetector::New()
{
return new TapGestureDetector;
}
-TapGestureDetectorPtr TapGestureDetector::New( unsigned int tapsRequired )
+TapGestureDetectorPtr TapGestureDetector::New(unsigned int tapsRequired)
{
- return new TapGestureDetector( tapsRequired );
+ return new TapGestureDetector(tapsRequired);
}
TapGestureDetector::TapGestureDetector()
-: GestureDetector( GestureType::TAP ),
- mMinimumTapsRequired( DEFAULT_TAPS_REQUIRED ),
- mMaximumTapsRequired( DEFAULT_TAPS_REQUIRED ),
- mTouchesRequired( DEFAULT_TOUCHES_REQUIRED )
+: GestureDetector(GestureType::TAP),
+ mMinimumTapsRequired(DEFAULT_TAPS_REQUIRED),
+ mMaximumTapsRequired(DEFAULT_TAPS_REQUIRED),
+ mTouchesRequired(DEFAULT_TOUCHES_REQUIRED),
+ mTimerId(0),
+ mTappedActor(),
+ mTap(),
+ mReceiveAllTapEvents(false)
{
}
-TapGestureDetector::TapGestureDetector( unsigned int tapsRequired )
-: GestureDetector( GestureType::TAP ),
- mMinimumTapsRequired( tapsRequired ),
- mMaximumTapsRequired( tapsRequired ),
- mTouchesRequired( DEFAULT_TOUCHES_REQUIRED )
+TapGestureDetector::TapGestureDetector(unsigned int tapsRequired)
+: GestureDetector(GestureType::TAP),
+ mMinimumTapsRequired(tapsRequired),
+ mMaximumTapsRequired(tapsRequired),
+ mTouchesRequired(DEFAULT_TOUCHES_REQUIRED),
+ mTimerId(0),
+ mTappedActor(),
+ mTap()
{
}
-TapGestureDetector::~TapGestureDetector() = default;
+TapGestureDetector::~TapGestureDetector()
+{
+ if(mTimerId != 0 && ThreadLocalStorage::Created())
+ {
+ Dali::Integration::PlatformAbstraction& platformAbstraction = ThreadLocalStorage::Get().GetPlatformAbstraction();
+ platformAbstraction.CancelTimer(mTimerId);
+ }
+}
void TapGestureDetector::SetMinimumTapsRequired(unsigned int taps)
{
- if ( mMinimumTapsRequired != taps )
+ if(mMinimumTapsRequired != taps)
{
mMinimumTapsRequired = taps;
- if ( !mAttachedActors.empty() )
+ if(!mAttachedActors.empty())
{
mGestureEventProcessor.GestureDetectorUpdated(this);
}
void TapGestureDetector::SetMaximumTapsRequired(unsigned int taps)
{
- if ( mMaximumTapsRequired != taps )
+ if(mMaximumTapsRequired != taps)
{
mMaximumTapsRequired = taps;
- if ( !mAttachedActors.empty() )
+ if(!mAttachedActors.empty())
{
mGestureEventProcessor.GestureDetectorUpdated(this);
}
void TapGestureDetector::SetTouchesRequired(unsigned int touches)
{
- if (mTouchesRequired != touches)
+ if(mTouchesRequired != touches)
{
mTouchesRequired = touches;
- if (!mAttachedActors.empty())
+ if(!mAttachedActors.empty())
{
mGestureEventProcessor.GestureDetectorUpdated(this);
}
return mTouchesRequired;
}
+void TapGestureDetector::ReceiveAllTapEvents(bool receive)
+{
+ mReceiveAllTapEvents = receive;
+}
+
void TapGestureDetector::EmitTapGestureSignal(Dali::Actor tappedActor, const Dali::TapGesture& tap)
{
+ Dali::Integration::PlatformAbstraction& platformAbstraction = ThreadLocalStorage::Get().GetPlatformAbstraction();
+ if(mTimerId != 0)
+ {
+ platformAbstraction.CancelTimer(mTimerId);
+ mTimerId = 0;
+ }
+ if(mMaximumTapsRequired > tap.GetNumberOfTaps() && !mReceiveAllTapEvents)
+ {
+ mTappedActor = tappedActor;
+
+ Internal::TapGesturePtr internalTap(new Internal::TapGesture(tap.GetState()));
+ internalTap->SetTime(tap.GetTime());
+ internalTap->SetNumberOfTaps(tap.GetNumberOfTaps());
+ internalTap->SetNumberOfTouches(tap.GetNumberOfTouches());
+ internalTap->SetScreenPoint(tap.GetScreenPoint());
+ internalTap->SetLocalPoint(tap.GetLocalPoint());
+ internalTap->SetGestureSourceType(tap.GetSourceType());
+ mTap = Dali::TapGesture(internalTap.Get());
+
+ mTimerId = platformAbstraction.StartTimer(DEFAULT_TAP_WAIT_TIME, MakeCallback(this, &TapGestureDetector::TimerCallback));
+ }
+ else
+ {
+ // Guard against destruction during signal emission
+ Dali::TapGestureDetector handle(this);
+
+ mDetectedSignal.Emit(tappedActor, tap);
+ }
+}
+
+bool TapGestureDetector::TimerCallback()
+{
// Guard against destruction during signal emission
- Dali::TapGestureDetector handle( this );
+ Dali::TapGestureDetector handle(this);
+
+ mDetectedSignal.Emit(mTappedActor, mTap);
- mDetectedSignal.Emit( tappedActor, tap );
+ mTimerId = 0;
+ return false;
}
-bool TapGestureDetector::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
+bool TapGestureDetector::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
{
- bool connected( true );
- TapGestureDetector* gesture = static_cast< TapGestureDetector* >(object); // TypeRegistry guarantees that this is the correct type.
+ bool connected(true);
+ TapGestureDetector* gesture = static_cast<TapGestureDetector*>(object); // TypeRegistry guarantees that this is the correct type.
- if ( 0 == strcmp( signalName.c_str(), SIGNAL_TAP_DETECTED ) )
+ if(0 == strcmp(signalName.c_str(), SIGNAL_TAP_DETECTED))
{
- gesture->DetectedSignal().Connect( tracker, functor );
+ gesture->DetectedSignal().Connect(tracker, functor);
}
else
{
} // namespace Internal
-} // namespace Dali
+} // namespace Dali
\ No newline at end of file