Added key event transfer
authortaeyoon0.lee <taeyoon0.lee@samsung.com>
Wed, 12 Jul 2017 15:08:30 +0000 (00:08 +0900)
committertaeyoon0.lee <taeyoon0.lee@samsung.com>
Thu, 13 Jul 2017 08:40:50 +0000 (17:40 +0900)
 - Added OnKeyEvent
 - Added functions to get keycode

Change-Id: I6e431146ddd1ebfea11d70522debad8162790974

CMakeLists.txt
internal/widget_view/widget_view_impl.cpp
internal/widget_view/widget_view_impl.h

index f7d104f..dcaa1d4 100644 (file)
@@ -18,9 +18,11 @@ pkg_check_modules(viewer_dali REQUIRED
        widget_service
        pkgmgr-info
        capi-system-info
+       dali-core
        dali-adaptor
        dali-toolkit
        cynara-client
+       ecore-wayland
        ecore-input
        tizen-remote-surface-client
        screen_connector_watcher
index 9dbb93e..d78c843 100644 (file)
@@ -23,6 +23,7 @@
 // EXTERNAL INCLUDES
 #include <dali/public-api/common/stage.h>
 #include <dali/public-api/events/touch-data.h>
+#include <dali/public-api/events/key-event.h>
 #include <dali/public-api/events/wheel-event.h>
 #include <dali/public-api/images/native-image.h>
 #include <dali/public-api/object/type-registry.h>
@@ -31,7 +32,9 @@
 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
 #include <dali/integration-api/debug.h>
 #include <dali/devel-api/events/touch-event-devel.h>
+#include <dali/devel-api/events/key-event-devel.h>
 #include <string.h>
+#include <Ecore_Wayland.h>
 #include <Ecore_Input.h>
 #include <widget_service.h>
 #include <widget_instance.h>
@@ -40,6 +43,7 @@
 #include <tbm_surface_internal.h>
 #include <unistd.h>
 #include <libintl.h>
+#include <xkbcommon/xkbcommon.h>
 
 namespace Dali
 {
@@ -114,6 +118,74 @@ const char* const TEXT_POINT_SIZE( "textPointSize" );
 const char* const TEXT_COLOR( "textColor" );
 const char* const TEXT_VISIBLE( "textVisible" ); //ToDo: it should be removed after retry text property is public one
 
+// ToDo: Now dali provides only dali key codes.
+// This funtion will be used to get platform specific key codes from key name
+struct KeyCodeMap
+{
+  xkb_keysym_t keySym;
+  xkb_keycode_t keyCode;
+  bool isKeyCode;
+};
+
+static void FindKeyCode( struct xkb_keymap* keyMap, xkb_keycode_t key, void* data )
+{
+  KeyCodeMap* foundKeyCode = static_cast< KeyCodeMap* >( data );
+  if( foundKeyCode->isKeyCode )
+  {
+    return;
+  }
+
+  xkb_keysym_t keySym = foundKeyCode->keySym;
+  int nsyms = 0;
+  const xkb_keysym_t* symsOut = NULL;
+
+  nsyms = xkb_keymap_key_get_syms_by_level( keyMap, key, 0, 0, &symsOut );
+
+  if( nsyms && symsOut )
+  {
+    if( *symsOut == keySym )
+    {
+      foundKeyCode->keyCode = key;
+      foundKeyCode->isKeyCode = true;
+    }
+  }
+}
+
+static bool GetKeyCode( std::string keyName, int32_t& keyCode )
+{
+  xkb_keymap* keyMap = NULL;
+  Ecore_Wl_Input* ecoreWlInput = NULL;
+  xkb_keysym_t sym = XKB_KEY_NoSymbol;
+  KeyCodeMap foundKeyCode;
+
+  ecoreWlInput = ecore_wl_input_get();
+  if( !ecoreWlInput )
+  {
+    DALI_LOG_ERROR( "Failed to get Ecore_Wl_Input in WidgetView\n" );
+    return false;
+  }
+
+  keyMap = ecore_wl_input_keymap_get( ecoreWlInput );
+  if( !keyMap )
+  {
+    DALI_LOG_ERROR( "Failed to get keymap in WidgetView\n" );
+    return false;
+  }
+
+  sym = xkb_keysym_from_name( keyName.c_str(), XKB_KEYSYM_NO_FLAGS );
+  if( sym == XKB_KEY_NoSymbol )
+  {
+    DALI_LOG_ERROR( "Failed to get keysym in WidgetView\n" );
+    return false;
+  }
+
+  foundKeyCode.keySym = sym;
+  foundKeyCode.isKeyCode = false;
+  xkb_keymap_key_for_each( keyMap, FindKeyCode, &foundKeyCode );
+  keyCode = static_cast< int32_t >( foundKeyCode.keyCode );
+  return true;
+}
+
 static void OnBufferUpdated( struct tizen_remote_surface *surface, uint32_t type, struct wl_buffer *buffer,
                               int32_t img_file_fd, uint32_t img_file_size, uint32_t time, struct wl_array *keys,
                               const char *appid, const char *instance_id, const int pid, void *data)
@@ -941,7 +1013,6 @@ void WidgetView::ConnectSignal( tizen_remote_surface* surface )
     Self().TouchSignal().Connect( this, &WidgetView::OnTouch );
     Self().WheelEventSignal().Connect( this, &WidgetView::OnWheelEvent );
   }
-
 }
 
 bool WidgetView::OnTouch( Dali::Actor actor, const Dali::TouchData& event )
@@ -984,7 +1055,56 @@ bool WidgetView::OnWheelEvent( Dali::Actor actor, const Dali::WheelEvent& event
                                              "",
                                              event.timeStamp
                                            );
-  return true;
+  return false;
+}
+
+bool WidgetView::OnKeyEvent( const Dali::KeyEvent& event )
+{
+  if( mRemoteSurface == NULL )
+  {
+    return false;
+  }
+
+  tizen_remote_surface_event_type type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_NONE;
+
+  switch( event.state )
+  {
+    case Dali::KeyEvent::Down:
+    {
+      type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_KEY_DOWN;
+      break;
+    }
+    case Dali::KeyEvent::Up:
+    {
+      type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_KEY_UP;
+      break;
+    }
+    case Dali::KeyEvent::Last:
+    {
+      break;
+    }
+    default:
+    {
+      return false;
+    }
+  }
+
+  int32_t keyCode;
+  if( GetKeyCode( event.keyPressedName, keyCode ) == false )
+  {
+    return false;
+  }
+
+  tizen_remote_surface_transfer_key_event( mRemoteSurface,
+                                           type,
+                                           keyCode,
+                                           Dali::DevelKeyEvent::GetDeviceClass( event ),
+                                           Dali::DevelKeyEvent::GetDeviceSubclass( event ),
+                                           "",
+                                           static_cast< uint32_t >( event.time )
+                                         );
+
+  return false;
 }
 
 Vector3 WidgetView::GetNaturalSize()
index 3d64bed..8d66248 100644 (file)
@@ -243,6 +243,11 @@ private: // From Control
   virtual void OnSizeSet( const Vector3& targetSize );
 
   /**
+   * @copydoc Toolkit::Control::OnKeyEvent()
+   */
+  virtual bool OnKeyEvent( const KeyEvent& event );
+
+  /**
    * @copydoc Toolkit::Control::GetNaturalSize
    */
   virtual Vector3 GetNaturalSize();