!929 panel显示隐藏回调editor panelStatusInfo

Merge pull request !929 from cy7717/master
This commit is contained in:
openharmony_ci 2023-10-27 11:10:38 +00:00 committed by Gitee
commit 2a188f4593
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
24 changed files with 512 additions and 157 deletions

View File

@ -200,7 +200,7 @@ napi_value JsPanel::Show(napi_env env, napi_callback_info info)
auto ctxt = std::make_shared<PanelContentContext>(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<PanelContentContext>(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;

View File

@ -75,6 +75,8 @@ public:
int32_t CreatePanel(const std::shared_ptr<AbilityRuntime::Context> &context, const PanelInfo &panelInfo,
std::shared_ptr<InputMethodPanel> &inputMethodPanel);
int32_t DestroyPanel(const std::shared_ptr<InputMethodPanel> &inputMethodPanel);
int32_t ShowPanel(const std::shared_ptr<InputMethodPanel> &inputMethodPanel);
int32_t HidePanel(const std::shared_ptr<InputMethodPanel> &inputMethodPanel);
bool IsCurrentIme();
bool IsEnable();
int32_t ExitCurrentInputType();
@ -84,8 +86,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<InputControlChannelProxy> controlChannel_ = nullptr;
@ -122,7 +122,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<InputMethodPanel> GetSoftKeyboardPanel();
int32_t ShowPanel(const std::shared_ptr<InputMethodPanel> &inputMethodPanel, Trigger trigger);
int32_t HidePanel(const std::shared_ptr<InputMethodPanel> &inputMethodPanel, Trigger trigger);
void NotifyPanelStatusInfo(const PanelStatusInfo &info);
ConcurrentMap<PanelType, std::shared_ptr<InputMethodPanel>> panels_{};
std::atomic_bool isPanelKeyboard_{ false };
std::atomic_bool isBound_{ false };

View File

@ -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;
// 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 result = panels_.Find(SOFT_KEYBOARD);
if (!result.first) {
IMSA_HILOGE("SOFT_KEYBOARD panel not found");
return ErrorCode::ERROR_OPERATE_PANEL;
auto channel = GetInputDataChannelProxy();
if (channel != nullptr) {
info.visible ? channel->SendKeyboardStatus(KeyboardStatus::SHOW)
: channel->SendKeyboardStatus(KeyboardStatus::HIDE);
channel->NotifyPanelStatusInfo(info);
}
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 controlChannel = GetInputControlChannel();
if (controlChannel != nullptr && info.trigger == Trigger::IME_APP && !info.visible) {
controlChannel->HideKeyboardSelf();
}
auto ret = panel->ShowPanel();
if (ret != ErrorCode::NO_ERROR) {
IMSA_HILOGE("Show panel failed, ret = %{public}d.", ret);
}
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 ret = HideKeyboard(Trigger::IME_APP);
if (ret == ErrorCode::NO_ERROR) {
InputMethodSysEvent::GetInstance().OperateSoftkeyboardBehaviour(OperateIMEInfoCode::IME_HIDE_SELF);
}
auto controlChannel = GetInputControlChannel();
if (controlChannel == nullptr) {
IMSA_HILOGE("InputMethodAbility::controlChannel is nullptr");
return ErrorCode::ERROR_CLIENT_NULL_POINTER;
}
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<InputMethodPanel>
return ret;
}
int32_t InputMethodAbility::ShowPanel(const std::shared_ptr<InputMethodPanel> &inputMethodPanel)
{
return ShowPanel(inputMethodPanel, Trigger::IME_APP);
}
int32_t InputMethodAbility::HidePanel(const std::shared_ptr<InputMethodPanel> &inputMethodPanel)
{
return HidePanel(inputMethodPanel, Trigger::IME_APP);
}
int32_t InputMethodAbility::ShowPanel(const std::shared_ptr<InputMethodPanel> &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> &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<InputMethodPanel> 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");

View File

@ -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

View File

@ -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<InputDataChannelProxy> delegator_;

View File

@ -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<class T> 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<int32_t, RequestHandler> HANDLERS = {
{ static_cast<uint32_t>(INSERT_TEXT), &InputDataChannelStub::InsertTextOnRemote },
@ -91,6 +93,7 @@ private:
{ static_cast<uint32_t>(HANDLE_EXTEND_ACTION), &InputDataChannelStub::HandleExtendActionOnRemote },
{ static_cast<uint32_t>(GET_TEXT_INDEX_AT_CURSOR), &InputDataChannelStub::GetTextIndexAtCursorOnRemote },
{ static_cast<uint32_t>(GET_TEXT_CONFIG), &InputDataChannelStub::GetTextConfigOnRemote },
{ static_cast<uint32_t>(NOTIFY_PANEL_STATUS_INFO), &InputDataChannelStub::NotifyPanelStatusInfoOnRemote },
};
};
} // namespace MiscServices

View File

@ -19,6 +19,7 @@
#include <stdint.h>
#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:

View File

@ -80,6 +80,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);

View File

@ -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<int32_t>(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)

View File

