在showSysPanel中增加软键盘窗口大小参数

Signed-off-by: guojin31 <guojin31@huawei.com>
This commit is contained in:
guojin31 2024-06-27 10:28:39 +08:00
parent 1344a83e32
commit a4e44348cc
19 changed files with 136 additions and 37 deletions

View File

@ -26,6 +26,7 @@
#include "input_window_info.h"
#include "message_parcel.h"
#include "panel_info.h"
#include "sys_panel_status.h"
namespace OHOS {
namespace MiscServices {
@ -82,6 +83,9 @@ public:
static bool Marshalling(const PanelStatusInfo &info, MessageParcel &data);
static bool Unmarshalling(PanelStatusInfo &info, MessageParcel &data);
static bool Marshalling(const SysPanelStatus &input, MessageParcel &data);
static bool Unmarshalling(SysPanelStatus &output, MessageParcel &data);
static bool Marshalling(InputType input, MessageParcel &data);
static bool Unmarshalling(InputType &output, MessageParcel &data);

View File

@ -312,6 +312,21 @@ bool ITypesUtil::Unmarshalling(PanelStatusInfo &output, MessageParcel &data)
return true;
}
bool ITypesUtil::Marshalling(const SysPanelStatus &input, MessageParcel &data)
{
return data.WriteBool(input.isSecurity) && data.WriteInt32(input.flag) && data.WriteUint32(input.width) &&
data.WriteUint32(input.height);
}
bool ITypesUtil::Unmarshalling(SysPanelStatus &output, MessageParcel &data)
{
if (!data.ReadBool(output.isSecurity) || !data.ReadInt32(output.flag) || !data.ReadUint32(output.width) ||
!data.ReadUint32(output.height)) {
return false;
}
return true;
}
bool ITypesUtil::Marshalling(const OHOS::AppExecFwk::ElementName &input, MessageParcel &data)
{
return data.WriteString(input.GetBundleName().c_str()) && data.WriteString(input.GetModuleName().c_str()) &&

View File

@ -168,7 +168,8 @@ napi_value JsPanel::Resize(napi_env env, napi_callback_info info)
auto exec = [ctxt](AsyncCall::Context *ctx) {
CHECK_RETURN_VOID(ctxt->inputMethodPanel != nullptr, "inputMethodPanel_ is nullptr.");
InputMethodAbility::GetInstance()->ShowSysPanel(ctxt->inputMethodPanel, ctxt->inputMethodPanel->GetPanelFlag());
SysPanelStatus sysPanelStatus = { false, ctxt->inputMethodPanel->GetPanelFlag(), ctxt->width, ctxt->height };
InputMethodAbility::GetInstance()->NotifyPanelStatus(ctxt->inputMethodPanel, sysPanelStatus);
auto code = ctxt->inputMethodPanel->Resize(ctxt->width, ctxt->height);
if (code == ErrorCode::NO_ERROR) {
ctxt->SetState(napi_ok);

View File

@ -281,12 +281,12 @@ void JsKeyboardPanelManager::ReceivePrivateCommand(
eventHandler->PostTask(task, type, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE);
}
void JsKeyboardPanelManager::NotifyIsShowSysPanel(bool shouldSysPanelShow)
void JsKeyboardPanelManager::NotifyPanelStatus(const SysPanelStatus &sysPanelStatus)
{
IMSA_HILOGD("JsKeyboardPanelManager, run in");
std::string type = "isPanelShow";
auto entry =
GetEntry(type, [shouldSysPanelShow](UvEntry &entry) { entry.shouldSysPanelShow = shouldSysPanelShow; });
GetEntry(type, [sysPanelStatus](UvEntry &entry) { entry.sysPanelStatus = sysPanelStatus; });
if (entry == nullptr) {
return;
}
@ -300,7 +300,12 @@ void JsKeyboardPanelManager::NotifyIsShowSysPanel(bool shouldSysPanelShow)
if (argc < 1) {
return false;
}
napi_value jsObject = JsUtil::GetValue(env, entry->shouldSysPanelShow);
napi_value jsObject = JsPanelStatus::Write(env, entry->sysPanelStatus);
if (jsObject == nullptr) {
IMSA_HILOGE("GetJsSysPanelStatus failed: jsObject is nullptr");
return false;
}
// 0 means the first param of callback.
args[0] = { jsObject };
return true;
};
@ -340,5 +345,16 @@ std::shared_ptr<JsKeyboardPanelManager::UvEntry> JsKeyboardPanelManager::GetEntr
}
return entry;
}
napi_value JsPanelStatus::Write(napi_env env, const SysPanelStatus &in)
{
napi_value jsObject = nullptr;
napi_create_object(env, &jsObject);
bool ret = JsUtil::Object::WriteProperty(env, jsObject, "isSecurity", in.isSecurity);
ret = ret && JsUtil::Object::WriteProperty(env, jsObject, "flag", in.flag);
ret = ret && JsUtil::Object::WriteProperty(env, jsObject, "width", in.width);
ret = ret && JsUtil::Object::WriteProperty(env, jsObject, "height", in.height);
return ret ? jsObject : JsUtil::Const::Null(env);
}
} // namespace MiscServices
} // namespace OHOS

