Skip to content

Commit e629333

Browse files
authored
Update TextInputChannel to supprot platform view (#52)
* Current the text input channel handles user input for only existing flutter components. Therefore, we added the logic so that the platform view can also handle the composition events happened by user input.
1 parent 113f51b commit e629333

File tree

6 files changed

+102
-20
lines changed

6 files changed

+102
-20
lines changed

shell/platform/tizen/channels/platform_view_channel.cc

+17
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,23 @@ void PlatformViewChannel::SendKeyEvent(Ecore_Event_Key* key, bool is_down) {
108108
}
109109
}
110110

111+
void PlatformViewChannel::DispatchCompositionUpdateEvent(
112+
const std::string& key) {
113+
auto instances = ViewInstances();
114+
auto it = instances.find(CurrentFocusedViewId());
115+
if (it != instances.end()) {
116+
it->second->DispatchCompositionUpdateEvent(key.c_str(), key.size());
117+
}
118+
}
119+
120+
void PlatformViewChannel::DispatchCompositionEndEvent(const std::string& key) {
121+
auto instances = ViewInstances();
122+
auto it = instances.find(CurrentFocusedViewId());
123+
if (it != instances.end()) {
124+
it->second->DispatchCompositionEndEvent(key.c_str(), key.size());
125+
}
126+
}
127+
111128
int PlatformViewChannel::CurrentFocusedViewId() {
112129
for (auto it = view_instances_.begin(); it != view_instances_.end(); it++) {
113130
if (it->second->IsFocused()) {

shell/platform/tizen/channels/platform_view_channel.h

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ class PlatformViewChannel {
3030
void SendKeyEvent(Ecore_Event_Key* key, bool is_down);
3131
int CurrentFocusedViewId();
3232

33+
void DispatchCompositionUpdateEvent(const std::string& key);
34+
void DispatchCompositionEndEvent(const std::string& key);
35+
3336
private:
3437
TizenEmbedderEngine* engine_;
3538
std::unique_ptr<flutter::MethodChannel<flutter::EncodableValue>> channel_;

shell/platform/tizen/channels/text_input_channel.cc

+76-17
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,37 @@ static bool IsASCIIPrintableKey(char c) {
5959
void 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

6675
void 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

277296
void 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

574633
void TextInputChannel::ShowSoftwareKeyboard() {
575634
FT_LOGD("Show input panel");

shell/platform/tizen/channels/text_input_channel.h

+4
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,13 @@ class TextInputChannel {
2929
void OnKeyDown(Ecore_Event_Key* key);
3030
void OnCommit(std::string str);
3131
void OnPreedit(std::string str, int cursor_pos);
32+
void OnPreeditForPlatformView(std::string str, int cursor_pos);
33+
3234
void ShowSoftwareKeyboard();
3335
void HideSoftwareKeyboard();
3436
bool IsSoftwareKeyboardShowing() { return is_software_keyboard_showing_; }
37+
void SetSoftwareKeyboardShowing() { is_software_keyboard_showing_ = true; }
38+
3539
void SetEditStatus(EditStatus edit_status);
3640
SoftwareKeyboardGeometry GetCurrentKeyboardGeometry() {
3741
return current_keyboard_geometry_;

shell/platform/tizen/key_event_handler.cc

-3
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ Eina_Bool KeyEventHandler::OnKey(void *data, int type, void *event) {
4646
if (engine->key_event_channel) {
4747
engine->key_event_channel->SendKeyEvent(key, is_down);
4848
}
49-
if (engine->platform_view_channel) {
50-
engine->platform_view_channel->SendKeyEvent(key, is_down);
51-
}
5249
}
5350
return ECORE_CALLBACK_PASS_ON;
5451
}

shell/platform/tizen/public/flutter_platform_view.h

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class PlatformView {
3838
// Key input event
3939
virtual void DispatchKeyDownEvent(Ecore_Event_Key* key) = 0;
4040
virtual void DispatchKeyUpEvent(Ecore_Event_Key* key) = 0;
41+
virtual void DispatchCompositionUpdateEvent(const char* str, int size) = 0;
42+
virtual void DispatchCompositionEndEvent(const char* str, int size) = 0;
4143

4244
virtual void SetSoftwareKeyboardContext(Ecore_IMF_Context* context) = 0;
4345

0 commit comments

Comments
 (0)