Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions shell/platform/tizen/channels/key_event_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ constexpr char kTypeKey[] = "type";
constexpr char kModifiersKey[] = "modifiers";
constexpr char kToolkitKey[] = "toolkit";
constexpr char kUnicodeScalarValuesKey[] = "unicodeScalarValues";
constexpr char kHandledKey[] = "handled";

constexpr char kKeyUp[] = "keyup";
constexpr char kKeyDown[] = "keydown";
Expand Down Expand Up @@ -226,10 +227,9 @@ KeyEventChannel::KeyEventChannel(BinaryMessenger* messenger)

KeyEventChannel::~KeyEventChannel() {}

void KeyEventChannel::SendKeyEvent(Ecore_Event_Key* key, bool is_down) {
FT_LOGI("code: %d, name: %s, mods: %d, type: %s", key->keycode, key->keyname,
key->modifiers, is_down ? kKeyDown : kKeyUp);

void KeyEventChannel::SendKeyEvent(Ecore_Event_Key* key,
bool is_down,
std::function<void(bool)> callback) {
int gtk_keycode = 0;
if (kKeyCodeMap.count(key->keycode) > 0) {
gtk_keycode = kKeyCodeMap.at(key->keycode);
Expand All @@ -254,7 +254,15 @@ void KeyEventChannel::SendKeyEvent(Ecore_Event_Key* key, bool is_down) {
} else {
event.AddMember(kTypeKey, kKeyUp, allocator);
}
channel_->Send(event);
channel_->Send(event, [callback = std::move(callback)](const uint8_t* reply,
size_t reply_size) {
if (reply != nullptr) {
auto decoded = flutter::JsonMessageCodec::GetInstance().DecodeMessage(
reply, reply_size);
bool handled = (*decoded)[kHandledKey].GetBool();
callback(handled);
}
});
}

} // namespace flutter
4 changes: 3 additions & 1 deletion shell/platform/tizen/channels/key_event_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ class KeyEventChannel {
explicit KeyEventChannel(BinaryMessenger* messenger);
virtual ~KeyEventChannel();

void SendKeyEvent(Ecore_Event_Key* key, bool is_down);
void SendKeyEvent(Ecore_Event_Key* key,
bool is_down,
std::function<void(bool)> callback);

private:
std::unique_ptr<BasicMessageChannel<rapidjson::Document>> channel_;
Expand Down
52 changes: 35 additions & 17 deletions shell/platform/tizen/key_event_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@

#include "key_event_handler.h"

#include "flutter/shell/platform/tizen/flutter_tizen_engine.h"
#include <app.h>

static constexpr char kPlatformBackButtonName[] = "XF86Back";
#include "flutter/shell/platform/tizen/flutter_tizen_engine.h"
#include "flutter/shell/platform/tizen/tizen_log.h"

namespace flutter {

namespace {

constexpr char kBackKey[] = "XF86Back";
constexpr char kExitKey[] = "XF86Exit";

} // namespace

KeyEventHandler::KeyEventHandler(FlutterTizenEngine* engine) : engine_(engine) {
key_event_handlers_.push_back(
ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, OnKey, this));
Expand All @@ -30,24 +38,34 @@ Eina_Bool KeyEventHandler::OnKey(void* data, int type, void* event) {
auto* engine = self->engine_;
auto is_down = type == ECORE_EVENT_KEY_DOWN;

if (strcmp(key->keyname, kPlatformBackButtonName) == 0) {
// The device back button was pressed.
if (engine->navigation_channel && !is_down) {
engine->navigation_channel->PopRoute();
}
} else {
if (engine->text_input_channel) {
if (is_down) {
engine->text_input_channel->OnKeyDown(key);
}
if (engine->text_input_channel->IsSoftwareKeyboardShowing()) {
return ECORE_CALLBACK_PASS_ON;
}
FT_LOGI("Keycode: %d, name: %s, mods: %d, is_down: %d", key->keycode,
key->keyname, key->modifiers, is_down);

if (engine->text_input_channel) {
if (is_down) {
engine->text_input_channel->OnKeyDown(key);
}
if (engine->key_event_channel) {
engine->key_event_channel->SendKeyEvent(key, is_down);
if (engine->text_input_channel->IsSoftwareKeyboardShowing()) {
return ECORE_CALLBACK_PASS_ON;
}
}

if (engine->key_event_channel) {
engine->key_event_channel->SendKeyEvent(
key, is_down,
[engine, keyname = std::string(key->keyname), is_down](bool handled) {
if (handled) {
return;
}
if (keyname == kBackKey && !is_down) {
if (engine->navigation_channel) {
engine->navigation_channel->PopRoute();
}
} else if (keyname == kExitKey && !is_down) {
ui_app_exit();
}
});
}
return ECORE_CALLBACK_PASS_ON;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This callback still returns ECORE_CALLBACK_PASS_ON instead of ECORE_CALLBACK_DONE because whether the app handled the key event is determined asynchronously. I'll try to find a better solution as noted in the PR comment.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try to find a better solution as noted in the PR comment.

Do you mean flutter/flutter#44918?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, probably. But the new API still doesn't make the result from Dart code synchronously available to the caller.

}

Expand Down