mirror of
https://github.com/openharmony/miscservices_inputmethod.git
synced 2026-07-20 23:45:31 -04:00
@@ -35,6 +35,9 @@ namespace MiscServices {
|
||||
CLOSE,
|
||||
GET_TEXT_BEFORE_CURSOR,
|
||||
GET_TEXT_AFTER_CURSOR,
|
||||
GET_ENTER_KEY_TYPE,
|
||||
GET_INPUT_PATTERN,
|
||||
STOP_INPUT,
|
||||
SEND_KEYBOARD_STATUS,
|
||||
SEND_FUNCTION_KEY,
|
||||
MOVE_CURSOR,
|
||||
@@ -46,11 +49,14 @@ namespace MiscServices {
|
||||
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 std::u16string GetTextBeforeCursor(int32_t number) = 0;
|
||||
virtual std::u16string GetTextAfterCursor(int32_t number) = 0;
|
||||
virtual void SendKeyboardStatus(int32_t status) = 0;
|
||||
virtual void SendFunctionKey(int32_t funcKey) = 0;
|
||||
virtual void MoveCursor(int32_t keyCode) = 0;
|
||||
virtual int32_t GetEnterKeyType() = 0;
|
||||
virtual int32_t GetInputPattern() = 0;
|
||||
virtual void StopInput() = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,11 +32,14 @@ namespace MiscServices {
|
||||
bool DeleteForward(int32_t length) override;
|
||||
bool DeleteBackward(int32_t length) override;
|
||||
void Close() override;
|
||||
std::u16string GetTextBeforeCursor() override;
|
||||
std::u16string GetTextAfterCursor() override;
|
||||
std::u16string GetTextBeforeCursor(int32_t number) override;
|
||||
std::u16string GetTextAfterCursor(int32_t number) override;
|
||||
void SendKeyboardStatus(int32_t status) override;
|
||||
void SendFunctionKey(int32_t funcKey) override;
|
||||
void MoveCursor(int32_t keyCode) override;
|
||||
int32_t GetEnterKeyType() override;
|
||||
int32_t GetInputPattern() override;
|
||||
void StopInput() override;
|
||||
|
||||
private:
|
||||
static inline BrokerDelegator<InputDataChannelProxy> delegator_;
|
||||
|
||||
@@ -40,11 +40,14 @@ namespace MiscServices {
|
||||
bool DeleteForward(int32_t length) override;
|
||||
bool DeleteBackward(int32_t length) override;
|
||||
void Close() override;
|
||||
std::u16string GetTextBeforeCursor() override;
|
||||
std::u16string GetTextAfterCursor() override;
|
||||
std::u16string GetTextBeforeCursor(int32_t number) override;
|
||||
std::u16string GetTextAfterCursor(int32_t number) override;
|
||||
void SendKeyboardStatus(int32_t status) override;
|
||||
void SendFunctionKey(int32_t funcKey) override;
|
||||
void MoveCursor(int32_t keyCode) override;
|
||||
int32_t GetEnterKeyType() override;
|
||||
int32_t GetInputPattern() override;
|
||||
void StopInput() override;
|
||||
private:
|
||||
MessageHandler *msgHandler;
|
||||
};
|
||||
|
||||
@@ -56,8 +56,8 @@ namespace MiscServices {
|
||||
public:
|
||||
static sptr<InputMethodController> GetInstance();
|
||||
void Attach(sptr<OnTextChangedListener> &listener);
|
||||
std::u16string GetTextBeforeCursor();
|
||||
std::u16string GetTextAfterCursor();
|
||||
std::u16string GetTextBeforeCursor(int32_t number);
|
||||
std::u16string GetTextAfterCursor(int32_t number);
|
||||
void ShowTextInput();
|
||||
void HideTextInput();
|
||||
void Close();
|
||||
@@ -68,6 +68,9 @@ namespace MiscServices {
|
||||
bool dispatchKeyEvent(std::shared_ptr<MMI::KeyEvent> keyEvent);
|
||||
void DisplayOptionalInputMethod();
|
||||
std::vector<InputMethodProperty*> ListInputMethod();
|
||||
int32_t GetEnterKeyType();
|
||||
int32_t GetInputPattern();
|
||||
void HideCurrentInput();
|
||||
private:
|
||||
InputMethodController();
|
||||
~InputMethodController();
|
||||
@@ -100,6 +103,8 @@ namespace MiscServices {
|
||||
std::thread workThreadHandler;
|
||||
MessageHandler *msgHandler;
|
||||
bool stop_;
|
||||
int32_t enterKeyType_ = 0;
|
||||
int32_t inputPattern_ = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ namespace MiscServices {
|
||||
virtual void startInput(MessageParcel& data) override;
|
||||
virtual void stopInput(MessageParcel& data) override;
|
||||
virtual void SetCoreAndAgent(MessageParcel& data) override;
|
||||
virtual void HideCurrentInput(MessageParcel& data) override;
|
||||
|
||||
int32_t Prepare(int32_t displayId, sptr<InputClientStub> &client, sptr<InputDataChannelStub> &channel,
|
||||
InputAttribute &attribute);
|
||||
|
||||
@@ -84,24 +84,26 @@ namespace MiscServices {
|
||||
}
|
||||
}
|
||||
|
||||
std::u16string InputDataChannelProxy::GetTextBeforeCursor()
|
||||
std::u16string InputDataChannelProxy::GetTextBeforeCursor(int32_t number)
|
||||
{
|
||||
IMSA_HILOGI("InputDataChannelProxy::GetTextBeforeCursor");
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(GetDescriptor());
|
||||
data.WriteInt32(number);
|
||||
|
||||
Remote()->SendRequest(GET_TEXT_BEFORE_CURSOR, data, reply, option);
|
||||
auto result = reply.ReadString16();
|
||||
return result;
|
||||
}
|
||||
|
||||
std::u16string InputDataChannelProxy::GetTextAfterCursor()
|
||||
std::u16string InputDataChannelProxy::GetTextAfterCursor(int32_t number)
|
||||
{
|
||||
IMSA_HILOGI("InputDataChannelProxy::GetTextAfterCursor");
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(GetDescriptor());
|
||||
data.WriteInt32(number);
|
||||
|
||||
Remote()->SendRequest(GET_TEXT_AFTER_CURSOR, data, reply, option);
|
||||
auto result = reply.ReadString16();
|
||||
@@ -141,5 +143,39 @@ namespace MiscServices {
|
||||
|
||||
Remote()->SendRequest(MOVE_CURSOR, data, reply, option);
|
||||
}
|
||||
|
||||
int32_t InputDataChannelProxy::GetEnterKeyType()
|
||||
{
|
||||
IMSA_HILOGI("InputDataChannelProxy::GetEnterKeyType");
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(GetDescriptor());
|
||||
|
||||
Remote()->SendRequest(GET_ENTER_KEY_TYPE, data, reply, option);
|
||||
auto result = reply.ReadInt32();
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t InputDataChannelProxy::GetInputPattern()
|
||||
{
|
||||
IMSA_HILOGI("InputDataChannelProxy::GetInputPattern");
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(GetDescriptor());
|
||||
|
||||
Remote()->SendRequest(GET_INPUT_PATTERN, data, reply, option);
|
||||
auto result = reply.ReadInt32();
|
||||
return result;
|
||||
}
|
||||
|
||||
void InputDataChannelProxy::StopInput()
|
||||
{
|
||||
IMSA_HILOGI("InputDataChannelProxy::StopInput");
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(GetDescriptor());
|
||||
|
||||
Remote()->SendRequest(STOP_INPUT, data, reply, option);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,11 +59,13 @@ namespace MiscServices {
|
||||
break;
|
||||
}
|
||||
case GET_TEXT_BEFORE_CURSOR: {
|
||||
reply.WriteString16(GetTextBeforeCursor());
|
||||
auto number = data.ReadInt32();
|
||||
reply.WriteString16(GetTextBeforeCursor(number));
|
||||
break;
|
||||
}
|
||||
case GET_TEXT_AFTER_CURSOR: {
|
||||
reply.WriteString16(GetTextAfterCursor());
|
||||
auto number = data.ReadInt32();
|
||||
reply.WriteString16(GetTextAfterCursor(number));
|
||||
break;
|
||||
}
|
||||
case SEND_KEYBOARD_STATUS: {
|
||||
@@ -80,6 +82,18 @@ namespace MiscServices {
|
||||
auto keyCode = data.ReadInt32();
|
||||
MoveCursor(keyCode);
|
||||
}
|
||||
case GET_ENTER_KEY_TYPE: {
|
||||
reply.WriteInt32(GetEnterKeyType());
|
||||
break;
|
||||
}
|
||||
case GET_INPUT_PATTERN: {
|
||||
reply.WriteInt32(GetInputPattern());
|
||||
break;
|
||||
}
|
||||
case STOP_INPUT: {
|
||||
StopInput();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
@@ -131,16 +145,34 @@ namespace MiscServices {
|
||||
{
|
||||
}
|
||||
|
||||
std::u16string InputDataChannelStub::GetTextBeforeCursor()
|
||||
std::u16string InputDataChannelStub::GetTextBeforeCursor(int32_t number)
|
||||
{
|
||||
IMSA_HILOGI("InputDataChannelStub::GetTextBeforeCursor");
|
||||
return InputMethodController::GetInstance()->GetTextBeforeCursor();
|
||||
return InputMethodController::GetInstance()->GetTextBeforeCursor(number);
|
||||
}
|
||||
|
||||
std::u16string InputDataChannelStub::GetTextAfterCursor()
|
||||
std::u16string InputDataChannelStub::GetTextAfterCursor(int32_t number)
|
||||
{
|
||||
IMSA_HILOGI("InputDataChannelStub::GetTextAfterCursor");
|
||||
return InputMethodController::GetInstance()->GetTextAfterCursor();
|
||||
return InputMethodController::GetInstance()->GetTextAfterCursor(number);
|
||||
}
|
||||
|
||||
int32_t InputDataChannelStub::GetEnterKeyType()
|
||||
{
|
||||
IMSA_HILOGI("InputDataChannelStub::GetEnterKeyType");
|
||||
return InputMethodController::GetInstance()->GetEnterKeyType();
|
||||
}
|
||||
|
||||
int32_t InputDataChannelStub::GetInputPattern()
|
||||
{
|
||||
IMSA_HILOGI("InputDataChannelStub::GetInputPattern");
|
||||
return InputMethodController::GetInstance()->GetInputPattern();
|
||||
}
|
||||
|
||||
void InputDataChannelStub::StopInput()
|
||||
{
|
||||
IMSA_HILOGI("InputDataChannelStub::StopInput");
|
||||
InputMethodController::GetInstance()->HideTextInput();
|
||||
}
|
||||
|
||||
void InputDataChannelStub::SendKeyboardStatus(int32_t status)
|
||||
|
||||
@@ -208,6 +208,19 @@ using namespace MessageID;
|
||||
StopInput(mClient);
|
||||
}
|
||||
|
||||
void InputMethodController::HideCurrentInput()
|
||||
{
|
||||
IMSA_HILOGI("InputMethodController::HideCurrentInput");
|
||||
if (mImms == nullptr) {
|
||||
return;
|
||||
}
|
||||
MessageParcel data;
|
||||
if (!(data.WriteInterfaceToken(mImms->GetDescriptor()))) {
|
||||
return;
|
||||
}
|
||||
mImms->HideCurrentInput(data);
|
||||
}
|
||||
|
||||
void InputMethodController::Close()
|
||||
{
|
||||
ReleaseInput(mClient);
|
||||
@@ -348,24 +361,26 @@ using namespace MessageID;
|
||||
void InputMethodController::OnConfigurationChange(Configuration info)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodController::OnConfigurationChange");
|
||||
enterKeyType_ = static_cast<uint32_t>(info.GetEnterKeyType());
|
||||
inputPattern_ = static_cast<uint32_t>(info.GetTextInputType());
|
||||
}
|
||||
|
||||
std::u16string InputMethodController::GetTextBeforeCursor()
|
||||
std::u16string InputMethodController::GetTextBeforeCursor(int32_t number)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodController::GetTextBeforeCursor");
|
||||
if (!mTextString.empty()) {
|
||||
return mTextString.substr(0, mSelectNewBegin);
|
||||
int32_t startPos = (mSelectNewBegin >= number ? (mSelectNewBegin - number + 1) : 0);
|
||||
return mTextString.substr(startPos, mSelectNewBegin);
|
||||
}
|
||||
return u"";
|
||||
}
|
||||
|
||||
std::u16string InputMethodController::GetTextAfterCursor()
|
||||
std::u16string InputMethodController::GetTextAfterCursor(int32_t number)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodController::GetTextBeforeCursor");
|
||||
if (!mTextString.empty()) {
|
||||
if (mTextString.size() > mSelectNewEnd) {
|
||||
return mTextString.substr(mSelectNewEnd);
|
||||
}
|
||||
int32_t endPos = (mSelectNewEnd+number<mTextString.size()) ? (mSelectNewEnd + number) : mTextString.size();
|
||||
return mTextString.substr(mSelectNewEnd, endPos);
|
||||
}
|
||||
return u"";
|
||||
}
|
||||
@@ -386,5 +401,17 @@ using namespace MessageID;
|
||||
|
||||
return mAgent->DispatchKeyEvent(data);
|
||||
}
|
||||
|
||||
int32_t InputMethodController::GetEnterKeyType()
|
||||
{
|
||||
IMSA_HILOGI("InputMethodController::GetEnterKeyType");
|
||||
return enterKeyType_;
|
||||
}
|
||||
|
||||
int32_t InputMethodController::GetInputPattern()
|
||||
{
|
||||
IMSA_HILOGI("InputMethodController::GetInputPattern");
|
||||
return inputPattern_;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -131,6 +131,25 @@ namespace MiscServices {
|
||||
Remote()->SendRequest(SET_CORE_AND_AGENT, data, reply, option);
|
||||
}
|
||||
|
||||
void InputMethodSystemAbilityProxy::HideCurrentInput(MessageParcel& data)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodSystemAbilityProxy::HideCurrentInput");
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
|
||||
auto ret = Remote()->SendRequest(HIDE_CURRENT_INPUT, data, reply, option);
|
||||
if (ret != NO_ERROR) {
|
||||
IMSA_HILOGI("InputMethodSystemAbilityProxy::HideCurrentInput SendRequest failed");
|
||||
return;
|
||||
}
|
||||
|
||||
ret = reply.ReadInt32();
|
||||
if (ret != NO_ERROR) {
|
||||
IMSA_HILOGI("InputMethodSystemAbilityProxy::HideCurrentInput reply failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t InputMethodSystemAbilityProxy::Prepare(int32_t displayId, sptr<InputClientStub> &client,
|
||||
sptr<InputDataChannelStub> &channel, InputAttribute &attribute)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user