diff --git a/flutter/shell/platform/tizen/BUILD.gn b/flutter/shell/platform/tizen/BUILD.gn index d3546a1..fa3f6ad 100644 --- a/flutter/shell/platform/tizen/BUILD.gn +++ b/flutter/shell/platform/tizen/BUILD.gn @@ -84,8 +84,8 @@ template("embedder") { "channels/app_control_channel.cc", "channels/feedback_manager.cc", "channels/input_device_channel.cc", - "channels/key_event_channel.cc", "channels/key_mapping.cc", + "channels/keyboard_channel.cc", "channels/lifecycle_channel.cc", "channels/mouse_cursor_channel.cc", "channels/navigation_channel.cc", diff --git a/flutter/shell/platform/tizen/channels/key_event_channel.cc b/flutter/shell/platform/tizen/channels/keyboard_channel.cc similarity index 82% rename from flutter/shell/platform/tizen/channels/key_event_channel.cc rename to flutter/shell/platform/tizen/channels/keyboard_channel.cc index bd80c5a..1d10573 100644 --- a/flutter/shell/platform/tizen/channels/key_event_channel.cc +++ b/flutter/shell/platform/tizen/channels/keyboard_channel.cc @@ -2,13 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "key_event_channel.h" +#include "keyboard_channel.h" #include #include #include #include +#include "flutter/shell/platform/common/client_wrapper/include/flutter/standard_method_codec.h" #include "flutter/shell/platform/common/json_message_codec.h" #include "flutter/shell/platform/tizen/channels/key_mapping.h" #include "flutter/shell/platform/tizen/logger.h" @@ -17,8 +18,10 @@ namespace flutter { namespace { -constexpr char kChannelName[] = "flutter/keyevent"; +constexpr char kKeyboardChannelName[] = "flutter/keyboard"; +constexpr char kKeyEventChannelName[] = "flutter/keyevent"; +constexpr char kGetKeyboardStateMethod[] = "getKeyboardState"; constexpr char kKeyMapKey[] = "keymap"; constexpr char kKeyCodeKey[] = "keyCode"; constexpr char kScanCodeKey[] = "scanCode"; @@ -88,17 +91,28 @@ uint32_t GetFallbackScanCodeFromKey(const std::string& key) { } // namespace -KeyEventChannel::KeyEventChannel(BinaryMessenger* messenger, +KeyboardChannel::KeyboardChannel(BinaryMessenger* messenger, SendEventHandler send_event) - : channel_(std::make_unique>( + : keyboard_channel_(std::make_unique>( messenger, - kChannelName, - &JsonMessageCodec::GetInstance())), - send_event_(send_event) {} + kKeyboardChannelName, + &StandardMethodCodec::GetInstance())), + key_event_channel_( + std::make_unique>( + messenger, + kKeyEventChannelName, + &JsonMessageCodec::GetInstance())), + send_event_(send_event) { + keyboard_channel_->SetMethodCallHandler( + [this](const MethodCall& call, + std::unique_ptr> result) { + HandleMethodCall(call, std::move(result)); + }); +} -KeyEventChannel::~KeyEventChannel() {} +KeyboardChannel::~KeyboardChannel() {} -void KeyEventChannel::SendKey(const char* key, +void KeyboardChannel::SendKey(const char* key, const char* string, const char* compose, uint32_t modifiers, @@ -130,13 +144,13 @@ void KeyEventChannel::SendKey(const char* key, SendEmbedderEvent(key, string, compose, modifiers, scan_code, is_down, sequence_id); // The channel-based API (RawKeyEvent) is deprecated and |SendChannelEvent| - // will be removed in the future. This class (KeyEventChannel) itself will + // will be removed in the future. This class (KeyboardChannel) itself will // also be renamed and refactored then. SendChannelEvent(key, string, compose, modifiers, scan_code, is_down, sequence_id); } -void KeyEventChannel::SendChannelEvent(const char* key, +void KeyboardChannel::SendChannelEvent(const char* key, const char* string, const char* compose, uint32_t modifiers, @@ -174,7 +188,7 @@ void KeyEventChannel::SendChannelEvent(const char* key, } else { event.AddMember(kTypeKey, kKeyUp, allocator); } - channel_->Send( + key_event_channel_->Send( event, [this, sequence_id](const uint8_t* reply, size_t reply_size) { if (reply != nullptr) { std::unique_ptr decoded = @@ -185,7 +199,7 @@ void KeyEventChannel::SendChannelEvent(const char* key, }); } -void KeyEventChannel::SendEmbedderEvent(const char* key, +void KeyboardChannel::SendEmbedderEvent(const char* key, const char* string, const char* compose, uint32_t modifiers, @@ -262,7 +276,7 @@ void KeyEventChannel::SendEmbedderEvent(const char* key, })); } -void KeyEventChannel::ResolvePendingEvent(uint64_t sequence_id, bool handled) { +void KeyboardChannel::ResolvePendingEvent(uint64_t sequence_id, bool handled) { auto iter = pending_events_.find(sequence_id); if (iter != pending_events_.end()) { PendingEvent* event = iter->second.get(); @@ -279,4 +293,22 @@ void KeyEventChannel::ResolvePendingEvent(uint64_t sequence_id, bool handled) { FT_ASSERT_NOT_REACHED(); } +void KeyboardChannel::HandleMethodCall( + const MethodCall& method_call, + std::unique_ptr> result) { + const std::string& method_name = method_call.method_name(); + if (method_name == kGetKeyboardStateMethod) { + EncodableMap map; + for (const auto& key : pressing_records_) { + EncodableValue physical_value(static_cast(key.first)); + EncodableValue logical_value(static_cast(key.second)); + map[physical_value] = logical_value; + } + + result->Success(EncodableValue(map)); + } else { + result->NotImplemented(); + } +} + } // namespace flutter diff --git a/flutter/shell/platform/tizen/channels/key_event_channel.h b/flutter/shell/platform/tizen/channels/keyboard_channel.h similarity index 78% rename from flutter/shell/platform/tizen/channels/key_event_channel.h rename to flutter/shell/platform/tizen/channels/keyboard_channel.h index 6535248..8127d24 100644 --- a/flutter/shell/platform/tizen/channels/key_event_channel.h +++ b/flutter/shell/platform/tizen/channels/keyboard_channel.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef EMBEDDER_KEY_EVENT_CHANNEL_H_ -#define EMBEDDER_KEY_EVENT_CHANNEL_H_ +#ifndef EMBEDDER_KEYBOARD_CHANNEL_H_ +#define EMBEDDER_KEYBOARD_CHANNEL_H_ #include #include @@ -11,20 +11,23 @@ #include "flutter/shell/platform/common/client_wrapper/include/flutter/basic_message_channel.h" #include "flutter/shell/platform/common/client_wrapper/include/flutter/binary_messenger.h" +#include "flutter/shell/platform/common/client_wrapper/include/flutter/encodable_value.h" +#include "flutter/shell/platform/common/client_wrapper/include/flutter/method_channel.h" #include "flutter/shell/platform/embedder/embedder.h" + #include "rapidjson/document.h" namespace flutter { -class KeyEventChannel { +class KeyboardChannel { public: using SendEventHandler = std::function; - explicit KeyEventChannel(BinaryMessenger* messenger, + explicit KeyboardChannel(BinaryMessenger* messenger, SendEventHandler send_event); - virtual ~KeyEventChannel(); + virtual ~KeyboardChannel(); void SendKey(const char* key, const char* string, @@ -35,7 +38,8 @@ class KeyEventChannel { std::function callback); private: - std::unique_ptr> channel_; + std::unique_ptr> keyboard_channel_; + std::unique_ptr> key_event_channel_; SendEventHandler send_event_; struct PendingEvent { @@ -76,8 +80,12 @@ class KeyEventChannel { uint64_t sequence_id); void ResolvePendingEvent(uint64_t sequence_id, bool handled); + + void HandleMethodCall( + const flutter::MethodCall& method_call, + std::unique_ptr> result); }; } // namespace flutter -#endif // EMBEDDER_KEY_EVENT_CHANNEL_H_ +#endif // EMBEDDER_KEYBOARD_CHANNEL_H_ diff --git a/flutter/shell/platform/tizen/flutter_tizen_engine.cc b/flutter/shell/platform/tizen/flutter_tizen_engine.cc index 46d1820..e3e2bbb 100644 --- a/flutter/shell/platform/tizen/flutter_tizen_engine.cc +++ b/flutter/shell/platform/tizen/flutter_tizen_engine.cc @@ -247,7 +247,7 @@ bool FlutterTizenEngine::RunEngine() { if (IsHeaded()) { texture_registrar_ = std::make_unique(this); - key_event_channel_ = std::make_unique( + keyboard_channel_ = std::make_unique( internal_plugin_registrar_->messenger(), [this](const FlutterKeyEvent& event, FlutterKeyEventCallback callback, void* user_data) { SendKeyEvent(event, callback, user_data); }); diff --git a/flutter/shell/platform/tizen/flutter_tizen_engine.h b/flutter/shell/platform/tizen/flutter_tizen_engine.h index 42d7119..a3525a9 100644 --- a/flutter/shell/platform/tizen/flutter_tizen_engine.h +++ b/flutter/shell/platform/tizen/flutter_tizen_engine.h @@ -17,7 +17,7 @@ #include "flutter/shell/platform/tizen/accessibility_settings.h" #include "flutter/shell/platform/tizen/channels/accessibility_channel.h" #include "flutter/shell/platform/tizen/channels/app_control_channel.h" -#include "flutter/shell/platform/tizen/channels/key_event_channel.h" +#include "flutter/shell/platform/tizen/channels/keyboard_channel.h" #include "flutter/shell/platform/tizen/channels/lifecycle_channel.h" #include "flutter/shell/platform/tizen/channels/navigation_channel.h" #include "flutter/shell/platform/tizen/channels/platform_view_channel.h" @@ -101,7 +101,7 @@ class FlutterTizenEngine { return app_control_channel_.get(); } - KeyEventChannel* key_event_channel() { return key_event_channel_.get(); } + KeyboardChannel* keyboard_channel() { return keyboard_channel_.get(); } LifecycleChannel* lifecycle_channel() { return lifecycle_channel_.get(); } @@ -251,8 +251,8 @@ class FlutterTizenEngine { // A plugin that implements the Tizen app_control channel. std::unique_ptr app_control_channel_; - // A plugin that implements the Flutter keyevent channel. - std::unique_ptr key_event_channel_; + // A plugin that implements the Flutter keyboard channel. + std::unique_ptr keyboard_channel_; // A plugin that implements the Flutter lifecycle channel. std::unique_ptr lifecycle_channel_; diff --git a/flutter/shell/platform/tizen/flutter_tizen_view.cc b/flutter/shell/platform/tizen/flutter_tizen_view.cc index 8abd29c..6a66fb3 100644 --- a/flutter/shell/platform/tizen/flutter_tizen_view.cc +++ b/flutter/shell/platform/tizen/flutter_tizen_view.cc @@ -351,8 +351,8 @@ void FlutterTizenView::OnKey(const char* key, } } - if (engine_->key_event_channel()) { - engine_->key_event_channel()->SendKey( + if (engine_->keyboard_channel()) { + engine_->keyboard_channel()->SendKey( key, string, compose, modifiers, scan_code, is_down, [engine = engine_.get(), symbol = std::string(key), is_down](bool handled) {