Skip to content

Commit

Permalink
Handle the key-up event in text_input_channel (flutter-tizen#238)
Browse files Browse the repository at this point in the history
* Long press event was recently added to the input panel of VD.
  So we have to handle the key-up event appropriately.

Signed-off-by: Boram Bae <boram21.bae@samsung.com>
  • Loading branch information
bbrto21 authored Feb 15, 2022
1 parent cea8daa commit 789ddaf
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 26 deletions.
9 changes: 5 additions & 4 deletions shell/platform/tizen/channels/text_input_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ TextInputChannel::TextInputChannel(
TextInputChannel::~TextInputChannel() {}

bool TextInputChannel::SendKeyEvent(Ecore_Event_Key* key, bool is_down) {
if (!active_model_ || !is_down) {
if (!active_model_) {
return false;
}

if (!FilterEvent(key)) {
if (!FilterEvent(key, is_down) && is_down) {
HandleUnfilteredEvent(key);
}

Expand Down Expand Up @@ -314,7 +314,7 @@ void TextInputChannel::SendStateUpdate(const TextInputModel& model) {
channel_->InvokeMethod(kUpdateEditingStateMethod, std::move(args));
}

bool TextInputChannel::FilterEvent(Ecore_Event_Key* event) {
bool TextInputChannel::FilterEvent(Ecore_Event_Key* event, bool is_down) {
bool handled = false;

#if defined(__X64_SHELL__)
Expand All @@ -339,7 +339,8 @@ bool TextInputChannel::FilterEvent(Ecore_Event_Key* event) {
return false;
}

handled = input_method_context_->FilterEvent(event, is_ime ? "ime" : "");
handled =
input_method_context_->FilterEvent(event, is_ime ? "ime" : "", is_down);

#ifdef WEARABLE_PROFILE
if (!handled && !strcmp(event->key, "Return") &&
Expand Down
2 changes: 1 addition & 1 deletion shell/platform/tizen/channels/text_input_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class TextInputChannel {
const MethodCall<rapidjson::Document>& method_call,
std::unique_ptr<MethodResult<rapidjson::Document>> result);
void SendStateUpdate(const TextInputModel& model);
bool FilterEvent(Ecore_Event_Key* event);
bool FilterEvent(Ecore_Event_Key* event, bool is_down);
void HandleUnfilteredEvent(Ecore_Event_Key* event);
void EnterPressed(TextInputModel* model, bool select);
void ResetTextEditingContext() {
Expand Down
57 changes: 37 additions & 20 deletions shell/platform/tizen/tizen_input_method_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const char* GetEcoreImfContextAvailableId() {
return nullptr;
}

Ecore_IMF_Input_Panel_Layout TextInputTypeToEcoreIMFInputPanelLayout(
Ecore_IMF_Input_Panel_Layout TextInputTypeToEcoreImfInputPanelLayout(
const std::string& text_input_type) {
if (text_input_type == "TextInputType.text" ||
text_input_type == "TextInputType.multiline") {
Expand All @@ -44,7 +44,7 @@ Ecore_IMF_Input_Panel_Layout TextInputTypeToEcoreIMFInputPanelLayout(
}
}

Ecore_IMF_Keyboard_Modifiers EcoreInputModifiersToEcoreIMFModifiers(
Ecore_IMF_Keyboard_Modifiers EcoreInputModifiersToEcoreImfModifiers(
unsigned int ecore_modifiers) {
unsigned int modifiers(ECORE_IMF_KEYBOARD_MODIFIER_NONE);
if (ecore_modifiers & ECORE_EVENT_MODIFIER_SHIFT) {
Expand All @@ -65,7 +65,7 @@ Ecore_IMF_Keyboard_Modifiers EcoreInputModifiersToEcoreIMFModifiers(
return static_cast<Ecore_IMF_Keyboard_Modifiers>(modifiers);
}

Ecore_IMF_Keyboard_Locks EcoreInputModifiersToEcoreIMFLocks(
Ecore_IMF_Keyboard_Locks EcoreInputModifiersToEcoreImfLocks(
unsigned int modifiers) {
// If no other matches, returns NONE.
unsigned int locks(ECORE_IMF_KEYBOARD_LOCK_NONE);
Expand All @@ -81,6 +81,24 @@ Ecore_IMF_Keyboard_Locks EcoreInputModifiersToEcoreIMFLocks(
return static_cast<Ecore_IMF_Keyboard_Locks>(locks);
}

template <typename T>
T EcoreEventKeyToEcoreImfEvent(Ecore_Event_Key* event, const char* dev_name) {
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.modifiers =
EcoreInputModifiersToEcoreImfModifiers(event->modifiers);
imf_event.locks = EcoreInputModifiersToEcoreImfLocks(event->modifiers);
imf_event.dev_name = dev_name;
imf_event.keycode = event->keycode;

return imf_event;
}

} // namespace

namespace flutter {
Expand Down Expand Up @@ -125,26 +143,25 @@ TizenInputMethodContext::~TizenInputMethodContext() {
}

bool TizenInputMethodContext::FilterEvent(Ecore_Event_Key* event,
const char* dev_name) {
const char* dev_name,
bool is_down) {
FT_ASSERT(imf_context_);
FT_ASSERT(event);
FT_ASSERT(dev_name);
Ecore_IMF_Event_Key_Down 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.modifiers =
EcoreInputModifiersToEcoreIMFModifiers(event->modifiers);
imf_event.locks = EcoreInputModifiersToEcoreIMFLocks(event->modifiers);
imf_event.dev_name = dev_name;
imf_event.keycode = event->keycode;

return ecore_imf_context_filter_event(
imf_context_, ECORE_IMF_EVENT_KEY_DOWN,
reinterpret_cast<Ecore_IMF_Event*>(&imf_event));
if (is_down) {
auto imf_event =
EcoreEventKeyToEcoreImfEvent<Ecore_IMF_Event_Key_Down>(event, dev_name);
return ecore_imf_context_filter_event(
imf_context_, ECORE_IMF_EVENT_KEY_DOWN,
reinterpret_cast<Ecore_IMF_Event*>(&imf_event));
} else {
auto imf_event =
EcoreEventKeyToEcoreImfEvent<Ecore_IMF_Event_Key_Up>(event, dev_name);
return ecore_imf_context_filter_event(
imf_context_, ECORE_IMF_EVENT_KEY_UP,
reinterpret_cast<Ecore_IMF_Event*>(&imf_event));
}
}

InputPanelGeometry TizenInputMethodContext::GetInputPanelGeometry() {
Expand Down Expand Up @@ -175,7 +192,7 @@ void TizenInputMethodContext::HideInputPanel() {
void TizenInputMethodContext::SetInputPanelLayout(
const std::string& input_type) {
FT_ASSERT(imf_context_);
auto panel_layout = TextInputTypeToEcoreIMFInputPanelLayout(input_type);
auto panel_layout = TextInputTypeToEcoreImfInputPanelLayout(input_type);
ecore_imf_context_input_panel_layout_set(imf_context_, panel_layout);
}

Expand Down
2 changes: 1 addition & 1 deletion shell/platform/tizen/tizen_input_method_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class TizenInputMethodContext {
TizenInputMethodContext(FlutterTizenEngine* engine);
~TizenInputMethodContext();

bool FilterEvent(Ecore_Event_Key* event, const char* dev_name);
bool FilterEvent(Ecore_Event_Key* event, const char* dev_name, bool is_down);

InputPanelGeometry GetInputPanelGeometry();

Expand Down

0 comments on commit 789ddaf

Please sign in to comment.