Revert "[Tizen] Revert "Support multiple window rendering""
[platform/core/uifw/dali-adaptor.git] / dali / internal / input / tizen-wayland / input-method-context-impl-ecore-wl.cpp
index b4f71ea..34255a5 100755 (executable)
@@ -23,8 +23,8 @@
 #include <dali/internal/input/tizen-wayland/input-method-context-impl-ecore-wl.h>
 
 // EXTERNAL INCLUDES
-#include <Ecore_IMF.h>
 #include <Ecore_Input.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>
 // INTERNAL INCLUDES
 #include <dali/integration-api/adaptor.h>
 #include <dali/internal/system/common/locale-utils.h>
-#include <dali/internal/adaptor/common/adaptor-impl.h>
 #include <dali/internal/system/common/singleton-service-impl.h>
 #include <dali/public-api/adaptor-framework/input-method.h>
 #include <dali/internal/input/common/key-impl.h>
+#include <dali/internal/window-system/common/window-render-surface.h>
 
 #define TOKEN_STRING(x) #x
 
@@ -265,21 +265,17 @@ Dali::TypeRegistration type( typeid(Dali::InputMethodContext), typeid(Dali::Base
 InputMethodContextPtr InputMethodContextEcoreWl::New()
 {
   InputMethodContextPtr inputMethodContext;
-  if ( Adaptor::IsAvailable() )
+
+  // Create instance only if the adaptor is available
+  if ( Dali::Adaptor::IsAvailable() )
   {
-    // Create instance only if the adaptor is available
-    Adaptor &adaptorImpl(Adaptor::GetImplementation(Adaptor::Get()));
-    Any nativeWindow = adaptorImpl.GetNativeWindowHandle();
-
-    // The Ecore_Wl_Window needs to use the InputMethodContext.
-    // Only when the render surface is window, we can get the Ecore_Wl_Window.
-    Ecore_Wl_Window *ecoreWwin(AnyCast<Ecore_Wl_Window *>(nativeWindow));
-    if (ecoreWwin)
+    Any nativeWindow = Dali::Adaptor::Get().GetNativeWindowHandle();
+
+    // The window needs to use the InputMethodContext.
+    // Only when the render surface is window, we can get the window.
+    if( !nativeWindow.Empty() )
     {
-      // If we fail to get Ecore_Wl_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().
-      inputMethodContext = new InputMethodContextEcoreWl(ecoreWwin);
+      inputMethodContext = new InputMethodContextEcoreWl();
     }
     else
     {
@@ -297,9 +293,8 @@ void InputMethodContextEcoreWl::Finalize()
   DeleteContext();
 }
 
-InputMethodContextEcoreWl::InputMethodContextEcoreWl( Ecore_Wl_Window *ecoreWlwin )
+InputMethodContextEcoreWl::InputMethodContextEcoreWl()
 : mIMFContext(),
-  mEcoreWlwin( ecoreWlwin ),
   mIMFCursorPosition( 0 ),
   mSurroundingText(),
   mRestoreAfterFocusLost( false ),
@@ -316,11 +311,11 @@ InputMethodContextEcoreWl::~InputMethodContextEcoreWl()
 
 void InputMethodContextEcoreWl::Initialize()
 {
-  CreateContext( mEcoreWlwin );
+  CreateContext();
   ConnectCallbacks();
 }
 
-void InputMethodContextEcoreWl::CreateContext( Ecore_Wl_Window *ecoreWlwin )
+void InputMethodContextEcoreWl::CreateContext()
 {
   DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContext::CreateContext\n" );
 
@@ -331,10 +326,16 @@ void InputMethodContextEcoreWl::CreateContext( Ecore_Wl_Window *ecoreWlwin )
 
     if( mIMFContext )
     {
-      if( ecoreWlwin )
+      // If we fail to get window id, 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().
+      Dali::RenderSurfaceInterface& renderSurface = Dali::Adaptor::Get().GetSurface();
+      WindowRenderSurface& windowRenderSurface = static_cast< WindowRenderSurface& >( renderSurface );
+
+      int windowId = windowRenderSurface.GetNativeWindowId();
+      if( windowId != 0 )
       {
-        ecore_imf_context_client_window_set( mIMFContext,
-        reinterpret_cast<void*>( ecore_wl_window_id_get(ecoreWlwin)) );
+        ecore_imf_context_client_window_set( mIMFContext, reinterpret_cast< void* >( windowId ) );
       }
     }
     else
@@ -919,21 +920,48 @@ bool InputMethodContextEcoreWl::FilterEventKey( const Dali::KeyEvent& keyEvent )
   return eventHandled;
 }
 
+void InputMethodContextEcoreWl::AllowTextPrediction( bool prediction )
+{
+  DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::AllowTextPrediction\n" );
+
+  if( mIMFContext )
+  {
+    ecore_imf_context_prediction_allow_set( mIMFContext, prediction );
+  }
+}
+
+bool InputMethodContextEcoreWl::IsTextPredictionAllowed() const
+{
+  DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::IsTextPredictionAllowed\n" );
+  bool prediction = false;
+  if( mIMFContext )
+  {
+    prediction = ecore_imf_context_prediction_allow_get( mIMFContext );
+  }
+  return prediction;
+}
+
 bool InputMethodContextEcoreWl::ProcessEventKeyDown( const KeyEvent& keyEvent )
 {
   bool eventHandled( false );
   if ( mIMFContext )
   {
+    Integration::KeyEvent integKeyEvent( keyEvent );
+    std::string key = integKeyEvent.logicalKey;
+
+    std::string compose = keyEvent.GetCompose();
+    std::string deviceName = keyEvent.GetDeviceName();
+
     // 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 = keyEvent.keyPressedName.c_str();
+    ecoreKeyDownEvent.key = key.c_str();
     ecoreKeyDownEvent.string = keyEvent.keyPressed.c_str();
-    ecoreKeyDownEvent.compose = keyEvent.GetCompose().c_str();
+    ecoreKeyDownEvent.compose = compose.c_str();
     ecoreKeyDownEvent.timestamp = keyEvent.time;
     ecoreKeyDownEvent.modifiers = EcoreInputModifierToEcoreIMFModifier( keyEvent.keyModifier );
     ecoreKeyDownEvent.locks = EcoreInputModifierToEcoreIMFLock( keyEvent.keyModifier );
-    ecoreKeyDownEvent.dev_name = keyEvent.GetDeviceName().c_str();
+    ecoreKeyDownEvent.dev_name = deviceName.c_str();
     ecoreKeyDownEvent.dev_class = static_cast<Ecore_IMF_Device_Class> ( keyEvent.GetDeviceClass() );//ECORE_IMF_DEVICE_CLASS_KEYBOARD;
     ecoreKeyDownEvent.dev_subclass = static_cast<Ecore_IMF_Device_Subclass> ( keyEvent.GetDeviceSubclass() );//ECORE_IMF_DEVICE_SUBCLASS_NONE;
 
@@ -971,16 +999,22 @@ bool InputMethodContextEcoreWl::ProcessEventKeyUp( const KeyEvent& keyEvent )
   bool eventHandled( false );
   if( mIMFContext )
   {
+    Integration::KeyEvent integKeyEvent( keyEvent );
+    std::string key = integKeyEvent.logicalKey;
+
+    std::string compose = keyEvent.GetCompose();
+    std::string deviceName = keyEvent.GetDeviceName();
+
     // 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 = keyEvent.keyPressedName.c_str();
+    ecoreKeyUpEvent.key = key.c_str();
     ecoreKeyUpEvent.string = keyEvent.keyPressed.c_str();
-    ecoreKeyUpEvent.compose = keyEvent.GetCompose().c_str();
+    ecoreKeyUpEvent.compose = compose.c_str();
     ecoreKeyUpEvent.timestamp = keyEvent.time;
     ecoreKeyUpEvent.modifiers =  EcoreInputModifierToEcoreIMFModifier( keyEvent.keyModifier );
     ecoreKeyUpEvent.locks = EcoreInputModifierToEcoreIMFLock( keyEvent.keyModifier );
-    ecoreKeyUpEvent.dev_name = keyEvent.GetDeviceName().c_str();
+    ecoreKeyUpEvent.dev_name = deviceName.c_str();
     ecoreKeyUpEvent.dev_class = static_cast<Ecore_IMF_Device_Class> ( keyEvent.GetDeviceClass() );//ECORE_IMF_DEVICE_CLASS_KEYBOARD;
     ecoreKeyUpEvent.dev_subclass = static_cast<Ecore_IMF_Device_Subclass> ( keyEvent.GetDeviceSubclass() );//ECORE_IMF_DEVICE_SUBCLASS_NONE;