[dali_2.3.29] Merge branch 'devel/master'
[platform/core/uifw/dali-adaptor.git] / dali / internal / input / ubuntu-x11 / input-method-context-impl-x.cpp
old mode 100755 (executable)
new mode 100644 (file)
index 60cba35..0460378
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019 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/internal/input/ubuntu-x11/input-method-context-impl-x.h>
 
 // EXTERNAL INCLUDES
-#include <dali/internal/input/linux/dali-ecore-imf.h>
-#include <dali/internal/input/ubuntu-x11/dali-ecore-input.h>
+#include <dali/devel-api/common/singleton-service.h>
+#include <dali/integration-api/debug.h>
 #include <dali/public-api/events/key-event.h>
-#include <dali/public-api/adaptor-framework/key.h>
 #include <dali/public-api/object/type-registry.h>
-#include <dali/integration-api/debug.h>
 
 // INTERNAL INCLUDES
-#include <dali/integration-api/adaptor.h>
+#include <dali/integration-api/adaptor-framework/adaptor.h>
 #include <dali/internal/adaptor/common/adaptor-impl.h>
-#include <dali/internal/system/common/locale-utils.h>
-#include <dali/internal/system/common/singleton-service-impl.h>
-#include <dali/internal/input/common/virtual-keyboard-impl.h>
 #include <dali/internal/input/common/key-impl.h>
