diff --git a/BUILD.gn b/BUILD.gn index 30af9cd2..c8dbfd35 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -24,7 +24,7 @@ group("imf_packages") { "frameworks/inputmethod_ability:inputmethod_ability", "frameworks/inputmethod_controller:inputmethod_client", "interfaces/kits/js/declaration:inputmethod", - "interfaces/kits/js/napi/inputmethod:inputmethod", + "interfaces/kits/js/napi/inputmethodclient:inputmethod", "interfaces/kits/js/napi/inputmethodengine:inputmethodengine", "profile:inputmethod_inputmethod_sa_profiles", "services:inputmethod_service", diff --git a/bundle.json b/bundle.json index 7536698e..d065e614 100644 --- a/bundle.json +++ b/bundle.json @@ -57,7 +57,7 @@ "//base/inputmethod/imf/frameworks/kits/extension:inputmethod_extension", "//base/inputmethod/imf/frameworks/kits/extension:inputmethod_extension_module", "//base/inputmethod/imf/interfaces/kits/js/declaration:inputmethod", - "//base/inputmethod/imf/interfaces/kits/js/napi/inputmethod:inputmethod", + "//base/inputmethod/imf/interfaces/kits/js/napi/inputmethodclient:inputmethod", "//base/inputmethod/imf/interfaces/kits/js/napi/inputmethodengine:inputmethodengine", "//base/inputmethod/imf/interfaces/kits/js/napi/inputmethod_extension_ability:inputmethodextensionability_napi", "//base/inputmethod/imf/interfaces/kits/js/napi/inputmethod_extension_context:inputmethodextensioncontext_napi", @@ -103,33 +103,6 @@ ], "header_base": "//base/inputmethod/imf/frameworks/inputmethod_ability/include" } - }, - { - "name": "//base/inputmethod/imf/interfaces/kits/js/napi/inputmethod:inputmethod", - "header": { - "header_files": [ - "js_input_method_registry.h", - "js_input_method_utils.h", - "js_input_method_setting.h", - "js_input_method_controller.h" - ], - "header_base": "//base/inputmethod/imf/interfaces/kits/js/napi/inputmethod/include" - } - }, - { - "name": "//base/inputmethod/imf/interfaces/kits/js/napi/inputmethodengine:inputmethodengine", - "header": { - "header_files": [ - "js_input_method_engine_registry.h", - "js_input_method_engine_listener.h", - "js_input_method_engine.h", - "js_input_method_engine_utils.h", - "js_keyboard_controller.h", - "js_text_input_client.h", - "js_keyboard_delegate.h" - ], - "header_base": "//base/inputmethod/imf/interfaces/kits/js/napi/inputmethodengine/include" - } } ], "test": [ diff --git a/frameworks/inputmethod_ability/include/i_input_method_core.h b/frameworks/inputmethod_ability/include/i_input_method_core.h index 112aaac4..a19d604f 100644 --- a/frameworks/inputmethod_ability/include/i_input_method_core.h +++ b/frameworks/inputmethod_ability/include/i_input_method_core.h @@ -53,7 +53,7 @@ namespace MiscServices { const InputAttribute& editorAttribute, bool supportPhysicalKbd) = 0; virtual int32_t stopInput() = 0; - virtual bool showKeyboard(const sptr& inputDataChannel) = 0; + virtual bool showKeyboard(const sptr& inputDataChannel, bool isShowKeyboard) = 0; virtual bool hideKeyboard(int32_t flags) = 0; virtual int32_t setKeyboardType(const KeyboardType& type) = 0; virtual int32_t getKeyboardWindowHeight(int32_t &retHeight) = 0; diff --git a/frameworks/inputmethod_ability/include/input_method_ability.h b/frameworks/inputmethod_ability/include/input_method_ability.h index 5f5c54b5..639b7941 100644 --- a/frameworks/inputmethod_ability/include/input_method_ability.h +++ b/frameworks/inputmethod_ability/include/input_method_ability.h @@ -107,7 +107,7 @@ namespace MiscServices { void OnSelectionChange(Message *msg); void InitialInputWindow(); - void ShowInputWindow(); + void ShowInputWindow(bool isShowKeyboard); void DissmissInputWindow(); }; } // namespace MiscServices diff --git a/frameworks/inputmethod_ability/include/input_method_core_proxy.h b/frameworks/inputmethod_ability/include/input_method_core_proxy.h index 9a1770b1..5b07fd2f 100644 --- a/frameworks/inputmethod_ability/include/input_method_core_proxy.h +++ b/frameworks/inputmethod_ability/include/input_method_core_proxy.h @@ -40,7 +40,7 @@ namespace MiscServices { const InputAttribute& editorAttribute, bool supportPhysicalKbd) override; int32_t stopInput() override; - bool showKeyboard(const sptr& inputDataChannel) override; + bool showKeyboard(const sptr& inputDataChannel, bool isShowKeyboard) override; bool hideKeyboard(int32_t flags) override; int32_t setKeyboardType(const KeyboardType& type) override; int32_t getKeyboardWindowHeight(int32_t &retHeight) override; diff --git a/frameworks/inputmethod_ability/include/input_method_core_stub.h b/frameworks/inputmethod_ability/include/input_method_core_stub.h index 0e680564..61d64167 100644 --- a/frameworks/inputmethod_ability/include/input_method_core_stub.h +++ b/frameworks/inputmethod_ability/include/input_method_core_stub.h @@ -49,7 +49,7 @@ namespace MiscServices { const InputAttribute& editorAttribute, bool supportPhysicalKbd) override; int32_t stopInput() override; - bool showKeyboard(const sptr& inputDataChannel) override; + bool showKeyboard(const sptr& inputDataChannel, bool isShowKeyboard) override; bool hideKeyboard(int32_t flags)override; int32_t setKeyboardType(const KeyboardType& type) override; int32_t getKeyboardWindowHeight(int32_t &retHeight) override; diff --git a/frameworks/inputmethod_ability/src/input_method_ability.cpp b/frameworks/inputmethod_ability/src/input_method_ability.cpp index f8dbb06b..61d08c05 100644 --- a/frameworks/inputmethod_ability/src/input_method_ability.cpp +++ b/frameworks/inputmethod_ability/src/input_method_ability.cpp @@ -243,7 +243,8 @@ namespace MiscServices { return; } SetInputDataChannel(channelObject); - ShowInputWindow(); + bool isShowKeyboard = data->ReadBool(); + ShowInputWindow(isShowKeyboard); } void InputMethodAbility::OnHideKeyboard(Message *msg) @@ -321,7 +322,7 @@ namespace MiscServices { kdListener_->OnSelectionChange(oldBegin, oldEnd, newBegin, newEnd); } - void InputMethodAbility::ShowInputWindow() + void InputMethodAbility::ShowInputWindow(bool isShowKeyboard) { IMSA_HILOGI("InputMethodAbility::ShowInputWindow"); if (!imeListener_) { @@ -329,6 +330,10 @@ namespace MiscServices { return; } imeListener_->OnInputStart(); + if (!isShowKeyboard) { + IMSA_HILOGI("InputMethodAbility::ShowInputWindow will not show keyboard"); + return; + } imeListener_->OnKeyboardStatus(true); std::shared_ptr channel = GetInputDataChannel(); if (channel == nullptr) { diff --git a/frameworks/inputmethod_ability/src/input_method_core_proxy.cpp b/frameworks/inputmethod_ability/src/input_method_core_proxy.cpp index a977547b..a310a1b6 100644 --- a/frameworks/inputmethod_ability/src/input_method_core_proxy.cpp +++ b/frameworks/inputmethod_ability/src/input_method_core_proxy.cpp @@ -193,7 +193,7 @@ namespace MiscServices { return reply.ReadInt32(); } - bool InputMethodCoreProxy::showKeyboard(const sptr &inputDataChannel) + bool InputMethodCoreProxy::showKeyboard(const sptr &inputDataChannel, bool isShowKeyboard) { IMSA_HILOGI("InputMethodCoreProxy::showKeyboard"); auto remote = Remote(); @@ -203,14 +203,12 @@ namespace MiscServices { } MessageParcel data; - if (!(data.WriteInterfaceToken(GetDescriptor()) - && data.WriteRemoteObject(inputDataChannel->AsObject()))) { + if (!(data.WriteInterfaceToken(GetDescriptor()) && data.WriteRemoteObject(inputDataChannel->AsObject()) + && data.WriteBool(isShowKeyboard))) { return false; } MessageParcel reply; - MessageOption option { - MessageOption::TF_SYNC - }; + MessageOption option { MessageOption::TF_SYNC }; int32_t res = remote->SendRequest(SHOW_KEYBOARD, data, reply, option); if (res != ErrorCode::NO_ERROR) { diff --git a/frameworks/inputmethod_ability/src/input_method_core_stub.cpp b/frameworks/inputmethod_ability/src/input_method_core_stub.cpp index 0882cda4..575cb0a2 100644 --- a/frameworks/inputmethod_ability/src/input_method_core_stub.cpp +++ b/frameworks/inputmethod_ability/src/input_method_core_stub.cpp @@ -110,7 +110,8 @@ namespace MiscServices { } case SHOW_KEYBOARD: { sptr inputDataChannel = iface_cast(data.ReadRemoteObject()); - showKeyboard(inputDataChannel); + bool isShowKeyboard = data.ReadBool(); + showKeyboard(inputDataChannel, isShowKeyboard); reply.WriteNoException(); break; } @@ -230,19 +231,27 @@ namespace MiscServices { msgHandler_->SendMessage(msg); } - bool InputMethodCoreStub::showKeyboard(const sptr& inputDataChannel) + bool InputMethodCoreStub::showKeyboard(const sptr& inputDataChannel, bool isShowKeyboard) { IMSA_HILOGI("InputMethodCoreStub::showKeyboard"); if (!msgHandler_) { return false; } - MessageParcel *data = new MessageParcel(); + auto *data = new (std::nothrow) MessageParcel(); + if (data == nullptr) { + return false; + } + IMSA_HILOGI("InputMethodCoreStub::showKeyboard isShowKeyboard %{public}s", isShowKeyboard ? "true" : "false"); if (inputDataChannel) { IMSA_HILOGI("InputMethodCoreStub::showKeyboard inputDataChannel is not nullptr"); data->WriteRemoteObject(inputDataChannel->AsObject()); + data->WriteBool(isShowKeyboard); } - Message *msg = new Message(MessageID::MSG_ID_SHOW_KEYBOARD, data); + Message *msg = new (std::nothrow) Message(MessageID::MSG_ID_SHOW_KEYBOARD, data); + if (msg == nullptr) { + return false; + } msgHandler_->SendMessage(msg); return true; } diff --git a/frameworks/inputmethod_controller/include/input_method_controller.h b/frameworks/inputmethod_controller/include/input_method_controller.h index 36473c9c..4771b643 100644 --- a/frameworks/inputmethod_controller/include/input_method_controller.h +++ b/frameworks/inputmethod_controller/include/input_method_controller.h @@ -59,6 +59,7 @@ namespace MiscServices { public: static sptr GetInstance(); void Attach(sptr &listener); + void Attach(sptr &listener, bool isShowKeyboard); std::u16string GetTextBeforeCursor(int32_t number); std::u16string GetTextAfterCursor(int32_t number); void ShowTextInput(); @@ -74,6 +75,7 @@ namespace MiscServices { int32_t GetEnterKeyType(); int32_t GetInputPattern(); int32_t HideCurrentInput(); + int32_t ShowCurrentInput(); void SetCallingWindow(uint32_t windowId); int32_t SwitchInputMethod(const InputMethodProperty &target); @@ -85,7 +87,7 @@ namespace MiscServices { sptr GetImsaProxy(); void PrepareInput(int32_t displayId, sptr &client, sptr &channel, InputAttribute &attribute); - void StartInput(sptr &client); + void StartInput(sptr &client, bool isShowKeyboard); void StopInput(sptr &client); void ReleaseInput(sptr &client); void SetInputMethodAgent(sptr &object); diff --git a/frameworks/inputmethod_controller/include/input_method_system_ability_proxy.h b/frameworks/inputmethod_controller/include/input_method_system_ability_proxy.h index b89348b1..6e47473c 100644 --- a/frameworks/inputmethod_controller/include/input_method_system_ability_proxy.h +++ b/frameworks/inputmethod_controller/include/input_method_system_ability_proxy.h @@ -50,6 +50,7 @@ namespace MiscServices { void stopInput(MessageParcel& data) override; void SetCoreAndAgent(MessageParcel& data) override; int32_t HideCurrentInput(MessageParcel& data) override; + int32_t ShowCurrentInput(MessageParcel& data) override; int32_t Prepare(int32_t displayId, sptr &client, sptr &channel, InputAttribute &attribute); diff --git a/frameworks/inputmethod_controller/src/input_method_controller.cpp b/frameworks/inputmethod_controller/src/input_method_controller.cpp index 44fe052d..aa92405e 100644 --- a/frameworks/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/inputmethod_controller/src/input_method_controller.cpp @@ -200,18 +200,24 @@ using namespace MessageID; } void InputMethodController::Attach(sptr &listener) + { + Attach(listener, true); + } + + void InputMethodController::Attach(sptr &listener, bool isShowKeyboard) { textListener = listener; IMSA_HILOGI("InputMethodController::Attach"); InputmethodTrace tracer("InputMethodController Attach trace."); - StartInput(mClient); + IMSA_HILOGI("InputMethodController::Attach isShowKeyboard %{public}s", isShowKeyboard ? "true" : "false"); + StartInput(mClient, isShowKeyboard); PrepareInput(0, mClient, mInputDataChannel, mAttribute); } void InputMethodController::ShowTextInput() { IMSA_HILOGI("InputMethodController::ShowTextInput"); - StartInput(mClient); + StartInput(mClient, true); } void InputMethodController::HideTextInput() @@ -233,6 +239,19 @@ using namespace MessageID; return mImms->HideCurrentInput(data); } + int32_t InputMethodController::ShowCurrentInput() + { + IMSA_HILOGI("InputMethodController::ShowCurrentInput"); + if (!mImms) { + return ErrorCode::ERROR_KBD_SHOW_FAILED; + } + MessageParcel data; + if (!(data.WriteInterfaceToken(mImms->GetDescriptor()))) { + return ErrorCode::ERROR_KBD_SHOW_FAILED; + } + return mImms->ShowCurrentInput(data); + } + void InputMethodController::Close() { ReleaseInput(mClient); @@ -283,15 +302,15 @@ using namespace MessageID; return properties; } - void InputMethodController::StartInput(sptr &client) + void InputMethodController::StartInput(sptr &client, bool isShowKeyboard) { IMSA_HILOGI("InputMethodController::StartInput"); if (!mImms) { return; } MessageParcel data; - if (!(data.WriteInterfaceToken(mImms->GetDescriptor()) - && data.WriteRemoteObject(client->AsObject()))) { + if (!(data.WriteInterfaceToken(mImms->GetDescriptor()) && data.WriteRemoteObject(client->AsObject()) + && data.WriteBool(isShowKeyboard))) { return; } isStopInput = false; diff --git a/frameworks/inputmethod_controller/src/input_method_system_ability_proxy.cpp b/frameworks/inputmethod_controller/src/input_method_system_ability_proxy.cpp index 954f0281..df515342 100644 --- a/frameworks/inputmethod_controller/src/input_method_system_ability_proxy.cpp +++ b/frameworks/inputmethod_controller/src/input_method_system_ability_proxy.cpp @@ -81,7 +81,7 @@ namespace MiscServices { } } - void InputMethodSystemAbilityProxy::startInput(MessageParcel& data) + void InputMethodSystemAbilityProxy::startInput(MessageParcel &data) { IMSA_HILOGI("InputMethodSystemAbilityProxy::startInput"); MessageParcel reply; @@ -155,6 +155,26 @@ namespace MiscServices { return ErrorCode::NO_ERROR; } + int32_t InputMethodSystemAbilityProxy::ShowCurrentInput(MessageParcel &data) + { + IMSA_HILOGI("InputMethodSystemAbilityProxy::ShowCurrentInput"); + MessageParcel reply; + MessageOption option; + + auto ret = Remote()->SendRequest(SHOW_CURRENT_INPUT, data, reply, option); + if (ret != NO_ERROR) { + IMSA_HILOGI("InputMethodSystemAbilityProxy::ShowCurrentInput SendRequest failed"); + return ErrorCode::ERROR_KBD_SHOW_FAILED; + } + + ret = reply.ReadInt32(); + if (ret != NO_ERROR) { + IMSA_HILOGI("InputMethodSystemAbilityProxy::ShowCurrentInput reply failed"); + return ErrorCode::ERROR_KBD_SHOW_FAILED; + } + return ErrorCode::NO_ERROR; + } + int32_t InputMethodSystemAbilityProxy::Prepare(int32_t displayId, sptr &client, sptr &channel, InputAttribute &attribute) { diff --git a/interfaces/kits/js/declaration/@ohos.inputmethod.d.ts b/interfaces/kits/js/declaration/@ohos.inputmethod.d.ts index babe470d..b28b69f3 100644 --- a/interfaces/kits/js/declaration/@ohos.inputmethod.d.ts +++ b/interfaces/kits/js/declaration/@ohos.inputmethod.d.ts @@ -117,6 +117,48 @@ declare namespace inputMethod { stopInput(callback: AsyncCallback): void; stopInput(): Promise; + + /** + * Show soft keyboard + * @since 9 + * @param callback + * @return : + * if true, success. + * if false, fail. + * @syscap SystemCapability.MiscServices.InputMethodFramework + */ + showSoftKeyboard(callback: AsyncCallback): void; + + /** + * Show soft keyboard + * @since 9 + * @return : + * if true, success. + * if false, fail. + * @syscap SystemCapability.MiscServices.InputMethodFramework + */ + showSoftKeyboard():Promise; + + /** + * Hide soft keyboard + * @since 9 + * @param callback + * @return : + * if true, success. + * if false, fail. + * @syscap SystemCapability.MiscServices.InputMethodFramework + */ + hideSoftKeyboard(callback: AsyncCallback): void; + + /** + * Hide soft keyboard + * @since 9 + * @return : + * if true, success. + * if false, fail. + * @syscap SystemCapability.MiscServices.InputMethodFramework + */ + hideSoftKeyboard():Promise; } /** diff --git a/interfaces/kits/js/napi/inputmethodclient/BUILD.gn b/interfaces/kits/js/napi/inputmethodclient/BUILD.gn new file mode 100644 index 00000000..716626a9 --- /dev/null +++ b/interfaces/kits/js/napi/inputmethodclient/BUILD.gn @@ -0,0 +1,75 @@ +# Copyright (C) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//base/inputmethod/imf/inputmethod.gni") +import("//build/ohos.gni") + +config("imf_config") { + visibility = [ ":*" ] + include_dirs = [ "include" ] +} + +config("imf_public_config") { + visibility = [] + include_dirs = [ + "include", + "${inputmethod_path}/frameworks/inputmethod_controller/include", + "${inputmethod_path}/services/dfx/include", + ] +} + +ohos_shared_library("inputmethod") { + sources = [ + "${inputmethod_path}/frameworks/inputmethod_controller/src/input_client_stub.cpp", + "${inputmethod_path}/frameworks/inputmethod_controller/src/input_data_channel_stub.cpp", + "${inputmethod_path}/frameworks/inputmethod_controller/src/input_method_controller.cpp", + "async_call.cpp", + "input_method_module.cpp", + "js_get_input_method_controller.cpp", + "js_get_input_method_setting.cpp", + "js_input_method.cpp", + ] + + configs = [ ":imf_config" ] + + deps = [ + "${ability_runtime_inner_api_path}/ability_manager:ability_manager", + "${ability_runtime_inner_api_path}/app_manager:app_manager", + "${ability_runtime_path}/frameworks/native/ability/native:abilitykit_native", + "${inputmethod_path}/services/dfx:inputmethod_dfx_static", + "//base/global/resource_management/frameworks/resmgr:global_resmgr", + "//base/inputmethod/imf/frameworks/inputmethod_ability:inputmethod_ability", + "//foundation/arkui/napi/:ace_napi", + "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", + "//foundation/communication/ipc/interfaces/innerkits/ipc_single:ipc_single", + "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", + "//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + ] + + external_deps = [ + "ability_base:want", + "ability_runtime:runtime", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "eventhandler:libeventhandler", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + ] + + public_configs = [ ":imf_public_config" ] + + relative_install_dir = "module" + subsystem_name = "inputmethod" + part_name = "imf" +} diff --git a/interfaces/kits/js/napi/inputmethodclient/js_get_input_method_controller.cpp b/interfaces/kits/js/napi/inputmethodclient/js_get_input_method_controller.cpp index 7523d0a1..8c2a8b26 100644 --- a/interfaces/kits/js/napi/inputmethodclient/js_get_input_method_controller.cpp +++ b/interfaces/kits/js/napi/inputmethodclient/js_get_input_method_controller.cpp @@ -32,6 +32,8 @@ napi_value JsGetInputMethodController::Init(napi_env env, napi_value info) napi_property_descriptor properties[] = { DECLARE_NAPI_FUNCTION("stopInput", StopInput), + DECLARE_NAPI_FUNCTION("hideSoftKeyboard", HideSoftKeyboard), + DECLARE_NAPI_FUNCTION("showSoftKeyboard", ShowSoftKeyboard), }; napi_value cons = nullptr; NAPI_CALL(env, napi_define_class(env, IMC_CLASS_NAME.c_str(), IMC_CLASS_NAME.size(), @@ -81,30 +83,46 @@ napi_value JsGetInputMethodController::GetInputMethodController(napi_env env, na return instance; } -napi_value JsGetInputMethodController::StopInput(napi_env env, napi_callback_info info) +napi_value JsGetInputMethodController::HandleSoftKeyboard( + napi_env env, napi_callback_info info, std::function callback) { - auto ctxt = std::make_shared(); + auto ctxt = std::make_shared(); auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status { NAPI_ASSERT_BASE(env, argc == 0 || argc == 1, " should null or 1 parameters!", napi_invalid_arg); return napi_ok; }; auto output = [ctxt](napi_env env, napi_value *result) -> napi_status { - napi_status status = napi_get_boolean(env, ctxt->isStopInput, result); + napi_status status = napi_get_boolean(env, ctxt->isHandle, result); IMSA_HILOGE("output napi_get_boolean != nullptr[%{public}d]", result != nullptr); return status; }; - auto exec = [ctxt](AsyncCall::Context *ctx) { - int32_t errCode = InputMethodController::GetInstance()->HideCurrentInput(); - IMSA_HILOGE("exec HideCurrentInput %{public}d", errCode); + auto exec = [ctxt, callback](AsyncCall::Context *ctx) { + int errCode = callback(); + IMSA_HILOGI("exec %{public}d", errCode); if (errCode == ErrorCode::NO_ERROR) { - IMSA_HILOGE("exec HideCurrentInput success"); + IMSA_HILOGI("exec success"); ctxt->status = napi_ok; - ctxt->isStopInput = true; + ctxt->isHandle = true; } }; ctxt->SetAction(std::move(input), std::move(output)); AsyncCall asyncCall(env, info, std::dynamic_pointer_cast(ctxt), 0); return asyncCall.Call(env, exec); } + +napi_value JsGetInputMethodController::ShowSoftKeyboard(napi_env env, napi_callback_info info) +{ + return HandleSoftKeyboard(env, info, [] { return InputMethodController::GetInstance()->ShowCurrentInput(); }); } + +napi_value JsGetInputMethodController::HideSoftKeyboard(napi_env env, napi_callback_info info) +{ + return HandleSoftKeyboard(env, info, [] { return InputMethodController::GetInstance()->HideCurrentInput(); }); } + +napi_value JsGetInputMethodController::StopInput(napi_env env, napi_callback_info info) +{ + return HandleSoftKeyboard(env, info, [] { return InputMethodController::GetInstance()->HideCurrentInput(); }); +} +} // namespace MiscServices +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/js/napi/inputmethodclient/js_get_input_method_controller.h b/interfaces/kits/js/napi/inputmethodclient/js_get_input_method_controller.h index e9b9009f..8dbf9cca 100644 --- a/interfaces/kits/js/napi/inputmethodclient/js_get_input_method_controller.h +++ b/interfaces/kits/js/napi/inputmethodclient/js_get_input_method_controller.h @@ -15,17 +15,17 @@ #ifndef INTERFACE_KITS_JS_GETINPUT_METHOD_CCONTROLLER_H #define INTERFACE_KITS_JS_GETINPUT_METHOD_CCONTROLLER_H -#include "global.h" #include "async_call.h" +#include "global.h" #include "js_input_method.h" namespace OHOS { namespace MiscServices { -struct StopInputContext : public AsyncCall::Context { - bool isStopInput = false; +struct HandleContext : public AsyncCall::Context { + bool isHandle = false; napi_status status = napi_generic_failure; - StopInputContext() : Context(nullptr, nullptr) { }; - StopInputContext(InputAction input, OutputAction output) : Context(std::move(input), std::move(output)) { }; + HandleContext() : Context(nullptr, nullptr) { }; + HandleContext(InputAction input, OutputAction output) : Context(std::move(input), std::move(output)) { }; napi_status operator()(napi_env env, size_t argc, napi_value *argv, napi_value self) override { @@ -47,12 +47,16 @@ public: ~JsGetInputMethodController() = default; static napi_value Init(napi_env env, napi_value info); static napi_value GetInputMethodController(napi_env env, napi_callback_info info); - static napi_value StopInput(napi_env env, napi_callback_info Info); + static napi_value HandleSoftKeyboard(napi_env env, napi_callback_info info, std::function callback); + static napi_value HideSoftKeyboard(napi_env env, napi_callback_info info); + static napi_value ShowSoftKeyboard(napi_env env, napi_callback_info info); + static napi_value StopInput(napi_env env, napi_callback_info info); + private: static napi_value JsConstructor(napi_env env, napi_callback_info cbinfo); static const std::string IMC_CLASS_NAME; static thread_local napi_ref IMCRef_; }; -} -} +} // namespace MiscServices +} // namespace OHOS #endif // INTERFACE_KITS_JS_GETINPUT_METHOD_CCONTROLLER_H diff --git a/services/include/i_input_method_system_ability.h b/services/include/i_input_method_system_ability.h index 611f33e5..c94d5fb9 100644 --- a/services/include/i_input_method_system_ability.h +++ b/services/include/i_input_method_system_ability.h @@ -38,6 +38,7 @@ namespace MiscServices { START_INPUT, STOP_INPUT, HIDE_CURRENT_INPUT, + SHOW_CURRENT_INPUT, SET_INPUT_METHOD_CORE, GET_DISPLAY_MODE, GET_KEYBOARD_WINDOW_HEIGHT, @@ -58,6 +59,7 @@ namespace MiscServices { virtual void stopInput(MessageParcel& data) = 0; virtual void SetCoreAndAgent(MessageParcel& data) = 0; virtual int32_t HideCurrentInput(MessageParcel& data) = 0; + virtual int32_t ShowCurrentInput(MessageParcel& data) = 0; virtual int32_t displayOptionalInputMethod(MessageParcel& data) = 0; virtual int32_t getDisplayMode(int32_t &retMode) = 0; diff --git a/services/include/input_method_system_ability_stub.h b/services/include/input_method_system_ability_stub.h index 68a407ae..8e12227f 100644 --- a/services/include/input_method_system_ability_stub.h +++ b/services/include/input_method_system_ability_stub.h @@ -35,6 +35,7 @@ namespace MiscServices { void stopInput(MessageParcel& data) override; void SetCoreAndAgent(MessageParcel& data) override; int32_t HideCurrentInput(MessageParcel& data) override; + int32_t ShowCurrentInput(MessageParcel& data) override; int32_t displayOptionalInputMethod(MessageParcel& data) override; virtual int32_t listInputMethodByUserId(int32_t userId, std::vector *properties) = 0; int32_t SwitchInputMethod(MessageParcel &data); diff --git a/services/include/message_handler.h b/services/include/message_handler.h index 9ab10d6c..2cf88b56 100644 --- a/services/include/message_handler.h +++ b/services/include/message_handler.h @@ -46,6 +46,7 @@ namespace MessageID { MSG_ID_RELEASE_INPUT, // release input MSG_ID_SET_CORE_AND_AGENT, MSG_HIDE_CURRENT_INPUT, + MSG_SHOW_CURRENT_INPUT, MSG_ID_SWITCH_INPUT_METHOD, // switch input method // the request to handle the condition that the remote object died diff --git a/services/include/peruser_session.h b/services/include/peruser_session.h index a8e9dd72..03aa40f3 100644 --- a/services/include/peruser_session.h +++ b/services/include/peruser_session.h @@ -171,6 +171,7 @@ namespace MiscServices { void OnClientDied(const wptr& who); void OnImsDied(const wptr& who); void OnHideKeyboardSelf(int flags); + void OnShowKeyboardSelf(); void OnAdvanceToNext(); void OnSetDisplayMode(int mode); void OnRestartIms(int index, const std::u16string& imeId); @@ -181,7 +182,7 @@ namespace MiscServices { int RemoveClient(const sptr& inputClient, int retClientNum); int StartInputMethod(int index); int StopInputMethod(int index); - int ShowKeyboard(const sptr& inputClient); + int ShowKeyboard(const sptr& inputClient, bool isShowKeyboard); int HideKeyboard(const sptr& inputClient); void SetDisplayId(int displayId); int GetImeIndex(const sptr& inputClient); diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index 9fc90151..5590adba 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -603,6 +603,7 @@ namespace MiscServices { case MSG_ID_START_INPUT: case MSG_ID_STOP_INPUT: case MSG_HIDE_CURRENT_INPUT: + case MSG_SHOW_CURRENT_INPUT: case MSG_ID_SET_CORE_AND_AGENT: case MSG_ID_HIDE_KEYBOARD_SELF: case MSG_ID_SET_DISPLAY_MODE: diff --git a/services/src/input_method_system_ability_stub.cpp b/services/src/input_method_system_ability_stub.cpp index 85992e86..90b0691e 100644 --- a/services/src/input_method_system_ability_stub.cpp +++ b/services/src/input_method_system_ability_stub.cpp @@ -170,6 +170,11 @@ namespace MiscServices { reply.WriteInt32(NO_ERROR); break; } + case SHOW_CURRENT_INPUT: { + int32_t ret = ShowCurrentInput(data); + reply.WriteInt32(ret); + break; + } case SWITCH_INPUT_METHOD: { int32_t ret = SwitchInputMethod(data); reply.WriteInt32(ret); @@ -255,6 +260,7 @@ namespace MiscServices { MessageParcel *parcel = new MessageParcel(); parcel->WriteInt32(userId); parcel->WriteRemoteObject(data.ReadRemoteObject()); + parcel->WriteBool(data.ReadBool()); Message *msg = new Message(MSG_ID_START_INPUT, parcel); MessageHandler::Instance()->SendMessage(msg); @@ -311,6 +317,26 @@ namespace MiscServices { return ErrorCode::NO_ERROR; } + int32_t InputMethodSystemAbilityStub::ShowCurrentInput(MessageParcel &data) + { + IMSA_HILOGI("InputMethodSystemAbilityStub::ShowCurrentInput"); + int32_t uid = IPCSkeleton::GetCallingUid(); + int32_t userId = getUserId(uid); + + auto *parcel = new (std::nothrow) MessageParcel(); + if (parcel == nullptr) { + return ErrorCode::ERROR_EX_NULL_POINTER; + } + parcel->WriteInt32(userId); + + auto *msg = new (std::nothrow) Message(MSG_SHOW_CURRENT_INPUT, parcel); + if (msg == nullptr) { + return ErrorCode::ERROR_EX_NULL_POINTER; + } + MessageHandler::Instance()->SendMessage(msg); + return ErrorCode::NO_ERROR; + } + int32_t InputMethodSystemAbilityStub::SwitchInputMethod(MessageParcel &data) { IMSA_HILOGI("InputMethodSystemAbilityStub::switchInputMethod"); diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index 6f579359..c357d8f7 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -186,6 +186,10 @@ namespace MiscServices { OnHideKeyboardSelf(0); break; } + case MSG_SHOW_CURRENT_INPUT: { + OnShowKeyboardSelf(); + break; + } default: { break; } @@ -271,7 +275,7 @@ namespace MiscServices { break; } if (needReshowClient && GetImeIndex(needReshowClient) == i) { - ShowKeyboard(needReshowClient); + ShowKeyboard(needReshowClient, true); needReshowClient = nullptr; } } @@ -478,7 +482,7 @@ namespace MiscServices { \return ErrorCode::ERROR_KBD_SHOW_FAILED failed to show keyboard \return other errors returned by binder driver */ - int PerUserSession::ShowKeyboard(const sptr& inputClient) + int PerUserSession::ShowKeyboard(const sptr& inputClient, bool isShowKeyboard) { IMSA_HILOGI("PerUserSession::ShowKeyboard"); ClientInfo *clientInfo = GetClientInfo(inputClient); @@ -493,7 +497,7 @@ namespace MiscServices { return ErrorCode::ERROR_NULL_POINTER; } - imsCore[0]->showKeyboard(clientInfo->channel); + imsCore[0]->showKeyboard(clientInfo->channel, isShowKeyboard); currentClient = inputClient; return ErrorCode::NO_ERROR; @@ -799,6 +803,12 @@ namespace MiscServices { HideKeyboard(currentClient); } + void PerUserSession::OnShowKeyboardSelf() + { + IMSA_HILOGI("PerUserSession::OnShowKeyboardSelf"); + ShowKeyboard(currentClient, true); + } + /*! Switch to next keyboard type */ void PerUserSession::OnAdvanceToNext() @@ -875,7 +885,7 @@ namespace MiscServices { int ret = StartInputMethod(index); if (needReshowClient && GetImeIndex(needReshowClient) == index) { if (ret == ErrorCode::NO_ERROR) { - ShowKeyboard(needReshowClient); + ShowKeyboard(needReshowClient, true); } needReshowClient = nullptr; } @@ -1253,7 +1263,8 @@ namespace MiscServices { if (imsCore[0]) { imsCore[0]->SetClientState(true); } - ShowKeyboard(client); + bool isShowKeyboard = data->ReadBool(); + ShowKeyboard(client, isShowKeyboard); } void PerUserSession::SetCoreAndAgent(Message *msg) diff --git a/unitest/src/input_method_controller_test.cpp b/unitest/src/input_method_controller_test.cpp index 93194f6d..ddbc1f1e 100644 --- a/unitest/src/input_method_controller_test.cpp +++ b/unitest/src/input_method_controller_test.cpp @@ -218,6 +218,14 @@ namespace MiscServices { int waitForStatusOk = 2; sleep(waitForStatusOk); + IMSA_HILOGI("IMC Attach isShowKeyboard true START"); + imc->Attach(textListener, true); + sleep(waitForStatusOk); + + IMSA_HILOGI("IMC Attach isShowKeyboard false START"); + imc->Attach(textListener, false); + sleep(waitForStatusOk); + IMSA_HILOGI("IMC ShowTextInput START"); imc->ShowTextInput(); sleep(10);