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.
20 #include <dali/internal/input/tizen-wayland/input-method-context-impl-ecore-wl.h>
23 #include <Ecore_Input.h>
26 #include <Ecore_Wl2.h>
28 #include <Ecore_Wayland.h>
31 #include <dali/public-api/events/key-event.h>
32 #include <dali/public-api/adaptor-framework/key.h>
33 #include <dali/public-api/object/type-registry.h>
34 #include <dali/integration-api/debug.h>
37 #include <dali/public-api/adaptor-framework/input-method.h>
38 #include <dali/integration-api/adaptor-framework/adaptor.h>
39 #include <dali/integration-api/adaptor-framework/scene-holder.h>
40 #include <dali/internal/input/common/key-impl.h>
41 #include <dali/internal/system/common/locale-utils.h>
42 #include <dali/internal/system/common/singleton-service-impl.h>
43 #include <dali/internal/window-system/common/window-render-surface.h>
45 #define TOKEN_STRING(x) #x
47 Ecore_IMF_Input_Panel_Layout panelLayoutMap[] =
49 ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL,
50 ECORE_IMF_INPUT_PANEL_LAYOUT_NUMBER,
51 ECORE_IMF_INPUT_PANEL_LAYOUT_EMAIL,
52 ECORE_IMF_INPUT_PANEL_LAYOUT_URL,
53 ECORE_IMF_INPUT_PANEL_LAYOUT_PHONENUMBER,
54 ECORE_IMF_INPUT_PANEL_LAYOUT_IP,
55 ECORE_IMF_INPUT_PANEL_LAYOUT_MONTH,
56 ECORE_IMF_INPUT_PANEL_LAYOUT_NUMBERONLY,
57 ECORE_IMF_INPUT_PANEL_LAYOUT_HEX,
58 ECORE_IMF_INPUT_PANEL_LAYOUT_TERMINAL,
59 ECORE_IMF_INPUT_PANEL_LAYOUT_PASSWORD,
60 ECORE_IMF_INPUT_PANEL_LAYOUT_DATETIME,
61 ECORE_IMF_INPUT_PANEL_LAYOUT_EMOTICON,
62 ECORE_IMF_INPUT_PANEL_LAYOUT_VOICE
65 Ecore_IMF_Autocapital_Type autoCapitalMap[] =
67 ECORE_IMF_AUTOCAPITAL_TYPE_NONE,
68 ECORE_IMF_AUTOCAPITAL_TYPE_WORD,
69 ECORE_IMF_AUTOCAPITAL_TYPE_SENTENCE,
70 ECORE_IMF_AUTOCAPITAL_TYPE_ALLCHARACTER,
73 Ecore_IMF_Input_Panel_Return_Key_Type returnKeyTypeMap[] =
75 ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DEFAULT,
76 ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DONE,
77 ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_GO,
78 ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_JOIN,
79 ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_LOGIN,
80 ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_NEXT,
81 ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_SEARCH,
82 ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_SEND,
83 ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_SIGNIN
97 #if defined(DEBUG_ENABLED)
98 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_INPUT_METHOD_CONTEXT");
101 const int kUninitializedWindowId = 0;
103 // Currently this code is internal to dali/dali/internal/event/text/utf8.h but should be made Public and used from there instead.
104 size_t Utf8SequenceLength(const unsigned char leadByte)
108 if ((leadByte & 0x80) == 0 ) //ASCII character (lead bit zero)
112 else if (( leadByte & 0xe0 ) == 0xc0 ) //110x xxxx
116 else if (( leadByte & 0xf0 ) == 0xe0 ) //1110 xxxx
120 else if (( leadByte & 0xf8 ) == 0xf0 ) //1111 0xxx
128 // Static function calls used by ecore 'c' style callback registration
129 void Commit( void *data, Ecore_IMF_Context *imfContext, void *eventInfo )
133 InputMethodContextEcoreWl* inputMethodContext = static_cast< InputMethodContextEcoreWl* >( data );
134 inputMethodContext->CommitReceived( data, imfContext, eventInfo );
138 void PreEdit( void *data, Ecore_IMF_Context *imfContext, void *eventInfo )
142 InputMethodContextEcoreWl* inputMethodContext = static_cast< InputMethodContextEcoreWl* >( data );
143 inputMethodContext->PreEditChanged( data, imfContext, eventInfo );
147 Eina_Bool ImfRetrieveSurrounding(void *data, Ecore_IMF_Context *imfContext, char** text, int* cursorPosition )
151 InputMethodContextEcoreWl* inputMethodContext = static_cast< InputMethodContextEcoreWl* >( data );
152 return inputMethodContext->RetrieveSurrounding( data, imfContext, text, cursorPosition );
160 void InputPanelStateChangeCallback( void* data, Ecore_IMF_Context* context, int value )
166 InputMethodContextEcoreWl* inputMethodContext = static_cast< InputMethodContextEcoreWl* >( data );
169 case ECORE_IMF_INPUT_PANEL_STATE_SHOW:
171 inputMethodContext->StatusChangedSignal().Emit( true );
175 case ECORE_IMF_INPUT_PANEL_STATE_HIDE:
177 inputMethodContext->StatusChangedSignal().Emit( false );
181 case ECORE_IMF_INPUT_PANEL_STATE_WILL_SHOW:
190 void InputPanelLanguageChangeCallback( void* data, Ecore_IMF_Context* context, int value )
196 InputMethodContextEcoreWl* inputMethodContext = static_cast< InputMethodContextEcoreWl* >( data );
197 // Emit the signal that the language has changed
198 inputMethodContext->LanguageChangedSignal().Emit(value);
201 void InputPanelGeometryChangedCallback ( void *data, Ecore_IMF_Context *context, int value )
207 InputMethodContextEcoreWl* inputMethodContext = static_cast< InputMethodContextEcoreWl* >( data );
208 // Emit signal that the keyboard is resized
209 inputMethodContext->ResizedSignal().Emit(value);
212 void InputPanelKeyboardTypeChangedCallback( void *data, Ecore_IMF_Context *context, int value )
219 InputMethodContextEcoreWl* inputMethodContext = static_cast< InputMethodContextEcoreWl* >( data );
222 case ECORE_IMF_INPUT_PANEL_SW_KEYBOARD_MODE:
224 // Emit Signal that the keyboard type is changed to Software Keyboard
225 inputMethodContext->KeyboardTypeChangedSignal().Emit( Dali::InputMethodContext::KeyboardType::SOFTWARE_KEYBOARD );
228 case ECORE_IMF_INPUT_PANEL_HW_KEYBOARD_MODE:
230 // Emit Signal that the keyboard type is changed to Hardware Keyboard
231 inputMethodContext->KeyboardTypeChangedSignal().Emit( Dali::InputMethodContext::KeyboardType::HARDWARE_KEYBOARD );
238 * Called when an IMF delete surrounding event is received.
239 * Here we tell the application that it should delete a certain range.
241 void ImfDeleteSurrounding( void *data, Ecore_IMF_Context *imfContext, void *eventInfo )
245 InputMethodContextEcoreWl* inputMethodContext = static_cast< InputMethodContextEcoreWl* >( data );
246 inputMethodContext->DeleteSurrounding( data, imfContext, eventInfo );
251 * Called when the input method sends a private command.
253 void PrivateCommand( void *data, Ecore_IMF_Context *imfContext, void *eventInfo )
257 InputMethodContextEcoreWl* inputMethodContext = static_cast< InputMethodContextEcoreWl* >( data );
258 inputMethodContext->SendPrivateCommand( data, imfContext, eventInfo );
263 * Called when the input method commits content, such as an image.
265 void CommitContent( void *data, Ecore_IMF_Context *imfContext, void *eventInfo )
269 InputMethodContextEcoreWl* inputMethodContext = static_cast< InputMethodContextEcoreWl* >( data );
270 inputMethodContext->SendCommitContent( data, imfContext, eventInfo );
274 int GetWindowIdFromActor( Dali::Actor actor )
276 int windowId = kUninitializedWindowId;
278 if( actor.OnStage() )
280 Any nativeWindowHandle = Dali::Integration::SceneHolder::Get( actor ).GetNativeHandle();
282 #ifdef ECORE_WAYLAND2
283 windowId = ecore_wl2_window_id_get( AnyCast< Ecore_Wl2_Window* >( nativeWindowHandle ) );
285 windowId = ecore_wl_window_id_get( AnyCast< Ecore_Wl_Window* >( nativeWindowHandle ) );
294 return Dali::InputMethodContext::New( Dali::Actor() );
297 Dali::TypeRegistration type( typeid(Dali::InputMethodContext), typeid(Dali::BaseHandle), Create );
299 } // unnamed namespace
301 InputMethodContextPtr InputMethodContextEcoreWl::New( Dali::Actor actor )
303 InputMethodContextPtr inputMethodContext;
305 // Create instance only if the adaptor is available and the valid actor exists
306 if ( actor && Dali::Adaptor::IsAvailable() )
308 inputMethodContext = new InputMethodContextEcoreWl( actor );
310 return inputMethodContext;
313 void InputMethodContextEcoreWl::Finalize()
315 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContext::Finalize\n" );
317 DisconnectCallbacks();
321 InputMethodContextEcoreWl::InputMethodContextEcoreWl( Dali::Actor actor )
323 mIMFCursorPosition( 0 ),
325 mRestoreAfterFocusLost( false ),
326 mIdleCallbackConnected( false ),
327 mPreeditType( Dali::InputMethodContext::PreeditStyle::NONE ),
328 mWindowId( GetWindowIdFromActor( actor ) )
332 actor.OnStageSignal().Connect( this, &InputMethodContextEcoreWl::OnStaged );
335 InputMethodContextEcoreWl::~InputMethodContextEcoreWl()
338 ecore_imf_shutdown();
341 void InputMethodContextEcoreWl::Initialize()
347 void InputMethodContextEcoreWl::CreateContext()
349 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContext::CreateContext\n" );
351 if( mWindowId == kUninitializedWindowId )
356 const char *contextId = ecore_imf_context_default_id_get();
359 mIMFContext = ecore_imf_context_add( contextId );
363 ecore_imf_context_client_window_set( mIMFContext, reinterpret_cast< void* >( mWindowId ) );
367 DALI_LOG_WARNING( "InputMethodContext Unable to get IMFContext\n" );
372 DALI_LOG_WARNING( "InputMethodContext Unable to get IMFContext\n" );
376 void InputMethodContextEcoreWl::DeleteContext()
378 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::DeleteContext\n" );
382 ecore_imf_context_del( mIMFContext );
387 // Callbacks for predicitive text support.
388 void InputMethodContextEcoreWl::ConnectCallbacks()
392 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::ConnectCallbacks\n" );
394 ecore_imf_context_event_callback_add( mIMFContext, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, PreEdit, this );
395 ecore_imf_context_event_callback_add( mIMFContext, ECORE_IMF_CALLBACK_COMMIT, Commit, this );
396 ecore_imf_context_event_callback_add( mIMFContext, ECORE_IMF_CALLBACK_DELETE_SURROUNDING, ImfDeleteSurrounding, this );
397 ecore_imf_context_event_callback_add( mIMFContext, ECORE_IMF_CALLBACK_PRIVATE_COMMAND_SEND, PrivateCommand, this );
398 ecore_imf_context_event_callback_add( mIMFContext, ECORE_IMF_CALLBACK_COMMIT_CONTENT, CommitContent, this );
400 ecore_imf_context_input_panel_event_callback_add( mIMFContext, ECORE_IMF_INPUT_PANEL_STATE_EVENT, InputPanelStateChangeCallback, this );
401 ecore_imf_context_input_panel_event_callback_add( mIMFContext, ECORE_IMF_INPUT_PANEL_LANGUAGE_EVENT, InputPanelLanguageChangeCallback, this );
402 ecore_imf_context_input_panel_event_callback_add( mIMFContext, ECORE_IMF_INPUT_PANEL_GEOMETRY_EVENT, InputPanelGeometryChangedCallback, this );
403 ecore_imf_context_input_panel_event_callback_add( mIMFContext, ECORE_IMF_INPUT_PANEL_KEYBOARD_MODE_EVENT, InputPanelKeyboardTypeChangedCallback, this );
405 ecore_imf_context_retrieve_surrounding_callback_set( mIMFContext, ImfRetrieveSurrounding, this);
409 void InputMethodContextEcoreWl::DisconnectCallbacks()
413 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::DisconnectCallbacks\n" );
415 ecore_imf_context_event_callback_del( mIMFContext, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, PreEdit );
416 ecore_imf_context_event_callback_del( mIMFContext, ECORE_IMF_CALLBACK_COMMIT, Commit );
417 ecore_imf_context_event_callback_del( mIMFContext, ECORE_IMF_CALLBACK_DELETE_SURROUNDING, ImfDeleteSurrounding );
418 ecore_imf_context_event_callback_del( mIMFContext, ECORE_IMF_CALLBACK_PRIVATE_COMMAND_SEND, PrivateCommand );
419 ecore_imf_context_event_callback_del( mIMFContext, ECORE_IMF_CALLBACK_COMMIT_CONTENT, CommitContent );
421 ecore_imf_context_input_panel_event_callback_del( mIMFContext, ECORE_IMF_INPUT_PANEL_STATE_EVENT, InputPanelStateChangeCallback );
422 ecore_imf_context_input_panel_event_callback_del( mIMFContext, ECORE_IMF_INPUT_PANEL_LANGUAGE_EVENT, InputPanelLanguageChangeCallback );
423 ecore_imf_context_input_panel_event_callback_del( mIMFContext, ECORE_IMF_INPUT_PANEL_GEOMETRY_EVENT, InputPanelGeometryChangedCallback );
424 ecore_imf_context_input_panel_event_callback_del( mIMFContext, ECORE_IMF_INPUT_PANEL_KEYBOARD_MODE_EVENT, InputPanelKeyboardTypeChangedCallback );
426 // We do not need to unset the retrieve surrounding callback.
430 void InputMethodContextEcoreWl::Activate()
432 // Reset mIdleCallbackConnected
433 mIdleCallbackConnected = false;
437 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::Activate\n" );
439 ecore_imf_context_focus_in( mIMFContext );
441 // emit keyboard activated signal
442 Dali::InputMethodContext handle( this );
443 mActivatedSignal.Emit( handle );
447 void InputMethodContextEcoreWl::Deactivate()
451 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::Deactivate\n" );
454 ecore_imf_context_focus_out( mIMFContext );
457 // Reset mIdleCallbackConnected
458 mIdleCallbackConnected = false;
461 void InputMethodContextEcoreWl::Reset()
463 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::Reset\n" );
467 ecore_imf_context_reset( mIMFContext );
471 ImfContext* InputMethodContextEcoreWl::GetContext()
473 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::GetContext\n" );
478 bool InputMethodContextEcoreWl::RestoreAfterFocusLost() const
480 return mRestoreAfterFocusLost;
483 void InputMethodContextEcoreWl::SetRestoreAfterFocusLost( bool toggle )
485 mRestoreAfterFocusLost = toggle;
489 * Called when an InputMethodContext Pre-Edit changed event is received.
490 * We are still predicting what the user is typing. The latest string is what the InputMethodContext module thinks
491 * the user wants to type.
493 void InputMethodContextEcoreWl::PreEditChanged( void*, ImfContext* imfContext, void* eventInfo )
495 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::PreEditChanged\n" );
496 auto context = static_cast<Ecore_IMF_Context*>( imfContext );
498 char* preEditString( NULL );
499 int cursorPosition( 0 );
500 Eina_List* attrs = NULL;
503 Ecore_IMF_Preedit_Attr* attr;
505 // Retrieves attributes as well as the string the cursor position offset from start of pre-edit string.
506 // the attributes (attrs) is used in languages that use the soft arrows keys to insert characters into a current pre-edit string.
507 ecore_imf_context_preedit_string_with_attributes_get( context, &preEditString, &attrs, &cursorPosition );
511 // iterate through the list of attributes getting the type, start and end position.
512 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) ) ))
514 switch( attr->preedit_type )
516 case ECORE_IMF_PREEDIT_TYPE_NONE:
518 mPreeditType = Dali::InputMethodContext::PreeditStyle::NONE;
521 case ECORE_IMF_PREEDIT_TYPE_SUB1:
523 mPreeditType = Dali::InputMethodContext::PreeditStyle::UNDERLINE;
526 case ECORE_IMF_PREEDIT_TYPE_SUB2:
528 mPreeditType = Dali::InputMethodContext::PreeditStyle::REVERSE;
531 case ECORE_IMF_PREEDIT_TYPE_SUB3:
533 mPreeditType = Dali::InputMethodContext::PreeditStyle::HIGHLIGHT;
542 #ifdef DALI_PROFILE_UBUNTU
543 if ( attr->preedit_type == ECORE_IMF_PREEDIT_TYPE_SUB3 ) // (Ecore_IMF)
544 #else // DALI_PROFILE_UBUNTU
545 if ( attr->preedit_type == ECORE_IMF_PREEDIT_TYPE_SUB4 ) // (Ecore_IMF)
546 #endif // DALI_PROFILE_UBUNTU
548 // 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.
550 size_t visualCharacterIndex = 0;
551 size_t byteIndex = 0;
553 // iterate through null terminated string checking each character's position against the given byte position ( attr->end_index ).
554 const char leadByte = preEditString[byteIndex];
555 while( leadByte != '\0' )
557 // attr->end_index is provided as a byte position not character and we need to know the character position.
558 const size_t currentSequenceLength = Utf8SequenceLength( leadByte ); // returns number of bytes used to represent character.
559 if ( byteIndex == attr->end_index )
561 cursorPosition = visualCharacterIndex;
563 // end loop as found cursor position that matches byte position
567 byteIndex += currentSequenceLength; // jump to next character
568 visualCharacterIndex++; // increment character count so we know our position for when we get a match
571 DALI_ASSERT_DEBUG( visualCharacterIndex < strlen( preEditString ));
577 if ( Dali::Adaptor::IsAvailable() )
579 Dali::InputMethodContext handle( this );
580 Dali::InputMethodContext::EventData eventData( Dali::InputMethodContext::PRE_EDIT, preEditString, cursorPosition, 0 );
581 Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit( handle, eventData );
583 if ( callbackData.update )
585 SetCursorPosition( callbackData.cursorPosition );
586 SetSurroundingText( callbackData.currentText );
588 NotifyCursorPosition();
591 if ( callbackData.preeditResetRequired )
596 free( preEditString );
599 void InputMethodContextEcoreWl::CommitReceived( void*, ImfContext* imfContext, void* eventInfo )
601 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::CommitReceived\n" );
603 if ( Dali::Adaptor::IsAvailable() )
605 const std::string keyString( static_cast<char*>( eventInfo ) );
607 Dali::InputMethodContext handle( this );
608 Dali::InputMethodContext::EventData eventData( Dali::InputMethodContext::COMMIT, keyString, 0, 0 );
609 Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit( handle, eventData );
611 if( callbackData.update )
613 SetCursorPosition( callbackData.cursorPosition );
614 SetSurroundingText( callbackData.currentText );
616 NotifyCursorPosition();
622 * Called when an InputMethodContext retrieve surround event is received.
623 * Here the InputMethodContext module wishes to know the string we are working with and where within the string the cursor is
624 * We need to signal the application to tell us this information.
626 bool InputMethodContextEcoreWl::RetrieveSurrounding( void* data, ImfContext* imfContext, char** text, int* cursorPosition )
628 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::RetrieveSurrounding\n" );
630 Dali::InputMethodContext::EventData imfData( Dali::InputMethodContext::GET_SURROUNDING, std::string(), 0, 0 );
631 Dali::InputMethodContext handle( this );
632 Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit( handle, imfData );
634 if( callbackData.update )
638 mIMFCursorPosition = static_cast<int>( callbackData.cursorPosition );
639 *cursorPosition = mIMFCursorPosition;
644 const char* plainText = callbackData.currentText.c_str();
648 // The memory allocated by strdup() can be freed by ecore_imf_context_surrounding_get() internally.
649 *text = strdup( plainText );
651 // If the current input panel is password mode, dali should replace the plain text with '*' (Asterisk) character.
652 if( ecore_imf_context_input_hint_get( mIMFContext ) & ECORE_IMF_INPUT_HINT_SENSITIVE_DATA )
654 for( char* iter = *text; *iter; ++iter )
669 * Called when an InputMethodContext delete surrounding event is received.
670 * Here we tell the application that it should delete a certain range.
672 void InputMethodContextEcoreWl::DeleteSurrounding( void* data, ImfContext* imfContext, void* eventInfo )
674 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::DeleteSurrounding\n" );
676 if( Dali::Adaptor::IsAvailable() )
678 Ecore_IMF_Event_Delete_Surrounding* deleteSurroundingEvent = static_cast<Ecore_IMF_Event_Delete_Surrounding*>( eventInfo );
680 Dali::InputMethodContext::EventData imfData( Dali::InputMethodContext::DELETE_SURROUNDING, std::string(), deleteSurroundingEvent->offset, deleteSurroundingEvent->n_chars );
681 Dali::InputMethodContext handle( this );
682 mEventSignal.Emit( handle, imfData );
687 * Called when the input method sends a private command.
689 void InputMethodContextEcoreWl::SendPrivateCommand( void* data, ImfContext* imfContext, void* eventInfo )
691 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::SendPrivateCommand\n" );
693 if( Dali::Adaptor::IsAvailable() )
695 const char* privateCommandSendEvent = static_cast<const char*>( eventInfo );
697 Dali::InputMethodContext::EventData imfData( Dali::InputMethodContext::PRIVATE_COMMAND, privateCommandSendEvent, 0, 0 );
698 Dali::InputMethodContext handle( this );
699 mEventSignal.Emit( handle, imfData );
704 * Called when the input method commits content, such as an image.
706 void InputMethodContextEcoreWl::SendCommitContent( void* data, ImfContext* imfContext, void* eventInfo )
708 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::SendCommitContent\n" );
710 if( Dali::Adaptor::IsAvailable() )
712 Ecore_IMF_Event_Commit_Content* commitContent = static_cast<Ecore_IMF_Event_Commit_Content *>( eventInfo );
715 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::SendCommitContent commit content : %s, description : %s, mime type : %s\n",
716 commitContent->content_uri, commitContent->description, commitContent->mime_types );
717 mContentReceivedSignal.Emit( commitContent->content_uri, commitContent->description, commitContent->mime_types );
722 void InputMethodContextEcoreWl::NotifyCursorPosition()
724 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::NotifyCursorPosition\n" );
728 ecore_imf_context_cursor_position_set( mIMFContext, mIMFCursorPosition );
732 void InputMethodContextEcoreWl::SetCursorPosition( unsigned int cursorPosition )
734 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::SetCursorPosition\n" );
736 mIMFCursorPosition = static_cast<int>( cursorPosition );
739 unsigned int InputMethodContextEcoreWl::GetCursorPosition() const
741 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::GetCursorPosition\n" );
743 return static_cast<unsigned int>( mIMFCursorPosition );
746 void InputMethodContextEcoreWl::SetSurroundingText( const std::string& text )
748 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::SetSurroundingText\n" );
750 mSurroundingText = text;
753 const std::string& InputMethodContextEcoreWl::GetSurroundingText() const
755 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::GetSurroundingText\n" );
757 return mSurroundingText;
760 void InputMethodContextEcoreWl::NotifyTextInputMultiLine( bool multiLine )
764 Ecore_IMF_Input_Hints currentHint = ecore_imf_context_input_hint_get(mIMFContext);
765 ecore_imf_context_input_hint_set( mIMFContext,
766 static_cast< Ecore_IMF_Input_Hints >( multiLine ?
767 (currentHint | ECORE_IMF_INPUT_HINT_MULTILINE) :
768 (currentHint & ~ECORE_IMF_INPUT_HINT_MULTILINE)));
772 Dali::InputMethodContext::TextDirection InputMethodContextEcoreWl::GetTextDirection()
774 Dali::InputMethodContext::TextDirection direction ( Dali::InputMethodContext::LeftToRight );
778 char* locale( NULL );
779 ecore_imf_context_input_panel_language_locale_get( mIMFContext, &locale );
783 direction = static_cast< Dali::InputMethodContext::TextDirection >( Locale::GetDirection( std::string( locale ) ) );
791 Rect<int> InputMethodContextEcoreWl::GetInputMethodArea()
793 int xPos, yPos, width, height;
795 width = height = xPos = yPos = 0;
799 ecore_imf_context_input_panel_geometry_get( mIMFContext, &xPos, &yPos, &width, &height );
803 DALI_LOG_WARNING("VKB Unable to get IMFContext so GetSize unavailable\n");
804 // return 0 as real size unknown.
807 return Rect<int>(xPos,yPos,width,height);
810 void InputMethodContextEcoreWl::ApplyOptions( const InputMethodOptions& options )
812 using namespace Dali::InputMethod::Category;
816 if( mIMFContext == NULL )
818 DALI_LOG_WARNING("VKB Unable to excute ApplyOptions with Null ImfContext\n");
822 if( mOptions.CompareAndSet(PANEL_LAYOUT, options, index) )
824 ecore_imf_context_input_panel_layout_set( mIMFContext, panelLayoutMap[index] );
826 // Sets the input hint which allows input methods to fine-tune their behavior.
827 if( panelLayoutMap[index] == ECORE_IMF_INPUT_PANEL_LAYOUT_PASSWORD )
829 ecore_imf_context_input_hint_set( mIMFContext, static_cast< Ecore_IMF_Input_Hints >( ecore_imf_context_input_hint_get( mIMFContext ) | ECORE_IMF_INPUT_HINT_SENSITIVE_DATA ) );
833 ecore_imf_context_input_hint_set( mIMFContext, static_cast< Ecore_IMF_Input_Hints >( ecore_imf_context_input_hint_get( mIMFContext ) & ~ECORE_IMF_INPUT_HINT_SENSITIVE_DATA ) );
836 if( mOptions.CompareAndSet(BUTTON_ACTION, options, index) )
838 ecore_imf_context_input_panel_return_key_type_set( mIMFContext, returnKeyTypeMap[index] );
840 if( mOptions.CompareAndSet(AUTO_CAPITALIZE, options, index) )
842 ecore_imf_context_autocapital_type_set( mIMFContext, autoCapitalMap[index] );
844 if( mOptions.CompareAndSet(VARIATION, options, index) )
846 ecore_imf_context_input_panel_layout_variation_set( mIMFContext, index );
850 void InputMethodContextEcoreWl::SetInputPanelData( const std::string& data )
852 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::SetInputPanelData\n" );
856 int length = data.length();
857 ecore_imf_context_input_panel_imdata_set( mIMFContext, data.c_str(), length );
861 void InputMethodContextEcoreWl::GetInputPanelData( std::string& data )
863 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::GetInputPanelData\n" );
867 int length = 4096; // The max length is 4096 bytes
868 Dali::Vector< char > buffer;
869 buffer.Resize( length );
870 ecore_imf_context_input_panel_imdata_get( mIMFContext, &buffer[0], &length );
871 data = std::string( buffer.Begin(), buffer.End() );
875 Dali::InputMethodContext::State InputMethodContextEcoreWl::GetInputPanelState()
877 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::GetInputPanelState\n" );
882 value = ecore_imf_context_input_panel_state_get( mIMFContext );
886 case ECORE_IMF_INPUT_PANEL_STATE_SHOW:
888 return Dali::InputMethodContext::SHOW;
892 case ECORE_IMF_INPUT_PANEL_STATE_HIDE:
894 return Dali::InputMethodContext::HIDE;
898 case ECORE_IMF_INPUT_PANEL_STATE_WILL_SHOW:
900 return Dali::InputMethodContext::WILL_SHOW;
906 return Dali::InputMethodContext::DEFAULT;
910 return Dali::InputMethodContext::DEFAULT;
913 void InputMethodContextEcoreWl::SetReturnKeyState( bool visible )
915 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::SetReturnKeyState\n" );
919 ecore_imf_context_input_panel_return_key_disabled_set( mIMFContext, !visible );
923 void InputMethodContextEcoreWl::AutoEnableInputPanel( bool enabled )
925 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::AutoEnableInputPanel\n" );
929 ecore_imf_context_input_panel_enabled_set( mIMFContext, enabled );
933 void InputMethodContextEcoreWl::ShowInputPanel()
935 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::ShowInputPanel\n" );
939 ecore_imf_context_input_panel_show( mIMFContext );
943 void InputMethodContextEcoreWl::HideInputPanel()
945 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::HideInputPanel\n" );
949 ecore_imf_context_input_panel_hide( mIMFContext );
953 Dali::InputMethodContext::KeyboardType InputMethodContextEcoreWl::GetKeyboardType()
955 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::GetKeyboardType\n" );
960 value = ecore_imf_context_keyboard_mode_get( mIMFContext );
964 case ECORE_IMF_INPUT_PANEL_SW_KEYBOARD_MODE:
966 return Dali::InputMethodContext::SOFTWARE_KEYBOARD;
969 case ECORE_IMF_INPUT_PANEL_HW_KEYBOARD_MODE:
971 return Dali::InputMethodContext::HARDWARE_KEYBOARD;
977 return Dali::InputMethodContext::KeyboardType::SOFTWARE_KEYBOARD;
980 std::string InputMethodContextEcoreWl::GetInputPanelLocale()
982 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::GetInputPanelLocale\n" );
984 std::string locale = "";
989 ecore_imf_context_input_panel_language_locale_get( mIMFContext, &value );
993 std::string valueCopy( value );
996 // The locale string retrieved must be freed with free().
1003 void InputMethodContextEcoreWl::SetContentMIMETypes( const std::string& mimeTypes )
1005 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::SetContentMIMETypes\n" );
1009 ecore_imf_context_mime_type_accept_set( mIMFContext, mimeTypes.c_str() );
1013 bool InputMethodContextEcoreWl::FilterEventKey( const Dali::KeyEvent& keyEvent )
1015 bool eventHandled( false );
1017 // If a device key then skip ecore_imf_context_filter_event.
1018 if ( ! KeyLookup::IsDeviceButton( keyEvent.keyPressedName.c_str() ))
1020 //check whether it's key down or key up event
1021 if ( keyEvent.state == KeyEvent::Down )
1023 eventHandled = ProcessEventKeyDown( keyEvent );
1025 else if ( keyEvent.state == KeyEvent::Up )
1027 eventHandled = ProcessEventKeyUp( keyEvent );
1031 return eventHandled;
1034 void InputMethodContextEcoreWl::AllowTextPrediction( bool prediction )
1036 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::AllowTextPrediction\n" );
1040 ecore_imf_context_prediction_allow_set( mIMFContext, prediction );
1044 bool InputMethodContextEcoreWl::IsTextPredictionAllowed() const
1046 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::IsTextPredictionAllowed\n" );
1047 bool prediction = false;
1050 prediction = ecore_imf_context_prediction_allow_get( mIMFContext );
1055 void InputMethodContextEcoreWl::SetInputPanelLanguage( Dali::InputMethodContext::InputPanelLanguage language )
1057 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::SetInputPanelLanguage\n" );
1062 case Dali::InputMethodContext::InputPanelLanguage::AUTOMATIC:
1064 ecore_imf_context_input_panel_language_set( mIMFContext, ECORE_IMF_INPUT_PANEL_LANG_AUTOMATIC );
1067 case Dali::InputMethodContext::InputPanelLanguage::ALPHABET:
1069 ecore_imf_context_input_panel_language_set( mIMFContext, ECORE_IMF_INPUT_PANEL_LANG_ALPHABET );
1076 Dali::InputMethodContext::InputPanelLanguage InputMethodContextEcoreWl::GetInputPanelLanguage() const
1078 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::GetInputPanelLanguage\n" );
1082 value = ecore_imf_context_input_panel_language_get( mIMFContext );
1086 case ECORE_IMF_INPUT_PANEL_LANG_AUTOMATIC:
1088 return Dali::InputMethodContext::InputPanelLanguage::AUTOMATIC;
1091 case ECORE_IMF_INPUT_PANEL_LANG_ALPHABET:
1093 return Dali::InputMethodContext::InputPanelLanguage::ALPHABET;
1098 return Dali::InputMethodContext::InputPanelLanguage::AUTOMATIC;
1101 void InputMethodContextEcoreWl::SetInputPanelPosition( unsigned int x, unsigned int y )
1103 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::SetInputPanelPosition\n" );
1107 ecore_imf_context_input_panel_position_set( mIMFContext, x, y );
1111 Dali::InputMethodContext::PreeditStyle InputMethodContextEcoreWl::GetPreeditStyle() const
1113 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::GetPreeditStyle\n" );
1114 return mPreeditType;
1117 bool InputMethodContextEcoreWl::ProcessEventKeyDown( const KeyEvent& keyEvent )
1119 bool eventHandled( false );
1122 Integration::KeyEvent integKeyEvent( keyEvent );
1123 std::string key = integKeyEvent.logicalKey;
1125 std::string compose = keyEvent.GetCompose();
1126 std::string deviceName = keyEvent.GetDeviceName();
1128 // We're consuming key down event so we have to pass to InputMethodContext so that it can parse it as well.
1129 Ecore_IMF_Event_Key_Down ecoreKeyDownEvent;
1130 ecoreKeyDownEvent.keyname = keyEvent.keyPressedName.c_str();
1131 ecoreKeyDownEvent.key = key.c_str();
1132 ecoreKeyDownEvent.string = keyEvent.keyPressed.c_str();
1133 ecoreKeyDownEvent.compose = compose.c_str();
1134 ecoreKeyDownEvent.timestamp = keyEvent.time;
1135 ecoreKeyDownEvent.modifiers = EcoreInputModifierToEcoreIMFModifier( keyEvent.keyModifier );
1136 ecoreKeyDownEvent.locks = EcoreInputModifierToEcoreIMFLock( keyEvent.keyModifier );
1137 ecoreKeyDownEvent.dev_name = deviceName.c_str();
1138 ecoreKeyDownEvent.dev_class = static_cast<Ecore_IMF_Device_Class> ( keyEvent.GetDeviceClass() );//ECORE_IMF_DEVICE_CLASS_KEYBOARD;
1139 ecoreKeyDownEvent.dev_subclass = static_cast<Ecore_IMF_Device_Subclass> ( keyEvent.GetDeviceSubclass() );//ECORE_IMF_DEVICE_SUBCLASS_NONE;
1140 #if defined(ECORE_VERSION_MAJOR) && (ECORE_VERSION_MAJOR >= 1) && defined(ECORE_VERSION_MINOR) && (ECORE_VERSION_MINOR >= 22)
1141 ecoreKeyDownEvent.keycode = keyEvent.keyCode; // Ecore_IMF_Event structure has added 'keycode' variable since ecore_imf 1.22 version.
1142 #endif // Since ecore_imf 1.22 version
1144 // 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.
1145 if ((keyEvent.GetDeviceName() == "ime") && ((!strncmp(keyEvent.keyPressedName.c_str(), "Left", 4)) ||
1146 (!strncmp(keyEvent.keyPressedName.c_str(), "Right", 5)) ||
1147 (!strncmp(keyEvent.keyPressedName.c_str(), "Up", 2)) ||
1148 (!strncmp(keyEvent.keyPressedName.c_str(), "Down", 4))))
1154 eventHandled = ecore_imf_context_filter_event(mIMFContext,
1155 ECORE_IMF_EVENT_KEY_DOWN,
1156 reinterpret_cast<Ecore_IMF_Event *>( &ecoreKeyDownEvent ) );
1159 // If the event has not been handled by InputMethodContext then check if we should reset our input method context
1162 if (!strcmp(keyEvent.keyPressedName.c_str(), "Escape") ||
1163 !strcmp(keyEvent.keyPressedName.c_str(), "Return") ||
1164 !strcmp(keyEvent.keyPressedName.c_str(), "KP_Enter"))
1166 ecore_imf_context_reset(mIMFContext);
1170 return eventHandled;
1173 bool InputMethodContextEcoreWl::ProcessEventKeyUp( const KeyEvent& keyEvent )
1175 bool eventHandled( false );
1178 Integration::KeyEvent integKeyEvent( keyEvent );
1179 std::string key = integKeyEvent.logicalKey;
1181 std::string compose = keyEvent.GetCompose();
1182 std::string deviceName = keyEvent.GetDeviceName();
1184 // We're consuming key up event so we have to pass to InputMethodContext so that it can parse it as well.
1185 Ecore_IMF_Event_Key_Up ecoreKeyUpEvent;
1186 ecoreKeyUpEvent.keyname = keyEvent.keyPressedName.c_str();
1187 ecoreKeyUpEvent.key = key.c_str();
1188 ecoreKeyUpEvent.string = keyEvent.keyPressed.c_str();
1189 ecoreKeyUpEvent.compose = compose.c_str();
1190 ecoreKeyUpEvent.timestamp = keyEvent.time;
1191 ecoreKeyUpEvent.modifiers = EcoreInputModifierToEcoreIMFModifier( keyEvent.keyModifier );
1192 ecoreKeyUpEvent.locks = EcoreInputModifierToEcoreIMFLock( keyEvent.keyModifier );
1193 ecoreKeyUpEvent.dev_name = deviceName.c_str();
1194 ecoreKeyUpEvent.dev_class = static_cast<Ecore_IMF_Device_Class> ( keyEvent.GetDeviceClass() );//ECORE_IMF_DEVICE_CLASS_KEYBOARD;
1195 ecoreKeyUpEvent.dev_subclass = static_cast<Ecore_IMF_Device_Subclass> ( keyEvent.GetDeviceSubclass() );//ECORE_IMF_DEVICE_SUBCLASS_NONE;
1196 #if defined(ECORE_VERSION_MAJOR) && (ECORE_VERSION_MAJOR >= 1) && defined(ECORE_VERSION_MINOR) && (ECORE_VERSION_MINOR >= 22)
1197 ecoreKeyUpEvent.keycode = keyEvent.keyCode; // Ecore_IMF_Event structure has added 'keycode' variable since ecore_imf 1.22 version.
1198 #endif // Since ecore_imf 1.22 version
1200 eventHandled = ecore_imf_context_filter_event(mIMFContext,
1201 ECORE_IMF_EVENT_KEY_UP,
1202 reinterpret_cast<Ecore_IMF_Event *>( &ecoreKeyUpEvent ) );
1204 return eventHandled;
1207 Ecore_IMF_Keyboard_Modifiers InputMethodContextEcoreWl::EcoreInputModifierToEcoreIMFModifier( unsigned int ecoreModifier )
1209 unsigned int modifier( ECORE_IMF_KEYBOARD_MODIFIER_NONE ); // If no other matches returns NONE.
1211 if ( ecoreModifier & ECORE_EVENT_MODIFIER_SHIFT ) // enums from ecore_input/Ecore_Input.h
1213 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_SHIFT; // enums from ecore_imf/ecore_imf.h
1216 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALT )
1218 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALT;
1221 if ( ecoreModifier & ECORE_EVENT_MODIFIER_CTRL )
1223 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_CTRL;
1226 if ( ecoreModifier & ECORE_EVENT_MODIFIER_WIN )
1228 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_WIN;
1231 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALTGR )
1233 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALTGR;
1236 return static_cast<Ecore_IMF_Keyboard_Modifiers>( modifier );
1239 Ecore_IMF_Keyboard_Locks InputMethodContextEcoreWl::EcoreInputModifierToEcoreIMFLock( unsigned int modifier )
1241 unsigned int lock( ECORE_IMF_KEYBOARD_LOCK_NONE ); // If no other matches, returns NONE.
1243 if( modifier & ECORE_EVENT_LOCK_NUM )
1245 lock |= ECORE_IMF_KEYBOARD_LOCK_NUM; // Num lock is active.
1248 if( modifier & ECORE_EVENT_LOCK_CAPS )
1250 lock |= ECORE_IMF_KEYBOARD_LOCK_CAPS; // Caps lock is active.
1253 if( modifier & ECORE_EVENT_LOCK_SCROLL )
1255 lock |= ECORE_IMF_KEYBOARD_LOCK_SCROLL; // Scroll lock is active.
1258 return static_cast<Ecore_IMF_Keyboard_Locks>( lock );
1261 void InputMethodContextEcoreWl::OnStaged( Dali::Actor actor )
1263 int windowId = GetWindowIdFromActor( actor );
1265 if( mWindowId != windowId )
1267 mWindowId = windowId;