1. Revert "Sets the tap gesture timer to 330ms." 38/261938/12
authorjoogab.yun <joogab.yun@samsung.com>
Thu, 29 Jul 2021 17:09:43 +0000 (02:09 +0900)
committerjoogab.yun <joogab.yun@samsung.com>
Wed, 4 Aug 2021 01:50:47 +0000 (10:50 +0900)
2. Revert "Add Timer at TapGestureRecognizer"

3. Add Timer at TapGestureDetector

   Currently, when double tap operation is performed,
   single tap and double tap are always transmitted together.

   So, when single and double taps are required, then after one tap, we wait for the timeout,
   if the timeout happens, then we emit the single-tap,
   if we tap again during this time, then we emit a double-tap instead.

Change-Id: Iac7cfd964a3f9d58593325e85841d2a6ee53b9ac

dali/internal/event/events/tap-gesture/tap-gesture-detector-impl.cpp
dali/internal/event/events/tap-gesture/tap-gesture-detector-impl.h
dali/internal/event/events/tap-gesture/tap-gesture-recognizer.cpp
dali/internal/event/events/tap-gesture/tap-gesture-recognizer.h

index 0177d50..ee1f0d5 100644 (file)
 
 // INTERNAL INCLUDES
 #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>
 
@@ -33,8 +36,9 @@ 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";
@@ -64,7 +68,10 @@ TapGestureDetector::TapGestureDetector()
 : GestureDetector(GestureType::TAP),
   mMinimumTapsRequired(DEFAULT_TAPS_REQUIRED),
   mMaximumTapsRequired(DEFAULT_TAPS_REQUIRED),
-  mTouchesRequired(DEFAULT_TOUCHES_REQUIRED)
+  mTouchesRequired(DEFAULT_TOUCHES_REQUIRED),
+  mTimerId(0),
+  mTappedActor(),
+  mTap()
 {
 }
 
@@ -72,11 +79,21 @@ TapGestureDetector::TapGestureDetector(unsigned int tapsRequired)
 : GestureDetector(GestureType::TAP),
   mMinimumTapsRequired(tapsRequired),
   mMaximumTapsRequired(tapsRequired),
-  mTouchesRequired(DEFAULT_TOUCHES_REQUIRED)
+  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)
 {
@@ -134,10 +151,45 @@ unsigned int TapGestureDetector::GetTouchesRequired() const
 
 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())
+  {
+    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);
 
-  mDetectedSignal.Emit(tappedActor, tap);
+  mDetectedSignal.Emit(mTappedActor, mTap);
+
+  mTimerId = 0;
+  return false;
 }
 
 bool TapGestureDetector::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
@@ -175,4 +227,4 @@ void TapGestureDetector::OnActorDestroyed(Object& object)
 
 } // namespace Internal
 
-} // namespace Dali
+} // namespace Dali
\ No newline at end of file
index 1e5a074..fd7db72 100644 (file)
@@ -133,6 +133,12 @@ private:
   TapGestureDetector(const TapGestureDetector&);
   TapGestureDetector& operator=(const TapGestureDetector& rhs);
 
