[Tizen] dali ubuntu tizen branch build error fix
[platform/core/uifw/dali-adaptor.git] / adaptors / x11 / ecore-x-event-handler.cpp
index 6acd1a3..2d3ce7f 100644 (file)
@@ -49,6 +49,7 @@
 #include <dali/integration-api/events/touch-event-integ.h>
 #include <dali/integration-api/events/hover-event-integ.h>
 #include <dali/integration-api/events/wheel-event-integ.h>
+#include <dali/devel-api/events/key-event-devel.h>
 
 // INTERNAL INCLUDES
 #include <events/gesture-manager.h>
@@ -84,6 +85,8 @@ namespace
 {
 
 const char * DETENT_DEVICE_NAME = "tizen_detent";
+const std::string DEFAULT_DEVICE_NAME = "";
+const DevelKeyEvent::DeviceClass::Type DEFAULT_DEVICE_CLASS = DevelKeyEvent::DeviceClass::NONE;
 
 // DBUS accessibility
 #define A11Y_BUS "org.a11y.Bus"
@@ -291,6 +294,10 @@ struct EventHandler::Impl
     mEcoreEventHandler(),
     mWindow( window ),
     mXiDeviceId( 0 )
+#ifdef DALI_ELDBUS_AVAILABLE
+  , mSessionConnection( NULL ),
+    mA11yConnection( NULL )
+#endif
   {
     // Only register for touch and key events if we have a window
     if ( window != 0 )
@@ -368,10 +375,14 @@ struct EventHandler::Impl
             mXiDeviceId = xiEventMask.deviceid;
 
             // SelectXi2Event
-            xiEventMask.mask = (unsigned char*)(calloc( 1, XIMaskLen( XI_LASTEVENT ) ) );
+            Dali::Vector< unsigned char > mask;
+            std::size_t xiMaskLen = XIMaskLen( XI_LASTEVENT );
+            mask.Reserve( xiMaskLen );
+            xiEventMask.mask = mask.Begin();
+
             XISetMask( xiEventMask.mask, XI_RawMotion );
 
-            xiEventMask.mask_len = sizeof( xiEventMask.mask );
+            xiEventMask.mask_len = xiMaskLen * sizeof( unsigned char );
 
             int ret = XISelectEvents( display, rootWindow, &xiEventMask, 1 );
             if( ret == 0 )
@@ -383,13 +394,11 @@ struct EventHandler::Impl
             {
               DALI_LOG_INFO( gImfLogging, Debug::General, "Failed to Select Events\n" );
             }
+          }
 
-            free( xiEventMask.mask );
-
-            if( deviceInfo != NULL )
-            {
-              XIFreeDeviceInfo( deviceInfo );
-            }
+          if( deviceInfo != NULL )
+          {
+            XIFreeDeviceInfo( deviceInfo );
           }
         }
         else
@@ -411,19 +420,18 @@ struct EventHandler::Impl
 #ifdef DALI_ELDBUS_AVAILABLE
 
       // Initialize ElDBus.
-      DALI_LOG_INFO( gImfLogging, Debug::General, "Starting DBus Initialization" );
+      DALI_LOG_INFO( gImfLogging, Debug::General, "Starting DBus Initialization\n" );
       eldbus_init();
 
-      Eldbus_Connection *sessionConnection;
-      sessionConnection = eldbus_connection_get( ELDBUS_CONNECTION_TYPE_SESSION );
+      mSessionConnection = eldbus_connection_get( ELDBUS_CONNECTION_TYPE_SESSION );
 
-      Eldbus_Object *a11yObject = eldbus_object_get( sessionConnection, A11Y_BUS, A11Y_PATH );
+      Eldbus_Object *a11yObject = eldbus_object_get( mSessionConnection, A11Y_BUS, A11Y_PATH );
       Eldbus_Proxy *elDBusManager = eldbus_proxy_get( a11yObject, A11Y_INTERFACE );
 
       // Pass in handler in the cb_data field so we can access the accessibility adaptor within the callback.
       eldbus_proxy_call( elDBusManager, A11Y_GET_ADDRESS, EcoreElDBusInitialisation, handler, -1, "" );
 
-      DALI_LOG_INFO( gImfLogging, Debug::General, "Finished DBus Initialization" );
+      DALI_LOG_INFO( gImfLogging, Debug::General, "Finished DBus Initialization\n" );
 
 #endif // DALI_ELDBUS_AVAILABLE
     }
@@ -446,6 +454,16 @@ struct EventHandler::Impl
 
 #ifdef DALI_ELDBUS_AVAILABLE
     // Close down ElDBus
