diff --git a/shell/platform/tizen/flutter_tizen.cc b/shell/platform/tizen/flutter_tizen.cc index a41b0b9202362..6588925a1ebd4 100644 --- a/shell/platform/tizen/flutter_tizen.cc +++ b/shell/platform/tizen/flutter_tizen.cc @@ -14,6 +14,9 @@ #include "flutter/shell/platform/tizen/logger.h" #include "flutter/shell/platform/tizen/public/flutter_platform_view.h" #include "flutter/shell/platform/tizen/tizen_view.h" +#ifdef NUI_SUPPORT +#include "flutter/shell/platform/tizen/tizen_view_nui.h" +#endif #include "flutter/shell/platform/tizen/tizen_window.h" #ifndef WEARABLE_PROFILE #include "flutter/shell/platform/tizen/tizen_window_ecore_wl2.h" @@ -266,13 +269,30 @@ void FlutterDesktopViewOnPointerEvent(FlutterDesktopViewRef view, } void FlutterDesktopViewOnKeyEvent(FlutterDesktopViewRef view, + const char* device_name, + uint32_t device_class, + uint32_t device_subclass, const char* key, const char* string, uint32_t modifiers, uint32_t scan_code, + size_t timestamp, bool is_down) { +#ifdef NUI_SUPPORT + auto* tizen_view = reinterpret_cast( + ViewFromHandle(view)->tizen_view()); + + if (tizen_view->GetType() == flutter::TizenViewType::kView && + ViewFromHandle(view)->engine()->renderer()->type() == + FlutterDesktopRendererType::kEGL) { + reinterpret_cast(tizen_view) + ->OnKey(device_name, device_class, device_subclass, key, string, + nullptr, modifiers, scan_code, timestamp, is_down); + } +#else ViewFromHandle(view)->OnKey(key, string, nullptr, modifiers, scan_code, is_down); +#endif } void FlutterDesktopViewSetFocus(FlutterDesktopViewRef view, bool focused) { diff --git a/shell/platform/tizen/public/flutter_tizen.h b/shell/platform/tizen/public/flutter_tizen.h index 23b4d3767193d..c1132d6cd223a 100644 --- a/shell/platform/tizen/public/flutter_tizen.h +++ b/shell/platform/tizen/public/flutter_tizen.h @@ -210,10 +210,14 @@ FLUTTER_EXPORT void FlutterDesktopViewOnPointerEvent( int32_t device_id); FLUTTER_EXPORT void FlutterDesktopViewOnKeyEvent(FlutterDesktopViewRef view, + const char* device_name, + uint32_t device_class, + uint32_t device_subclass, const char* key, const char* string, uint32_t modifiers, uint32_t scan_code, + size_t timestamp, bool is_down); FLUTTER_EXPORT void FlutterDesktopViewSetFocus(FlutterDesktopViewRef view, diff --git a/shell/platform/tizen/tizen_input_method_context.cc b/shell/platform/tizen/tizen_input_method_context.cc index 02505561a9419..0c94620a22863 100644 --- a/shell/platform/tizen/tizen_input_method_context.cc +++ b/shell/platform/tizen/tizen_input_method_context.cc @@ -146,6 +146,12 @@ TizenInputMethodContext::TizenInputMethodContext(uintptr_t window_id) { TizenInputMethodContext::~TizenInputMethodContext() { UnregisterEventCallbacks(); +#ifdef NUI_SUPPORT + if (ecore_device_) { + ecore_device_del(ecore_device_); + } +#endif + if (imf_context_) { ecore_imf_context_del(imf_context_); } @@ -191,6 +197,51 @@ bool TizenInputMethodContext::HandleEvasEventKeyUp(Evas_Event_Key_Up* event) { reinterpret_cast(&imf_event)); } +#ifdef NUI_SUPPORT +bool TizenInputMethodContext::HandleNuiKeyEvent(const char* device_name, + uint32_t device_class, + uint32_t device_subclass, + const char* key, + const char* string, + uint32_t modifiers, + uint32_t scan_code, + size_t timestamp, + bool is_down) { + Ecore_Event_Key event; + event.keyname = event.key = key ? key : ""; + event.string = string ? string : ""; + event.modifiers = modifiers; + event.keycode = scan_code; + event.timestamp = timestamp; + if (device_name) { + if (!ecore_device_) { + ecore_device_ = ecore_device_add(); + } + + event.dev = ecore_device_; + ecore_device_name_set(event.dev, device_name); + ecore_device_class_set(event.dev, + static_cast(device_class)); + ecore_device_subclass_set( + event.dev, static_cast(device_subclass)); + } + + if (is_down) { + Ecore_IMF_Event_Key_Down imf_event = + EcoreEventKeyToEcoreImfEvent(&event); + return ecore_imf_context_filter_event( + imf_context_, ECORE_IMF_EVENT_KEY_DOWN, + reinterpret_cast(&imf_event)); + } else { + Ecore_IMF_Event_Key_Up imf_event = + EcoreEventKeyToEcoreImfEvent(&event); + return ecore_imf_context_filter_event( + imf_context_, ECORE_IMF_EVENT_KEY_UP, + reinterpret_cast(&imf_event)); + } +} +#endif + InputPanelGeometry TizenInputMethodContext::GetInputPanelGeometry() { FT_ASSERT(imf_context_); InputPanelGeometry geometry; diff --git a/shell/platform/tizen/tizen_input_method_context.h b/shell/platform/tizen/tizen_input_method_context.h index b94ddb1538a09..c241f909ad7ae 100644 --- a/shell/platform/tizen/tizen_input_method_context.h +++ b/shell/platform/tizen/tizen_input_method_context.h @@ -35,6 +35,18 @@ class TizenInputMethodContext { bool HandleEvasEventKeyUp(Evas_Event_Key_Up* event); +#ifdef NUI_SUPPORT + bool HandleNuiKeyEvent(const char* device_name, + uint32_t device_class, + uint32_t device_subclass, + const char* key, + const char* string, + uint32_t modifiers, + uint32_t scan_code, + size_t timestamp, + bool is_down); +#endif + InputPanelGeometry GetInputPanelGeometry(); void ResetInputMethodContext(); @@ -70,6 +82,9 @@ class TizenInputMethodContext { void SetContextOptions(); void SetInputPanelOptions(); +#ifdef NUI_SUPPORT + Ecore_Device* ecore_device_ = nullptr; +#endif Ecore_IMF_Context* imf_context_ = nullptr; OnCommit on_commit_; OnPreeditChanged on_preedit_changed_; diff --git a/shell/platform/tizen/tizen_view_nui.cc b/shell/platform/tizen/tizen_view_nui.cc index 2cb180738ec77..c9eb2eb4a196c 100644 --- a/shell/platform/tizen/tizen_view_nui.cc +++ b/shell/platform/tizen/tizen_view_nui.cc @@ -74,6 +74,29 @@ void TizenViewNui::RequestRendering() { rendering_callback_->Trigger(); } +void TizenViewNui::OnKey(const char* device_name, + uint32_t device_class, + uint32_t device_subclass, + const char* key, + const char* string, + const char* compose, + uint32_t modifiers, + uint32_t scan_code, + size_t timestamp, + bool is_down) { + bool handled = false; + + if (input_method_context_->IsInputPanelShown()) { + handled = input_method_context_->HandleNuiKeyEvent( + device_name, device_class, device_subclass, key, string, modifiers, + scan_code, timestamp, is_down); + } + + if (!handled) { + view_delegate_->OnKey(key, string, compose, modifiers, scan_code, is_down); + } +} + void TizenViewNui::PrepareInputMethod() { input_method_context_ = std::make_unique(GetWindowId()); diff --git a/shell/platform/tizen/tizen_view_nui.h b/shell/platform/tizen/tizen_view_nui.h index 83d39e65e0f78..5ddf9172f7b16 100644 --- a/shell/platform/tizen/tizen_view_nui.h +++ b/shell/platform/tizen/tizen_view_nui.h @@ -42,6 +42,17 @@ class TizenViewNui : public TizenView { void RequestRendering(); + void OnKey(const char* device_name, + uint32_t device_class, + uint32_t device_subclass, + const char* key, + const char* string, + const char* compose, + uint32_t modifiers, + uint32_t scan_code, + size_t timestamp, + bool is_down); + private: void RegisterEventHandlers();