+  /**
+   * Timer Callback
+   * @return will return false; one-shot timer.
+   */
+  bool TimerCallback();
+
 private: // GestureDetector overrides
   /**
    * @copydoc Dali::Internal::GestureDetector::OnActorAttach(Actor&)
@@ -152,9 +158,12 @@ private: // GestureDetector overrides
 private:
   Dali::TapGestureDetector::DetectedSignalType mDetectedSignal;
 
-  unsigned int mMinimumTapsRequired;
-  unsigned int mMaximumTapsRequired;
-  unsigned int mTouchesRequired;
+  unsigned int     mMinimumTapsRequired;
+  unsigned int     mMaximumTapsRequired;
+  unsigned int     mTouchesRequired;
+  uint32_t         mTimerId;
+  Dali::Actor      mTappedActor;
+  Dali::TapGesture mTap;
 };
 
 } // namespace Internal
@@ -181,4 +190,4 @@ inline const Internal::TapGestureDetector& GetImplementation(const Dali::TapGest
 
 } // namespace Dali
 
-#endif // DALI_INTERNAL_TAP_GESTURE_DETECTOR_H
+#endif // DALI_INTERNAL_TAP_GESTURE_DETECTOR_H
\ No newline at end of file
index ab8c1a8..975c847 100644 (file)
 
 #include <dali/public-api/math/vector2.h>
 
-// INTERNAL INCLUDES
 #include <dali/integration-api/events/touch-event-integ.h>
-#include <dali/integration-api/platform-abstraction.h>
+
+// INTERNAL INCLUDES
 #include <dali/internal/event/common/scene-impl.h>
-#include <dali/internal/event/common/thread-local-storage.h>
 #include <dali/internal/event/events/gesture-requests.h>
 
 namespace Dali
@@ -39,7 +38,6 @@ namespace
 // TODO: Set these according to DPI
 const float         MAXIMUM_MOTION_ALLOWED = 20.0f;
 const unsigned long MAXIMUM_TIME_ALLOWED   = 500u;
-const uint32_t      WAIT_TIME              = 330u;
 } // unnamed namespace
 
 TapGestureRecognizer::TapGestureRecognizer(Observer& observer, Vector2 screenSize, const TapGestureRequest& request)
@@ -52,20 +50,11 @@ TapGestureRecognizer::TapGestureRecognizer(Observer& observer, Vector2 screenSiz
   mTouchPosition(),
   mTouchTime(0u),
   mLastTapTime(0u),
-  mEventTime(0u),
-  mGestureSourceType(GestureSourceType::INVALID),
-  mTimerId(0)
+  mGestureSourceType(GestureSourceType::INVALID)
 {
 }
 
-TapGestureRecognizer::~TapGestureRecognizer()
-{
-  if(mTimerId != 0 && ThreadLocalStorage::Created())
-  {
-    Dali::Integration::PlatformAbstraction& platformAbstraction = ThreadLocalStorage::Get().GetPlatformAbstraction();
-    platformAbstraction.CancelTimer(mTimerId);
-  }
-}
+TapGestureRecognizer::~TapGestureRecognizer() = default;
 
 void TapGestureRecognizer::SendEvent(const Integration::TouchEvent& event)
 {
@@ -73,9 +62,8 @@ void TapGestureRecognizer::SendEvent(const Integration::TouchEvent& event)
 
   if(event.GetPointCount() == 1)
   {
-    const Integration::Point&               point               = event.points[0];
-    PointState::Type                        pointState          = point.GetState();
-    Dali::Integration::PlatformAbstraction& platformAbstraction = ThreadLocalStorage::Get().GetPlatformAbstraction();
+    const Integration::Point& point      = event.points[0];
+    PointState::Type          pointState = point.GetState();
 
     MouseButton::Type mouseButton = point.GetMouseButton();
     switch(mouseButton)
@@ -126,12 +114,6 @@ void TapGestureRecognizer::SendEvent(const Integration::TouchEvent& event)
         {
           if(deltaBetweenTouchDownTouchUp < MAXIMUM_TIME_ALLOWED)
           {
-            if(mMaximumTapsRequired > mMinimumTapsRequired)
-            {
-              mEventTime = event.time;
-              mTimerId   = platformAbstraction.StartTimer(WAIT_TIME, MakeCallback(this, &TapGestureRecognizer::TimerCallback));
-            }
-
             mLastTapTime = mTouchTime;
             EmitSingleTap(event.time, point);
             mState = REGISTERED;
@@ -163,15 +145,7 @@ void TapGestureRecognizer::SendEvent(const Integration::TouchEvent& event)
           else if(deltaBetweenTouchDownTouchUp < MAXIMUM_TIME_ALLOWED)
           {
             ++mTapsRegistered;
-            if(mMaximumTapsRequired > mMinimumTapsRequired)
-            {
-              mEventTime = event.time;
-              mTimerId   = platformAbstraction.StartTimer(WAIT_TIME, MakeCallback(this, &TapGestureRecognizer::TimerCallback));
-            }
-            else
-            {
-              EmitGesture(GestureState::STARTED, event.time);
-            }
+            EmitGesture(GestureState::STARTED, event.time);
           }
           else // Delta between touch down and touch up too long to be considered a TAP event
           {
@@ -196,12 +170,6 @@ void TapGestureRecognizer::SendEvent(const Integration::TouchEvent& event)
           {
             EmitPossibleState(event);
           }
-
-          if(mTimerId != 0)
-          {
-            platformAbstraction.CancelTimer(mTimerId);
-            mTimerId = 0;
-          }
         }
         break;
       }
@@ -223,14 +191,6 @@ void TapGestureRecognizer::SendEvent(const Integration::TouchEvent& event)
   }
 }
 
-bool TapGestureRecognizer::TimerCallback()
-{
-  EmitGesture(GestureState::STARTED, mEventTime);
-
-  mTimerId = 0;
-  return false;
-}
-
 void TapGestureRecognizer::SetupForTouchDown(const Integration::TouchEvent& event, const Integration::Point& point)
 {
   mTouchPosition  = point.GetScreenPosition();
@@ -278,22 +238,13 @@ void TapGestureRecognizer::EmitSingleTap(uint32_t time, const Integration::Point
   Vector2         distanceDelta(std::abs(mTouchPosition.x - screen.x),
                         std::abs(mTouchPosition.y - screen.y));
 
-  mTapsRegistered = 1u;
   if(distanceDelta.x > MAXIMUM_MOTION_ALLOWED ||
      distanceDelta.y > MAXIMUM_MOTION_ALLOWED)
   {
     event.state = GestureState::CANCELLED;
-    if(mTimerId != 0)
-    {
-      Dali::Integration::PlatformAbstraction& platformAbstraction = ThreadLocalStorage::Get().GetPlatformAbstraction();
-      platformAbstraction.CancelTimer(mTimerId);
-      mTimerId = 0;
-    }
-  }
-  if(mTimerId == 0)
-  {
-    EmitTap(time, event);
   }
+  mTapsRegistered = 1u;
+  EmitTap(time, event);
 }
 
 void TapGestureRecognizer::EmitTap(uint32_t time, TapGestureEvent& event)
index 5b01982..f87d2ec 100644 (file)
@@ -117,12 +117,6 @@ private:
    */
   void ProcessEvent(TapGestureEvent& event);
 
-  /**
-   * Timer Callback
-   * @return will return false; one-shot timer.
-   */
-  bool TimerCallback();
-
 private:
   // Reference to the gesture processor for this recognizer
   Observer& mObserver;
@@ -147,11 +141,8 @@ private:
   Vector2  mTouchPosition; ///< The initial touch down position.
   uint32_t mTouchTime;     ///< The initial touch down time.
   uint32_t mLastTapTime;   ///< Time last tap gesture was registered
-  uint32_t mEventTime;     ///< The touch event time.
 
   GestureSourceType mGestureSourceType; /// < Gesture input source type value.
-
-  uint32_t mTimerId;
 };
 
 } // namespace Internal