2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/input/ubuntu-x11/input-method-context-impl-x.h>
22 #include <dali/internal/input/linux/dali-ecore-imf.h>
23 #include <dali/internal/input/ubuntu-x11/dali-ecore-input.h>
24 #include <dali/internal/system/linux/dali-ecore.h>
25 #include <dali/public-api/events/key-event.h>
26 #include <dali/public-api/adaptor-framework/key.h>
27 #include <dali/public-api/object/type-registry.h>
28 #include <dali/integration-api/debug.h>
31 #include <dali/integration-api/adaptor.h>
32 #include <dali/internal/adaptor/common/adaptor-impl.h>
33 #include <dali/internal/system/common/locale-utils.h>
34 #include <dali/internal/system/common/singleton-service-impl.h>
35 #include <dali/internal/input/common/virtual-keyboard-impl.h>
36 #include <dali/internal/input/common/key-impl.h>
37 #include <dali/internal/input/tizen-wayland/ecore-virtual-keyboard.h>
50 #if defined(DEBUG_ENABLED)
51 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_INPUT_METHOD_CONTEXT");
54 // Currently this code is internal to dali/dali/internal/event/text/utf8.h but should be made Public and used from there instead.
55 size_t Utf8SequenceLength(const unsigned char leadByte)
59 if ((leadByte & 0x80) == 0 ) //ASCII character (lead bit zero)
63 else if (( leadByte & 0xe0 ) == 0xc0 ) //110x xxxx
67 else if (( leadByte & 0xf0 ) == 0xe0 ) //1110 xxxx
71 else if (( leadByte & 0xf8 ) == 0xf0 ) //1111 0xxx
79 // Static function calls used by ecore 'c' style callback registration
80 void Commit( void *data, Ecore_IMF_Context *imfContext, void *eventInfo )
84 InputMethodContextX* inputMethodContext = static_cast< InputMethodContextX* >( data );
85 inputMethodContext->CommitReceived( data, imfContext, eventInfo );
89 void PreEdit( void *data, Ecore_IMF_Context *imfContext, void *eventInfo )
93 InputMethodContextX* inputMethodContext = static_cast< InputMethodContextX* >( data );
94 inputMethodContext->PreEditChanged( data, imfContext, eventInfo );
98 Eina_Bool ImfRetrieveSurrounding(void *data, Ecore_IMF_Context *imfContext, char** text, int* cursorPosition )
102 InputMethodContextX* inputMethodContext = static_cast< InputMethodContextX* >( data );
103 return inputMethodContext->RetrieveSurrounding( data, imfContext, text, cursorPosition );
112 * Called when an InputMethodContext delete surrounding event is received.
113 * Here we tell the application that it should delete a certain range.
115 void ImfDeleteSurrounding( void *data, Ecore_IMF_Context *imfContext, void *eventInfo )
119 InputMethodContextX* inputMethodContext = static_cast< InputMethodContextX* >( data );
120 inputMethodContext->DeleteSurrounding( data, imfContext, eventInfo );
124 } // unnamed namespace
126 InputMethodContextPtr InputMethodContextX::New( Dali::Actor actor )
128 InputMethodContextPtr manager;
130 if( actor && Dali::Adaptor::IsAvailable() )
132 manager = new InputMethodContextX( actor );
138 void InputMethodContextX::Finalize()
140 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::Finalize\n" );
141 VirtualKeyboard::DisconnectCallbacks( mIMFContext );
142 DisconnectCallbacks();
146 InputMethodContextX::InputMethodContextX( Dali::Actor actor )
149 mIMFCursorPosition( 0 ),
151 mRestoreAfterFocusLost( false ),
152 mIdleCallbackConnected( false )
156 actor.OnStageSignal().Connect( this, &InputMethodContextX::OnStaged );
159 InputMethodContextX::~InputMethodContextX()
162 ecore_imf_shutdown();
165 void InputMethodContextX::Initialize()
169 VirtualKeyboard::ConnectCallbacks( mIMFContext );
172 void InputMethodContextX::CreateContext()
174 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::CreateContext\n" );
181 const char *contextId = ecore_imf_context_default_id_get();
184 mIMFContext = ecore_imf_context_add( contextId );
188 ecore_imf_context_client_window_set( mIMFContext, reinterpret_cast<void*>( mEcoreXwin ) );
192 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContext Unable to get IMFContext\n");
197 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContext Unable to get IMFContext\n");
201 void InputMethodContextX::DeleteContext()
203 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::DeleteContext\n" );
207 ecore_imf_context_del( mIMFContext );
212 // Callbacks for predicitive text support.
213 void InputMethodContextX::ConnectCallbacks()
217 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::ConnectCallbacks\n" );
219 ecore_imf_context_event_callback_add( mIMFContext, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, PreEdit, this );
220 ecore_imf_context_event_callback_add( mIMFContext, ECORE_IMF_CALLBACK_COMMIT, Commit, this );
221 ecore_imf_context_event_callback_add( mIMFContext, ECORE_IMF_CALLBACK_DELETE_SURROUNDING, ImfDeleteSurrounding, this );
223 ecore_imf_context_retrieve_surrounding_callback_set( mIMFContext, ImfRetrieveSurrounding, this);
227 void InputMethodContextX::DisconnectCallbacks()
231 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::DisconnectCallbacks\n" );
233 ecore_imf_context_event_callback_del( mIMFContext, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, PreEdit );
234 ecore_imf_context_event_callback_del( mIMFContext, ECORE_IMF_CALLBACK_COMMIT, Commit );
235 ecore_imf_context_event_callback_del( mIMFContext, ECORE_IMF_CALLBACK_DELETE_SURROUNDING, ImfDeleteSurrounding );
237 // We do not need to unset the retrieve surrounding callback.
241 void InputMethodContextX::Activate()
243 // Reset mIdleCallbackConnected
244 mIdleCallbackConnected = false;
248 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::Activate\n" );
250 ecore_imf_context_focus_in( mIMFContext );
252 // emit keyboard activated signal
253 Dali::InputMethodContext handle( this );
254 mActivatedSignal.Emit( handle );
258 void InputMethodContextX::Deactivate()
262 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::Deactivate\n" );
265 ecore_imf_context_focus_out( mIMFContext );
268 // Reset mIdleCallbackConnected
269 mIdleCallbackConnected = false;
272 void InputMethodContextX::Reset()
274 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::Reset\n" );
278 ecore_imf_context_reset( mIMFContext );
282 ImfContext* InputMethodContextX::GetContext()
284 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetContext\n" );
289 bool InputMethodContextX::RestoreAfterFocusLost() const
291 return mRestoreAfterFocusLost;
294 void InputMethodContextX::SetRestoreAfterFocusLost( bool toggle )
296 mRestoreAfterFocusLost = toggle;
300 * Called when an InputMethodContext Pre-Edit changed event is received.
301 * We are still predicting what the user is typing. The latest string is what the InputMethodContext module thinks
302 * the user wants to type.
304 void InputMethodContextX::PreEditChanged( void*, ImfContext* imfContext, void* eventInfo )
306 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::PreEditChanged\n" );
307 auto context = static_cast<Ecore_IMF_Context*>( imfContext );
309 char* preEditString( NULL );
310 int cursorPosition( 0 );
311 Eina_List* attrs = NULL;
314 Ecore_IMF_Preedit_Attr* attr;
316 // Retrieves attributes as well as the string the cursor position offset from start of pre-edit string.
317 // the attributes (attrs) is used in languages that use the soft arrows keys to insert characters into a current pre-edit string.
318 ecore_imf_context_preedit_string_with_attributes_get( context, &preEditString, &attrs, &cursorPosition );
322 // iterate through the list of attributes getting the type, start and end position.
323 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) ) ))
325 #ifdef DALI_PROFILE_UBUNTU
326 if ( attr->preedit_type == ECORE_IMF_PREEDIT_TYPE_SUB3 ) // (Ecore_IMF)
327 #else // DALI_PROFILE_UBUNTU
328 if ( attr->preedit_type == ECORE_IMF_PREEDIT_TYPE_SUB4 ) // (Ecore_IMF)
329 #endif // DALI_PROFILE_UBUNTU
331 // 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.
333 size_t visualCharacterIndex = 0;
334 size_t byteIndex = 0;
336 // iterate through null terminated string checking each character's position against the given byte position ( attr->end_index ).
337 const char leadByte = preEditString[byteIndex];
338 while( leadByte != '\0' )
340 // attr->end_index is provided as a byte position not character and we need to know the character position.
341 const size_t currentSequenceLength = Utf8SequenceLength( leadByte ); // returns number of bytes used to represent character.
342 if ( byteIndex == attr->end_index )
344 cursorPosition = static_cast<int>( visualCharacterIndex );
346 // end loop as found cursor position that matches byte position
350 byteIndex += currentSequenceLength; // jump to next character
351 visualCharacterIndex++; // increment character count so we know our position for when we get a match
354 DALI_ASSERT_DEBUG( visualCharacterIndex < strlen( preEditString ));
360 if ( Dali::Adaptor::IsAvailable() )
362 Dali::InputMethodContext handle( this );
363 Dali::InputMethodContext::EventData eventData( Dali::InputMethodContext::PRE_EDIT, preEditString, cursorPosition, 0 );
364 Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit( handle, eventData );
366 if( callbackData.update )
368 mIMFCursorPosition = static_cast<int>( callbackData.cursorPosition );
370 NotifyCursorPosition();
373 if( callbackData.preeditResetRequired )
378 free( preEditString );
381 void InputMethodContextX::CommitReceived( void*, ImfContext* imfContext, void* eventInfo )
383 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::CommitReceived\n" );
385 if ( Dali::Adaptor::IsAvailable() )
387 const std::string keyString( static_cast<char*>( eventInfo ) );
389 Dali::InputMethodContext handle( this );
390 Dali::InputMethodContext::EventData eventData( Dali::InputMethodContext::COMMIT, keyString, 0, 0 );
391 Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit( handle, eventData );
393 if( callbackData.update )
395 mIMFCursorPosition = static_cast<int>( callbackData.cursorPosition );
397 NotifyCursorPosition();
403 * Called when an InputMethodContext retrieve surround event is received.
404 * Here the InputMethodContext module wishes to know the string we are working with and where within the string the cursor is
405 * We need to signal the application to tell us this information.
407 bool InputMethodContextX::RetrieveSurrounding( void* data, ImfContext* imfContext, char** text, int* cursorPosition )
409 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::RetrieveSurrounding\n" );
411 Dali::InputMethodContext::EventData imfData( Dali::InputMethodContext::GET_SURROUNDING, std::string(), 0, 0 );
412 Dali::InputMethodContext handle( this );
413 Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit( handle, imfData );
415 if( callbackData.update )
419 *text = strdup( callbackData.currentText.c_str() );
424 mIMFCursorPosition = static_cast<int>( callbackData.cursorPosition );
425 *cursorPosition = mIMFCursorPosition;
433 * Called when an InputMethodContext delete surrounding event is received.
434 * Here we tell the application that it should delete a certain range.
436 void InputMethodContextX::DeleteSurrounding( void* data, ImfContext* imfContext, void* eventInfo )
438 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::DeleteSurrounding\n" );
440 if( Dali::Adaptor::IsAvailable() )
442 Ecore_IMF_Event_Delete_Surrounding* deleteSurroundingEvent = static_cast<Ecore_IMF_Event_Delete_Surrounding*>( eventInfo );
444 Dali::InputMethodContext::EventData imfData( Dali::InputMethodContext::DELETE_SURROUNDING, std::string(), deleteSurroundingEvent->offset, deleteSurroundingEvent->n_chars );
445 Dali::InputMethodContext handle( this );
446 Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit( handle, imfData );
448 if( callbackData.update )
450 mIMFCursorPosition = static_cast<int>( callbackData.cursorPosition );
452 NotifyCursorPosition();
457 void InputMethodContextX::NotifyCursorPosition()
459 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::NotifyCursorPosition\n" );
463 ecore_imf_context_cursor_position_set( mIMFContext, mIMFCursorPosition );
467 void InputMethodContextX::SetCursorPosition( unsigned int cursorPosition )
469 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::SetCursorPosition\n" );
471 mIMFCursorPosition = static_cast<int>( cursorPosition );
474 unsigned int InputMethodContextX::GetCursorPosition() const
476 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetCursorPosition\n" );
478 return static_cast<unsigned int>( mIMFCursorPosition );
481 void InputMethodContextX::SetSurroundingText( const std::string& text )
483 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::SetSurroundingText\n" );
485 mSurroundingText = text;
488 const std::string& InputMethodContextX::GetSurroundingText() const
490 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetSurroundingText\n" );
492 return mSurroundingText;
495 void InputMethodContextX::NotifyTextInputMultiLine( bool multiLine )
499 Dali::InputMethodContext::TextDirection InputMethodContextX::GetTextDirection()
501 Dali::InputMethodContext::TextDirection direction ( Dali::InputMethodContext::LeftToRight );
505 char* locale( NULL );
506 ecore_imf_context_input_panel_language_locale_get( mIMFContext, &locale );
510 direction = static_cast< Dali::InputMethodContext::TextDirection >( Locale::GetDirection( std::string( locale ) ) );
518 Rect<int> InputMethodContextX::GetInputMethodArea()
520 int xPos, yPos, width, height;
522 width = height = xPos = yPos = 0;
526 ecore_imf_context_input_panel_geometry_get( mIMFContext, &xPos, &yPos, &width, &height );
530 DALI_LOG_WARNING("VKB Unable to get InputMethodContext Context so GetSize unavailable\n");
533 return Rect<int>(xPos,yPos,width,height);
536 void InputMethodContextX::ApplyOptions( const InputMethodOptions& options )
538 using namespace Dali::InputMethod::Category;
542 if (mIMFContext == NULL)
544 DALI_LOG_WARNING("VKB Unable to excute ApplyOptions with Null ImfContext\n");
548 if ( mOptions.CompareAndSet(PANEL_LAYOUT, options, index) )
551 if ( mOptions.CompareAndSet(BUTTON_ACTION, options, index) )
554 if ( mOptions.CompareAndSet(AUTO_CAPITALIZE, options, index) )
557 if ( mOptions.CompareAndSet(VARIATION, options, index) )
562 void InputMethodContextX::SetInputPanelData( const std::string& data )
564 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::SetInputPanelData\n" );
568 int length = data.length();
569 ecore_imf_context_input_panel_imdata_set( mIMFContext, data.c_str(), length );
573 void InputMethodContextX::GetInputPanelData( std::string& data )
575 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetInputPanelData\n" );
579 int length = 4096; // The max length is 4096 bytes
580 Dali::Vector< char > buffer;
581 buffer.Resize( length );
582 ecore_imf_context_input_panel_imdata_get( mIMFContext, &buffer[0], &length );
583 data = std::string( buffer.Begin(), buffer.End() );
587 Dali::InputMethodContext::State InputMethodContextX::GetInputPanelState()
589 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetInputPanelState\n" );
594 value = ecore_imf_context_input_panel_state_get( mIMFContext );
598 case ECORE_IMF_INPUT_PANEL_STATE_SHOW:
600 return Dali::InputMethodContext::SHOW;
604 case ECORE_IMF_INPUT_PANEL_STATE_HIDE:
606 return Dali::InputMethodContext::HIDE;
610 case ECORE_IMF_INPUT_PANEL_STATE_WILL_SHOW:
612 return Dali::InputMethodContext::WILL_SHOW;
618 return Dali::InputMethodContext::DEFAULT;
622 return Dali::InputMethodContext::DEFAULT;
625 void InputMethodContextX::SetReturnKeyState( bool visible )
627 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::SetReturnKeyState\n" );
631 ecore_imf_context_input_panel_return_key_disabled_set( mIMFContext, !visible );
635 void InputMethodContextX::AutoEnableInputPanel( bool enabled )
637 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::AutoEnableInputPanel\n" );
641 ecore_imf_context_input_panel_enabled_set( mIMFContext, enabled );
645 void InputMethodContextX::ShowInputPanel()
647 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::ShowInputPanel\n" );
651 ecore_imf_context_input_panel_show( mIMFContext );
655 void InputMethodContextX::HideInputPanel()
657 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::HideInputPanel\n" );
661 ecore_imf_context_input_panel_hide( mIMFContext );
665 Dali::InputMethodContext::KeyboardType InputMethodContextX::GetKeyboardType()
667 return Dali::InputMethodContext::KeyboardType::SOFTWARE_KEYBOARD;
670 std::string InputMethodContextX::GetInputPanelLocale()
672 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetInputPanelLocale\n" );
674 std::string locale = "";
679 ecore_imf_context_input_panel_language_locale_get( mIMFContext, &value );
683 std::string valueCopy( value );
686 // The locale string retrieved must be freed with free().
693 void InputMethodContextX::SetContentMIMETypes( const std::string& mimeTypes )
695 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::SetContentMIMETypes\n" );
696 // ecore_imf_context_mime_type_accept_set() is supported from ecore-imf 1.20.0 version.
699 bool InputMethodContextX::FilterEventKey( const Dali::KeyEvent& keyEvent )
701 bool eventHandled( false );
703 // If a device key then skip ecore_imf_context_filter_event.
704 if ( ! KeyLookup::IsDeviceButton( keyEvent.keyPressedName.c_str() ))
706 //check whether it's key down or key up event
707 if ( keyEvent.state == KeyEvent::Down )
709 eventHandled = ProcessEventKeyDown( keyEvent );
711 else if ( keyEvent.state == KeyEvent::Up )
713 eventHandled = ProcessEventKeyUp( keyEvent );
720 void InputMethodContextX::AllowTextPrediction( bool prediction )
722 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::AllowTextPrediction\n" );
726 ecore_imf_context_prediction_allow_set( mIMFContext, prediction );
730 bool InputMethodContextX::IsTextPredictionAllowed() const
732 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::IsTextPredictionAllowed\n" );
733 bool prediction = false;
736 prediction = ecore_imf_context_prediction_allow_get( mIMFContext );
741 void InputMethodContextX::SetInputPanelLanguage( Dali::InputMethodContext::InputPanelLanguage language )
743 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::SetInputPanelLanguage\n" );
748 case Dali::InputMethodContext::InputPanelLanguage::AUTOMATIC:
750 ecore_imf_context_input_panel_language_set( mIMFContext, ECORE_IMF_INPUT_PANEL_LANG_AUTOMATIC );
753 case Dali::InputMethodContext::InputPanelLanguage::ALPHABET:
755 ecore_imf_context_input_panel_language_set( mIMFContext, ECORE_IMF_INPUT_PANEL_LANG_ALPHABET );
762 Dali::InputMethodContext::InputPanelLanguage InputMethodContextX::GetInputPanelLanguage() const
764 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetInputPanelLanguage\n" );
768 value = ecore_imf_context_input_panel_language_get( mIMFContext );
772 case ECORE_IMF_INPUT_PANEL_LANG_AUTOMATIC:
774 return Dali::InputMethodContext::InputPanelLanguage::AUTOMATIC;
777 case ECORE_IMF_INPUT_PANEL_LANG_ALPHABET:
779 return Dali::InputMethodContext::InputPanelLanguage::ALPHABET;
784 return Dali::InputMethodContext::InputPanelLanguage::AUTOMATIC;
787 void InputMethodContextX::SetInputPanelPosition( unsigned int x, unsigned int y )
789 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::SetInputPanelPosition\n" );
791 // ecore_imf_context_input_panel_position_set() is supported from ecore-imf 1.21.0 version.
794 bool InputMethodContextX::ProcessEventKeyDown( const KeyEvent& keyEvent )
796 bool eventHandled( false );
799 Integration::KeyEvent integKeyEvent( keyEvent );
800 std::string key = integKeyEvent.logicalKey;
802 std::string compose = keyEvent.GetCompose();
804 // We're consuming key down event so we have to pass to InputMethodContext so that it can parse it as well.
805 Ecore_IMF_Event_Key_Down ecoreKeyDownEvent;
806 ecoreKeyDownEvent.keyname = keyEvent.keyPressedName.c_str();
807 ecoreKeyDownEvent.key = key.c_str();
808 ecoreKeyDownEvent.string = keyEvent.keyPressed.c_str();
809 ecoreKeyDownEvent.compose = compose.c_str();
810 ecoreKeyDownEvent.timestamp = keyEvent.time;
811 ecoreKeyDownEvent.modifiers = EcoreInputModifierToEcoreIMFModifier( keyEvent.keyModifier );
812 ecoreKeyDownEvent.locks = EcoreInputModifierToEcoreIMFLock( keyEvent.keyModifier );
814 #if defined(ECORE_VERSION_MAJOR) && (ECORE_VERSION_MAJOR >= 1) && defined(ECORE_VERSION_MINOR)
815 #if (ECORE_VERSION_MINOR >= 14)
816 ecoreKeyDownEvent.dev_name = "";
817 ecoreKeyDownEvent.dev_class = ECORE_IMF_DEVICE_CLASS_KEYBOARD;
818 ecoreKeyDownEvent.dev_subclass = ECORE_IMF_DEVICE_SUBCLASS_NONE;
819 #endif // Since ecore_imf 1.14 version
820 #if (ECORE_VERSION_MINOR >= 22)
821 ecoreKeyDownEvent.keycode = keyEvent.keyCode;
822 #endif // Since ecore_imf 1.22 version
823 #endif // Since ecore_imf Version 1
825 // 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.
826 if ((keyEvent.GetDeviceName() == "ime") && ((!strncmp(keyEvent.keyPressedName.c_str(), "Left", 4)) ||
827 (!strncmp(keyEvent.keyPressedName.c_str(), "Right", 5)) ||
828 (!strncmp(keyEvent.keyPressedName.c_str(), "Up", 2)) ||
829 (!strncmp(keyEvent.keyPressedName.c_str(), "Down", 4))))
835 eventHandled = ecore_imf_context_filter_event(mIMFContext,
836 ECORE_IMF_EVENT_KEY_DOWN,
837 reinterpret_cast<Ecore_IMF_Event *>( &ecoreKeyDownEvent ));
840 // If the event has not been handled by InputMethodContext then check if we should reset our IMFcontext
843 if (!strcmp(keyEvent.keyPressedName.c_str(), "Escape") ||
844 !strcmp(keyEvent.keyPressedName.c_str(), "Return") ||
845 !strcmp(keyEvent.keyPressedName.c_str(), "KP_Enter"))
847 ecore_imf_context_reset(mIMFContext);
854 bool InputMethodContextX::ProcessEventKeyUp( const KeyEvent& keyEvent )
856 bool eventHandled( false );
859 Integration::KeyEvent integKeyEvent( keyEvent );
860 std::string key = integKeyEvent.logicalKey;
862 std::string compose = keyEvent.GetCompose();
864 // We're consuming key up event so we have to pass to InputMethodContext so that it can parse it as well.
865 Ecore_IMF_Event_Key_Up ecoreKeyUpEvent;
866 ecoreKeyUpEvent.keyname = keyEvent.keyPressedName.c_str();
867 ecoreKeyUpEvent.key = key.c_str();
868 ecoreKeyUpEvent.string = keyEvent.keyPressed.c_str();
869 ecoreKeyUpEvent.compose = compose.c_str();
870 ecoreKeyUpEvent.timestamp = keyEvent.time;
871 ecoreKeyUpEvent.modifiers = EcoreInputModifierToEcoreIMFModifier( keyEvent.keyModifier );
872 ecoreKeyUpEvent.locks = EcoreInputModifierToEcoreIMFLock( keyEvent.keyModifier );
873 #if defined(ECORE_VERSION_MAJOR) && (ECORE_VERSION_MAJOR >= 1) && defined(ECORE_VERSION_MINOR)
874 #if (ECORE_VERSION_MINOR >= 14)
875 ecoreKeyUpEvent.dev_name = "";
876 #endif // Since ecore_imf 1.14 version
877 #if (ECORE_VERSION_MINOR >= 22)
878 ecoreKeyUpEvent.keycode = keyEvent.keyCode;
879 #endif // Since ecore_imf 1.22 version
880 #endif // Since ecore_imf Version 1
882 eventHandled = ecore_imf_context_filter_event(mIMFContext,
883 ECORE_IMF_EVENT_KEY_UP,
884 reinterpret_cast<Ecore_IMF_Event *>( &ecoreKeyUpEvent ));
889 Ecore_IMF_Keyboard_Modifiers InputMethodContextX::EcoreInputModifierToEcoreIMFModifier( unsigned int ecoreModifier )
891 unsigned int modifier( ECORE_IMF_KEYBOARD_MODIFIER_NONE ); // If no other matches returns NONE.
893 if ( ecoreModifier & ECORE_EVENT_MODIFIER_SHIFT ) // enums from ecore_input/Ecore_Input.h
895 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_SHIFT; // enums from ecore_imf/ecore_imf.h
898 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALT )
900 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALT;
903 if ( ecoreModifier & ECORE_EVENT_MODIFIER_CTRL )
905 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_CTRL;
908 if ( ecoreModifier & ECORE_EVENT_MODIFIER_WIN )
910 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_WIN;
913 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALTGR )
915 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALTGR;
918 return static_cast<Ecore_IMF_Keyboard_Modifiers>( modifier );
921 Ecore_IMF_Keyboard_Locks InputMethodContextX::EcoreInputModifierToEcoreIMFLock( unsigned int modifier )
923 unsigned int lock( ECORE_IMF_KEYBOARD_LOCK_NONE ); // If no other matches, returns NONE.
925 if( modifier & ECORE_EVENT_LOCK_NUM )
927 lock |= ECORE_IMF_KEYBOARD_LOCK_NUM; // Num lock is active.
930 if( modifier & ECORE_EVENT_LOCK_CAPS )
932 lock |= ECORE_IMF_KEYBOARD_LOCK_CAPS; // Caps lock is active.
935 if( modifier & ECORE_EVENT_LOCK_SCROLL )
937 lock |= ECORE_IMF_KEYBOARD_LOCK_SCROLL; // Scroll lock is active.
940 return static_cast<Ecore_IMF_Keyboard_Locks>( lock );
943 void InputMethodContextX::OnStaged( Dali::Actor actor )
945 Ecore_X_Window ecoreXwin( AnyCast< Ecore_X_Window >( Dali::Integration::SceneHolder::Get( actor ).GetNativeHandle() ) );
947 if( mEcoreXwin != ecoreXwin )
949 mEcoreXwin = ecoreXwin;