From 83212dfbce5049e2400432ebe31bd9d5ff9b8ccf Mon Sep 17 00:00:00 2001 From: cy7717 Date: Fri, 20 Oct 2023 16:11:50 +0800 Subject: [PATCH 1/6] MOD Signed-off-by: cy7717 --- .../js/napi/inputmethodability/js_panel.cpp | 4 +- .../adapter/input_dev_monitor/BUILD.gn | 48 ++++++++ .../include/input_dev_monitor.h | 46 +++++++ .../src/input_dev_monitor.cpp | 66 ++++++++++ .../include/input_method_ability.h | 8 +- .../src/input_method_ability.cpp | 116 +++++++++++++++--- .../inner_api/inputmethod_ability/BUILD.gn | 5 +- services/include/peruser_session.h | 1 + services/src/input_method_system_ability.cpp | 2 +- services/src/peruser_session.cpp | 12 ++ 10 files changed, 283 insertions(+), 25 deletions(-) create mode 100644 frameworks/native/inputmethod_ability/adapter/input_dev_monitor/BUILD.gn create mode 100644 frameworks/native/inputmethod_ability/adapter/input_dev_monitor/include/input_dev_monitor.h create mode 100644 frameworks/native/inputmethod_ability/adapter/input_dev_monitor/src/input_dev_monitor.cpp diff --git a/frameworks/js/napi/inputmethodability/js_panel.cpp b/frameworks/js/napi/inputmethodability/js_panel.cpp index 82cdf7b6..bfde1584 100644 --- a/frameworks/js/napi/inputmethodability/js_panel.cpp +++ b/frameworks/js/napi/inputmethodability/js_panel.cpp @@ -200,7 +200,7 @@ napi_value JsPanel::Show(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(env, info); auto exec = [ctxt](AsyncCall::Context *ctx) { CHECK_RETURN_VOID(ctxt->inputMethodPanel != nullptr, "inputMethodPanel_ is nullptr."); - auto code = ctxt->inputMethodPanel->ShowPanel(); + auto code = InputMethodAbility::GetInstance()->ShowPanelSelf(ctxt->inputMethodPanel); if (code == ErrorCode::NO_ERROR) { ctxt->SetState(napi_ok); return; @@ -217,7 +217,7 @@ napi_value JsPanel::Hide(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(env, info); auto exec = [ctxt](AsyncCall::Context *ctx) { CHECK_RETURN_VOID(ctxt->inputMethodPanel != nullptr, "inputMethodPanel_ is nullptr."); - auto code = ctxt->inputMethodPanel->HidePanel(); + auto code = InputMethodAbility::GetInstance()->HidePanelSelf(ctxt->inputMethodPanel); if (code == ErrorCode::NO_ERROR) { ctxt->SetState(napi_ok); return; diff --git a/frameworks/native/inputmethod_ability/adapter/input_dev_monitor/BUILD.gn b/frameworks/native/inputmethod_ability/adapter/input_dev_monitor/BUILD.gn new file mode 100644 index 00000000..61ee2a37 --- /dev/null +++ b/frameworks/native/inputmethod_ability/adapter/input_dev_monitor/BUILD.gn @@ -0,0 +1,48 @@ +# Copyright (C) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//base/inputmethod/imf/inputmethod.gni") +import("//build/ohos.gni") + +config("input_dev_monitor_config") { + visibility = [ ":*" ] + include_dirs = [ "include" ] + ldflags = [ "-Wl,--exclude-libs=ALL" ] + cflags = [ + "-fdata-sections", + "-ffunction-sections", + "-fvisibility=hidden", + ] +} + +config("input_dev_monitor_public_config") { + visibility = [ "./*" ] + include_dirs = [ + "include", + "${inputmethod_path}/services/include", + "//foundation/multimodalinput/input/interfaces/native/innerkits/event/include", + ] +} + +ohos_static_library("input_dev_monitor") { + sources = [ "src/input_dev_monitor.cpp" ] + configs = [ ":input_dev_monitor_config" ] + public_configs = [ ":input_dev_monitor_public_config" ] + deps = [] + external_deps = [ + "input:libmmi-client", + "hilog:libhilog", + ] + subsystem_name = "inputmethod" + part_name = "imf" +} diff --git a/frameworks/native/inputmethod_ability/adapter/input_dev_monitor/include/input_dev_monitor.h b/frameworks/native/inputmethod_ability/adapter/input_dev_monitor/include/input_dev_monitor.h new file mode 100644 index 00000000..49c73e5e --- /dev/null +++ b/frameworks/native/inputmethod_ability/adapter/input_dev_monitor/include/input_dev_monitor.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef IMF_DEV_MONITOR_H +#define IMF_DEV_MONITOR_H +#include +#include + +#include "input_manager.h" +namespace OHOS { +namespace MiscServices { +class InputDevMonitor { +public: + using FocusHandle = std::function; + static InputDevMonitor &GetInstance(); + int32_t RegisterDevListener(const FocusHandle &handle); + class InputDeviceListenerImpl : public MMI::IInputDeviceListener { + public: + explicit InputDeviceListenerImpl(FocusHandle handler) : handler_(std::move(handler)){}; + virtual ~InputDeviceListenerImpl() = default; + void OnDeviceAdded(int32_t deviceId, const std::string &type) override; + void OnDeviceRemoved(int32_t deviceId, const std::string &type) override; + + private: + FocusHandle handler_; + }; + +private: + InputDevMonitor() = default; +}; +} // namespace MiscServices +} // namespace OHOS + +#endif // IMF_DEV_MONITOR_H diff --git a/frameworks/native/inputmethod_ability/adapter/input_dev_monitor/src/input_dev_monitor.cpp b/frameworks/native/inputmethod_ability/adapter/input_dev_monitor/src/input_dev_monitor.cpp new file mode 100644 index 00000000..289a0f66 --- /dev/null +++ b/frameworks/native/inputmethod_ability/adapter/input_dev_monitor/src/input_dev_monitor.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "input_dev_monitor.h" + +#include "global.h" +#include "input_device.h" + +namespace OHOS { +namespace MiscServices { +using namespace MMI; +InputDevMonitor &InputDevMonitor::GetInstance() +{ + static InputDevMonitor monitor; + return monitor; +} + +int32_t InputDevMonitor::RegisterDevListener(const FocusHandle &handler) +{ + return MMI::InputManager::GetInstance()->RegisterDevListener( + "change", std::make_shared(handler)); +} + +void InputDevMonitor::InputDeviceListenerImpl::OnDeviceAdded(int32_t deviceId, const std::string &type) +{ + IMSA_HILOGD("deviceId: %{public}d, type: %{public}s.", deviceId, type.c_str()); + if (type != "add") { + return; + } + int32_t kbType = -1; + auto ret = MMI::InputManager::GetInstance()->GetKeyboardType( + deviceId, [&kbType](int32_t keyboardType) { kbType = keyboardType; }); + IMSA_HILOGD("ret: %{public}d.", ret); + if (ret == 0 && kbType == KeyboardType::KEYBOARD_TYPE_ALPHABETICKEYBOARD) { + handler_(true); + } +} + +void InputDevMonitor::InputDeviceListenerImpl::OnDeviceRemoved(int32_t deviceId, const std::string &type) +{ + IMSA_HILOGD("deviceId: %{public}d, type: %{public}s.", deviceId, type.c_str()); + if (type != "remove") { + return; + } + int32_t kbType = -1; + auto ret = MMI::InputManager::GetInstance()->GetKeyboardType( + deviceId, [&kbType](int32_t keyboardType) { kbType = keyboardType; }); + IMSA_HILOGD("ret: %{public}d.", ret); + if (ret == 0 && kbType == KeyboardType::KEYBOARD_TYPE_ALPHABETICKEYBOARD) { + handler_(false); + } +} +} // namespace MiscServices +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/inputmethod_ability/include/input_method_ability.h b/frameworks/native/inputmethod_ability/include/input_method_ability.h index ede0cfc8..a35e7a53 100644 --- a/frameworks/native/inputmethod_ability/include/input_method_ability.h +++ b/frameworks/native/inputmethod_ability/include/input_method_ability.h @@ -75,6 +75,8 @@ public: int32_t CreatePanel(const std::shared_ptr &context, const PanelInfo &panelInfo, std::shared_ptr &inputMethodPanel); int32_t DestroyPanel(const std::shared_ptr &inputMethodPanel); + int32_t ShowPanel(const std::shared_ptr &inputMethodPanel); + int32_t HidePanel(const std::shared_ptr &inputMethodPanel); bool IsCurrentIme(); bool IsEnable(); int32_t ExitCurrentInputType(); @@ -121,7 +123,11 @@ private: void OnSelectionChange(Message *msg); void OnConfigurationChange(Message *msg); void OnTextConfigChange(const TextTotalConfig &textConfig); - int32_t ShowPanelKeyboard(); + int32_t ShowPanelSoftKeyboard(); + int32_t HidePanelSoftKeyboard(); + int32_t HidePanelSoftKeyBoard(const std::shared_ptr &inputMethodPanel); + void UpdateAlphaKeyboardFlag(bool hasAlphaKeyboard); + bool hasAlphaKeyboard_{ false }; ConcurrentMap> panels_{}; std::atomic_bool isPanelKeyboard_{ false }; std::atomic_bool isBound_{ false }; diff --git a/frameworks/native/inputmethod_ability/src/input_method_ability.cpp b/frameworks/native/inputmethod_ability/src/input_method_ability.cpp index 7838a9d5..45fdf12f 100644 --- a/frameworks/native/inputmethod_ability/src/input_method_ability.cpp +++ b/frameworks/native/inputmethod_ability/src/input_method_ability.cpp @@ -20,6 +20,7 @@ #include #include "global.h" +#include "input_dev_monitor.h" #include "input_method_agent_proxy.h" #include "input_method_core_proxy.h" #include "input_method_utils.h" @@ -40,6 +41,7 @@ std::mutex InputMethodAbility::instanceLock_; constexpr double INVALID_CURSOR_VALUE = -1.0; constexpr int32_t INVALID_SELECTION_VALUE = -1; constexpr uint32_t FIND_PANEL_RETRY_INTERVAL = 10; +constexpr uint32_t REGISTER_DEV_LISTENER_RETRY_INTERVAL = 100; constexpr uint32_t MAX_RETRY_TIMES = 100; InputMethodAbility::InputMethodAbility() : msgHandler_(nullptr), stop_(false) { @@ -160,6 +162,12 @@ void InputMethodAbility::Initialize() coreStub_->SetMessageHandler(msgHandler_); agentStub_->SetMessageHandler(msgHandler_); workThreadHandler = std::thread([this] { WorkThread(); }); + + auto handler = [this](bool hasAlphaKeyboard) { UpdateAlphaKeyboardFlag(hasAlphaKeyboard); }; + if (!BlockRetry(REGISTER_DEV_LISTENER_RETRY_INTERVAL, MAX_RETRY_TIMES, + [handler]() -> bool { return InputDevMonitor::GetInstance().RegisterDevListener(handler) == 0; })) { + IMSA_HILOGE("register device listener failed."); + } } void InputMethodAbility::SetImeListener(std::shared_ptr imeListener) @@ -378,7 +386,7 @@ int32_t InputMethodAbility::ShowKeyboard() } imeListener_->OnKeyboardStatus(true); if (isPanelKeyboard_.load()) { - auto ret = ShowPanelKeyboard(); + auto ret = ShowPanelSoftKeyboard(); if (ret != ErrorCode::NO_ERROR) { return ret; } @@ -392,7 +400,7 @@ int32_t InputMethodAbility::ShowKeyboard() return ErrorCode::NO_ERROR; } -int32_t InputMethodAbility::ShowPanelKeyboard() +int32_t InputMethodAbility::ShowPanelSoftKeyboard() { if (!BlockRetry(FIND_PANEL_RETRY_INTERVAL, MAX_RETRY_TIMES, [this]() -> bool { return panels_.Find(SOFT_KEYBOARD).first; })) { @@ -417,6 +425,23 @@ int32_t InputMethodAbility::ShowPanelKeyboard() return ret; } +int32_t InputMethodAbility::HidePanelSoftKeyboard() +{ + auto result = panels_.Find(SOFT_KEYBOARD); + if (!result.first) { + IMSA_HILOGE("Not find SOFT_KEYBOARD panel."); + return ErrorCode::NO_ERROR; + } + auto panel = result.second; + if (panel->GetPanelFlag() == PanelFlag::FLG_CANDIDATE_COLUMN) { + IMSA_HILOGD("panel flag is candidate, not need to hide."); + return ErrorCode::NO_ERROR; + } + auto ret = panel->HidePanel(); + IMSA_HILOGD("Hide panel, ret = %{public}d.", ret); + return ret; +} + void InputMethodAbility::NotifyAllTextConfig() { TextTotalConfig textConfig = {}; @@ -476,19 +501,7 @@ int32_t InputMethodAbility::HideKeyboard() return ErrorCode::ERROR_CLIENT_NULL_POINTER; } channel->SendKeyboardStatus(KEYBOARD_HIDE); - auto result = panels_.Find(SOFT_KEYBOARD); - if (!result.first) { - IMSA_HILOGE("Not find SOFT_KEYBOARD panel."); - return ErrorCode::NO_ERROR; - } - auto panel = result.second; - if (panel->GetPanelFlag() == PanelFlag::FLG_CANDIDATE_COLUMN) { - IMSA_HILOGD("panel flag is candidate, not need to hide."); - return ErrorCode::NO_ERROR; - } - auto ret = panel->HidePanel(); - IMSA_HILOGD("Hide panel, ret = %{public}d.", ret); - return ret; + return HidePanelSoftKeyboard(); } int32_t InputMethodAbility::InsertText(const std::string text) @@ -538,16 +551,21 @@ int32_t InputMethodAbility::HideKeyboardSelf() { auto channel = GetInputDataChannelProxy(); if (channel == nullptr) { - IMSA_HILOGE("InputMethodAbility::channel is nullptr"); + IMSA_HILOGE("channel is nullptr"); return ErrorCode::ERROR_CLIENT_NULL_POINTER; } + if (imeListener_ == nullptr) { + IMSA_HILOGE("imeListener_ is nullptr"); + return ErrorCode::NO_ERROR; + } + imeListener_->OnKeyboardStatus(false); // todo 是否需要处理panel + channel->SendKeyboardStatus(KEYBOARD_HIDE); auto controlChannel = GetInputControlChannel(); - if (controlChannel == nullptr) { - IMSA_HILOGE("InputMethodAbility::controlChannel is nullptr"); - return ErrorCode::ERROR_CLIENT_NULL_POINTER; + if (controlChannel != nullptr) { + controlChannel->HideKeyboardSelf(); } InputMethodSysEvent::GetInstance().OperateSoftkeyboardBehaviour(OperateIMEInfoCode::IME_HIDE_SELF); - return controlChannel->HideKeyboardSelf(); + return ErrorCode::NO_ERROR; } int32_t InputMethodAbility::SendExtendAction(int32_t action) @@ -770,6 +788,59 @@ int32_t InputMethodAbility::DestroyPanel(const std::shared_ptr return ret; } +int32_t InputMethodAbility::ShowPanel(const std::shared_ptr &inputMethodPanel) +{ + if (inputMethodPanel == nullptr) { + return ErrorCode::ERROR_BAD_PARAMETERS; + } + auto channel = GetInputDataChannelProxy(); + if (channel == nullptr) { + IMSA_HILOGE("channel is nullptr"); + return ErrorCode::ERROR_CLIENT_NULL_POINTER; + } + auto type = inputMethodPanel->GetPanelType(); + IMSA_HILOGI("InputMethodAbility::type: %{public}d.", type); + if (type == PanelType::SOFT_KEYBOARD && !hasAlphaKeyboard_) { + return ErrorCode::NO_ERROR; + } + return inputMethodPanel->ShowPanel(); +} + +int32_t InputMethodAbility::HidePanel(const std::shared_ptr &inputMethodPanel) +{ + if (inputMethodPanel == nullptr) { + return ErrorCode::ERROR_BAD_PARAMETERS; + } + auto type = inputMethodPanel->GetPanelType(); + IMSA_HILOGI("InputMethodAbility::type: %{public}d.", type); + if (type == PanelType::SOFT_KEYBOARD && !hasAlphaKeyboard_) { + return HidePanelSoftKeyBoard(inputMethodPanel); + } + return inputMethodPanel->HidePanel(); +} + +int32_t InputMethodAbility::HidePanelSoftKeyBoard(const std::shared_ptr &inputMethodPanel) +{ + if (inputMethodPanel == nullptr) { + return ErrorCode::ERROR_BAD_PARAMETERS; + } + auto channel = GetInputDataChannelProxy(); + if (channel == nullptr) { + IMSA_HILOGE("channel is nullptr"); + return ErrorCode::ERROR_CLIENT_NULL_POINTER; + } + auto ret = inputMethodPanel->HidePanel(); + if (ret != ErrorCode::NO_ERROR) { + return ret; + } + channel->SendKeyboardStatus(KEYBOARD_HIDE); + auto controlChannel = GetInputControlChannel(); + if (controlChannel != nullptr) { + controlChannel->HideKeyboardSelf(); + } + return ErrorCode::NO_ERROR; +} + bool InputMethodAbility::IsCurrentIme() { IMSA_HILOGD("InputMethodAbility, in"); @@ -799,5 +870,10 @@ int32_t InputMethodAbility::ExitCurrentInputType() } return proxy->ExitCurrentInputType(); } + +void InputMethodAbility::UpdateAlphaKeyboardFlag(bool hasAlphaKeyboard) +{ + hasAlphaKeyboard_ = hasAlphaKeyboard; +} } // namespace MiscServices } // namespace OHOS diff --git a/interfaces/inner_api/inputmethod_ability/BUILD.gn b/interfaces/inner_api/inputmethod_ability/BUILD.gn index ca3d3f5d..3feb82c3 100644 --- a/interfaces/inner_api/inputmethod_ability/BUILD.gn +++ b/interfaces/inner_api/inputmethod_ability/BUILD.gn @@ -79,7 +79,10 @@ ohos_shared_library("inputmethod_ability") { "window_manager:libwm", ] - deps = [ "${inputmethod_path}/services/dfx:inputmethod_dfx_static" ] + deps = [ + "${inputmethod_path}/services/dfx:inputmethod_dfx_static", + "${inputmethod_path}/frameworks/native/inputmethod_ability/adapter/input_dev_monitor:input_dev_monitor", + ] public_configs = [ ":inputmethod_ability_native_public_config" ] diff --git a/services/include/peruser_session.h b/services/include/peruser_session.h index e365f80d..1f075cb4 100644 --- a/services/include/peruser_session.h +++ b/services/include/peruser_session.h @@ -74,6 +74,7 @@ public: int32_t OnShowCurrentInput(); int32_t OnShowInput(sptr client); int32_t OnHideInput(sptr client); + void OnHideSoftKeyBoardSelf(); void StopInputService(); void NotifyImeChangeToClients(const Property &property, const SubProperty &subProperty); int32_t SwitchSubtype(const SubProperty &subProperty); diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index 226b8b3e..32918aa5 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -655,7 +655,7 @@ void InputMethodSystemAbility::WorkThread() break; } case MSG_ID_HIDE_KEYBOARD_SELF: { - userSession_->OnHideCurrentInput(); + userSession_->OnHideSoftKeyBoardSelf(); break; } default: { diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index 94350e5c..7b21577f 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -294,6 +294,18 @@ int32_t PerUserSession::OnShowInput(sptr client) return ShowKeyboard(client); } +void PerUserSession::OnHideSoftKeyBoardSelf() +{ + IMSA_HILOGD("run in"); + sptr client = GetCurrentClient(); + if (client == nullptr) { + IMSA_HILOGE("current client is nullptr"); + return; + } + bool isShowKeyboard = false; + UpdateClientInfo(client->AsObject(), { UpdateFlag::ISSHOWKEYBOARD, isShowKeyboard }); +} + /** Get ClientInfo * @param inputClient the IRemoteObject remote handler of given input client * @return a pointer of ClientInfo if client is found -- Gitee From 72307f91c1871364165d313b3b9a7f2df2420019 Mon Sep 17 00:00:00 2001 From: cy7717 Date: Tue, 24 Oct 2023 21:04:11 +0800 Subject: [PATCH 2/6] mod Signed-off-by: cy7717 --- .../js/napi/inputmethodability/js_panel.cpp | 4 +- .../include/input_dev_monitor.h | 1 + .../src/input_dev_monitor.cpp | 10 +- .../include/input_method_ability.h | 13 +- .../src/input_method_ability.cpp | 206 ++++++++++-------- .../include/i_input_data_channel.h | 2 + .../include/input_data_channel_proxy.h | 1 + .../include/input_data_channel_stub.h | 3 + .../include/input_method_utils.h | 17 +- .../src/input_data_channel_proxy.cpp | 6 + .../src/input_data_channel_stub.cpp | 25 +++ .../src/input_method_controller.cpp | 14 ++ .../include/input_method_controller.h | 13 ++ services/src/peruser_session.cpp | 2 +- 14 files changed, 212 insertions(+), 105 deletions(-) diff --git a/frameworks/js/napi/inputmethodability/js_panel.cpp b/frameworks/js/napi/inputmethodability/js_panel.cpp index bfde1584..59438473 100644 --- a/frameworks/js/napi/inputmethodability/js_panel.cpp +++ b/frameworks/js/napi/inputmethodability/js_panel.cpp @@ -200,7 +200,7 @@ napi_value JsPanel::Show(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(env, info); auto exec = [ctxt](AsyncCall::Context *ctx) { CHECK_RETURN_VOID(ctxt->inputMethodPanel != nullptr, "inputMethodPanel_ is nullptr."); - auto code = InputMethodAbility::GetInstance()->ShowPanelSelf(ctxt->inputMethodPanel); + auto code = InputMethodAbility::GetInstance()->ShowPanel(ctxt->inputMethodPanel); if (code == ErrorCode::NO_ERROR) { ctxt->SetState(napi_ok); return; @@ -217,7 +217,7 @@ napi_value JsPanel::Hide(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(env, info); auto exec = [ctxt](AsyncCall::Context *ctx) { CHECK_RETURN_VOID(ctxt->inputMethodPanel != nullptr, "inputMethodPanel_ is nullptr."); - auto code = InputMethodAbility::GetInstance()->HidePanelSelf(ctxt->inputMethodPanel); + auto code = InputMethodAbility::GetInstance()->HidePanel(ctxt->inputMethodPanel); if (code == ErrorCode::NO_ERROR) { ctxt->SetState(napi_ok); return; diff --git a/frameworks/native/inputmethod_ability/adapter/input_dev_monitor/include/input_dev_monitor.h b/frameworks/native/inputmethod_ability/adapter/input_dev_monitor/include/input_dev_monitor.h index 49c73e5e..f4f3d373 100644 --- a/frameworks/native/inputmethod_ability/adapter/input_dev_monitor/include/input_dev_monitor.h +++ b/frameworks/native/inputmethod_ability/adapter/input_dev_monitor/include/input_dev_monitor.h @@ -35,6 +35,7 @@ public: private: FocusHandle handler_; + int32_t deviceId_; }; private: diff --git a/frameworks/native/inputmethod_ability/adapter/input_dev_monitor/src/input_dev_monitor.cpp b/frameworks/native/inputmethod_ability/adapter/input_dev_monitor/src/input_dev_monitor.cpp index 289a0f66..33180757 100644 --- a/frameworks/native/inputmethod_ability/adapter/input_dev_monitor/src/input_dev_monitor.cpp +++ b/frameworks/native/inputmethod_ability/adapter/input_dev_monitor/src/input_dev_monitor.cpp @@ -42,9 +42,10 @@ void InputDevMonitor::InputDeviceListenerImpl::OnDeviceAdded(int32_t deviceId, c int32_t kbType = -1; auto ret = MMI::InputManager::GetInstance()->GetKeyboardType( deviceId, [&kbType](int32_t keyboardType) { kbType = keyboardType; }); - IMSA_HILOGD("ret: %{public}d.", ret); + IMSA_HILOGD("ret: %{public}d, kbType: %{public}d", ret, kbType); if (ret == 0 && kbType == KeyboardType::KEYBOARD_TYPE_ALPHABETICKEYBOARD) { handler_(true); + deviceId_ = deviceId; } } @@ -54,12 +55,9 @@ void InputDevMonitor::InputDeviceListenerImpl::OnDeviceRemoved(int32_t deviceId, if (type != "remove") { return; } - int32_t kbType = -1; - auto ret = MMI::InputManager::GetInstance()->GetKeyboardType( - deviceId, [&kbType](int32_t keyboardType) { kbType = keyboardType; }); - IMSA_HILOGD("ret: %{public}d.", ret); - if (ret == 0 && kbType == KeyboardType::KEYBOARD_TYPE_ALPHABETICKEYBOARD) { + if (deviceId == deviceId_) { handler_(false); + deviceId_ = -1; } } } // namespace MiscServices diff --git a/frameworks/native/inputmethod_ability/include/input_method_ability.h b/frameworks/native/inputmethod_ability/include/input_method_ability.h index a35e7a53..defc2096 100644 --- a/frameworks/native/inputmethod_ability/include/input_method_ability.h +++ b/frameworks/native/inputmethod_ability/include/input_method_ability.h @@ -123,11 +123,16 @@ private: void OnSelectionChange(Message *msg); void OnConfigurationChange(Message *msg); void OnTextConfigChange(const TextTotalConfig &textConfig); - int32_t ShowPanelSoftKeyboard(); - int32_t HidePanelSoftKeyboard(); - int32_t HidePanelSoftKeyBoard(const std::shared_ptr &inputMethodPanel); + + std::shared_ptr GetSoftKeyboardPanel(); + int32_t ShowPanel(const std::shared_ptr &inputMethodPanel, bool isByIme); + int32_t HidePanel(const std::shared_ptr &inputMethodPanel, bool isByIme); + PanelState GetPanelState( + const std::shared_ptr &inputMethodPanel, bool isShow, bool isByIme); + void NotifyPanelState(const PanelState &state); + void UpdateAlphaKeyboardFlag(bool hasAlphaKeyboard); - bool hasAlphaKeyboard_{ false }; + std::atomic_bool hasAlphaKeyboard_{ false }; ConcurrentMap> panels_{}; std::atomic_bool isPanelKeyboard_{ false }; std::atomic_bool isBound_{ false }; diff --git a/frameworks/native/inputmethod_ability/src/input_method_ability.cpp b/frameworks/native/inputmethod_ability/src/input_method_ability.cpp index 45fdf12f..35b3be26 100644 --- a/frameworks/native/inputmethod_ability/src/input_method_ability.cpp +++ b/frameworks/native/inputmethod_ability/src/input_method_ability.cpp @@ -385,61 +385,46 @@ int32_t InputMethodAbility::ShowKeyboard() return ErrorCode::ERROR_IME; } imeListener_->OnKeyboardStatus(true); + if (isPanelKeyboard_.load()) { - auto ret = ShowPanelSoftKeyboard(); - if (ret != ErrorCode::NO_ERROR) { - return ret; + auto panel = GetSoftKeyboardPanel(); + if (panel == nullptr) { + return ErrorCode::ERROR_IME; + } + if (panel->GetPanelFlag() == FLG_CANDIDATE_COLUMN) { + return ErrorCode::NO_ERROR; + } + return ShowPanel(panel, false); + } else { + if (!hasAlphaKeyboard_.load()) { + NotifyPanelState(PanelState::FIXED_SOFT_KEYBOARD_SHOW); } } - auto channel = GetInputDataChannelProxy(); - if (channel == nullptr) { - IMSA_HILOGE("channel is nullptr"); - return ErrorCode::ERROR_CLIENT_NULL_POINTER; - } - channel->SendKeyboardStatus(KEYBOARD_SHOW); return ErrorCode::NO_ERROR; } -int32_t InputMethodAbility::ShowPanelSoftKeyboard() -{ - if (!BlockRetry(FIND_PANEL_RETRY_INTERVAL, MAX_RETRY_TIMES, - [this]() -> bool { return panels_.Find(SOFT_KEYBOARD).first; })) { - IMSA_HILOGE("SOFT_KEYBOARD panel not found"); - return ErrorCode::ERROR_OPERATE_PANEL; - } - auto result = panels_.Find(SOFT_KEYBOARD); - if (!result.first) { - IMSA_HILOGE("SOFT_KEYBOARD panel not found"); - return ErrorCode::ERROR_OPERATE_PANEL; - } - IMSA_HILOGI("find SOFT_KEYBOARD panel."); - auto panel = result.second; - if (panel->GetPanelFlag() == PanelFlag::FLG_CANDIDATE_COLUMN) { - IMSA_HILOGD("panel flag is candidate, not need to show."); - return ErrorCode::NO_ERROR; - } - auto ret = panel->ShowPanel(); - if (ret != ErrorCode::NO_ERROR) { - IMSA_HILOGE("Show panel failed, ret = %{public}d.", ret); - } - return ret; -} - -int32_t InputMethodAbility::HidePanelSoftKeyboard() +void InputMethodAbility::NotifyPanelState(const PanelState &state) { - auto result = panels_.Find(SOFT_KEYBOARD); - if (!result.first) { - IMSA_HILOGE("Not find SOFT_KEYBOARD panel."); - return ErrorCode::NO_ERROR; + auto channel = GetInputDataChannelProxy(); + if (channel != nullptr) { + channel->SendPanelState(state); + if (state == PanelState::FIXED_SOFT_KEYBOARD_HIDE + || state == PanelState::FIXED_SOFT_KEYBOARD_HIDE_BY_IME) { + channel->SendKeyboardStatus(KEYBOARD_HIDE); + } + if (state == PanelState::FIXED_SOFT_KEYBOARD_SHOW + || state == PanelState::FIXED_SOFT_KEYBOARD_SHOW_BY_IME) { + channel->SendKeyboardStatus(KEYBOARD_SHOW); + } } - auto panel = result.second; - if (panel->GetPanelFlag() == PanelFlag::FLG_CANDIDATE_COLUMN) { - IMSA_HILOGD("panel flag is candidate, not need to hide."); - return ErrorCode::NO_ERROR; + if ((state == PanelState::FIXED_SOFT_KEYBOARD_HIDE_BY_IME + || state == PanelState::FLOATING_SOFT_KEYBOARD_HIDE_BY_IME) + && !hasAlphaKeyboard_.load()) { + auto controlChannel = GetInputControlChannel(); + if (controlChannel != nullptr) { + controlChannel->HideKeyboardSelf(); + } } - auto ret = panel->HidePanel(); - IMSA_HILOGD("Hide panel, ret = %{public}d.", ret); - return ret; } void InputMethodAbility::NotifyAllTextConfig() @@ -495,13 +480,22 @@ int32_t InputMethodAbility::HideKeyboard() return ErrorCode::ERROR_IME; } imeListener_->OnKeyboardStatus(false); - auto channel = GetInputDataChannelProxy(); - if (channel == nullptr) { - IMSA_HILOGE("InputMethodAbility::HideKeyboard channel is nullptr"); - return ErrorCode::ERROR_CLIENT_NULL_POINTER; + + if (isPanelKeyboard_.load()) { + auto panel = GetSoftKeyboardPanel(); + if (panel == nullptr) { + return ErrorCode::ERROR_IME; + } + if (panel->GetPanelFlag() == FLG_CANDIDATE_COLUMN) { + return ErrorCode::NO_ERROR; + } + return HidePanel(panel, false); + } else { + if (!hasAlphaKeyboard_.load()) { + NotifyPanelState(PanelState::FIXED_SOFT_KEYBOARD_HIDE); + } } - channel->SendKeyboardStatus(KEYBOARD_HIDE); - return HidePanelSoftKeyboard(); + return ErrorCode::NO_ERROR; } int32_t InputMethodAbility::InsertText(const std::string text) @@ -558,12 +552,8 @@ int32_t InputMethodAbility::HideKeyboardSelf() IMSA_HILOGE("imeListener_ is nullptr"); return ErrorCode::NO_ERROR; } - imeListener_->OnKeyboardStatus(false); // todo 是否需要处理panel - channel->SendKeyboardStatus(KEYBOARD_HIDE); - auto controlChannel = GetInputControlChannel(); - if (controlChannel != nullptr) { - controlChannel->HideKeyboardSelf(); - } + imeListener_->OnKeyboardStatus(false); + NotifyPanelState(PanelState::FIXED_SOFT_KEYBOARD_HIDE_BY_IME); InputMethodSysEvent::GetInstance().OperateSoftkeyboardBehaviour(OperateIMEInfoCode::IME_HIDE_SELF); return ErrorCode::NO_ERROR; } @@ -790,36 +780,15 @@ int32_t InputMethodAbility::DestroyPanel(const std::shared_ptr int32_t InputMethodAbility::ShowPanel(const std::shared_ptr &inputMethodPanel) { - if (inputMethodPanel == nullptr) { - return ErrorCode::ERROR_BAD_PARAMETERS; - } - auto channel = GetInputDataChannelProxy(); - if (channel == nullptr) { - IMSA_HILOGE("channel is nullptr"); - return ErrorCode::ERROR_CLIENT_NULL_POINTER; - } - auto type = inputMethodPanel->GetPanelType(); - IMSA_HILOGI("InputMethodAbility::type: %{public}d.", type); - if (type == PanelType::SOFT_KEYBOARD && !hasAlphaKeyboard_) { - return ErrorCode::NO_ERROR; - } - return inputMethodPanel->ShowPanel(); + return ShowPanel(inputMethodPanel, true); } int32_t InputMethodAbility::HidePanel(const std::shared_ptr &inputMethodPanel) { - if (inputMethodPanel == nullptr) { - return ErrorCode::ERROR_BAD_PARAMETERS; - } - auto type = inputMethodPanel->GetPanelType(); - IMSA_HILOGI("InputMethodAbility::type: %{public}d.", type); - if (type == PanelType::SOFT_KEYBOARD && !hasAlphaKeyboard_) { - return HidePanelSoftKeyBoard(inputMethodPanel); - } - return inputMethodPanel->HidePanel(); + return HidePanel(inputMethodPanel, true); } -int32_t InputMethodAbility::HidePanelSoftKeyBoard(const std::shared_ptr &inputMethodPanel) +int32_t InputMethodAbility::ShowPanel(const std::shared_ptr &inputMethodPanel, bool isByIme) { if (inputMethodPanel == nullptr) { return ErrorCode::ERROR_BAD_PARAMETERS; @@ -829,16 +798,25 @@ int32_t InputMethodAbility::HidePanelSoftKeyBoard(const std::shared_ptrHidePanel(); - if (ret != ErrorCode::NO_ERROR) { - return ret; + auto ret = inputMethodPanel->ShowPanel(); + if (ret == ErrorCode::NO_ERROR) { + auto state = GetPanelState(inputMethodPanel, true, isByIme); + NotifyPanelState(state); } - channel->SendKeyboardStatus(KEYBOARD_HIDE); - auto controlChannel = GetInputControlChannel(); - if (controlChannel != nullptr) { - controlChannel->HideKeyboardSelf(); + return ret; +} + +int32_t InputMethodAbility::HidePanel(const std::shared_ptr &inputMethodPanel, bool isByIme) +{ + if (inputMethodPanel == nullptr) { + return ErrorCode::ERROR_BAD_PARAMETERS; } - return ErrorCode::NO_ERROR; + auto ret = inputMethodPanel->HidePanel(); + if (ret == ErrorCode::NO_ERROR) { + auto state = GetPanelState(inputMethodPanel, false, isByIme); + NotifyPanelState(state); + } + return ret; } bool InputMethodAbility::IsCurrentIme() @@ -873,7 +851,53 @@ int32_t InputMethodAbility::ExitCurrentInputType() void InputMethodAbility::UpdateAlphaKeyboardFlag(bool hasAlphaKeyboard) { - hasAlphaKeyboard_ = hasAlphaKeyboard; + IMSA_HILOGD("hasAlphaKeyboard: %{public}d.", hasAlphaKeyboard); + hasAlphaKeyboard_.store(hasAlphaKeyboard); +} + +PanelState InputMethodAbility::GetPanelState( + const std::shared_ptr &inputMethodPanel, bool isShow, bool isByIme) +{ + auto type = inputMethodPanel->GetPanelType(); + auto flag = inputMethodPanel->GetPanelFlag(); + if (type == PanelType::SOFT_KEYBOARD && flag == FLG_FIXED && !isByIme) { + return isShow ? PanelState::FIXED_SOFT_KEYBOARD_SHOW : PanelState::FIXED_SOFT_KEYBOARD_HIDE; + } + if (type == PanelType::SOFT_KEYBOARD && flag == FLG_FLOATING && !isByIme) { + return isShow ? PanelState::FLOATING_SOFT_KEYBOARD_SHOW + : PanelState::FLOATING_SOFT_KEYBOARD_HIDE; + } + if (type == PanelType::SOFT_KEYBOARD && flag == FLG_FIXED && isByIme) { + return isShow ? PanelState::FIXED_SOFT_KEYBOARD_SHOW_BY_IME + : PanelState::FIXED_SOFT_KEYBOARD_HIDE_BY_IME; + } + if (type == PanelType::SOFT_KEYBOARD && flag == FLG_FLOATING && isByIme) { + return isShow ? PanelState::FLOATING_SOFT_KEYBOARD_SHOW_BY_IME + : PanelState::FLOATING_SOFT_KEYBOARD_HIDE_BY_IME; + } + if (type == PanelType::SOFT_KEYBOARD && flag == FLG_CANDIDATE_COLUMN) { + return isShow ? PanelState::CANDIDATE_COLUMN_SHOW_BY_IME + : PanelState::CANDIDATE_COLUMN_HIDE_BY_IME; + } + if (type == PanelType::STATUS_BAR) { + return isShow ? PanelState::STATUS_BAR_SHOW_BY_IME : PanelState::STATUS_BAR_HIDE_BY_IME; + } + return PanelState::NONE; +} + +std::shared_ptr InputMethodAbility::GetSoftKeyboardPanel() +{ + if (!BlockRetry(FIND_PANEL_RETRY_INTERVAL, MAX_RETRY_TIMES, + [this]() -> bool { return panels_.Find(SOFT_KEYBOARD).first; })) { + IMSA_HILOGE("SOFT_KEYBOARD panel not found"); + return nullptr; + } + auto result = panels_.Find(SOFT_KEYBOARD); + if (!result.first) { + IMSA_HILOGE("SOFT_KEYBOARD panel not found"); + return nullptr; + } + return result.second; } } // namespace MiscServices } // namespace OHOS diff --git a/frameworks/native/inputmethod_controller/include/i_input_data_channel.h b/frameworks/native/inputmethod_controller/include/i_input_data_channel.h index 539e888c..b54caece 100644 --- a/frameworks/native/inputmethod_controller/include/i_input_data_channel.h +++ b/frameworks/native/inputmethod_controller/include/i_input_data_channel.h @@ -45,6 +45,7 @@ public: HANDLE_EXTEND_ACTION, GET_TEXT_INDEX_AT_CURSOR, GET_TEXT_CONFIG, + SEND_PANEL_STATE, DATA_CHANNEL_CMD_LAST }; @@ -65,6 +66,7 @@ public: virtual int32_t SelectByMovement(int32_t direction, int32_t cursorMoveSkip) = 0; virtual int32_t HandleExtendAction(int32_t action) = 0; virtual int32_t GetTextIndexAtCursor(int32_t &index) = 0; + virtual void SendPanelState(const PanelState &state) = 0; }; } // namespace MiscServices } // namespace OHOS diff --git a/frameworks/native/inputmethod_controller/include/input_data_channel_proxy.h b/frameworks/native/inputmethod_controller/include/input_data_channel_proxy.h index 000e5c96..662a88dc 100644 --- a/frameworks/native/inputmethod_controller/include/input_data_channel_proxy.h +++ b/frameworks/native/inputmethod_controller/include/input_data_channel_proxy.h @@ -50,6 +50,7 @@ public: int32_t HandleExtendAction(int32_t action) override; int32_t GetTextIndexAtCursor(int32_t &index) override; int32_t GetTextConfig(TextTotalConfig &textConfig) override; + void SendPanelState(const PanelState &state) override; private: static inline BrokerDelegator delegator_; diff --git a/frameworks/native/inputmethod_controller/include/input_data_channel_stub.h b/frameworks/native/inputmethod_controller/include/input_data_channel_stub.h index 396f52ef..7a753c20 100644 --- a/frameworks/native/inputmethod_controller/include/input_data_channel_stub.h +++ b/frameworks/native/inputmethod_controller/include/input_data_channel_stub.h @@ -52,6 +52,7 @@ public: int32_t SelectByMovement(int32_t direction, int32_t cursorMoveSkip) override; int32_t HandleExtendAction(int32_t action) override; int32_t GetTextConfig(TextTotalConfig &textConfig) override; + void SendPanelState(const PanelState &state) override; private: template struct ResultInfo { @@ -74,6 +75,7 @@ private: int32_t SelectByMovementOnRemote(MessageParcel &data, MessageParcel &reply); int32_t HandleExtendActionOnRemote(MessageParcel &data, MessageParcel &reply); int32_t GetTextIndexAtCursorOnRemote(MessageParcel &data, MessageParcel &reply); + int32_t SendPanelStateOnRemote(MessageParcel &data, MessageParcel &reply); using RequestHandler = int32_t (InputDataChannelStub::*)(MessageParcel &, MessageParcel &); static inline const std::unordered_map HANDLERS = { { static_cast(INSERT_TEXT), &InputDataChannelStub::InsertTextOnRemote }, @@ -91,6 +93,7 @@ private: { static_cast(HANDLE_EXTEND_ACTION), &InputDataChannelStub::HandleExtendActionOnRemote }, { static_cast(GET_TEXT_INDEX_AT_CURSOR), &InputDataChannelStub::GetTextIndexAtCursorOnRemote }, { static_cast(GET_TEXT_CONFIG), &InputDataChannelStub::GetTextConfigOnRemote }, + { static_cast(SEND_PANEL_STATE), &InputDataChannelStub::SendPanelStateOnRemote }, }; }; } // namespace MiscServices diff --git a/frameworks/native/inputmethod_controller/include/input_method_utils.h b/frameworks/native/inputmethod_controller/include/input_method_utils.h index d1fb3e58..ce681c61 100644 --- a/frameworks/native/inputmethod_controller/include/input_method_utils.h +++ b/frameworks/native/inputmethod_controller/include/input_method_utils.h @@ -95,7 +95,22 @@ struct CursorInfo { class KeyEvent { }; -enum class KeyboardStatus { NONE = 0, HIDE, SHOW }; +enum class KeyboardStatus { NONE = 0, HIDE, SHOW }; // soft keyboard +enum class PanelState : int32_t { // all panel state + FIXED_SOFT_KEYBOARD_SHOW, + FIXED_SOFT_KEYBOARD_HIDE, + FLOATING_SOFT_KEYBOARD_SHOW, + FLOATING_SOFT_KEYBOARD_HIDE, + FIXED_SOFT_KEYBOARD_SHOW_BY_IME, + FIXED_SOFT_KEYBOARD_HIDE_BY_IME, + FLOATING_SOFT_KEYBOARD_SHOW_BY_IME, + FLOATING_SOFT_KEYBOARD_HIDE_BY_IME, + CANDIDATE_COLUMN_SHOW_BY_IME, + CANDIDATE_COLUMN_HIDE_BY_IME, + STATUS_BAR_SHOW_BY_IME, + STATUS_BAR_HIDE_BY_IME, + NONE +}; class FunctionKey { public: diff --git a/frameworks/native/inputmethod_controller/src/input_data_channel_proxy.cpp b/frameworks/native/inputmethod_controller/src/input_data_channel_proxy.cpp index dbcb92a6..e07098c2 100644 --- a/frameworks/native/inputmethod_controller/src/input_data_channel_proxy.cpp +++ b/frameworks/native/inputmethod_controller/src/input_data_channel_proxy.cpp @@ -67,6 +67,12 @@ void InputDataChannelProxy::SendKeyboardStatus(int32_t status) SEND_KEYBOARD_STATUS, [status](MessageParcel &parcel) { return ITypesUtil::Marshal(parcel, status); }); } +void InputDataChannelProxy::SendPanelState(const PanelState &state) +{ + SendRequest(SEND_KEYBOARD_STATUS, + [state](MessageParcel &parcel) { return ITypesUtil::Marshal(parcel, static_cast(state)); }); +} + int32_t InputDataChannelProxy::SendFunctionKey(int32_t funcKey) { return SendRequest( diff --git a/frameworks/native/inputmethod_controller/src/input_data_channel_stub.cpp b/frameworks/native/inputmethod_controller/src/input_data_channel_stub.cpp index e64327bd..06f63d2c 100644 --- a/frameworks/native/inputmethod_controller/src/input_data_channel_stub.cpp +++ b/frameworks/native/inputmethod_controller/src/input_data_channel_stub.cpp @@ -196,6 +196,17 @@ int32_t InputDataChannelStub::GetTextIndexAtCursorOnRemote(MessageParcel &data, : ErrorCode::ERROR_EX_PARCELABLE; } +int32_t InputDataChannelStub::SendPanelStateOnRemote(MessageParcel &data, MessageParcel &reply) +{ + int32_t status = 0; + if (!ITypesUtil::Unmarshal(data, status)) { + IMSA_HILOGE("failed to read message parcel"); + return ErrorCode::ERROR_EX_PARCELABLE; + } + SendPanelState(static_cast(status)); + return reply.WriteInt32(ErrorCode::NO_ERROR) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE; +} + int32_t InputDataChannelStub::InsertText(const std::u16string &text) { auto result = std::make_shared>(MAX_TIMEOUT); @@ -448,5 +459,19 @@ int32_t InputDataChannelStub::HandleExtendAction(int32_t action) } return ret; } + +void InputDataChannelStub::SendPanelState(const PanelState &state) +{ + auto result = std::make_shared>(MAX_TIMEOUT, false); + auto blockTask = [state, result]() { + InputMethodController::GetInstance()->SendPanelState(state); + bool ret = true; + result->SetValue(ret); + }; + ffrt::submit(blockTask); + if (!result->GetValue()) { + IMSA_HILOGE("failed due to timeout"); + } +} } // namespace MiscServices } // namespace OHOS diff --git a/frameworks/native/inputmethod_controller/src/input_method_controller.cpp b/frameworks/native/inputmethod_controller/src/input_method_controller.cpp index 033cb336..48d68b57 100644 --- a/frameworks/native/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/native/inputmethod_controller/src/input_method_controller.cpp @@ -1003,6 +1003,20 @@ void InputMethodController::SendKeyboardStatus(int32_t status) } } +void InputMethodController::SendPanelState(const PanelState &state) +{ + IMSA_HILOGD("run in, status: %{public}d", state); + auto listener = GetTextListener(); + if (listener == nullptr) { + IMSA_HILOGE("textListener_ is nullptr"); + return; + } + listener->SendPanelState(state); +// if (keyboardStatus == KeyboardStatus::HIDE) { +// clientInfo_.isShowKeyboard = false; // todo 更新clientInfo_.isShowKeyboard +// } +} + int32_t InputMethodController::SendFunctionKey(int32_t functionKey) { auto listener = GetTextListener(); diff --git a/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h b/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h index 1ed32cca..65a3957d 100644 --- a/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h +++ b/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h @@ -47,6 +47,9 @@ public: virtual void DeleteBackward(int32_t length) = 0; virtual void SendKeyEventFromInputMethod(const KeyEvent &event) = 0; virtual void SendKeyboardStatus(const KeyboardStatus &keyboardStatus) = 0; + virtual void SendPanelState(const PanelState &state) + { + } virtual void SendFunctionKey(const FunctionKey &functionKey) = 0; virtual void SetKeyboardStatus(bool status) = 0; virtual void MoveCursor(const Direction direction) = 0; @@ -562,6 +565,16 @@ public: */ IMF_API void SendKeyboardStatus(int32_t status); + /** + * @brief Send panel state. + * + * This function is used to send panel state to editor. + * + * @param status Indicates the state of panel. + * @since 10 + */ + IMF_API void SendPanelState(const PanelState &state); + /** * @brief Send function key. * diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index 7b21577f..6c498ed8 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -303,7 +303,7 @@ void PerUserSession::OnHideSoftKeyBoardSelf() return; } bool isShowKeyboard = false; - UpdateClientInfo(client->AsObject(), { UpdateFlag::ISSHOWKEYBOARD, isShowKeyboard }); + UpdateClientInfo(client->AsObject(), { { UpdateFlag::ISSHOWKEYBOARD, isShowKeyboard } }); } /** Get ClientInfo -- Gitee From 13a113ce2a018ace0c9a5d976151994cf4c33ab9 Mon Sep 17 00:00:00 2001 From: cy7717 Date: Wed, 25 Oct 2023 11:53:53 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=96=E6=8E=A5?= =?UTF-8?q?=E9=94=AE=E7=9B=98=E7=9A=84=E7=9B=91=E5=90=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cy7717 --- .../adapter/input_dev_monitor/BUILD.gn | 48 ------- .../include/input_dev_monitor.h | 47 ------- .../src/input_dev_monitor.cpp | 64 ---------- .../include/input_method_ability.h | 10 +- .../include/input_method_panel.h | 17 +-- .../inputmethod_ability/include/panel_info.h | 39 ++++++ .../src/input_method_ability.cpp | 118 ++++++------------ .../include/i_input_data_channel.h | 4 +- .../include/input_data_channel_proxy.h | 2 +- .../include/input_data_channel_stub.h | 6 +- .../include/input_method_utils.h | 21 ++-- .../include/itypes_util.h | 3 + .../src/input_data_channel_proxy.cpp | 5 +- .../src/input_data_channel_stub.cpp | 14 +-- .../src/input_method_controller.cpp | 13 +- .../src/itypes_util.cpp | 19 +++ .../inner_api/inputmethod_ability/BUILD.gn | 5 +- .../include/input_method_controller.h | 13 +- 18 files changed, 139 insertions(+), 309 deletions(-) delete mode 100644 frameworks/native/inputmethod_ability/adapter/input_dev_monitor/BUILD.gn delete mode 100644 frameworks/native/inputmethod_ability/adapter/input_dev_monitor/include/input_dev_monitor.h delete mode 100644 frameworks/native/inputmethod_ability/adapter/input_dev_monitor/src/input_dev_monitor.cpp create mode 100644 frameworks/native/inputmethod_ability/include/panel_info.h diff --git a/frameworks/native/inputmethod_ability/adapter/input_dev_monitor/BUILD.gn b/frameworks/native/inputmethod_ability/adapter/input_dev_monitor/BUILD.gn deleted file mode 100644 index 61ee2a37..00000000 --- a/frameworks/native/inputmethod_ability/adapter/input_dev_monitor/BUILD.gn +++ /dev/null @@ -1,48 +0,0 @@ -# Copyright (C) 2023 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//base/inputmethod/imf/inputmethod.gni") -import("//build/ohos.gni") - -config("input_dev_monitor_config") { - visibility = [ ":*" ] - include_dirs = [ "include" ] - ldflags = [ "-Wl,--exclude-libs=ALL" ] - cflags = [ - "-fdata-sections", - "-ffunction-sections", - "-fvisibility=hidden", - ] -} - -config("input_dev_monitor_public_config") { - visibility = [ "./*" ] - include_dirs = [ - "include", - "${inputmethod_path}/services/include", - "//foundation/multimodalinput/input/interfaces/native/innerkits/event/include", - ] -} - -ohos_static_library("input_dev_monitor") { - sources = [ "src/input_dev_monitor.cpp" ] - configs = [ ":input_dev_monitor_config" ] - public_configs = [ ":input_dev_monitor_public_config" ] - deps = [] - external_deps = [ - "input:libmmi-client", - "hilog:libhilog", - ] - subsystem_name = "inputmethod" - part_name = "imf" -} diff --git a/frameworks/native/inputmethod_ability/adapter/input_dev_monitor/include/input_dev_monitor.h b/frameworks/native/inputmethod_ability/adapter/input_dev_monitor/include/input_dev_monitor.h deleted file mode 100644 index f4f3d373..00000000 --- a/frameworks/native/inputmethod_ability/adapter/input_dev_monitor/include/input_dev_monitor.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef IMF_DEV_MONITOR_H -#define IMF_DEV_MONITOR_H -#include -#include - -#include "input_manager.h" -namespace OHOS { -namespace MiscServices { -class InputDevMonitor { -public: - using FocusHandle = std::function; - static InputDevMonitor &GetInstance(); - int32_t RegisterDevListener(const FocusHandle &handle); - class InputDeviceListenerImpl : public MMI::IInputDeviceListener { - public: - explicit InputDeviceListenerImpl(FocusHandle handler) : handler_(std::move(handler)){}; - virtual ~InputDeviceListenerImpl() = default; - void OnDeviceAdded(int32_t deviceId, const std::string &type) override; - void OnDeviceRemoved(int32_t deviceId, const std::string &type) override; - - private: - FocusHandle handler_; - int32_t deviceId_; - }; - -private: - InputDevMonitor() = default; -}; -} // namespace MiscServices -} // namespace OHOS - -#endif // IMF_DEV_MONITOR_H diff --git a/frameworks/native/inputmethod_ability/adapter/input_dev_monitor/src/input_dev_monitor.cpp b/frameworks/native/inputmethod_ability/adapter/input_dev_monitor/src/input_dev_monitor.cpp deleted file mode 100644 index 33180757..00000000 --- a/frameworks/native/inputmethod_ability/adapter/input_dev_monitor/src/input_dev_monitor.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "input_dev_monitor.h" - -#include "global.h" -#include "input_device.h" - -namespace OHOS { -namespace MiscServices { -using namespace MMI; -InputDevMonitor &InputDevMonitor::GetInstance() -{ - static InputDevMonitor monitor; - return monitor; -} - -int32_t InputDevMonitor::RegisterDevListener(const FocusHandle &handler) -{ - return MMI::InputManager::GetInstance()->RegisterDevListener( - "change", std::make_shared(handler)); -} - -void InputDevMonitor::InputDeviceListenerImpl::OnDeviceAdded(int32_t deviceId, const std::string &type) -{ - IMSA_HILOGD("deviceId: %{public}d, type: %{public}s.", deviceId, type.c_str()); - if (type != "add") { - return; - } - int32_t kbType = -1; - auto ret = MMI::InputManager::GetInstance()->GetKeyboardType( - deviceId, [&kbType](int32_t keyboardType) { kbType = keyboardType; }); - IMSA_HILOGD("ret: %{public}d, kbType: %{public}d", ret, kbType); - if (ret == 0 && kbType == KeyboardType::KEYBOARD_TYPE_ALPHABETICKEYBOARD) { - handler_(true); - deviceId_ = deviceId; - } -} - -void InputDevMonitor::InputDeviceListenerImpl::OnDeviceRemoved(int32_t deviceId, const std::string &type) -{ - IMSA_HILOGD("deviceId: %{public}d, type: %{public}s.", deviceId, type.c_str()); - if (type != "remove") { - return; - } - if (deviceId == deviceId_) { - handler_(false); - deviceId_ = -1; - } -} -} // namespace MiscServices -} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/inputmethod_ability/include/input_method_ability.h b/frameworks/native/inputmethod_ability/include/input_method_ability.h index defc2096..13ece8a8 100644 --- a/frameworks/native/inputmethod_ability/include/input_method_ability.h +++ b/frameworks/native/inputmethod_ability/include/input_method_ability.h @@ -125,14 +125,10 @@ private: void OnTextConfigChange(const TextTotalConfig &textConfig); std::shared_ptr GetSoftKeyboardPanel(); - int32_t ShowPanel(const std::shared_ptr &inputMethodPanel, bool isByIme); - int32_t HidePanel(const std::shared_ptr &inputMethodPanel, bool isByIme); - PanelState GetPanelState( - const std::shared_ptr &inputMethodPanel, bool isShow, bool isByIme); - void NotifyPanelState(const PanelState &state); + int32_t ShowPanel(const std::shared_ptr &inputMethodPanel, Trigger trigger); + int32_t HidePanel(const std::shared_ptr &inputMethodPanel, Trigger trigger); + void NotifyPanelStatusInfo(const PanelStatusInfo &info); - void UpdateAlphaKeyboardFlag(bool hasAlphaKeyboard); - std::atomic_bool hasAlphaKeyboard_{ false }; ConcurrentMap> panels_{}; std::atomic_bool isPanelKeyboard_{ false }; std::atomic_bool isBound_{ false }; diff --git a/frameworks/native/inputmethod_ability/include/input_method_panel.h b/frameworks/native/inputmethod_ability/include/input_method_panel.h index 3ba264d5..7def25ea 100644 --- a/frameworks/native/inputmethod_ability/include/input_method_panel.h +++ b/frameworks/native/inputmethod_ability/include/input_method_panel.h @@ -22,27 +22,12 @@ #include "input_window_info.h" #include "js_runtime_utils.h" +#include "panel_info.h" #include "panel_status_listener.h" #include "window.h" namespace OHOS { namespace MiscServices { -enum PanelType { - SOFT_KEYBOARD = 0, - STATUS_BAR, -}; - -enum PanelFlag { - FLG_FIXED = 0, - FLG_FLOATING, - FLG_CANDIDATE_COLUMN, -}; - -struct PanelInfo { - PanelType panelType = SOFT_KEYBOARD; - PanelFlag panelFlag = FLG_FIXED; -}; - class InputMethodPanel { public: InputMethodPanel() = default; diff --git a/frameworks/native/inputmethod_ability/include/panel_info.h b/frameworks/native/inputmethod_ability/include/panel_info.h new file mode 100644 index 00000000..f9938b6a --- /dev/null +++ b/frameworks/native/inputmethod_ability/include/panel_info.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef INPUT_METHOD_PANEL_INFO_H +#define INPUT_METHOD_PANEL_INFO_H + +namespace OHOS { +namespace MiscServices { +enum PanelType { + SOFT_KEYBOARD = 0, + STATUS_BAR, +}; + +enum PanelFlag { + FLG_FIXED = 0, + FLG_FLOATING, + FLG_CANDIDATE_COLUMN, +}; + +struct PanelInfo { + PanelType panelType = SOFT_KEYBOARD; + PanelFlag panelFlag = FLG_FIXED; +}; +} // namespace MiscServices +} // namespace OHOS + +#endif //INPUT_METHOD_PANEL_INFO_H diff --git a/frameworks/native/inputmethod_ability/src/input_method_ability.cpp b/frameworks/native/inputmethod_ability/src/input_method_ability.cpp index 35b3be26..8f60e392 100644 --- a/frameworks/native/inputmethod_ability/src/input_method_ability.cpp +++ b/frameworks/native/inputmethod_ability/src/input_method_ability.cpp @@ -20,7 +20,6 @@ #include #include "global.h" -#include "input_dev_monitor.h" #include "input_method_agent_proxy.h" #include "input_method_core_proxy.h" #include "input_method_utils.h" @@ -41,7 +40,6 @@ std::mutex InputMethodAbility::instanceLock_; constexpr double INVALID_CURSOR_VALUE = -1.0; constexpr int32_t INVALID_SELECTION_VALUE = -1; constexpr uint32_t FIND_PANEL_RETRY_INTERVAL = 10; -constexpr uint32_t REGISTER_DEV_LISTENER_RETRY_INTERVAL = 100; constexpr uint32_t MAX_RETRY_TIMES = 100; InputMethodAbility::InputMethodAbility() : msgHandler_(nullptr), stop_(false) { @@ -162,12 +160,6 @@ void InputMethodAbility::Initialize() coreStub_->SetMessageHandler(msgHandler_); agentStub_->SetMessageHandler(msgHandler_); workThreadHandler = std::thread([this] { WorkThread(); }); - - auto handler = [this](bool hasAlphaKeyboard) { UpdateAlphaKeyboardFlag(hasAlphaKeyboard); }; - if (!BlockRetry(REGISTER_DEV_LISTENER_RETRY_INTERVAL, MAX_RETRY_TIMES, - [handler]() -> bool { return InputDevMonitor::GetInstance().RegisterDevListener(handler) == 0; })) { - IMSA_HILOGE("register device listener failed."); - } } void InputMethodAbility::SetImeListener(std::shared_ptr imeListener) @@ -392,38 +384,34 @@ int32_t InputMethodAbility::ShowKeyboard() return ErrorCode::ERROR_IME; } if (panel->GetPanelFlag() == FLG_CANDIDATE_COLUMN) { + IMSA_HILOGD("panel flag is candidate, no need to show."); return ErrorCode::NO_ERROR; } - return ShowPanel(panel, false); - } else { - if (!hasAlphaKeyboard_.load()) { - NotifyPanelState(PanelState::FIXED_SOFT_KEYBOARD_SHOW); - } + return ShowPanel(panel, Trigger::IMF); + } + auto channel = GetInputDataChannelProxy(); + if (channel != nullptr) { + channel->SendKeyboardStatus(KEYBOARD_SHOW); } return ErrorCode::NO_ERROR; } -void InputMethodAbility::NotifyPanelState(const PanelState &state) +void InputMethodAbility::NotifyPanelStatusInfo(const PanelStatusInfo &info) { + // only notify the status info of soft keyboard(not contain candidate column) at present + if (info.panelInfo.panelType != PanelType::SOFT_KEYBOARD + || info.panelInfo.panelFlag == PanelFlag::FLG_CANDIDATE_COLUMN) { + return; + } auto channel = GetInputDataChannelProxy(); if (channel != nullptr) { - channel->SendPanelState(state); - if (state == PanelState::FIXED_SOFT_KEYBOARD_HIDE - || state == PanelState::FIXED_SOFT_KEYBOARD_HIDE_BY_IME) { - channel->SendKeyboardStatus(KEYBOARD_HIDE); - } - if (state == PanelState::FIXED_SOFT_KEYBOARD_SHOW - || state == PanelState::FIXED_SOFT_KEYBOARD_SHOW_BY_IME) { - channel->SendKeyboardStatus(KEYBOARD_SHOW); - } + info.visible ? channel->SendKeyboardStatus(KEYBOARD_SHOW) : channel->SendKeyboardStatus(KEYBOARD_HIDE); + channel->NotifyPanelStatusInfo(info); } - if ((state == PanelState::FIXED_SOFT_KEYBOARD_HIDE_BY_IME - || state == PanelState::FLOATING_SOFT_KEYBOARD_HIDE_BY_IME) - && !hasAlphaKeyboard_.load()) { - auto controlChannel = GetInputControlChannel(); - if (controlChannel != nullptr) { - controlChannel->HideKeyboardSelf(); - } + + auto controlChannel = GetInputControlChannel(); + if (controlChannel != nullptr && info.trigger == Trigger::IME_APP && !info.visible) { + controlChannel->HideKeyboardSelf(); } } @@ -487,13 +475,14 @@ int32_t InputMethodAbility::HideKeyboard() return ErrorCode::ERROR_IME; } if (panel->GetPanelFlag() == FLG_CANDIDATE_COLUMN) { + IMSA_HILOGD("panel flag is candidate, no need to hide."); return ErrorCode::NO_ERROR; } - return HidePanel(panel, false); - } else { - if (!hasAlphaKeyboard_.load()) { - NotifyPanelState(PanelState::FIXED_SOFT_KEYBOARD_HIDE); - } + return HidePanel(panel, Trigger::IMF); + } + auto channel = GetInputDataChannelProxy(); + if (channel != nullptr) { + channel->SendKeyboardStatus(KEYBOARD_HIDE); } return ErrorCode::NO_ERROR; } @@ -553,7 +542,11 @@ int32_t InputMethodAbility::HideKeyboardSelf() return ErrorCode::NO_ERROR; } imeListener_->OnKeyboardStatus(false); - NotifyPanelState(PanelState::FIXED_SOFT_KEYBOARD_HIDE_BY_IME); + channel->SendKeyboardStatus(KEYBOARD_HIDE); + auto controlChannel = GetInputControlChannel(); + if (controlChannel != nullptr) { + controlChannel->HideKeyboardSelf(); + } InputMethodSysEvent::GetInstance().OperateSoftkeyboardBehaviour(OperateIMEInfoCode::IME_HIDE_SELF); return ErrorCode::NO_ERROR; } @@ -780,15 +773,15 @@ int32_t InputMethodAbility::DestroyPanel(const std::shared_ptr int32_t InputMethodAbility::ShowPanel(const std::shared_ptr &inputMethodPanel) { - return ShowPanel(inputMethodPanel, true); + return ShowPanel(inputMethodPanel, Trigger::IME_APP); } int32_t InputMethodAbility::HidePanel(const std::shared_ptr &inputMethodPanel) { - return HidePanel(inputMethodPanel, true); + return HidePanel(inputMethodPanel, Trigger::IME_APP); } -int32_t InputMethodAbility::ShowPanel(const std::shared_ptr &inputMethodPanel, bool isByIme) +int32_t InputMethodAbility::ShowPanel(const std::shared_ptr &inputMethodPanel, Trigger trigger) { if (inputMethodPanel == nullptr) { return ErrorCode::ERROR_BAD_PARAMETERS; @@ -800,21 +793,21 @@ int32_t InputMethodAbility::ShowPanel(const std::shared_ptr &i } auto ret = inputMethodPanel->ShowPanel(); if (ret == ErrorCode::NO_ERROR) { - auto state = GetPanelState(inputMethodPanel, true, isByIme); - NotifyPanelState(state); + NotifyPanelStatusInfo( + { { inputMethodPanel->GetPanelType(), inputMethodPanel->GetPanelFlag() }, true, trigger }); } return ret; } -int32_t InputMethodAbility::HidePanel(const std::shared_ptr &inputMethodPanel, bool isByIme) +int32_t InputMethodAbility::HidePanel(const std::shared_ptr &inputMethodPanel, Trigger trigger) { if (inputMethodPanel == nullptr) { return ErrorCode::ERROR_BAD_PARAMETERS; } auto ret = inputMethodPanel->HidePanel(); if (ret == ErrorCode::NO_ERROR) { - auto state = GetPanelState(inputMethodPanel, false, isByIme); - NotifyPanelState(state); + NotifyPanelStatusInfo( + { { inputMethodPanel->GetPanelType(), inputMethodPanel->GetPanelFlag() }, false, trigger }); } return ret; } @@ -849,44 +842,9 @@ int32_t InputMethodAbility::ExitCurrentInputType() return proxy->ExitCurrentInputType(); } -void InputMethodAbility::UpdateAlphaKeyboardFlag(bool hasAlphaKeyboard) -{ - IMSA_HILOGD("hasAlphaKeyboard: %{public}d.", hasAlphaKeyboard); - hasAlphaKeyboard_.store(hasAlphaKeyboard); -} - -PanelState InputMethodAbility::GetPanelState( - const std::shared_ptr &inputMethodPanel, bool isShow, bool isByIme) -{ - auto type = inputMethodPanel->GetPanelType(); - auto flag = inputMethodPanel->GetPanelFlag(); - if (type == PanelType::SOFT_KEYBOARD && flag == FLG_FIXED && !isByIme) { - return isShow ? PanelState::FIXED_SOFT_KEYBOARD_SHOW : PanelState::FIXED_SOFT_KEYBOARD_HIDE; - } - if (type == PanelType::SOFT_KEYBOARD && flag == FLG_FLOATING && !isByIme) { - return isShow ? PanelState::FLOATING_SOFT_KEYBOARD_SHOW - : PanelState::FLOATING_SOFT_KEYBOARD_HIDE; - } - if (type == PanelType::SOFT_KEYBOARD && flag == FLG_FIXED && isByIme) { - return isShow ? PanelState::FIXED_SOFT_KEYBOARD_SHOW_BY_IME - : PanelState::FIXED_SOFT_KEYBOARD_HIDE_BY_IME; - } - if (type == PanelType::SOFT_KEYBOARD && flag == FLG_FLOATING && isByIme) { - return isShow ? PanelState::FLOATING_SOFT_KEYBOARD_SHOW_BY_IME - : PanelState::FLOATING_SOFT_KEYBOARD_HIDE_BY_IME; - } - if (type == PanelType::SOFT_KEYBOARD && flag == FLG_CANDIDATE_COLUMN) { - return isShow ? PanelState::CANDIDATE_COLUMN_SHOW_BY_IME - : PanelState::CANDIDATE_COLUMN_HIDE_BY_IME; - } - if (type == PanelType::STATUS_BAR) { - return isShow ? PanelState::STATUS_BAR_SHOW_BY_IME : PanelState::STATUS_BAR_HIDE_BY_IME; - } - return PanelState::NONE; -} - std::shared_ptr InputMethodAbility::GetSoftKeyboardPanel() { + IMSA_HILOGD("find SOFT_KEYBOARD panel."); if (!BlockRetry(FIND_PANEL_RETRY_INTERVAL, MAX_RETRY_TIMES, [this]() -> bool { return panels_.Find(SOFT_KEYBOARD).first; })) { IMSA_HILOGE("SOFT_KEYBOARD panel not found"); diff --git a/frameworks/native/inputmethod_controller/include/i_input_data_channel.h b/frameworks/native/inputmethod_controller/include/i_input_data_channel.h index b54caece..ea94a67c 100644 --- a/frameworks/native/inputmethod_controller/include/i_input_data_channel.h +++ b/frameworks/native/inputmethod_controller/include/i_input_data_channel.h @@ -45,7 +45,7 @@ public: HANDLE_EXTEND_ACTION, GET_TEXT_INDEX_AT_CURSOR, GET_TEXT_CONFIG, - SEND_PANEL_STATE, + NOTIFY_PANEL_STATUS_INFO, DATA_CHANNEL_CMD_LAST }; @@ -66,7 +66,7 @@ public: virtual int32_t SelectByMovement(int32_t direction, int32_t cursorMoveSkip) = 0; virtual int32_t HandleExtendAction(int32_t action) = 0; virtual int32_t GetTextIndexAtCursor(int32_t &index) = 0; - virtual void SendPanelState(const PanelState &state) = 0; + virtual void NotifyPanelStatusInfo(const PanelStatusInfo &info) = 0; }; } // namespace MiscServices } // namespace OHOS diff --git a/frameworks/native/inputmethod_controller/include/input_data_channel_proxy.h b/frameworks/native/inputmethod_controller/include/input_data_channel_proxy.h index 662a88dc..78db5f71 100644 --- a/frameworks/native/inputmethod_controller/include/input_data_channel_proxy.h +++ b/frameworks/native/inputmethod_controller/include/input_data_channel_proxy.h @@ -50,7 +50,7 @@ public: int32_t HandleExtendAction(int32_t action) override; int32_t GetTextIndexAtCursor(int32_t &index) override; int32_t GetTextConfig(TextTotalConfig &textConfig) override; - void SendPanelState(const PanelState &state) override; + void NotifyPanelStatusInfo(const PanelStatusInfo &info) override; private: static inline BrokerDelegator delegator_; diff --git a/frameworks/native/inputmethod_controller/include/input_data_channel_stub.h b/frameworks/native/inputmethod_controller/include/input_data_channel_stub.h index 7a753c20..88fbf9e5 100644 --- a/frameworks/native/inputmethod_controller/include/input_data_channel_stub.h +++ b/frameworks/native/inputmethod_controller/include/input_data_channel_stub.h @@ -52,7 +52,7 @@ public: int32_t SelectByMovement(int32_t direction, int32_t cursorMoveSkip) override; int32_t HandleExtendAction(int32_t action) override; int32_t GetTextConfig(TextTotalConfig &textConfig) override; - void SendPanelState(const PanelState &state) override; + void NotifyPanelStatusInfo(const PanelStatusInfo &info) override; private: template struct ResultInfo { @@ -75,7 +75,7 @@ private: int32_t SelectByMovementOnRemote(MessageParcel &data, MessageParcel &reply); int32_t HandleExtendActionOnRemote(MessageParcel &data, MessageParcel &reply); int32_t GetTextIndexAtCursorOnRemote(MessageParcel &data, MessageParcel &reply); - int32_t SendPanelStateOnRemote(MessageParcel &data, MessageParcel &reply); + int32_t NotifyPanelStatusInfoOnRemote(MessageParcel &data, MessageParcel &reply); using RequestHandler = int32_t (InputDataChannelStub::*)(MessageParcel &, MessageParcel &); static inline const std::unordered_map HANDLERS = { { static_cast(INSERT_TEXT), &InputDataChannelStub::InsertTextOnRemote }, @@ -93,7 +93,7 @@ private: { static_cast(HANDLE_EXTEND_ACTION), &InputDataChannelStub::HandleExtendActionOnRemote }, { static_cast(GET_TEXT_INDEX_AT_CURSOR), &InputDataChannelStub::GetTextIndexAtCursorOnRemote }, { static_cast(GET_TEXT_CONFIG), &InputDataChannelStub::GetTextConfigOnRemote }, - { static_cast(SEND_PANEL_STATE), &InputDataChannelStub::SendPanelStateOnRemote }, + { static_cast(NOTIFY_PANEL_STATUS_INFO), &InputDataChannelStub::NotifyPanelStatusInfoOnRemote }, }; }; } // namespace MiscServices diff --git a/frameworks/native/inputmethod_controller/include/input_method_utils.h b/frameworks/native/inputmethod_controller/include/input_method_utils.h index ce681c61..2ed96bab 100644 --- a/frameworks/native/inputmethod_controller/include/input_method_utils.h +++ b/frameworks/native/inputmethod_controller/include/input_method_utils.h @@ -19,6 +19,7 @@ #include #include "input_attribute.h" +#include "panel_info.h" namespace OHOS { namespace MiscServices { @@ -96,20 +97,12 @@ class KeyEvent { }; enum class KeyboardStatus { NONE = 0, HIDE, SHOW }; // soft keyboard -enum class PanelState : int32_t { // all panel state - FIXED_SOFT_KEYBOARD_SHOW, - FIXED_SOFT_KEYBOARD_HIDE, - FLOATING_SOFT_KEYBOARD_SHOW, - FLOATING_SOFT_KEYBOARD_HIDE, - FIXED_SOFT_KEYBOARD_SHOW_BY_IME, - FIXED_SOFT_KEYBOARD_HIDE_BY_IME, - FLOATING_SOFT_KEYBOARD_SHOW_BY_IME, - FLOATING_SOFT_KEYBOARD_HIDE_BY_IME, - CANDIDATE_COLUMN_SHOW_BY_IME, - CANDIDATE_COLUMN_HIDE_BY_IME, - STATUS_BAR_SHOW_BY_IME, - STATUS_BAR_HIDE_BY_IME, - NONE + +enum Trigger : int32_t { IME_APP, IMF }; +struct PanelStatusInfo { + PanelInfo panelInfo; + bool visible{ false }; + Trigger trigger{ IMF }; }; class FunctionKey { diff --git a/frameworks/native/inputmethod_controller/include/itypes_util.h b/frameworks/native/inputmethod_controller/include/itypes_util.h index e47bb922..a4a0de5a 100644 --- a/frameworks/native/inputmethod_controller/include/itypes_util.h +++ b/frameworks/native/inputmethod_controller/include/itypes_util.h @@ -78,6 +78,9 @@ public: static bool Marshalling(const TextTotalConfig &input, MessageParcel &data); static bool Unmarshalling(TextTotalConfig &output, MessageParcel &data); + static bool Marshalling(const PanelStatusInfo &info, MessageParcel &data); + static bool Unmarshalling(PanelStatusInfo &info, MessageParcel &data); + static bool Marshalling(EventType input, MessageParcel &data); static bool Unmarshalling(EventType &output, MessageParcel &data); diff --git a/frameworks/native/inputmethod_controller/src/input_data_channel_proxy.cpp b/frameworks/native/inputmethod_controller/src/input_data_channel_proxy.cpp index e07098c2..917ba100 100644 --- a/frameworks/native/inputmethod_controller/src/input_data_channel_proxy.cpp +++ b/frameworks/native/inputmethod_controller/src/input_data_channel_proxy.cpp @@ -67,10 +67,9 @@ void InputDataChannelProxy::SendKeyboardStatus(int32_t status) SEND_KEYBOARD_STATUS, [status](MessageParcel &parcel) { return ITypesUtil::Marshal(parcel, status); }); } -void InputDataChannelProxy::SendPanelState(const PanelState &state) +void InputDataChannelProxy::NotifyPanelStatusInfo(const PanelStatusInfo &info) { - SendRequest(SEND_KEYBOARD_STATUS, - [state](MessageParcel &parcel) { return ITypesUtil::Marshal(parcel, static_cast(state)); }); + SendRequest(SEND_KEYBOARD_STATUS, [&info](MessageParcel &parcel) { return ITypesUtil::Marshal(parcel, info); }); } int32_t InputDataChannelProxy::SendFunctionKey(int32_t funcKey) diff --git a/frameworks/native/inputmethod_controller/src/input_data_channel_stub.cpp b/frameworks/native/inputmethod_controller/src/input_data_channel_stub.cpp index 06f63d2c..3550817c 100644 --- a/frameworks/native/inputmethod_controller/src/input_data_channel_stub.cpp +++ b/frameworks/native/inputmethod_controller/src/input_data_channel_stub.cpp @@ -196,14 +196,14 @@ int32_t InputDataChannelStub::GetTextIndexAtCursorOnRemote(MessageParcel &data, : ErrorCode::ERROR_EX_PARCELABLE; } -int32_t InputDataChannelStub::SendPanelStateOnRemote(MessageParcel &data, MessageParcel &reply) +int32_t InputDataChannelStub::NotifyPanelStatusInfoOnRemote(MessageParcel &data, MessageParcel &reply) { - int32_t status = 0; - if (!ITypesUtil::Unmarshal(data, status)) { + PanelStatusInfo info{}; + if (!ITypesUtil::Unmarshal(data, info)) { IMSA_HILOGE("failed to read message parcel"); return ErrorCode::ERROR_EX_PARCELABLE; } - SendPanelState(static_cast(status)); + NotifyPanelStatusInfo(info); return reply.WriteInt32(ErrorCode::NO_ERROR) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE; } @@ -460,11 +460,11 @@ int32_t InputDataChannelStub::HandleExtendAction(int32_t action) return ret; } -void InputDataChannelStub::SendPanelState(const PanelState &state) +void InputDataChannelStub::NotifyPanelStatusInfo(const PanelStatusInfo &info) { auto result = std::make_shared>(MAX_TIMEOUT, false); - auto blockTask = [state, result]() { - InputMethodController::GetInstance()->SendPanelState(state); + auto blockTask = [info, result]() { + InputMethodController::GetInstance()->NotifyPanelStatusInfo(info); bool ret = true; result->SetValue(ret); }; diff --git a/frameworks/native/inputmethod_controller/src/input_method_controller.cpp b/frameworks/native/inputmethod_controller/src/input_method_controller.cpp index 48d68b57..9c441288 100644 --- a/frameworks/native/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/native/inputmethod_controller/src/input_method_controller.cpp @@ -1003,18 +1003,19 @@ void InputMethodController::SendKeyboardStatus(int32_t status) } } -void InputMethodController::SendPanelState(const PanelState &state) +void InputMethodController::NotifyPanelStatusInfo(const PanelStatusInfo &info) { - IMSA_HILOGD("run in, status: %{public}d", state); + IMSA_HILOGD("run in."); auto listener = GetTextListener(); if (listener == nullptr) { IMSA_HILOGE("textListener_ is nullptr"); return; } - listener->SendPanelState(state); -// if (keyboardStatus == KeyboardStatus::HIDE) { -// clientInfo_.isShowKeyboard = false; // todo 更新clientInfo_.isShowKeyboard -// } + listener->NotifyPanelStatusInfo(info); + if (info.panelInfo.panelType == PanelType::SOFT_KEYBOARD + && info.panelInfo.panelFlag != PanelFlag::FLG_CANDIDATE_COLUMN && !info.visible) { + clientInfo_.isShowKeyboard = false; + } } int32_t InputMethodController::SendFunctionKey(int32_t functionKey) diff --git a/frameworks/native/inputmethod_controller/src/itypes_util.cpp b/frameworks/native/inputmethod_controller/src/itypes_util.cpp index b1114183..8fad3164 100644 --- a/frameworks/native/inputmethod_controller/src/itypes_util.cpp +++ b/frameworks/native/inputmethod_controller/src/itypes_util.cpp @@ -294,5 +294,24 @@ bool ITypesUtil::Unmarshalling(InputType &output, MessageParcel &data) output = static_cast(ret); return true; } + +bool ITypesUtil::Marshalling(const PanelStatusInfo &input, MessageParcel &data) +{ + return data.WriteInt32(static_cast(input.panelInfo.panelType)) && data.WriteInt32(static_cast(input.panelInfo.panelFlag)) + && data.WriteBool(input.visible) && data.WriteInt32(static_cast(input.trigger)); +} + +bool ITypesUtil::Unmarshalling(PanelStatusInfo &output, MessageParcel &data) +{ + int32_t type = -1; + int32_t flag = -1; + bool visible = false; + int32_t trigger = -1; + if (!data.ReadInt32(type) || !data.ReadInt32(flag) || !data.ReadBool(visible) || !data.ReadInt32(trigger)) { + return false; + } + output = { { static_cast(type), static_cast(flag) }, visible, static_cast(trigger) }; + return true; +} } // namespace MiscServices } // namespace OHOS \ No newline at end of file diff --git a/interfaces/inner_api/inputmethod_ability/BUILD.gn b/interfaces/inner_api/inputmethod_ability/BUILD.gn index 3feb82c3..ca3d3f5d 100644 --- a/interfaces/inner_api/inputmethod_ability/BUILD.gn +++ b/interfaces/inner_api/inputmethod_ability/BUILD.gn @@ -79,10 +79,7 @@ ohos_shared_library("inputmethod_ability") { "window_manager:libwm", ] - deps = [ - "${inputmethod_path}/services/dfx:inputmethod_dfx_static", - "${inputmethod_path}/frameworks/native/inputmethod_ability/adapter/input_dev_monitor:input_dev_monitor", - ] + deps = [ "${inputmethod_path}/services/dfx:inputmethod_dfx_static" ] public_configs = [ ":inputmethod_ability_native_public_config" ] diff --git a/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h b/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h index 65a3957d..2413fa3f 100644 --- a/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h +++ b/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h @@ -47,9 +47,7 @@ public: virtual void DeleteBackward(int32_t length) = 0; virtual void SendKeyEventFromInputMethod(const KeyEvent &event) = 0; virtual void SendKeyboardStatus(const KeyboardStatus &keyboardStatus) = 0; - virtual void SendPanelState(const PanelState &state) - { - } + virtual void NotifyPanelStatusInfo(const PanelStatusInfo &info){} virtual void SendFunctionKey(const FunctionKey &functionKey) = 0; virtual void SetKeyboardStatus(bool status) = 0; virtual void MoveCursor(const Direction direction) = 0; @@ -566,14 +564,15 @@ public: IMF_API void SendKeyboardStatus(int32_t status); /** - * @brief Send panel state. + * @brief Send panel status info. * - * This function is used to send panel state to editor. + * This function is used to send panel status info to editor. + * Only notify the status info of soft keyboard(not contain candidate column) at present * - * @param status Indicates the state of panel. + * @param info Indicates the status info of panel. * @since 10 */ - IMF_API void SendPanelState(const PanelState &state); + IMF_API void NotifyPanelStatusInfo(const PanelStatusInfo &info); /** * @brief Send function key. -- Gitee From 16aada7a2df307018eedb239dc8b3c539dcfaeb7 Mon Sep 17 00:00:00 2001 From: cy7717 Date: Wed, 25 Oct 2023 16:59:42 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E4=B8=8E=E8=A7=A3=E7=BB=91=E6=B5=81=E7=A8=8BOnKeyboardStatus?= =?UTF-8?q?=E7=9A=84=E5=9B=9E=E8=B0=83=E6=97=B6=E6=9C=BA=E4=B8=BAGetPanelF?= =?UTF-8?q?lag=E4=B9=8B=E5=90=8E=EF=BC=8C=E9=98=B2=E6=AD=A2=E6=9C=AA?= =?UTF-8?q?=E5=A4=84=E7=90=86panel=E6=98=BE=E7=A4=BA=E9=9A=90=E8=97=8F?= =?UTF-8?q?=E5=89=8D=EF=BC=8C=E8=BE=93=E5=85=A5=E6=B3=95=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E6=94=B6=E5=88=B0OnKeyboardStatus=E6=97=B6=E6=94=B9=E4=BA=86fl?= =?UTF-8?q?ag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cy7717 --- .../include/input_method_ability.h | 2 - .../src/input_method_ability.cpp | 39 ++++++++++++------- .../include/i_input_data_channel.h | 2 +- .../include/input_data_channel_proxy.h | 2 +- .../include/input_data_channel_stub.h | 2 +- .../include/input_method_utils.h | 2 +- .../src/input_data_channel_proxy.cpp | 8 ++-- .../src/input_data_channel_stub.cpp | 4 +- .../src/input_method_controller.cpp | 9 ++--- .../include/input_method_controller.h | 4 +- 10 files changed, 40 insertions(+), 34 deletions(-) diff --git a/frameworks/native/inputmethod_ability/include/input_method_ability.h b/frameworks/native/inputmethod_ability/include/input_method_ability.h index 13ece8a8..d4061af2 100644 --- a/frameworks/native/inputmethod_ability/include/input_method_ability.h +++ b/frameworks/native/inputmethod_ability/include/input_method_ability.h @@ -85,8 +85,6 @@ private: std::thread workThreadHandler; MessageHandler *msgHandler_; bool stop_ = false; - int32_t KEYBOARD_HIDE = 1; - int32_t KEYBOARD_SHOW = 2; std::mutex controlChannelLock_; std::shared_ptr controlChannel_ = nullptr; diff --git a/frameworks/native/inputmethod_ability/src/input_method_ability.cpp b/frameworks/native/inputmethod_ability/src/input_method_ability.cpp index 8f60e392..095656f5 100644 --- a/frameworks/native/inputmethod_ability/src/input_method_ability.cpp +++ b/frameworks/native/inputmethod_ability/src/input_method_ability.cpp @@ -376,23 +376,27 @@ int32_t InputMethodAbility::ShowKeyboard() IMSA_HILOGE("InputMethodAbility, imeListener is nullptr"); return ErrorCode::ERROR_IME; } - imeListener_->OnKeyboardStatus(true); - + auto channel = GetInputDataChannelProxy(); + if (channel == nullptr) { + IMSA_HILOGE("InputMethodAbility::channel is nullptr"); + return ErrorCode::ERROR_CLIENT_NULL_POINTER; + } if (isPanelKeyboard_.load()) { auto panel = GetSoftKeyboardPanel(); if (panel == nullptr) { return ErrorCode::ERROR_IME; } - if (panel->GetPanelFlag() == FLG_CANDIDATE_COLUMN) { + auto flag = panel->GetPanelFlag(); + imeListener_->OnKeyboardStatus(true); + if (flag == FLG_CANDIDATE_COLUMN) { IMSA_HILOGD("panel flag is candidate, no need to show."); return ErrorCode::NO_ERROR; } return ShowPanel(panel, Trigger::IMF); } - auto channel = GetInputDataChannelProxy(); - if (channel != nullptr) { - channel->SendKeyboardStatus(KEYBOARD_SHOW); - } + + channel->SendKeyboardStatus(KeyboardStatus::SHOW); + imeListener_->OnKeyboardStatus(true); return ErrorCode::NO_ERROR; } @@ -405,7 +409,7 @@ void InputMethodAbility::NotifyPanelStatusInfo(const PanelStatusInfo &info) } auto channel = GetInputDataChannelProxy(); if (channel != nullptr) { - info.visible ? channel->SendKeyboardStatus(KEYBOARD_SHOW) : channel->SendKeyboardStatus(KEYBOARD_HIDE); + info.visible ? channel->SendKeyboardStatus(KeyboardStatus::SHOW) : channel->SendKeyboardStatus(KeyboardStatus::HIDE); channel->NotifyPanelStatusInfo(info); } @@ -467,23 +471,28 @@ int32_t InputMethodAbility::HideKeyboard() IMSA_HILOGE("InputMethodAbility::HideKeyboard imeListener_ is nullptr"); return ErrorCode::ERROR_IME; } - imeListener_->OnKeyboardStatus(false); + auto channel = GetInputDataChannelProxy(); + if (channel == nullptr) { + IMSA_HILOGE("InputMethodAbility::channel is nullptr"); + return ErrorCode::ERROR_CLIENT_NULL_POINTER; + } if (isPanelKeyboard_.load()) { auto panel = GetSoftKeyboardPanel(); if (panel == nullptr) { return ErrorCode::ERROR_IME; } - if (panel->GetPanelFlag() == FLG_CANDIDATE_COLUMN) { + auto flag = panel->GetPanelFlag(); + imeListener_->OnKeyboardStatus(false); + if (flag == FLG_CANDIDATE_COLUMN) { IMSA_HILOGD("panel flag is candidate, no need to hide."); return ErrorCode::NO_ERROR; } return HidePanel(panel, Trigger::IMF); } - auto channel = GetInputDataChannelProxy(); - if (channel != nullptr) { - channel->SendKeyboardStatus(KEYBOARD_HIDE); - } + + channel->SendKeyboardStatus(KeyboardStatus::HIDE); + imeListener_->OnKeyboardStatus(false); return ErrorCode::NO_ERROR; } @@ -542,7 +551,7 @@ int32_t InputMethodAbility::HideKeyboardSelf() return ErrorCode::NO_ERROR; } imeListener_->OnKeyboardStatus(false); - channel->SendKeyboardStatus(KEYBOARD_HIDE); + channel->SendKeyboardStatus(KeyboardStatus::HIDE); auto controlChannel = GetInputControlChannel(); if (controlChannel != nullptr) { controlChannel->HideKeyboardSelf(); diff --git a/frameworks/native/inputmethod_controller/include/i_input_data_channel.h b/frameworks/native/inputmethod_controller/include/i_input_data_channel.h index ea94a67c..ab6d8e4c 100644 --- a/frameworks/native/inputmethod_controller/include/i_input_data_channel.h +++ b/frameworks/native/inputmethod_controller/include/i_input_data_channel.h @@ -57,7 +57,7 @@ public: virtual int32_t GetTextBeforeCursor(int32_t number, std::u16string &text) = 0; virtual int32_t GetTextAfterCursor(int32_t number, std::u16string &text) = 0; virtual int32_t GetTextConfig(TextTotalConfig &textConfig) = 0; - virtual void SendKeyboardStatus(int32_t status) = 0; + virtual void SendKeyboardStatus(KeyboardStatus status) = 0; virtual int32_t SendFunctionKey(int32_t funcKey) = 0; virtual int32_t MoveCursor(int32_t keyCode) = 0; virtual int32_t GetEnterKeyType(int32_t &keyType) = 0; diff --git a/frameworks/native/inputmethod_controller/include/input_data_channel_proxy.h b/frameworks/native/inputmethod_controller/include/input_data_channel_proxy.h index 78db5f71..bc274b9d 100644 --- a/frameworks/native/inputmethod_controller/include/input_data_channel_proxy.h +++ b/frameworks/native/inputmethod_controller/include/input_data_channel_proxy.h @@ -40,7 +40,7 @@ public: int32_t DeleteBackward(int32_t length) override; int32_t GetTextBeforeCursor(int32_t number, std::u16string &text) override; int32_t GetTextAfterCursor(int32_t number, std::u16string &text) override; - void SendKeyboardStatus(int32_t status) override; + void SendKeyboardStatus(KeyboardStatus status) override; int32_t SendFunctionKey(int32_t funcKey) override; int32_t MoveCursor(int32_t keyCode) override; int32_t GetEnterKeyType(int32_t &keyType) override; diff --git a/frameworks/native/inputmethod_controller/include/input_data_channel_stub.h b/frameworks/native/inputmethod_controller/include/input_data_channel_stub.h index 88fbf9e5..db62e9eb 100644 --- a/frameworks/native/inputmethod_controller/include/input_data_channel_stub.h +++ b/frameworks/native/inputmethod_controller/include/input_data_channel_stub.h @@ -43,7 +43,7 @@ public: int32_t GetTextBeforeCursor(int32_t number, std::u16string &text) override; int32_t GetTextAfterCursor(int32_t number, std::u16string &text) override; int32_t GetTextIndexAtCursor(int32_t &index) override; - void SendKeyboardStatus(int32_t status) override; + void SendKeyboardStatus(KeyboardStatus status) override; int32_t SendFunctionKey(int32_t funcKey) override; int32_t MoveCursor(int32_t keyCode) override; int32_t GetEnterKeyType(int32_t &keyType) override; diff --git a/frameworks/native/inputmethod_controller/include/input_method_utils.h b/frameworks/native/inputmethod_controller/include/input_method_utils.h index 2ed96bab..c047a8bf 100644 --- a/frameworks/native/inputmethod_controller/include/input_method_utils.h +++ b/frameworks/native/inputmethod_controller/include/input_method_utils.h @@ -96,7 +96,7 @@ struct CursorInfo { class KeyEvent { }; -enum class KeyboardStatus { NONE = 0, HIDE, SHOW }; // soft keyboard +enum class KeyboardStatus : int32_t { NONE = 0, HIDE, SHOW }; // soft keyboard enum Trigger : int32_t { IME_APP, IMF }; struct PanelStatusInfo { diff --git a/frameworks/native/inputmethod_controller/src/input_data_channel_proxy.cpp b/frameworks/native/inputmethod_controller/src/input_data_channel_proxy.cpp index 917ba100..31b526d3 100644 --- a/frameworks/native/inputmethod_controller/src/input_data_channel_proxy.cpp +++ b/frameworks/native/inputmethod_controller/src/input_data_channel_proxy.cpp @@ -61,15 +61,15 @@ int32_t InputDataChannelProxy::GetTextAfterCursor(int32_t number, std::u16string [&text](MessageParcel &parcel) { return ITypesUtil::Unmarshal(parcel, text);}); } -void InputDataChannelProxy::SendKeyboardStatus(int32_t status) +void InputDataChannelProxy::SendKeyboardStatus(KeyboardStatus status) { - SendRequest( - SEND_KEYBOARD_STATUS, [status](MessageParcel &parcel) { return ITypesUtil::Marshal(parcel, status); }); + SendRequest(SEND_KEYBOARD_STATUS, + [status](MessageParcel &parcel) { return ITypesUtil::Marshal(parcel, static_cast(status)); }); } void InputDataChannelProxy::NotifyPanelStatusInfo(const PanelStatusInfo &info) { - SendRequest(SEND_KEYBOARD_STATUS, [&info](MessageParcel &parcel) { return ITypesUtil::Marshal(parcel, info); }); + SendRequest(NOTIFY_PANEL_STATUS_INFO, [&info](MessageParcel &parcel) { return ITypesUtil::Marshal(parcel, info); }); } int32_t InputDataChannelProxy::SendFunctionKey(int32_t funcKey) diff --git a/frameworks/native/inputmethod_controller/src/input_data_channel_stub.cpp b/frameworks/native/inputmethod_controller/src/input_data_channel_stub.cpp index 3550817c..b63669b1 100644 --- a/frameworks/native/inputmethod_controller/src/input_data_channel_stub.cpp +++ b/frameworks/native/inputmethod_controller/src/input_data_channel_stub.cpp @@ -119,7 +119,7 @@ int32_t InputDataChannelStub::SendKeyboardStatusOnRemote(MessageParcel &data, Me IMSA_HILOGE("failed to read message parcel"); return ErrorCode::ERROR_EX_PARCELABLE; } - SendKeyboardStatus(status); + SendKeyboardStatus(static_cast(status)); return reply.WriteInt32(ErrorCode::NO_ERROR) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE; } @@ -363,7 +363,7 @@ int32_t InputDataChannelStub::GetTextConfig(TextTotalConfig &textConfig) return result.errCode; } -void InputDataChannelStub::SendKeyboardStatus(int32_t status) +void InputDataChannelStub::SendKeyboardStatus(KeyboardStatus status) { auto result = std::make_shared>(MAX_TIMEOUT, false); auto blockTask = [status, result]() { diff --git a/frameworks/native/inputmethod_controller/src/input_method_controller.cpp b/frameworks/native/inputmethod_controller/src/input_method_controller.cpp index 9c441288..8bbabfb4 100644 --- a/frameworks/native/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/native/inputmethod_controller/src/input_method_controller.cpp @@ -988,17 +988,16 @@ int32_t InputMethodController::MoveCursor(Direction direction) return ErrorCode::NO_ERROR; } -void InputMethodController::SendKeyboardStatus(int32_t status) +void InputMethodController::SendKeyboardStatus(KeyboardStatus status) { - IMSA_HILOGD("run in, status: %{public}d", status); + IMSA_HILOGD("run in, status: %{public}d", static_cast(status)); auto listener = GetTextListener(); if (listener == nullptr) { IMSA_HILOGE("textListener_ is nullptr"); return; } - auto keyboardStatus = static_cast(status); - listener->SendKeyboardStatus(keyboardStatus); - if (keyboardStatus == KeyboardStatus::HIDE) { + listener->SendKeyboardStatus(status); + if (status == KeyboardStatus::HIDE) { clientInfo_.isShowKeyboard = false; } } diff --git a/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h b/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h index 2413fa3f..8de9e1ea 100644 --- a/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h +++ b/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h @@ -561,7 +561,7 @@ public: * @param status Indicates the status of keyboard. * @since 10 */ - IMF_API void SendKeyboardStatus(int32_t status); + IMF_API void SendKeyboardStatus(KeyboardStatus status); /** * @brief Send panel status info. @@ -570,7 +570,7 @@ public: * Only notify the status info of soft keyboard(not contain candidate column) at present * * @param info Indicates the status info of panel. - * @since 10 + * @since 11 */ IMF_API void NotifyPanelStatusInfo(const PanelStatusInfo &info); -- Gitee From c23d1c5314abc6fbd61fb231e9eb694d177030c5 Mon Sep 17 00:00:00 2001 From: cy7717 Date: Thu, 26 Oct 2023 17:58:00 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E5=A2=9E=E5=8A=A0tdd=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cy7717 --- .../include/input_method_utils.h | 9 +- .../src/input_data_channel_stub.cpp | 2 +- test/common/include/text_listener.h | 5 +- test/common/src/text_listener.cpp | 36 +++-- .../input_method_ability_exception_test.cpp | 1 + .../src/input_method_ability_test.cpp | 153 +++++++++++++++++- .../cpp_test/src/input_method_attach_test.cpp | 4 +- .../src/input_method_controller_test.cpp | 33 ++-- .../cpp_test/src/input_method_editor_test.cpp | 10 +- .../src/text_listener_inner_api_test.cpp | 17 +- 10 files changed, 209 insertions(+), 61 deletions(-) diff --git a/frameworks/native/inputmethod_controller/include/input_method_utils.h b/frameworks/native/inputmethod_controller/include/input_method_utils.h index c047a8bf..8340ad5f 100644 --- a/frameworks/native/inputmethod_controller/include/input_method_utils.h +++ b/frameworks/native/inputmethod_controller/include/input_method_utils.h @@ -98,11 +98,16 @@ class KeyEvent { enum class KeyboardStatus : int32_t { NONE = 0, HIDE, SHOW }; // soft keyboard -enum Trigger : int32_t { IME_APP, IMF }; +enum Trigger : int32_t { IME_APP, IMF, END }; struct PanelStatusInfo { PanelInfo panelInfo; bool visible{ false }; - Trigger trigger{ IMF }; + Trigger trigger{ END }; + bool operator==(const PanelStatusInfo &info) const + { + return info.panelInfo.panelFlag == panelInfo.panelFlag && info.panelInfo.panelType == panelInfo.panelType + && info.visible == visible && info.trigger == trigger; + } }; class FunctionKey { diff --git a/frameworks/native/inputmethod_controller/src/input_data_channel_stub.cpp b/frameworks/native/inputmethod_controller/src/input_data_channel_stub.cpp index b63669b1..09709cb4 100644 --- a/frameworks/native/inputmethod_controller/src/input_data_channel_stub.cpp +++ b/frameworks/native/inputmethod_controller/src/input_data_channel_stub.cpp @@ -114,7 +114,7 @@ int32_t InputDataChannelStub::GetTextConfigOnRemote(MessageParcel &data, Message int32_t InputDataChannelStub::SendKeyboardStatusOnRemote(MessageParcel &data, MessageParcel &reply) { - int32_t status = 0; + int32_t status = -1; if (!ITypesUtil::Unmarshal(data, status)) { IMSA_HILOGE("failed to read message parcel"); return ErrorCode::ERROR_EX_PARCELABLE; diff --git a/test/common/include/text_listener.h b/test/common/include/text_listener.h index 1a9fdfa8..8d61071f 100644 --- a/test/common/include/text_listener.h +++ b/test/common/include/text_listener.h @@ -41,12 +41,14 @@ public: void HandleSetSelection(int32_t start, int32_t end) override; void HandleExtendAction(int32_t action) override; void HandleSelect(int32_t keyCode, int32_t cursorMoveSkip) override; + void NotifyPanelStatusInfo(const PanelStatusInfo &info) override; std::u16string GetLeftTextOfCursor(int32_t number) override; std::u16string GetRightTextOfCursor(int32_t number) override; int32_t GetTextIndexAtCursor() override; static void setTimeout(bool isTimeout); static void ResetParam(); - static bool WaitIMACallback(); + static bool WaitSendKeyboardStatusCallback(const KeyboardStatus &keyboardStatus); + static bool WaitNotifyPanelStatusInfoCallback(const PanelStatusInfo &info); static std::mutex textListenerCallbackLock_; static std::condition_variable textListenerCv_; static int32_t direction_; @@ -61,6 +63,7 @@ public: static int32_t selectionSkip_; static int32_t action_; static KeyboardStatus keyboardStatus_; + static PanelStatusInfo info_; static bool isTimeout_; std::shared_ptr serviceHandler_; static constexpr int32_t MAX_TIMEOUT = 2700000; diff --git a/test/common/src/text_listener.cpp b/test/common/src/text_listener.cpp index 30ea316b..f7310f85 100644 --- a/test/common/src/text_listener.cpp +++ b/test/common/src/text_listener.cpp @@ -32,6 +32,7 @@ int32_t TextListener::selectionSkip_ = -1; int32_t TextListener::action_ = -1; KeyboardStatus TextListener::keyboardStatus_ = { KeyboardStatus::NONE }; bool TextListener::isTimeout_ = { false }; +PanelStatusInfo TextListener::info_{}; TextListener::TextListener() { @@ -66,18 +67,8 @@ void TextListener::SendKeyEventFromInputMethod(const KeyEvent &event) {} void TextListener::SendKeyboardStatus(const KeyboardStatus &keyboardStatus) { IMSA_HILOGD("TextListener::SendKeyboardStatus %{public}d", static_cast(keyboardStatus)); - constexpr int32_t interval = 20; - { - std::unique_lock lock(textListenerCallbackLock_); - IMSA_HILOGD("TextListener::SendKeyboardStatus lock"); - keyboardStatus_ = keyboardStatus; - } - serviceHandler_->PostTask( - [this]() { - textListenerCv_.notify_all(); - }, - interval); - IMSA_HILOGD("TextListener::SendKeyboardStatus notify_all"); + keyboardStatus_ = keyboardStatus; + textListenerCv_.notify_one(); } void TextListener::SendFunctionKey(const FunctionKey &functionKey) @@ -143,6 +134,14 @@ int32_t TextListener::GetTextIndexAtCursor() } return TEXT_INDEX; } +void TextListener::NotifyPanelStatusInfo(const PanelStatusInfo &info) +{ + IMSA_HILOGD("TextListener::type: %{public}d, flag: %{public}d, visible: %{public}d, trigger: %{public}d.", + static_cast(info.panelInfo.panelType), static_cast(info.panelInfo.panelFlag), + info.visible, static_cast(info.trigger)); + info_ = info; + textListenerCv_.notify_one(); +} void TextListener::setTimeout(bool isTimeout) { isTimeout_ = isTimeout; @@ -161,12 +160,21 @@ void TextListener::ResetParam() selectionSkip_ = -1; action_ = -1; keyboardStatus_ = KeyboardStatus::NONE; + info_ = {}; isTimeout_ = false; } -bool TextListener::WaitIMACallback() +bool TextListener::WaitSendKeyboardStatusCallback(const KeyboardStatus &keyboardStatus) +{ + std::unique_lock lock(textListenerCallbackLock_); + textListenerCv_.wait_for( + lock, std::chrono::seconds(1), [&keyboardStatus]() { return keyboardStatus == keyboardStatus_; }); + return keyboardStatus == keyboardStatus_; +} +bool TextListener::WaitNotifyPanelStatusInfoCallback(const PanelStatusInfo &info) { std::unique_lock lock(textListenerCallbackLock_); - return TextListener::textListenerCv_.wait_for(lock, std::chrono::seconds(1)) != std::cv_status::timeout; + textListenerCv_.wait_for(lock, std::chrono::seconds(1), [info]() { return info == info_; }); + return info == info_; } } // namespace MiscServices } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/cpp_test/src/input_method_ability_exception_test.cpp b/test/unittest/cpp_test/src/input_method_ability_exception_test.cpp index 5a1ccbe3..665aaf1f 100644 --- a/test/unittest/cpp_test/src/input_method_ability_exception_test.cpp +++ b/test/unittest/cpp_test/src/input_method_ability_exception_test.cpp @@ -329,6 +329,7 @@ HWTEST_F(InputMethodAbilityExceptionTest, testHideKeyboard_001, TestSize.Level0) auto panel = std::make_shared(); panel->panelFlag_ = FLG_CANDIDATE_COLUMN; inputMethodAbility_->panels_.Insert(SOFT_KEYBOARD, panel); + inputMethodAbility_->isPanelKeyboard_ = true; ret = inputMethodAbility_->HideKeyboard(); EXPECT_EQ(ret, ErrorCode::NO_ERROR); diff --git a/test/unittest/cpp_test/src/input_method_ability_test.cpp b/test/unittest/cpp_test/src/input_method_ability_test.cpp index 815cea7c..4da55256 100644 --- a/test/unittest/cpp_test/src/input_method_ability_test.cpp +++ b/test/unittest/cpp_test/src/input_method_ability_test.cpp @@ -52,6 +52,7 @@ public: static bool showKeyboard_; static constexpr int CURSOR_DIRECTION_BASE_VALUE = 2011; static sptr imc_; + static sptr textListener_; static sptr inputMethodAbility_; static uint32_t windowId_; @@ -104,6 +105,8 @@ public: WindowMgr::ShowWindow(); bool isFocused = FocusChangedListenerTestImpl::isFocused_->GetValue(); IMSA_HILOGI("getFocus end, isFocused = %{public}d", isFocused); + imc_ = InputMethodController::GetInstance(); + textListener_ = new TextListener(); } static void TearDownTestCase(void) { @@ -121,12 +124,42 @@ public: { IMSA_HILOGI("InputMethodAbilityTest::TearDown"); } + void CheckPanelStatusInfo(const std::shared_ptr &panel, const PanelStatusInfo &info) + { + TextListener::ResetParam(); + if (info.visible) { + auto ret = inputMethodAbility_->ShowPanel(panel); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + if (info.panelInfo.panelType == SOFT_KEYBOARD && info.panelInfo.panelFlag != FLG_CANDIDATE_COLUMN) { + EXPECT_TRUE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::SHOW)); + EXPECT_TRUE(TextListener::WaitNotifyPanelStatusInfoCallback( + { { info.panelInfo.panelType, info.panelInfo.panelFlag }, info.visible, info.trigger })); + } else { + EXPECT_FALSE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::SHOW)); + EXPECT_FALSE(TextListener::WaitNotifyPanelStatusInfoCallback( + { { info.panelInfo.panelType, info.panelInfo.panelFlag }, info.visible, info.trigger })); + } + return; + } + auto ret = inputMethodAbility_->HidePanel(panel); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + if (info.panelInfo.panelType == SOFT_KEYBOARD && info.panelInfo.panelFlag != FLG_CANDIDATE_COLUMN) { + EXPECT_TRUE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::HIDE)); + EXPECT_TRUE(TextListener::WaitNotifyPanelStatusInfoCallback( + { { info.panelInfo.panelType, info.panelInfo.panelFlag }, info.visible, info.trigger })); + } else { + EXPECT_FALSE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::HIDE)); + EXPECT_FALSE(TextListener::WaitNotifyPanelStatusInfoCallback( + { { info.panelInfo.panelType, info.panelInfo.panelFlag }, info.visible, info.trigger })); + } + } }; std::mutex InputMethodAbilityTest::imeListenerCallbackLock_; std::condition_variable InputMethodAbilityTest::imeListenerCv_; bool InputMethodAbilityTest::showKeyboard_ = true; sptr InputMethodAbilityTest::imc_; +sptr InputMethodAbilityTest::textListener_; sptr InputMethodAbilityTest::inputMethodAbility_; uint32_t InputMethodAbilityTest::windowId_ = 0; @@ -241,9 +274,7 @@ HWTEST_F(InputMethodAbilityTest, testStartInputWithoutPanel, TestSize.Level0) HWTEST_F(InputMethodAbilityTest, testHideKeyboardSelf, TestSize.Level0) { IMSA_HILOGI("InputMethodAbility testHideKeyboardSelf START"); - sptr textListener = new TextListener(); - imc_ = InputMethodController::GetInstance(); - imc_->Attach(textListener); + imc_->Attach(textListener_); std::unique_lock lock(InputMethodAbilityTest::imeListenerCallbackLock_); InputMethodAbilityTest::showKeyboard_ = true; inputMethodAbility_->SetImeListener(std::make_shared()); @@ -393,16 +424,14 @@ HWTEST_F(InputMethodAbilityTest, testGetEnterKeyType, TestSize.Level0) HWTEST_F(InputMethodAbilityTest, testGetTextConfig, TestSize.Level0) { IMSA_HILOGI("InputMethodAbility testGetTextConfig START"); - sptr textListener = new TextListener(); TextConfig textConfig; textConfig.inputAttribute = { .inputPattern = 0, .enterKeyType = 1 }; - auto ret = imc_->Attach(textListener, false, textConfig); + auto ret = imc_->Attach(textListener_, false, textConfig); TextTotalConfig textTotalConfig; ret = inputMethodAbility_->GetTextConfig(textTotalConfig); EXPECT_EQ(ret, ErrorCode::NO_ERROR); EXPECT_EQ(textTotalConfig.inputAttribute.inputPattern, textConfig.inputAttribute.inputPattern); EXPECT_EQ(textTotalConfig.inputAttribute.enterKeyType, textConfig.inputAttribute.enterKeyType); - textListener = nullptr; } /** @@ -768,5 +797,117 @@ HWTEST_F(InputMethodAbilityTest, testSetCallingWindow001, TestSize.Level0) }); EXPECT_EQ(InputMethodAbilityTest::windowId_, windowId); } + +/** +* @tc.name: testNotifyPanelStatusInfo_001 +* @tc.desc: ShowKeyboard HideKeyboard SOFT_KEYBOARD FLG_FIXED +* @tc.type: FUNC +* @tc.require: +* @tc.author: chenyu +*/ +HWTEST_F(InputMethodAbilityTest, testNotifyPanelStatusInfo_001, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodAbility testNotifyPanelStatusInfo_001 START"); + imc_->Attach(textListener_); + PanelInfo info = { .panelType = STATUS_BAR }; + auto panel = std::make_shared(); + auto ret = inputMethodAbility_->CreatePanel(nullptr, info, panel); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + auto panel1 = std::make_shared(); + PanelInfo info1 = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED }; + ret = inputMethodAbility_->CreatePanel(nullptr, info1, panel1); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + + TextListener::ResetParam(); + ret = inputMethodAbility_->ShowKeyboard(); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + EXPECT_TRUE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::SHOW)); + EXPECT_TRUE(TextListener::WaitNotifyPanelStatusInfoCallback({ info1, true, Trigger::IMF })); + + TextListener::ResetParam(); + ret = inputMethodAbility_->HideKeyboard(); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + EXPECT_TRUE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::HIDE)); + EXPECT_TRUE(TextListener::WaitNotifyPanelStatusInfoCallback({ info1, false, Trigger::IMF })); + + ret = inputMethodAbility_->DestroyPanel(panel); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + ret = inputMethodAbility_->DestroyPanel(panel1); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); +} + +/** +* @tc.name: testNotifyPanelStatusInfo_002 +* @tc.desc: ShowPanel HidePanel SOFT_KEYBOARD FLG_FLOATING +* @tc.type: FUNC +* @tc.require: +* @tc.author: chenyu +*/ +HWTEST_F(InputMethodAbilityTest, testNotifyPanelStatusInfo_002, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodAbility testNotifyPanelStatusInfo_002 START"); + imc_->Attach(textListener_); + PanelInfo info = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING }; + auto panel = std::make_shared(); + auto ret = inputMethodAbility_->CreatePanel(nullptr, info, panel); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + // ShowPanel + CheckPanelStatusInfo(panel, { info, true, Trigger::IME_APP }); + // HidePanel + CheckPanelStatusInfo(panel, { info, false, Trigger::IME_APP }); + + ret = inputMethodAbility_->DestroyPanel(panel); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); +} + +/** +* @tc.name: testNotifyPanelStatusInfo_003 +* @tc.desc: ShowPanel HidePanel STATUS_BAR +* @tc.type: FUNC +* @tc.require: +* @tc.author: chenyu +*/ +HWTEST_F(InputMethodAbilityTest, testNotifyPanelStatusInfo_003, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodAbility testNotifyPanelStatusInfo_003 START"); + imc_->Attach(textListener_); + PanelInfo info = { .panelType = STATUS_BAR }; + auto panel = std::make_shared(); + auto ret = inputMethodAbility_->CreatePanel(nullptr, info, panel); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + + // ShowPanel + CheckPanelStatusInfo(panel, { info, true, Trigger::IME_APP }); + // HidePanel + CheckPanelStatusInfo(panel, { info, false, Trigger::IME_APP }); + + ret = inputMethodAbility_->DestroyPanel(panel); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); +} + +/** +* @tc.name: testNotifyPanelStatusInfo_004 +* @tc.desc: ShowPanel HidePanel SOFT_KEYBOARD FLG_CANDIDATE_COLUMN +* @tc.type: FUNC +* @tc.require: +* @tc.author: chenyu +*/ +HWTEST_F(InputMethodAbilityTest, testNotifyPanelStatusInfo_004, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodAbility testNotifyPanelStatusInfo_004 START"); + imc_->Attach(textListener_); + PanelInfo info = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_CANDIDATE_COLUMN }; + auto panel = std::make_shared(); + auto ret = inputMethodAbility_->CreatePanel(nullptr, info, panel); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + + // ShowPanel + CheckPanelStatusInfo(panel, { info, true, Trigger::IME_APP }); + // HidePanel + CheckPanelStatusInfo(panel, { info, false, Trigger::IME_APP }); + + ret = inputMethodAbility_->DestroyPanel(panel); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); +} } // namespace MiscServices } // namespace OHOS diff --git a/test/unittest/cpp_test/src/input_method_attach_test.cpp b/test/unittest/cpp_test/src/input_method_attach_test.cpp index bc1f587d..049e16d4 100644 --- a/test/unittest/cpp_test/src/input_method_attach_test.cpp +++ b/test/unittest/cpp_test/src/input_method_attach_test.cpp @@ -232,13 +232,13 @@ HWTEST_F(InputMethodAttachTest, testAttach006, TestSize.Level0) sptr textListener = new TextListener(); auto ret = InputMethodAttachTest::inputMethodController_->Attach(textListener, false); EXPECT_EQ(ret, ErrorCode::NO_ERROR); - EXPECT_EQ(TextListener::keyboardStatus_, KeyboardStatus::NONE); + EXPECT_TRUE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::NONE)); InputMethodAttachTest::inputMethodController_->Close(); TextListener::ResetParam(); ret = InputMethodAttachTest::inputMethodController_->Attach(textListener, true); EXPECT_EQ(ret, ErrorCode::NO_ERROR); - EXPECT_EQ(TextListener::keyboardStatus_, KeyboardStatus::SHOW); + EXPECT_TRUE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::SHOW)); } /** diff --git a/test/unittest/cpp_test/src/input_method_controller_test.cpp b/test/unittest/cpp_test/src/input_method_controller_test.cpp index 06eb3fcc..bb7f2b79 100644 --- a/test/unittest/cpp_test/src/input_method_controller_test.cpp +++ b/test/unittest/cpp_test/src/input_method_controller_test.cpp @@ -408,10 +408,11 @@ HWTEST_F(InputMethodControllerTest, testIMCAttach, TestSize.Level0) { IMSA_HILOGD("IMC Attach Test START"); imeListener_->isInputStart_ = false; + TextListener::ResetParam(); inputMethodController_->Attach(textListener_, false); inputMethodController_->Attach(textListener_); inputMethodController_->Attach(textListener_, true); - EXPECT_TRUE(TextListener::WaitIMACallback()); + EXPECT_TRUE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::SHOW)); EXPECT_TRUE(imeListener_->isInputStart_ && imeListener_->keyboardState_); } @@ -648,10 +649,9 @@ HWTEST_F(InputMethodControllerTest, testIMCOnSelectionChange02, TestSize.Level0) HWTEST_F(InputMethodControllerTest, testShowTextInput, TestSize.Level0) { IMSA_HILOGI("IMC ShowTextInput Test START"); - TextListener::keyboardStatus_ = KeyboardStatus::NONE; + TextListener::ResetParam(); inputMethodController_->ShowTextInput(); - EXPECT_TRUE(TextListener::WaitIMACallback()); - EXPECT_TRUE(TextListener::keyboardStatus_ == KeyboardStatus::SHOW); + EXPECT_TRUE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::SHOW)); } /** @@ -663,11 +663,10 @@ HWTEST_F(InputMethodControllerTest, testShowSoftKeyboard, TestSize.Level0) { IMSA_HILOGI("IMC ShowSoftKeyboard Test START"); imeListener_->keyboardState_ = false; - TextListener::keyboardStatus_ = KeyboardStatus::NONE; + TextListener::ResetParam(); int32_t ret = inputMethodController_->ShowSoftKeyboard(); - EXPECT_TRUE(TextListener::WaitIMACallback()); EXPECT_EQ(ret, ErrorCode::NO_ERROR); - EXPECT_TRUE(imeListener_->keyboardState_ && TextListener::keyboardStatus_ == KeyboardStatus::SHOW); + EXPECT_TRUE(imeListener_->keyboardState_ && TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::SHOW)); } /** @@ -679,11 +678,10 @@ HWTEST_F(InputMethodControllerTest, testShowCurrentInput, TestSize.Level0) { IMSA_HILOGI("IMC ShowCurrentInput Test START"); imeListener_->keyboardState_ = false; - TextListener::keyboardStatus_ = KeyboardStatus::NONE; + TextListener::ResetParam(); int32_t ret = inputMethodController_->ShowCurrentInput(); - EXPECT_TRUE(TextListener::WaitIMACallback()); EXPECT_EQ(ret, ErrorCode::NO_ERROR); - EXPECT_TRUE(imeListener_->keyboardState_ && TextListener::keyboardStatus_ == KeyboardStatus::SHOW); + EXPECT_TRUE(imeListener_->keyboardState_ && TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::SHOW)); } /** @@ -744,11 +742,10 @@ HWTEST_F(InputMethodControllerTest, testHideSoftKeyboard, TestSize.Level0) { IMSA_HILOGI("IMC HideSoftKeyboard Test START"); imeListener_->keyboardState_ = true; - TextListener::keyboardStatus_ = KeyboardStatus::NONE; + TextListener::ResetParam(); int32_t ret = inputMethodController_->HideSoftKeyboard(); - EXPECT_TRUE(TextListener::WaitIMACallback()); EXPECT_EQ(ret, ErrorCode::NO_ERROR); - EXPECT_TRUE(!imeListener_->keyboardState_ && TextListener::keyboardStatus_ == KeyboardStatus::HIDE); + EXPECT_TRUE(!imeListener_->keyboardState_ && TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::HIDE)); } /** @@ -761,11 +758,10 @@ HWTEST_F(InputMethodControllerTest, testIMCHideCurrentInput, TestSize.Level0) { IMSA_HILOGI("IMC HideCurrentInput Test START"); imeListener_->keyboardState_ = true; - TextListener::keyboardStatus_ = KeyboardStatus::NONE; + TextListener::ResetParam(); int32_t ret = inputMethodController_->HideCurrentInput(); - EXPECT_TRUE(TextListener::WaitIMACallback()); EXPECT_EQ(ret, ErrorCode::NO_ERROR); - EXPECT_TRUE(!imeListener_->keyboardState_ && TextListener::keyboardStatus_ == KeyboardStatus::HIDE); + EXPECT_TRUE(!imeListener_->keyboardState_ && TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::HIDE)); } /** @@ -779,7 +775,6 @@ HWTEST_F(InputMethodControllerTest, testIMCInputStopSession, TestSize.Level0) { IMSA_HILOGI("IMC StopInputSession Test START"); imeListener_->keyboardState_ = true; - TextListener::keyboardStatus_ = KeyboardStatus::NONE; int32_t ret = inputMethodController_->StopInputSession(); EXPECT_EQ(ret, ErrorCode::NO_ERROR); WaitKeyboardStatusCallback(false); @@ -795,7 +790,6 @@ HWTEST_F(InputMethodControllerTest, testIMCHideTextInput, TestSize.Level0) { IMSA_HILOGI("IMC HideTextInput Test START"); imeListener_->keyboardState_ = true; - TextListener::keyboardStatus_ = KeyboardStatus::NONE; inputMethodController_->HideTextInput(); WaitKeyboardStatusCallback(false); EXPECT_TRUE(!imeListener_->keyboardState_); @@ -906,12 +900,13 @@ HWTEST_F(InputMethodControllerTest, testOnRemoteDied, TestSize.Level0) EXPECT_EQ(ret, ErrorCode::NO_ERROR); pid_t pid = TddUtil::GetImsaPid(); EXPECT_TRUE(pid > 0); + TextListener::ResetParam(); ret = kill(pid, SIGTERM); EXPECT_EQ(ret, 0); EXPECT_TRUE(WaitRemoteDiedCallback()); CheckProxyObject(); inputMethodController_->OnRemoteSaDied(nullptr); - EXPECT_TRUE(TextListener::WaitIMACallback()); + EXPECT_TRUE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::SHOW)); bool result = inputMethodController_->WasAttached(); EXPECT_TRUE(result); inputMethodController_->Close(); diff --git a/test/unittest/cpp_test/src/input_method_editor_test.cpp b/test/unittest/cpp_test/src/input_method_editor_test.cpp index 6ab2075c..4d19117a 100644 --- a/test/unittest/cpp_test/src/input_method_editor_test.cpp +++ b/test/unittest/cpp_test/src/input_method_editor_test.cpp @@ -214,14 +214,14 @@ HWTEST_F(InputMethodEditorTest, testAttachFocused, TestSize.Level0) InputMethodEditorTest::imeListener_->isInputStart_ = false; InputMethodEditorTest::imeListener_->keyboardState_ = false; ret = InputMethodEditorTest::inputMethodController_->Attach(InputMethodEditorTest::textListener_); - EXPECT_TRUE(TextListener::WaitIMACallback()); + EXPECT_TRUE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::SHOW)); EXPECT_TRUE(imeListener_->isInputStart_ && imeListener_->keyboardState_); EXPECT_EQ(ret, ErrorCode::NO_ERROR); InputMethodEditorTest::imeListener_->isInputStart_ = false; InputMethodEditorTest::imeListener_->keyboardState_ = false; ret = InputMethodEditorTest::inputMethodController_->Attach(InputMethodEditorTest::textListener_, true); - EXPECT_TRUE(TextListener::WaitIMACallback()); + EXPECT_TRUE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::SHOW)); EXPECT_TRUE(imeListener_->isInputStart_ && imeListener_->keyboardState_); EXPECT_EQ(ret, ErrorCode::NO_ERROR); InputMethodEditorTest::inputMethodController_->Close(); @@ -243,13 +243,12 @@ HWTEST_F(InputMethodEditorTest, testShowSoftKeyboard, TestSize.Level0) bool isFocused = FocusChangedListenerTestImpl::isFocused_->GetValue(); IMSA_HILOGI("testShowSoftKeyboard getFocus end, isFocused = %{public}d", isFocused); InputMethodEditorTest::imeListener_->keyboardState_ = false; - TextListener::keyboardStatus_ = KeyboardStatus::NONE; + TextListener::ResetParam(); int32_t ret = InputMethodEditorTest::inputMethodController_->Attach(InputMethodEditorTest::textListener_, false); EXPECT_EQ(ret, ErrorCode::NO_ERROR); ret = InputMethodEditorTest::inputMethodController_->ShowSoftKeyboard(); - EXPECT_TRUE(TextListener::WaitIMACallback()); EXPECT_EQ(ret, ErrorCode::NO_ERROR); - EXPECT_TRUE(imeListener_->keyboardState_ && TextListener::keyboardStatus_ == KeyboardStatus::SHOW); + EXPECT_TRUE(imeListener_->keyboardState_ && TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::SHOW)); WindowMgr::HideWindow(); bool unFocus = FocusChangedListenerTestImpl::unFocused_->GetValue(); IMSA_HILOGI("testShowSoftKeyboard unFocus end, unFocus = %{public}d", unFocus); @@ -271,7 +270,6 @@ HWTEST_F(InputMethodEditorTest, testIMCHideTextInput, TestSize.Level0) EXPECT_EQ(ret, ErrorCode::NO_ERROR); imeListener_->keyboardState_ = true; - TextListener::keyboardStatus_ = KeyboardStatus::NONE; InputMethodEditorTest::inputMethodController_->HideTextInput(); bool result = InputMethodEditorTest::inputMethodController_->DispatchKeyEvent(InputMethodEditorTest::keyEvent_); EXPECT_FALSE(result); diff --git a/test/unittest/cpp_test/src/text_listener_inner_api_test.cpp b/test/unittest/cpp_test/src/text_listener_inner_api_test.cpp index 747b7ad6..65f03de8 100644 --- a/test/unittest/cpp_test/src/text_listener_inner_api_test.cpp +++ b/test/unittest/cpp_test/src/text_listener_inner_api_test.cpp @@ -298,9 +298,8 @@ HWTEST_F(TextListenerInnerApiTest, testSendKeyboardStatus01, TestSize.Level0) IMSA_HILOGI("TextListenerInnerApiTest testSendKeyboardStatus01 START"); TextListener::ResetParam(); imc_->Attach(textListener_); - int32_t status = 1; - TextListenerInnerApiTest::imc_->SendKeyboardStatus(status); - EXPECT_EQ(TextListener::keyboardStatus_, static_cast(status)); + TextListenerInnerApiTest::imc_->SendKeyboardStatus(KeyboardStatus::HIDE); + EXPECT_TRUE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::HIDE)); } /** @@ -312,18 +311,16 @@ HWTEST_F(TextListenerInnerApiTest, testSendKeyboardStatus01, TestSize.Level0) HWTEST_F(TextListenerInnerApiTest, testSendKeyboardStatus02, TestSize.Level0) { IMSA_HILOGI("TextListenerInnerApiTest testSendKeyboardStatus02 START"); - TextListener::ResetParam(); - int32_t status = 1; - TextListenerInnerApiTest::imc_->Attach(TextListenerInnerApiTest::textListener_); + TextListener::ResetParam(); TextListenerInnerApiTest::imc_->textListener_ = nullptr; - TextListenerInnerApiTest::imc_->SendKeyboardStatus(status); - EXPECT_NE(TextListener::keyboardStatus_, static_cast(status)); + TextListenerInnerApiTest::imc_->SendKeyboardStatus(KeyboardStatus::HIDE); + EXPECT_TRUE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::NONE)); TextListener::ResetParam(); TextListenerInnerApiTest::imc_->Close(); - TextListenerInnerApiTest::imc_->SendKeyboardStatus(status); - EXPECT_NE(TextListener::keyboardStatus_, static_cast(status)); + TextListenerInnerApiTest::imc_->SendKeyboardStatus(KeyboardStatus::HIDE); + EXPECT_TRUE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::NONE)); } /** -- Gitee From 87f56968dc609158da2116b7e162fdb7d8af7744 Mon Sep 17 00:00:00 2001 From: cy7717 Date: Fri, 27 Oct 2023 14:41:58 +0800 Subject: [PATCH 6/6] mod Signed-off-by: cy7717 --- .../include/input_method_ability.h | 1 + .../inputmethod_ability/include/panel_info.h | 6 +- .../src/input_method_ability.cpp | 117 +++++++++--------- .../src/itypes_util.cpp | 40 +++--- .../input_method_ability_exception_test.cpp | 3 + .../src/input_method_ability_test.cpp | 50 +++++--- 6 files changed, 120 insertions(+), 97 deletions(-) diff --git a/frameworks/native/inputmethod_ability/include/input_method_ability.h b/frameworks/native/inputmethod_ability/include/input_method_ability.h index c4ac3011..7a4ead9c 100644 --- a/frameworks/native/inputmethod_ability/include/input_method_ability.h +++ b/frameworks/native/inputmethod_ability/include/input_method_ability.h @@ -122,6 +122,7 @@ private: void OnConfigurationChange(Message *msg); void OnTextConfigChange(const TextTotalConfig &textConfig); + int32_t HideKeyboard(Trigger trigger); std::shared_ptr GetSoftKeyboardPanel(); int32_t ShowPanel(const std::shared_ptr &inputMethodPanel, Trigger trigger); int32_t HidePanel(const std::shared_ptr &inputMethodPanel, Trigger trigger); diff --git a/frameworks/native/inputmethod_ability/include/panel_info.h b/frameworks/native/inputmethod_ability/include/panel_info.h index f9938b6a..7ac622ff 100644 --- a/frameworks/native/inputmethod_ability/include/panel_info.h +++ b/frameworks/native/inputmethod_ability/include/panel_info.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef INPUT_METHOD_PANEL_INFO_H -#define INPUT_METHOD_PANEL_INFO_H +#ifndef INPUTMETHOD_IMF_PANEL_INFO_H +#define INPUTMETHOD_IMF_PANEL_INFO_H namespace OHOS { namespace MiscServices { @@ -36,4 +36,4 @@ struct PanelInfo { } // namespace MiscServices } // namespace OHOS -#endif //INPUT_METHOD_PANEL_INFO_H +#endif // INPUTMETHOD_IMF_PANEL_INFO_H diff --git a/frameworks/native/inputmethod_ability/src/input_method_ability.cpp b/frameworks/native/inputmethod_ability/src/input_method_ability.cpp index c733856e..4f0eac26 100644 --- a/frameworks/native/inputmethod_ability/src/input_method_ability.cpp +++ b/frameworks/native/inputmethod_ability/src/input_method_ability.cpp @@ -467,34 +467,7 @@ void InputMethodAbility::OnTextConfigChange(const TextTotalConfig &textConfig) int32_t InputMethodAbility::HideKeyboard() { - IMSA_HILOGI("InputMethodAbility::HideKeyboard"); - if (imeListener_ == nullptr) { - IMSA_HILOGE("InputMethodAbility::HideKeyboard imeListener_ is nullptr"); - return ErrorCode::ERROR_IME; - } - auto channel = GetInputDataChannelProxy(); - if (channel == nullptr) { - IMSA_HILOGE("InputMethodAbility::channel is nullptr"); - return ErrorCode::ERROR_CLIENT_NULL_POINTER; - } - - if (isPanelKeyboard_.load()) { - auto panel = GetSoftKeyboardPanel(); - if (panel == nullptr) { - return ErrorCode::ERROR_IME; - } - auto flag = panel->GetPanelFlag(); - imeListener_->OnKeyboardStatus(false); - if (flag == FLG_CANDIDATE_COLUMN) { - IMSA_HILOGD("panel flag is candidate, no need to hide."); - return ErrorCode::NO_ERROR; - } - return HidePanel(panel, Trigger::IMF); - } - - channel->SendKeyboardStatus(KeyboardStatus::HIDE); - imeListener_->OnKeyboardStatus(false); - return ErrorCode::NO_ERROR; + return HideKeyboard(Trigger::IMF); } int32_t InputMethodAbility::InsertText(const std::string text) @@ -542,23 +515,11 @@ int32_t InputMethodAbility::SendFunctionKey(int32_t funcKey) int32_t InputMethodAbility::HideKeyboardSelf() { - auto channel = GetInputDataChannelProxy(); - if (channel == nullptr) { - IMSA_HILOGE("channel is nullptr"); - return ErrorCode::ERROR_CLIENT_NULL_POINTER; - } - if (imeListener_ == nullptr) { - IMSA_HILOGE("imeListener_ is nullptr"); - return ErrorCode::NO_ERROR; - } - imeListener_->OnKeyboardStatus(false); - channel->SendKeyboardStatus(KeyboardStatus::HIDE); - auto controlChannel = GetInputControlChannel(); - if (controlChannel != nullptr) { - controlChannel->HideKeyboardSelf(); + auto ret = HideKeyboard(Trigger::IME_APP); + if (ret == ErrorCode::NO_ERROR) { + InputMethodSysEvent::GetInstance().OperateSoftkeyboardBehaviour(OperateIMEInfoCode::IME_HIDE_SELF); } - InputMethodSysEvent::GetInstance().OperateSoftkeyboardBehaviour(OperateIMEInfoCode::IME_HIDE_SELF); - return ErrorCode::NO_ERROR; + return ret == ErrorCode::ERROR_CLIENT_NULL_POINTER ? ret : ErrorCode::NO_ERROR; } int32_t InputMethodAbility::SendExtendAction(int32_t action) @@ -822,6 +783,58 @@ int32_t InputMethodAbility::HidePanel(const std::shared_ptr &i return ret; } +int32_t InputMethodAbility::HideKeyboard(Trigger trigger) +{ + IMSA_HILOGI("InputMethodAbility::HideKeyboard"); + if (imeListener_ == nullptr) { + IMSA_HILOGE("InputMethodAbility::HideKeyboard imeListener_ is nullptr"); + return ErrorCode::ERROR_IME; + } + auto channel = GetInputDataChannelProxy(); + if (channel == nullptr) { + IMSA_HILOGE("InputMethodAbility::channel is nullptr"); + return ErrorCode::ERROR_CLIENT_NULL_POINTER; + } + + if (isPanelKeyboard_.load()) { + auto panel = GetSoftKeyboardPanel(); + if (panel == nullptr) { + return ErrorCode::ERROR_IME; + } + auto flag = panel->GetPanelFlag(); + imeListener_->OnKeyboardStatus(false); + if (flag == FLG_CANDIDATE_COLUMN) { + IMSA_HILOGD("panel flag is candidate, no need to hide."); + return ErrorCode::NO_ERROR; + } + return HidePanel(panel, trigger); + } + + channel->SendKeyboardStatus(KeyboardStatus::HIDE); + imeListener_->OnKeyboardStatus(false); + auto controlChannel = GetInputControlChannel(); + if (controlChannel != nullptr && trigger == Trigger::IME_APP) { + controlChannel->HideKeyboardSelf(); + } + return ErrorCode::NO_ERROR; +} + +std::shared_ptr InputMethodAbility::GetSoftKeyboardPanel() +{ + IMSA_HILOGD("find SOFT_KEYBOARD panel."); + if (!BlockRetry(FIND_PANEL_RETRY_INTERVAL, MAX_RETRY_TIMES, + [this]() -> bool { return panels_.Find(SOFT_KEYBOARD).first; })) { + IMSA_HILOGE("SOFT_KEYBOARD panel not found"); + return nullptr; + } + auto result = panels_.Find(SOFT_KEYBOARD); + if (!result.first) { + IMSA_HILOGE("SOFT_KEYBOARD panel not found"); + return nullptr; + } + return result.second; +} + bool InputMethodAbility::IsCurrentIme() { IMSA_HILOGD("InputMethodAbility, in"); @@ -851,21 +864,5 @@ int32_t InputMethodAbility::ExitCurrentInputType() } return proxy->ExitCurrentInputType(); } - -std::shared_ptr InputMethodAbility::GetSoftKeyboardPanel() -{ - IMSA_HILOGD("find SOFT_KEYBOARD panel."); - if (!BlockRetry(FIND_PANEL_RETRY_INTERVAL, MAX_RETRY_TIMES, - [this]() -> bool { return panels_.Find(SOFT_KEYBOARD).first; })) { - IMSA_HILOGE("SOFT_KEYBOARD panel not found"); - return nullptr; - } - auto result = panels_.Find(SOFT_KEYBOARD); - if (!result.first) { - IMSA_HILOGE("SOFT_KEYBOARD panel not found"); - return nullptr; - } - return result.second; -} } // namespace MiscServices } // namespace OHOS diff --git a/frameworks/native/inputmethod_controller/src/itypes_util.cpp b/frameworks/native/inputmethod_controller/src/itypes_util.cpp index 7d7c52f8..f57b370a 100644 --- a/frameworks/native/inputmethod_controller/src/itypes_util.cpp +++ b/frameworks/native/inputmethod_controller/src/itypes_util.cpp @@ -269,6 +269,26 @@ bool ITypesUtil::Unmarshalling(InputWindowInfo &output, MessageParcel &data) return true; } +bool ITypesUtil::Marshalling(const PanelStatusInfo &input, MessageParcel &data) +{ + return data.WriteInt32(static_cast(input.panelInfo.panelType)) + && data.WriteInt32(static_cast(input.panelInfo.panelFlag)) && data.WriteBool(input.visible) + && data.WriteInt32(static_cast(input.trigger)); +} + +bool ITypesUtil::Unmarshalling(PanelStatusInfo &output, MessageParcel &data) +{ + int32_t type = -1; + int32_t flag = -1; + bool visible = false; + int32_t trigger = -1; + if (!data.ReadInt32(type) || !data.ReadInt32(flag) || !data.ReadBool(visible) || !data.ReadInt32(trigger)) { + return false; + } + output = { { static_cast(type), static_cast(flag) }, visible, static_cast(trigger) }; + return true; +} + bool ITypesUtil::Marshalling(EventType input, MessageParcel &data) { return data.WriteUint32(static_cast(input)); @@ -316,25 +336,5 @@ bool ITypesUtil::Unmarshalling(InputType &output, MessageParcel &data) output = static_cast(ret); return true; } - -bool ITypesUtil::Marshalling(const PanelStatusInfo &input, MessageParcel &data) -{ - return data.WriteInt32(static_cast(input.panelInfo.panelType)) - && data.WriteInt32(static_cast(input.panelInfo.panelFlag)) && data.WriteBool(input.visible) - && data.WriteInt32(static_cast(input.trigger)); -} - -bool ITypesUtil::Unmarshalling(PanelStatusInfo &output, MessageParcel &data) -{ - int32_t type = -1; - int32_t flag = -1; - bool visible = false; - int32_t trigger = -1; - if (!data.ReadInt32(type) || !data.ReadInt32(flag) || !data.ReadBool(visible) || !data.ReadInt32(trigger)) { - return false; - } - output = { { static_cast(type), static_cast(flag) }, visible, static_cast(trigger) }; - return true; -} } // namespace MiscServices } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/cpp_test/src/input_method_ability_exception_test.cpp b/test/unittest/cpp_test/src/input_method_ability_exception_test.cpp index 665aaf1f..e998bcfe 100644 --- a/test/unittest/cpp_test/src/input_method_ability_exception_test.cpp +++ b/test/unittest/cpp_test/src/input_method_ability_exception_test.cpp @@ -245,8 +245,11 @@ HWTEST_F(InputMethodAbilityExceptionTest, testDispatchKeyEventException, TestSiz HWTEST_F(InputMethodAbilityExceptionTest, testHideKeyboardSelf_001, TestSize.Level0) { IMSA_HILOGI("InputMethodAbilityExceptionTest testHideKeyboardSelf_001 START"); + auto imeListener = std::make_shared(); + inputMethodAbility_->SetImeListener(imeListener); auto ret = inputMethodAbility_->HideKeyboardSelf(); EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER); + ResetMemberVar(); } /** diff --git a/test/unittest/cpp_test/src/input_method_ability_test.cpp b/test/unittest/cpp_test/src/input_method_ability_test.cpp index 164dbaaf..5ddadb2e 100644 --- a/test/unittest/cpp_test/src/input_method_ability_test.cpp +++ b/test/unittest/cpp_test/src/input_method_ability_test.cpp @@ -233,20 +233,6 @@ HWTEST_F(InputMethodAbilityTest, testHideKeyboardWithoutImeListener, TestSize.Le EXPECT_EQ(ret, ErrorCode::ERROR_IME); } -/** -* @tc.name: testHideKeyboardSelfWithoutAttach -* @tc.desc: InputMethodAbility HideKeyboardSelf Without Attach -* @tc.type: FUNC -* @tc.require: -* @tc.author: Hollokin -*/ -HWTEST_F(InputMethodAbilityTest, testHideKeyboardSelfWithoutAttach, TestSize.Level0) -{ - IMSA_HILOGI("InputMethodAbility testHideKeyboardSelfWithoutAttach START"); - auto ret = inputMethodAbility_->HideKeyboardSelf(); - EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER); -} - /** * @tc.name: testStartInputWithoutPanel * @tc.desc: InputMethodAbility StartInput Without Panel @@ -912,5 +898,41 @@ HWTEST_F(InputMethodAbilityTest, testNotifyPanelStatusInfo_004, TestSize.Level0) ret = inputMethodAbility_->DestroyPanel(panel); EXPECT_EQ(ret, ErrorCode::NO_ERROR); } + +/** +* @tc.name: testNotifyPanelStatusInfo_005 +* @tc.desc: HideKeyboardSelf +* @tc.type: FUNC +* @tc.require: +* @tc.author: chenyu +*/ +HWTEST_F(InputMethodAbilityTest, testNotifyPanelStatusInfo_005, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodAbility testNotifyPanelStatusInfo_005 START"); + PanelInfo info = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING }; + imc_->Attach(textListener_); + + // has no panel + TextListener::ResetParam(); + auto ret = inputMethodAbility_->HideKeyboardSelf(); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + EXPECT_TRUE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::HIDE)); + EXPECT_FALSE(TextListener::WaitNotifyPanelStatusInfoCallback({ info, false, Trigger::IME_APP })); + + auto panel = std::make_shared(); + ret = inputMethodAbility_->CreatePanel(nullptr, info, panel); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + ret = inputMethodAbility_->ShowPanel(panel); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + // has panel + TextListener::ResetParam(); + ret = inputMethodAbility_->HideKeyboardSelf(); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + EXPECT_TRUE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::HIDE)); + EXPECT_TRUE(TextListener::WaitNotifyPanelStatusInfoCallback({ info, false, Trigger::IME_APP })); + + ret = inputMethodAbility_->DestroyPanel(panel); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); +} } // namespace MiscServices } // namespace OHOS -- Gitee