Touch and Hover event propagrated by geometry way.(5)
[platform/core/uifw/dali-core.git] / dali / internal / event / events / long-press-gesture / long-press-gesture-recognizer.cpp
index e4a9e02..85d10bb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 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 <dali/devel-api/events/touch-point.h>
 #include <dali/public-api/math/vector2.h>
 
-#include <dali/internal/event/common/thread-local-storage.h>
-#include <dali/internal/event/events/gesture-requests.h>
 #include <dali/integration-api/events/touch-event-integ.h>
 #include <dali/integration-api/platform-abstraction.h>
+#include <dali/internal/event/common/thread-local-storage.h>
+#include <dali/internal/event/events/gesture-requests.h>
 
 namespace Dali
 {
-
 namespace Internal
 {
-
 namespace
 {
 // TODO: Set these according to DPI
@@ -42,21 +40,21 @@ const float MAXIMUM_MOTION_ALLOWED = 60.0f;
 
 } // unnamed namespace
 
-LongPressGestureRecognizer::LongPressGestureRecognizer(Observer& observer, Vector2 screenSize, const LongPressGestureRequest& request, uint32_t minimumHoldingTime )
-: GestureRecognizer( screenSize, Dali::Gesture::LongPress ),
-  mObserver( observer ),
-  mState( Clear ),
-  mMinimumTouchesRequired( request.minTouches ),
-  mMaximumTouchesRequired( request.maxTouches ),
-  mTouchTime( 0 ),
-  mTimerId( 0 ),
-  mMinimumHoldingTime( minimumHoldingTime )
+LongPressGestureRecognizer::LongPressGestureRecognizer(Observer& observer, Vector2 screenSize, const LongPressGestureRequest& request, uint32_t minimumHoldingTime)
+: GestureRecognizer(screenSize, GestureType::LONG_PRESS),
+  mObserver(observer),
+  mState(CLEAR),
+  mMinimumTouchesRequired(request.minTouches),
+  mMaximumTouchesRequired(request.maxTouches),
+  mTouchTime(0),
+  mTimerId(0),
+  mMinimumHoldingTime(minimumHoldingTime)
 {
 }
 
 LongPressGestureRecognizer::~LongPressGestureRecognizer()
 {
-  if( mTimerId != 0 && ThreadLocalStorage::Created() )
+  if(mTimerId != 0 && ThreadLocalStorage::Created())
   {
     Dali::Integration::PlatformAbstraction& platformAbstraction = ThreadLocalStorage::Get().GetPlatformAbstraction();
     platformAbstraction.CancelTimer(mTimerId);
@@ -65,58 +63,58 @@ LongPressGestureRecognizer::~LongPressGestureRecognizer()
 
 void LongPressGestureRecognizer::SendEvent(const Integration::TouchEvent& event)
 {
-  unsigned int pointCount( event.GetPointCount() );
+  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)
+  GestureRecognizerPtr                    ptr(this); // To keep us from being destroyed during the life-time of this method
+  switch(mState)
   {
-    // Clear: Wait till one point touches the screen before starting timer.
-    case Clear:
+    // CLEAR: Wait till one point touches the screen before starting timer.
+    case CLEAR:
     {
       const Integration::Point& point = event.points[0];
 
-      if ( point.GetState() == PointState::DOWN )
+      if(point.GetState() == PointState::DOWN)
       {
         mTouchPositions.clear();
         mTouchPositions[point.GetDeviceId()] = point.GetScreenPosition();
 
         mTouchTime = event.time;
 
-        if( mTimerId != 0 )
+        if(mTimerId != 0)
         {
           platformAbstraction.CancelTimer(mTimerId);
         }
-        mTimerId = platformAbstraction.StartTimer( mMinimumHoldingTime, MakeCallback( this, &LongPressGestureRecognizer::TimerCallback ) );
+        mTimerId = platformAbstraction.StartTimer(mMinimumHoldingTime, MakeCallback(this, &LongPressGestureRecognizer::TimerCallback));
 
-        // A long press gesture may be possible, tell Core about this and change state to Touched.
-        mState = Touched;
-        EmitGesture( Dali::Gesture::Possible );
+        // A long press gesture may be possible, tell Core about this and change state to TOUCHED.
+        mState = TOUCHED;
+        EmitGesture(GestureState::POSSIBLE);
       }
 
       break;
     }
 
-    // Touched: Monitor movement and addition/removal of points.
-    case Touched:
+    // TOUCHED: Monitor movement and addition/removal of points.
+    case TOUCHED:
     {
-      if (pointCount > mMaximumTouchesRequired)
+      if(pointCount > mMaximumTouchesRequired)
       {
-        // A long press did not occur, tell Core that it was cancelled and change state to Failed.
-        EmitGesture( Dali::Gesture::Cancelled );
+        // A long press did not occur, tell Core that it was cancelled and change state to FAILED.
+        EmitGesture(GestureState::CANCELLED);
         mTouchPositions.clear();
         platformAbstraction.CancelTimer(mTimerId);
         mTimerId = 0;
-        mState = Failed;
+        mState   = FAILED;
         break;
       }
 
       bool endLoop(false);
 
-      for ( Integration::PointContainerConstIterator iter = event.points.begin(), endIter = event.points.end();
-           iter != endIter && !endLoop; ++iter)
+      for(Integration::PointContainerConstIterator iter = event.points.begin(), endIter = event.points.end();
+          iter != endIter && !endLoop;
+          ++iter)
       {
-        switch( iter->GetState() )
+        switch(iter->GetState())
         {
           // add point.
           case PointState::DOWN:
@@ -130,28 +128,28 @@ void LongPressGestureRecognizer::SendEvent(const Integration::TouchEvent& event)
           case PointState::INTERRUPTED:
           {
             // System has interrupted us, long press is not possible, inform Core
-            EmitGesture( Dali::Gesture::Cancelled );
+            EmitGesture(GestureState::CANCELLED);
             mTouchPositions.clear();
             platformAbstraction.CancelTimer(mTimerId);
             mTimerId = 0;
-            mState = ( pointCount == 1 ) ? Clear : Failed; // Change state to Clear if only one point, Failed otherwise.
-            endLoop = true;
+            mState   = (pointCount == 1) ? CLEAR : FAILED; // Change state to CLEAR if only one point, FAILED otherwise.
+            endLoop  = true;
             break;
           }
 
           case PointState::MOTION:
           {
-            const Vector2 touchPosition( mTouchPositions[iter->GetDeviceId()] - iter->GetScreenPosition() );
-            float distanceSquared = touchPosition.LengthSquared();
+            const Vector2 touchPosition(mTouchPositions[iter->GetDeviceId()] - iter->GetScreenPosition());
+            float         distanceSquared = touchPosition.LengthSquared();
 
-            if (distanceSquared > ( MAXIMUM_MOTION_ALLOWED * MAXIMUM_MOTION_ALLOWED ) )
+            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( Dali::Gesture::Cancelled );
+              // We have moved more than the allowable motion for a long press gesture. Inform Core and change state to FAILED.
+              EmitGesture(GestureState::CANCELLED);
               platformAbstraction.CancelTimer(mTimerId);
               mTimerId = 0;
-              mState = Failed;
-              endLoop = true;
+              mState   = FAILED;
+              endLoop  = true;
             }
             break;
           }
@@ -166,24 +164,24 @@ void LongPressGestureRecognizer::SendEvent(const Integration::TouchEvent& event)
       break;
     }
 
-    // Failed/Finished: Monitor the touches, waiting for all touches to be released.
-    case Failed:
-    case Finished:
+    // FAILED/FINISHED: Monitor the touches, waiting for all touches to be released.
+    case FAILED:
+    case FINISHED:
     {
       // eventually the final touch point will be removed, marking the end of this gesture.
-      if ( pointCount == 1 )
+      if(pointCount == 1)
       {
         PointState::Type primaryPointState = event.points[0].GetState();
 
-        if ( (primaryPointState == PointState::UP) || (primaryPointState == PointState::INTERRUPTED) )
+        if((primaryPointState == PointState::UP) || (primaryPointState == PointState::INTERRUPTED))
         {
-          if(mState == Finished)
+          if(mState == FINISHED)
           {
             // When the last touch point is lifted, we should inform the Core that the Long press has finished.
-            EmitGesture(Dali::Gesture::Finished);
+            EmitGesture(GestureState::FINISHED);
           }
           mTouchPositions.clear();
-          mState = Clear; // Reset state to clear when last touch point is lifted.
+          mState = CLEAR; // Reset state to clear when last touch point is lifted.
         }
       }
       break;
@@ -199,49 +197,51 @@ void LongPressGestureRecognizer::Update(const GestureRequest& request)
   mMaximumTouchesRequired = longPress.maxTouches;
 }
 
-void LongPressGestureRecognizer::SetMinimumHoldingTime( uint32_t time )
+void LongPressGestureRecognizer::SetMinimumHoldingTime(uint32_t time)
 {
   mMinimumHoldingTime = time;
 }
 
-
 bool LongPressGestureRecognizer::TimerCallback()
 {
-  EmitGesture(Dali::Gesture::Started);
+  EmitGesture(GestureState::STARTED);
 
-  mState = Finished;
+  mState = FINISHED;
 
   mTimerId = 0;
 
   return false;
 }
 
-void LongPressGestureRecognizer::EmitGesture(Gesture::State state)
+void LongPressGestureRecognizer::EmitGesture(GestureState state)
 {
-  unsigned int touchPoints ( static_cast<unsigned int>( mTouchPositions.size() ) );
+  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 == Dali::Gesture::Possible) ||
-       (state == Dali::Gesture::Cancelled) ||
-       (touchPoints >= mMinimumTouchesRequired) )
+  // We should tell Core about the POSSIBLE and CANCELLED states regardless of whether we have satisfied long press requirements.
+  if((state == GestureState::POSSIBLE) ||
+     (state == GestureState::CANCELLED) ||
+     (touchPoints >= mMinimumTouchesRequired))
   {
-    LongPressGestureEvent longPress( state );
+    LongPressGestureEvent longPress(state);
     longPress.numberOfTouches = touchPoints;
 
-    for (std::map<int, Vector2>::iterator iter = mTouchPositions.begin(), endIter = mTouchPositions.end();
-         iter != endIter; ++iter)
+    for(std::map<int, Vector2>::iterator iter = mTouchPositions.begin(), endIter = mTouchPositions.end();
+        iter != endIter;
+        ++iter)
     {
       longPress.point += iter->second;
     }
-    longPress.point /= static_cast<float>( touchPoints );
+    longPress.point /= static_cast<float>(touchPoints);
 
     longPress.time = mTouchTime;
-    if ( state != Dali::Gesture::Possible )
+    if(state != GestureState::POSSIBLE)
     {
       longPress.time += mMinimumHoldingTime;
     }
+    longPress.sourceType = mSourceType;
+    longPress.sourceData = mSourceData;
 
-    if( mScene )
+    if(mScene)
     {
       // Create another handle so the recognizer cannot be destroyed during process function
       GestureRecognizerPtr recognizerHandle = this;