+    if( mA11yConnection )
+    {
+      eldbus_connection_unref( mA11yConnection );
+    }
+
+    if( mSessionConnection )
+    {
+      eldbus_connection_unref( mSessionConnection );
+    }
+
     eldbus_shutdown();
 #endif // DALI_ELDBUS_AVAILABLE
   }
@@ -466,17 +484,23 @@ struct EventHandler::Impl
 
     if ( touchEvent->window == handler->mImpl->mWindow )
     {
-      TouchPoint::State state ( TouchPoint::Down );
+      PointState::Type state ( PointState::DOWN );
 
       // Check if the buttons field is set and ensure it's the primary touch button.
       // If this event was triggered by buttons other than the primary button (used for touch), then
       // just send an interrupted event to Core.
       if ( touchEvent->buttons && (touchEvent->buttons != PRIMARY_TOUCH_BUTTON_ID ) )
       {
-        state = TouchPoint::Interrupted;
+        state = PointState::INTERRUPTED;
       }
 
-      TouchPoint point( touchEvent->multi.device, state, touchEvent->x, touchEvent->y );
+      Integration::Point point;
+      point.SetDeviceId( touchEvent->multi.device );
+      point.SetState( state );
+      point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
+      point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
+      point.SetPressure( touchEvent->multi.pressure );
+      point.SetAngle( Degree( touchEvent->multi.angle ) );
       handler->SendEvent( point, touchEvent->timestamp );
     }
 
@@ -493,7 +517,13 @@ struct EventHandler::Impl
 
     if ( touchEvent->window == handler->mImpl->mWindow )
     {
-      TouchPoint point( touchEvent->multi.device, TouchPoint::Up, touchEvent->x, touchEvent->y );
+      Integration::Point point;
+      point.SetDeviceId( touchEvent->multi.device );
+      point.SetState( PointState::UP );
+      point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
+      point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
+      point.SetPressure( touchEvent->multi.pressure );
+      point.SetAngle( Degree( touchEvent->multi.angle ) );
       handler->SendEvent( point, touchEvent->timestamp );
     }
 
@@ -510,7 +540,13 @@ struct EventHandler::Impl
 
     if ( touchEvent->window == handler->mImpl->mWindow )
     {
-      TouchPoint point( touchEvent->multi.device, TouchPoint::Motion, touchEvent->x, touchEvent->y );
+      Integration::Point point;
+      point.SetDeviceId( touchEvent->multi.device );
+      point.SetState( PointState::MOTION );
+      point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
+      point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
+      point.SetPressure( touchEvent->multi.pressure );
+      point.SetAngle( Degree( touchEvent->multi.angle ) );
       handler->SendEvent( point, touchEvent->timestamp );
     }
 
@@ -620,7 +656,7 @@ struct EventHandler::Impl
       Dali::ImfManager imfManager( ImfManager::Get() );
       if ( imfManager )
       {
-        imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
+        imfContext = ImfManager::GetImplementation( imfManager ).GetContext();
       }
 
       if ( imfContext )
@@ -634,6 +670,11 @@ struct EventHandler::Impl
         ecoreKeyDownEvent.timestamp = keyEvent->timestamp;
         ecoreKeyDownEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
         ecoreKeyDownEvent.locks     = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
+#ifdef ECORE_IMF_1_13
+        ecoreKeyDownEvent.dev_name  = "";
+        ecoreKeyDownEvent.dev_class = ECORE_IMF_DEVICE_CLASS_KEYBOARD;
+        ecoreKeyDownEvent.dev_subclass = ECORE_IMF_DEVICE_SUBCLASS_NONE;
+#endif // ECORE_IMF_1_13
 
         eventHandled = ecore_imf_context_filter_event( imfContext,
                                                        ECORE_IMF_EVENT_KEY_DOWN,
@@ -669,7 +710,7 @@ struct EventHandler::Impl
           keyString = keyEvent->string;
         }
 
-        KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, KeyEvent::Down);
+        Integration::KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DEFAULT_DEVICE_CLASS );
         handler->SendEvent( keyEvent );
       }
     }
@@ -688,19 +729,14 @@ struct EventHandler::Impl
     Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
     bool eventHandled( false );
 