View File

@ -62,6 +62,10 @@ struct SmartMenuContext : public AsyncCall::Context {
}
};
struct JsPanelStatus {
static napi_value Write(napi_env env, const SysPanelStatus &in);
};
class JsKeyboardPanelManager : public OnSystemCmdListener {
public:
JsKeyboardPanelManager();
@ -77,20 +81,20 @@ public:
static napi_value GetJsInputMethodProperty(napi_env env, const Property &property);
void ReceivePrivateCommand(const std::unordered_map<std::string, PrivateDataValue> &privateCommand) override;
void NotifyIsShowSysPanel(bool shouldSysPanelShow) override;
void NotifyPanelStatus(const SysPanelStatus &sysPanelStatus) override;
private:
void RegisterListener(napi_value callback, std::string type, std::shared_ptr<JSCallbackObject> callbackObj);
void UnRegisterListener(napi_value callback, std::string type);
napi_value GetJsPanelStatus(napi_env env, const SysPanelStatus &in);
struct UvEntry {
std::vector<std::shared_ptr<JSCallbackObject>> vecCopy;
std::string type;
bool shouldSysPanelShow = false;
SysPanelStatus sysPanelStatus;
std::string smartMenu;
std::unordered_map<std::string, PrivateDataValue> privateCommand;
explicit UvEntry(const std::vector<std::shared_ptr<JSCallbackObject>> &cbVec, const std::string &type)
: vecCopy(cbVec), type(type), shouldSysPanelShow(false), smartMenu(""), privateCommand({})
: vecCopy(cbVec), type(type), sysPanelStatus({ false, 0, 0, 0 }), smartMenu(""), privateCommand({})
{
}
};

View File

@ -93,7 +93,8 @@ public:
int32_t GetCallingWindowInfo(CallingWindowInfo &windowInfo);
int32_t SetPreviewText(const std::string &text, const Range &range);
int32_t FinishTextPreview();
int32_t ShowSysPanel(const std::shared_ptr<InputMethodPanel> &inputMethodPanel, PanelFlag flag);
int32_t NotifyPanelStatus(const std::shared_ptr<InputMethodPanel> &inputMethodPanel,
SysPanelStatus &sysPanelStatus);
private:
std::thread workThreadHandler;

View File

@ -78,6 +78,7 @@ public:
int32_t ShowPanel();
int32_t HidePanel();
int32_t SizeChange(const WindowSize &size);
WindowSize GetKeyboardSize();
bool SetPanelStatusListener(std::shared_ptr<PanelStatusListener> statusListener, const std::string &type);
void ClearPanelListener(const std::string &type);
int32_t SetCallingWindow(uint32_t windowId);
@ -144,6 +145,8 @@ private:
Rosen::KeyboardLayoutParams keyboardLayoutParams_;
std::mutex keyboardSizeLock_;
WindowSize keyboardSize_{ 0, 0 };
std::mutex windowListenerLock_;
sptr<Rosen::IWindowChangeListener> windowChangedListener_ = nullptr;
CallbackFunc panelHeightCallback_ = nullptr;

View File

@ -383,7 +383,9 @@ void InputMethodAbility::OnAttributeChange(Message *msg)
// add for mod inputPattern when panel show
auto panel = GetSoftKeyboardPanel();
if (panel != nullptr) {
ShowSysPanel(panel, panel->GetPanelFlag());
auto keyboardSize = panel->GetKeyboardSize();
SysPanelStatus sysPanelStatus = { false, panel->GetPanelFlag(), keyboardSize.width, keyboardSize.height };
NotifyPanelStatus(panel, sysPanelStatus);
}
kdListener_->OnEditorAttributeChange(attribute);
}
@ -886,7 +888,9 @@ int32_t InputMethodAbility::ShowPanel(const std::shared_ptr<InputMethodPanel> &i
IMSA_HILOGE("Set Keyboard failed, ret = %{public}d", ret);
}
}
ShowSysPanel(inputMethodPanel, flag);
auto keyboardSize = inputMethodPanel->GetKeyboardSize();
SysPanelStatus sysPanelStatus = { false, flag, keyboardSize.width, keyboardSize.height };
NotifyPanelStatus(inputMethodPanel, sysPanelStatus);
auto ret = inputMethodPanel->ShowPanel();
if (ret == ErrorCode::NO_ERROR) {
NotifyPanelStatusInfo({ { inputMethodPanel->GetPanelType(), flag }, true, trigger });
@ -907,7 +911,8 @@ int32_t InputMethodAbility::HidePanel(const std::shared_ptr<InputMethodPanel> &i
return ret;
}
int32_t InputMethodAbility::ShowSysPanel(const std::shared_ptr<InputMethodPanel> &inputMethodPanel, PanelFlag flag)
int32_t InputMethodAbility::NotifyPanelStatus(
const std::shared_ptr<InputMethodPanel> &inputMethodPanel, SysPanelStatus &sysPanelStatus)
{
if (inputMethodPanel->GetPanelType() != SOFT_KEYBOARD) {
return ErrorCode::NO_ERROR;
@ -917,13 +922,14 @@ int32_t InputMethodAbility::ShowSysPanel(const std::shared_ptr<InputMethodPanel>
if (channel == nullptr) {
return ErrorCode::NO_ERROR;
}
bool shouldSysPanelShow = !GetInputAttribute().GetSecurityFlag() && flag != PanelFlag::FLG_CANDIDATE_COLUMN;
bool isSecurity = GetInputAttribute().GetSecurityFlag();
sysPanelStatus.isSecurity = isSecurity;
auto systemChannel = GetSystemCmdChannelProxy();
if (systemChannel == nullptr) {
IMSA_HILOGE("channel is nullptr");
return ErrorCode::ERROR_CLIENT_NULL_POINTER;
}
return systemChannel->ShowSysPanel(shouldSysPanelShow);
return systemChannel->NotifyPanelStatus(sysPanelStatus);
}
void InputMethodAbility::SetInputAttribute(const InputAttribute &inputAttribute)

View File

@ -146,6 +146,8 @@ int32_t InputMethodPanel::Resize(uint32_t width, uint32_t height)
IMSA_HILOGE("failed to resize, ret: %{public}d", ret);
return ErrorCode::ERROR_OPERATE_PANEL;
}
std::lock_guard<std::mutex> lock(keyboardSizeLock_);
keyboardSize_ = { width, height };
IMSA_HILOGI("success, width/height: %{public}u/%{public}u", width, height);
return ErrorCode::NO_ERROR;
}
@ -787,12 +789,20 @@ bool InputMethodPanel::IsSizeValid(uint32_t width, uint32_t height)
return true;
}
WindowSize InputMethodPanel::GetKeyboardSize()
{
std::lock_guard<std::mutex> lock(keyboardSizeLock_);
return keyboardSize_;
}
int32_t InputMethodPanel::SizeChange(const WindowSize &size)
{
IMSA_HILOGD("InputMethodPanel, run in");
IMSA_HILOGI("type/flag: %{public}d/%{public}d, width/height: %{public}d/%{public}d",
static_cast<int32_t>(panelType_), static_cast<int32_t>(panelFlag_), static_cast<int32_t>(size.width),
static_cast<int32_t>(size.height));
std::lock_guard<std::mutex> lock(keyboardSizeLock_);
keyboardSize_ = size;
panelStatusListener_->OnSizeChange(windowId_, size);
return ErrorCode::NO_ERROR;
}

