From 3f807ff9468181909448dd4662d1b538187f6692 Mon Sep 17 00:00:00 2001 From: wangxinpeng Date: Sat, 15 Jan 2022 17:11:49 +0800 Subject: [PATCH] dispatch keyboard event to input method Signed-off-by: wangxinpeng Change-Id: I0fdb9724f3821fbc7b3f9ac2fae2073ca3482e58 --- wm/BUILD.gn | 1 + wm/include/window_input_channel.h | 1 + wm/src/window_input_channel.cpp | 29 ++++++++++++++++++++++++----- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/wm/BUILD.gn b/wm/BUILD.gn index 42dcfa781a..de4ee028f7 100644 --- a/wm/BUILD.gn +++ b/wm/BUILD.gn @@ -175,6 +175,7 @@ ohos_shared_library("libwm") { external_deps = [ "aafwk_standard:ability_context_native", "bytrace_standard:bytrace_core", + "inputmethod_native:inputmethod_client", "ipc:ipc_core", ] diff --git a/wm/include/window_input_channel.h b/wm/include/window_input_channel.h index fb700a1d54..c58acb6f95 100644 --- a/wm/include/window_input_channel.h +++ b/wm/include/window_input_channel.h @@ -30,6 +30,7 @@ public: void SetInputListener(std::shared_ptr& listener); private: void OnVsync(int64_t timeStamp); + bool IsKeyboardEvent(const std::shared_ptr& keyEvent) const; std::vector> pointerEventPool_; sptr window_; std::shared_ptr callback_ = diff --git a/wm/src/window_input_channel.cpp b/wm/src/window_input_channel.cpp index c436a5c6a2..07196476a4 100644 --- a/wm/src/window_input_channel.cpp +++ b/wm/src/window_input_channel.cpp @@ -14,7 +14,8 @@ */ #include "window_input_channel.h" -#include +#include +#include "window_manager_hilog.h" namespace OHOS { namespace Rosen { @@ -33,11 +34,20 @@ void WindowInputChannel::HandleKeyEvent(std::shared_ptr& keyEvent WLOGE("HandleKeyEvent keyEvent is nullptr"); return; } - if (inputListener_ != nullptr) { - inputListener_->OnInputEvent(keyEvent); - return; + bool isKeyboardEvent = IsKeyboardEvent(keyEvent); + bool inputMethodHasProcessed = false; + if (isKeyboardEvent) { + WLOGI("dispatch keyEvent to input method"); + inputMethodHasProcessed = MiscServices::InputMethodController::GetInstance()->dispatchKeyEvent(keyEvent); + } + if (!isKeyboardEvent || !inputMethodHasProcessed) { + WLOGI("dispatch keyEvent to ACE"); + if (inputListener_ != nullptr) { + inputListener_->OnInputEvent(keyEvent); + return; + } + window_->ConsumeKeyEvent(keyEvent); } - window_->ConsumeKeyEvent(keyEvent); keyEvent->MarkProcessed(); } @@ -82,5 +92,14 @@ void WindowInputChannel::SetInputListener(std::shared_ptr& keyEvent) const +{ + int32_t keyCode = keyEvent->GetKeyCode(); + bool isKeyFN = (keyCode == MMI::KeyEvent::KEYCODE_FN); + bool isKeyboard = (keyCode >= MMI::KeyEvent::KEYCODE_0 && keyCode <= MMI::KeyEvent::KEYCODE_NUMPAD_RIGHT_PAREN); + WLOGI("isKeyFN: %{public}d, isKeyboard: %{public}d", isKeyFN, isKeyboard); + return (isKeyFN || isKeyboard); +} } } \ No newline at end of file -- Gitee