From dd69d6ae66acff87cff99963808adf78d4dc850c Mon Sep 17 00:00:00 2001 From: zhouyongfei Date: Thu, 13 Jan 2022 19:49:53 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=BB=84=E5=8C=BA?= =?UTF-8?q?=E9=9C=80=E6=B1=82=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhouyongfei --- frameworks/inputmethod_ability/BUILD.gn | 2 +- .../include/event_target.h | 49 +++- .../include/i_input_method_agent.h | 5 + .../include/i_input_method_core.h | 2 + .../include/input_method_ability.h | 9 + .../include/input_method_agent_proxy.h | 3 + .../include/input_method_agent_stub.h | 3 + .../inputmethod_ability/src/event_target.cpp | 214 +++++++++++++++++- .../src/input_method_ability.cpp | 109 ++++++++- .../src/input_method_agent_proxy.cpp | 37 +++ .../src/input_method_agent_stub.cpp | 49 ++++ .../src/input_method_core_stub.cpp | 4 +- frameworks/inputmethod_controller/BUILD.gn | 18 +- .../include/i_input_data_channel.h | 13 ++ .../include/input_data_channel_proxy.h | 7 + .../include/input_data_channel_stub.h | 10 + .../include/input_method_controller.h | 10 +- .../input_method_system_ability_proxy.h | 1 + .../include/input_method_utils.h | 5 +- .../src/input_data_channel_proxy.cpp | 75 ++++++ .../src/input_data_channel_stub.cpp | 87 +++++++ .../src/input_method_controller.cpp | 100 +++++++- .../api/@ohos.inputmethodengine.d.ts | 20 +- interfaces/kits/js/napi/BUILD.gn | 1 - .../kits/js/napi/js_input_method_engine.cpp | 123 +++++++++- services/BUILD.gn | 1 + services/include/i_input_method_proxy.h | 37 --- .../include/input_method_system_ability.h | 1 + services/include/message_handler.h | 8 +- services/src/input_method_agent_proxy.cpp | 48 ---- services/src/peruser_setting.cpp | 1 - unitest/src/input_method_controller_test.cpp | 4 +- 32 files changed, 934 insertions(+), 122 deletions(-) delete mode 100644 services/include/i_input_method_proxy.h delete mode 100644 services/src/input_method_agent_proxy.cpp diff --git a/frameworks/inputmethod_ability/BUILD.gn b/frameworks/inputmethod_ability/BUILD.gn index 0d518b7e3..a42b344df 100644 --- a/frameworks/inputmethod_ability/BUILD.gn +++ b/frameworks/inputmethod_ability/BUILD.gn @@ -41,11 +41,11 @@ ohos_shared_library("inputmethod_ability") { deps = [ "//base/global/resmgr_standard/frameworks/resmgr:global_resmgr", "//base/miscservices/inputmethod/services:inputmethod_service", - "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", "//foundation/aafwk/standard/interfaces/innerkits/base:base", "//foundation/aafwk/standard/interfaces/innerkits/intent:intent", "//foundation/aafwk/standard/interfaces/innerkits/want:want", + "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/ace/napi/:ace_napi", "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base", "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core", diff --git a/frameworks/inputmethod_ability/include/event_target.h b/frameworks/inputmethod_ability/include/event_target.h index afd0c4924..4fbee86eb 100644 --- a/frameworks/inputmethod_ability/include/event_target.h +++ b/frameworks/inputmethod_ability/include/event_target.h @@ -29,6 +29,52 @@ namespace MiscServices { virtual napi_value ToJsObject() = 0; }; + class NapiKeyEvent : public Event { + public: + NapiKeyEvent(napi_env env, int32_t key, int32_t status); + ~NapiKeyEvent(); + napi_value ToJsObject() override; + private: + napi_env keyEev; + int32_t key_; + int32_t status_; + }; + + class NapiCursorChange : public Event { + public: + NapiCursorChange(napi_env env, int32_t px, int32_t py, int32_t height); + ~NapiCursorChange(); + napi_value ToJsObject() override; + private: + napi_env env_; + int32_t px_; + int32_t py_; + int32_t height_; + }; + + class NapiSelectionChange : public Event { + public: + NapiSelectionChange(napi_env env, int32_t oldBegin, int32_t oldEnd, int32_t newBegin, int32_t newEnd); + ~NapiSelectionChange(); + napi_value ToJsObject() override; + private: + napi_env env_; + int32_t oldBegin_; + int32_t oldEnd_; + int32_t newBegin_; + int32_t newEnd_; + }; + + class NapiTextChange : public Event { + public: + NapiTextChange(napi_env env, std::u16string text); + ~NapiTextChange(); + napi_value ToJsObject() override; + private: + napi_env env_; + std::u16string text_; + }; + class EventTarget : public RefBase { public: EventTarget(napi_env env, napi_value thisVar); @@ -39,8 +85,9 @@ namespace MiscServices { virtual void Off(const char *type, napi_value handler); virtual void Off(const char *type); virtual void Emit(sptr &eventTarget, const char *type, Event *event); + virtual napi_env GetEnv(); - protected: + private: napi_env env_; napi_ref thisVarRef_; EventListener *first_; diff --git a/frameworks/inputmethod_ability/include/i_input_method_agent.h b/frameworks/inputmethod_ability/include/i_input_method_agent.h index e9eb80a81..432e3a3ef 100644 --- a/frameworks/inputmethod_ability/include/i_input_method_agent.h +++ b/frameworks/inputmethod_ability/include/i_input_method_agent.h @@ -29,11 +29,16 @@ namespace MiscServices { public: enum { DISPATCH_KEY = FIRST_CALL_TRANSACTION, + ON_CURSOR_UPDATE, + ON_SELECTION_CHANGE, }; DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.inputmethod.IInputMethodAgent"); virtual int32_t DispatchKey(int32_t key, int32_t status) = 0; + virtual void OnCursorUpdate(int32_t positionX, int32_t positionY, int height) = 0; + virtual void OnSelectionChange(std::u16string text, int32_t oldBegin, int32_t oldEnd, + int32_t newBegin, int32_t newEnd) = 0; }; } } diff --git a/frameworks/inputmethod_ability/include/i_input_method_core.h b/frameworks/inputmethod_ability/include/i_input_method_core.h index eb73f9cc4..4fc9fef19 100644 --- a/frameworks/inputmethod_ability/include/i_input_method_core.h +++ b/frameworks/inputmethod_ability/include/i_input_method_core.h @@ -38,6 +38,8 @@ namespace MiscServices { STOP_INPUT, SHOW_KEYBOARD, HIDE_KEYBOARD, + ON_CURSOR_UPDATE, + ON_SELECT_TEXT_CHANGE, SET_KEYBOARD_TYPE, GET_KEYBOARD_WINDOW_HEIGHT, }; diff --git a/frameworks/inputmethod_ability/include/input_method_ability.h b/frameworks/inputmethod_ability/include/input_method_ability.h index 01bfd5357..67212c37e 100644 --- a/frameworks/inputmethod_ability/include/input_method_ability.h +++ b/frameworks/inputmethod_ability/include/input_method_ability.h @@ -42,8 +42,13 @@ namespace MiscServices { sptr OnConnect(); bool InsertText(const std::string text); void setEventTarget(sptr &eventTarget); + void DeleteForward(int32_t length); void DeleteBackward(int32_t length); void HideKeyboardSelf(); + std::u16string GetTextBeforeCursor(); + std::u16string GetTextAfterCursor(); + void SendFunctionKey(int32_t funcKey); + void MoveCursor(int32_t keyCode); private: std::thread workThreadHandler; @@ -54,6 +59,8 @@ namespace MiscServices { sptr startInputToken; InputChannel *writeInputChannel; bool stop_; + int32_t KEYBOARD_HIDE = 1; + int32_t KEYBOARD_SHOW = 2; // communicating with IMSA sptr inputControlChannel; @@ -81,6 +88,8 @@ namespace MiscServices { // the message from IMC bool DispatchKey(Message *msg); + void OnCursorUpdate(Message *msg); + void OnSelectionChange(Message *msg); // control inputwindow void InitialInputWindow(); diff --git a/frameworks/inputmethod_ability/include/input_method_agent_proxy.h b/frameworks/inputmethod_ability/include/input_method_agent_proxy.h index 038f3abae..0ef71ef74 100644 --- a/frameworks/inputmethod_ability/include/input_method_agent_proxy.h +++ b/frameworks/inputmethod_ability/include/input_method_agent_proxy.h @@ -28,6 +28,9 @@ namespace MiscServices { DISALLOW_COPY_AND_MOVE(InputMethodAgentProxy); int32_t DispatchKey(int32_t key, int32_t status) override; + void OnCursorUpdate(int32_t positionX, int32_t positionY, int32_t height) override; + void OnSelectionChange(std::u16string text, int32_t oldBegin, int32_t oldEnd, + int32_t newBegin, int32_t newEnd) override; private: static inline BrokerDelegator delegator_; }; diff --git a/frameworks/inputmethod_ability/include/input_method_agent_stub.h b/frameworks/inputmethod_ability/include/input_method_agent_stub.h index c26922a01..e943d5ac5 100644 --- a/frameworks/inputmethod_ability/include/input_method_agent_stub.h +++ b/frameworks/inputmethod_ability/include/input_method_agent_stub.h @@ -33,6 +33,9 @@ namespace MiscServices { MessageParcel &reply, MessageOption &option) override; virtual int32_t DispatchKey(int32_t key, int32_t status) override; + virtual void OnCursorUpdate(int32_t positionX, int32_t positionY, int height) override; + virtual void OnSelectionChange(std::u16string text, int32_t oldBegin, int32_t oldEnd, + int32_t newBegin, int32_t newEnd) override; void SetMessageHandler(MessageHandler *msgHandler); private: MessageHandler *msgHandler_; diff --git a/frameworks/inputmethod_ability/src/event_target.cpp b/frameworks/inputmethod_ability/src/event_target.cpp index 4c6f1b032..508c16a4f 100644 --- a/frameworks/inputmethod_ability/src/event_target.cpp +++ b/frameworks/inputmethod_ability/src/event_target.cpp @@ -12,13 +12,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include #include "event_target.h" -#include "securec.h" - +#include #include "utils/log.h" #include "input_method_ability.h" +#include "securec.h" +#include "string_ex.h" #define LISTENER_TYPTE_MAX_LENGTH 64 namespace OHOS { namespace MiscServices { @@ -38,6 +38,203 @@ namespace MiscServices { const char *type; Event *event; }; + + NapiKeyEvent::NapiKeyEvent(napi_env env, int32_t key, int32_t status) + { + keyEev = env; + key_ = key; + status_ = status; + } + + NapiKeyEvent::~NapiKeyEvent() + { + } + + napi_value NapiKeyEvent::ToJsObject() + { + napi_value object = nullptr; + napi_status status = napi_generic_failure; + + status = napi_create_object(keyEev, &object); + if (status != napi_ok) { + napi_throw_type_error(keyEev, nullptr, + "NapiKeyEvent Throw Error:ToJsObject create object failed"); + return nullptr; + } + + napi_value intVal; + + napi_create_int32(keyEev, key_, &intVal); + status = napi_set_named_property(keyEev, object, "keyCode", intVal); + if (status != napi_ok) { + napi_throw_type_error(keyEev, nullptr, + "NapiKeyEvent Throw Error:ToJsObject set named property failed"); + return nullptr; + } + + napi_create_int32(keyEev, status_, &intVal); + status = napi_set_named_property(keyEev, object, "keyAction", intVal); + if (status != napi_ok) { + napi_throw_type_error(keyEev, nullptr, + "NapiKeyEvent Throw Error:ToJsObject set named property failed"); + return nullptr; + } + + return object; + } + + NapiCursorChange::NapiCursorChange(napi_env env, int32_t px, int32_t py, int32_t height) + { + env_ = env; + px_ = px; + py_ = py; + height_ = height; + } + + NapiCursorChange::~NapiCursorChange() + { + } + + napi_value NapiCursorChange::ToJsObject() + { + napi_value object = nullptr; + napi_status status = napi_generic_failure; + + status = napi_create_object(env_, &object); + if (status != napi_ok) { + napi_throw_type_error(env_, nullptr, + "NapiCursorChange Throw Error:ToJsObject create object failed"); + return nullptr; + } + + napi_value intVal; + + napi_create_int32(env_, px_, &intVal); + status = napi_set_named_property(env_, object, "x", intVal); + if (status != napi_ok) { + napi_throw_type_error(env_, nullptr, + "NapiCursorChange Throw Error:ToJsObject set named property failed"); + return nullptr; + } + + napi_create_int32(env_, py_, &intVal); + status = napi_set_named_property(env_, object, "y", intVal); + if (status != napi_ok) { + napi_throw_type_error(env_, nullptr, + "NapiCursorChange Throw Error:ToJsObject set named property failed"); + return nullptr; + } + + napi_create_int32(env_, height_, &intVal); + status = napi_set_named_property(env_, object, "height", intVal); + if (status != napi_ok) { + napi_throw_type_error(env_, nullptr, + "NapiCursorChange Throw Error:ToJsObject set named property failed"); + return nullptr; + } + + return object; + } + + NapiSelectionChange::NapiSelectionChange(napi_env env, int32_t oldBegin, int32_t oldEnd, + int32_t newBegin, int32_t newEnd) + { + env_ = env; + oldBegin_ = oldBegin; + oldEnd_ = oldEnd; + newBegin_ = newBegin; + newEnd_ = newEnd; + } + + NapiSelectionChange::~NapiSelectionChange() + { + } + + napi_value NapiSelectionChange::ToJsObject() + { + napi_value object = nullptr; + napi_status status = napi_generic_failure; + + status = napi_create_object(env_, &object); + if (status != napi_ok) { + napi_throw_type_error(env_, nullptr, + "NapiSelectionChange Throw Error:ToJsObject create object failed"); + return nullptr; + } + + napi_value intVal; + + napi_create_int32(env_, oldBegin_, &intVal); + status = napi_set_named_property(env_, object, "oldBegin", intVal); + if (status != napi_ok) { + napi_throw_type_error(env_, nullptr, + "NapiSelectionChange Throw Error:ToJsObject set named property failed"); + return nullptr; + } + + napi_create_int32(env_, oldEnd_, &intVal); + status = napi_set_named_property(env_, object, "oldEnd", intVal); + if (status != napi_ok) { + napi_throw_type_error(env_, nullptr, + "NapiSelectionChange Throw Error:ToJsObject set named property failed"); + return nullptr; + } + + napi_create_int32(env_, newBegin_, &intVal); + status = napi_set_named_property(env_, object, "newBegin", intVal); + if (status != napi_ok) { + napi_throw_type_error(env_, nullptr, + "NapiCursorChange Throw Error:ToJsObject set named property failed"); + return nullptr; + } + + napi_create_int32(env_, newEnd_, &intVal); + status = napi_set_named_property(env_, object, "newEnd", intVal); + if (status != napi_ok) { + napi_throw_type_error(env_, nullptr, + "NapiCursorChange Throw Error:ToJsObject set named property failed"); + return nullptr; + } + + return object; + } + + NapiTextChange::NapiTextChange(napi_env env, std::u16string text) + { + env_ = env; + text_ = text; + } + + NapiTextChange::~NapiTextChange() + { + } + + napi_value NapiTextChange::ToJsObject() + { + napi_value object = nullptr; + napi_status status = napi_generic_failure; + + status = napi_create_object(env_, &object); + if (status != napi_ok) { + napi_throw_type_error(env_, nullptr, + "NapiTextChange Throw Error:ToJsObject create object failed"); + return nullptr; + } + + napi_value intVal; + + std::string outString = Str16ToStr8(text_.c_str()); + napi_create_string_utf8(env_, outString.c_str(), NAPI_AUTO_LENGTH, &intVal); + status = napi_set_named_property(env_, object, "text", intVal); + if (status != napi_ok) { + napi_throw_type_error(env_, nullptr, + "NapiTextChange Throw Error:ToJsObject set named property failed"); + return nullptr; + } + + return object; + } + EventTarget::EventTarget(napi_env env, napi_value thisVar) { IMSA_HILOGI("EventTarget::EventTarget"); @@ -202,13 +399,15 @@ namespace MiscServices { napi_value thisVar = nullptr; napi_get_reference_value(eventTargetCB->env, eventTargetCB->thisVarRef, &thisVar); - for (EventListener *eventListener = eventTargetCB->first; eventListener != nullptr; eventListener = eventListener->next) { + for (EventListener *eventListener = eventTargetCB->first; eventListener != nullptr; + eventListener = eventListener->next) { if (strcmp(eventListener->type, eventTargetCB->type) == 0) { napi_value jsEvent = eventTargetCB->event ? eventTargetCB->event->ToJsObject() : nullptr; napi_value handler = nullptr; napi_value result = nullptr; napi_get_reference_value(eventTargetCB->env, eventListener->handlerRef, &handler); - napi_call_function(eventTargetCB->env, thisVar, handler, jsEvent ? 1 : 0, jsEvent ? &jsEvent : nullptr, &result); + napi_call_function(eventTargetCB->env, thisVar, handler, + jsEvent ? 1 : 0, jsEvent ? &jsEvent : nullptr, &result); if (eventListener->isOnce) { eventTargetCB->eventTarget->Off(eventTargetCB->type, handler); } @@ -226,5 +425,10 @@ namespace MiscServices { delete work; } } + + napi_env EventTarget::GetEnv() + { + return env_; + } } } \ No newline at end of file diff --git a/frameworks/inputmethod_ability/src/input_method_ability.cpp b/frameworks/inputmethod_ability/src/input_method_ability.cpp index c14fd5ff0..401a1c3cf 100644 --- a/frameworks/inputmethod_ability/src/input_method_ability.cpp +++ b/frameworks/inputmethod_ability/src/input_method_ability.cpp @@ -13,15 +13,17 @@ * limitations under the License. */ #include "input_method_ability.h" -#include "input_method_core_proxy.h" -#include "input_method_core_stub.h" +#include "string_ex.h" #include "input_method_agent_proxy.h" #include "input_method_agent_stub.h" #include "message_parcel.h" #include "event_target.h" -#include "iservice_registry.h" #include "system_ability_definition.h" #include "input_data_channel_proxy.h" +#include "input_method_utils.h" +#include "iservice_registry.h" +#include "input_method_core_proxy.h" +#include "input_method_core_stub.h" namespace OHOS { namespace MiscServices { @@ -89,8 +91,9 @@ namespace MiscServices { sptr stub2 = stub; if (mImms != nullptr) { mImms->setInputMethodCore(stub2); + } else { + IMSA_HILOGI("InputMethodAbility::OnConnect() mImms is nullptr"); } - IMSA_HILOGI("InputMethodAbility::OnConnect() mImms is nullptr"); return nullptr; } @@ -144,7 +147,14 @@ namespace MiscServices { DispatchKey(msg); break; } - + case MSG_ID_ON_CURSOR_UPDATE: { + OnCursorUpdate(msg); + break; + } + case MSG_ID_ON_SELECTION_CHANGE: { + OnSelectionChange(msg); + break; + } default: { break; } @@ -223,8 +233,46 @@ namespace MiscServices { int32_t key = data->ReadInt32(); int32_t status = data->ReadInt32(); IMSA_HILOGI("InputMethodAbility::DispatchKey: key = %{public}d, status = %{public}d", key, status); + + napi_env env = eventTarget_->GetEnv(); + MiscServices::NapiKeyEvent *napiKeyEvent = new MiscServices::NapiKeyEvent(env, key, status); + eventTarget_->Emit(eventTarget_, "keyDown", napiKeyEvent); return true; } + + void InputMethodAbility::OnCursorUpdate(Message *msg) + { + IMSA_HILOGI("InputMethodAbility::OnCursorUpdate"); + MessageParcel *data = msg->msgContent_; + int32_t positionX = data->ReadInt32(); + int32_t positionY = data->ReadInt32(); + int32_t height = data->ReadInt32(); + + napi_env env = eventTarget_->GetEnv(); + MiscServices::NapiCursorChange *napiCursorChange = new MiscServices::NapiCursorChange(env, positionX, + positionY, height); + eventTarget_->Emit(eventTarget_, "cursorContextChange", napiCursorChange); + } + + void InputMethodAbility::OnSelectionChange(Message *msg) + { + IMSA_HILOGI("InputMethodAbility::OnSelectionChange"); + MessageParcel *data = msg->msgContent_; + const std::u16string text = data->ReadString16(); + int32_t oldBegin = data->ReadInt32(); + int32_t oldEnd = data->ReadInt32(); + int32_t newBegin = data->ReadInt32(); + int32_t newEnd = data->ReadInt32(); + + napi_env env = eventTarget_->GetEnv(); + + MiscServices::NapiTextChange *napiTextChange = new MiscServices::NapiTextChange(env, text); + eventTarget_->Emit(eventTarget_, "textChange", napiTextChange); + + MiscServices::NapiSelectionChange *napiSelectionChange = new MiscServices::NapiSelectionChange(env, oldBegin, + oldEnd, newBegin, newEnd); + eventTarget_->Emit(eventTarget_, "selectionChange", napiSelectionChange); + } void InputMethodAbility::CreateInputMethodAgent(bool supportPhysicalKbd) { @@ -243,12 +291,18 @@ namespace MiscServices { { IMSA_HILOGI("InputMethodAbility::ShowInputWindow"); eventTarget_->Emit(eventTarget_, "keyboardShow", nullptr); + if (inputDataChannel != nullptr) { + inputDataChannel->SendKeyboardStatus(KEYBOARD_SHOW); + } } void InputMethodAbility::DissmissInputWindow() { IMSA_HILOGI("InputMethodAbility::DissmissInputWindow"); eventTarget_->Emit(eventTarget_, "keyboardHide", nullptr); + if (inputDataChannel != nullptr) { + inputDataChannel->SendKeyboardStatus(KEYBOARD_HIDE); + } } bool InputMethodAbility::InsertText(const std::string text) @@ -262,6 +316,16 @@ namespace MiscServices { return inputDataChannel->InsertText(Utils::to_utf16(text)); } + void InputMethodAbility::DeleteForward(int32_t length) + { + IMSA_HILOGI("InputMethodAbility::DeleteForward"); + if (inputDataChannel == nullptr) { + IMSA_HILOGI("InputMethodAbility::DeleteForward inputDataChanel is nullptr"); + return; + } + inputDataChannel->DeleteForward(length); + } + void InputMethodAbility::DeleteBackward(int32_t length) { IMSA_HILOGI("InputMethodAbility::DeleteBackward"); @@ -272,10 +336,45 @@ namespace MiscServices { inputDataChannel->DeleteBackward(length); } + void InputMethodAbility::SendFunctionKey(int32_t funcKey) + { + IMSA_HILOGI("InputMethodAbility::SendFunctionKey"); + if (inputDataChannel == nullptr) { + IMSA_HILOGI("InputMethodAbility::SendFunctionKey inputDataChanel is nullptr"); + return; + } + inputDataChannel->SendFunctionKey(funcKey); + } + void InputMethodAbility::HideKeyboardSelf() { IMSA_HILOGI("InputMethodAbility::HideKeyboardSelf"); inputControlChannel->hideKeyboardSelf(1); } + + std::u16string InputMethodAbility::GetTextBeforeCursor() + { + IMSA_HILOGI("InputMethodAbility::GetTextBeforeCursor"); + return inputDataChannel->GetTextBeforeCursor(); + } + + std::u16string InputMethodAbility::GetTextAfterCursor() + { + IMSA_HILOGI("InputMethodAbility::GetTextAfterCursor"); + return inputDataChannel->GetTextAfterCursor(); + } + + void InputMethodAbility::MoveCursor(int32_t keyCode) + { + IMSA_HILOGI("InputMethodAbility::MoveCursor"); + + if (inputDataChannel == nullptr) { + IMSA_HILOGI("InputMethodAbility::MoveCursor inputDataChanel is nullptr"); + return; + } + + inputDataChannel->MoveCursor(keyCode); + return; + } } } \ No newline at end of file diff --git a/frameworks/inputmethod_ability/src/input_method_agent_proxy.cpp b/frameworks/inputmethod_ability/src/input_method_agent_proxy.cpp index 1e06f7e0f..456fab351 100644 --- a/frameworks/inputmethod_ability/src/input_method_agent_proxy.cpp +++ b/frameworks/inputmethod_ability/src/input_method_agent_proxy.cpp @@ -39,5 +39,42 @@ namespace MiscServices { auto ret = Remote()->SendRequest(DISPATCH_KEY, data, reply, option); return ret; } + + void InputMethodAgentProxy::OnCursorUpdate(int32_t positionX, int32_t positionY, int32_t height) + { + IMSA_HILOGI("InputMethodAgentProxy::OnCursorUpdate"); + MessageParcel data, reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + IMSA_HILOGI("InputMethodAgentProxy::OnCursorUpdate descriptor is not match"); + return; + } + + data.WriteInt32(positionX); + data.WriteInt32(positionY); + data.WriteInt32(height); + + Remote()->SendRequest(ON_CURSOR_UPDATE, data, reply, option); + } + + void InputMethodAgentProxy::OnSelectionChange(std::u16string text, int32_t oldBegin, int32_t oldEnd, + int32_t newBegin, int32_t newEnd) + { + IMSA_HILOGI("InputMethodAgentProxy::OnSelectionChange"); + MessageParcel data, reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + IMSA_HILOGI("InputMethodAgentProxy::OnSelectionChange descriptor is not match"); + return; + } + + data.WriteString16(text); + data.WriteInt32(oldBegin); + data.WriteInt32(oldEnd); + data.WriteInt32(newBegin); + data.WriteInt32(newEnd); + + Remote()->SendRequest(ON_SELECTION_CHANGE, data, reply, option); + } } } diff --git a/frameworks/inputmethod_ability/src/input_method_agent_stub.cpp b/frameworks/inputmethod_ability/src/input_method_agent_stub.cpp index c75abde85..449c72039 100644 --- a/frameworks/inputmethod_ability/src/input_method_agent_stub.cpp +++ b/frameworks/inputmethod_ability/src/input_method_agent_stub.cpp @@ -52,6 +52,24 @@ namespace MiscServices { } return result; } + case ON_CURSOR_UPDATE: { + int32_t positionX = data.ReadInt32(); + int32_t positionY = data.ReadInt32(); + int32_t height = data.ReadInt32(); + OnCursorUpdate(positionX, positionY, height); + reply.WriteNoException(); + return ErrorCode::NO_ERROR; + } + case ON_SELECTION_CHANGE: { + std::u16string text = data.ReadString16(); + int32_t oldBegin = data.ReadInt32(); + int32_t oldEnd = data.ReadInt32(); + int32_t newBegin = data.ReadInt32(); + int32_t newEnd = data.ReadInt32(); + OnSelectionChange(text, oldBegin, oldEnd, newBegin, newEnd); + reply.WriteNoException(); + return ErrorCode::NO_ERROR; + } default: { return IRemoteStub::OnRemoteRequest(code, data, reply, option); } @@ -72,6 +90,37 @@ namespace MiscServices { msgHandler_->SendMessage(message); return ErrorCode::NO_ERROR; } + + void InputMethodAgentStub::OnCursorUpdate(int32_t positionX, int32_t positionY, int height) + { + IMSA_HILOGI("InputMethodAgentStub::OnCursorUpdate"); + if (msgHandler_ == nullptr) { + return; + } + MessageParcel *data = new MessageParcel(); + data->WriteInt32(positionX); + data->WriteInt32(positionY); + data->WriteInt32(height); + Message *message = new Message(MessageID::MSG_ID_ON_CURSOR_UPDATE, data); + msgHandler_->SendMessage(message); + } + + void InputMethodAgentStub::OnSelectionChange(std::u16string text, int32_t oldBegin, int32_t oldEnd, + int32_t newBegin, int32_t newEnd) + { + IMSA_HILOGI("InputMethodAgentStub::OnSelectionChange"); + if (msgHandler_ == nullptr) { + return; + } + MessageParcel *data = new MessageParcel(); + data->WriteString16(text); + data->WriteInt32(oldBegin); + data->WriteInt32(oldEnd); + data->WriteInt32(newBegin); + data->WriteInt32(newEnd); + Message *message = new Message(MessageID::MSG_ID_ON_SELECTION_CHANGE, data); + msgHandler_->SendMessage(message); + } void InputMethodAgentStub::SetMessageHandler(MessageHandler *msgHandler) { diff --git a/frameworks/inputmethod_ability/src/input_method_core_stub.cpp b/frameworks/inputmethod_ability/src/input_method_core_stub.cpp index bf51a666e..c34f3b790 100644 --- a/frameworks/inputmethod_ability/src/input_method_core_stub.cpp +++ b/frameworks/inputmethod_ability/src/input_method_core_stub.cpp @@ -12,13 +12,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "input_method_core_stub.h" + #include #include #include "message_handler.h" #include "i_input_data_channel.h" -#include "input_method_core_stub.h" #include "input_channel.h" -#include "i_input_method_proxy.h" #include "platform.h" #include "message_parcel.h" #include "input_control_channel_proxy.h" diff --git a/frameworks/inputmethod_controller/BUILD.gn b/frameworks/inputmethod_controller/BUILD.gn index 3c3b1eac5..230c70138 100644 --- a/frameworks/inputmethod_controller/BUILD.gn +++ b/frameworks/inputmethod_controller/BUILD.gn @@ -26,9 +26,10 @@ config("inputmethod_client_native_public_config") { include_dirs = [ "//base/miscservices/inputmethod/frameworks/inputmethod_controller/include", "//base/miscservices/inputmethod/frameworks/inputmethod_ability/include", - "//foundation/communication/ipc/interfaces/innerkits/ipc_core/include", - "//base/hiviewdfx/hilog/interfaces/native/innerkits/include", "//base/miscservices/inputmethod/services/include", + "//base/hiviewdfx/hilog/interfaces/native/innerkits/include", + "//foundation/communication/ipc/interfaces/innerkits/ipc_core/include", + "//foundation/multimodalinput/input/interfaces/native/innerkits/event/include", "//utils/native/base/include", ] } @@ -42,15 +43,24 @@ ohos_shared_library("inputmethod_client") { "src/input_method_controller.cpp", "src/input_method_system_ability_proxy.cpp", "src/input_method_utils.cpp", + + "${inputmethod_path}/frameworks/inputmethod_ability/src/input_method_agent_proxy.cpp", + + "${inputmethod_path}/services/src/input_channel.cpp", + "${inputmethod_path}/services/src/global.cpp", + "${inputmethod_path}/services/src/message_handler.cpp", + "${inputmethod_path}/services/src/keyboard_type.cpp", + "${inputmethod_path}/services/src/input_method_property.cpp", + "${inputmethod_path}/services/src/message.cpp", + "${inputmethod_path}/services/src/input_attribute.cpp", ] deps = [ - "//base/miscservices/inputmethod/frameworks/inputmethod_ability:inputmethod_ability", - "//base/miscservices/inputmethod/services:inputmethod_service", "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", "//foundation/communication/ipc/interfaces/innerkits/ipc_single:ipc_single", "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//foundation/multimodalinput/input/frameworks/proxy:libmmi-common", "//utils/native/base:utils", ] diff --git a/frameworks/inputmethod_controller/include/i_input_data_channel.h b/frameworks/inputmethod_controller/include/i_input_data_channel.h index 39e0a4fc7..2d95e4693 100644 --- a/frameworks/inputmethod_controller/include/i_input_data_channel.h +++ b/frameworks/inputmethod_controller/include/i_input_data_channel.h @@ -18,6 +18,7 @@ #include #include "iremote_broker.h" #include "global.h" +#include "input_method_utils.h" /** * brief Definition of interface IInputDataChannel @@ -29,15 +30,27 @@ namespace MiscServices { public: enum { INSERT_TEXT = 0, + DELETE_FORWARD, DELETE_BACKWARD, CLOSE, + GET_TEXT_BEFORE_CURSOR, + GET_TEXT_AFTER_CURSOR, + SEND_KEYBOARD_STATUS, + SEND_FUNCTION_KEY, + MOVE_CURSOR, }; DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.inputmethod.IInputDataChannel"); virtual bool InsertText(const std::u16string& text) = 0; + virtual bool DeleteForward(int32_t length) = 0; virtual bool DeleteBackward(int32_t length) = 0; virtual void Close() = 0; + virtual std::u16string GetTextBeforeCursor() = 0; + virtual std::u16string GetTextAfterCursor() = 0; + virtual void SendKeyboardStatus(int32_t status) = 0; + virtual void SendFunctionKey(int32_t funcKey) = 0; + virtual void MoveCursor(int32_t keyCode) = 0; }; } } diff --git a/frameworks/inputmethod_controller/include/input_data_channel_proxy.h b/frameworks/inputmethod_controller/include/input_data_channel_proxy.h index 23c695129..d2db27f5e 100644 --- a/frameworks/inputmethod_controller/include/input_data_channel_proxy.h +++ b/frameworks/inputmethod_controller/include/input_data_channel_proxy.h @@ -18,6 +18,7 @@ #include "iremote_proxy.h" #include "i_input_data_channel.h" +#include "input_method_utils.h" namespace OHOS { namespace MiscServices { @@ -28,8 +29,14 @@ namespace MiscServices { DISALLOW_COPY_AND_MOVE(InputDataChannelProxy); bool InsertText(const std::u16string& text) override; + bool DeleteForward(int32_t length) override; bool DeleteBackward(int32_t length) override; void Close() override; + std::u16string GetTextBeforeCursor() override; + std::u16string GetTextAfterCursor() override; + void SendKeyboardStatus(int32_t status) override; + void SendFunctionKey(int32_t funcKey) override; + void MoveCursor(int32_t keyCode) override; private: static inline BrokerDelegator delegator_; diff --git a/frameworks/inputmethod_controller/include/input_data_channel_stub.h b/frameworks/inputmethod_controller/include/input_data_channel_stub.h index c0a7b9eeb..26d8512d4 100644 --- a/frameworks/inputmethod_controller/include/input_data_channel_stub.h +++ b/frameworks/inputmethod_controller/include/input_data_channel_stub.h @@ -20,9 +20,13 @@ #include "i_input_data_channel.h" #include "iremote_stub.h" #include "message_handler.h" +#include "input_method_utils.h" +#include "input_method_controller.h" namespace OHOS { namespace MiscServices { + class InputMethodController; + class InputDataChannelStub : public IRemoteStub { public: DISALLOW_COPY_AND_MOVE(InputDataChannelStub); @@ -33,8 +37,14 @@ namespace MiscServices { void SetHandler(MessageHandler *handler); bool InsertText(const std::u16string& text) override; + bool DeleteForward(int32_t length) override; bool DeleteBackward(int32_t length) override; void Close() override; + std::u16string GetTextBeforeCursor() override; + std::u16string GetTextAfterCursor() override; + void SendKeyboardStatus(int32_t status) override; + void SendFunctionKey(int32_t funcKey) override; + void MoveCursor(int32_t keyCode) override; private: MessageHandler *msgHandler; }; diff --git a/frameworks/inputmethod_controller/include/input_method_controller.h b/frameworks/inputmethod_controller/include/input_method_controller.h index 142676d45..4557fdfb3 100644 --- a/frameworks/inputmethod_controller/include/input_method_controller.h +++ b/frameworks/inputmethod_controller/include/input_method_controller.h @@ -27,6 +27,7 @@ #include "message_handler.h" #include "iremote_object.h" #include "input_method_utils.h" +#include "key_event.h" namespace OHOS { namespace MiscServices { @@ -55,6 +56,8 @@ namespace MiscServices { public: static sptr GetInstance(); void Attach(sptr &listener); + std::u16string GetTextBeforeCursor(); + std::u16string GetTextAfterCursor(); void ShowTextInput(); void HideTextInput(); void Close(); @@ -62,6 +65,7 @@ namespace MiscServices { void OnCursorUpdate(CursorInfo cursorInfo); void OnSelectionChange(std::u16string text, int start, int end); void OnConfigurationChange(Configuration info); + bool dispatchKeyEvent(std::shared_ptr keyEvent); private: InputMethodController(); ~InputMethodController(); @@ -83,8 +87,10 @@ namespace MiscServices { OnTextChangedListener *textListener; InputAttribute mAttribute; std::u16string mTextString; - int mSelectStart; - int mSelectEnd; + int mSelectOldBegin = 0; + int mSelectOldEnd = 0; + int mSelectNewBegin = 0; + int mSelectNewEnd = 0; static std::mutex instanceLock_; static sptr instance_; 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 fcd4e5960..80fdc6f15 100644 --- a/frameworks/inputmethod_controller/include/input_method_system_ability_proxy.h +++ b/frameworks/inputmethod_controller/include/input_method_system_ability_proxy.h @@ -29,6 +29,7 @@ namespace OHOS { namespace MiscServices { + class InputDataChannelStub; class InputMethodSystemAbilityProxy : public IRemoteProxy { public: explicit InputMethodSystemAbilityProxy(const sptr &object); diff --git a/frameworks/inputmethod_controller/include/input_method_utils.h b/frameworks/inputmethod_controller/include/input_method_utils.h index 4207759b8..54e9afeab 100644 --- a/frameworks/inputmethod_controller/include/input_method_utils.h +++ b/frameworks/inputmethod_controller/include/input_method_utils.h @@ -32,6 +32,7 @@ namespace MiscServices { }; enum class TextInputType { + NONE = -1, TEXT = 0, MULTILINE, NUMBER, @@ -61,6 +62,7 @@ namespace MiscServices { { enterKeyType = keyType; } + TextInputType GetTextInputType() const { return textInputType; @@ -93,7 +95,7 @@ namespace MiscServices { }; enum class FunctionKey { NONE = 0, - CONFIRM, + CONFIRM }; class KeyboardInfo { public: @@ -116,7 +118,6 @@ namespace MiscServices { { functionKey = static_cast(key); } - private: KeyboardStatus keyboardStatus = KeyboardStatus::NONE; FunctionKey functionKey = FunctionKey::NONE; diff --git a/frameworks/inputmethod_controller/src/input_data_channel_proxy.cpp b/frameworks/inputmethod_controller/src/input_data_channel_proxy.cpp index 9026e96c4..087ab07a4 100644 --- a/frameworks/inputmethod_controller/src/input_data_channel_proxy.cpp +++ b/frameworks/inputmethod_controller/src/input_data_channel_proxy.cpp @@ -40,6 +40,22 @@ namespace MiscServices { return result; } + bool InputDataChannelProxy::DeleteForward(int32_t length) + { + IMSA_HILOGI("InputDataChannelProxy::DeleteForward"); + MessageParcel data, reply; + MessageOption option; + data.WriteInterfaceToken(GetDescriptor()); + data.WriteInt32(length); + + auto ret = Remote()->SendRequest(DELETE_FORWARD, data, reply, option); + if (ret != NO_ERROR) { + return false; + } + auto result = reply.ReadBool(); + return result; + } + bool InputDataChannelProxy::DeleteBackward(int32_t length) { IMSA_HILOGI("InputDataChannelProxy::DeleteBackward"); @@ -67,5 +83,64 @@ namespace MiscServices { if (ret != NO_ERROR) { } } + + std::u16string InputDataChannelProxy::GetTextBeforeCursor() + { + IMSA_HILOGI("InputDataChannelProxy::GetTextBeforeCursor"); + MessageParcel data, reply; + MessageOption option; + data.WriteInterfaceToken(GetDescriptor()); + + Remote()->SendRequest(GET_TEXT_BEFORE_CURSOR, data, reply, option); + auto result = reply.ReadString16(); + return result; + } + + std::u16string InputDataChannelProxy::GetTextAfterCursor() + { + IMSA_HILOGI("InputDataChannelProxy::GetTextAfterCursor"); + MessageParcel data, reply; + MessageOption option; + data.WriteInterfaceToken(GetDescriptor()); + + Remote()->SendRequest(GET_TEXT_AFTER_CURSOR, data, reply, option); + auto result = reply.ReadString16(); + return result; + } + + void InputDataChannelProxy::SendKeyboardStatus(int32_t status) + { + IMSA_HILOGI("InputDataChannelProxy::SendKeyboardStatus"); + MessageParcel data, reply; + MessageOption option; + data.WriteInterfaceToken(GetDescriptor()); + data.WriteInt32(status); + + Remote()->SendRequest(SEND_KEYBOARD_STATUS, data, reply, option); + } + + void InputDataChannelProxy::SendFunctionKey(int32_t funcKey) + { + IMSA_HILOGI("InputDataChannelProxy::SendFunctionKey"); + MessageParcel data, reply; + MessageOption option; + data.WriteInterfaceToken(GetDescriptor()); + data.WriteInt32(funcKey); + + Remote()->SendRequest(SEND_FUNCTION_KEY, data, reply, option); + } + + void InputDataChannelProxy::MoveCursor(int32_t keyCode) + { + IMSA_HILOGI("InputDataChannelProxy::MoveCursor"); + + MessageParcel data, reply; + MessageOption option; + data.WriteInterfaceToken(GetDescriptor()); + data.WriteInt32(keyCode); + + Remote()->SendRequest(MOVE_CURSOR, data, reply, option); + } +} } } \ No newline at end of file diff --git a/frameworks/inputmethod_controller/src/input_data_channel_stub.cpp b/frameworks/inputmethod_controller/src/input_data_channel_stub.cpp index 9c91dad86..6b80035fa 100644 --- a/frameworks/inputmethod_controller/src/input_data_channel_stub.cpp +++ b/frameworks/inputmethod_controller/src/input_data_channel_stub.cpp @@ -14,6 +14,7 @@ */ #include "input_data_channel_stub.h" +#include "string_ex.h" namespace OHOS { namespace MiscServices { @@ -43,6 +44,11 @@ namespace MiscServices { InsertText(text); break; } + case DELETE_FORWARD: { + auto length = data.ReadInt32(); + DeleteForward(length); + break; + } case DELETE_BACKWARD: { auto length = data.ReadInt32(); DeleteBackward(length); @@ -52,6 +58,28 @@ namespace MiscServices { Close(); break; } + case GET_TEXT_BEFORE_CURSOR: { + reply.WriteString16(GetTextBeforeCursor()); + break; + } + case GET_TEXT_AFTER_CURSOR: { + reply.WriteString16(GetTextAfterCursor()); + break; + } + case SEND_KEYBOARD_STATUS: { + auto status = data.ReadInt32(); + SendKeyboardStatus(status); + break; + } + case SEND_FUNCTION_KEY: { + auto funcKey = data.ReadInt32(); + SendFunctionKey(funcKey); + break; + } + case MOVE_CURSOR: { + auto keyCode = data.ReadInt32(); + MoveCursor(keyCode); + } default: return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } @@ -72,6 +100,20 @@ namespace MiscServices { return false; } + bool InputDataChannelStub::DeleteForward(int32_t length) + { + IMSA_HILOGI("InputDataChannelStub::DeleteForward"); + if (msgHandler == nullptr) { + return false; + } + MessageParcel *parcel = new MessageParcel; + parcel->WriteInt32(length); + Message *msg = new Message(MessageID::MSG_ID_DELETE_FORWARD, parcel); + msgHandler->SendMessage(msg); + + return true; + } + bool InputDataChannelStub::DeleteBackward(int32_t length) { IMSA_HILOGI("InputDataChannelStub::DeleteBackward"); @@ -89,6 +131,51 @@ namespace MiscServices { { } + std::u16string InputDataChannelStub::GetTextBeforeCursor() + { + IMSA_HILOGI("InputDataChannelStub::GetTextBeforeCursor"); + return InputMethodController::GetInstance()->GetTextBeforeCursor(); + } + + std::u16string InputDataChannelStub::GetTextAfterCursor() + { + IMSA_HILOGI("InputDataChannelStub::GetTextAfterCursor"); + return InputMethodController::GetInstance()->GetTextAfterCursor(); + } + + void InputDataChannelStub::SendKeyboardStatus(int32_t status) + { + IMSA_HILOGI("InputDataChannelStub::SendKeyboardStatus"); + if (msgHandler != nullptr) { + MessageParcel *parcel = new MessageParcel; + parcel->WriteInt32(status); + Message *msg = new Message(MessageID::MSG_ID_SEND_KEYBOARD_STATUS, parcel); + msgHandler->SendMessage(msg); + } + } + + void InputDataChannelStub::SendFunctionKey(int32_t funcKey) + { + IMSA_HILOGI("InputDataChannelStub::SendFunctionKey"); + if (msgHandler != nullptr) { + MessageParcel *parcel = new MessageParcel; + parcel->WriteInt32(funcKey); + Message *msg = new Message(MessageID::MSG_ID_SEND_FUNCTION_KEY, parcel); + msgHandler->SendMessage(msg); + } + } + + void InputDataChannelStub::MoveCursor(int32_t keyCode) + { + IMSA_HILOGI("InputDataChannelStub::MoveCursor"); + if (msgHandler != nullptr) { + MessageParcel *parcel = new MessageParcel; + parcel->WriteInt32(keyCode); + Message *msg = new Message(MessageID::MSG_ID_MOVE_CURSOR, parcel); + msgHandler->SendMessage(msg); + } + } + void InputDataChannelStub::SetHandler(MessageHandler *handler) { msgHandler = handler; diff --git a/frameworks/inputmethod_controller/src/input_method_controller.cpp b/frameworks/inputmethod_controller/src/input_method_controller.cpp index 9b9a255d0..5c0df77f7 100644 --- a/frameworks/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/inputmethod_controller/src/input_method_controller.cpp @@ -109,7 +109,9 @@ using namespace MessageID; } break; } - case MSG_ID_DELETE_BACKWARD: { + + case MSG_ID_DELETE_FORWARD: { + IMSA_HILOGI("InputMethodController::MSG_ID_DELETE_FORWARD"); MessageParcel *data = msg->msgContent_; int32_t length = data->ReadInt32(); if (textListener != nullptr) { @@ -117,6 +119,15 @@ using namespace MessageID; } break; } + case MSG_ID_DELETE_BACKWARD: { + IMSA_HILOGI("InputMethodController::MSG_ID_DELETE_BACKWARD"); + MessageParcel *data = msg->msgContent_; + int32_t length = data->ReadInt32(); + if (textListener != nullptr) { + textListener->DeleteBackward(length); + } + break; + } case MSG_ID_SET_DISPLAY_MODE: { MessageParcel *data = msg->msgContent_; int32_t ret = data->ReadInt32(); @@ -147,6 +158,38 @@ using namespace MessageID; IMSA_HILOGI("MSG_ID_EXIT_SERVICE : %{public}d", ret); break; } + case MSG_ID_SEND_KEYBOARD_STATUS: { + MessageParcel *data = msg->msgContent_; + int32_t ret = data->ReadInt32(); + IMSA_HILOGI("MSG_ID_SEND_KEYBOARD_STATUS : %{public}d", ret); + KeyboardInfo *info = new KeyboardInfo(); + info->SetKeyboardStatus(ret); + if (textListener != nullptr) { + textListener->SendKeyboardInfo(*info); + } + break; + } + case MSG_ID_SEND_FUNCTION_KEY: { + MessageParcel *data = msg->msgContent_; + int32_t ret = data->ReadInt32(); + IMSA_HILOGI("MSG_ID_SEND_FUNCTION_KEY : %{public}d", ret); + KeyboardInfo *info = new KeyboardInfo(); + info->SetFunctionKey(ret); + if (textListener != nullptr) { + textListener->SendKeyboardInfo(*info); + } + break; + } + case MSG_ID_MOVE_CURSOR: { + MessageParcel *data = msg->msgContent_; + int32_t ret = data->ReadInt32(); + IMSA_HILOGI("MSG_ID_MOVE_CURSOR : %{public}d", ret); + if (textListener != nullptr) { + Direction direction = static_cast(ret); + textListener->MoveCursor(direction); + } + break; + } default: { break; } @@ -159,7 +202,7 @@ using namespace MessageID; void InputMethodController::Attach(sptr &listener) { PrepareInput(0, mClient, mInputDataChannel, mAttribute); - textListener=listener; + textListener = listener; } void InputMethodController::ShowTextInput() @@ -177,6 +220,7 @@ using namespace MessageID; void InputMethodController::Close() { ReleaseInput(mClient); + textListener = nullptr; } void InputMethodController::PrepareInput(int32_t displayId, sptr &client, @@ -255,20 +299,64 @@ using namespace MessageID; void InputMethodController::OnCursorUpdate(CursorInfo cursorInfo) { - IMSA_HILOGI("InputMethodController::OnCursorUpdate"); + if (mAgent == nullptr) { + IMSA_HILOGI("InputMethodController::OnCursorUpdate mAgent is nullptr"); + return; + } + + mAgent->OnCursorUpdate(cursorInfo.left, cursorInfo.top, cursorInfo.height); } void InputMethodController::OnSelectionChange(std::u16string text, int start, int end) { IMSA_HILOGI("InputMethodController::OnSelectionChange"); mTextString = text; - mSelectStart = start; - mSelectEnd = end; + mSelectOldBegin = mSelectNewBegin; + mSelectOldEnd = mSelectNewEnd; + mSelectNewBegin = start; + mSelectNewEnd = end; + if (mAgent == nullptr) { + IMSA_HILOGI("InputMethodController::OnSelectionChange mAgent is nullptr"); + return; + } + mAgent->OnSelectionChange(mTextString, mSelectOldBegin, mSelectOldEnd, mSelectNewBegin, mSelectNewEnd); } void InputMethodController::OnConfigurationChange(Configuration info) { IMSA_HILOGI("InputMethodController::OnConfigurationChange"); } + + std::u16string InputMethodController::GetTextBeforeCursor() + { + IMSA_HILOGI("InputMethodController::GetTextBeforeCursor"); + if (!mTextString.empty()) { + return mTextString.substr(0, mSelectNewBegin); + } + return u""; + } + + std::u16string InputMethodController::GetTextAfterCursor() + { + IMSA_HILOGI("InputMethodController::GetTextBeforeCursor"); + if (!mTextString.empty()) { + if (mTextString.size() > mSelectNewEnd) { + return mTextString.substr(mSelectNewEnd); + } + } + return u""; + } + + bool InputMethodController::dispatchKeyEvent(std::shared_ptr keyEvent) + { + IMSA_HILOGI("InputMethodController::dispatchKeyEvent"); + if (mAgent == nullptr) { + IMSA_HILOGI("InputMethodController::dispatchKeyEvent mAgent is nullptr"); + return false; + } + IMSA_HILOGI("InputMethodController::dispatchKeyEvent (%{public}d, %{public}d)", keyEvent->GetKeyCode(), keyEvent->GetKeyAction()); + mAgent->DispatchKey(keyEvent->GetKeyCode(), keyEvent->GetKeyAction()); + return true; + } +} } -} \ No newline at end of file diff --git a/interfaces/kits/js/declaration/api/@ohos.inputmethodengine.d.ts b/interfaces/kits/js/declaration/api/@ohos.inputmethodengine.d.ts index 0d4ef4db2..a2b85610f 100644 --- a/interfaces/kits/js/declaration/api/@ohos.inputmethodengine.d.ts +++ b/interfaces/kits/js/declaration/api/@ohos.inputmethodengine.d.ts @@ -28,14 +28,28 @@ declare namespace inputMethodEngine { function on(type: 'keyboardHide', callback: () => void): void; function off(type: 'keyboardHide', callback: () => void): void; - function insertText(text: string, callback: AsyncCallback): void; - function insertText(text: string): Promise; + function InsertText(text: string, callback: AsyncCallback): void; + function InsertText(text: string): Promise; + + function DeleteForward(length: number, callback: () => void): void; + function DeleteForward(length: number): Promise; function DeleteBackward(length: number, callback: () => void): void; function DeleteBackward(length: number): Promise; - function HideKeyboardSelf(callback: callback: () => void): void; + function HideKeyboardSelf(callback: () => void): void; function HideKeyboardSelf(): Promise; + + function GetTextBeforeCursor(callback: () => string): void; + function GetTextBeforeCursor(): Promise; + + function GetTextAfterCursor(callback: () => string): void; + function GetTextAfterCursor(): Promise; + + function SendFunctionKey(callback: () => void): void; + function SendFunctionKey(): Promise; + + const FUNCTION_KEY_CONFIRM: number; } export default inputMethodEngine; diff --git a/interfaces/kits/js/napi/BUILD.gn b/interfaces/kits/js/napi/BUILD.gn index a7407f3c6..f5ea0e438 100644 --- a/interfaces/kits/js/napi/BUILD.gn +++ b/interfaces/kits/js/napi/BUILD.gn @@ -47,7 +47,6 @@ ohos_shared_library("inputmethodengine") { "//foundation/aafwk/standard/interfaces/innerkits/base:base", "//foundation/aafwk/standard/interfaces/innerkits/intent:intent", "//foundation/aafwk/standard/interfaces/innerkits/want:want", - "//foundation/aafwk/standard/interfaces/innerkits/want:want", "//foundation/ace/napi/:ace_napi", "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base", "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core", diff --git a/interfaces/kits/js/napi/js_input_method_engine.cpp b/interfaces/kits/js/napi/js_input_method_engine.cpp index e044d1fca..aad47e68a 100644 --- a/interfaces/kits/js/napi/js_input_method_engine.cpp +++ b/interfaces/kits/js/napi/js_input_method_engine.cpp @@ -17,6 +17,8 @@ #include "napi/native_api.h" #include "napi/native_node_api.h" #include "global.h" +#include "string_ex.h" +#include "input_method_utils.h" namespace OHOS { namespace MiscServices { @@ -64,6 +66,27 @@ namespace MiscServices { return result; } + napi_value JS_DeleteForward(napi_env env, napi_callback_info cbInfo) + { + IMSA_HILOGI("JS_DeleteForward() is called!"); + size_t argc = 1; + napi_value argv[2] = { 0 }; + napi_value thisVar = nullptr; + void *data = nullptr; + napi_get_cb_info(env, cbInfo, &argc, argv, &thisVar, &data); + + EventTarget *eventTarget = nullptr; + napi_unwrap(env, thisVar, (void **)&eventTarget); + + int32_t value32 = 0; + napi_get_value_int32(env, argv[0], &value32); + InputMethodAbility::GetInstance()->DeleteForward(value32); + + napi_value result = nullptr; + napi_get_undefined(env, &result); + return result; + } + napi_value JS_DeleteBackward(napi_env env, napi_callback_info cbInfo) { IMSA_HILOGI("JS_DeleteBackward() is called!"); @@ -85,6 +108,27 @@ namespace MiscServices { return result; } + napi_value JS_MoveCursor(napi_env env, napi_callback_info cbInfo) + { + IMSA_HILOGI("JS_MoveCursor() is called!"); + size_t argc = 1; + napi_value argv[2] = { 0 }; + napi_value thisVar = nullptr; + void *data = nullptr; + napi_get_cb_info(env, cbInfo, &argc, argv, &thisVar, &data); + + EventTarget *eventTarget = nullptr; + napi_unwrap(env, thisVar, (void **)&eventTarget); + + int32_t value32 = 0; + napi_get_value_int32(env, argv[0], &value32); + InputMethodAbility::GetInstance()->MoveCursor(value32); + + napi_value result = nullptr; + napi_get_undefined(env, &result); + return result; + } + napi_value JS_HideKeyboardSelf(napi_env env, napi_callback_info cbInfo) { IMSA_HILOGI("JS_HideKeyboardSelf() is called!"); @@ -104,6 +148,67 @@ namespace MiscServices { return result; } + napi_value JS_GetTextBeforeCursor(napi_env env, napi_callback_info cbInfo) + { + IMSA_HILOGI("JS_GetTextBeforeCursor() is called!"); + size_t argc = 1; + napi_value argv[2] = { 0 }; + napi_value thisVar = nullptr; + void *data = nullptr; + napi_get_cb_info(env, cbInfo, &argc, argv, &thisVar, &data); + + EventTarget *eventTarget = nullptr; + napi_unwrap(env, thisVar, (void **)&eventTarget); + + std::u16string textString = InputMethodAbility::GetInstance()->GetTextBeforeCursor(); + std::string outString = Str16ToStr8(textString.c_str()); + + napi_value result = nullptr; + napi_create_string_utf8(env, outString.c_str(), NAPI_AUTO_LENGTH, &result); + return result; + } + + napi_value JS_GetTextAfterCursor(napi_env env, napi_callback_info cbInfo) + { + IMSA_HILOGI("JS_GetTextAfterCursor() is called!"); + size_t argc = 1; + napi_value argv[2] = { 0 }; + napi_value thisVar = nullptr; + void *data = nullptr; + napi_get_cb_info(env, cbInfo, &argc, argv, &thisVar, &data); + + EventTarget *eventTarget = nullptr; + napi_unwrap(env, thisVar, (void **)&eventTarget); + + std::u16string textString = InputMethodAbility::GetInstance()->GetTextAfterCursor(); + std::string outString = Str16ToStr8(textString.c_str()); + + napi_value result = nullptr; + napi_create_string_utf8(env, outString.c_str(), NAPI_AUTO_LENGTH, &result); + return result; + } + + napi_value JS_SendFunctionKey(napi_env env, napi_callback_info cbInfo) + { + IMSA_HILOGI("JS_SendFunctionKey() is called!"); + size_t argc = 1; + napi_value argv[2] = { 0 }; + napi_value thisVar = nullptr; + void *data = nullptr; + napi_get_cb_info(env, cbInfo, &argc, argv, &thisVar, &data); + + EventTarget *eventTarget = nullptr; + napi_unwrap(env, thisVar, (void **)&eventTarget); + + int32_t value32 = 0; + napi_get_value_int32(env, argv[0], &value32); + InputMethodAbility::GetInstance()->SendFunctionKey(value32); + + napi_value result = nullptr; + napi_get_undefined(env, &result); + return result; + } + napi_value JS_On(napi_env env, napi_callback_info cbInfo) { IMSA_HILOGI("JS_On() is called!"); @@ -178,17 +283,33 @@ namespace MiscServices { return result; } + napi_value ToInt32Value(napi_env env, int32_t value) + { + napi_value staticValue = nullptr; + napi_create_int32(env, value, &staticValue); + return staticValue; + } + napi_value InputMethodEngineInit(napi_env env, napi_value exports) { IMSA_HILOGI("InputMethodEngineInit() is called!"); const char className[] = "EventTarget"; napi_value constructor = nullptr; napi_property_descriptor desc[] = { - DECLARE_NAPI_FUNCTION("insertText", JS_InsertText), + DECLARE_NAPI_FUNCTION("InsertText", JS_InsertText), + DECLARE_NAPI_FUNCTION("DeleteForward", JS_DeleteForward), DECLARE_NAPI_FUNCTION("DeleteBackward", JS_DeleteBackward), DECLARE_NAPI_FUNCTION("HideKeyboardSelf", JS_HideKeyboardSelf), + DECLARE_NAPI_FUNCTION("GetTextBeforeCursor", JS_GetTextBeforeCursor), + DECLARE_NAPI_FUNCTION("GetTextAfterCursor", JS_GetTextAfterCursor), + DECLARE_NAPI_FUNCTION("SendFunctionKey", JS_SendFunctionKey), DECLARE_NAPI_FUNCTION("on", JS_On), DECLARE_NAPI_FUNCTION("off", JS_Off), + DECLARE_NAPI_STATIC_PROPERTY("FUNCTION_KEY_CONFIRM", ToInt32Value(env, 1)), + DECLARE_NAPI_STATIC_PROPERTY("CURSOR_UP", ToInt32Value(env, 1)), + DECLARE_NAPI_STATIC_PROPERTY("CURSOR_DOWN", ToInt32Value(env, 2)), + DECLARE_NAPI_STATIC_PROPERTY("CURSOR_LEFT", ToInt32Value(env, 3)), + DECLARE_NAPI_STATIC_PROPERTY("CURSOR_RIGHT", ToInt32Value(env, 4)), }; napi_define_class(env, className, sizeof(className), JS_Constructor, nullptr, sizeof(desc) / sizeof(desc[0]), desc, &constructor); diff --git a/services/BUILD.gn b/services/BUILD.gn index 23db56920..e01e86d94 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -29,6 +29,7 @@ ohos_shared_library("inputmethod_service") { "${inputmethod_path}/frameworks/inputmethod_ability/src/input_method_ability.cpp", "${inputmethod_path}/frameworks/inputmethod_ability/src/input_method_agent_proxy.cpp", "${inputmethod_path}/frameworks/inputmethod_ability/src/input_method_agent_stub.cpp", + "${inputmethod_path}/frameworks/inputmethod_ability/src/event_target.cpp", "${inputmethod_path}/frameworks/inputmethod_ability/src/input_method_core_proxy.cpp", "${inputmethod_path}/frameworks/inputmethod_ability/src/input_method_core_stub.cpp", "${inputmethod_path}/frameworks/inputmethod_controller/src/input_client_proxy.cpp", diff --git a/services/include/i_input_method_proxy.h b/services/include/i_input_method_proxy.h deleted file mode 100644 index 35f1573ef..000000000 --- a/services/include/i_input_method_proxy.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FM_IMMS_PROJECT_IINPUTMETHODAGENT_H -#define FM_IMMS_PROJECT_IINPUTMETHODAGENT_H - -#include "iremote_broker.h" -#include "iremote_object.h" -#include "global.h" - -namespace OHOS { - namespace MiscServices { - class IInputMethodProxy : public IRemoteBroker { - public: - enum { - DISPATCH_KEY = FIRST_CALL_TRANSACTION, - }; - - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.inputmethod.IInputMethodProxy"); - - virtual int32_t dispatchKey(int key, int status) = 0; - }; - } -} -#endif // FM_IMMS_PROJECT_IINPUTMETHODAGENT_H diff --git a/services/include/input_method_system_ability.h b/services/include/input_method_system_ability.h index 661d7b789..c0f4b3df6 100644 --- a/services/include/input_method_system_ability.h +++ b/services/include/input_method_system_ability.h @@ -27,6 +27,7 @@ namespace OHOS { namespace MiscServices { + class InputDataChannelStub; enum class ServiceRunningState { STATE_NOT_START, STATE_RUNNING diff --git a/services/include/message_handler.h b/services/include/message_handler.h index b370193c5..530310a73 100644 --- a/services/include/message_handler.h +++ b/services/include/message_handler.h @@ -58,11 +58,15 @@ namespace MessageID { MSG_ID_SHELL_COMMAND, // shell command MSG_ID_EXIT_SERVICE, // exit service - //the request from IMSA to IMC + // the request from IMSA to IMC MSG_ID_INSERT_CHAR, + MSG_ID_DELETE_FORWARD, MSG_ID_DELETE_BACKWARD, MSG_ID_CLOSE, MSG_ID_ON_INPUT_READY, + MSG_ID_SEND_KEYBOARD_STATUS, + MSG_ID_SEND_FUNCTION_KEY, + MSG_ID_MOVE_CURSOR, // the request from IMSA to IMA MSG_ID_SHOW_KEYBOARD, @@ -73,6 +77,8 @@ namespace MessageID { // the request from IMC to IMA MSG_ID_DISPATCH_KEY, // dispatch key from PhysicalKbd + MSG_ID_ON_CURSOR_UPDATE, + MSG_ID_ON_SELECTION_CHANGE, }; } diff --git a/services/src/input_method_agent_proxy.cpp b/services/src/input_method_agent_proxy.cpp deleted file mode 100644 index 03da4ecf7..000000000 --- a/services/src/input_method_agent_proxy.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "i_input_method_agent.h" -#include "iremote_proxy.h" -#include "iremote_broker.h" -#include "global.h" - -/*! \class BpInputMethodAgentProxy - \brief The proxy implementation of IInputMethodAgent - - This class should be implemented by input client -*/ -namespace OHOS { -namespace MiscServices { - class InputMethodAgentProxy : public IRemoteProxy { - public: - InputMethodAgentProxy(const sptr& impl) - : IRemoteProxy(impl) - { - } - - ~InputMethodAgentProxy() - { - } - - int32_t dispatchKey(int key, int status) - { - (void)key; - (void)status; - return NO_ERROR; - } - }; -} -} - diff --git a/services/src/peruser_setting.cpp b/services/src/peruser_setting.cpp index 5dcdf453e..0d999c870 100644 --- a/services/src/peruser_setting.cpp +++ b/services/src/peruser_setting.cpp @@ -290,7 +290,6 @@ namespace MiscServices { for (int i = 0; i < size; i++) { dprintf(fd, " [%d] ImeId = %s\n", i, Utils::to_utf8(imeList[i]).c_str()); std::vector hashCodeList = inputMethodSetting.GetEnabledKeyboardTypes(imeList[i]); - dprintf(fd, " Enabled keyboard count = %d, hashcode list : ", hashCodeList.size()); for (int j = 0; j < (int)hashCodeList.size(); j++) { dprintf(fd, "%d", hashCodeList[j]); if (j < (int)hashCodeList.size()-1) { diff --git a/unitest/src/input_method_controller_test.cpp b/unitest/src/input_method_controller_test.cpp index 702f36c78..ba8878aec 100644 --- a/unitest/src/input_method_controller_test.cpp +++ b/unitest/src/input_method_controller_test.cpp @@ -60,13 +60,13 @@ namespace MiscServices { { IMSA_HILOGI("IMC TEST TextListener sendKeyEventFromInputMethod"); } - void SendKeyboardInfo(const KeyboardInfo& info) + void SendKeyboardInfo(const KeyboardInfo& status) { IMSA_HILOGI("IMC TEST TextListener SendKeyboardInfo"); } void MoveCursor(const Direction direction) { - IMSA_HILOGI("IMC TEST TextListener Direction"); + IMSA_HILOGI("IMC TEST TextListener MoveCursor"); } }; class InputMethodControllerTest : public testing::Test { -- Gitee From 6d01ffd0b4fec8195f202a08e62f8a5b640865a9 Mon Sep 17 00:00:00 2001 From: zhouyongfei Date: Thu, 13 Jan 2022 20:08:22 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhouyongfei --- .../inputmethod_controller/src/input_data_channel_proxy.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/frameworks/inputmethod_controller/src/input_data_channel_proxy.cpp b/frameworks/inputmethod_controller/src/input_data_channel_proxy.cpp index 087ab07a4..7d6207b57 100644 --- a/frameworks/inputmethod_controller/src/input_data_channel_proxy.cpp +++ b/frameworks/inputmethod_controller/src/input_data_channel_proxy.cpp @@ -143,4 +143,3 @@ namespace MiscServices { } } } -} \ No newline at end of file -- Gitee From 66a5eca3ce1643b8d518187c093d14c825f5e27a Mon Sep 17 00:00:00 2001 From: zhouyongfei Date: Thu, 13 Jan 2022 20:12:44 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=9D=99=E6=80=81?= =?UTF-8?q?=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhouyongfei --- .../inputmethod_controller/src/input_method_controller.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frameworks/inputmethod_controller/src/input_method_controller.cpp b/frameworks/inputmethod_controller/src/input_method_controller.cpp index 5c0df77f7..0e92e0e80 100644 --- a/frameworks/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/inputmethod_controller/src/input_method_controller.cpp @@ -354,7 +354,8 @@ using namespace MessageID; IMSA_HILOGI("InputMethodController::dispatchKeyEvent mAgent is nullptr"); return false; } - IMSA_HILOGI("InputMethodController::dispatchKeyEvent (%{public}d, %{public}d)", keyEvent->GetKeyCode(), keyEvent->GetKeyAction()); + IMSA_HILOGI("InputMethodController::dispatchKeyEvent (%{public}d, %{public}d)", + keyEvent->GetKeyCode(), keyEvent->GetKeyAction()); mAgent->DispatchKey(keyEvent->GetKeyCode(), keyEvent->GetKeyAction()); return true; } -- Gitee From d7dfac3482e35bd3d1eff3a486355e925e63ea56 Mon Sep 17 00:00:00 2001 From: zhouyongfei Date: Thu, 13 Jan 2022 20:45:48 +0800 Subject: [PATCH 4/7] =?UTF-8?q?format=20gn=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhouyongfei --- frameworks/inputmethod_ability/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/inputmethod_ability/BUILD.gn b/frameworks/inputmethod_ability/BUILD.gn index a42b344df..0d518b7e3 100644 --- a/frameworks/inputmethod_ability/BUILD.gn +++ b/frameworks/inputmethod_ability/BUILD.gn @@ -41,11 +41,11 @@ ohos_shared_library("inputmethod_ability") { deps = [ "//base/global/resmgr_standard/frameworks/resmgr:global_resmgr", "//base/miscservices/inputmethod/services:inputmethod_service", + "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", "//foundation/aafwk/standard/interfaces/innerkits/base:base", "//foundation/aafwk/standard/interfaces/innerkits/intent:intent", "//foundation/aafwk/standard/interfaces/innerkits/want:want", - "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/ace/napi/:ace_napi", "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base", "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core", -- Gitee From 8ba043c28001eebad902d750b83aff9c5a2c4e2a Mon Sep 17 00:00:00 2001 From: zhouyongfei Date: Thu, 13 Jan 2022 20:47:59 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=9D=99=E6=80=81?= =?UTF-8?q?=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhouyongfei --- frameworks/inputmethod_ability/src/event_target.cpp | 4 ++-- .../inputmethod_ability/src/input_method_agent_proxy.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frameworks/inputmethod_ability/src/event_target.cpp b/frameworks/inputmethod_ability/src/event_target.cpp index 508c16a4f..0d052b9b4 100644 --- a/frameworks/inputmethod_ability/src/event_target.cpp +++ b/frameworks/inputmethod_ability/src/event_target.cpp @@ -387,7 +387,7 @@ namespace MiscServices { work->data = (void *)eventTargetCB; int ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, [](uv_work_t *work, int status) { - //Js Thread + // Js Thread if (work == nullptr) { IMSA_HILOGI("EventTarget::Emit work == nullptr"); return; @@ -407,7 +407,7 @@ namespace MiscServices { napi_value result = nullptr; napi_get_reference_value(eventTargetCB->env, eventListener->handlerRef, &handler); napi_call_function(eventTargetCB->env, thisVar, handler, - jsEvent ? 1 : 0, jsEvent ? &jsEvent : nullptr, &result); + jsEvent ? 1 : 0, jsEvent ? &jsEvent : nullptr, &result); if (eventListener->isOnce) { eventTargetCB->eventTarget->Off(eventTargetCB->type, handler); } diff --git a/frameworks/inputmethod_ability/src/input_method_agent_proxy.cpp b/frameworks/inputmethod_ability/src/input_method_agent_proxy.cpp index 456fab351..9ffa3d4d3 100644 --- a/frameworks/inputmethod_ability/src/input_method_agent_proxy.cpp +++ b/frameworks/inputmethod_ability/src/input_method_agent_proxy.cpp @@ -19,7 +19,7 @@ namespace OHOS { namespace MiscServices { using namespace ErrorCode; InputMethodAgentProxy::InputMethodAgentProxy(const sptr &object) - : IRemoteProxy(object) + : IRemoteProxy(object) { } -- Gitee From f85da636778a6926dc5e9196f30b64cd19914399 Mon Sep 17 00:00:00 2001 From: zhouyongfei Date: Fri, 14 Jan 2022 09:34:03 +0800 Subject: [PATCH 6/7] commit gn -s Signed-off-by: zhouyongfei --- frameworks/inputmethod_controller/BUILD.gn | 18 ++++++++---------- services/BUILD.gn | 2 +- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/frameworks/inputmethod_controller/BUILD.gn b/frameworks/inputmethod_controller/BUILD.gn index 230c70138..75174929a 100644 --- a/frameworks/inputmethod_controller/BUILD.gn +++ b/frameworks/inputmethod_controller/BUILD.gn @@ -36,6 +36,14 @@ config("inputmethod_client_native_public_config") { ohos_shared_library("inputmethod_client") { sources = [ + "${inputmethod_path}/frameworks/inputmethod_ability/src/input_method_agent_proxy.cpp", + "${inputmethod_path}/services/src/global.cpp", + "${inputmethod_path}/services/src/input_attribute.cpp", + "${inputmethod_path}/services/src/input_channel.cpp", + "${inputmethod_path}/services/src/input_method_property.cpp", + "${inputmethod_path}/services/src/keyboard_type.cpp", + "${inputmethod_path}/services/src/message.cpp", + "${inputmethod_path}/services/src/message_handler.cpp", "src/input_client_proxy.cpp", "src/input_client_stub.cpp", "src/input_data_channel_proxy.cpp", @@ -43,16 +51,6 @@ ohos_shared_library("inputmethod_client") { "src/input_method_controller.cpp", "src/input_method_system_ability_proxy.cpp", "src/input_method_utils.cpp", - - "${inputmethod_path}/frameworks/inputmethod_ability/src/input_method_agent_proxy.cpp", - - "${inputmethod_path}/services/src/input_channel.cpp", - "${inputmethod_path}/services/src/global.cpp", - "${inputmethod_path}/services/src/message_handler.cpp", - "${inputmethod_path}/services/src/keyboard_type.cpp", - "${inputmethod_path}/services/src/input_method_property.cpp", - "${inputmethod_path}/services/src/message.cpp", - "${inputmethod_path}/services/src/input_attribute.cpp", ] deps = [ diff --git a/services/BUILD.gn b/services/BUILD.gn index e01e86d94..79462f849 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -26,10 +26,10 @@ config("inputmethod_services_native_config") { ohos_shared_library("inputmethod_service") { sources = [ + "${inputmethod_path}/frameworks/inputmethod_ability/src/event_target.cpp", "${inputmethod_path}/frameworks/inputmethod_ability/src/input_method_ability.cpp", "${inputmethod_path}/frameworks/inputmethod_ability/src/input_method_agent_proxy.cpp", "${inputmethod_path}/frameworks/inputmethod_ability/src/input_method_agent_stub.cpp", - "${inputmethod_path}/frameworks/inputmethod_ability/src/event_target.cpp", "${inputmethod_path}/frameworks/inputmethod_ability/src/input_method_core_proxy.cpp", "${inputmethod_path}/frameworks/inputmethod_ability/src/input_method_core_stub.cpp", "${inputmethod_path}/frameworks/inputmethod_controller/src/input_client_proxy.cpp", -- Gitee From 3fb3ca50cd264319d11ae6de6f683407df002ce0 Mon Sep 17 00:00:00 2001 From: zhouyongfei Date: Fri, 14 Jan 2022 17:52:03 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhouyongfei --- interfaces/kits/js/napi/js_input_method_engine.cpp | 1 - services/src/peruser_setting.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/interfaces/kits/js/napi/js_input_method_engine.cpp b/interfaces/kits/js/napi/js_input_method_engine.cpp index aad47e68a..a1e8121b0 100644 --- a/interfaces/kits/js/napi/js_input_method_engine.cpp +++ b/interfaces/kits/js/napi/js_input_method_engine.cpp @@ -276,7 +276,6 @@ namespace MiscServices { eventTarget->Off(type); } - delete type; type = nullptr; napi_value result = nullptr; napi_get_undefined(env, &result); diff --git a/services/src/peruser_setting.cpp b/services/src/peruser_setting.cpp index 0d999c870..bb897dd5b 100644 --- a/services/src/peruser_setting.cpp +++ b/services/src/peruser_setting.cpp @@ -161,7 +161,7 @@ namespace MiscServices { std::u16string key = InputMethodSetting::ENABLED_INPUT_METHODS_TAG; imSetting.SetValue(key, inputMethodSetting.GetValue(key)); - int flag = imSetting.RemoveEnabledInputMethod(imeId); + bool flag = imSetting.RemoveEnabledInputMethod(imeId); if (flag == false) { IMSA_HILOGI("The package removed is not an enabled IME. [%d]\n", userId_); return ErrorCode::NO_ERROR; -- Gitee