View File

@ -20,6 +20,7 @@
#include "input_method_utils.h"
#include "iremote_broker.h"
#include "sys_panel_status.h"
/**
* brief Definition of interface ISystemCmdChannel
@ -38,7 +39,7 @@ public:
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.inputmethod.ISystemCmdChannel");
virtual int32_t SendPrivateCommand(const std::unordered_map<std::string, PrivateDataValue> &privateCommand) = 0;
virtual int32_t ShowSysPanel(bool shouldSysPanelShow) = 0;
virtual int32_t NotifyPanelStatus(const SysPanelStatus &sysPanelStatus) = 0;
};
} // namespace MiscServices
} // namespace OHOS

View File

@ -0,0 +1,35 @@
/*
* Copyright (C) 2024 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 FRAMEWORKS_INPUTMETHOD_CONTROLLER_SYS_PANEL_STATUS_H
#define FRAMEWORKS_INPUTMETHOD_CONTROLLER_SYS_PANEL_STATUS_H
#include <cstdint>
#include "message_parcel.h"
#include "panel_info.h"
namespace OHOS {
namespace MiscServices {
struct SysPanelStatus {
bool isSecurity { false };
int32_t flag = FLG_FIXED;
uint32_t width = 0;
uint32_t height = 0;
};
} // namespace MiscServices
} // namespace OHOS
#endif // FRAMEWORKS_INPUTMETHOD_CONTROLLER_SYS_PANEL_STATUS_H

View File

@ -36,7 +36,7 @@ public:
DISALLOW_COPY_AND_MOVE(SystemCmdChannelProxy);
int32_t SendPrivateCommand(const std::unordered_map<std::string, PrivateDataValue> &privateCommand) override;
int32_t ShowSysPanel(bool shouldSysPanelShow) override;
int32_t NotifyPanelStatus(const SysPanelStatus &sysPanelStatus) override;
private:
static inline BrokerDelegator<SystemCmdChannelProxy> delegator_;

View File

@ -36,15 +36,15 @@ public:
SystemCmdChannelStub();
~SystemCmdChannelStub();
int32_t SendPrivateCommand(const std::unordered_map<std::string, PrivateDataValue> &privateCommand) override;
int32_t ShowSysPanel(bool shouldSysPanelShow) override;
int32_t NotifyPanelStatus(const SysPanelStatus &sysPanelStatus) override;
private:
int32_t ShowSysPanelOnRemote(MessageParcel &data, MessageParcel &reply);
int32_t NotifyPanelStatusOnRemote(MessageParcel &data, MessageParcel &reply);
int32_t SendPrivateCommandOnRemote(MessageParcel &data, MessageParcel &reply);
using RequestHandler = int32_t (SystemCmdChannelStub::*)(MessageParcel &, MessageParcel &);
static inline const std::unordered_map<int32_t, RequestHandler> HANDLERS = {
{ static_cast<uint32_t>(SEND_PRIVATE_COMMAND), &SystemCmdChannelStub::SendPrivateCommandOnRemote },
{ static_cast<uint32_t>(SHOULD_SYSTEM_PANEL_SHOW), &SystemCmdChannelStub::ShowSysPanelOnRemote },
{ static_cast<uint32_t>(SHOULD_SYSTEM_PANEL_SHOW), &SystemCmdChannelStub::NotifyPanelStatusOnRemote },
};
};
} // namespace MiscServices

View File

@ -230,14 +230,14 @@ int32_t ImeSystemCmdChannel::SendPrivateCommand(const std::unordered_map<std::st
return ErrorCode::ERROR_INVALID_PRIVATE_COMMAND;
}
int32_t ImeSystemCmdChannel::ShowSysPanel(bool shouldSysPanelShow)
int32_t ImeSystemCmdChannel::NotifyPanelStatus(const SysPanelStatus &sysPanelStatus)
{
auto listener = GetSystemCmdListener();
if (listener == nullptr) {
IMSA_HILOGE("listener is nullptr");
return ErrorCode::ERROR_NULL_POINTER;
}
listener->NotifyIsShowSysPanel(shouldSysPanelShow);
listener->NotifyPanelStatus(sysPanelStatus);
return ErrorCode::NO_ERROR;
}

View File

@ -34,10 +34,12 @@ int32_t SystemCmdChannelProxy::SendPrivateCommand(
[&privateCommand](MessageParcel &parcel) { return ITypesUtil::Marshal(parcel, privateCommand); });
}
int32_t SystemCmdChannelProxy::ShowSysPanel(bool shouldSysPanelShow)
int32_t SystemCmdChannelProxy::NotifyPanelStatus(const SysPanelStatus &sysPanelStatus)
{
return SendRequest(SHOULD_SYSTEM_PANEL_SHOW,
[shouldSysPanelShow](MessageParcel &parcel) { return ITypesUtil::Marshal(parcel, shouldSysPanelShow); });
return SendRequest(
SHOULD_SYSTEM_PANEL_SHOW, [sysPanelStatus](MessageParcel &parcel) {
return ITypesUtil::Marshal(parcel, sysPanelStatus);
});
}
int32_t SystemCmdChannelProxy::SendRequest(int code, ParcelHandler input, ParcelHandler output)

View File

@ -49,19 +49,20 @@ int32_t SystemCmdChannelStub::SendPrivateCommandOnRemote(MessageParcel &data, Me
return reply.WriteInt32(SendPrivateCommand(privateCommand)) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
}
int32_t SystemCmdChannelStub::ShowSysPanel(bool shouldSysPanelShow)
int32_t SystemCmdChannelStub::NotifyPanelStatus(const SysPanelStatus &sysPanelStatus)
{
return ImeSystemCmdChannel::GetInstance()->ShowSysPanel(shouldSysPanelShow);
return ImeSystemCmdChannel::GetInstance()->NotifyPanelStatus(sysPanelStatus);
}
int32_t SystemCmdChannelStub::ShowSysPanelOnRemote(MessageParcel &data, MessageParcel &reply)
int32_t SystemCmdChannelStub::NotifyPanelStatusOnRemote(MessageParcel &data, MessageParcel &reply)
{
bool shouldSysPanelShow = false;
if (!ITypesUtil::Unmarshal(data, shouldSysPanelShow)) {
SysPanelStatus sysPanelStatus;
if (!ITypesUtil::Unmarshal(data, sysPanelStatus)) {
IMSA_HILOGE("failed to read message parcel");
return ErrorCode::ERROR_EX_PARCELABLE;
}
return reply.WriteInt32(ShowSysPanel(shouldSysPanelShow)) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
return reply.WriteInt32(NotifyPanelStatus(sysPanelStatus)) ? ErrorCode::NO_ERROR
: ErrorCode::ERROR_EX_PARCELABLE;
}
int32_t SystemCmdChannelStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,

View File

@ -34,7 +34,7 @@ public:
virtual void ReceivePrivateCommand(const std::unordered_map<std::string, PrivateDataValue> &privateCommand)
{
}
virtual void NotifyIsShowSysPanel(bool shouldSysPanelShow)
virtual void NotifyPanelStatus(const SysPanelStatus &sysPanelStatus)
{
}
};
@ -84,7 +84,7 @@ public:
*/
IMF_API std::string GetSmartMenuCfg();
int32_t ReceivePrivateCommand(const std::unordered_map<std::string, PrivateDataValue> &privateCommand) override;
int32_t ShowSysPanel(bool shouldSysPanelShow);
int32_t NotifyPanelStatus(const SysPanelStatus &sysPanelStatus);
void OnConnectCmdReady(const sptr<IRemoteObject> &agentObject);
IMF_API int32_t GetDefaultImeCfg(std::shared_ptr<Property> &property);

