@@ -59,19 +59,37 @@ static bool IsASCIIPrintableKey(char c) {
5959void TextInputChannel::CommitCallback (void * data, Ecore_IMF_Context* ctx,
6060 void * event_info) {
6161 TextInputChannel* self = (TextInputChannel*)data;
62+ if (!self) {
63+ return ;
64+ }
6265 char * str = (char *)event_info;
66+ if (self->engine_ && self->engine_ ->platform_view_channel &&
67+ self->engine_ ->platform_view_channel ->CurrentFocusedViewId () > -1 ) {
68+ self->engine_ ->platform_view_channel ->DispatchCompositionEndEvent (str);
69+ return ;
70+ }
71+
6372 self->OnCommit (str);
6473}
6574
6675void TextInputChannel::PreeditCallback (void * data, Ecore_IMF_Context* ctx,
6776 void * event_info) {
6877 TextInputChannel* self = (TextInputChannel*)data;
69- char * preedit_string = nullptr ;
78+ if (!self) {
79+ return ;
80+ }
81+
82+ char * str = nullptr ;
7083 int cursor_pos;
71- ecore_imf_context_preedit_string_get (ctx, &preedit_string, &cursor_pos);
72- if (preedit_string) {
73- self->OnPreedit (preedit_string, cursor_pos);
74- free (preedit_string);
84+ ecore_imf_context_preedit_string_get (ctx, &str, &cursor_pos);
85+ if (str) {
86+ if (self->engine_ && self->engine_ ->platform_view_channel &&
87+ self->engine_ ->platform_view_channel ->CurrentFocusedViewId () > -1 ) {
88+ self->OnPreeditForPlatformView (str, cursor_pos);
89+ } else {
90+ self->OnPreedit (str, cursor_pos);
91+ }
92+ free (str);
7593 }
7694}
7795
@@ -99,6 +117,7 @@ void TextInputChannel::InputPanelStateChangedCallback(
99117 TextInputChannel* self = (TextInputChannel*)data;
100118 switch (value) {
101119 case ECORE_IMF_INPUT_PANEL_STATE_SHOW:
120+ self->SetSoftwareKeyboardShowing ();
102121 break ;
103122 case ECORE_IMF_INPUT_PANEL_STATE_HIDE:
104123 self->HideSoftwareKeyboard (); // FIXME: Fallback for HW back-key
@@ -275,7 +294,7 @@ TextInputChannel::~TextInputChannel() {
275294}
276295
277296void TextInputChannel::OnKeyDown (Ecore_Event_Key* key) {
278- if (active_model_ && !FilterEvent (key) && !have_preedit_) {
297+ if (!FilterEvent (key) && !have_preedit_) {
279298 NonIMFFallback (key);
280299 }
281300}
@@ -431,6 +450,8 @@ bool TextInputChannel::FilterEvent(Ecore_Event_Key* keyDownEvent) {
431450 if (isIME) {
432451 if (!strcmp (keyDownEvent->key , " Left" ) ||
433452 !strcmp (keyDownEvent->key , " Right" ) ||
453+ !strcmp (keyDownEvent->key , " Up" ) ||
454+ !strcmp (keyDownEvent->key , " Down" ) ||
434455 !strcmp (keyDownEvent->key , " End" ) ||
435456 !strcmp (keyDownEvent->key , " Home" ) ||
436457 !strcmp (keyDownEvent->key , " BackSpace" ) ||
@@ -481,35 +502,49 @@ void TextInputChannel::NonIMFFallback(Ecore_Event_Key* keyDownEvent) {
481502 }
482503
483504 bool select = !strcmp (keyDownEvent->key , " Select" );
505+ bool is_filtered = true ;
484506 if (!strcmp (keyDownEvent->key , " Left" )) {
485- if (active_model_->MoveCursorBack ()) {
507+ if (active_model_ && active_model_ ->MoveCursorBack ()) {
486508 SendStateUpdate (*active_model_);
487509 }
488510 } else if (!strcmp (keyDownEvent->key , " Right" )) {
489- if (active_model_->MoveCursorForward ()) {
511+ if (active_model_ && active_model_ ->MoveCursorForward ()) {
490512 SendStateUpdate (*active_model_);
491513 }
492514 } else if (!strcmp (keyDownEvent->key , " End" )) {
493- active_model_->MoveCursorToEnd ();
494- SendStateUpdate (*active_model_);
515+ if (active_model_) {
516+ active_model_->MoveCursorToEnd ();
517+ SendStateUpdate (*active_model_);
518+ }
495519 } else if (!strcmp (keyDownEvent->key , " Home" )) {
496- active_model_->MoveCursorToBeginning ();
497- SendStateUpdate (*active_model_);
520+ if (active_model_) {
521+ active_model_->MoveCursorToBeginning ();
522+ SendStateUpdate (*active_model_);
523+ }
498524 } else if (!strcmp (keyDownEvent->key , " BackSpace" )) {
499- if (active_model_->Backspace ()) {
525+ if (active_model_ && active_model_ ->Backspace ()) {
500526 SendStateUpdate (*active_model_);
501527 }
502528 } else if (!strcmp (keyDownEvent->key , " Delete" )) {
503- if (active_model_->Delete ()) {
529+ if (active_model_ && active_model_ ->Delete ()) {
504530 SendStateUpdate (*active_model_);
505531 }
506532 } else if (!strcmp (keyDownEvent->key , " Return" ) ||
507533 (select && !in_select_mode_)) {
508- EnterPressed (active_model_.get (), select);
534+ if (active_model_) {
535+ EnterPressed (active_model_.get (), select);
536+ }
509537 } else if (keyDownEvent->string && strlen (keyDownEvent->string ) == 1 &&
510538 IsASCIIPrintableKey (keyDownEvent->string [0 ])) {
511- active_model_->AddCodePoint (keyDownEvent->string [0 ]);
512- SendStateUpdate (*active_model_);
539+ if (active_model_) {
540+ active_model_->AddCodePoint (keyDownEvent->string [0 ]);
541+ SendStateUpdate (*active_model_);
542+ }
543+ } else {
544+ is_filtered = false ;
545+ }
546+ if (!active_model_ && is_filtered) {
547+ engine_->platform_view_channel ->SendKeyEvent (keyDownEvent, true );
513548 }
514549 SetEditStatus (EditStatus::kNone );
515550}
@@ -570,6 +605,30 @@ void TextInputChannel::OnPreedit(std::string str, int cursor_pos) {
570605 preedit_end_pos_);
571606 }
572607}
608+ void TextInputChannel::OnPreeditForPlatformView (std::string str,
609+ int cursor_pos) {
610+ FT_LOGD (" OnPreeditForPlatformView str[%s], cursor_pos[%d]" , str.data (),
611+ cursor_pos);
612+
613+ SetEditStatus (EditStatus::kPreeditStart );
614+ if (str.compare (" " ) == 0 ) {
615+ SetEditStatus (EditStatus::kPreeditEnd );
616+ }
617+
618+ if (edit_status_ == EditStatus::kPreeditStart ||
619+ (edit_status_ == EditStatus::kPreeditEnd &&
620+ // For tv, fix me
621+ last_handled_ecore_event_keyname_.compare (" Return" ) != 0 )) {
622+ FT_LOGD (" last_handled_ecore_event_keyname_[%s]" ,
623+ last_handled_ecore_event_keyname_.data ());
624+ last_handled_ecore_event_keyname_ = " " ;
625+ }
626+
627+ have_preedit_ = false ;
628+ if (edit_status_ == EditStatus::kPreeditStart ) {
629+ engine_->platform_view_channel ->DispatchCompositionUpdateEvent (str);
630+ }
631+ }
573632
574633void TextInputChannel::ShowSoftwareKeyboard () {
575634 FT_LOGD (" Show input panel" );
0 commit comments