同步黄区需求代码

Signed-off-by: zhouyongfei <zhouyongfei@huawei.com>
This commit is contained in:
zhouyongfei 2022-01-13 19:49:53 +08:00
parent 102139ae9e
commit dd69d6ae66
32 changed files with 934 additions and 122 deletions

View File

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

View File

@ -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> &eventTarget, const char *type, Event *event);
virtual napi_env GetEnv();
protected:
private:
napi_env env_;
napi_ref thisVarRef_;
EventListener *first_;

View File

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

View File

@ -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,
};

View File

@ -42,8 +42,13 @@ namespace MiscServices {
sptr<IInputMethodCore> OnConnect();
bool InsertText(const std::string text);
void setEventTarget(sptr<EventTarget> &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<IRemoteObject> startInputToken;
InputChannel *writeInputChannel;
bool stop_;
int32_t KEYBOARD_HIDE = 1;
int32_t KEYBOARD_SHOW = 2;
// communicating with IMSA
sptr<IInputControlChannel> 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();

View File

@ -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<InputMethodAgentProxy> delegator_;
};

View File

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

View File

@ -12,13 +12,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <uv.h>
#include "event_target.h"
#include "securec.h"
#include <uv.h>
#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_;
}
}
}

View File

@ -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<IInputMethodCore> 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;
}
}
}

View File

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

View File

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

View File

@ -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 <chrono>
#include <cstdint>
#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"

View File

@ -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",
]

View File

@ -18,6 +18,7 @@
#include <errors.h>
#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;
};
}
}

View File

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

View File

@ -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<IInputDataChannel> {
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;
};

View File

@ -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<InputMethodController> GetInstance();
void Attach(sptr<OnTextChangedListener> &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<MMI::KeyEvent> 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<InputMethodController> instance_;

View File

@ -29,6 +29,7 @@
namespace OHOS {
namespace MiscServices {
class InputDataChannelStub;
class InputMethodSystemAbilityProxy : public IRemoteProxy<IInputMethodSystemAbility> {
public:
explicit InputMethodSystemAbilityProxy(const sptr<IRemoteObject> &object);

View File

@ -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<FunctionKey>(key);
}
private:
KeyboardStatus keyboardStatus = KeyboardStatus::NONE;
FunctionKey functionKey = FunctionKey::NONE;

View File

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

View File

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

View File

@ -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<Direction>(ret);
textListener->MoveCursor(direction);
}
break;
}
default: {
break;
}
@ -159,7 +202,7 @@ using namespace MessageID;
void InputMethodController::Attach(sptr<OnTextChangedListener> &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<InputClientStub> &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<MMI::KeyEvent> 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;
}
}
}
}

View File

@ -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<boolean>): void;
function insertText(text: string): Promise<boolean>;
function InsertText(text: string, callback: AsyncCallback<boolean>): void;
function InsertText(text: string): Promise<boolean>;
function DeleteForward(length: number, callback: () => void): void;
function DeleteForward(length: number): Promise<void>;
function DeleteBackward(length: number, callback: () => void): void;
function DeleteBackward(length: number): Promise<void>;
function HideKeyboardSelf(callback: callback: () => void): void;
function HideKeyboardSelf(callback: () => void): void;
function HideKeyboardSelf(): Promise<void>;
function GetTextBeforeCursor(callback: () => string): void;
function GetTextBeforeCursor(): Promise<string>;
function GetTextAfterCursor(callback: () => string): void;
function GetTextAfterCursor(): Promise<string>;
function SendFunctionKey(callback: () => void): void;
function SendFunctionKey(): Promise<void>;
const FUNCTION_KEY_CONFIRM: number;
}
export default inputMethodEngine;

View File

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

View File

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

View File

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

View File

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

View File

@ -27,6 +27,7 @@
namespace OHOS {
namespace MiscServices {
class InputDataChannelStub;
enum class ServiceRunningState {
STATE_NOT_START,
STATE_RUNNING

View File

@ -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,
};
}

View File

@ -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<IInputMethodAgent> {
public:
InputMethodAgentProxy(const sptr<IRemoteObject>& impl)
: IRemoteProxy<IInputMethodAgent>(impl)
{
}
~InputMethodAgentProxy()
{
}
int32_t dispatchKey(int key, int status)
{
(void)key;
(void)status;
return NO_ERROR;
}
};
}
}

View File

@ -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<int> 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) {

View File

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