View File

@ -29,7 +29,7 @@ class OnSystemCmdListenerImpl : public OnSystemCmdListener {
void ReceivePrivateCommand(const std::unordered_map<std::string, PrivateDataValue> &privateCommand) override
{
}
void NotifyIsShowSysPanel(bool shouldSysPanelShow) override
void NotifyPanelStatus(const SysPanelStatus &sysPanelStatus) override
{
}
};
@ -133,7 +133,7 @@ HWTEST_F(ImeSystemChannelTest, testImeSystemChannel_nullptr, TestSize.Level0)
imeSystemChannel_->GetSmartMenuCfg();
int32_t ret = imeSystemChannel_->ReceivePrivateCommand(privateCommand);
EXPECT_EQ(ret, ErrorCode::ERROR_EX_NULL_POINTER);
ret = imeSystemChannel_->ShowSysPanel(true);
ret = imeSystemChannel_->NotifyPanelStatus({ false, 0, 0, 0 });
EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
}
} // namespace MiscServices

View File

@ -125,7 +125,7 @@ public:
{
isReceivePrivateCommand_ = true;
}
void NotifyIsShowSysPanel(bool shouldSysPanelShow) override
void NotifyPanelStatus(const SysPanelStatus &sysPanelStatus)override
{
isNotifyIsShowSysPanel_ = true;
}
@ -263,12 +263,12 @@ HWTEST_F(VirtualListenerTest, testOnSystemCmdListener_001, TestSize.Level0)
SystemCmdChannelListenerImpl::ResetParam();
std::unordered_map<std::string, PrivateDataValue> privateCommand;
VirtualListenerTest::systemCmdListener_->ReceivePrivateCommand(privateCommand);
VirtualListenerTest::systemCmdListener_->NotifyIsShowSysPanel(false);
VirtualListenerTest::systemCmdListener_->NotifyPanelStatus({ false, 0, 0, 0 });
EXPECT_FALSE(SystemCmdChannelListenerImpl::isNotifyIsShowSysPanel_);
EXPECT_FALSE(SystemCmdChannelListenerImpl::isReceivePrivateCommand_);
SystemCmdChannelListenerImpl::ResetParam();
listener->ReceivePrivateCommand(privateCommand);
listener->NotifyIsShowSysPanel(false);
listener->NotifyPanelStatus({ false, 0, 0, 0 });
EXPECT_TRUE(SystemCmdChannelListenerImpl::isNotifyIsShowSysPanel_);
EXPECT_TRUE(SystemCmdChannelListenerImpl::isReceivePrivateCommand_);
}