-    // Menu, home, back button must skip ecore_imf_context_filter_event.
-    static const char* menuKeyName = KeyLookup::GetKeyName( DALI_KEY_MENU );
-    static const char* homeKeyName = KeyLookup::GetKeyName( DALI_KEY_HOME );
-    static const char* backKeyName = KeyLookup::GetKeyName( DALI_KEY_BACK );
-    if ( ( menuKeyName && strcmp( keyEvent->keyname, menuKeyName ) != 0 ) &&
-         ( homeKeyName && strcmp( keyEvent->keyname, homeKeyName ) != 0 ) &&
-         ( backKeyName && strcmp( keyEvent->keyname, backKeyName ) != 0 ) )
+    // Device keys like Menu, home, back button must skip ecore_imf_context_filter_event.
+    if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
     {
       Ecore_IMF_Context* imfContext = NULL;
       Dali::ImfManager imfManager( ImfManager::Get() );
       if ( imfManager )
       {
-        imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
+        imfContext = ImfManager::GetImplementation( imfManager ).GetContext();
       }
 
       if ( imfContext )
@@ -714,6 +750,9 @@ struct EventHandler::Impl
         ecoreKeyUpEvent.timestamp = keyEvent->timestamp;
         ecoreKeyUpEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
         ecoreKeyUpEvent.locks     = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
+#ifdef ECORE_IMF_1_13
+        ecoreKeyUpEvent.dev_name  = "";
+#endif // ECORE_IMF_1_13
 
         eventHandled = ecore_imf_context_filter_event( imfContext,
                                                        ECORE_IMF_EVENT_KEY_UP,
@@ -738,9 +777,9 @@ struct EventHandler::Impl
           keyString = keyEvent->string;
         }
 
-        KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, KeyEvent::Up);
-        handler->SendEvent( keyEvent );
+        Integration::KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME, DEFAULT_DEVICE_CLASS );
 
+        handler->SendEvent( keyEvent );
       }
     }
 
