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/integration-api/adaptor.h>
38 #include <dali/integration-api/scene-holder.h>
39 #include <dali/internal/system/common/locale-utils.h>
40 #include <dali/internal/system/common/singleton-service-impl.h>
41 #include <dali/public-api/adaptor-framework/input-method.h>
42 #include <dali/internal/input/common/key-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 mWindowId( GetWindowIdFromActor( actor ) )
331 actor.OnStageSignal().Connect( this, &InputMethodContextEcoreWl::OnStaged );
334 InputMethodContextEcoreWl::~InputMethodContextEcoreWl()
337 ecore_imf_shutdown();
340 void InputMethodContextEcoreWl::Initialize()
346 void InputMethodContextEcoreWl::CreateContext()
348 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContext::CreateContext\n" );
350 if( mWindowId == kUninitializedWindowId )
355 const char *contextId = ecore_imf_context_default_id_get();
358 mIMFContext = ecore_imf_context_add( contextId );
362 ecore_imf_context_client_window_set( mIMFContext, reinterpret_cast< void* >( mWindowId ) );
366 DALI_LOG_WARNING( "InputMethodContext Unable to get IMFContext\n" );
371 DALI_LOG_WARNING( "InputMethodContext Unable to get IMFContext\n" );
375 void InputMethodContextEcoreWl::DeleteContext()
377 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::DeleteContext\n" );
381 ecore_imf_context_del( mIMFContext );
386 // Callbacks for predicitive text support.
387 void InputMethodContextEcoreWl::ConnectCallbacks()
391 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::ConnectCallbacks\n" );
393 ecore_imf_context_event_callback_add( mIMFContext, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, PreEdit, this );
394 ecore_imf_context_event_callback_add( mIMFContext, ECORE_IMF_CALLBACK_COMMIT, Commit, this );
395 ecore_imf_context_event_callback_add( mIMFContext, ECORE_IMF_CALLBACK_DELETE_SURROUNDING, ImfDeleteSurrounding, this );
396 ecore_imf_context_event_callback_add( mIMFContext, ECORE_IMF_CALLBACK_PRIVATE_COMMAND_SEND, PrivateCommand, this );
397 ecore_imf_context_event_callback_add( mIMFContext, ECORE_IMF_CALLBACK_COMMIT_CONTENT, CommitContent, this );
399 ecore_imf_context_input_panel_event_callback_add( mIMFContext, ECORE_IMF_INPUT_PANEL_STATE_EVENT, InputPanelStateChangeCallback, this );
400 ecore_imf_context_input_panel_event_callback_add( mIMFContext, ECORE_IMF_INPUT_PANEL_LANGUAGE_EVENT, InputPanelLanguageChangeCallback, this );
401 ecore_imf_context_input_panel_event_callback_add( mIMFContext, ECORE_IMF_INPUT_PANEL_GEOMETRY_EVENT, InputPanelGeometryChangedCallback, this );
402 ecore_imf_context_input_panel_event_callback_add( mIMFContext, ECORE_IMF_INPUT_PANEL_KEYBOARD_MODE_EVENT, InputPanelKeyboardTypeChangedCallback, this );
404 ecore_imf_context_retrieve_surrounding_callback_set( mIMFContext, ImfRetrieveSurrounding, this);
408 void InputMethodContextEcoreWl::DisconnectCallbacks()
412 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::DisconnectCallbacks\n" );
414 ecore_imf_context_event_callback_del( mIMFContext, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, PreEdit );
415 ecore_imf_context_event_callback_del( mIMFContext, ECORE_IMF_CALLBACK_COMMIT, Commit );
416 ecore_imf_context_event_callback_del( mIMFContext, ECORE_IMF_CALLBACK_DELETE_SURROUNDING, ImfDeleteSurrounding );
417 ecore_imf_context_event_callback_del( mIMFContext, ECORE_IMF_CALLBACK_PRIVATE_COMMAND_SEND, PrivateCommand );
418 ecore_imf_context_event_callback_del( mIMFContext, ECORE_IMF_CALLBACK_COMMIT_CONTENT, CommitContent );
420 ecore_imf_context_input_panel_event_callback_del( mIMFContext, ECORE_IMF_INPUT_PANEL_STATE_EVENT, InputPanelStateChangeCallback );
421 ecore_imf_context_input_panel_event_callback_del( mIMFContext, ECORE_IMF_INPUT_PANEL_LANGUAGE_EVENT, InputPanelLanguageChangeCallback );
422 ecore_imf_context_input_panel_event_callback_del( mIMFContext, ECORE_IMF_INPUT_PANEL_GEOMETRY_EVENT, InputPanelGeometryChangedCallback );
423 ecore_imf_context_input_panel_event_callback_del( mIMFContext, ECORE_IMF_INPUT_PANEL_KEYBOARD_MODE_EVENT, InputPanelKeyboardTypeChangedCallback );
425 // We do not need to unset the retrieve surrounding callback.
429 void InputMethodContextEcoreWl::Activate()
431 // Reset mIdleCallbackConnected
432 mIdleCallbackConnected = false;
436 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::Activate\n" );
438 ecore_imf_context_focus_in( mIMFContext );
440 // emit keyboard activated signal
441 Dali::InputMethodContext handle( this );
442 mActivatedSignal.Emit( handle );
446 void InputMethodContextEcoreWl::Deactivate()
450 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::Deactivate\n" );
453 ecore_imf_context_focus_out( mIMFContext );
456 // Reset mIdleCallbackConnected
457 mIdleCallbackConnected = false;
460 void InputMethodContextEcoreWl::Reset()
462 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::Reset\n" );
466 ecore_imf_context_reset( mIMFContext );
470 ImfContext* InputMethodContextEcoreWl::GetContext()
472 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::GetContext\n" );
477 bool InputMethodContextEcoreWl::RestoreAfterFocusLost() const
479 return mRestoreAfterFocusLost;
482 void InputMethodContextEcoreWl::SetRestoreAfterFocusLost( bool toggle )
484 mRestoreAfterFocusLost = toggle;
488 * Called when an InputMethodContext Pre-Edit changed event is received.
489 * We are still predicting what the user is typing. The latest string is what the InputMethodContext module thinks
490 * the user wants to type.
492 void InputMethodContextEcoreWl::PreEditChanged( void*, ImfContext* imfContext, void* eventInfo )
494 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::PreEditChanged\n" );
495 auto context = static_cast<Ecore_IMF_Context*>( imfContext );
497 char* preEditString( NULL );
498 int cursorPosition( 0 );
499 Eina_List* attrs = NULL;
502 Ecore_IMF_Preedit_Attr* attr;
504 // Retrieves attributes as well as the string the cursor position offset from start of pre-edit string.
505 // the attributes (attrs) is used in languages that use the soft arrows keys to insert characters into a current pre-edit string.
506 ecore_imf_context_preedit_string_with_attributes_get( context, &preEditString, &attrs, &cursorPosition );
510 // iterate through the list of attributes getting the type, start and end position.
511 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) ) ))
513 #ifdef DALI_PROFILE_UBUNTU
514 if ( attr->preedit_type == ECORE_IMF_PREEDIT_TYPE_SUB3 ) // (Ecore_IMF)
515 #else // DALI_PROFILE_UBUNTU
516 if ( attr->preedit_type == ECORE_IMF_PREEDIT_TYPE_SUB4 ) // (Ecore_IMF)
517 #endif // DALI_PROFILE_UBUNTU
519 // 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.
521 size_t visualCharacterIndex = 0;
522 size_t byteIndex = 0;
524 // iterate through null terminated string checking each character's position against the given byte position ( attr->end_index ).
525 const char leadByte = preEditString[byteIndex];
526 while( leadByte != '\0' )
528 // attr->end_index is provided as a byte position not character and we need to know the character position.
529 const size_t currentSequenceLength = Utf8SequenceLength( leadByte ); // returns number of bytes used to represent character.
530 if ( byteIndex == attr->end_index )
532 cursorPosition = visualCharacterIndex;
534 // end loop as found cursor position that matches byte position
538 byteIndex += currentSequenceLength; // jump to next character
539 visualCharacterIndex++; // increment character count so we know our position for when we get a match
542 DALI_ASSERT_DEBUG( visualCharacterIndex < strlen( preEditString ));
548 if ( Dali::Adaptor::IsAvailable() )
550 Dali::InputMethodContext handle( this );
551 Dali::InputMethodContext::EventData eventData( Dali::InputMethodContext::PRE_EDIT, preEditString, cursorPosition, 0 );
552 Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit( handle, eventData );
554 if ( callbackData.update )
556 SetCursorPosition( callbackData.cursorPosition );
557 SetSurroundingText( callbackData.currentText );
559 NotifyCursorPosition();
562 if ( callbackData.preeditResetRequired )
567 free( preEditString );
570 void InputMethodContextEcoreWl::CommitReceived( void*, ImfContext* imfContext, void* eventInfo )
572 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::CommitReceived\n" );
574 if ( Dali::Adaptor::IsAvailable() )
576 const std::string keyString( static_cast<char*>( eventInfo ) );
578 Dali::InputMethodContext handle( this );
579 Dali::InputMethodContext::EventData eventData( Dali::InputMethodContext::COMMIT, keyString, 0, 0 );
580 Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit( handle, eventData );
582 if( callbackData.update )
584 SetCursorPosition( callbackData.cursorPosition );
585 SetSurroundingText( callbackData.currentText );
587 NotifyCursorPosition();
593 * Called when an InputMethodContext retrieve surround event is received.
594 * Here the InputMethodContext module wishes to know the string we are working with and where within the string the cursor is
595 * We need to signal the application to tell us this information.
597 bool InputMethodContextEcoreWl::RetrieveSurrounding( void* data, ImfContext* imfContext, char** text, int* cursorPosition )
599 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::RetrieveSurrounding\n" );
601 Dali::InputMethodContext::EventData imfData( Dali::InputMethodContext::GET_SURROUNDING, std::string(), 0, 0 );
602 Dali::InputMethodContext handle( this );
603 Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit( handle, imfData );
605 if( callbackData.update )
609 mIMFCursorPosition = static_cast<int>( callbackData.cursorPosition );
610 *cursorPosition = mIMFCursorPosition;
615 const char* plainText = callbackData.currentText.c_str();
619 // The memory allocated by strdup() can be freed by ecore_imf_context_surrounding_get() internally.
620 *text = strdup( plainText );
622 // If the current input panel is password mode, dali should replace the plain text with '*' (Asterisk) character.
623 if( ecore_imf_context_input_hint_get( mIMFContext ) & ECORE_IMF_INPUT_HINT_SENSITIVE_DATA )
625 for( char* iter = *text; *iter; ++iter )
640 * Called when an InputMethodContext delete surrounding event is received.
641 * Here we tell the application that it should delete a certain range.
643 void InputMethodContextEcoreWl::DeleteSurrounding( void* data, ImfContext* imfContext, void* eventInfo )
645 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::DeleteSurrounding\n" );
647 if( Dali::Adaptor::IsAvailable() )
649 Ecore_IMF_Event_Delete_Surrounding* deleteSurroundingEvent = static_cast<Ecore_IMF_Event_Delete_Surrounding*>( eventInfo );
651 Dali::InputMethodContext::EventData imfData( Dali::InputMethodContext::DELETE_SURROUNDING, std::string(), deleteSurroundingEvent->offset, deleteSurroundingEvent->n_chars );
652 Dali::InputMethodContext handle( this );
653 mEventSignal.Emit( handle, imfData );
658 * Called when the input method sends a private command.
660 void InputMethodContextEcoreWl::SendPrivateCommand( void* data, ImfContext* imfContext, void* eventInfo )
662 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::SendPrivateCommand\n" );
664 if( Dali::Adaptor::IsAvailable() )
666 const char* privateCommandSendEvent = static_cast<const char*>( eventInfo );
668 Dali::InputMethodContext::EventData imfData( Dali::InputMethodContext::PRIVATE_COMMAND, privateCommandSendEvent, 0, 0 );
669 Dali::InputMethodContext handle( this );
670 mEventSignal.Emit( handle, imfData );
675 * Called when the input method commits content, such as an image.
677 void InputMethodContextEcoreWl::SendCommitContent( void* data, ImfContext* imfContext, void* eventInfo )
679 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::SendCommitContent\n" );
681 if( Dali::Adaptor::IsAvailable() )
683 Ecore_IMF_Event_Commit_Content* commitContent = static_cast<Ecore_IMF_Event_Commit_Content *>( eventInfo );
686 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::SendCommitContent commit content : %s, description : %s, mime type : %s\n",
687 commitContent->content_uri, commitContent->description, commitContent->mime_types );
688 mContentReceivedSignal.Emit( commitContent->content_uri, commitContent->description, commitContent->mime_types );
693 void InputMethodContextEcoreWl::NotifyCursorPosition()
695 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::NotifyCursorPosition\n" );
699 ecore_imf_context_cursor_position_set( mIMFContext, mIMFCursorPosition );
703 void InputMethodContextEcoreWl::SetCursorPosition( unsigned int cursorPosition )
705 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::SetCursorPosition\n" );
707 mIMFCursorPosition = static_cast<int>( cursorPosition );
710 unsigned int InputMethodContextEcoreWl::GetCursorPosition() const
712 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::GetCursorPosition\n" );
714 return static_cast<unsigned int>( mIMFCursorPosition );
717 void InputMethodContextEcoreWl::SetSurroundingText( const std::string& text )
719 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::SetSurroundingText\n" );
721 mSurroundingText = text;
724 const std::string& InputMethodContextEcoreWl::GetSurroundingText() const
726 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::GetSurroundingText\n" );
728 return mSurroundingText;
731 void InputMethodContextEcoreWl::NotifyTextInputMultiLine( bool multiLine )
735 Ecore_IMF_Input_Hints currentHint = ecore_imf_context_input_hint_get(mIMFContext);
736 ecore_imf_context_input_hint_set( mIMFContext,
737 static_cast< Ecore_IMF_Input_Hints >( multiLine ?
738 (currentHint | ECORE_IMF_INPUT_HINT_MULTILINE) :
739 (currentHint & ~ECORE_IMF_INPUT_HINT_MULTILINE)));
743 Dali::InputMethodContext::TextDirection InputMethodContextEcoreWl::GetTextDirection()
745 Dali::InputMethodContext::TextDirection direction ( Dali::InputMethodContext::LeftToRight );
749 char* locale( NULL );
750 ecore_imf_context_input_panel_language_locale_get( mIMFContext, &locale );
754 direction = static_cast< Dali::InputMethodContext::TextDirection >( Locale::GetDirection( std::string( locale ) ) );
762 Rect<int> InputMethodContextEcoreWl::GetInputMethodArea()
764 int xPos, yPos, width, height;
766 width = height = xPos = yPos = 0;
770 ecore_imf_context_input_panel_geometry_get( mIMFContext, &xPos, &yPos, &width, &height );
774 DALI_LOG_WARNING("VKB Unable to get IMFContext so GetSize unavailable\n");
775 // return 0 as real size unknown.
778 return Rect<int>(xPos,yPos,width,height);
781 void InputMethodContextEcoreWl::ApplyOptions( const InputMethodOptions& options )
783 using namespace Dali::InputMethod::Category;
787 if( mIMFContext == NULL )
789 DALI_LOG_WARNING("VKB Unable to excute ApplyOptions with Null ImfContext\n");
793 if( mOptions.CompareAndSet(PANEL_LAYOUT, options, index) )
795 ecore_imf_context_input_panel_layout_set( mIMFContext, panelLayoutMap[index] );
797 // Sets the input hint which allows input methods to fine-tune their behavior.
798 if( panelLayoutMap[index] == ECORE_IMF_INPUT_PANEL_LAYOUT_PASSWORD )
800 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 ) );
804 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 ) );
807 if( mOptions.CompareAndSet(BUTTON_ACTION, options, index) )
809 ecore_imf_context_input_panel_return_key_type_set( mIMFContext, returnKeyTypeMap[index] );
811 if( mOptions.CompareAndSet(AUTO_CAPITALIZE, options, index) )
813 ecore_imf_context_autocapital_type_set( mIMFContext, autoCapitalMap[index] );
815 if( mOptions.CompareAndSet(VARIATION, options, index) )
817 ecore_imf_context_input_panel_layout_variation_set( mIMFContext, index );
821 void InputMethodContextEcoreWl::SetInputPanelData( const std::string& data )
823 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::SetInputPanelData\n" );
827 int length = data.length();
828 ecore_imf_context_input_panel_imdata_set( mIMFContext, data.c_str(), length );
832 void InputMethodContextEcoreWl::GetInputPanelData( std::string& data )
834 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::GetInputPanelData\n" );
838 int length = 4096; // The max length is 4096 bytes
839 Dali::Vector< char > buffer;
840 buffer.Resize( length );
841 ecore_imf_context_input_panel_imdata_get( mIMFContext, &buffer[0], &length );
842 data = std::string( buffer.Begin(), buffer.End() );
846 Dali::InputMethodContext::State InputMethodContextEcoreWl::GetInputPanelState()
848 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::GetInputPanelState\n" );
853 value = ecore_imf_context_input_panel_state_get( mIMFContext );
857 case ECORE_IMF_INPUT_PANEL_STATE_SHOW:
859 return Dali::InputMethodContext::SHOW;
863 case ECORE_IMF_INPUT_PANEL_STATE_HIDE:
865 return Dali::InputMethodContext::HIDE;
869 case ECORE_IMF_INPUT_PANEL_STATE_WILL_SHOW:
871 return Dali::InputMethodContext::WILL_SHOW;
877 return Dali::InputMethodContext::DEFAULT;
881 return Dali::InputMethodContext::DEFAULT;
884 void InputMethodContextEcoreWl::SetReturnKeyState( bool visible )
886 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::SetReturnKeyState\n" );
890 ecore_imf_context_input_panel_return_key_disabled_set( mIMFContext, !visible );
894 void InputMethodContextEcoreWl::AutoEnableInputPanel( bool enabled )
896 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::AutoEnableInputPanel\n" );
900 ecore_imf_context_input_panel_enabled_set( mIMFContext, enabled );
904 void InputMethodContextEcoreWl::ShowInputPanel()
906 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::ShowInputPanel\n" );
910 ecore_imf_context_input_panel_show( mIMFContext );
914 void InputMethodContextEcoreWl::HideInputPanel()
916 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::HideInputPanel\n" );
920 ecore_imf_context_input_panel_hide( mIMFContext );
924 Dali::InputMethodContext::KeyboardType InputMethodContextEcoreWl::GetKeyboardType()
926 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::GetKeyboardType\n" );
931 value = ecore_imf_context_keyboard_mode_get( mIMFContext );
935 case ECORE_IMF_INPUT_PANEL_SW_KEYBOARD_MODE:
937 return Dali::InputMethodContext::SOFTWARE_KEYBOARD;
940 case ECORE_IMF_INPUT_PANEL_HW_KEYBOARD_MODE:
942 return Dali::InputMethodContext::HARDWARE_KEYBOARD;
948 return Dali::InputMethodContext::KeyboardType::SOFTWARE_KEYBOARD;
951 std::string InputMethodContextEcoreWl::GetInputPanelLocale()
953 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::GetInputPanelLocale\n" );
955 std::string locale = "";
960 ecore_imf_context_input_panel_language_locale_get( mIMFContext, &value );
964 std::string valueCopy( value );
967 // The locale string retrieved must be freed with free().
974 void InputMethodContextEcoreWl::SetContentMIMETypes( const std::string& mimeTypes )
976 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::SetContentMIMETypes\n" );
980 ecore_imf_context_mime_type_accept_set( mIMFContext, mimeTypes.c_str() );
984 bool InputMethodContextEcoreWl::FilterEventKey( const Dali::KeyEvent& keyEvent )
986 bool eventHandled( false );
988 // If a device key then skip ecore_imf_context_filter_event.
989 if ( ! KeyLookup::IsDeviceButton( keyEvent.keyPressedName.c_str() ))
991 //check whether it's key down or key up event
992 if ( keyEvent.state == KeyEvent::Down )
994 eventHandled = ProcessEventKeyDown( keyEvent );
996 else if ( keyEvent.state == KeyEvent::Up )
998 eventHandled = ProcessEventKeyUp( keyEvent );
1002 return eventHandled;
1005 void InputMethodContextEcoreWl::AllowTextPrediction( bool prediction )
1007 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::AllowTextPrediction\n" );
1011 ecore_imf_context_prediction_allow_set( mIMFContext, prediction );
1015 bool InputMethodContextEcoreWl::IsTextPredictionAllowed() const
1017 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::IsTextPredictionAllowed\n" );
1018 bool prediction = false;
1021 prediction = ecore_imf_context_prediction_allow_get( mIMFContext );
1026 void InputMethodContextEcoreWl::SetInputPanelLanguage( Dali::InputMethodContext::InputPanelLanguage language )
1028 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::SetInputPanelLanguage\n" );
1033 case Dali::InputMethodContext::InputPanelLanguage::AUTOMATIC:
1035 ecore_imf_context_input_panel_language_set( mIMFContext, ECORE_IMF_INPUT_PANEL_LANG_AUTOMATIC );
1038 case Dali::InputMethodContext::InputPanelLanguage::ALPHABET:
1040 ecore_imf_context_input_panel_language_set( mIMFContext, ECORE_IMF_INPUT_PANEL_LANG_ALPHABET );
1047 Dali::InputMethodContext::InputPanelLanguage InputMethodContextEcoreWl::GetInputPanelLanguage() const
1049 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::GetInputPanelLanguage\n" );
1053 value = ecore_imf_context_input_panel_language_get( mIMFContext );
1057 case ECORE_IMF_INPUT_PANEL_LANG_AUTOMATIC:
1059 return Dali::InputMethodContext::InputPanelLanguage::AUTOMATIC;
1062 case ECORE_IMF_INPUT_PANEL_LANG_ALPHABET:
1064 return Dali::InputMethodContext::InputPanelLanguage::ALPHABET;
1069 return Dali::InputMethodContext::InputPanelLanguage::AUTOMATIC;
1072 bool InputMethodContextEcoreWl::ProcessEventKeyDown( const KeyEvent& keyEvent )
1074 bool eventHandled( false );
1077 Integration::KeyEvent integKeyEvent( keyEvent );
1078 std::string key = integKeyEvent.logicalKey;
1080 std::string compose = keyEvent.GetCompose();
1081 std::string deviceName = keyEvent.GetDeviceName();
1083 // We're consuming key down event so we have to pass to InputMethodContext so that it can parse it as well.
1084 Ecore_IMF_Event_Key_Down ecoreKeyDownEvent;
1085 ecoreKeyDownEvent.keyname = keyEvent.keyPressedName.c_str();
1086 ecoreKeyDownEvent.key = key.c_str();
1087 ecoreKeyDownEvent.string = keyEvent.keyPressed.c_str();
1088 ecoreKeyDownEvent.compose = compose.c_str();
1089 ecoreKeyDownEvent.timestamp = keyEvent.time;
1090 ecoreKeyDownEvent.modifiers = EcoreInputModifierToEcoreIMFModifier( keyEvent.keyModifier );
1091 ecoreKeyDownEvent.locks = EcoreInputModifierToEcoreIMFLock( keyEvent.keyModifier );
1092 ecoreKeyDownEvent.dev_name = deviceName.c_str();
1093 ecoreKeyDownEvent.dev_class = static_cast<Ecore_IMF_Device_Class> ( keyEvent.GetDeviceClass() );//ECORE_IMF_DEVICE_CLASS_KEYBOARD;
1094 ecoreKeyDownEvent.dev_subclass = static_cast<Ecore_IMF_Device_Subclass> ( keyEvent.GetDeviceSubclass() );//ECORE_IMF_DEVICE_SUBCLASS_NONE;
1096 // 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.
1097 if ((keyEvent.GetDeviceName() == "ime") && ((!strncmp(keyEvent.keyPressedName.c_str(), "Left", 4)) ||
1098 (!strncmp(keyEvent.keyPressedName.c_str(), "Right", 5)) ||
1099 (!strncmp(keyEvent.keyPressedName.c_str(), "Up", 2)) ||
1100 (!strncmp(keyEvent.keyPressedName.c_str(), "Down", 4))))
1106 eventHandled = ecore_imf_context_filter_event(mIMFContext,
1107 ECORE_IMF_EVENT_KEY_DOWN,
1108 reinterpret_cast<Ecore_IMF_Event *>( &ecoreKeyDownEvent ) );
1111 // If the event has not been handled by InputMethodContext then check if we should reset our input method context
1114 if (!strcmp(keyEvent.keyPressedName.c_str(), "Escape") ||
1115 !strcmp(keyEvent.keyPressedName.c_str(), "Return") ||
1116 !strcmp(keyEvent.keyPressedName.c_str(), "KP_Enter"))
1118 ecore_imf_context_reset(mIMFContext);
1122 return eventHandled;
1125 bool InputMethodContextEcoreWl::ProcessEventKeyUp( const KeyEvent& keyEvent )
1127 bool eventHandled( false );
1130 Integration::KeyEvent integKeyEvent( keyEvent );
1131 std::string key = integKeyEvent.logicalKey;
1133 std::string compose = keyEvent.GetCompose();
1134 std::string deviceName = keyEvent.GetDeviceName();
1136 // We're consuming key up event so we have to pass to InputMethodContext so that it can parse it as well.
1137 Ecore_IMF_Event_Key_Up ecoreKeyUpEvent;
1138 ecoreKeyUpEvent.keyname = keyEvent.keyPressedName.c_str();
1139 ecoreKeyUpEvent.key = key.c_str();
1140 ecoreKeyUpEvent.string = keyEvent.keyPressed.c_str();
1141 ecoreKeyUpEvent.compose = compose.c_str();
1142 ecoreKeyUpEvent.timestamp = keyEvent.time;
1143 ecoreKeyUpEvent.modifiers = EcoreInputModifierToEcoreIMFModifier( keyEvent.keyModifier );
1144 ecoreKeyUpEvent.locks = EcoreInputModifierToEcoreIMFLock( keyEvent.keyModifier );
1145 ecoreKeyUpEvent.dev_name = deviceName.c_str();
1146 ecoreKeyUpEvent.dev_class = static_cast<Ecore_IMF_Device_Class> ( keyEvent.GetDeviceClass() );//ECORE_IMF_DEVICE_CLASS_KEYBOARD;
1147 ecoreKeyUpEvent.dev_subclass = static_cast<Ecore_IMF_Device_Subclass> ( keyEvent.GetDeviceSubclass() );//ECORE_IMF_DEVICE_SUBCLASS_NONE;
1149 eventHandled = ecore_imf_context_filter_event(mIMFContext,
1150 ECORE_IMF_EVENT_KEY_UP,
1151 reinterpret_cast<Ecore_IMF_Event *>( &ecoreKeyUpEvent ) );
1153 return eventHandled;
1156 Ecore_IMF_Keyboard_Modifiers InputMethodContextEcoreWl::EcoreInputModifierToEcoreIMFModifier( unsigned int ecoreModifier )
1158 unsigned int modifier( ECORE_IMF_KEYBOARD_MODIFIER_NONE ); // If no other matches returns NONE.
1160 if ( ecoreModifier & ECORE_EVENT_MODIFIER_SHIFT ) // enums from ecore_input/Ecore_Input.h
1162 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_SHIFT; // enums from ecore_imf/ecore_imf.h
1165 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALT )
1167 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALT;
1170 if ( ecoreModifier & ECORE_EVENT_MODIFIER_CTRL )
1172 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_CTRL;
1175 if ( ecoreModifier & ECORE_EVENT_MODIFIER_WIN )
1177 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_WIN;
1180 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALTGR )
1182 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALTGR;
1185 return static_cast<Ecore_IMF_Keyboard_Modifiers>( modifier );
1188 Ecore_IMF_Keyboard_Locks InputMethodContextEcoreWl::EcoreInputModifierToEcoreIMFLock( unsigned int modifier )
1190 unsigned int lock( ECORE_IMF_KEYBOARD_LOCK_NONE ); // If no other matches, returns NONE.
1192 if( modifier & ECORE_EVENT_LOCK_NUM )
1194 lock |= ECORE_IMF_KEYBOARD_LOCK_NUM; // Num lock is active.
1197 if( modifier & ECORE_EVENT_LOCK_CAPS )
1199 lock |= ECORE_IMF_KEYBOARD_LOCK_CAPS; // Caps lock is active.
1202 if( modifier & ECORE_EVENT_LOCK_SCROLL )
1204 lock |= ECORE_IMF_KEYBOARD_LOCK_SCROLL; // Scroll lock is active.
1207 return static_cast<Ecore_IMF_Keyboard_Locks>( lock );
1210 void InputMethodContextEcoreWl::OnStaged( Dali::Actor actor )
1212 int windowId = GetWindowIdFromActor( actor );
1214 if( mWindowId != windowId )
1216 mWindowId = windowId;