@ -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<KeyboardStatus>(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<BlockData<int32_t>>(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<BlockData<bool>>(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<BlockData<bool>>(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

View File

@ -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<int32_t>(status));
auto listener = GetTextListener();
if (listener == nullptr) {
IMSA_HILOGE("textListener_ is nullptr");
return;
}
auto keyboardStatus = static_cast<KeyboardStatus>(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<PanelType>(info.panelInfo.panelType), static_cast<PanelFlag>(info.panelInfo.panelFlag),
info.visible, static_cast<Trigger>(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;
}
}

View File

@ -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<int32_t>(input.panelInfo.panelType))
&& data.WriteInt32(static_cast<int32_t>(input.panelInfo.panelFlag)) && data.WriteBool(input.visible)
&& data.WriteInt32(static_cast<int32_t>(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<PanelType>(type), static_cast<PanelFlag>(flag) }, visible, static_cast<Trigger>(trigger) };
return true;
}
bool ITypesUtil::Marshalling(EventType input, MessageParcel &data)
{
return data.WriteUint32(static_cast<uint32_t>(input));

View File

@ -49,6 +49,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;
@ -582,7 +585,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.

View File

@ -75,6 +75,7 @@ public:
int32_t OnShowCurrentInput();
int32_t OnShowInput(sptr<IInputClient> client);
int32_t OnHideInput(sptr<IInputClient> client);
void OnHideSoftKeyBoardSelf();
void StopInputService();
void NotifyImeChangeToClients(const Property &property, const SubProperty &subProperty);
int32_t SwitchSubtype(const SubProperty &subProperty);

View File

@ -669,7 +669,7 @@ void InputMethodSystemAbility::WorkThread()
break;
}
case MSG_ID_HIDE_KEYBOARD_SELF: {
userSession_->OnHideCurrentInput();
userSession_->OnHideSoftKeyBoardSelf();
break;
}
default: {

View File

@ -294,6 +294,18 @@ int32_t PerUserSession::OnShowInput(sptr<IInputClient> client)
return ShowKeyboard(client);
}
void PerUserSession::OnHideSoftKeyBoardSelf()
{
IMSA_HILOGD("run in");
sptr<IInputClient> 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

View File

@ -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<AppExecFwk::EventHandler> serviceHandler_;
static constexpr int32_t MAX_TIMEOUT = 2700000;

View File

@ -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<int>(keyboardStatus));
constexpr int32_t interval = 20;
{
std::unique_lock<std::mutex> 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<PanelType>(info.panelInfo.panelType), static_cast<PanelFlag>(info.panelInfo.panelFlag),
info.visible, static_cast<Trigger>(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<std::mutex> lock(textListenerCallbackLock_);
return TextListener::textListenerCv_.wait_for(lock, std::chrono::seconds(1)) != std::cv_status::timeout;
textListenerCv_.wait_for(
lock, std::chrono::seconds(1), [&keyboardStatus]() { return keyboardStatus == keyboardStatus_; });
return keyboardStatus == keyboardStatus_;
}
bool TextListener::WaitNotifyPanelStatusInfoCallback(const PanelStatusInfo &info)
{
std::unique_lock<std::mutex> lock(textListenerCallbackLock_);
textListenerCv_.wait_for(lock, std::chrono::seconds(1), [info]() { return info == info_; });
return info == info_;
}
} // namespace MiscServices
} // namespace OHOS

View File

@ -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<InputMethodEngineListenerImpl>();
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<InputMethodPanel>();
panel->panelFlag_ = FLG_CANDIDATE_COLUMN;
inputMethodAbility_->panels_.Insert(SOFT_KEYBOARD, panel);
inputMethodAbility_->isPanelKeyboard_ = true;
ret = inputMethodAbility_->HideKeyboard();
EXPECT_EQ(ret, ErrorCode::NO_ERROR);

View File

@ -52,6 +52,7 @@ public:
static bool showKeyboard_;
static constexpr int CURSOR_DIRECTION_BASE_VALUE = 2011;
static sptr<InputMethodController> imc_;
static sptr<OnTextChangedListener> textListener_;
static sptr<InputMethodAbility> 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<InputMethodPanel> &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<InputMethodController> InputMethodAbilityTest::imc_;
sptr<OnTextChangedListener> InputMethodAbilityTest::textListener_;
sptr<InputMethodAbility> 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<OnTextChangedListener> textListener = new TextListener();
imc_ = InputMethodController::GetInstance();
imc_->Attach(textListener);
imc_->Attach(textListener_);
std::unique_lock<std::mutex> lock(InputMethodAbilityTest::imeListenerCallbackLock_);
InputMethodAbilityTest::showKeyboard_ = true;
inputMethodAbility_->SetImeListener(std::make_shared<InputMethodEngineListenerImpl>());
@ -396,16 +413,14 @@ HWTEST_F(InputMethodAbilityTest, testGetEnterKeyType, TestSize.Level0)
HWTEST_F(InputMethodAbilityTest, testGetTextConfig, TestSize.Level0)
{
IMSA_HILOGI("InputMethodAbility testGetTextConfig START");
sptr<OnTextChangedListener> 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<InputMethodPanel>();
auto ret = inputMethodAbility_->CreatePanel(nullptr, info, panel);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
auto panel1 = std::make_shared<InputMethodPanel>();
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<InputMethodPanel>();
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<InputMethodPanel>();
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<InputMethodPanel>();
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<InputMethodPanel>();
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

View File

@ -232,13 +232,13 @@ HWTEST_F(InputMethodAttachTest, testAttach006, TestSize.Level0)
sptr<OnTextChangedListener> 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));
}
/**

View File

@ -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();

View File

@ -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);

View File

@ -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<KeyboardStatus>(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<KeyboardStatus>(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<KeyboardStatus>(status));
TextListenerInnerApiTest::imc_->SendKeyboardStatus(KeyboardStatus::HIDE);
EXPECT_TRUE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::NONE));
}
/**