Revert "[Tizen] Revert "Use touch consumed return to set whether we process a gesture...
[platform/core/uifw/dali-core.git] / dali / internal / event / events / event-processor.cpp
index 560b48a..ff6007b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 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.
 // INTERNAL INCLUDES
 #include <dali/integration-api/debug.h>
 #include <dali/integration-api/events/event.h>
-#include <dali/integration-api/events/gesture-event.h>
 #include <dali/integration-api/events/key-event-integ.h>
 #include <dali/integration-api/events/wheel-event-integ.h>
 #include <dali/integration-api/events/touch-event-integ.h>
 #include <dali/integration-api/events/hover-event-integ.h>
-#include <dali/integration-api/events/pinch-gesture-event.h>
-#include <dali/integration-api/events/pan-gesture-event.h>
-#include <dali/integration-api/events/tap-gesture-event.h>
-#include <dali/integration-api/events/long-press-gesture-event.h>
 #include <dali/internal/event/events/gesture-event-processor.h>
 #include <dali/internal/common/core-impl.h>
 #include <dali/internal/event/common/notification-manager.h>
@@ -46,8 +41,7 @@ namespace // unnamed namespace
 {
 
 static const std::size_t MAX_MESSAGE_SIZE = std::max( sizeof(Integration::TouchEvent),
-                                                      std::max( sizeof(Integration::KeyEvent),
-                                                                std::max( sizeof(Integration::WheelEvent), sizeof(Integration::GestureEvent) ) ) );
+                                                      std::max( sizeof(Integration::KeyEvent), sizeof(Integration::WheelEvent) ) );
 
 static const std::size_t INITIAL_MIN_CAPACITY = 4;
 
@@ -55,12 +49,13 @@ static const std::size_t INITIAL_BUFFER_SIZE = MAX_MESSAGE_SIZE * INITIAL_MIN_CA
 
 } // unnamed namespace
 
-EventProcessor::EventProcessor(Stage& stage, NotificationManager& /* notificationManager */, GestureEventProcessor& gestureEventProcessor)
-: mTouchEventProcessor(stage),
-  mHoverEventProcessor(stage),
-  mGestureEventProcessor(gestureEventProcessor),
-  mKeyEventProcessor(stage),
-  mWheelEventProcessor(stage),
+EventProcessor::EventProcessor( Scene& scene, GestureEventProcessor& gestureEventProcessor )
+: mScene( scene ),
+  mTouchEventProcessor( scene ),
+  mHoverEventProcessor( scene ),
+  mGestureEventProcessor( gestureEventProcessor ),
+  mKeyEventProcessor( scene ),
+  mWheelEventProcessor( scene ),
   mEventQueue0( INITIAL_BUFFER_SIZE ),
   mEventQueue1( INITIAL_BUFFER_SIZE ),
   mCurrentEventQueue( &mEventQueue0 )
@@ -93,7 +88,7 @@ void EventProcessor::QueueEvent( const Event& event )
       typedef Integration::TouchEvent DerivedType;
 
       // Reserve some memory inside the message queue
-      unsigned int* slot = mCurrentEventQueue->ReserveMessageSlot( sizeof( DerivedType ) );
+      uint32_t* slot = mCurrentEventQueue->ReserveMessageSlot( sizeof( DerivedType ) );
 
       // Construct message in the message queue memory; note that delete should not be called on the return value
       new (slot) DerivedType( static_cast<const DerivedType&>(event) );
