mirror of
https://github.com/openharmony/miscservices_inputmethod.git
synced 2026-07-22 08:25:20 -04:00
@@ -18,6 +18,7 @@ config("inputmethod_client_native_config") {
|
||||
include_dirs = [
|
||||
"include",
|
||||
"//utils/native/base/include",
|
||||
"${inputmethod_path}/services/include",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -37,9 +38,7 @@ 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",
|
||||
|
||||
@@ -37,8 +37,7 @@ namespace MiscServices {
|
||||
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.inputmethod.InputClient");
|
||||
|
||||
virtual int32_t onInputReady(int32_t retValue, const sptr<IInputMethodAgent>& agent,
|
||||
const InputChannel *channel) = 0;
|
||||
virtual int32_t onInputReady(const sptr<IInputMethodAgent>& agent) = 0;
|
||||
virtual int32_t onInputReleased(int32_t retValue) = 0;
|
||||
virtual int32_t setDisplayMode(int32_t mode) = 0;
|
||||
};
|
||||
|
||||
@@ -22,13 +22,13 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
class InputClientProxy : public IRemoteProxy<IInputClient> {
|
||||
class InputClientProxy : public IRemoteProxy<IInputClient> {
|
||||
public:
|
||||
explicit InputClientProxy(const sptr<IRemoteObject> &object);
|
||||
~InputClientProxy() = default;
|
||||
DISALLOW_COPY_AND_MOVE(InputClientProxy);
|
||||
|
||||
int32_t onInputReady(int32_t retValue, const sptr<IInputMethodAgent>& agent, const InputChannel *channel) override;
|
||||
int32_t onInputReady(const sptr<IInputMethodAgent>& agent) override;
|
||||
int32_t onInputReleased(int32_t retValue) override;
|
||||
int32_t setDisplayMode(int32_t mode) override;
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "iremote_stub.h"
|
||||
#include "i_input_client.h"
|
||||
#include "message_handler.h"
|
||||
#include "message.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
@@ -32,8 +33,7 @@ namespace MiscServices {
|
||||
~InputClientStub();
|
||||
void SetHandler(MessageHandler *handler);
|
||||
|
||||
int32_t onInputReady(int32_t retValue, const sptr<IInputMethodAgent>& agent,
|
||||
const InputChannel *channel) override;
|
||||
int32_t onInputReady(const sptr<IInputMethodAgent>& agent) override;
|
||||
int32_t onInputReleased(int32_t retValue) override;
|
||||
int32_t setDisplayMode(int32_t mode) override;
|
||||
private:
|
||||
|
||||
@@ -91,7 +91,7 @@ namespace MiscServices {
|
||||
int mSelectOldEnd = 0;
|
||||
int mSelectNewBegin = 0;
|
||||
int mSelectNewEnd = 0;
|
||||
int32_t mSpecialKeyPress = 0;
|
||||
CursorInfo cursorInfo_;
|
||||
|
||||
static std::mutex instanceLock_;
|
||||
static sptr<InputMethodController> instance_;
|
||||
@@ -101,4 +101,4 @@ namespace MiscServices {
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -40,8 +40,7 @@ namespace MiscServices {
|
||||
virtual void releaseInput(MessageParcel& data) override;
|
||||
virtual void startInput(MessageParcel& data) override;
|
||||
virtual void stopInput(MessageParcel& data) override;
|
||||
virtual void DispatchKey(MessageParcel& data) override;
|
||||
virtual int32_t setInputMethodCore(sptr<IInputMethodCore> &core) override;
|
||||
virtual void SetCoreAndAgent(MessageParcel& data) override;
|
||||
|
||||
int32_t Prepare(int32_t displayId, sptr<InputClientStub> &client, sptr<InputDataChannelStub> &channel,
|
||||
InputAttribute &attribute);
|
||||
|
||||
@@ -22,8 +22,7 @@ using namespace ErrorCode;
|
||||
{
|
||||
}
|
||||
|
||||
int32_t InputClientProxy::onInputReady(int32_t retValue, const sptr<IInputMethodAgent>& agent,
|
||||
const InputChannel *channel)
|
||||
int32_t InputClientProxy::onInputReady(const sptr<IInputMethodAgent>& agent)
|
||||
{
|
||||
IMSA_HILOGI("InputClientProxy::onInputReady");
|
||||
MessageParcel data, reply;
|
||||
@@ -32,22 +31,7 @@ using namespace ErrorCode;
|
||||
return ERROR_EX_PARCELABLE;
|
||||
}
|
||||
|
||||
if (!data.WriteInt32(retValue)) {
|
||||
return ERROR_EX_PARCELABLE;
|
||||
}
|
||||
if (agent == nullptr) {
|
||||
data.WriteInt32(0);
|
||||
} else {
|
||||
data.WriteInt32(1);
|
||||
data.WriteRemoteObject(agent->AsObject().GetRefPtr());
|
||||
}
|
||||
|
||||
if (channel == nullptr) {
|
||||
data.WriteInt32(0);
|
||||
} else {
|
||||
data.WriteInt32(1);
|
||||
data.WriteParcelable(channel);
|
||||
}
|
||||
data.WriteRemoteObject(agent->AsObject().GetRefPtr());
|
||||
|
||||
auto ret = Remote()->SendRequest(ON_INPUT_READY, data, reply, option);
|
||||
if (ret != NO_ERROR) {
|
||||
|
||||
@@ -40,13 +40,7 @@ namespace MiscServices {
|
||||
break;
|
||||
}
|
||||
MessageParcel *parcel = new MessageParcel();
|
||||
parcel->WriteInt32(data.ReadInt32());
|
||||
if (data.ReadInt32() > 0) {
|
||||
parcel->WriteRemoteObject(data.ReadRemoteObject());
|
||||
}
|
||||
if (data.ReadInt32() > 0) {
|
||||
parcel->WriteParcelable(data.ReadParcelable<InputChannel>());
|
||||
}
|
||||
parcel->WriteRemoteObject(data.ReadRemoteObject());
|
||||
|
||||
Message *msg = new Message(MessageID::MSG_ID_ON_INPUT_READY, parcel);
|
||||
msgHandler->SendMessage(msg);
|
||||
@@ -78,8 +72,7 @@ namespace MiscServices {
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
int32_t InputClientStub::onInputReady(int32_t retValue, const sptr<IInputMethodAgent>& agent,
|
||||
const InputChannel *channel)
|
||||
int32_t InputClientStub::onInputReady(const sptr<IInputMethodAgent>& agent)
|
||||
{
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,6 @@ using namespace MessageID;
|
||||
|
||||
sptr<InputMethodController> InputMethodController::GetInstance()
|
||||
{
|
||||
IMSA_HILOGI("InputMethodController::GetInstance");
|
||||
if (instance_ == nullptr) {
|
||||
std::lock_guard<std::mutex> autoLock(instanceLock_);
|
||||
if (instance_ == nullptr) {
|
||||
@@ -68,6 +67,7 @@ using namespace MessageID;
|
||||
mAttribute.SetInputPattern(InputAttribute::PATTERN_TEXT);
|
||||
|
||||
textListener = nullptr;
|
||||
PrepareInput(0, mClient, mInputDataChannel, mAttribute);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -136,18 +136,9 @@ using namespace MessageID;
|
||||
}
|
||||
case MSG_ID_ON_INPUT_READY: {
|
||||
MessageParcel *data = msg->msgContent_;
|
||||
int32_t ret = data->ReadInt32();
|
||||
if (ret != ErrorCode::NO_ERROR) {
|
||||
if (textListener != nullptr) {
|
||||
textListener->SetKeyboardStatus(false);
|
||||
}
|
||||
mAgent = nullptr;
|
||||
break;
|
||||
}
|
||||
sptr<IRemoteObject> object = data->ReadRemoteObject();
|
||||
mAgent = new InputMethodAgentProxy(object);
|
||||
if (textListener != nullptr) {
|
||||
textListener->SetKeyboardStatus(true);
|
||||
if (object != nullptr) {
|
||||
mAgent = new InputMethodAgentProxy(object);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -201,8 +192,8 @@ using namespace MessageID;
|
||||
|
||||
void InputMethodController::Attach(sptr<OnTextChangedListener> &listener)
|
||||
{
|
||||
PrepareInput(0, mClient, mInputDataChannel, mAttribute);
|
||||
textListener = listener;
|
||||
StartInput(mClient);
|
||||
}
|
||||
|
||||
void InputMethodController::ShowTextInput()
|
||||
@@ -304,11 +295,19 @@ using namespace MessageID;
|
||||
return;
|
||||
}
|
||||
|
||||
if (cursorInfo_.left == cursorInfo.left && cursorInfo_.top == cursorInfo.top
|
||||
&& cursorInfo_.height == cursorInfo.height) {
|
||||
return;
|
||||
}
|
||||
cursorInfo_ = cursorInfo;
|
||||
mAgent->OnCursorUpdate(cursorInfo.left, cursorInfo.top, cursorInfo.height);
|
||||
}
|
||||
|
||||
void InputMethodController::OnSelectionChange(std::u16string text, int start, int end)
|
||||
{
|
||||
if (mTextString == text && mSelectNewBegin == start && mSelectNewEnd == end) {
|
||||
return;
|
||||
}
|
||||
IMSA_HILOGI("InputMethodController::OnSelectionChange");
|
||||
mTextString = text;
|
||||
mSelectOldBegin = mSelectNewBegin;
|
||||
@@ -350,35 +349,18 @@ using namespace MessageID;
|
||||
bool InputMethodController::dispatchKeyEvent(std::shared_ptr<MMI::KeyEvent> keyEvent)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodController::dispatchKeyEvent");
|
||||
if (textListener == nullptr) {
|
||||
IMSA_HILOGI("InputMethodController::dispatchKeyEvent textListener is nullptr");
|
||||
return false;
|
||||
}
|
||||
if (mImms == nullptr) {
|
||||
return false;
|
||||
}
|
||||
int32_t code = keyEvent->GetKeyCode();
|
||||
int32_t status = keyEvent->GetKeyAction();
|
||||
if (mSpecialKeyPress != 0) {
|
||||
if ((code == MMI::KeyEvent::KEYCODE_CTRL_LEFT || code == MMI::KeyEvent::KEYCODE_CTRL_RIGHT) && status == MMI::KeyEvent::KEY_ACTION_UP) {
|
||||
mSpecialKeyPress--;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if ((code == MMI::KeyEvent::KEYCODE_CTRL_LEFT || code == MMI::KeyEvent::KEYCODE_CTRL_RIGHT) && status == MMI::KeyEvent::KEY_ACTION_DOWN) {
|
||||
mSpecialKeyPress++;
|
||||
if (mAgent == nullptr) {
|
||||
IMSA_HILOGI("InputMethodController::dispatchKeyEvent mAgent is nullptr");
|
||||
return false;
|
||||
}
|
||||
MessageParcel data;
|
||||
if (!(data.WriteInterfaceToken(mImms->GetDescriptor())
|
||||
&& data.WriteRemoteObject(mClient->AsObject().GetRefPtr())
|
||||
if (!(data.WriteInterfaceToken(mAgent->GetDescriptor())
|
||||
&& data.WriteInt32(keyEvent->GetKeyCode())
|
||||
&& data.WriteInt32(keyEvent->GetKeyAction()))) {
|
||||
return false;
|
||||
}
|
||||
mImms->DispatchKey(data);
|
||||
|
||||
return true;
|
||||
return mAgent->DispatchKeyEvent(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,49 +97,20 @@ namespace MiscServices {
|
||||
}
|
||||
}
|
||||
|
||||
void InputMethodSystemAbilityProxy::DispatchKey(MessageParcel& data)
|
||||
void InputMethodSystemAbilityProxy::SetCoreAndAgent(MessageParcel& data)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodSystemAbilityProxy::DispatchKey");
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
IMSA_HILOGI("InputMethodSystemAbilityProxy::SetCoreAndAgent");
|
||||
|
||||
auto ret = Remote()->SendRequest(DISPATCH_KEY, data, reply, option);
|
||||
if (ret != NO_ERROR) {
|
||||
IMSA_HILOGI("InputMethodSystemAbilityProxy::DispatchKey SendRequest failed");
|
||||
return;
|
||||
}
|
||||
|
||||
ret = reply.ReadInt32();
|
||||
if (ret != NO_ERROR) {
|
||||
IMSA_HILOGI("InputMethodSystemAbilityProxy::DispatchKey reply failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t InputMethodSystemAbilityProxy::setInputMethodCore(sptr<IInputMethodCore> &core)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodSystemAbilityProxy::setInputMethodCore");
|
||||
|
||||
if (core == nullptr) {
|
||||
IMSA_HILOGI("InputMethodSystemAbilityProxy::setInputMethodCore inputDataChannel is nullptr");
|
||||
}
|
||||
auto remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
MessageParcel data;
|
||||
if (!(data.WriteInterfaceToken(GetDescriptor())
|
||||
&& data.WriteRemoteObject(core->AsObject()))) {
|
||||
return -1;
|
||||
return;
|
||||
}
|
||||
MessageParcel reply;
|
||||
MessageOption option {
|
||||
MessageOption::TF_SYNC
|
||||
};
|
||||
|
||||
int32_t status = Remote()->SendRequest(SET_INPUT_METHOD_CORE, data, reply, option);
|
||||
|
||||
return status;
|
||||
Remote()->SendRequest(SET_CORE_AND_AGENT, data, reply, option);
|
||||
}
|
||||
|
||||
int32_t InputMethodSystemAbilityProxy::Prepare(int32_t displayId, sptr<InputClientStub> &client,
|
||||
|
||||
Reference in New Issue
Block a user