diff --git a/frameworks/js/napi/inputmethodability/js_panel.cpp b/frameworks/js/napi/inputmethodability/js_panel.cpp index 82cdf7b6aed54e17ab0998b52754451e08de41a0..594384739b03be7ee69b1d7b970a533f0cf3fee5 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()->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 = ctxt->inputMethodPanel->HidePanel(); + auto code = InputMethodAbility::GetInstance()->HidePanel(ctxt->inputMethodPanel); if (code == ErrorCode::NO_ERROR) { ctxt->SetState(napi_ok); return; diff --git a/frameworks/native/inputmethod_ability/include/input_method_ability.h b/frameworks/native/inputmethod_ability/include/input_method_ability.h index 3cfffe0e1593e177258097c43f095ba471c413d7..7a4ead9cdf1faf8b4d0f8380fd3546821e5e614d 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(); @@ -83,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; @@ -121,7 +121,13 @@ private: void OnSelectionChange(Message *msg); void OnConfigurationChange(Message *msg); void OnTextConfigChange(const TextTotalConfig &textConfig); - int32_t ShowPanelKeyboard(); + + 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); + void NotifyPanelStatusInfo(const PanelStatusInfo &info); + 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 3ba264d5397bc287258cf3e894b78d258a564b1a..7def25ea4f9543a5a88b8c6550614775dfd7caa7 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 0000000000000000000000000000000000000000..7ac622ff6b777b8a9cf644fc4b130894c34a2590 --- /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 INPUTMETHOD_IMF_PANEL_INFO_H +#define INPUTMETHOD_IMF_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 // 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 66964cc3d277bb7721e7a052632625e341df25eb..4f0eac2632fdbf66a3a703ccc73f86100dbf56b2 100644 --- a/frameworks/native/inputmethod_ability/src/input_method_ability.cpp +++ b/frameworks/native/inputmethod_ability/src/input_method_ability.cpp @@ -376,45 +376,48 @@ int32_t InputMethodAbility::ShowKeyboard() IMSA_HILOGE("InputMethodAbility, imeListener is nullptr"); return ErrorCode::ERROR_IME; } - imeListener_->OnKeyboardStatus(true); - if (isPanelKeyboard_.load()) { - auto ret = ShowPanelKeyboard(); - if (ret != ErrorCode::NO_ERROR) { - return ret; - } - } auto channel = GetInputDataChannelProxy(); if (channel == nullptr) { - IMSA_HILOGE("channel is nullptr"); + IMSA_HILOGE("InputMethodAbility::channel is nullptr"); return ErrorCode::ERROR_CLIENT_NULL_POINTER; } - channel->SendKeyboardStatus(KEYBOARD_SHOW); + if (isPanelKeyboard_.load()) { + auto panel = GetSoftKeyboardPanel(); + if (panel == nullptr) { + return ErrorCode::ERROR_IME; + } + 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); + } + + channel->SendKeyboardStatus(KeyboardStatus::SHOW); + imeListener_->OnKeyboardStatus(true); return ErrorCode::NO_ERROR; } -int32_t InputMethodAbility::ShowPanelKeyboard() +void InputMethodAbility::NotifyPanelStatusInfo(const PanelStatusInfo &info) { - 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; + // 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; } - 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 channel = GetInputDataChannelProxy(); + if (channel != nullptr) { + info.visible ? channel->SendKeyboardStatus(KeyboardStatus::SHOW) + : channel->SendKeyboardStatus(KeyboardStatus::HIDE); + channel->NotifyPanelStatusInfo(info); } - auto ret = panel->ShowPanel(); - if (ret != ErrorCode::NO_ERROR) { - IMSA_HILOGE("Show panel failed, ret = %{public}d.", ret); + + auto controlChannel = GetInputControlChannel(); + if (controlChannel != nullptr && info.trigger == Trigger::IME_APP && !info.visible) { + controlChannel->HideKeyboardSelf(); } - return ret; } void InputMethodAbility::NotifyAllTextConfig() @@ -464,31 +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; - } - imeListener_->OnKeyboardStatus(false); - auto channel = GetInputDataChannelProxy(); - if (channel == nullptr) { - IMSA_HILOGE("InputMethodAbility::HideKeyboard channel is nullptr"); - 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 HideKeyboard(Trigger::IMF); } int32_t InputMethodAbility::InsertText(const std::string text) @@ -536,18 +515,11 @@ int32_t InputMethodAbility::SendFunctionKey(int32_t funcKey) int32_t InputMethodAbility::HideKeyboardSelf() { - auto channel = GetInputDataChannelProxy(); - if (channel == nullptr) { - IMSA_HILOGE("InputMethodAbility::channel is nullptr"); - return ErrorCode::ERROR_CLIENT_NULL_POINTER; - } - auto controlChannel = GetInputControlChannel(); - if (controlChannel == nullptr) { - IMSA_HILOGE("InputMethodAbility::controlChannel is nullptr"); - return ErrorCode::ERROR_CLIENT_NULL_POINTER; + 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 controlChannel->HideKeyboardSelf(); + return ret == ErrorCode::ERROR_CLIENT_NULL_POINTER ? ret : ErrorCode::NO_ERROR; } int32_t InputMethodAbility::SendExtendAction(int32_t action) @@ -770,6 +742,99 @@ int32_t InputMethodAbility::DestroyPanel(const std::shared_ptr return ret; } +int32_t InputMethodAbility::ShowPanel(const std::shared_ptr &inputMethodPanel) +{ + return ShowPanel(inputMethodPanel, Trigger::IME_APP); +} + +int32_t InputMethodAbility::HidePanel(const std::shared_ptr &inputMethodPanel) +{ + return HidePanel(inputMethodPanel, Trigger::IME_APP); +} + +int32_t InputMethodAbility::ShowPanel(const std::shared_ptr &inputMethodPanel, Trigger trigger) +{ + 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->ShowPanel(); + if (ret == ErrorCode::NO_ERROR) { + NotifyPanelStatusInfo( + { { inputMethodPanel->GetPanelType(), inputMethodPanel->GetPanelFlag() }, true, trigger }); + } + return ret; +} + +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) { + NotifyPanelStatusInfo( + { { inputMethodPanel->GetPanelType(), inputMethodPanel->GetPanelFlag() }, false, trigger }); + } + 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"); 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 539e888c8e98a3b25d74aaa5a2a2078eb5008101..ab6d8e4ccd42b7b23727b77a7e53ee1cae823145 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, + NOTIFY_PANEL_STATUS_INFO, DATA_CHANNEL_CMD_LAST }; @@ -56,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; @@ -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 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 e440c97f2102bd8cd5db20dfbcab86f6588d5211..4f405acf0ef4abec81b4926a71f0407a6a451360 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; @@ -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 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 396f52ef8c23fe67d52509994c5878fc2533715b..db62e9eb8e93e8d1c9709423ea8703d71ae48103 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; @@ -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 NotifyPanelStatusInfo(const PanelStatusInfo &info) 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 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 }, @@ -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(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 d1fb3e58059fe8dcadc8966ae3f7a6ae80e5ba5e..8340ad5f9e14bbc1666afe6c6132a6f83325a78f 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 { @@ -95,7 +96,19 @@ struct CursorInfo { class KeyEvent { }; -enum class KeyboardStatus { NONE = 0, HIDE, SHOW }; +enum class KeyboardStatus : int32_t { NONE = 0, HIDE, SHOW }; // soft keyboard + +enum Trigger : int32_t { IME_APP, IMF, END }; +struct PanelStatusInfo { + PanelInfo panelInfo; + bool visible{ false }; + 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 { public: diff --git a/frameworks/native/inputmethod_controller/include/itypes_util.h b/frameworks/native/inputmethod_controller/include/itypes_util.h index 38891ff725160b0349fe09e5185df24874a61817..58793fc3e29b599357e8db268fad62be14fdc921 100644 --- a/frameworks/native/inputmethod_controller/include/itypes_util.h +++ b/frameworks/native/inputmethod_controller/include/itypes_util.h @@ -79,6 +79,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 bdfde64dbc467aa1ef78510005515e72251e9550..8c33ee351de0f0b0f2faf3b8d04a088252cfb52b 100644 --- a/frameworks/native/inputmethod_controller/src/input_data_channel_proxy.cpp +++ b/frameworks/native/inputmethod_controller/src/input_data_channel_proxy.cpp @@ -58,9 +58,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(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 e64327bdd92e460f14063fcd8cc79db615868bd7..09709cb4889e528c656928ae5364d922e1911829 100644 --- a/frameworks/native/inputmethod_controller/src/input_data_channel_stub.cpp +++ b/frameworks/native/inputmethod_controller/src/input_data_channel_stub.cpp @@ -114,12 +114,12 @@ 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; } - SendKeyboardStatus(status); + SendKeyboardStatus(static_cast(status)); return reply.WriteInt32(ErrorCode::NO_ERROR) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE; } @@ -196,6 +196,17 @@ int32_t InputDataChannelStub::GetTextIndexAtCursorOnRemote(MessageParcel &data, : ErrorCode::ERROR_EX_PARCELABLE; } +int32_t InputDataChannelStub::NotifyPanelStatusInfoOnRemote(MessageParcel &data, MessageParcel &reply) +{ + PanelStatusInfo info{}; + if (!ITypesUtil::Unmarshal(data, info)) { + IMSA_HILOGE("failed to read message parcel"); + return ErrorCode::ERROR_EX_PARCELABLE; + } + NotifyPanelStatusInfo(info); + 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); @@ -352,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]() { @@ -448,5 +459,19 @@ int32_t InputDataChannelStub::HandleExtendAction(int32_t action) } return ret; } + +void InputDataChannelStub::NotifyPanelStatusInfo(const PanelStatusInfo &info) +{ + auto result = std::make_shared>(MAX_TIMEOUT, false); + auto blockTask = [info, result]() { + InputMethodController::GetInstance()->NotifyPanelStatusInfo(info); + 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 2aa881c3fc3846cfa0c4357291ce79b119af41f9..ed1c0e3b681b404d6b28676107893fcd798b9aeb 100644 --- a/frameworks/native/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/native/inputmethod_controller/src/input_method_controller.cpp @@ -1000,17 +1000,33 @@ 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("KeyboardStatusNotify, 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; + } +} + +void InputMethodController::NotifyPanelStatusInfo(const PanelStatusInfo &info) +{ + IMSA_HILOGD("PanelStatusInfoNotify, 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)); + auto listener = GetTextListener(); + if (listener == nullptr) { + IMSA_HILOGE("textListener_ is nullptr"); + return; + } + listener->NotifyPanelStatusInfo(info); + if (info.panelInfo.panelType == PanelType::SOFT_KEYBOARD + && info.panelInfo.panelFlag != PanelFlag::FLG_CANDIDATE_COLUMN && !info.visible) { clientInfo_.isShowKeyboard = false; } } diff --git a/frameworks/native/inputmethod_controller/src/itypes_util.cpp b/frameworks/native/inputmethod_controller/src/itypes_util.cpp index 2d2e7dd1bb6f61cbc1f250179f4af7e1f1a54d4d..f57b370a8ccc38dd83af93a4258043d05cb69578 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)); 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 edab3660a4a0b1f1003bd957db5cb2facd7774b1..e4b44cddb62441d320968eac0120069fe3e12199 100644 --- a/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h +++ b/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h @@ -48,6 +48,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 NotifyPanelStatusInfo(const PanelStatusInfo &info) + { + } virtual void SendFunctionKey(const FunctionKey &functionKey) = 0; virtual void SetKeyboardStatus(bool status) = 0; virtual void MoveCursor(const Direction direction) = 0; @@ -581,7 +584,18 @@ 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. + * + * 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 info Indicates the status info of panel. + * @since 11 + */ + IMF_API void NotifyPanelStatusInfo(const PanelStatusInfo &info); /** * @brief Send function key. diff --git a/services/include/peruser_session.h b/services/include/peruser_session.h index 9aa7970482276f03e2df881f4b96d1d82e4342b2..477cbe0d75c6d6316755609b15d27b96b1f8d54b 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 46d8755a8ae552ac31e52f380a6cb06af37fc9ab..eeeb1f270e8b54a26ed8f3ea78f4092f3432469c 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -660,7 +660,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 014b030da1d92706fab07621ce695323b8dedc59..4e27318c1cee368dec6d8b929e522aa987b0ddff 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 diff --git a/test/common/include/text_listener.h b/test/common/include/text_listener.h index 1a9fdfa8eb0bd55eb4927e919f7be3fa5d28f027..8d61071f210e0aa7daf0a627b7fa82c36c2f10b9 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 30ea316b628575eab5d2bffdb983720d6bb9e9ba..f7310f85e4ba75b0afc33b93f6db0f86476746e8 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 5a1ccbe3048ab167a2647a94cb929be830127a1c..e998bcfe0cf0d6a5334933803abd6d88eacb4361 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(); } /** @@ -329,6 +332,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 4405815ef6cb673875bdf184433b4b2f76153cfd..5ddadb2e366b54eb0a2c425f25e72d32e9b49872 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; @@ -200,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 @@ -244,9 +263,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()); @@ -396,16 +413,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; } /** @@ -771,5 +786,153 @@ 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); +} + +/** +* @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 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 bc1f587dc5e9beb885f8d6e5af5d28ebfcafd0de..049e16d42f678d14caac180329be7d129ed1bb54 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 06eb3fccbf748da4c485cc475dcadcb05f118f75..bb7f2b791db5ca4329590f9592b49e7394d7c90a 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 6ab2075cbeac3ab3db9eda8e899ad1e068d01035..4d19117a8a3ace8d2b0548b6ed578cd1253e6807 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 747b7ad625a5d8889bc738885df9f679ca4ae608..65f03de80549d0ee6489242cd306576b1113343a 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)); } /**