@@ -103,10 +98,10 @@ void EventProcessor::QueueEvent( const Event& event )
 
     case Event::Hover:
     {
-      typedef Integration::HoverEvent DerivedType;
+      using DerivedType = Integration::HoverEvent;
 
       // Reserve some memory inside the message queue
-      unsigned int* slot = mCurrentEventQueue->ReserveMessageSlot( sizeof( DerivedType ) );
+      uint32_t* slot = mCurrentEventQueue->ReserveMessageSlot( sizeof( DerivedType ) );
 
       // Construct message in the message queue memory; note that delete should not be called on the return value
       new (slot) DerivedType( static_cast<const DerivedType&>(event) );
@@ -116,10 +111,10 @@ void EventProcessor::QueueEvent( const Event& event )
 
     case Event::Key:
     {
-      typedef Integration::KeyEvent DerivedType;
+      using DerivedType = Integration::KeyEvent;
 
       // Reserve some memory inside the message queue
-      unsigned int* slot = mCurrentEventQueue->ReserveMessageSlot( sizeof( DerivedType ) );
+      uint32_t* slot = mCurrentEventQueue->ReserveMessageSlot( sizeof( DerivedType ) );
 
       // Construct message in the message queue memory; note that delete should not be called on the return value
       new (slot) DerivedType( static_cast<const DerivedType&>(event) );
@@ -129,75 +124,10 @@ void EventProcessor::QueueEvent( const Event& event )
 
     case Event::Wheel:
     {
-      typedef Integration::WheelEvent DerivedType;
+      using DerivedType = Integration::WheelEvent;
 
       // Reserve some memory inside the message queue
-      unsigned int* slot = mCurrentEventQueue->ReserveMessageSlot( sizeof( DerivedType ) );
-
-      // Construct message in the message queue memory; note that delete should not be called on the return value
-      new (slot) DerivedType( static_cast<const DerivedType&>(event) );
-
-      break;
-    }
-
-    case Event::Gesture:
-    {
-      QueueGestureEvent( static_cast<const Integration::GestureEvent&>(event) );
-      break;
-    }
-
-  }
-}
-
-void EventProcessor::QueueGestureEvent(const Integration::GestureEvent& event)
-{
-  switch( event.gestureType )
-  {
-    case Gesture::Pinch:
-    {
-      typedef Integration::PinchGestureEvent DerivedType;
-
-      // Reserve some memory inside the message queue
-      unsigned int* slot = mCurrentEventQueue->ReserveMessageSlot( sizeof( DerivedType ) );
-
-      // Construct message in the message queue memory; note that delete should not be called on the return value
-      new (slot) DerivedType( static_cast<const DerivedType&>(event) );
-
-      break;
-    }
-
-    case Gesture::Pan:
-    {
-      typedef Integration::PanGestureEvent DerivedType;
-
-      // Reserve some memory inside the message queue
-      unsigned int* slot = mCurrentEventQueue->ReserveMessageSlot( sizeof( DerivedType ) );
-
-      // Construct message in the message queue memory; note that delete should not be called on the return value
-      new (slot) DerivedType( static_cast<const DerivedType&>(event) );
-
-      break;
-    }
-
-    case Gesture::Tap:
-    {
-      typedef Integration::TapGestureEvent DerivedType;
-
-      // Reserve some memory inside the message queue
-      unsigned int* slot = mCurrentEventQueue->ReserveMessageSlot( sizeof( DerivedType ) );
-
-      // Construct message in the message queue memory; note that delete should not be called on the return value
-      new (slot) DerivedType( static_cast<const DerivedType&>(event) );
-
-      break;
-    }
-
-    case Gesture::LongPress:
-    {
-      typedef Integration::LongPressGestureEvent DerivedType;
-
-      // Reserve some memory inside the message queue
-      unsigned int* slot = mCurrentEventQueue->ReserveMessageSlot( sizeof( DerivedType ) );
+      uint32_t* slot = mCurrentEventQueue->ReserveMessageSlot( sizeof( DerivedType ) );
 
       // Construct message in the message queue memory; note that delete should not be called on the return value
       new (slot) DerivedType( static_cast<const DerivedType&>(event) );
@@ -212,7 +142,7 @@ void EventProcessor::ProcessEvents()
   MessageBuffer* queueToProcess = mCurrentEventQueue;
 
   // Switch current queue; events can be added safely while iterating through the other queue.
-  mCurrentEventQueue = (&mEventQueue0 == mCurrentEventQueue) ? &mEventQueue1 : &mEventQueue0;
+  mCurrentEventQueue = ( &mEventQueue0 == mCurrentEventQueue ) ? &mEventQueue1 : &mEventQueue0;
 
   for( MessageBuffer::Iterator iter = queueToProcess->Begin(); iter.IsValid(); iter.Next() )
   {
@@ -222,7 +152,18 @@ void EventProcessor::ProcessEvents()
     {
       case Event::Touch:
       {
-        mTouchEventProcessor.ProcessTouchEvent( static_cast<const Integration::TouchEvent&>(*event) );
+        Integration::TouchEvent& touchEvent = static_cast<Integration::TouchEvent&>(*event);
+        const bool consumed = mTouchEventProcessor.ProcessTouchEvent( touchEvent );
+
+        // If touch is consumed, then gestures should be cancelled
+        // Do this by sending an interrupted event to the GestureEventProcessor
+        if( consumed )
+        {
+          Integration::Point& point = touchEvent.GetPoint(0);
+          point.SetState( PointState::INTERRUPTED );
+        }
+
+        mGestureEventProcessor.ProcessTouchEvent(mScene, touchEvent);
         break;
       }
 
@@ -243,13 +184,6 @@ void EventProcessor::ProcessEvents()
         mWheelEventProcessor.ProcessWheelEvent( static_cast<const Integration::WheelEvent&>(*event) );
         break;
       }
-
-      case Event::Gesture:
-      {
-        mGestureEventProcessor.ProcessGestureEvent( static_cast<const Integration::GestureEvent&>(*event) );
-        break;
-      }
-
     }
     // Call virtual destructor explictly; since delete will not be called after placement new
     event->~Event();