mirror of
https://gitee.com/openharmony/inputmethod_imf
synced 2024-11-27 00:41:04 +00:00
modify code
Signed-off-by: zhaolinglan <zhaolinglan1@huawei.com>
This commit is contained in:
parent
9af1e6cfc6
commit
5dadc1f6e4
@ -937,7 +937,7 @@ napi_value JsTextInputClientEngine::FinishTextPreview(napi_env env, napi_callbac
|
||||
auto exec = [ctxt, traceId](AsyncCall::Context *ctx) {
|
||||
InputMethodSyncTrace tracer("JS_FinishTextPreview_Exec", traceId);
|
||||
editorQueue_.Wait(ctxt->info);
|
||||
int32_t code = InputMethodAbility::GetInstance()->FinishTextPreview();
|
||||
int32_t code = InputMethodAbility::GetInstance()->FinishTextPreview(false);
|
||||
editorQueue_.Pop();
|
||||
if (code == ErrorCode::NO_ERROR) {
|
||||
IMSA_HILOGI("exec finishTextPreview success.");
|
||||
@ -959,7 +959,7 @@ napi_value JsTextInputClientEngine::FinishTextPreviewSync(napi_env env, napi_cal
|
||||
EditorEventInfo eventInfo = { std::chrono::system_clock::now(), EditorEvent::SET_PREVIEW_TEXT };
|
||||
editorQueue_.Push(eventInfo);
|
||||
editorQueue_.Wait(eventInfo);
|
||||
int32_t ret = InputMethodAbility::GetInstance()->FinishTextPreview();
|
||||
int32_t ret = InputMethodAbility::GetInstance()->FinishTextPreview(false);
|
||||
editorQueue_.Pop();
|
||||
if (ret != ErrorCode::NO_ERROR) {
|
||||
JsUtils::ThrowException(env, JsUtils::Convert(ret), "failed to finish text preview!", TYPE_NONE);
|
||||
|
@ -92,7 +92,7 @@ public:
|
||||
bool IsDefaultIme();
|
||||
int32_t GetCallingWindowInfo(CallingWindowInfo &windowInfo);
|
||||
int32_t SetPreviewText(const std::string &text, const Range &range);
|
||||
int32_t FinishTextPreview();
|
||||
int32_t FinishTextPreview(bool isAsync);
|
||||
int32_t NotifyPanelStatus(const std::shared_ptr<InputMethodPanel> &inputMethodPanel,
|
||||
SysPanelStatus &sysPanelStatus);
|
||||
InputAttribute GetInputAttribute();
|
||||
|
@ -944,10 +944,16 @@ int32_t InputMethodAbility::HidePanel(const std::shared_ptr<InputMethodPanel> &i
|
||||
return ErrorCode::ERROR_BAD_PARAMETERS;
|
||||
}
|
||||
auto ret = inputMethodPanel->HidePanel();
|
||||
if (ret == ErrorCode::NO_ERROR) {
|
||||
NotifyPanelStatusInfo({ { inputMethodPanel->GetPanelType(), flag }, false, trigger });
|
||||
if (ret != ErrorCode::NO_ERROR) {
|
||||
IMSA_HILOGD("failed, ret: %{public}d", ret);
|
||||
return ret;
|
||||
}
|
||||
return ret;
|
||||
NotifyPanelStatusInfo({ { inputMethodPanel->GetPanelType(), flag }, false, trigger });
|
||||
// finish previewing text when soft keyboard hides
|
||||
if (inputMethodPanel->GetPanelType() == PanelType::SOFT_KEYBOARD) {
|
||||
FinishTextPreview(true);
|
||||
}
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
|
||||
int32_t InputMethodAbility::NotifyPanelStatus(
|
||||
@ -1127,16 +1133,16 @@ int32_t InputMethodAbility::IsPanelShown(const PanelInfo &panelInfo, bool &isSho
|
||||
void InputMethodAbility::OnClientInactive(const sptr<IRemoteObject> &channel)
|
||||
{
|
||||
IMSA_HILOGI("client inactive.");
|
||||
ClearDataChannel(channel);
|
||||
if (imeListener_ != nullptr) {
|
||||
imeListener_->OnInputFinish();
|
||||
}
|
||||
panels_.ForEach([](const PanelType &panelType, const std::shared_ptr<InputMethodPanel> &panel) {
|
||||
panels_.ForEach([this](const PanelType &panelType, const std::shared_ptr<InputMethodPanel> &panel) {
|
||||
if (panelType != PanelType::SOFT_KEYBOARD || panel->GetPanelFlag() != PanelFlag::FLG_FIXED) {
|
||||
panel->HidePanel();
|
||||
HidePanel(panel);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
ClearDataChannel(channel);
|
||||
}
|
||||
|
||||
void InputMethodAbility::NotifyKeyboardHeight(uint32_t panelHeight, PanelFlag panelFlag)
|
||||
@ -1207,7 +1213,7 @@ int32_t InputMethodAbility::SetPreviewText(const std::string &text, const Range
|
||||
return dataChannel->SetPreviewText(text, range);
|
||||
}
|
||||
|
||||
int32_t InputMethodAbility::FinishTextPreview()
|
||||
int32_t InputMethodAbility::FinishTextPreview(bool isAsync)
|
||||
{
|
||||
InputMethodSyncTrace tracer("IMA_FinishTextPreview");
|
||||
auto dataChannel = GetInputDataChannelProxy();
|
||||
@ -1215,7 +1221,7 @@ int32_t InputMethodAbility::FinishTextPreview()
|
||||
IMSA_HILOGE("dataChannel is nullptr!");
|
||||
return ErrorCode::ERROR_CLIENT_NULL_POINTER;
|
||||
}
|
||||
return dataChannel->FinishTextPreview();
|
||||
return dataChannel->FinishTextPreview(isAsync);
|
||||
}
|
||||
|
||||
int32_t InputMethodAbility::GetCallingWindowInfo(CallingWindowInfo &windowInfo)
|
||||
|
@ -75,7 +75,7 @@ public:
|
||||
virtual void NotifyKeyboardHeight(uint32_t height) = 0;
|
||||
virtual int32_t SendPrivateCommand(const std::unordered_map<std::string, PrivateDataValue> &privateCommand) = 0;
|
||||
virtual int32_t SetPreviewText(const std::string &text, const Range &range) = 0;
|
||||
virtual int32_t FinishTextPreview() = 0;
|
||||
virtual int32_t FinishTextPreview(bool isAsync) = 0;
|
||||
};
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
||||
|
@ -54,12 +54,13 @@ public:
|
||||
void NotifyKeyboardHeight(uint32_t height) override;
|
||||
int32_t SendPrivateCommand(const std::unordered_map<std::string, PrivateDataValue> &privateCommand) override;
|
||||
int32_t SetPreviewText(const std::string &text, const Range &range) override;
|
||||
int32_t FinishTextPreview() override;
|
||||
int32_t FinishTextPreview(bool isAsync) override;
|
||||
|
||||
private:
|
||||
static inline BrokerDelegator<InputDataChannelProxy> delegator_;
|
||||
using ParcelHandler = std::function<bool(MessageParcel &)>;
|
||||
int32_t SendRequest(int code, ParcelHandler input = nullptr, ParcelHandler output = nullptr);
|
||||
int32_t SendRequest(int code, ParcelHandler input = nullptr, ParcelHandler output = nullptr,
|
||||
MessageOption option = MessageOption::TF_SYNC);
|
||||
void GetMessageOption(int32_t code, MessageOption &option);
|
||||
};
|
||||
} // namespace MiscServices
|
||||
|
@ -56,7 +56,7 @@ public:
|
||||
void NotifyKeyboardHeight(uint32_t height) override;
|
||||
int32_t SendPrivateCommand(const std::unordered_map<std::string, PrivateDataValue> &privateCommand) override;
|
||||
int32_t SetPreviewText(const std::string &text, const Range &range) override;
|
||||
int32_t FinishTextPreview() override;
|
||||
int32_t FinishTextPreview(bool isAsync) override;
|
||||
|
||||
private:
|
||||
int32_t InvalidRequest(MessageParcel &data, MessageParcel &reply)
|
||||
|
@ -142,9 +142,13 @@ int32_t InputDataChannelProxy::SetPreviewText(const std::string &text, const Ran
|
||||
[&text, &range](MessageParcel &parcel) { return ITypesUtil::Marshal(parcel, text, range); });
|
||||
}
|
||||
|
||||
int32_t InputDataChannelProxy::FinishTextPreview()
|
||||
int32_t InputDataChannelProxy::FinishTextPreview(bool isAsync)
|
||||
{
|
||||
return SendRequest(FINISH_TEXT_PREVIEW);
|
||||
if (isAsync) {
|
||||
return SendRequest(FINISH_TEXT_PREVIEW, nullptr, nullptr, MessageOption::TF_ASYNC);
|
||||
} else {
|
||||
return SendRequest(FINISH_TEXT_PREVIEW);
|
||||
}
|
||||
}
|
||||
|
||||
void InputDataChannelProxy::GetMessageOption(int32_t code, MessageOption &option)
|
||||
@ -162,12 +166,11 @@ void InputDataChannelProxy::GetMessageOption(int32_t code, MessageOption &option
|
||||
}
|
||||
}
|
||||
|
||||
int32_t InputDataChannelProxy::SendRequest(int code, ParcelHandler input, ParcelHandler output)
|
||||
int32_t InputDataChannelProxy::SendRequest(int code, ParcelHandler input, ParcelHandler output, MessageOption option)
|
||||
{
|
||||
IMSA_HILOGD("InputDataChannelProxy run in, code = %{public}d", code);
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
GetMessageOption(code, option);
|
||||
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
|
@ -239,7 +239,8 @@ int32_t InputDataChannelStub::SetPreviewTextOnRemote(MessageParcel &data, Messag
|
||||
|
||||
int32_t InputDataChannelStub::FinishTextPreviewOnRemote(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
return reply.WriteInt32(FinishTextPreview()) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
|
||||
bool isAsync = false;
|
||||
return reply.WriteInt32(FinishTextPreview(isAsync)) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
|
||||
}
|
||||
|
||||
int32_t InputDataChannelStub::InsertText(const std::u16string &text)
|
||||
@ -340,7 +341,7 @@ int32_t InputDataChannelStub::SetPreviewText(const std::string &text, const Rang
|
||||
return InputMethodController::GetInstance()->SetPreviewText(text, range);
|
||||
}
|
||||
|
||||
int32_t InputDataChannelStub::FinishTextPreview()
|
||||
int32_t InputDataChannelStub::FinishTextPreview(bool isAsync)
|
||||
{
|
||||
return InputMethodController::GetInstance()->FinishTextPreview();
|
||||
}
|
||||
|
@ -166,20 +166,10 @@ sptr<IInputMethodSystemAbility> InputMethodController::GetSystemAbilityProxy()
|
||||
|
||||
void InputMethodController::DeactivateClient()
|
||||
{
|
||||
auto textListener = GetTextListener();
|
||||
if (textListener != nullptr && textConfig_.inputAttribute.isTextPreviewSupported) {
|
||||
IMSA_HILOGD("finish text preview.");
|
||||
textListener->FinishTextPreview();
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(clientInfoLock_);
|
||||
clientInfo_.state = ClientState::INACTIVE;
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> autoLock(agentLock_);
|
||||
agent_ = nullptr;
|
||||
agentObject_ = nullptr;
|
||||
}
|
||||
SendKeyboardStatus(KeyboardStatus::NONE);
|
||||
}
|
||||
|
||||
@ -225,8 +215,9 @@ int32_t InputMethodController::Attach(sptr<OnTextChangedListener> listener, bool
|
||||
{
|
||||
IMSA_HILOGI("isShowKeyboard %{public}d.", isShowKeyboard);
|
||||
InputMethodSyncTrace tracer("InputMethodController Attach with textConfig trace.");
|
||||
clientInfo_.isNotifyInputStart = GetTextListener() != listener;
|
||||
ClearEditorCache(clientInfo_.isNotifyInputStart);
|
||||
auto lastListener = GetTextListener();
|
||||
clientInfo_.isNotifyInputStart = lastListener != listener;
|
||||
ClearEditorCache(clientInfo_.isNotifyInputStart, lastListener);
|
||||
SetTextListener(listener);
|
||||
clientInfo_.isShowKeyboard = isShowKeyboard;
|
||||
SaveTextConfig(textConfig);
|
||||
@ -929,9 +920,14 @@ void InputMethodController::OnInputStop()
|
||||
isEditable_.store(false);
|
||||
}
|
||||
|
||||
void InputMethodController::ClearEditorCache(bool isNewEditor)
|
||||
void InputMethodController::ClearEditorCache(bool isNewEditor, sptr<OnTextChangedListener> lastListener)
|
||||
{
|
||||
IMSA_HILOGD("isNewEditor: %{public}d.", isNewEditor);
|
||||
if (isNewEditor && isBound_.load() && lastListener != nullptr
|
||||
&& textConfig_.inputAttribute.isTextPreviewSupported) {
|
||||
IMSA_HILOGD("last editor FinishTextPreview");
|
||||
lastListener->FinishTextPreview();
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(editorContentLock_);
|
||||
// reset old range when editor changes or first attach
|
||||
@ -1294,12 +1290,12 @@ int32_t InputMethodController::FinishTextPreview()
|
||||
InputMethodSyncTrace tracer("IMC_FinishTextPreview");
|
||||
IMSA_HILOGD("IMC start.");
|
||||
if (!textConfig_.inputAttribute.isTextPreviewSupported) {
|
||||
IMSA_HILOGE("text preview do not supported!");
|
||||
IMSA_HILOGD("text preview do not supported!");
|
||||
return ErrorCode::ERROR_TEXT_PREVIEW_NOT_SUPPORTED;
|
||||
}
|
||||
auto listener = GetTextListener();
|
||||
if (!IsEditable() || listener == nullptr) {
|
||||
IMSA_HILOGE("not editable or listener is nullptr!");
|
||||
if (!isBound_.load() || listener == nullptr) {
|
||||
IMSA_HILOGW("not bound or listener is nullptr!");
|
||||
return ErrorCode::ERROR_CLIENT_NOT_EDITABLE;
|
||||
}
|
||||
{
|
||||
|
@ -775,7 +775,7 @@ private:
|
||||
int32_t HideInput(sptr<IInputClient> &client);
|
||||
int32_t ReleaseInput(sptr<IInputClient> &client);
|
||||
int32_t ListInputMethodCommon(InputMethodStatus status, std::vector<Property> &props);
|
||||
void ClearEditorCache(bool isNewEditor);
|
||||
void ClearEditorCache(bool isNewEditor, sptr<OnTextChangedListener> lastListener);
|
||||
void OnRemoteSaDied(const wptr<IRemoteObject> &object);
|
||||
void RestoreListenInfoInSaDied();
|
||||
void RestoreAttachInfoInSaDied();
|
||||
|
@ -382,6 +382,10 @@ int32_t PerUserSession::OnRequestHideInput()
|
||||
if (currentClient != nullptr) {
|
||||
UpdateClientInfo(currentClient->AsObject(), { { UpdateFlag::ISSHOWKEYBOARD, false } });
|
||||
}
|
||||
auto inactiveClient = GetInactiveClient();
|
||||
if (inactiveClient != nullptr) {
|
||||
RemoveClient(inactiveClient, false);
|
||||
}
|
||||
ExitCurrentInputType();
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
@ -760,10 +764,9 @@ void PerUserSession::ReplaceCurrentClient(const sptr<IInputClient> &client)
|
||||
auto inactiveClientInfo = GetClientInfo(inactiveClient->AsObject());
|
||||
if (inactiveClientInfo != nullptr && inactiveClientInfo->pid != clientInfo->pid) {
|
||||
IMSA_HILOGI("remove inactive client: [%{public}d]", inactiveClientInfo->pid);
|
||||
RemoveClientInfo(inactiveClient->AsObject());
|
||||
RemoveClient(inactiveClient, false);
|
||||
}
|
||||
}
|
||||
SetInactiveClient(nullptr);
|
||||
}
|
||||
|
||||
void PerUserSession::SetInactiveClient(sptr<IInputClient> client)
|
||||
|
@ -1279,7 +1279,7 @@ HWTEST_F(InputMethodAbilityTest, testFinishTextPreview_001, TestSize.Level0)
|
||||
TextListener::ResetParam();
|
||||
InputMethodAbilityTest::GetIMCAttachIMA();
|
||||
InputMethodAbilityTest::imc_->textConfig_.inputAttribute.isTextPreviewSupported = true;
|
||||
auto ret = InputMethodAbilityTest::inputMethodAbility_->FinishTextPreview();
|
||||
auto ret = InputMethodAbilityTest::inputMethodAbility_->FinishTextPreview(false);
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
EXPECT_TRUE(TextListener::isFinishTextPreviewCalled_);
|
||||
InputMethodAbilityTest::GetIMCDetachIMA();
|
||||
@ -1298,7 +1298,7 @@ HWTEST_F(InputMethodAbilityTest, testFinishTextPreview_002, TestSize.Level0)
|
||||
TextListener::ResetParam();
|
||||
InputMethodAbilityTest::inputMethodAbility_->ClearDataChannel(
|
||||
InputMethodAbilityTest::inputMethodAbility_->dataChannelObject_);
|
||||
auto ret = InputMethodAbilityTest::inputMethodAbility_->FinishTextPreview();
|
||||
auto ret = InputMethodAbilityTest::inputMethodAbility_->FinishTextPreview(false);
|
||||
EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER);
|
||||
EXPECT_FALSE(TextListener::isFinishTextPreviewCalled_);
|
||||
}
|
||||
@ -1316,7 +1316,7 @@ HWTEST_F(InputMethodAbilityTest, testFinishTextPreview_003, TestSize.Level0)
|
||||
TextListener::ResetParam();
|
||||
InputMethodAbilityTest::GetIMCAttachIMA();
|
||||
InputMethodAbilityTest::imc_->textConfig_.inputAttribute.isTextPreviewSupported = false;
|
||||
auto ret = InputMethodAbilityTest::inputMethodAbility_->FinishTextPreview();
|
||||
auto ret = InputMethodAbilityTest::inputMethodAbility_->FinishTextPreview(false);
|
||||
EXPECT_EQ(ret, ErrorCode::ERROR_TEXT_PREVIEW_NOT_SUPPORTED);
|
||||
EXPECT_FALSE(TextListener::isFinishTextPreviewCalled_);
|
||||
InputMethodAbilityTest::GetIMCDetachIMA();
|
||||
|
Loading…
Reference in New Issue
Block a user