Merge "Support multiple surfaces for partial update" into devel/master
[platform/core/uifw/dali-adaptor.git] / dali / internal / input / ubuntu-x11 / input-method-context-impl-x.cpp
index 7101b58..58125ad 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019 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.
@@ -56,22 +56,30 @@ 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;
 }
@@ -153,7 +161,7 @@ InputMethodContextX::InputMethodContextX( Dali::Actor actor )
 {
   ecore_imf_init();
 
-  actor.OnStageSignal().Connect( this, &InputMethodContextX::OnStaged );
+  actor.OnSceneSignal().Connect( this, &InputMethodContextX::OnStaged );
 }
 
 InputMethodContextX::~InputMethodContextX()
@@ -332,16 +340,19 @@ void InputMethodContextX::PreEditChanged( void*, ImfContext* imfContext, void* e
       size_t byteIndex = 0;
 
       // iterate through null terminated string checking each character's position against the given byte position ( attr->end_index ).
-      const char leadByte = preEditString[byteIndex];
+      char leadByte = preEditString[byteIndex];
+
       while( leadByte != '\0' )
       {
+        leadByte = preEditString[byteIndex]; // Update the character to get the number of its byte
+
         // 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 )
+        if( byteIndex >= attr->end_index )
         {
           data.endIndex = visualCharacterIndex;
           break;
@@ -547,7 +558,7 @@ 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 )
     {
@@ -750,14 +761,14 @@ bool InputMethodContextX::FilterEventKey( const Dali::KeyEvent& keyEvent )
   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 );
     }
-    else if ( keyEvent.state == KeyEvent::Up )
+    else if ( keyEvent.GetState() == Dali::KeyEvent::UP )
     {
       eventHandled = ProcessEventKeyUp( keyEvent );
     }
@@ -840,31 +851,31 @@ void InputMethodContextX::SetInputPanelPosition( unsigned int x, unsigned int y
   // ecore_imf_context_input_panel_position_set() is supported from ecore-imf 1.21.0 version.
 }
 
-void InputMethodContextX::GetPreeditStyle( Vector< Dali::InputMethodContext::PreeditAttributeData >& attrs ) const
+void InputMethodContextX::GetPreeditStyle( Dali::InputMethodContext::PreEditAttributeDataContainer& attrs ) const
 {
   DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetPreeditStyle\n" );
   attrs = mPreeditAttrs;
 }
 
-bool InputMethodContextX::ProcessEventKeyDown( const KeyEvent& keyEvent )
+bool InputMethodContextX::ProcessEventKeyDown( const Dali::KeyEvent& keyEvent )
 {
   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 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.keyname = integKeyEvent.keyName.c_str();
     ecoreKeyDownEvent.key = key.c_str();
-    ecoreKeyDownEvent.string = keyEvent.keyPressed.c_str();
+    ecoreKeyDownEvent.string = integKeyEvent.keyString.c_str();
     ecoreKeyDownEvent.compose = compose.c_str();
-    ecoreKeyDownEvent.timestamp = keyEvent.time;
-    ecoreKeyDownEvent.modifiers = EcoreInputModifierToEcoreIMFModifier( keyEvent.keyModifier );
-    ecoreKeyDownEvent.locks = EcoreInputModifierToEcoreIMFLock( keyEvent.keyModifier );
+    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)
@@ -873,15 +884,15 @@ bool InputMethodContextX::ProcessEventKeyDown( const KeyEvent& keyEvent )
     ecoreKeyDownEvent.dev_subclass = ECORE_IMF_DEVICE_SUBCLASS_NONE;
 #endif // Since ecore_imf 1.14 version
 #if (ECORE_VERSION_MINOR >= 22)
-    ecoreKeyDownEvent.keycode = keyEvent.keyCode;
+    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;
     }
@@ -895,9 +906,9 @@ bool InputMethodContextX::ProcessEventKeyDown( const KeyEvent& keyEvent )
     // If the event has not been handled by InputMethodContext then check if we should reset our IMFcontext
     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);
       }
@@ -906,31 +917,32 @@ 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 )
   {
-    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.keyname = integKeyEvent.keyName.c_str();
     ecoreKeyUpEvent.key = key.c_str();
-    ecoreKeyUpEvent.string = keyEvent.keyPressed.c_str();
+    ecoreKeyUpEvent.string = integKeyEvent.keyString.c_str();
     ecoreKeyUpEvent.compose = compose.c_str();
-    ecoreKeyUpEvent.timestamp = keyEvent.time;
-    ecoreKeyUpEvent.modifiers = EcoreInputModifierToEcoreIMFModifier( keyEvent.keyModifier );
-    ecoreKeyUpEvent.locks = EcoreInputModifierToEcoreIMFLock( keyEvent.keyModifier );
+    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 = keyEvent.keyCode;
+    ecoreKeyUpEvent.keycode = integKeyEvent.keyCode;
 #endif // Since ecore_imf 1.22 version
 #endif // Since ecore_imf Version 1