-#include <dali/internal/input/tizen-wayland/ecore-virtual-keyboard.h>
+#include <dali/internal/input/common/virtual-keyboard-impl.h>
+#include <dali/internal/input/linux/dali-ecore-imf.h>
+#include <dali/internal/input/ubuntu-x11/dali-ecore-input.h>
+#include <dali/internal/system/common/locale-utils.h>
+#include <dali/internal/system/linux/dali-ecore.h>
+#include <dali/public-api/adaptor-framework/key.h>
 
 namespace Dali
 {
-
 namespace Internal
 {
-
 namespace Adaptor
 {
-
 namespace
 {
 #if defined(DEBUG_ENABLED)
@@ -55,51 +52,59 @@ size_t Utf8SequenceLength(const unsigned char leadByte)
 {
   size_t length = 0;
 
-  if ((leadByte & 0x80) == 0 )          //ASCII character (lead bit zero)
+  if((leadByte & 0x80) == 0) //ASCII character (lead bit zero)
   {
     length = 1;
   }
-  else if (( leadByte & 0xe0 ) == 0xc0 ) //110x xxxx
+  else if((leadByte & 0xe0) == 0xc0) //110x xxxx
   {
     length = 2;
   }
-  else if (( leadByte & 0xf0 ) == 0xe0 ) //1110 xxxx
+  else if((leadByte & 0xf0) == 0xe0) //1110 xxxx
   {
     length = 3;
   }
-  else if (( leadByte & 0xf8 ) == 0xf0 ) //1111 0xxx
+  else if((leadByte & 0xf8) == 0xf0) //1111 0xxx
   {
     length = 4;
   }
+  else if((leadByte & 0xfc) == 0xf8) //1111 10xx
+  {
+    length = 5;
+  }
+  else if((leadByte & 0xfe) == 0xfc) //1111 110x
+  {
+    length = 6;
+  }
 
   return length;
 }
 
 // Static function calls used by ecore 'c' style callback registration
-void Commit( void *data, Ecore_IMF_Context *imfContext, void *eventInfo )
+void Commit(void* data, Ecore_IMF_Context* imfContext, void* eventInfo)
 {
-  if ( data )
+  if(data)
   {
-    InputMethodContextX* inputMethodContext = reinterpret_cast< InputMethodContextX* > ( data );
-    inputMethodContext->CommitReceived( data, imfContext, eventInfo );
+    InputMethodContextX* inputMethodContext = static_cast<InputMethodContextX*>(data);
+    inputMethodContext->CommitReceived(data, imfContext, eventInfo);
   }
 }
 
-void PreEdit( void *data, Ecore_IMF_Context *imfContext, void *eventInfo )
+void PreEdit(void* data, Ecore_IMF_Context* imfContext, void* eventInfo)
 {
-  if ( data )
+  if(data)
   {
-    InputMethodContextX* inputMethodContext = reinterpret_cast< InputMethodContextX* > ( data );
-    inputMethodContext->PreEditChanged( data, imfContext, eventInfo );
+    InputMethodContextX* inputMethodContext = static_cast<InputMethodContextX*>(data);
+    inputMethodContext->PreEditChanged(data, imfContext, eventInfo);
   }
 }
 
-Eina_Bool ImfRetrieveSurrounding(void *data, Ecore_IMF_Context *imfContext, char** text, int* cursorPosition )
+Eina_Bool ImfRetrieveSurrounding(void* data, Ecore_IMF_Context* imfContext, char** text, int* cursorPosition)
 {
-  if ( data )
+  if(data)
   {
-    InputMethodContextX* inputMethodContext = reinterpret_cast< InputMethodContextX* > ( data );
-    return inputMethodContext->RetrieveSurrounding( data, imfContext, text, cursorPosition );
+    InputMethodContextX* inputMethodContext = static_cast<InputMethodContextX*>(data);
+    return inputMethodContext->RetrieveSurrounding(data, imfContext, text, cursorPosition);
   }
   else
   {
@@ -111,42 +116,24 @@ Eina_Bool ImfRetrieveSurrounding(void *data, Ecore_IMF_Context *imfContext, char
  * Called when an InputMethodContext delete surrounding event is received.
  * Here we tell the application that it should delete a certain range.
  */
-void ImfDeleteSurrounding( void *data, Ecore_IMF_Context *imfContext, void *eventInfo )
+void ImfDeleteSurrounding(void* data, Ecore_IMF_Context* imfContext, void* eventInfo)
 {
-  if ( data )
+  if(data)
   {
-    InputMethodContextX* inputMethodContext = reinterpret_cast< InputMethodContextX* > ( data );
-    inputMethodContext->DeleteSurrounding( data, imfContext, eventInfo );
+    InputMethodContextX* inputMethodContext = static_cast<InputMethodContextX*>(data);
+    inputMethodContext->DeleteSurrounding(data, imfContext, eventInfo);
   }
 }
 
 } // unnamed namespace
 
-InputMethodContextPtr InputMethodContextX::New()
+InputMethodContextPtr InputMethodContextX::New(Dali::Actor actor)
 {
   InputMethodContextPtr manager;
 
-  if ( Adaptor::IsAvailable() )
+  if(actor && Dali::Adaptor::IsAvailable())
   {
-    // Create instance and register singleton only if the adaptor is available
-    Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) );
-    Any nativeWindow = adaptorImpl.GetNativeWindowHandle();
-
-    // The Ecore_X_Window needs to use the InputMethodContext.
-    // Only when the render surface is window, we can get the Ecore_X_Window.
-    Ecore_X_Window ecoreXwin( AnyCast<Ecore_X_Window>(nativeWindow) );
-    if (ecoreXwin)
-    {
-      // If we fail to get Ecore_X_Window, we can't use the InputMethodContext correctly.
-      // Thus you have to call "ecore_imf_context_client_window_set" somewhere.
-      // In EvasPlugIn, this function is called in EvasPlugin::ConnectEcoreEvent().
-
-      manager = new InputMethodContextX( ecoreXwin );
-    }
-    else
-    {
-      DALI_LOG_ERROR("Failed to get native window handle\n");
-    }
+    manager = new InputMethodContextX(actor);
   }
 
   return manager;
@@ -154,21 +141,22 @@ InputMethodContextPtr InputMethodContextX::New()
 
 void InputMethodContextX::Finalize()
 {
-  DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::Finalize\n" );
-  VirtualKeyboard::DisconnectCallbacks( mIMFContext );
+  DALI_LOG_INFO(gLogFilter, Debug::General, "InputMethodContextX::Finalize\n");
   DisconnectCallbacks();
   DeleteContext();
 }
 
-InputMethodContextX::InputMethodContextX( Ecore_X_Window ecoreXwin )
+InputMethodContextX::InputMethodContextX(Dali::Actor actor)
 : mIMFContext(),
-  mEcoreXwin( ecoreXwin ),
-  mIMFCursorPosition( 0 ),
+  mEcoreXwin(0),
+  mIMFCursorPosition(0),
   mSurroundingText(),
-  mRestoreAfterFocusLost( false ),
-  mIdleCallbackConnected( false )
+  mRestoreAfterFocusLost(false),
+  mIdleCallbackConnected(false)
 {
   ecore_imf_init();
+
+  actor.OnSceneSignal().Connect(this, &InputMethodContextX::OnStaged);
 }
 
 InputMethodContextX::~InputMethodContextX()
@@ -179,45 +167,46 @@ InputMethodContextX::~InputMethodContextX()
 
 void InputMethodContextX::Initialize()
 {
-  CreateContext( mEcoreXwin );
+  CreateContext();
   ConnectCallbacks();
-  VirtualKeyboard::ConnectCallbacks( mIMFContext );
 }
 
-void InputMethodContextX::CreateContext( Ecore_X_Window ecoreXwin )
+void InputMethodContextX::CreateContext()
 {
-  DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::CreateContext\n" );
+  DALI_LOG_INFO(gLogFilter, Debug::General, "InputMethodContextX::CreateContext\n");
+
+  if(!mEcoreXwin)
+  {
+    return;
+  }
 
-  const char *contextId = ecore_imf_context_default_id_get();
-  if( contextId )
+  const charcontextId = ecore_imf_context_default_id_get();
+  if(contextId)
   {
-    mIMFContext = ecore_imf_context_add( contextId );
+    mIMFContext = ecore_imf_context_add(contextId);
 
-    if( mIMFContext )
+    if(mIMFContext)
     {
-      if( ecoreXwin )
-      {
-        ecore_imf_context_client_window_set( mIMFContext, reinterpret_cast<void*>( ecoreXwin ) );
-      }
+      ecore_imf_context_client_window_set(mIMFContext, reinterpret_cast<void*>(mEcoreXwin));
     }
     else
     {
-      DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContext Unable to get IMFContext\n");
+      DALI_LOG_INFO(gLogFilter, Debug::General, "InputMethodContext Unable to get IMFContext\n");
     }
   }
   else
   {
-    DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContext Unable to get IMFContext\n");
+    DALI_LOG_INFO(gLogFilter, Debug::General, "InputMethodContext Unable to get IMFContext\n");
   }
 }
 
 void InputMethodContextX::DeleteContext()
 {
-  DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::DeleteContext\n" );
+  DALI_LOG_INFO(gLogFilter, Debug::General, "InputMethodContextX::DeleteContext\n");
 
-  if ( mIMFContext )
+  if(mIMFContext)
   {
-    ecore_imf_context_del( mIMFContext );
+    ecore_imf_context_del(mIMFContext);
     mIMFContext = NULL;
   }
 }
@@ -225,27 +214,27 @@ void InputMethodContextX::DeleteContext()
 // Callbacks for predicitive text support.
 void InputMethodContextX::ConnectCallbacks()
 {
-  if ( mIMFContext )
+  if(mIMFContext)
   {
-    DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::ConnectCallbacks\n" );
+    DALI_LOG_INFO(gLogFilter, Debug::General, "InputMethodContextX::ConnectCallbacks\n");
 
-    ecore_imf_context_event_callback_add( mIMFContext, ECORE_IMF_CALLBACK_PREEDIT_CHANGED,    PreEdit,    this );
-    ecore_imf_context_event_callback_add( mIMFContext, ECORE_IMF_CALLBACK_COMMIT,             Commit,     this );
-    ecore_imf_context_event_callback_add( mIMFContext, ECORE_IMF_CALLBACK_DELETE_SURROUNDING, ImfDeleteSurrounding, this );
+    ecore_imf_context_event_callback_add(mIMFContext, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, PreEdit, this);
+    ecore_imf_context_event_callback_add(mIMFContext, ECORE_IMF_CALLBACK_COMMIT, Commit, this);
+    ecore_imf_context_event_callback_add(mIMFContext, ECORE_IMF_CALLBACK_DELETE_SURROUNDING, ImfDeleteSurrounding, this);
 
-    ecore_imf_context_retrieve_surrounding_callback_set( mIMFContext, ImfRetrieveSurrounding, this);
+    ecore_imf_context_retrieve_surrounding_callback_set(mIMFContext, ImfRetrieveSurrounding, this);
   }
 }
 
 void InputMethodContextX::DisconnectCallbacks()
 {
-  if ( mIMFContext )
+  if(mIMFContext)
   {
-    DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::DisconnectCallbacks\n" );
+    DALI_LOG_INFO(gLogFilter, Debug::General, "InputMethodContextX::DisconnectCallbacks\n");
 
-    ecore_imf_context_event_callback_del( mIMFContext, ECORE_IMF_CALLBACK_PREEDIT_CHANGED,    PreEdit );
-    ecore_imf_context_event_callback_del( mIMFContext, ECORE_IMF_CALLBACK_COMMIT,             Commit );
-    ecore_imf_context_event_callback_del( mIMFContext, ECORE_IMF_CALLBACK_DELETE_SURROUNDING, ImfDeleteSurrounding );
+    ecore_imf_context_event_callback_del(mIMFContext, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, PreEdit);
+    ecore_imf_context_event_callback_del(mIMFContext, ECORE_IMF_CALLBACK_COMMIT, Commit);
+    ecore_imf_context_event_callback_del(mIMFContext, ECORE_IMF_CALLBACK_DELETE_SURROUNDING, ImfDeleteSurrounding);
 
     // We do not need to unset the retrieve surrounding callback.
   }
@@ -256,26 +245,26 @@ void InputMethodContextX::Activate()
   // Reset mIdleCallbackConnected
   mIdleCallbackConnected = false;
 
-  if ( mIMFContext )
+  if(mIMFContext)
   {
-    DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::Activate\n" );
+    DALI_LOG_INFO(gLogFilter, Debug::General, "InputMethodContextX::Activate\n");
 
-    ecore_imf_context_focus_in( mIMFContext );
+    ecore_imf_context_focus_in(mIMFContext);
 
     // emit keyboard activated signal
-    Dali::InputMethodContext handle( this );
-    mActivatedSignal.Emit( handle );
+    Dali::InputMethodContext handle(this);
+    mActivatedSignal.Emit(handle);
   }
 }
 
 void InputMethodContextX::Deactivate()
 {
-  if( mIMFContext )
+  if(mIMFContext)
   {
-    DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::Deactivate\n" );
+    DALI_LOG_INFO(gLogFilter, Debug::General, "InputMethodContextX::Deactivate\n");
 
     Reset();
-    ecore_imf_context_focus_out( mIMFContext );
+    ecore_imf_context_focus_out(mIMFContext);
   }
 
   // Reset mIdleCallbackConnected
@@ -284,17 +273,17 @@ void InputMethodContextX::Deactivate()
 
 void InputMethodContextX::Reset()
 {
-  DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::Reset\n" );
+  DALI_LOG_INFO(gLogFilter, Debug::General, "InputMethodContextX::Reset\n");
 
-  if ( mIMFContext )
+  if(mIMFContext)
   {
-    ecore_imf_context_reset( mIMFContext );
+    ecore_imf_context_reset(mIMFContext);
   }
 }
 
 ImfContext* InputMethodContextX::GetContext()
 {
-  DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetContext\n" );
+  DALI_LOG_INFO(gLogFilter, Debug::General, "InputMethodContextX::GetContext\n");
 
   return mIMFContext;
 }
@@ -304,7 +293,7 @@ bool InputMethodContextX::RestoreAfterFocusLost() const
   return mRestoreAfterFocusLost;
 }
 
-void InputMethodContextX::SetRestoreAfterFocusLost( bool toggle )
+void InputMethodContextX::SetRestoreAfterFocusLost(bool toggle)
 {
   mRestoreAfterFocusLost = toggle;
 }
@@ -314,98 +303,150 @@ void InputMethodContextX::SetRestoreAfterFocusLost( bool toggle )
  * We are still predicting what the user is typing.  The latest string is what the InputMethodContext module thinks
  * the user wants to type.
  */
-void InputMethodContextX::PreEditChanged( void*, ImfContext* imfContext, void* eventInfo )
+void InputMethodContextX::PreEditChanged(void*, ImfContext* imfContext, void* eventInfo)
 {
-  DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::PreEditChanged\n" );
-  auto context = reinterpret_cast<Ecore_IMF_Context*>(imfContext);
+  DALI_LOG_INFO(gLogFilter, Debug::General, "InputMethodContextX::PreEditChanged\n");
+  auto context = static_cast<Ecore_IMF_Context*>(imfContext);
 
-  char* preEditString( NULL );
-  int cursorPosition( 0 );
+  char*      preEditString(NULL);
+  int        cursorPosition(0);
   Eina_List* attrs = NULL;
-  Eina_List* l = NULL;
+  Eina_List* l     = NULL;
 
   Ecore_IMF_Preedit_Attr* attr;
 
+  mPreeditAttrs.Clear();
+
   // Retrieves attributes as well as the string the cursor position offset from start of pre-edit string.
   // the attributes (attrs) is used in languages that use the soft arrows keys to insert characters into a current pre-edit string.
-  ecore_imf_context_preedit_string_with_attributes_get( context, &preEditString, &attrs, &cursorPosition );
+  ecore_imf_context_preedit_string_with_attributes_get(context, &preEditString, &attrs, &cursorPosition);
 
-  if ( attrs )
+  if(attrs)
   {
     // iterate through the list of attributes getting the type, start and end position.
-    for ( l = attrs, (attr =  static_cast<Ecore_IMF_Preedit_Attr*>( eina_list_data_get(l) ) ); l; l = eina_list_next(l), ( attr = static_cast<Ecore_IMF_Preedit_Attr*>( eina_list_data_get(l) ) ))
+    for(l = attrs, (attr = static_cast<Ecore_IMF_Preedit_Attr*>(eina_list_data_get(l))); l; l = eina_list_next(l), (attr = static_cast<Ecore_IMF_Preedit_Attr*>(eina_list_data_get(l))))
     {
-#ifdef DALI_PROFILE_UBUNTU
-      if ( attr->preedit_type == ECORE_IMF_PREEDIT_TYPE_SUB3 ) // (Ecore_IMF)
-#else // DALI_PROFILE_UBUNTU
-      if ( attr->preedit_type == ECORE_IMF_PREEDIT_TYPE_SUB4 ) // (Ecore_IMF)
-#endif // DALI_PROFILE_UBUNTU
+      Dali::InputMethodContext::PreeditAttributeData data;
+      data.startIndex = 0;
+      data.endIndex   = 0;
+
+      size_t visualCharacterIndex = 0;
+      size_t byteIndex            = 0;
+
+      // iterate through null terminated string checking each character's position against the given byte position ( attr->end_index ).
+      char leadByte = preEditString[byteIndex];
+
+      while(leadByte != '\0')
       {
-        // check first byte so know how many bytes a character is represented by as keyboard returns cursor position in bytes. Which is different for some languages.
+        leadByte = preEditString[byteIndex]; // Update the character to get the number of its byte
 
-        size_t visualCharacterIndex = 0;
-        size_t byteIndex = 0;
+        // attr->end_index is provided as a byte position not character and we need to know the character position.
+        const size_t currentSequenceLength = Utf8SequenceLength(leadByte); // returns number of bytes used to represent character.
+        if(byteIndex <= attr->start_index)
+        {
+          data.startIndex = visualCharacterIndex;
+        }
+        if(byteIndex >= attr->end_index)
+        {
+          data.endIndex = visualCharacterIndex;
+          break;
+          // end loop as found cursor position that matches byte position
+        }
+        else
+        {
+          byteIndex += currentSequenceLength; // jump to next character
+          visualCharacterIndex++;             // increment character count so we know our position for when we get a match
+        }
+      }
 
-        // iterate through null terminated string checking each character's position against the given byte position ( attr->end_index ).
-        const char leadByte = preEditString[byteIndex];
-        while( leadByte != '\0' )
+      switch(attr->preedit_type)
+      {
+        case ECORE_IMF_PREEDIT_TYPE_NONE:
+        {
+          data.preeditType = Dali::InputMethodContext::PreeditStyle::NONE;
+          break;
+        }
+        case ECORE_IMF_PREEDIT_TYPE_SUB1:
+        {
+          data.preeditType = Dali::InputMethodContext::PreeditStyle::UNDERLINE;
+          break;
+        }
+        case ECORE_IMF_PREEDIT_TYPE_SUB2:
         {
-          // attr->end_index is provided as a byte position not character and we need to know the character position.
-          const size_t currentSequenceLength = Utf8SequenceLength( leadByte ); // returns number of bytes used to represent character.
-          if ( byteIndex == attr->end_index )
-          {
-            cursorPosition = static_cast<int>( visualCharacterIndex );
-            break;
-            // end loop as found cursor position that matches byte position
-          }
-          else
-          {
-            byteIndex += currentSequenceLength; // jump to next character
-            visualCharacterIndex++;  // increment character count so we know our position for when we get a match
-          }
-
-          DALI_ASSERT_DEBUG( visualCharacterIndex < strlen( preEditString ));
+          data.preeditType = Dali::InputMethodContext::PreeditStyle::REVERSE;
+          break;
+        }
+        case ECORE_IMF_PREEDIT_TYPE_SUB3:
+        {
+          data.preeditType = Dali::InputMethodContext::PreeditStyle::HIGHLIGHT;
+          break;
+        }
+        case ECORE_IMF_PREEDIT_TYPE_SUB4:
+        {
+          data.preeditType = Dali::InputMethodContext::PreeditStyle::CUSTOM_PLATFORM_STYLE_1;
+          break;
+        }
+        case ECORE_IMF_PREEDIT_TYPE_SUB5:
+        {
+          data.preeditType = Dali::InputMethodContext::PreeditStyle::CUSTOM_PLATFORM_STYLE_2;
+          break;
+        }
+        case ECORE_IMF_PREEDIT_TYPE_SUB6:
+        {
+          data.preeditType = Dali::InputMethodContext::PreeditStyle::CUSTOM_PLATFORM_STYLE_3;
+          break;
+        }
+        case ECORE_IMF_PREEDIT_TYPE_SUB7:
+        {
+          data.preeditType = Dali::InputMethodContext::PreeditStyle::CUSTOM_PLATFORM_STYLE_4;
+          break;
+        }
+        default:
+        {
+          data.preeditType = Dali::InputMethodContext::PreeditStyle::NONE;
+          break;
         }
       }
+      mPreeditAttrs.PushBack(data);
     }
   }
 
-  if ( Dali::Adaptor::IsAvailable() )
+  if(Dali::Adaptor::IsAvailable())
   {
-    Dali::InputMethodContext handle( this );
-    Dali::InputMethodContext::EventData eventData( Dali::InputMethodContext::PRE_EDIT, preEditString, cursorPosition, 0 );
-    Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit( handle, eventData );
+    Dali::InputMethodContext               handle(this);
+    Dali::InputMethodContext::EventData    eventData(Dali::InputMethodContext::PRE_EDIT, preEditString, cursorPosition, 0);
+    Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit(handle, eventData);
 
-    if( callbackData.update )
+    if(callbackData.update)
     {
-      mIMFCursorPosition = static_cast<int>( callbackData.cursorPosition );
+      mIMFCursorPosition = static_cast<int>(callbackData.cursorPosition);
 
       NotifyCursorPosition();
     }
 
-    if( callbackData.preeditResetRequired )
+    if(callbackData.preeditResetRequired)
     {
       Reset();
     }
   }
-  free( preEditString );
+  free(preEditString);
 }
 
-void InputMethodContextX::CommitReceived( void*, ImfContext* imfContext, void* eventInfo )
+void InputMethodContextX::CommitReceived(void*, ImfContext* imfContext, void* eventInfo)
 {
-  DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::CommitReceived\n" );
+  DALI_LOG_INFO(gLogFilter, Debug::General, "InputMethodContextX::CommitReceived\n");
 
-  if ( Dali::Adaptor::IsAvailable() )
+  if(Dali::Adaptor::IsAvailable())
   {
-    const std::string keyString( static_cast<char*>( eventInfo ) );
+    const std::string keyString(static_cast<char*>(eventInfo));
 
-    Dali::InputMethodContext handle( this );
-    Dali::InputMethodContext::EventData eventData( Dali::InputMethodContext::COMMIT, keyString, 0, 0 );
-    Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit( handle, eventData );
+    Dali::InputMethodContext               handle(this);
+    Dali::InputMethodContext::EventData    eventData(Dali::InputMethodContext::COMMIT, keyString, 0, 0);
+    Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit(handle, eventData);
 
-    if( callbackData.update )
+    if(callbackData.update)
     {
-      mIMFCursorPosition = static_cast<int>( callbackData.cursorPosition );
+      mIMFCursorPosition = static_cast<int>(callbackData.cursorPosition);
 
       NotifyCursorPosition();
     }
@@ -417,25 +458,25 @@ void InputMethodContextX::CommitReceived( void*, ImfContext* imfContext, void* e
  * Here the InputMethodContext module wishes to know the string we are working with and where within the string the cursor is
  * We need to signal the application to tell us this information.
  */
-bool InputMethodContextX::RetrieveSurrounding( void* data, ImfContext* imfContext, char** text, int* cursorPosition )
+bool InputMethodContextX::RetrieveSurrounding(void* data, ImfContext* imfContext, char** text, int* cursorPosition)
 {
-  DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::RetrieveSurrounding\n" );
+  DALI_LOG_INFO(gLogFilter, Debug::General, "InputMethodContextX::RetrieveSurrounding\n");
 
-  Dali::InputMethodContext::EventData imfData( Dali::InputMethodContext::GET_SURROUNDING, std::string(), 0, 0 );
-  Dali::InputMethodContext handle( this );
-  Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit( handle, imfData );
+  Dali::InputMethodContext::EventData    imfData(Dali::InputMethodContext::GET_SURROUNDING, std::string(), 0, 0);
+  Dali::InputMethodContext               handle(this);
+  Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit(handle, imfData);
 
-  if( callbackData.update )
+  if(callbackData.update)
   {
-    if( text )
+    if(text)
     {
-      *text = strdup( callbackData.currentText.c_str() );
+      *text = strdup(callbackData.currentText.c_str());
     }
 
-    if( cursorPosition )
+    if(cursorPosition)
     {
-      mIMFCursorPosition = static_cast<int>( callbackData.cursorPosition );
-      *cursorPosition = mIMFCursorPosition;
+      mIMFCursorPosition = static_cast<int>(callbackData.cursorPosition);
+      *cursorPosition    = mIMFCursorPosition;
     }
   }
 
@@ -446,21 +487,21 @@ bool InputMethodContextX::RetrieveSurrounding( void* data, ImfContext* imfContex
  * Called when an InputMethodContext delete surrounding event is received.
  * Here we tell the application that it should delete a certain range.
  */
-void InputMethodContextX::DeleteSurrounding( void* data, ImfContext* imfContext, void* eventInfo )
+void InputMethodContextX::DeleteSurrounding(void* data, ImfContext* imfContext, void* eventInfo)
 {
-  DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::DeleteSurrounding\n" );
+  DALI_LOG_INFO(gLogFilter, Debug::General, "InputMethodContextX::DeleteSurrounding\n");
 
-  if( Dali::Adaptor::IsAvailable() )
+  if(Dali::Adaptor::IsAvailable())
   {
-    Ecore_IMF_Event_Delete_Surrounding* deleteSurroundingEvent = static_cast<Ecore_IMF_Event_Delete_Surrounding*>( eventInfo );
+    Ecore_IMF_Event_Delete_Surrounding* deleteSurroundingEvent = static_cast<Ecore_IMF_Event_Delete_Surrounding*>(eventInfo);
 
-    Dali::InputMethodContext::EventData imfData( Dali::InputMethodContext::DELETE_SURROUNDING, std::string(), deleteSurroundingEvent->offset, deleteSurroundingEvent->n_chars );
-    Dali::InputMethodContext handle( this );
-    Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit( handle, imfData );
+    Dali::InputMethodContext::EventData    imfData(Dali::InputMethodContext::DELETE_SURROUNDING, std::string(), deleteSurroundingEvent->offset, deleteSurroundingEvent->n_chars);
+    Dali::InputMethodContext               handle(this);
+    Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit(handle, imfData);
 
-    if( callbackData.update )
+    if(callbackData.update)
     {
-      mIMFCursorPosition = static_cast<int>( callbackData.cursorPosition );
+      mIMFCursorPosition = static_cast<int>(callbackData.cursorPosition);
 
       NotifyCursorPosition();
     }
@@ -469,61 +510,61 @@ void InputMethodContextX::DeleteSurrounding( void* data, ImfContext* imfContext,
 
 void InputMethodContextX::NotifyCursorPosition()
 {
-  DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::NotifyCursorPosition\n" );
+  DALI_LOG_INFO(gLogFilter, Debug::General, "InputMethodContextX::NotifyCursorPosition\n");
 
-  if( mIMFContext )
+  if(mIMFContext)
   {
-    ecore_imf_context_cursor_position_set( mIMFContext, mIMFCursorPosition );
+    ecore_imf_context_cursor_position_set(mIMFContext, mIMFCursorPosition);
   }
 }
 
-void InputMethodContextX::SetCursorPosition( unsigned int cursorPosition )
+void InputMethodContextX::SetCursorPosition(unsigned int cursorPosition)
 {
-  DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::SetCursorPosition\n" );
+  DALI_LOG_INFO(gLogFilter, Debug::General, "InputMethodContextX::SetCursorPosition\n");
 
-  mIMFCursorPosition = static_cast<int>( cursorPosition );
+  mIMFCursorPosition = static_cast<int>(cursorPosition);
 }
 
 unsigned int InputMethodContextX::GetCursorPosition() const
 {
-  DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetCursorPosition\n" );
+  DALI_LOG_INFO(gLogFilter, Debug::General, "InputMethodContextX::GetCursorPosition\n");
 
-  return static_cast<unsigned int>( mIMFCursorPosition );
+  return static_cast<unsigned int>(mIMFCursorPosition);
 }
 
-void InputMethodContextX::SetSurroundingText( const std::string& text )
+void InputMethodContextX::SetSurroundingText(const std::string& text)
 {
-  DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::SetSurroundingText\n" );
+  DALI_LOG_INFO(gLogFilter, Debug::General, "InputMethodContextX::SetSurroundingText\n");
 
   mSurroundingText = text;
 }
 
 const std::string& InputMethodContextX::GetSurroundingText() const
 {
-  DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetSurroundingText\n" );
+  DALI_LOG_INFO(gLogFilter, Debug::General, "InputMethodContextX::GetSurroundingText\n");
 
   return mSurroundingText;
 }
 
-void InputMethodContextX::NotifyTextInputMultiLine( bool multiLine )
+void InputMethodContextX::NotifyTextInputMultiLine(bool multiLine)
 {
 }
 
 Dali::InputMethodContext::TextDirection InputMethodContextX::GetTextDirection()
 {
-  Dali::InputMethodContext::TextDirection direction ( Dali::InputMethodContext::LeftToRight );
+  Dali::InputMethodContext::TextDirection direction(Dali::InputMethodContext::LEFT_TO_RIGHT);
 
-    if ( mIMFContext )
-    {
-      char* locale( NULL );
-      ecore_imf_context_input_panel_language_locale_get( mIMFContext, &locale );
+  if(mIMFContext)
+  {
+    char* locale(NULL);
+    ecore_imf_context_input_panel_language_locale_get(mIMFContext, &locale);
 
-      if ( locale )
-      {
-        direction = static_cast< Dali::InputMethodContext::TextDirection >( Locale::GetDirection( std::string( locale ) ) );
-        free( locale );
-      }
+    if(locale)
+    {
+      direction = static_cast<Dali::InputMethodContext::TextDirection>(Locale::GetDirection(std::string(locale)));
+      free(locale);
     }
+  }
 
   return direction;
 }
@@ -534,79 +575,79 @@ Rect<int> InputMethodContextX::GetInputMethodArea()
 
   width = height = xPos = yPos = 0;
 
-  if( mIMFContext )
+  if(mIMFContext)
   {
-    ecore_imf_context_input_panel_geometry_get( mIMFContext, &xPos, &yPos, &width, &height );
+    ecore_imf_context_input_panel_geometry_get(mIMFContext, &xPos, &yPos, &width, &height);
   }
   else
   {
     DALI_LOG_WARNING("VKB Unable to get InputMethodContext Context so GetSize unavailable\n");
   }
 
-  return Rect<int>(xPos,yPos,width,height);
+  return Rect<int>(xPos, yPos, width, height);
 }
 
-void InputMethodContextX::ApplyOptions( const InputMethodOptions& options )
+void InputMethodContextX::ApplyOptions(const InputMethodOptions& options)
 {
   using namespace Dali::InputMethod::Category;
 
   int index;
 
-  if (mIMFContext == NULL)
+  if(mIMFContext == NULL)
   {
     DALI_LOG_WARNING("VKB Unable to excute ApplyOptions with Null ImfContext\n");
     return;
   }
 
-  if ( mOptions.CompareAndSet(PANEL_LAYOUT, options, index) )
+  if(mOptions.CompareAndSet(PANEL_LAYOUT, options, index))
   {
   }
-  if ( mOptions.CompareAndSet(BUTTON_ACTION, options, index) )
+  if(mOptions.CompareAndSet(BUTTON_ACTION, options, index))
   {
   }
-  if ( mOptions.CompareAndSet(AUTO_CAPITALIZE, options, index) )
+  if(mOptions.CompareAndSet(AUTO_CAPITALIZE, options, index))
   {
   }
-  if ( mOptions.CompareAndSet(VARIATION, options, index) )
+  if(mOptions.CompareAndSet(VARIATION, options, index))
   {
   }
 }
 
-void InputMethodContextX::SetInputPanelData( const std::string& data )
+void InputMethodContextX::SetInputPanelData(const std::string& data)
 {
-  DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::SetInputPanelData\n" );
+  DALI_LOG_INFO(gLogFilter, Debug::General, "InputMethodContextX::SetInputPanelData\n");
 
-  if( mIMFContext )
+  if(mIMFContext)
   {
     int length = data.length();
-    ecore_imf_context_input_panel_imdata_set( mIMFContext, data.c_str(), length );
+    ecore_imf_context_input_panel_imdata_set(mIMFContext, data.c_str(), length);
   }
 }
 
-void InputMethodContextX::GetInputPanelData( std::string& data )
+void InputMethodContextX::GetInputPanelData(std::string& data)
 {
-  DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetInputPanelData\n" );
+  DALI_LOG_INFO(gLogFilter, Debug::General, "InputMethodContextX::GetInputPanelData\n");
 
-  if( mIMFContext )
+  if(mIMFContext)
   {
-    int length = 4096; // The max length is 4096 bytes
-    Dali::Vector< char > buffer;
-    buffer.Resize( length );
-    ecore_imf_context_input_panel_imdata_get( mIMFContext, &buffer[0], &length );
-    data = std::string( buffer.Begin(), buffer.End() );
+    int                length = 4096; // The max length is 4096 bytes
+    Dali::Vector<char> buffer;
+    buffer.Resize(length);
+    ecore_imf_context_input_panel_imdata_get(mIMFContext, &buffer[0], &length);
+    data = std::string(buffer.Begin(), buffer.End());
   }
 }
 
 Dali::InputMethodContext::State InputMethodContextX::GetInputPanelState()
 {
-  DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetInputPanelState\n" );
+  DALI_LOG_INFO(gLogFilter, Debug::General, "InputMethodContextX::GetInputPanelState\n");
 
-  if( mIMFContext )
+  if(mIMFContext)
   {
     int value;
-    value = ecore_imf_context_input_panel_state_get( mIMFContext );
+    value = ecore_imf_context_input_panel_state_get(mIMFContext);
 
-    switch (value)
+    switch(value)
     {
       case ECORE_IMF_INPUT_PANEL_STATE_SHOW:
       {
@@ -635,43 +676,43 @@ Dali::InputMethodContext::State InputMethodContextX::GetInputPanelState()
   return Dali::InputMethodContext::DEFAULT;
 }
 
-void InputMethodContextX::SetReturnKeyState( bool visible )
+void InputMethodContextX::SetReturnKeyState(bool visible)
 {
-  DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::SetReturnKeyState\n" );
+  DALI_LOG_INFO(gLogFilter, Debug::General, "InputMethodContextX::SetReturnKeyState\n");
 
-  if( mIMFContext )
+  if(mIMFContext)
   {
-    ecore_imf_context_input_panel_return_key_disabled_set( mIMFContext, !visible );
+    ecore_imf_context_input_panel_return_key_disabled_set(mIMFContext, !visible);
   }
 }
 
-void InputMethodContextX::AutoEnableInputPanel( bool enabled )
+void InputMethodContextX::AutoEnableInputPanel(bool enabled)
 {
-  DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::AutoEnableInputPanel\n" );
+  DALI_LOG_INFO(gLogFilter, Debug::General, "InputMethodContextX::AutoEnableInputPanel\n");
 
-  if( mIMFContext )
+  if(mIMFContext)
   {
-    ecore_imf_context_input_panel_enabled_set( mIMFContext, enabled );
+    ecore_imf_context_input_panel_enabled_set(mIMFContext, enabled);
   }
 }
 
 void InputMethodContextX::ShowInputPanel()
 {
-  DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::ShowInputPanel\n" );
+  DALI_LOG_INFO(gLogFilter, Debug::General, "InputMethodContextX::ShowInputPanel\n");
 
-  if( mIMFContext )
+  if(mIMFContext)
   {
-    ecore_imf_context_input_panel_show( mIMFContext );
+    ecore_imf_context_input_panel_show(mIMFContext);
   }
 }
 
 void InputMethodContextX::HideInputPanel()
 {
-  DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::HideInputPanel\n" );
+  DALI_LOG_INFO(gLogFilter, Debug::General, "InputMethodContextX::HideInputPanel\n");
 
-  if( mIMFContext )
+  if(mIMFContext)
   {
-    ecore_imf_context_input_panel_hide( mIMFContext );
+    ecore_imf_context_input_panel_hide(mIMFContext);
   }
 }
 
@@ -682,90 +723,90 @@ Dali::InputMethodContext::KeyboardType InputMethodContextX::GetKeyboardType()
 
 std::string InputMethodContextX::GetInputPanelLocale()
 {
-  DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetInputPanelLocale\n" );
+  DALI_LOG_INFO(gLogFilter, Debug::General, "InputMethodContextX::GetInputPanelLocale\n");
 
   std::string locale = "";
 
-  if( mIMFContext )
+  if(mIMFContext)
   {
     char* value = NULL;
-    ecore_imf_context_input_panel_language_locale_get( mIMFContext, &value );
+    ecore_imf_context_input_panel_language_locale_get(mIMFContext, &value);
 
-    if( value )
+    if(value)
     {
-      std::string valueCopy( value );
+      std::string valueCopy(value);
       locale = valueCopy;
 
       // The locale string retrieved must be freed with free().
-      free( value );
+      free(value);
     }
   }
   return locale;
 }
 
-void InputMethodContextX::SetContentMIMETypes( const std::string& mimeTypes )
+void InputMethodContextX::SetContentMIMETypes(const std::string& mimeTypes)
 {
-  DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::SetContentMIMETypes\n" );
+  DALI_LOG_INFO(gLogFilter, Debug::General, "InputMethodContextX::SetContentMIMETypes\n");
   // ecore_imf_context_mime_type_accept_set() is supported from ecore-imf 1.20.0 version.
 }
 
-bool InputMethodContextX::FilterEventKey( const Dali::KeyEvent& keyEvent )
+bool InputMethodContextX::FilterEventKey(const Dali::KeyEvent& keyEvent)
 {
-  bool eventHandled( false );
+  bool eventHandled(false);
 
   // If a device key then skip ecore_imf_context_filter_event.
-  if ( ! KeyLookup::IsDeviceButton( keyEvent.keyPressedName.c_str() ))
+  if(!KeyLookup::IsDeviceButton(keyEvent.GetKeyName().c_str()))
   {
     //check whether it's key down or key up event
-    if ( keyEvent.state == KeyEvent::Down )
+    if(keyEvent.GetState() == Dali::KeyEvent::DOWN)
     {
-      eventHandled = ProcessEventKeyDown( keyEvent );
+      eventHandled = ProcessEventKeyDown(keyEvent);
     }
-    else if ( keyEvent.state == KeyEvent::Up )
+    else if(keyEvent.GetState() == Dali::KeyEvent::UP)
     {
-      eventHandled = ProcessEventKeyUp( keyEvent );
+      eventHandled = ProcessEventKeyUp(keyEvent);
     }
   }
 
   return eventHandled;
 }
 
-void InputMethodContextX::AllowTextPrediction( bool prediction )
+void InputMethodContextX::AllowTextPrediction(bool prediction)
 {
-  DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::AllowTextPrediction\n" );
+  DALI_LOG_INFO(gLogFilter, Debug::General, "InputMethodContextX::AllowTextPrediction\n");
 
-  if( mIMFContext )
+  if(mIMFContext)
   {
-    ecore_imf_context_prediction_allow_set( mIMFContext, prediction );
+    ecore_imf_context_prediction_allow_set(mIMFContext, prediction);
   }
 }
 
 bool InputMethodContextX::IsTextPredictionAllowed() const
 {
-  DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::IsTextPredictionAllowed\n" );
+  DALI_LOG_INFO(gLogFilter, Debug::General, "InputMethodContextX::IsTextPredictionAllowed\n");
   bool prediction = false;
-  if( mIMFContext )
+  if(mIMFContext)
   {
-    prediction = ecore_imf_context_prediction_allow_get( mIMFContext );
+    prediction = ecore_imf_context_prediction_allow_get(mIMFContext);
   }
   return prediction;
 }
 
-void InputMethodContextX::SetInputPanelLanguage( Dali::InputMethodContext::InputPanelLanguage language )
+void InputMethodContextX::SetInputPanelLanguage(Dali::InputMethodContext::InputPanelLanguage language)
 {
-  DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::SetInputPanelLanguage\n" );
-  if( mIMFContext )
+  DALI_LOG_INFO(gLogFilter, Debug::General, "InputMethodContextX::SetInputPanelLanguage\n");
+  if(mIMFContext)
   {
-    switch (language)
+    switch(language)
     {
       case Dali::InputMethodContext::InputPanelLanguage::AUTOMATIC:
       {
-        ecore_imf_context_input_panel_language_set( mIMFContext, ECORE_IMF_INPUT_PANEL_LANG_AUTOMATIC );
+        ecore_imf_context_input_panel_language_set(mIMFContext, ECORE_IMF_INPUT_PANEL_LANG_AUTOMATIC);
         break;
       }
       case Dali::InputMethodContext::InputPanelLanguage::ALPHABET:
       {
-        ecore_imf_context_input_panel_language_set( mIMFContext, ECORE_IMF_INPUT_PANEL_LANG_ALPHABET );
+        ecore_imf_context_input_panel_language_set(mIMFContext, ECORE_IMF_INPUT_PANEL_LANG_ALPHABET);
         break;
       }
     }
@@ -774,13 +815,13 @@ void InputMethodContextX::SetInputPanelLanguage( Dali::InputMethodContext::Input
 
 Dali::InputMethodContext::InputPanelLanguage InputMethodContextX::GetInputPanelLanguage() const
 {
-  DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetInputPanelLanguage\n" );
-  if( mIMFContext )
+  DALI_LOG_INFO(gLogFilter, Debug::General, "InputMethodContextX::GetInputPanelLanguage\n");
+  if(mIMFContext)
   {
     int value;
-    value =  ecore_imf_context_input_panel_language_get( mIMFContext );
+    value = ecore_imf_context_input_panel_language_get(mIMFContext);
 
-    switch (value)
+    switch(value)
     {
       case ECORE_IMF_INPUT_PANEL_LANG_AUTOMATIC:
       {
@@ -797,36 +838,61 @@ Dali::InputMethodContext::InputPanelLanguage InputMethodContextX::GetInputPanelL
   return Dali::InputMethodContext::InputPanelLanguage::AUTOMATIC;
 }
 
-bool InputMethodContextX::ProcessEventKeyDown( const KeyEvent& keyEvent )
+void InputMethodContextX::SetInputPanelPosition(unsigned int x, unsigned int y)
+{
+  DALI_LOG_INFO(gLogFilter, Debug::General, "InputMethodContextX::SetInputPanelPosition\n");
+
+  // ecore_imf_context_input_panel_position_set() is supported from ecore-imf 1.21.0 version.
+}
+
+bool InputMethodContextX::SetInputPanelPositionAlign(int x, int y, Dali::InputMethodContext::InputPanelAlign align)
+{
+  DALI_LOG_INFO(gLogFilter, Debug::General, "InputMethodContextX::SetInputPanelPositionAlign\n");
+  return false;
+}
+
+void InputMethodContextX::GetPreeditStyle(Dali::InputMethodContext::PreEditAttributeDataContainer& attrs) const
 {
-  bool eventHandled( false );
-  if ( mIMFContext )
+  DALI_LOG_INFO(gLogFilter, Debug::General, "InputMethodContextX::GetPreeditStyle\n");
+  attrs = mPreeditAttrs;
+}
+
+bool InputMethodContextX::ProcessEventKeyDown(const Dali::KeyEvent& keyEvent)
+{
+  bool eventHandled(false);
+  if(mIMFContext)
   {
-    Integration::KeyEvent integKeyEvent( keyEvent );
-    std::string key = integKeyEvent.logicalKey;
+    Integration::KeyEvent integKeyEvent(keyEvent.GetKeyName(), keyEvent.GetLogicalKey(), keyEvent.GetKeyString(), keyEvent.GetKeyCode(), keyEvent.GetKeyModifier(), keyEvent.GetTime(), static_cast<Integration::KeyEvent::State>(keyEvent.GetState()), keyEvent.GetCompose(), keyEvent.GetDeviceName(), keyEvent.GetDeviceClass(), keyEvent.GetDeviceSubclass());
+    std::string           key = integKeyEvent.logicalKey;
 
-    std::string compose = keyEvent.GetCompose();
+    std::string compose = integKeyEvent.compose;
 
     // We're consuming key down event so we have to pass to InputMethodContext so that it can parse it as well.
     Ecore_IMF_Event_Key_Down ecoreKeyDownEvent;
-    ecoreKeyDownEvent.keyname = keyEvent.keyPressedName.c_str();
-    ecoreKeyDownEvent.key = key.c_str();
-    ecoreKeyDownEvent.string = keyEvent.keyPressed.c_str();
-    ecoreKeyDownEvent.compose = compose.c_str();
-    ecoreKeyDownEvent.timestamp = keyEvent.time;
-    ecoreKeyDownEvent.modifiers = EcoreInputModifierToEcoreIMFModifier( keyEvent.keyModifier );
-    ecoreKeyDownEvent.locks = EcoreInputModifierToEcoreIMFLock( keyEvent.keyModifier );
-#ifdef ECORE_IMF_1_13
-    ecoreKeyDownEvent.dev_name  = "";
-    ecoreKeyDownEvent.dev_class = ECORE_IMF_DEVICE_CLASS_KEYBOARD;
+    ecoreKeyDownEvent.keyname   = integKeyEvent.keyName.c_str();
+    ecoreKeyDownEvent.key       = key.c_str();
+    ecoreKeyDownEvent.string    = integKeyEvent.keyString.c_str();
+    ecoreKeyDownEvent.compose   = compose.c_str();
+    ecoreKeyDownEvent.timestamp = integKeyEvent.time;
+    ecoreKeyDownEvent.modifiers = EcoreInputModifierToEcoreIMFModifier(integKeyEvent.keyModifier);
+    ecoreKeyDownEvent.locks     = EcoreInputModifierToEcoreIMFLock(integKeyEvent.keyModifier);
+
+#if defined(ECORE_VERSION_MAJOR) && (ECORE_VERSION_MAJOR >= 1) && defined(ECORE_VERSION_MINOR)
+#if(ECORE_VERSION_MINOR >= 14)
+    ecoreKeyDownEvent.dev_name     = "";
+    ecoreKeyDownEvent.dev_class    = ECORE_IMF_DEVICE_CLASS_KEYBOARD;
     ecoreKeyDownEvent.dev_subclass = ECORE_IMF_DEVICE_SUBCLASS_NONE;
-#endif // ECORE_IMF_1_13
+#endif // Since ecore_imf 1.14 version
+#if(ECORE_VERSION_MINOR >= 22)
+    ecoreKeyDownEvent.keycode = integKeyEvent.keyCode;
+#endif // Since ecore_imf 1.22 version
+#endif // Since ecore_imf Version 1
 
     // If the device is IME and the focused key is the direction keys, then we should send a key event to move a key cursor.
-    if ((keyEvent.GetDeviceName() == "ime") && ((!strncmp(keyEvent.keyPressedName.c_str(), "Left", 4)) ||
-                                   (!strncmp(keyEvent.keyPressedName.c_str(), "Right", 5)) ||
-                                   (!strncmp(keyEvent.keyPressedName.c_str(), "Up", 2)) ||
-                                   (!strncmp(keyEvent.keyPressedName.c_str(), "Down", 4))))
+    if((integKeyEvent.deviceName == "ime") && ((!strncmp(integKeyEvent.keyName.c_str(), "Left", 4)) ||
+                                               (!strncmp(integKeyEvent.keyName.c_str(), "Right", 5)) ||
+                                               (!strncmp(integKeyEvent.keyName.c_str(), "Up", 2)) ||
+                                               (!strncmp(integKeyEvent.keyName.c_str(), "Down", 4))))
     {
       eventHandled = 0;
     }
@@ -834,15 +900,15 @@ bool InputMethodContextX::ProcessEventKeyDown( const KeyEvent& keyEvent )
     {
       eventHandled = ecore_imf_context_filter_event(mIMFContext,
                                                     ECORE_IMF_EVENT_KEY_DOWN,
-                                                    reinterpret_cast<Ecore_IMF_Event *>( &ecoreKeyDownEvent ));
+                                                    reinterpret_cast<Ecore_IMF_Event*>(&ecoreKeyDownEvent));
     }
 
     // If the event has not been handled by InputMethodContext then check if we should reset our IMFcontext
-    if (!eventHandled)
+    if(!eventHandled)
     {
-      if (!strcmp(keyEvent.keyPressedName.c_str(), "Escape") ||
-          !strcmp(keyEvent.keyPressedName.c_str(), "Return") ||
-          !strcmp(keyEvent.keyPressedName.c_str(), "KP_Enter"))
+      if(!strcmp(integKeyEvent.keyName.c_str(), "Escape") ||
+         !strcmp(integKeyEvent.keyName.c_str(), "Return") ||
+         !strcmp(integKeyEvent.keyName.c_str(), "KP_Enter"))
       {
         ecore_imf_context_reset(mIMFContext);
       }
@@ -851,92 +917,112 @@ bool InputMethodContextX::ProcessEventKeyDown( const KeyEvent& keyEvent )
   return eventHandled;
 }
 
-bool InputMethodContextX::ProcessEventKeyUp( const KeyEvent& keyEvent )
+bool InputMethodContextX::ProcessEventKeyUp(const Dali::KeyEvent& keyEvent)
 {
-  bool eventHandled( false );
-  if( mIMFContext )
+  bool eventHandled(false);
+  if(mIMFContext)
   {
-    Integration::KeyEvent integKeyEvent( keyEvent );
+    Integration::KeyEvent integKeyEvent(keyEvent.GetKeyName(), keyEvent.GetLogicalKey(), keyEvent.GetKeyString(), keyEvent.GetKeyCode(), keyEvent.GetKeyModifier(), keyEvent.GetTime(), static_cast<Integration::KeyEvent::State>(keyEvent.GetState()), keyEvent.GetCompose(), keyEvent.GetDeviceName(), keyEvent.GetDeviceClass(), keyEvent.GetDeviceSubclass());
+
     std::string key = integKeyEvent.logicalKey;
 
-    std::string compose = keyEvent.GetCompose();
+    std::string compose = integKeyEvent.compose;
 
     // We're consuming key up event so we have to pass to InputMethodContext so that it can parse it as well.
     Ecore_IMF_Event_Key_Up ecoreKeyUpEvent;
-    ecoreKeyUpEvent.keyname = keyEvent.keyPressedName.c_str();
-    ecoreKeyUpEvent.key = key.c_str();
-    ecoreKeyUpEvent.string = keyEvent.keyPressed.c_str();
-    ecoreKeyUpEvent.compose = compose.c_str();
-    ecoreKeyUpEvent.timestamp = keyEvent.time;
-    ecoreKeyUpEvent.modifiers = EcoreInputModifierToEcoreIMFModifier( keyEvent.keyModifier );
-    ecoreKeyUpEvent.locks = EcoreInputModifierToEcoreIMFLock( keyEvent.keyModifier );
-#ifdef ECORE_IMF_1_13
-    ecoreKeyUpEvent.dev_name  = "";
-#endif // ECORE_IMF_1_13
+    ecoreKeyUpEvent.keyname   = integKeyEvent.keyName.c_str();
+    ecoreKeyUpEvent.key       = key.c_str();
+    ecoreKeyUpEvent.string    = integKeyEvent.keyString.c_str();
+    ecoreKeyUpEvent.compose   = compose.c_str();
+    ecoreKeyUpEvent.timestamp = integKeyEvent.time;
+    ecoreKeyUpEvent.modifiers = EcoreInputModifierToEcoreIMFModifier(integKeyEvent.keyModifier);
+    ecoreKeyUpEvent.locks     = EcoreInputModifierToEcoreIMFLock(integKeyEvent.keyModifier);
+#if defined(ECORE_VERSION_MAJOR) && (ECORE_VERSION_MAJOR >= 1) && defined(ECORE_VERSION_MINOR)
+#if(ECORE_VERSION_MINOR >= 14)
+    ecoreKeyUpEvent.dev_name = "";
+#endif // Since ecore_imf 1.14 version
+#if(ECORE_VERSION_MINOR >= 22)
+    ecoreKeyUpEvent.keycode = integKeyEvent.keyCode;
+#endif // Since ecore_imf 1.22 version
+#endif // Since ecore_imf Version 1
 
     eventHandled = ecore_imf_context_filter_event(mIMFContext,
                                                   ECORE_IMF_EVENT_KEY_UP,
-                                                  reinterpret_cast<Ecore_IMF_Event *>( &ecoreKeyUpEvent ));
+                                                  reinterpret_cast<Ecore_IMF_Event*>(&ecoreKeyUpEvent));
   }
   return eventHandled;
 }
 
-Ecore_IMF_Keyboard_Modifiers InputMethodContextX::EcoreInputModifierToEcoreIMFModifier( unsigned int ecoreModifier )
+Ecore_IMF_Keyboard_Modifiers InputMethodContextX::EcoreInputModifierToEcoreIMFModifier(unsigned int ecoreModifier)
 {
-  unsigned int modifier( ECORE_IMF_KEYBOARD_MODIFIER_NONE );  // If no other matches returns NONE.
+  unsigned int modifier(ECORE_IMF_KEYBOARD_MODIFIER_NONE); // If no other matches returns NONE.
 
-  if ( ecoreModifier & ECORE_EVENT_MODIFIER_SHIFT )  // enums from ecore_input/Ecore_Input.h
+  if(ecoreModifier & ECORE_EVENT_MODIFIER_SHIFT) // enums from ecore_input/Ecore_Input.h
   {
-    modifier |= ECORE_IMF_KEYBOARD_MODIFIER_SHIFT;  // enums from ecore_imf/ecore_imf.h
+    modifier |= ECORE_IMF_KEYBOARD_MODIFIER_SHIFT; // enums from ecore_imf/ecore_imf.h
   }
 
-  if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALT )
+  if(ecoreModifier & ECORE_EVENT_MODIFIER_ALT)
   {
     modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALT;
   }
 
-  if ( ecoreModifier & ECORE_EVENT_MODIFIER_CTRL )
+  if(ecoreModifier & ECORE_EVENT_MODIFIER_CTRL)
   {
     modifier |= ECORE_IMF_KEYBOARD_MODIFIER_CTRL;
   }
 
-  if ( ecoreModifier & ECORE_EVENT_MODIFIER_WIN )
+  if(ecoreModifier & ECORE_EVENT_MODIFIER_WIN)
   {
     modifier |= ECORE_IMF_KEYBOARD_MODIFIER_WIN;
   }
 
-  if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALTGR )
+  if(ecoreModifier & ECORE_EVENT_MODIFIER_ALTGR)
   {
     modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALTGR;
   }
 
-  return static_cast<Ecore_IMF_Keyboard_Modifiers>( modifier );
+  return static_cast<Ecore_IMF_Keyboard_Modifiers>(modifier);
 }
 
-Ecore_IMF_Keyboard_Locks InputMethodContextX::EcoreInputModifierToEcoreIMFLock( unsigned int modifier )
+Ecore_IMF_Keyboard_Locks InputMethodContextX::EcoreInputModifierToEcoreIMFLock(unsigned int modifier)
 {
-    unsigned int lock( ECORE_IMF_KEYBOARD_LOCK_NONE ); // If no other matches, returns NONE.
+  unsigned int lock(ECORE_IMF_KEYBOARD_LOCK_NONE); // If no other matches, returns NONE.
 
-    if( modifier & ECORE_EVENT_LOCK_NUM )
-    {
-      lock |= ECORE_IMF_KEYBOARD_LOCK_NUM; // Num lock is active.
-    }
+  if(modifier & ECORE_EVENT_LOCK_NUM)
+  {
+    lock |= ECORE_IMF_KEYBOARD_LOCK_NUM; // Num lock is active.
+  }
 
-    if( modifier & ECORE_EVENT_LOCK_CAPS )
-    {
-      lock |= ECORE_IMF_KEYBOARD_LOCK_CAPS; // Caps lock is active.
-    }
+  if(modifier & ECORE_EVENT_LOCK_CAPS)
+  {
+    lock |= ECORE_IMF_KEYBOARD_LOCK_CAPS; // Caps lock is active.
+  }
 
-    if( modifier & ECORE_EVENT_LOCK_SCROLL )
-    {
-      lock |= ECORE_IMF_KEYBOARD_LOCK_SCROLL; // Scroll lock is active.
-    }
+  if(modifier & ECORE_EVENT_LOCK_SCROLL)
+  {
+    lock |= ECORE_IMF_KEYBOARD_LOCK_SCROLL; // Scroll lock is active.
+  }
+
+  return static_cast<Ecore_IMF_Keyboard_Locks>(lock);
+}
+
+void InputMethodContextX::OnStaged(Dali::Actor actor)
+{
+  Ecore_X_Window ecoreXwin(AnyCast<Ecore_X_Window>(Dali::Integration::SceneHolder::Get(actor).GetNativeHandle()));
 
-    return static_cast<Ecore_IMF_Keyboard_Locks>( lock );
+  if(mEcoreXwin != ecoreXwin)
+  {
+    mEcoreXwin = ecoreXwin;
+
+    // Reset
+    Finalize();
+    Initialize();
+  }
 }
 
-} // Adaptor
+} // namespace Adaptor
 
-} // Internal
+} // namespace Internal
 
-} // Dali
+} // namespace Dali