同步黄区需求代码

Signed-off-by: zhouyongfei <zhouyongfei@huawei.com>
This commit is contained in:
zhouyongfei
2022-01-13 19:49:53 +08:00
parent 59f7b58f6c
commit b1a3a0c558
32 changed files with 934 additions and 122 deletions
+14 -4
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",
]
@@ -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;
};
}
}
@@ -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_;
@@ -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;
};
@@ -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_;
@@ -29,6 +29,7 @@
namespace OHOS {
namespace MiscServices {
class InputDataChannelStub;
class InputMethodSystemAbilityProxy : public IRemoteProxy<IInputMethodSystemAbility> {
public:
explicit InputMethodSystemAbilityProxy(const sptr<IRemoteObject> &object);
@@ -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;
@@ -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);
}
}
}
}
@@ -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;
@@ -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;
}
}
}
}