mirror of
https://gitee.com/openharmony/window_window_manager
synced 2024-10-07 04:03:37 +00:00
支持模态窗模整个应用进程意见修改
Signed-off-by: 苏嵋岩 <sumeiyan@huawei.com>
This commit is contained in:
parent
9e74c7784b
commit
1ddd39f2b6
@ -297,9 +297,9 @@ enum class WindowFlag : uint32_t {
|
||||
WINDOW_FLAG_FORBID_SPLIT_MOVE = 1 << 3,
|
||||
WINDOW_FLAG_WATER_MARK = 1 << 4,
|
||||
WINDOW_FLAG_IS_MODAL = 1 << 5,
|
||||
WINDOW_FLAG_HANDWRITING = 1 << 6,
|
||||
WINDOW_FLAG_IS_TOAST = 1 << 7,
|
||||
WINDOW_FLAG_IS_APPLICATION_MODAL = 1 << 8,
|
||||
WINDOW_FLAG_IS_APPLICATION_MODAL = 1 << 6,
|
||||
WINDOW_FLAG_HANDWRITING = 1 << 7,
|
||||
WINDOW_FLAG_IS_TOAST = 1 << 8,
|
||||
WINDOW_FLAG_END = 1 << 9,
|
||||
};
|
||||
|
||||
|
@ -853,40 +853,6 @@ napi_value JsExtensionWindow::GetProperties(napi_env env, napi_callback_info inf
|
||||
return CreateJsExtensionWindowPropertiesObject(env, window);
|
||||
}
|
||||
|
||||
static void SetWindowOption(sptr<Rosen::WindowOption>& windowOption)
|
||||
{
|
||||
windowOption->SetWindowType(Rosen::WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
|
||||
windowOption->SetWindowMode(Rosen::WindowMode::WINDOW_MODE_FLOATING);
|
||||
windowOption->SetOnlySupportSceneBoard(true);
|
||||
windowOption->SetExtensionTag(true);
|
||||
}
|
||||
|
||||
static void CreateSubWindowWithOptionsTask(std::shared_ptr<Rosen::ExtensionWindow>& extensionWindow,
|
||||
std::string windowName, sptr<WindowOption>& windowOption, napi_env env, NapiAsyncTask& task)
|
||||
{
|
||||
if (extensionWindow == nullptr) {
|
||||
task.Reject(env, CreateJsError(env,
|
||||
static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), "extensionWindow_ is null"));
|
||||
}
|
||||
SetWindowOption(windowOption);
|
||||
auto extWindow = extensionWindow->GetWindow();
|
||||
if (extWindow == nullptr) {
|
||||
task.Reject(env, CreateJsError(env,
|
||||
static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), "extension's window is null"));
|
||||
}
|
||||
auto window = Window::Create(windowName, windowOption, extWindow->GetContext());
|
||||
if (window == nullptr) {
|
||||
task.Reject(env, CreateJsError(env,
|
||||
static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), "create sub window failed"));
|
||||
return;
|
||||
}
|
||||
if (!window->IsTopmost()) {
|
||||
extWindow->NotifyModalUIExtensionMayBeCovered(false);
|
||||
}
|
||||
task.Resolve(env, CreateJsWindowObject(env, window));
|
||||
TLOGI(WmsLogTag::WMS_UIEXT, "[NAPI]Create sub window %{public}s end", windowName.c_str());
|
||||
}
|
||||
|
||||
napi_value JsExtensionWindow::OnCreateSubWindowWithOptions(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = 4;
|
||||
@ -910,10 +876,36 @@ napi_value JsExtensionWindow::OnCreateSubWindowWithOptions(napi_env env, napi_ca
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
option->SetParentId(hostWindowId_);
|
||||
const char* const where = __func__;
|
||||
NapiAsyncTask::CompleteCallback complete =
|
||||
[extensionWindow = extensionWindow_, windowName, windowOption = option](napi_env env, NapiAsyncTask& task,
|
||||
int32_t status) mutable {
|
||||
CreateSubWindowWithOptionsTask(extensionWindow, windowName, windowOption, env, task);
|
||||
[where, extensionWindow = extensionWindow_, windowName = std::move(windowName),
|
||||
windowOption = option](napi_env env, NapiAsyncTask& task, int32_t status) mutable {
|
||||
if (extensionWindow == nullptr) {
|
||||
task.Reject(env, CreateJsError(env,
|
||||
static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), "extensionWindow is null"));
|
||||
}
|
||||
windowOption->SetWindowType(Rosen::WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
|
||||
windowOption->SetWindowMode(Rosen::WindowMode::WINDOW_MODE_FLOATING);
|
||||
windowOption->SetOnlySupportSceneBoard(true);
|
||||
windowOption->SetExtensionTag(true);
|
||||
auto extWindow = extensionWindow->GetWindow();
|
||||
if (extWindow == nullptr) {
|
||||
task.Reject(env, CreateJsError(env,
|
||||
static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), "extension's window is null"));
|
||||
}
|
||||
auto window = Window::Create(windowName, windowOption, extWindow->GetContext());
|
||||
if (window == nullptr) {
|
||||
task.Reject(env, CreateJsError(env,
|
||||
static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), "create sub window failed"));
|
||||
return;
|
||||
}
|
||||
if (!window->IsTopmost()) {
|
||||
extWindow->NotifyModalUIExtensionMayBeCovered(false);
|
||||
}
|
||||
task.Resolve(env, CreateJsWindowObject(env, window));
|
||||
TLOGNI(WmsLogTag::WMS_UIEXT,
|
||||
"%{public}s [NAPI]Create sub window %{public}s end",
|
||||
where, windowName.c_str());
|
||||
};
|
||||
napi_value callback = (argv[2] != nullptr && GetType(env, argv[2]) == napi_function) ? argv[2] : nullptr;
|
||||
napi_value result = nullptr;
|
||||
|
@ -5934,39 +5934,8 @@ napi_value JsWindow::OnSetWindowDecorVisible(napi_env env, napi_callback_info in
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
|
||||
static void SetSubWindowModalTask(const sptr<Window>& window, bool isModal,
|
||||
ModalityType modalityType, napi_env env, NapiAsyncTask& task)
|
||||
{
|
||||
if (window == nullptr) {
|
||||
TLOGE(WmsLogTag::WMS_SUB, "CreateSubWindowModalTask window is nullptr");
|
||||
WmErrorCode wmErrorCode = WM_JS_TO_ERROR_CODE_MAP.at(WMError::WM_ERROR_NULLPTR);
|
||||
task.Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, "window is nullptr."));
|
||||
return;
|
||||
}
|
||||
if (!WindowHelper::IsSubWindow(window->GetType())) {
|
||||
TLOGE(WmsLogTag::WMS_SUB, "CreateSubWindowModalTask invalid call, type:%{public}d", window->GetType());
|
||||
WmErrorCode wmErrorCode = WmErrorCode::WM_ERROR_INVALID_CALLING;
|
||||
task.Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, "invalid window type."));
|
||||
return;
|
||||
}
|
||||
WMError ret = window->SetSubWindowModal(isModal, modalityType);
|
||||
if (ret == WMError::WM_OK) {
|
||||
task.Resolve(env, NapiGetUndefined(env));
|
||||
} else {
|
||||
WmErrorCode wmErrorCode = WM_JS_TO_ERROR_CODE_MAP.at(ret);
|
||||
TLOGE(WmsLogTag::WMS_SUB, "CreateSubWindowModalTask set failed, ret is %{public}d", wmErrorCode);
|
||||
task.Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, "Set subwindow modal failed"));
|
||||
}
|
||||
TLOGI(WmsLogTag::WMS_SUB,
|
||||
"CreateSubWindowModalTask id:%{public}u, name:%{public}s, isModal:%{public}d, modalityType:%{public}d",
|
||||
window->GetWindowId(), window->GetWindowName().c_str(), isModal, modalityType);
|
||||
}
|
||||
|
||||
napi_value JsWindow::OnSetSubWindowModal(napi_env env, napi_callback_info info)
|
||||
{
|
||||
bool isModal = false;
|
||||
ModalityType modalityType = ModalityType::WINDOW_MODALITY;
|
||||
uint32_t type = 0;
|
||||
size_t argc = 4;
|
||||
napi_value argv[4] = { nullptr };
|
||||
napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
@ -5974,17 +5943,21 @@ napi_value JsWindow::OnSetSubWindowModal(napi_env env, napi_callback_info info)
|
||||
TLOGE(WmsLogTag::WMS_SUB, "Argc is invalid: %{public}zu", argc);
|
||||
return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM);
|
||||
}
|
||||
bool isModal = false;
|
||||
if (!ConvertFromJsValue(env, argv[INDEX_ZERO], isModal)) {
|
||||
TLOGE(WmsLogTag::WMS_SUB, "Failed to convert parameter to isModal");
|
||||
return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM);
|
||||
}
|
||||
ModalityType modalityType = ModalityType::WINDOW_MODALITY;
|
||||
using T = std::underlying_type_t<ModalityType>;
|
||||
T type = 0;
|
||||
if (argc == 2 && ConvertFromJsValue(env, argv[INDEX_ONE], type)) { // 2: the param num
|
||||
if (!isModal) {
|
||||
TLOGE(WmsLogTag::WMS_SUB, "Normal subwindow not support modalityType");
|
||||
return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM);
|
||||
}
|
||||
if (type >= static_cast<uint32_t>(ApiModalityType::BEGIN) &&
|
||||
type <= static_cast<uint32_t>(ApiModalityType::END)) {
|
||||
if (type >= static_cast<T>(ApiModalityType::BEGIN) &&
|
||||
type <= static_cast<T>(ApiModalityType::END)) {
|
||||
modalityType = JS_TO_NATIVE_MODALITY_TYPE_MAP.at(static_cast<ApiModalityType>(type));
|
||||
} else {
|
||||
TLOGE(WmsLogTag::WMS_SUB, "Failed to convert parameter to modalityType");
|
||||
@ -5992,10 +5965,37 @@ napi_value JsWindow::OnSetSubWindowModal(napi_env env, napi_callback_info info)
|
||||
}
|
||||
}
|
||||
|
||||
const char* const where = __func__;
|
||||
NapiAsyncTask::CompleteCallback complete =
|
||||
[windowToken = windowToken_, isModal, modalityType](napi_env env, NapiAsyncTask& task,
|
||||
[where, window = windowToken_, isModal, modalityType](napi_env env, NapiAsyncTask& task,
|
||||
int32_t status) {
|
||||
SetSubWindowModalTask(windowToken, isModal, modalityType, env, task);
|
||||
if (window == nullptr) {
|
||||
TLOGNE(WmsLogTag::WMS_SUB, "%{public}s window is nullptr", where);
|
||||
WmErrorCode wmErrorCode = WM_JS_TO_ERROR_CODE_MAP.at(WMError::WM_ERROR_NULLPTR);
|
||||
task.Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, "window is nullptr."));
|
||||
return;
|
||||
}
|
||||
if (!WindowHelper::IsSubWindow(window->GetType())) {
|
||||
TLOGNE(WmsLogTag::WMS_SUB,
|
||||
"%{public}s invalid call, type:%{public}d",
|
||||
where, window->GetType());
|
||||
WmErrorCode wmErrorCode = WmErrorCode::WM_ERROR_INVALID_CALLING;
|
||||
task.Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, "invalid window type."));
|
||||
return;
|
||||
}
|
||||
WMError ret = window->SetSubWindowModal(isModal, modalityType);
|
||||
if (ret == WMError::WM_OK) {
|
||||
task.Resolve(env, NapiGetUndefined(env));
|
||||
} else {
|
||||
WmErrorCode wmErrorCode = WM_JS_TO_ERROR_CODE_MAP.at(ret);
|
||||
TLOGNE(WmsLogTag::WMS_SUB,
|
||||
"%{public}s set failed, ret is %{public}d",
|
||||
where, wmErrorCode);
|
||||
task.Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, "Set subwindow modal failed"));
|
||||
}
|
||||
TLOGNI(WmsLogTag::WMS_SUB,
|
||||
"%{public}s id:%{public}u, name:%{public}s, isModal:%{public}d, modalityType:%{public}d",
|
||||
where, window->GetWindowId(), window->GetWindowName().c_str(), isModal, modalityType);
|
||||
};
|
||||
napi_value lastParam = nullptr;
|
||||
napi_value result = nullptr;
|
||||
|
@ -1077,14 +1077,14 @@ napi_value ModalityTypeInit(napi_env env)
|
||||
napi_value objValue = nullptr;
|
||||
CHECK_NAPI_CREATE_OBJECT_RETURN_IF_NULL(env, objValue);
|
||||
|
||||
napi_set_named_property(env, objValue, "WINDOW_MODALITY", CreateJsValue(env,
|
||||
static_cast<uint32_t>(ApiModalityType::WINDOW_MODALITY)));
|
||||
napi_set_named_property(env, objValue, "APPLICATION_MODALITY", CreateJsValue(env,
|
||||
static_cast<uint32_t>(ApiModalityType::APPLICATION_MODALITY)));
|
||||
napi_set_named_property(env, objValue, "WINDOW_MODALITY",
|
||||
CreateJsValue(env, ApiModalityType::WINDOW_MODALITY));
|
||||
napi_set_named_property(env, objValue, "APPLICATION_MODALITY",
|
||||
CreateJsValue(env, ApiModalityType::APPLICATION_MODALITY));
|
||||
return objValue;
|
||||
}
|
||||
|
||||
static bool ParseModalityRelevantParam(napi_env env, napi_value jsObject, const sptr<WindowOption>& windowOption)
|
||||
static bool ParseModalityParam(napi_env env, napi_value jsObject, const sptr<WindowOption>& windowOption)
|
||||
{
|
||||
bool isModal = false;
|
||||
if (ParseJsValue(jsObject, env, "isModal", isModal)) {
|
||||
@ -1100,14 +1100,15 @@ static bool ParseModalityRelevantParam(napi_env env, napi_value jsObject, const
|
||||
}
|
||||
windowOption->SetWindowTopmost(isTopmost);
|
||||
}
|
||||
uint32_t modalityType = 0;
|
||||
using T = std::underlying_type_t<ModalityType>;
|
||||
T modalityType = 0;
|
||||
if (ParseJsValue(jsObject, env, "modalityType", modalityType)) {
|
||||
if (!isModal) {
|
||||
TLOGE(WmsLogTag::WMS_SUB, "Normal subwindow not support modalityType");
|
||||
return false;
|
||||
}
|
||||
if (modalityType >= static_cast<uint32_t>(ApiModalityType::BEGIN) &&
|
||||
modalityType <= static_cast<uint32_t>(ApiModalityType::END)) {
|
||||
if (modalityType >= static_cast<T>(ApiModalityType::BEGIN) &&
|
||||
modalityType <= static_cast<T>(ApiModalityType::END)) {
|
||||
TLOGI(WmsLogTag::WMS_SUB, "Normal subwindow modalityType: %{public}u", modalityType);
|
||||
auto type = JS_TO_NATIVE_MODALITY_TYPE_MAP.at(static_cast<ApiModalityType>(modalityType));
|
||||
if (type == ModalityType::APPLICATION_MODALITY) {
|
||||
@ -1140,7 +1141,7 @@ bool ParseSubWindowOptions(napi_env env, napi_value jsObject, const sptr<WindowO
|
||||
|
||||
windowOption->SetSubWindowTitle(title);
|
||||
windowOption->SetSubWindowDecorEnable(decorEnabled);
|
||||
return ParseModalityRelevantParam(env, jsObject, windowOption);
|
||||
return ParseModalityParam(env, jsObject, windowOption);
|
||||
}
|
||||
|
||||
} // namespace Rosen
|
||||
|
@ -270,14 +270,14 @@ const std::map<WindowSizeChangeReason, RectChangeReason> JS_SIZE_CHANGE_REASON {
|
||||
{ WindowSizeChangeReason::END, RectChangeReason::UNDEFINED },
|
||||
};
|
||||
|
||||
enum class ApiModalityType : uint32_t {
|
||||
enum class ApiModalityType : uint8_t {
|
||||
BEGIN = 0,
|
||||
WINDOW_MODALITY = BEGIN,
|
||||
APPLICATION_MODALITY,
|
||||
END = APPLICATION_MODALITY,
|
||||
};
|
||||
|
||||
const std::map<ApiModalityType, ModalityType> JS_TO_NATIVE_MODALITY_TYPE_MAP {
|
||||
inline const std::map<ApiModalityType, ModalityType> JS_TO_NATIVE_MODALITY_TYPE_MAP {
|
||||
{ ApiModalityType::WINDOW_MODALITY, ModalityType::WINDOW_MODALITY },
|
||||
{ ApiModalityType::APPLICATION_MODALITY, ModalityType::APPLICATION_MODALITY },
|
||||
};
|
||||
|
@ -648,26 +648,30 @@ napi_value JsWindowStage::OnCreateSubWindowWithOptions(napi_env env, napi_callba
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
|
||||
const char* const where = __func__;
|
||||
NapiAsyncTask::CompleteCallback complete =
|
||||
[weak = windowScene_, windowName, option](napi_env env, NapiAsyncTask& task, int32_t status) mutable {
|
||||
auto weakScene = weak.lock();
|
||||
if (weakScene == nullptr) {
|
||||
WLOGFE("[NAPI]Window scene is null");
|
||||
task.Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY));
|
||||
return;
|
||||
}
|
||||
option->SetWindowType(Rosen::WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
|
||||
option->SetWindowMode(Rosen::WindowMode::WINDOW_MODE_FLOATING);
|
||||
option->SetOnlySupportSceneBoard(true);
|
||||
auto window = weakScene->CreateWindow(windowName, option);
|
||||
if (window == nullptr) {
|
||||
WLOGFE("[NAPI]Get window failed");
|
||||
task.Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY,
|
||||
"Get window failed"));
|
||||
return;
|
||||
}
|
||||
task.Resolve(env, CreateJsWindowObject(env, window));
|
||||
WLOGI("[NAPI]Create sub window %{public}s end", windowName.c_str());
|
||||
[where, weak = windowScene_, windowName = std::move(windowName), option]
|
||||
(napi_env env, NapiAsyncTask& task, int32_t status) mutable {
|
||||
auto windowScene = weak.lock();
|
||||
if (windowScene == nullptr) {
|
||||
TLOGNE(WmsLogTag::WMS_SUB, "%{public}s [NAPI]Window scene is null", where);
|
||||
task.Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY));
|
||||
return;
|
||||
}
|
||||
option->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
|
||||
option->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
|
||||
option->SetOnlySupportSceneBoard(true);
|
||||
auto window = windowScene->CreateWindow(windowName, option);
|
||||
if (window == nullptr) {
|
||||
TLOGNE(WmsLogTag::WMS_SUB, "%{public}s [NAPI]Get window failed", where);
|
||||
task.Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY,
|
||||
"Get window failed"));
|
||||
return;
|
||||
}
|
||||
task.Resolve(env, CreateJsWindowObject(env, window));
|
||||
TLOGNI(WmsLogTag::WMS_SUB,
|
||||
"%{public}s [NAPI]Create sub window %{public}s end",
|
||||
where, windowName.c_str());
|
||||
};
|
||||
napi_value callback = (argv[2] != nullptr && GetType(env, argv[2]) == napi_function) ? argv[2] : nullptr;
|
||||
napi_value result = nullptr;
|
||||
|
@ -65,7 +65,7 @@ private:
|
||||
napi_value OnDisableWindowDecor(napi_env env, napi_callback_info info);
|
||||
napi_value OnSetDefaultDensityEnabled(napi_env env, napi_callback_info info);
|
||||
|
||||
std::weak_ptr<Rosen::WindowScene> windowScene_;
|
||||
std::weak_ptr<WindowScene> windowScene_;
|
||||
};
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
|
@ -240,9 +240,9 @@ enum class WindowFlag : uint32_t {
|
||||
WINDOW_FLAG_FORBID_SPLIT_MOVE = 1 << 3,
|
||||
WINDOW_FLAG_WATER_MARK = 1 << 4,
|
||||
WINDOW_FLAG_IS_MODAL = 1 << 5,
|
||||
WINDOW_FLAG_HANDWRITING = 1 << 6,
|
||||
WINDOW_FLAG_IS_TOAST = 1 << 7,
|
||||
WINDOW_FLAG_IS_APPLICATION_MODAL = 1 << 8,
|
||||
WINDOW_FLAG_IS_APPLICATION_MODAL = 1 << 6,
|
||||
WINDOW_FLAG_HANDWRITING = 1 << 7,
|
||||
WINDOW_FLAG_IS_TOAST = 1 << 8,
|
||||
WINDOW_FLAG_END = 1 << 9,
|
||||
};
|
||||
|
||||
|
@ -50,8 +50,8 @@ public:
|
||||
|
||||
static inline bool IsApplicationModalSubWindow(WindowType type, uint32_t windowFlags)
|
||||
{
|
||||
return IsModalSubWindow(type, windowFlags) && (windowFlags &
|
||||
static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_IS_APPLICATION_MODAL));
|
||||
return IsModalSubWindow(type, windowFlags) &&
|
||||
(windowFlags & static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_IS_APPLICATION_MODAL));
|
||||
}
|
||||
|
||||
static inline bool IsToastSubWindow(WindowType type, uint32_t windowFlags)
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* Copyright (c) 2023 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.
|
||||
@ -294,10 +294,10 @@ static void AddDialogSessionMapItem(const sptr<SceneSession>& session,
|
||||
if (property != nullptr && property->IsTopmost()) {
|
||||
isTopmostModalSubWindow = true;
|
||||
}
|
||||
SubWindowModalType modalType = session->GetSubWindowModalType();
|
||||
if (auto iter = dialogMap.find(mainSession->GetPersistentId());
|
||||
iter != dialogMap.end() && iter->second != nullptr) {
|
||||
auto& targetSession = iter->second;
|
||||
SubWindowModalType modalType = session->GetSubWindowModalType();
|
||||
SubWindowModalType targetModalType = targetSession->GetSubWindowModalType();
|
||||
if (modalType == targetModalType) {
|
||||
if (targetSession->GetSessionProperty() &&
|
||||
@ -319,32 +319,32 @@ static void AddDialogSessionMapItem(const sptr<SceneSession>& session,
|
||||
}
|
||||
|
||||
static void UpdateCallingPidMapItem(const sptr<SceneSession>& session,
|
||||
std::map<int32_t, sptr<SceneSession>>& callingPidMap)
|
||||
std::unordered_map<int32_t, sptr<SceneSession>>& callingPidMap)
|
||||
{
|
||||
auto sessionPid = session->GetCallingPid();
|
||||
auto targetSession = session->GetParentSession();
|
||||
while (targetSession) {
|
||||
auto targetSessionPid = targetSession->GetCallingPid();
|
||||
if (sessionPid != targetSessionPid) {
|
||||
callingPidMap[targetSessionPid] = session;
|
||||
auto parentSession = session->GetParentSession();
|
||||
while (parentSession) {
|
||||
auto parentSessionPid = parentSession->GetCallingPid();
|
||||
if (sessionPid != parentSessionPid) {
|
||||
callingPidMap[parentSessionPid] = session;
|
||||
}
|
||||
targetSession = targetSession->GetParentSession();
|
||||
parentSession = parentSession->GetParentSession();
|
||||
}
|
||||
}
|
||||
|
||||
static void AddCallingPidMapItem(const sptr<SceneSession>& session,
|
||||
std::map<int32_t, sptr<SceneSession>>& callingPidMap)
|
||||
std::unordered_map<int32_t, sptr<SceneSession>>& callingPidMap)
|
||||
{
|
||||
auto sessionCallingPid = session->GetCallingPid();
|
||||
auto callingPid = callingPidMap.find(sessionCallingPid);
|
||||
if (callingPid == callingPidMap.end()) {
|
||||
auto iter = callingPidMap.find(sessionCallingPid);
|
||||
if (iter == callingPidMap.end()) {
|
||||
callingPidMap.emplace(std::make_pair(sessionCallingPid, session));
|
||||
UpdateCallingPidMapItem(session, callingPidMap);
|
||||
TLOGD(WmsLogTag::WMS_DIALOG,
|
||||
"Add callingPid session, sessionCallingPid: %{public}d, sessionId: %{public}d",
|
||||
sessionCallingPid, session->GetPersistentId());
|
||||
} else {
|
||||
if (callingPid->second->GetZOrder() < session->GetZOrder()) {
|
||||
if (iter->second->GetZOrder() < session->GetZOrder()) {
|
||||
callingPidMap[sessionCallingPid] = session;
|
||||
UpdateCallingPidMapItem(session, callingPidMap);
|
||||
TLOGD(WmsLogTag::WMS_DIALOG,
|
||||
@ -354,20 +354,21 @@ static void AddCallingPidMapItem(const sptr<SceneSession>& session,
|
||||
}
|
||||
}
|
||||
|
||||
static void UpdateDialogSessionMap(const std::map<int32_t, sptr<SceneSession>>& sessionMap,
|
||||
std::map<int32_t, sptr<SceneSession>>& callingPidMap, std::map<int32_t, sptr<SceneSession>>& dialogMap)
|
||||
static void UpdateDialogSessionMap(
|
||||
const std::map<int32_t, sptr<SceneSession>>& sessionMap,
|
||||
const std::unordered_map<int32_t, sptr<SceneSession>>& callingPidMap,
|
||||
std::map<int32_t, sptr<SceneSession>>& dialogMap)
|
||||
{
|
||||
for (const auto& elem: sessionMap) {
|
||||
const auto& session = elem.second;
|
||||
for (const auto& [_, session] : sessionMap) {
|
||||
if (session == nullptr || session->GetForceHideState() != ForceHideState::NOT_HIDDEN) {
|
||||
continue;
|
||||
}
|
||||
auto callingPid = callingPidMap.find(session->GetCallingPid());
|
||||
if (callingPid != callingPidMap.end()) {
|
||||
dialogMap[session->GetPersistentId()] = callingPid->second;
|
||||
auto iter = callingPidMap.find(session->GetCallingPid());
|
||||
if (iter != callingPidMap.end()) {
|
||||
dialogMap[session->GetPersistentId()] = iter->second;
|
||||
TLOGD(WmsLogTag::WMS_DIALOG,
|
||||
"Update dialog session, sessionId: %{public}d, callingPidSessionId: %{public}d",
|
||||
session->GetPersistentId(), callingPid->second->GetPersistentId());
|
||||
session->GetPersistentId(), iter->second->GetPersistentId());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -376,10 +377,9 @@ std::map<int32_t, sptr<SceneSession>> SceneSessionDirtyManager::GetDialogSession
|
||||
const std::map<int32_t, sptr<SceneSession>>& sessionMap) const
|
||||
{
|
||||
std::map<int32_t, sptr<SceneSession>> dialogMap;
|
||||
std::map<int32_t, sptr<SceneSession>> callingPidMap;
|
||||
bool modalUpdateFlag = false;
|
||||
for (const auto& elem: sessionMap) {
|
||||
const auto& session = elem.second;
|
||||
std::unordered_map<int32_t, sptr<SceneSession>> callingPidMap;
|
||||
bool hasModalApplication = false;
|
||||
for (const auto& [_, session] : sessionMap) {
|
||||
if (session == nullptr || session->GetForceHideState() != ForceHideState::NOT_HIDDEN) {
|
||||
continue;
|
||||
}
|
||||
@ -387,19 +387,15 @@ std::map<int32_t, sptr<SceneSession>> SceneSessionDirtyManager::GetDialogSession
|
||||
if (modalType == SubWindowModalType::TYPE_DIALOG ||
|
||||
modalType == SubWindowModalType::TYPE_WINDOW_MODALITY) {
|
||||
AddDialogSessionMapItem(session, dialogMap);
|
||||
}
|
||||
if (modalType == SubWindowModalType::TYPE_APPLICATION_MODALITY) {
|
||||
} else if (modalType == SubWindowModalType::TYPE_APPLICATION_MODALITY) {
|
||||
AddDialogSessionMapItem(session, dialogMap);
|
||||
modalUpdateFlag = true;
|
||||
hasModalApplication = true;
|
||||
AddCallingPidMapItem(session, callingPidMap);
|
||||
}
|
||||
}
|
||||
|
||||
if (!modalUpdateFlag) {
|
||||
return dialogMap;
|
||||
if (hasModalApplication) {
|
||||
UpdateDialogSessionMap(sessionMap, callingPidMap, dialogMap);
|
||||
}
|
||||
UpdateDialogSessionMap(sessionMap, callingPidMap, dialogMap);
|
||||
|
||||
return dialogMap;
|
||||
}
|
||||
|
||||
|
@ -468,41 +468,21 @@ HWTEST_F(SceneSessionDirtyManagerTest, GetDialogSessionMap, Function | SmallTest
|
||||
*/
|
||||
HWTEST_F(SceneSessionDirtyManagerTest, GetDialogSessionMap02, Function | SmallTest | Level2)
|
||||
{
|
||||
std::map<int32_t, sptr<SceneSession>> sessionMap;
|
||||
SessionInfo info;
|
||||
info.abilityName_ = "TestAbilityName";
|
||||
info.bundleName_ = "TestBundleName";
|
||||
sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
|
||||
if (!sceneSession) {
|
||||
GTEST_LOG_(INFO) << "sceneSession is nullptr";
|
||||
return;
|
||||
}
|
||||
sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
|
||||
if (!property) {
|
||||
GTEST_LOG_(INFO) << "property is nullptr";
|
||||
return;
|
||||
}
|
||||
property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
|
||||
property->AddWindowFlag(WindowFlag::WINDOW_FLAG_IS_MODAL);
|
||||
property->AddWindowFlag(WindowFlag::WINDOW_FLAG_IS_APPLICATION_MODAL);
|
||||
sceneSession->SetSessionProperty(property);
|
||||
sptr<Session> session = sptr<Session>::MakeSptr(info);
|
||||
if (!session) {
|
||||
GTEST_LOG_(INFO) << "session is nullptr";
|
||||
return;
|
||||
}
|
||||
sceneSession->SetParentSession(session);
|
||||
std::map<int32_t, sptr<SceneSession>> sessionMap;
|
||||
sessionMap.emplace(1, sceneSession);
|
||||
auto sessionList = manager_->GetDialogSessionMap(sessionMap);
|
||||
ASSERT_EQ(1, sessionList.size());
|
||||
sceneSession->SetForceHideState(ForceHideState::NOT_HIDDEN);
|
||||
auto sessionList1 = manager_->GetDialogSessionMap(sessionMap);
|
||||
ASSERT_EQ(1, sessionList1.size());
|
||||
sceneSession->SetForceHideState(ForceHideState::HIDDEN_WHEN_FOCUSED);
|
||||
sceneSession->SetSessionProperty(nullptr);
|
||||
sceneSession->SetParentSession(nullptr);
|
||||
auto sessionList2 = manager_->GetDialogSessionMap(sessionMap);
|
||||
ASSERT_EQ(0, sessionList2.size());
|
||||
ASSERT_EQ(2, sessionList.size());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1719,15 +1719,15 @@ WMError WindowSessionImpl::SetSubWindowModal(bool isModal, ModalityType modality
|
||||
return WMError::WM_ERROR_INVALID_CALLING;
|
||||
}
|
||||
|
||||
WMError modalRet = (isModal ?
|
||||
WMError modalRet = isModal ?
|
||||
AddWindowFlag(WindowFlag::WINDOW_FLAG_IS_MODAL) :
|
||||
RemoveWindowFlag(WindowFlag::WINDOW_FLAG_IS_MODAL));
|
||||
RemoveWindowFlag(WindowFlag::WINDOW_FLAG_IS_MODAL);
|
||||
if (modalRet != WMError::WM_OK) {
|
||||
return modalRet;
|
||||
}
|
||||
modalRet = (isModal && modalityType == ModalityType::APPLICATION_MODALITY ?
|
||||
modalRet = isModal && modalityType == ModalityType::APPLICATION_MODALITY ?
|
||||
AddWindowFlag(WindowFlag::WINDOW_FLAG_IS_APPLICATION_MODAL) :
|
||||
RemoveWindowFlag(WindowFlag::WINDOW_FLAG_IS_APPLICATION_MODAL));
|
||||
RemoveWindowFlag(WindowFlag::WINDOW_FLAG_IS_APPLICATION_MODAL);
|
||||
return modalRet;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user