@@ -1242,7 +1281,12 @@ struct EventHandler::Impl
   // Callback for Ecore ElDBus accessibility events.
   static void OnEcoreElDBusAccessibilityNotification( void *context EINA_UNUSED, const Eldbus_Message *message )
   {
-    EventHandler* handler( (EventHandler*)context );
+    EventHandler* handler = static_cast< EventHandler* >( context );
+    // Ignore any accessibility events when paused.
+    if( handler->mPaused )
+    {
+      return;
+    }
 
     if ( !handler->mAccessibilityAdaptor )
     {
@@ -1525,6 +1569,7 @@ struct EventHandler::Impl
     Eldbus_Object *object;
     Eldbus_Proxy *manager;
     const char *a11yBusAddress = NULL;
+    EventHandler* handler = static_cast< EventHandler* >( handle );
 
     // The string defines the arg-list's respective types.
     if( !eldbus_message_arguments_get( message, "s", &a11yBusAddress ) )
@@ -1534,9 +1579,9 @@ struct EventHandler::Impl
 
     DALI_LOG_INFO( gImfLogging, Debug::General, "Ecore ElDBus Accessibility address: %s\n", a11yBusAddress );
 
-    Eldbus_Connection *a11yConnection = eldbus_address_connection_get( a11yBusAddress );
+    handler->mImpl->mA11yConnection = eldbus_address_connection_get( a11yBusAddress );
 
-    object = eldbus_object_get( a11yConnection, BUS, PATH );
+    object = eldbus_object_get( handler->mImpl->mA11yConnection, BUS, PATH );
     manager = eldbus_proxy_get( object, INTERFACE );
 
     // Pass the callback data through to the signal handler.
@@ -1639,6 +1684,7 @@ struct EventHandler::Impl
    */
   static void VconfNotifyFontSizeChanged( keynode_t* node, void* data )
   {
+    DALI_LOG_INFO(gTouchEventLogFilter, Debug::Verbose, "VconfNotifyFontSizeChanged\n" );
     EventHandler* handler = static_cast<EventHandler*>( data );
     handler->SendEvent( StyleChange::DEFAULT_FONT_SIZE_CHANGE );
   }
@@ -1649,10 +1695,15 @@ struct EventHandler::Impl
   std::vector<Ecore_Event_Handler*> mEcoreEventHandler;
   Ecore_X_Window mWindow;
   int mXiDeviceId;
+
+#ifdef DALI_ELDBUS_AVAILABLE
+  Eldbus_Connection* mSessionConnection;
+  Eldbus_Connection* mA11yConnection;
+#endif
 };
 
 EventHandler::EventHandler( RenderSurface* surface, CoreEventInterface& coreEventInterface, GestureManager& gestureManager, DamageObserver& damageObserver, DragAndDropDetectorPtr dndDetector )
-: mCoreEventInterface(coreEventInterface),
+: mCoreEventInterface( coreEventInterface ),
   mGestureManager( gestureManager ),
   mStyleMonitor( StyleMonitor::Get() ),
   mDamageObserver( damageObserver ),
@@ -1660,8 +1711,9 @@ EventHandler::EventHandler( RenderSurface* surface, CoreEventInterface& coreEven
   mDragAndDropDetector( dndDetector ),
   mAccessibilityAdaptor( AccessibilityAdaptor::Get() ),
   mClipboardEventNotifier( ClipboardEventNotifier::Get() ),
-  mClipboard(Clipboard::Get()),
-  mImpl( NULL )
+  mClipboard( Clipboard::Get() ),
+  mImpl( NULL ),
+  mPaused( false )
 {
   Ecore_X_Window window = 0;
 
@@ -1678,15 +1730,12 @@ EventHandler::EventHandler( RenderSurface* surface, CoreEventInterface& coreEven
 
 EventHandler::~EventHandler()
 {
-  if(mImpl)
-  {
-    delete mImpl;
-  }
+  delete mImpl;
 
   mGestureManager.Stop();
 }
 
-void EventHandler::SendEvent(TouchPoint& point, unsigned long timeStamp)
+void EventHandler::SendEvent(Integration::Point& point, unsigned long timeStamp)
 {
   if(timeStamp < 1)
   {
@@ -1698,7 +1747,7 @@ void EventHandler::SendEvent(TouchPoint& point, unsigned long timeStamp)
   Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent);
   if(type != Integration::TouchEventCombiner::DispatchNone )
   {
-    DALI_LOG_INFO(gTouchEventLogFilter, Debug::General, "%d: Device %d: Button state %d (%.2f, %.2f)\n", timeStamp, point.deviceId, point.state, point.local.x, point.local.y);
+    DALI_LOG_INFO(gTouchEventLogFilter, Debug::General, "%d: Device %d: Button state %d (%.2f, %.2f)\n", timeStamp, point.GetDeviceId(), point.GetState(), point.GetScreenPosition().x, point.GetScreenPosition().y);
 
     // First the touch and/or hover event & related gesture events are queued
     if(type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth)
@@ -1717,21 +1766,19 @@ void EventHandler::SendEvent(TouchPoint& point, unsigned long timeStamp)
   }
 }
 
-void EventHandler::SendEvent(KeyEvent& keyEvent)
+void EventHandler::SendEvent(Integration::KeyEvent& keyEvent)
 {
   Dali::PhysicalKeyboard physicalKeyboard = PhysicalKeyboard::Get();
   if ( physicalKeyboard )
   {
-    if ( ! KeyLookup::IsDeviceButton( keyEvent.keyPressedName.c_str() ) )
+    if ( ! KeyLookup::IsDeviceButton( keyEvent.keyName.c_str() ) )
     {
       GetImplementation( physicalKeyboard ).KeyReceived( keyEvent.time > 1 );
     }
   }
 
-  // Create KeyEvent and send to Core.
-  Integration::KeyEvent event(keyEvent.keyPressedName, keyEvent.keyPressed, keyEvent.keyCode,
-  keyEvent.keyModifier, keyEvent.time, static_cast<Integration::KeyEvent::State>(keyEvent.state));
-  mCoreEventInterface.QueueCoreEvent( event );
+  // Send to KeyEvent Core.
+  mCoreEventInterface.QueueCoreEvent( keyEvent );
   mCoreEventInterface.ProcessCoreEvents();
 }
 
@@ -1772,7 +1819,9 @@ void EventHandler::SendRotationRequestEvent( )
 
 void EventHandler::FeedTouchPoint( TouchPoint& point, int timeStamp)
 {
-  SendEvent(point, timeStamp);
+  Integration::Point convertedPoint( point );
+
+  SendEvent(convertedPoint, timeStamp);
 }
 
 void EventHandler::FeedWheelEvent( WheelEvent& wheelEvent )
@@ -1782,7 +1831,8 @@ void EventHandler::FeedWheelEvent( WheelEvent& wheelEvent )
 
 void EventHandler::FeedKeyEvent( KeyEvent& event )
 {
-  SendEvent( event );
+  Integration::KeyEvent convertedEvent( event );
+  SendEvent( convertedEvent );
 }
 
 void EventHandler::FeedEvent( Integration::Event& event )
@@ -1797,7 +1847,8 @@ void EventHandler::Reset()
 
   // Any touch listeners should be told of the interruption.
   Integration::TouchEvent event;
-  TouchPoint point(0, TouchPoint::Interrupted, 0, 0);
+  Integration::Point point;
+  point.SetState( PointState::INTERRUPTED );
   event.AddPoint( point );
 
   // First the touch event & related gesture events are queued
@@ -1808,6 +1859,18 @@ void EventHandler::Reset()
   mCoreEventInterface.ProcessCoreEvents();
 }
 
+void EventHandler::Pause()
+{
+  mPaused = true;
+  Reset();
+}
+
+void EventHandler::Resume()
+{
+  mPaused = false;
+  Reset();
+}
+
 void EventHandler::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
 {
   mDragAndDropDetector = detector;