diff --git a/shell/platform/tizen/channels/platform_channel.cc b/shell/platform/tizen/channels/platform_channel.cc index 9deb3a4ea255a..62d6f2e625982 100644 --- a/shell/platform/tizen/channels/platform_channel.cc +++ b/shell/platform/tizen/channels/platform_channel.cc @@ -14,6 +14,8 @@ #include "flutter/shell/platform/tizen/channels/tizen_shell.h" #endif #include "flutter/shell/platform/tizen/logger.h" +#include "flutter/shell/platform/tizen/tizen_view.h" +#include "flutter/shell/platform/tizen/tizen_window.h" namespace flutter { @@ -62,12 +64,12 @@ std::string text_clipboard = ""; } // namespace PlatformChannel::PlatformChannel(BinaryMessenger* messenger, - TizenWindow* window) + TizenViewBase* view) : channel_(std::make_unique>( messenger, kChannelName, &JsonMethodCodec::GetInstance())), - window_(window) { + view_(view) { channel_->SetMethodCallHandler( [this](const MethodCall& call, std::unique_ptr> result) { @@ -156,8 +158,10 @@ void PlatformChannel::HandleMethodCall( } void PlatformChannel::SystemNavigatorPop() { - if (window_) { + if (view_->GetType() == TizenViewType::kWindow) { ui_app_exit(); + } else { + reinterpret_cast(view_)->Unfocus(); } } @@ -174,13 +178,13 @@ void PlatformChannel::HapticFeedbackVibrate(const std::string& feedback_type) { } void PlatformChannel::RestoreSystemUiOverlays() { - if (!window_) { + if (view_->GetType() != TizenViewType::kWindow) { return; } #ifdef COMMON_PROFILE auto& shell = TizenShell::GetInstance(); - shell.InitializeSoftkey(window_->GetWindowId()); + shell.InitializeSoftkey(view_->GetWindowId()); if (shell.IsSoftkeyShown()) { shell.ShowSoftkey(); @@ -192,13 +196,13 @@ void PlatformChannel::RestoreSystemUiOverlays() { void PlatformChannel::SetEnabledSystemUiOverlays( const std::vector& overlays) { - if (!window_) { + if (view_->GetType() != TizenViewType::kWindow) { return; } #ifdef COMMON_PROFILE auto& shell = TizenShell::GetInstance(); - shell.InitializeSoftkey(window_->GetWindowId()); + shell.InitializeSoftkey(view_->GetWindowId()); if (std::find(overlays.begin(), overlays.end(), kSystemUiOverlayBottom) != overlays.end()) { @@ -211,7 +215,7 @@ void PlatformChannel::SetEnabledSystemUiOverlays( void PlatformChannel::SetPreferredOrientations( const std::vector& orientations) { - if (!window_) { + if (view_->GetType() != TizenViewType::kWindow) { return; } @@ -230,7 +234,7 @@ void PlatformChannel::SetPreferredOrientations( // default. rotations = {0, 90, 180, 270}; } - window_->SetPreferredOrientations(rotations); + reinterpret_cast(view_)->SetPreferredOrientations(rotations); } } // namespace flutter diff --git a/shell/platform/tizen/channels/platform_channel.h b/shell/platform/tizen/channels/platform_channel.h index 4e11fdd5ca7af..67d47e25d6ed1 100644 --- a/shell/platform/tizen/channels/platform_channel.h +++ b/shell/platform/tizen/channels/platform_channel.h @@ -11,14 +11,14 @@ #include "flutter/shell/platform/common/client_wrapper/include/flutter/binary_messenger.h" #include "flutter/shell/platform/common/client_wrapper/include/flutter/method_channel.h" -#include "flutter/shell/platform/tizen/tizen_window.h" +#include "flutter/shell/platform/tizen/tizen_view_base.h" #include "rapidjson/document.h" namespace flutter { class PlatformChannel { public: - explicit PlatformChannel(BinaryMessenger* messenger, TizenWindow* window); + explicit PlatformChannel(BinaryMessenger* messenger, TizenViewBase* view); virtual ~PlatformChannel(); private: @@ -35,9 +35,8 @@ class PlatformChannel { std::unique_ptr> channel_; - // A reference to the window object managed by FlutterTizenView. - // This can be nullptr if the engine is running in headless mode. - TizenWindow* window_; + // A reference to the native view managed by FlutterTizenView. + TizenViewBase* view_; }; } // namespace flutter diff --git a/shell/platform/tizen/channels/window_channel.h b/shell/platform/tizen/channels/window_channel.h index 78c01ee2b94a1..73ed2e19c413b 100644 --- a/shell/platform/tizen/channels/window_channel.h +++ b/shell/platform/tizen/channels/window_channel.h @@ -26,7 +26,7 @@ class WindowChannel { std::unique_ptr> channel_; - // A reference to the renderer object managed by FlutterTizenView. + // A reference to the native window managed by FlutterTizenView. TizenWindow* window_; }; diff --git a/shell/platform/tizen/flutter_tizen_view.cc b/shell/platform/tizen/flutter_tizen_view.cc index 20d9e2f8ea397..eab7f64463293 100644 --- a/shell/platform/tizen/flutter_tizen_view.cc +++ b/shell/platform/tizen/flutter_tizen_view.cc @@ -75,13 +75,12 @@ void FlutterTizenView::SetEngine(std::unique_ptr engine) { if (tizen_view_->GetType() == TizenViewType::kWindow) { auto* window = reinterpret_cast(tizen_view_.get()); - platform_channel_ = std::make_unique(messenger, window); window_channel_ = std::make_unique(messenger, window); } else { - platform_channel_ = std::make_unique(messenger, nullptr); window_channel_ = std::make_unique(messenger, nullptr); } - + platform_channel_ = + std::make_unique(messenger, tizen_view_.get()); text_input_channel_ = std::make_unique( internal_plugin_registrar_->messenger(), tizen_view_->input_method_context()); diff --git a/shell/platform/tizen/tizen_view.h b/shell/platform/tizen/tizen_view.h index f39447c2edaff..066ed8d3fd3d4 100644 --- a/shell/platform/tizen/tizen_view.h +++ b/shell/platform/tizen/tizen_view.h @@ -20,12 +20,15 @@ class TizenView : public TizenViewBase { TizenViewType GetType() override { return TizenViewType::kView; }; + void Unfocus() { focused_ = false; }; + protected: explicit TizenView(int32_t width, int32_t height) : initial_width_(width), initial_height_(height) {} int32_t initial_width_ = 0; int32_t initial_height_ = 0; + bool focused_ = false; }; } // namespace flutter diff --git a/shell/platform/tizen/tizen_view_elementary.cc b/shell/platform/tizen/tizen_view_elementary.cc index e4ecd0bf266e8..ceb5e16846836 100644 --- a/shell/platform/tizen/tizen_view_elementary.cc +++ b/shell/platform/tizen/tizen_view_elementary.cc @@ -243,7 +243,7 @@ void TizenViewElementary::RegisterEventHandlers() { void* event_info) { auto* self = reinterpret_cast(data); if (self->view_delegate_) { - if (self->event_layer_ == object) { + if (self->event_layer_ == object && self->focused_) { auto* key_event = reinterpret_cast(event_info); bool handled = false; key_event->event_flags = @@ -269,7 +269,7 @@ void TizenViewElementary::RegisterEventHandlers() { [](void* data, Evas* evas, Evas_Object* object, void* event_info) { auto* self = reinterpret_cast(data); if (self->view_delegate_) { - if (self->event_layer_ == object) { + if (self->event_layer_ == object && self->focused_) { auto* key_event = reinterpret_cast(event_info); bool handled = false; key_event->event_flags = Evas_Event_Flags(key_event->event_flags | @@ -290,6 +290,17 @@ void TizenViewElementary::RegisterEventHandlers() { evas_object_event_callback_add(event_layer_, EVAS_CALLBACK_KEY_UP, evas_object_callbacks_[EVAS_CALLBACK_KEY_UP], this); + + focused_callback_ = [](void* data, Evas_Object* object, void* event_info) { + auto* self = reinterpret_cast(data); + if (self->view_delegate_) { + if (self->event_layer_ == object) { + self->focused_ = true; + } + } + }; + evas_object_smart_callback_add(event_layer_, "focused", focused_callback_, + this); } void TizenViewElementary::UnregisterEventHandlers() { @@ -312,6 +323,7 @@ void TizenViewElementary::UnregisterEventHandlers() { evas_object_callbacks_[EVAS_CALLBACK_KEY_DOWN]); evas_object_event_callback_del(event_layer_, EVAS_CALLBACK_KEY_UP, evas_object_callbacks_[EVAS_CALLBACK_KEY_UP]); + evas_object_smart_callback_del(event_layer_, "focused", focused_callback_); } TizenGeometry TizenViewElementary::GetGeometry() { diff --git a/shell/platform/tizen/tizen_view_elementary.h b/shell/platform/tizen/tizen_view_elementary.h index 94e596c723b35..3c702a9893f42 100644 --- a/shell/platform/tizen/tizen_view_elementary.h +++ b/shell/platform/tizen/tizen_view_elementary.h @@ -56,6 +56,7 @@ class TizenViewElementary : public TizenView { std::unordered_map evas_object_callbacks_; std::vector ecore_event_key_handlers_; + Evas_Smart_Cb focused_callback_ = nullptr; bool scroll_hold_ = false; }; diff --git a/shell/platform/tizen/tizen_window_elementary.h b/shell/platform/tizen/tizen_window_elementary.h index aabb02cf8935b..5bff6a04a8102 100644 --- a/shell/platform/tizen/tizen_window_elementary.h +++ b/shell/platform/tizen/tizen_window_elementary.h @@ -65,7 +65,7 @@ class TizenWindowElementary : public TizenWindow { Evas_Object* elm_win_ = nullptr; Evas_Object* image_ = nullptr; - Evas_Smart_Cb rotation_changed_callback_; + Evas_Smart_Cb rotation_changed_callback_ = nullptr; std::unordered_map evas_object_callbacks_; };