Refactoring Gestures Class
[platform/core/uifw/dali-core.git] / dali / internal / event / events / long-press-gesture / long-press-gesture-recognizer.cpp
index de9fe1b..e4a9e02 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
@@ -21,7 +21,7 @@
 // EXTERNAL INCLUDES
 #include <cmath>
 
-#include <dali/public-api/events/touch-point.h>
+#include <dali/devel-api/events/touch-point.h>
 #include <dali/public-api/math/vector2.h>
 
 #include <dali/internal/event/common/thread-local-storage.h>
@@ -43,7 +43,7 @@ const float MAXIMUM_MOTION_ALLOWED = 60.0f;
 } // unnamed namespace
 
 LongPressGestureRecognizer::LongPressGestureRecognizer(Observer& observer, Vector2 screenSize, const LongPressGestureRequest& request, uint32_t minimumHoldingTime )
-: GestureRecognizer( screenSize, Gesture::LongPress ),
+: GestureRecognizer( screenSize, Dali::Gesture::LongPress ),
   mObserver( observer ),
   mState( Clear ),
   mMinimumTouchesRequired( request.minTouches ),
@@ -67,6 +67,7 @@ void LongPressGestureRecognizer::SendEvent(const Integration::TouchEvent& event)
 {
   unsigned int pointCount( event.GetPointCount() );
   Dali::Integration::PlatformAbstraction& platformAbstraction = ThreadLocalStorage::Get().GetPlatformAbstraction();
+  GestureRecognizerPtr ptr(this); // To keep us from being destroyed during the life-time of this method
 
   switch (mState)
   {
@@ -90,7 +91,7 @@ void LongPressGestureRecognizer::SendEvent(const Integration::TouchEvent& event)
 
         // A long press gesture may be possible, tell Core about this and change state to Touched.
         mState = Touched;
-        EmitGesture( Gesture::Possible );
+        EmitGesture( Dali::Gesture::Possible );
       }
 
       break;
@@ -102,7 +103,7 @@ void LongPressGestureRecognizer::SendEvent(const Integration::TouchEvent& event)
       if (pointCount > mMaximumTouchesRequired)
       {
         // A long press did not occur, tell Core that it was cancelled and change state to Failed.
-        EmitGesture( Gesture::Cancelled );
+        EmitGesture( Dali::Gesture::Cancelled );
         mTouchPositions.clear();
         platformAbstraction.CancelTimer(mTimerId);
         mTimerId = 0;
@@ -129,7 +130,7 @@ void LongPressGestureRecognizer::SendEvent(const Integration::TouchEvent& event)
           case PointState::INTERRUPTED:
           {
             // System has interrupted us, long press is not possible, inform Core
-            EmitGesture( Gesture::Cancelled );
+            EmitGesture( Dali::Gesture::Cancelled );
             mTouchPositions.clear();
             platformAbstraction.CancelTimer(mTimerId);
             mTimerId = 0;
@@ -146,7 +147,7 @@ void LongPressGestureRecognizer::SendEvent(const Integration::TouchEvent& event)
             if (distanceSquared > ( MAXIMUM_MOTION_ALLOWED * MAXIMUM_MOTION_ALLOWED ) )
             {
               // We have moved more than the allowable motion for a long press gesture. Inform Core and change state to Failed.
-              EmitGesture( Gesture::Cancelled );
+              EmitGesture( Dali::Gesture::Cancelled );
               platformAbstraction.CancelTimer(mTimerId);
               mTimerId = 0;
               mState = Failed;
@@ -179,7 +180,7 @@ void LongPressGestureRecognizer::SendEvent(const Integration::TouchEvent& event)
           if(mState == Finished)
           {
             // When the last touch point is lifted, we should inform the Core that the Long press has finished.
-            EmitGesture(Gesture::Finished);
+            EmitGesture(Dali::Gesture::Finished);
           }
           mTouchPositions.clear();
           mState = Clear; // Reset state to clear when last touch point is lifted.
@@ -206,7 +207,7 @@ void LongPressGestureRecognizer::SetMinimumHoldingTime( uint32_t time )
 
 bool LongPressGestureRecognizer::TimerCallback()
 {
-  EmitGesture(Gesture::Started);
+  EmitGesture(Dali::Gesture::Started);
 
   mState = Finished;
 
@@ -220,8 +221,8 @@ void LongPressGestureRecognizer::EmitGesture(Gesture::State state)
   unsigned int touchPoints ( static_cast<unsigned int>( mTouchPositions.size() ) );
 
   // We should tell Core about the Possible and Cancelled states regardless of whether we have satisfied long press requirements.
-  if ( (state == Gesture::Possible) ||
-       (state == Gesture::Cancelled) ||
+  if ( (state == Dali::Gesture::Possible) ||
+       (state == Dali::Gesture::Cancelled) ||
        (touchPoints >= mMinimumTouchesRequired) )
   {
     LongPressGestureEvent longPress( state );
@@ -235,7 +236,7 @@ void LongPressGestureRecognizer::EmitGesture(Gesture::State state)
     longPress.point /= static_cast<float>( touchPoints );
 
     longPress.time = mTouchTime;
-    if ( state != Gesture::Possible )
+    if ( state != Dali::Gesture::Possible )
     {
       longPress.time += mMinimumHoldingTime;
     }