diff --git a/shell/platform/tizen/channels/platform_view_channel.cc b/shell/platform/tizen/channels/platform_view_channel.cc index c076e36a0f5ae..10781e87420b4 100644 --- a/shell/platform/tizen/channels/platform_view_channel.cc +++ b/shell/platform/tizen/channels/platform_view_channel.cc @@ -89,6 +89,27 @@ PlatformViewChannel::~PlatformViewChannel() { view_instances_.clear(); } +void PlatformViewChannel::sendKeyEvent(Ecore_Event_Key* key, bool is_down) { + auto instances = viewInstances(); + auto it = instances.find(currentFocusedViewId()); + if (it != instances.end()) { + if (is_down) { + it->second->dispatchKeyDownEvent(key); + } else { + it->second->dispatchKeyUpEvent(key); + } + } +} + +int PlatformViewChannel::currentFocusedViewId() { + for (auto it = view_instances_.begin(); it != view_instances_.end(); it++) { + if (it->second->isFocused()) { + return it->second->getViewId(); + } + } + return -1; +} + void PlatformViewChannel::HandleMethodCall( const flutter::MethodCall& call, std::unique_ptr> result) { @@ -113,10 +134,22 @@ void PlatformViewChannel::HandleMethodCall( } auto it = view_factories_.find(viewType); if (it != view_factories_.end()) { + auto focuesdView = view_instances_.find(currentFocusedViewId()); + if (focuesdView != view_instances_.end()) { + focuesdView->second->setFocus(false); + } + auto viewInstance = it->second->create(viewId, width, height, byteMessage); + viewInstance->setFocus(true); view_instances_.insert( std::pair(viewId, viewInstance)); + + if (channel_ != nullptr) { + auto id = std::make_unique(viewId); + channel_->InvokeMethod("viewFocused", std::move(id)); + } + result->Success(flutter::EncodableValue(viewInstance->getTextureId())); } else { LoggerE("can't find view type = %s", viewType.c_str()); diff --git a/shell/platform/tizen/channels/platform_view_channel.h b/shell/platform/tizen/channels/platform_view_channel.h index ecd437d7053df..a6d13c8449f52 100644 --- a/shell/platform/tizen/channels/platform_view_channel.h +++ b/shell/platform/tizen/channels/platform_view_channel.h @@ -5,6 +5,8 @@ #ifndef EMBEDDER_PLATFORM_VIEW_CHANNEL_H_ #define EMBEDDER_PLATFORM_VIEW_CHANNEL_H_ +#include + #include #include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/binary_messenger.h" @@ -20,6 +22,10 @@ class PlatformViewChannel { std::map>& viewFactories() { return view_factories_; } + std::map& viewInstances() { return view_instances_; } + + void sendKeyEvent(Ecore_Event_Key* key, bool is_down); + int currentFocusedViewId(); private: std::unique_ptr> channel_; diff --git a/shell/platform/tizen/channels/text_input_channel.cc b/shell/platform/tizen/channels/text_input_channel.cc index 42258a4aa9945..554eeff693bab 100644 --- a/shell/platform/tizen/channels/text_input_channel.cc +++ b/shell/platform/tizen/channels/text_input_channel.cc @@ -21,6 +21,8 @@ static constexpr char kMultilineInputType[] = "TextInputType.multiline"; static constexpr char kUpdateEditingStateMethod[] = "TextInputClient.updateEditingState"; static constexpr char kPerformActionMethod[] = "TextInputClient.performAction"; +static constexpr char kSetPlatformViewClient[] = + "TextInput.setPlatformViewClient"; static constexpr char kTextInputAction[] = "inputAction"; static constexpr char kTextInputType[] = "inputType"; static constexpr char kTextInputTypeName[] = "name"; @@ -329,6 +331,8 @@ void TextInputChannel::HandleMethodCall( ShowSoftwareKeyboard(); } else if (method.compare(kHideMethod) == 0) { HideSoftwareKeyboard(); + } else if (method.compare(kSetPlatformViewClient) == 0) { + // TODO: implement if necessary } else if (method.compare(kClearClientMethod) == 0) { active_model_ = nullptr; } else if (method.compare(kSetClientMethod) == 0) { diff --git a/shell/platform/tizen/key_event_handler.cc b/shell/platform/tizen/key_event_handler.cc index ced29bc34b345..34bc1c7c355a3 100644 --- a/shell/platform/tizen/key_event_handler.cc +++ b/shell/platform/tizen/key_event_handler.cc @@ -47,6 +47,9 @@ Eina_Bool KeyEventHandler::OnKey(void *data, int type, void *event) { if (engine->key_event_channel) { engine->key_event_channel->SendKeyEvent(key, is_down); } + if (engine->platform_view_channel) { + engine->platform_view_channel->sendKeyEvent(key, is_down); + } } return ECORE_CALLBACK_PASS_ON; } diff --git a/shell/platform/tizen/public/flutter_platform_view.h b/shell/platform/tizen/public/flutter_platform_view.h index e6f0464506340..f07b18118c176 100644 --- a/shell/platform/tizen/public/flutter_platform_view.h +++ b/shell/platform/tizen/public/flutter_platform_view.h @@ -5,6 +5,7 @@ #ifndef FLUTTER_SHELL_PLATFORM_TIZEN_PUBLIC_FLUTTER_PLATFORM_VIEW_H_ #define FLUTTER_SHELL_PLATFORM_TIZEN_PUBLIC_FLUTTER_PLATFORM_VIEW_H_ +#include #include #include @@ -15,7 +16,10 @@ using ByteMessage = std::vector; class PlatformView { public: PlatformView(flutter::PluginRegistrar* registrar, int viewId) - : registrar_(registrar), viewId_(viewId), textureId_(0) {} + : registrar_(registrar), + viewId_(viewId), + textureId_(0), + isFocused_(false) {} virtual ~PlatformView() {} int getViewId() { return viewId_; } int getTextureId() { return textureId_; } @@ -27,11 +31,18 @@ class PlatformView { double dy) = 0; virtual void setDirection(int direction) = 0; virtual void clearFocus() = 0; + void setFocus(bool f) { isFocused_ = f; } + bool isFocused() { return isFocused_; } + + // Key input event + virtual void dispatchKeyDownEvent(Ecore_Event_Key* key) = 0; + virtual void dispatchKeyUpEvent(Ecore_Event_Key* key) = 0; private: flutter::PluginRegistrar* registrar_; int viewId_; int textureId_; + bool isFocused_; }; class PlatformViewFactory {