Merge "[3.0] Add Privilege doxygen tags" into tizen
[platform/core/uifw/dali-adaptor.git] / adaptors / ecore / wayland / event-handler-ecore-wl.cpp
index c32bec4..6d29d80 100644 (file)
@@ -49,6 +49,7 @@
 #include <physical-keyboard-impl.h>
 #include <style-monitor-impl.h>
 #include <base/core-event-interface.h>
+#include <virtual-keyboard.h>
 
 namespace Dali
 {
@@ -184,10 +185,21 @@ struct EventHandler::Impl
       // Register Mouse wheel events
       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_WHEEL,        EcoreEventMouseWheel,      handler ) );
 
+      // Register Focus events
+      mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_IN,  EcoreEventWindowFocusIn,   handler ) );
+      mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_OUT, EcoreEventWindowFocusOut,  handler ) );
+
       // Register Key events
       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_DOWN,           EcoreEventKeyDown,         handler ) );
       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_UP,             EcoreEventKeyUp,           handler ) );
 
+      // Register Selection event - clipboard selection
+      mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_DATA_SOURCE_SEND, EcoreEventDataSend, handler ) );
+      mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_SELECTION_DATA_READY, EcoreEventDataReceive, handler ) );
+
+      // Register Detent event
+      mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_DETENT_ROTATE, EcoreEventDetent, handler) );
+
 #ifndef DALI_PROFILE_UBUNTU
       // Register Vconf notify - font name and size
       vconf_notify_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontNameChanged, handler );
@@ -228,17 +240,23 @@ struct EventHandler::Impl
 
     if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(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 );
     }
 
@@ -255,7 +273,13 @@ struct EventHandler::Impl
 
     if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(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 );
     }
 
@@ -290,7 +314,13 @@ struct EventHandler::Impl
 
     if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(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 );
     }
 
@@ -358,10 +388,10 @@ struct EventHandler::Impl
       {
         std::string keyName( keyEvent->keyname );
         std::string keyString( "" );
-        int keyCode = 0/*ecore_x_keysym_keycode_get(keyEvent->keyname)*/;
+        int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname);
+        keyCode = (keyCode == -1) ? 0 : keyCode;
         int modifier( keyEvent->modifiers );
         unsigned long time = keyEvent->timestamp;
-
         if (!strncmp(keyEvent->keyname, "Keycode-", 8))
           keyCode = atoi(keyEvent->keyname + 8);
 
@@ -384,19 +414,14 @@ struct EventHandler::Impl
    */
   static Eina_Bool EcoreEventKeyUp( void* data, int type, void* event )
   {
-    DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyUp \n" );
+    DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyUp\n" );
 
     EventHandler* handler( (EventHandler*)data );
     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() );
@@ -430,10 +455,10 @@ struct EventHandler::Impl
       {
         std::string keyName( keyEvent->keyname );
         std::string keyString( "" );
-        int keyCode = 0/*ecore_x_keysym_keycode_get(keyEvent->keyname)*/;
+        int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname);
+        keyCode = (keyCode == -1) ? 0 : keyCode;
         int modifier( keyEvent->modifiers );
-        unsigned long time( keyEvent->timestamp );
-
+        unsigned long time = keyEvent->timestamp;
         if (!strncmp(keyEvent->keyname, "Keycode-", 8))
           keyCode = atoi(keyEvent->keyname + 8);
 
@@ -482,7 +507,8 @@ struct EventHandler::Impl
           }
         }
       }
-      // No need to connect callbacks as KeyboardStatusChanged will be called.
+      Dali::Clipboard clipboard = Clipboard::Get();
+      clipboard.HideClipboard();
     }
 
     return ECORE_CALLBACK_PASS_ON;
@@ -514,9 +540,13 @@ struct EventHandler::Impl
         }
       }
 
-      // Clipboard don't support that whether clipboard is shown or not. Hide clipboard.
+      // Hiding clipboard event will be ignored once because window focus out event is always received on showing clipboard
       Dali::Clipboard clipboard = Clipboard::Get();
-      clipboard.HideClipboard();
+      if ( clipboard )
+      {
+        Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
+        clipBoardImpl.HideClipboard(true);
+      }
     }
 
     return ECORE_CALLBACK_PASS_ON;
@@ -631,6 +661,65 @@ struct EventHandler::Impl
     return ECORE_CALLBACK_PASS_ON;
   }
 
+  /**
+  * Called when the source window notifies us the content in clipboard is selected.
+  */
+  static Eina_Bool EcoreEventDataSend( void* data, int type, void* event )
+  {
+    DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDataSend\n" );
+
+    Dali::Clipboard clipboard = Clipboard::Get();
+    if ( clipboard )
+    {
+      Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
+      clipBoardImpl.ExcuteBuffered( true, event );
+    }
+    return ECORE_CALLBACK_PASS_ON;
+  }
+
+   /**
+    * Called when the source window sends us about the selected content.
+    * For example, when item is selected in the clipboard.
+    */
+   static Eina_Bool EcoreEventDataReceive( void* data, int type, void* event )
+   {
+     DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDataReceive\n" );
+
+     EventHandler* handler( (EventHandler*)data );
+      Dali::Clipboard clipboard = Clipboard::Get();
+      char *selectionData = NULL;
+      if ( clipboard )
+      {
+        Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
+        selectionData = clipBoardImpl.ExcuteBuffered( false, event );
+      }
+      if ( selectionData && handler->mClipboardEventNotifier )
+      {
+        ClipboardEventNotifier& clipboardEventNotifier( ClipboardEventNotifier::GetImplementation( handler->mClipboardEventNotifier ) );
+        std::string content( selectionData, strlen(selectionData) );
+
+        clipboardEventNotifier.SetContent( content );
+        clipboardEventNotifier.EmitContentSelectedSignal();
+      }
+     return ECORE_CALLBACK_PASS_ON;
+   }
+
+  /*
+  * Called when detent event is recevied
+  */
+  static Eina_Bool EcoreEventDetent( void* data, int type, void* event )
+  {
+    DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDetent\n" );
+    EventHandler* handler( (EventHandler*)data );
+    Ecore_Event_Detent_Rotate *e((Ecore_Event_Detent_Rotate *)event);
+    int direction = (e->direction == ECORE_DETENT_DIRECTION_CLOCKWISE) ? 1 : -1;
+    int timeStamp = e->timestamp;
+
+    WheelEvent wheelEvent( WheelEvent::CUSTOM_WHEEL, 0, 0, Vector2(0.0f, 0.0f), direction, timeStamp );
+    handler->SendWheelEvent( wheelEvent );
+    return ECORE_CALLBACK_PASS_ON;
+  }
+
   /////////////////////////////////////////////////////////////////////////////////////////////////
   // Font Callbacks
   /////////////////////////////////////////////////////////////////////////////////////////////////
@@ -692,7 +781,7 @@ EventHandler::~EventHandler()
   mGestureManager.Stop();
 }
 
-void EventHandler::SendEvent(TouchPoint& point, unsigned long timeStamp)
+void EventHandler::SendEvent(Integration::Point& point, unsigned long timeStamp)
 {
   if(timeStamp < 1)
   {
@@ -778,7 +867,8 @@ 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 )
@@ -803,7 +893,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