mirror of
https://github.com/openharmony/miscservices_inputmethod.git
synced 2026-07-16 07:44:28 -04:00
@@ -31,6 +31,7 @@ namespace MiscServices {
|
||||
DISPATCH_KEY_EVENT = FIRST_CALL_TRANSACTION,
|
||||
ON_CURSOR_UPDATE,
|
||||
ON_SELECTION_CHANGE,
|
||||
SET_CALLING_WINDOW_ID,
|
||||
};
|
||||
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.inputmethod.IInputMethodAgent");
|
||||
@@ -39,6 +40,7 @@ namespace MiscServices {
|
||||
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;
|
||||
virtual void SetCallingWindow(uint32_t windowId) = 0;
|
||||
};
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -54,6 +54,7 @@ namespace MiscServices {
|
||||
void SendFunctionKey(int32_t funcKey);
|
||||
void MoveCursor(int32_t keyCode);
|
||||
bool DispatchKeyEvent(int32_t keyCode, int32_t keyStatus);
|
||||
void SetCallingWindow(uint32_t windowId);
|
||||
int32_t GetEnterKeyType();
|
||||
int32_t GetInputPattern();
|
||||
void StopInput();
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace MiscServices {
|
||||
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;
|
||||
|
||||
void SetCallingWindow(uint32_t windowId) override;
|
||||
private:
|
||||
static inline BrokerDelegator<InputMethodAgentProxy> delegator_;
|
||||
};
|
||||
|
||||
@@ -36,8 +36,8 @@ namespace MiscServices {
|
||||
void OnCursorUpdate(int32_t positionX, int32_t positionY, int height) override;
|
||||
void OnSelectionChange(std::u16string text, int32_t oldBegin, int32_t oldEnd,
|
||||
int32_t newBegin, int32_t newEnd) override;
|
||||
void SetCallingWindow(uint32_t windowId) override;
|
||||
void SetMessageHandler(MessageHandler *msgHandler);
|
||||
|
||||
private:
|
||||
MessageHandler *msgHandler_;
|
||||
};
|
||||
|
||||
@@ -272,7 +272,6 @@ namespace MiscServices {
|
||||
|
||||
bool InputMethodAbility::DispatchKeyEvent(int32_t keyCode, int32_t keyStatus)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodAbility::DispatchKeyEvent");
|
||||
IMSA_HILOGI("InputMethodAbility::DispatchKeyEvent: key = %{public}d, status = %{public}d", keyCode, keyStatus);
|
||||
if (!isBindClient) {
|
||||
IMSA_HILOGI("InputMethodAbility::DispatchKeyEvent abort. no client");
|
||||
@@ -284,6 +283,19 @@ namespace MiscServices {
|
||||
}
|
||||
return kdListener_->OnKeyEvent(keyCode, keyStatus);
|
||||
}
|
||||
|
||||
void InputMethodAbility::SetCallingWindow(uint32_t windowId)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodAbility::SetCallingWindow");
|
||||
|
||||
if (!imeListener_) {
|
||||
IMSA_HILOGI("InputMethodAbility::SetCallingWindow imeListener_ is nullptr");
|
||||
return;
|
||||
}
|
||||
imeListener_->OnSetCallingWindow(windowId);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void InputMethodAbility::OnCursorUpdate(Message *msg)
|
||||
{
|
||||
@@ -459,5 +471,6 @@ namespace MiscServices {
|
||||
}
|
||||
inputDataChannel->StopInput();
|
||||
}
|
||||
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -73,5 +73,19 @@ namespace MiscServices {
|
||||
|
||||
Remote()->SendRequest(ON_SELECTION_CHANGE, data, reply, option);
|
||||
}
|
||||
|
||||
void InputMethodAgentProxy::SetCallingWindow(uint32_t windowId)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodAgentProxy::SetCallingWindow");
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
IMSA_HILOGI("InputMethodAgentProxy::SetCallingWindow descriptor is not match");
|
||||
return;
|
||||
}
|
||||
|
||||
data.WriteInt32(windowId);
|
||||
Remote()->SendRequest(SET_CALLING_WINDOW_ID, data, reply, option);
|
||||
}
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -47,6 +47,10 @@ namespace MiscServices {
|
||||
reply.WriteBool(DispatchKeyEvent(*msgParcel));
|
||||
break;
|
||||
}
|
||||
case SET_CALLING_WINDOW_ID: {
|
||||
uint32_t windowId = data.ReadInt32;
|
||||
SetCallingWindow(windowId);
|
||||
}
|
||||
case ON_CURSOR_UPDATE: {
|
||||
int32_t positionX = data.ReadInt32();
|
||||
int32_t positionY = data.ReadInt32();
|
||||
@@ -81,6 +85,16 @@ namespace MiscServices {
|
||||
return InputMethodAbility::GetInstance()->DispatchKeyEvent(data.ReadInt32(), data.ReadInt32());
|
||||
}
|
||||
|
||||
void InputMethodAgentStub::SetCallingWindow(uint32_t windowId)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodAgentStub::SetCallingWindow");
|
||||
if (!msgHandler_) {
|
||||
return false;
|
||||
}
|
||||
InputMethodAbility::SetCallingWindow(windowId);
|
||||
return;
|
||||
}
|
||||
|
||||
void InputMethodAgentStub::OnCursorUpdate(int32_t positionX, int32_t positionY, int height)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodAgentStub::OnCursorUpdate");
|
||||
|
||||
@@ -71,6 +71,7 @@ namespace MiscServices {
|
||||
int32_t GetEnterKeyType();
|
||||
int32_t GetInputPattern();
|
||||
void HideCurrentInput();
|
||||
void SetCallingWindow(uint32_t windowId);
|
||||
|
||||
private:
|
||||
InputMethodController();
|
||||
|
||||
@@ -420,5 +420,17 @@ using namespace MessageID;
|
||||
IMSA_HILOGI("InputMethodController::GetInputPattern");
|
||||
return inputPattern_;
|
||||
}
|
||||
|
||||
void InputMethodController::SetCallingWindow(uint32_t windowId)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodController::SetCallingWindow windowId = %{public}d", windowId);
|
||||
if (!mAgent) {
|
||||
IMSA_HILOGI("InputMethodController::SetCallingWindow mAgent is nullptr");
|
||||
return;
|
||||
}
|
||||
mAgent->SetCallingWindow(windowId);
|
||||
return;
|
||||
}
|
||||
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -39,6 +39,7 @@ namespace MiscServices {
|
||||
void OnKeyboardStatus(bool isShow);
|
||||
void OnInputStart();
|
||||
void OnInputStop(std::string imeId);
|
||||
void OnSetCallingWindow(uint32_t windowId);
|
||||
|
||||
private:
|
||||
void AddCallback(std::string type, NativeValue* jsListenerObject);
|
||||
|
||||
@@ -198,5 +198,20 @@ namespace MiscServices {
|
||||
};
|
||||
mainHandler_->PostTask(task);
|
||||
}
|
||||
|
||||
void JsInputMethodEngineListener::OnSetCallingWindow(uint32_t windowId)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
IMSA_HILOGI("JsInputMethodEngineListener::OnSetCallingWindow");
|
||||
|
||||
auto task = [this, windowId] () {
|
||||
NativeValue* nativeValue = CreateJsValue(*engine_, windowId);
|
||||
NativeValue* argv[] = { nativeValue };
|
||||
std::string methodName = "setCallingWindow";
|
||||
CallJsMethod(methodName, argv, ArraySize(argv));
|
||||
};
|
||||
mainHandler_->PostTask(task);
|
||||
}
|
||||
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
||||
|
||||
Reference in New Issue
Block a user