Skip to content

Commit

Permalink
Fix input panel bugs (#351)
Browse files Browse the repository at this point in the history
* Resolve #346.
* Corrects deleting character in text composition.
* Now, filter makes the key focus move work properly,
  so no longer need to ignore specific key event handling.

Signed-off-by: Boram Bae <[email protected]>
  • Loading branch information
bbrto21 authored Sep 19, 2022
1 parent 6c8e921 commit f662810
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 47 deletions.
63 changes: 18 additions & 45 deletions shell/platform/tizen/tizen_input_method_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,32 @@ Ecore_IMF_Keyboard_Locks EcoreInputModifiersToEcoreImfLocks(
}

template <typename T>
T EcoreEventKeyToEcoreImfEvent(Ecore_Event_Key* event, const char* dev_name) {
T EcoreEventKeyToEcoreImfEvent(Ecore_Event_Key* event) {
T imf_event;

imf_event.keyname = event->keyname;
imf_event.key = event->key;
imf_event.string = event->string;
imf_event.compose = event->compose;
imf_event.timestamp = event->timestamp;
imf_event.keycode = event->keycode;

imf_event.modifiers =
EcoreInputModifiersToEcoreImfModifiers(event->modifiers);
imf_event.locks = EcoreInputModifiersToEcoreImfLocks(event->modifiers);
imf_event.dev_name = dev_name;
imf_event.keycode = event->keycode;

if (event->dev) {
const char* device_name = ecore_device_name_get(event->dev);
imf_event.dev_name = device_name ? device_name : "";
imf_event.dev_class =
static_cast<Ecore_IMF_Device_Class>(ecore_device_class_get(event->dev));
imf_event.dev_subclass = static_cast<Ecore_IMF_Device_Subclass>(
ecore_device_subclass_get(event->dev));
} else {
imf_event.dev_name = "";
imf_event.dev_class = ECORE_IMF_DEVICE_CLASS_NONE;
imf_event.dev_subclass = ECORE_IMF_DEVICE_SUBCLASS_NONE;
}

return imf_event;
}
Expand Down Expand Up @@ -144,30 +157,15 @@ bool TizenInputMethodContext::HandleEcoreEventKey(Ecore_Event_Key* event,
bool is_down) {
FT_ASSERT(imf_context_);
FT_ASSERT(event);
#ifdef WEARABLE_PROFILE
// Hardware keyboard is not supported on watch devices.
const char* device_name = "ime";
bool is_ime = true;
#else
const char* device_name = ecore_device_name_get(event->dev);
bool is_ime = device_name ? strcmp(device_name, "ime") == 0 : true;
#endif

if (ShouldIgnoreKey(event->key, is_ime)) {
return false;
}

if (is_down) {
Ecore_IMF_Event_Key_Down imf_event =
EcoreEventKeyToEcoreImfEvent<Ecore_IMF_Event_Key_Down>(event,
device_name);
EcoreEventKeyToEcoreImfEvent<Ecore_IMF_Event_Key_Down>(event);
return ecore_imf_context_filter_event(
imf_context_, ECORE_IMF_EVENT_KEY_DOWN,
reinterpret_cast<Ecore_IMF_Event*>(&imf_event));
} else {
Ecore_IMF_Event_Key_Up imf_event =
EcoreEventKeyToEcoreImfEvent<Ecore_IMF_Event_Key_Up>(event,
device_name);
EcoreEventKeyToEcoreImfEvent<Ecore_IMF_Event_Key_Up>(event);
return ecore_imf_context_filter_event(
imf_context_, ECORE_IMF_EVENT_KEY_UP,
reinterpret_cast<Ecore_IMF_Event*>(&imf_event));
Expand All @@ -176,10 +174,6 @@ bool TizenInputMethodContext::HandleEcoreEventKey(Ecore_Event_Key* event,

bool TizenInputMethodContext::HandleEvasEventKeyDown(
Evas_Event_Key_Down* event) {
if (ShouldIgnoreKey(event->key, true)) {
return false;
}

Ecore_IMF_Event_Key_Down imf_event;
ecore_imf_evas_event_key_down_wrap(event, &imf_event);

Expand All @@ -189,10 +183,6 @@ bool TizenInputMethodContext::HandleEvasEventKeyDown(
}

bool TizenInputMethodContext::HandleEvasEventKeyUp(Evas_Event_Key_Up* event) {
if (ShouldIgnoreKey(event->key, true)) {
return false;
}

Ecore_IMF_Event_Key_Up imf_event;
ecore_imf_evas_event_key_up_wrap(event, &imf_event);

Expand Down Expand Up @@ -363,21 +353,4 @@ void TizenInputMethodContext::SetInputPanelOptions() {
imf_context_, ECORE_IMF_INPUT_PANEL_LANG_AUTOMATIC);
}

bool TizenInputMethodContext::ShouldIgnoreKey(std::string key, bool is_ime) {
// The below keys should be handled by the flutter framework.
if (is_ime && (key == "Left" || key == "Right" || key == "Up" ||
key == "Down" || key == "End" || key == "Home" ||
key == "BackSpace" || key == "Delete")) {
return true;
}
#ifdef TV_PROFILE
// The Select key should be handled in the TextInputChannel.
if (is_ime && key == "Select") {
return true;
}
#endif

return false;
}

} // namespace flutter
2 changes: 0 additions & 2 deletions shell/platform/tizen/tizen_input_method_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ class TizenInputMethodContext {
void SetContextOptions();
void SetInputPanelOptions();

bool ShouldIgnoreKey(std::string key, bool is_ime);

Ecore_IMF_Context* imf_context_ = nullptr;
OnCommit on_commit_;
OnPreeditChanged on_preedit_changed_;
Expand Down

0 comments on commit f662810

Please sign in to comment.