123b3eb3cSopenharmony_ci/* 223b3eb3cSopenharmony_ci * Copyright (c) 2022-2023 Huawei Device Co., Ltd. 323b3eb3cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 423b3eb3cSopenharmony_ci * you may not use this file except in compliance with the License. 523b3eb3cSopenharmony_ci * You may obtain a copy of the License at 623b3eb3cSopenharmony_ci * 723b3eb3cSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 823b3eb3cSopenharmony_ci * 923b3eb3cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1023b3eb3cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1123b3eb3cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1223b3eb3cSopenharmony_ci * See the License for the specific language governing permissions and 1323b3eb3cSopenharmony_ci * limitations under the License. 1423b3eb3cSopenharmony_ci */ 1523b3eb3cSopenharmony_ci 1623b3eb3cSopenharmony_ci#include "adapter/ohos/entrance/subwindow/subwindow_ohos.h" 1723b3eb3cSopenharmony_ci 1823b3eb3cSopenharmony_ci#include "dm/display_manager.h" 1923b3eb3cSopenharmony_ci#include "interfaces/inner_api/ace/viewport_config.h" 2023b3eb3cSopenharmony_ci#include "render_service_client/core/ui/rs_surface_node.h" 2123b3eb3cSopenharmony_ci#include "window.h" 2223b3eb3cSopenharmony_ci 2323b3eb3cSopenharmony_ci#include "adapter/ohos/entrance/ace_application_info.h" 2423b3eb3cSopenharmony_ci#include "base/geometry/rect.h" 2523b3eb3cSopenharmony_ci#include "base/log/log_wrapper.h" 2623b3eb3cSopenharmony_ci#include "core/components/root/root_element.h" 2723b3eb3cSopenharmony_ci#include "core/components_ng/base/frame_node.h" 2823b3eb3cSopenharmony_ci#include "core/components_ng/base/ui_node.h" 2923b3eb3cSopenharmony_ci#include "core/components_ng/property/property.h" 3023b3eb3cSopenharmony_ci#include "core/components_v2/inspector/inspector_constants.h" 3123b3eb3cSopenharmony_ci#include "core/pipeline_ng/pipeline_context.h" 3223b3eb3cSopenharmony_ci#if defined(ENABLE_ROSEN_BACKEND) and !defined(UPLOAD_GPU_DISABLED) 3323b3eb3cSopenharmony_ci#include "adapter/ohos/entrance/ace_rosen_sync_task.h" 3423b3eb3cSopenharmony_ci#endif 3523b3eb3cSopenharmony_ci 3623b3eb3cSopenharmony_ci#include "adapter/ohos/entrance/ace_container.h" 3723b3eb3cSopenharmony_ci#include "adapter/ohos/entrance/ace_view_ohos.h" 3823b3eb3cSopenharmony_ci#include "adapter/ohos/entrance/dialog_container.h" 3923b3eb3cSopenharmony_ci#include "adapter/ohos/entrance/ui_content_impl.h" 4023b3eb3cSopenharmony_ci#include "adapter/ohos/entrance/utils.h" 4123b3eb3cSopenharmony_ci#include "base/log/frame_report.h" 4223b3eb3cSopenharmony_ci#include "base/utils/system_properties.h" 4323b3eb3cSopenharmony_ci#include "base/utils/utils.h" 4423b3eb3cSopenharmony_ci#include "bundlemgr/bundle_mgr_interface.h" 4523b3eb3cSopenharmony_ci#include "core/common/connect_server_manager.h" 4623b3eb3cSopenharmony_ci#include "core/common/container_scope.h" 4723b3eb3cSopenharmony_ci#include "core/common/frontend.h" 4823b3eb3cSopenharmony_ci#include "core/common/hdc_register.h" 4923b3eb3cSopenharmony_ci#include "core/common/text_field_manager.h" 5023b3eb3cSopenharmony_ci#include "core/components/bubble/bubble_component.h" 5123b3eb3cSopenharmony_ci#include "core/components/popup/popup_component.h" 5223b3eb3cSopenharmony_ci#include "core/components_ng/pattern/menu/menu_view.h" 5323b3eb3cSopenharmony_ci#include "core/components_ng/pattern/menu/wrapper/menu_wrapper_pattern.h" 5423b3eb3cSopenharmony_ci#include "core/components_ng/pattern/overlay/overlay_manager.h" 5523b3eb3cSopenharmony_ci#include "core/components_ng/render/adapter/rosen_render_context.h" 5623b3eb3cSopenharmony_ci#include "core/components_ng/render/adapter/rosen_window.h" 5723b3eb3cSopenharmony_ci#include "frameworks/bridge/common/utils/engine_helper.h" 5823b3eb3cSopenharmony_ci#include "frameworks/bridge/declarative_frontend/declarative_frontend.h" 5923b3eb3cSopenharmony_ci#include "iservice_registry.h" 6023b3eb3cSopenharmony_ci#ifdef OS_ACCOUNT_EXISTS 6123b3eb3cSopenharmony_ci#include "os_account_manager.h" 6223b3eb3cSopenharmony_ci#endif 6323b3eb3cSopenharmony_ci#include "system_ability_definition.h" 6423b3eb3cSopenharmony_ci 6523b3eb3cSopenharmony_cinamespace OHOS::Ace { 6623b3eb3cSopenharmony_cinamespace { 6723b3eb3cSopenharmony_ciconst Rect MIN_WINDOW_HOT_AREA = Rect(0.0f, 0.0f, 1.0f, 1.0f); 6823b3eb3cSopenharmony_ci#ifndef NG_BUILD 6923b3eb3cSopenharmony_ciconstexpr int32_t PLATFORM_VERSION_TEN = 10; 7023b3eb3cSopenharmony_ci#endif 7123b3eb3cSopenharmony_ci} // namespace 7223b3eb3cSopenharmony_ci 7323b3eb3cSopenharmony_ciint32_t SubwindowOhos::id_ = 0; 7423b3eb3cSopenharmony_cistatic std::atomic<int32_t> gToastDialogId = 0; 7523b3eb3cSopenharmony_ci 7623b3eb3cSopenharmony_ciclass SwitchFreeMultiWindowListener : public OHOS::Rosen::ISwitchFreeMultiWindowListener { 7723b3eb3cSopenharmony_cipublic: 7823b3eb3cSopenharmony_ci explicit SwitchFreeMultiWindowListener(int32_t instanceId) : instanceId_(instanceId) {} 7923b3eb3cSopenharmony_ci ~SwitchFreeMultiWindowListener() = default; 8023b3eb3cSopenharmony_ci 8123b3eb3cSopenharmony_ci void OnSwitchFreeMultiWindow(bool enable) 8223b3eb3cSopenharmony_ci { 8323b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_SUB_WINDOW, "Window status changes, freeMultiWindow is %{public}d", enable); 8423b3eb3cSopenharmony_ci auto container = Platform::AceContainer::GetContainer(instanceId_); 8523b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 8623b3eb3cSopenharmony_ci auto parentContainerId = SubwindowManager::GetInstance()->GetParentContainerId(instanceId_); 8723b3eb3cSopenharmony_ci auto subWindow = SubwindowManager::GetInstance()->GetSubwindow(parentContainerId); 8823b3eb3cSopenharmony_ci CHECK_NULL_VOID(subWindow); 8923b3eb3cSopenharmony_ci 9023b3eb3cSopenharmony_ci auto taskExecutor = container->GetTaskExecutor(); 9123b3eb3cSopenharmony_ci CHECK_NULL_VOID(taskExecutor); 9223b3eb3cSopenharmony_ci ContainerScope scope(instanceId_); 9323b3eb3cSopenharmony_ci taskExecutor->PostTask( 9423b3eb3cSopenharmony_ci [subWindow, enable]() { 9523b3eb3cSopenharmony_ci CHECK_NULL_VOID(subWindow); 9623b3eb3cSopenharmony_ci subWindow->OnFreeMultiWindowSwitch(enable); 9723b3eb3cSopenharmony_ci }, 9823b3eb3cSopenharmony_ci TaskExecutor::TaskType::UI, "ArkUIFreeMultiWindowSwitch"); 9923b3eb3cSopenharmony_ci } 10023b3eb3cSopenharmony_ci 10123b3eb3cSopenharmony_ciprivate: 10223b3eb3cSopenharmony_ci int32_t instanceId_ = -1; 10323b3eb3cSopenharmony_ci}; 10423b3eb3cSopenharmony_ci 10523b3eb3cSopenharmony_ciRefPtr<Subwindow> Subwindow::CreateSubwindow(int32_t instanceId) 10623b3eb3cSopenharmony_ci{ 10723b3eb3cSopenharmony_ci auto subWindow = AceType::MakeRefPtr<SubwindowOhos>(instanceId); 10823b3eb3cSopenharmony_ci CHECK_NULL_RETURN(subWindow, nullptr); 10923b3eb3cSopenharmony_ci auto ret = subWindow->InitContainer(); 11023b3eb3cSopenharmony_ci if (!ret) { 11123b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, "InitContainer failed, container id %{public}d", instanceId); 11223b3eb3cSopenharmony_ci return nullptr; 11323b3eb3cSopenharmony_ci } 11423b3eb3cSopenharmony_ci return subWindow; 11523b3eb3cSopenharmony_ci} 11623b3eb3cSopenharmony_ci 11723b3eb3cSopenharmony_ciSubwindowOhos::SubwindowOhos(int32_t instanceId) : windowId_(id_), parentContainerId_(instanceId) 11823b3eb3cSopenharmony_ci{ 11923b3eb3cSopenharmony_ci SetSubwindowId(windowId_); 12023b3eb3cSopenharmony_ci id_++; 12123b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_SUB_WINDOW, "Create Subwindow, subwindow id %{public}d, container id %{public}d", windowId_, 12223b3eb3cSopenharmony_ci instanceId); 12323b3eb3cSopenharmony_ci} 12423b3eb3cSopenharmony_ci 12523b3eb3cSopenharmony_ciRosen::WindowType SubwindowOhos::GetToastRosenType(bool IsSceneBoardEnabled) 12623b3eb3cSopenharmony_ci{ 12723b3eb3cSopenharmony_ci auto toastType = GetToastWindowType(); 12823b3eb3cSopenharmony_ci TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, 12923b3eb3cSopenharmony_ci "GetToastRosenType windowType: %{public}d, IsSceneBoardEnabled: %{public}d", 13023b3eb3cSopenharmony_ci toastType, IsSceneBoardEnabled); 13123b3eb3cSopenharmony_ci if (toastType == ToastWindowType::TOAST_IN_TYPE_APP_SUB_WINDOW) { 13223b3eb3cSopenharmony_ci if (!IsSceneBoardEnabled) { 13323b3eb3cSopenharmony_ci return Rosen::WindowType::WINDOW_TYPE_TOAST; 13423b3eb3cSopenharmony_ci } 13523b3eb3cSopenharmony_ci return Rosen::WindowType::WINDOW_TYPE_APP_SUB_WINDOW; 13623b3eb3cSopenharmony_ci } else if (toastType == ToastWindowType::TOAST_IN_TYPE_SYSTEM_SUB_WINDOW) { 13723b3eb3cSopenharmony_ci return Rosen::WindowType::WINDOW_TYPE_TOAST; 13823b3eb3cSopenharmony_ci } else if (toastType == ToastWindowType::TOAST_IN_TYPE_SYSTEM_FLOAT) { 13923b3eb3cSopenharmony_ci return Rosen::WindowType::WINDOW_TYPE_SYSTEM_FLOAT; 14023b3eb3cSopenharmony_ci } 14123b3eb3cSopenharmony_ci return Rosen::WindowType::WINDOW_TYPE_TOAST; 14223b3eb3cSopenharmony_ci} 14323b3eb3cSopenharmony_ci 14423b3eb3cSopenharmony_civoid SetToastWindowOption(RefPtr<Platform::AceContainer>& parentContainer, 14523b3eb3cSopenharmony_ci OHOS::sptr<OHOS::Rosen::WindowOption>& windowOption, 14623b3eb3cSopenharmony_ci const Rosen::WindowType& toastWindowType, uint32_t mainWindowId) 14723b3eb3cSopenharmony_ci{ 14823b3eb3cSopenharmony_ci if (toastWindowType == Rosen::WindowType::WINDOW_TYPE_APP_SUB_WINDOW) { 14923b3eb3cSopenharmony_ci windowOption->SetWindowMode(Rosen::WindowMode::WINDOW_MODE_FLOATING); 15023b3eb3cSopenharmony_ci windowOption->AddWindowFlag(Rosen::WindowFlag::WINDOW_FLAG_IS_TOAST); 15123b3eb3cSopenharmony_ci } 15223b3eb3cSopenharmony_ci windowOption->SetWindowType(toastWindowType); 15323b3eb3cSopenharmony_ci if (parentContainer->IsUIExtensionWindow()) { 15423b3eb3cSopenharmony_ci auto parentPipeline = parentContainer->GetPipelineContext(); 15523b3eb3cSopenharmony_ci CHECK_NULL_VOID(parentPipeline); 15623b3eb3cSopenharmony_ci auto hostWindowId = parentPipeline->GetFocusWindowId(); 15723b3eb3cSopenharmony_ci windowOption->SetIsUIExtAnySubWindow(true); 15823b3eb3cSopenharmony_ci windowOption->SetParentId(hostWindowId); 15923b3eb3cSopenharmony_ci } else { 16023b3eb3cSopenharmony_ci windowOption->SetParentId(mainWindowId); 16123b3eb3cSopenharmony_ci } 16223b3eb3cSopenharmony_ci} 16323b3eb3cSopenharmony_ci 16423b3eb3cSopenharmony_civoid SetUIExtensionSubwindowFlag(OHOS::sptr<OHOS::Rosen::WindowOption>& windowOption, 16523b3eb3cSopenharmony_ci bool isAppSubwindow, sptr<OHOS::Rosen::Window>& parentWindow) 16623b3eb3cSopenharmony_ci{ 16723b3eb3cSopenharmony_ci if (isAppSubwindow && (parentWindow->GetIsUIExtFirstSubWindow() || 16823b3eb3cSopenharmony_ci parentWindow->GetIsUIExtAnySubWindow())) { 16923b3eb3cSopenharmony_ci windowOption->SetIsUIExtAnySubWindow(true); 17023b3eb3cSopenharmony_ci } 17123b3eb3cSopenharmony_ci} 17223b3eb3cSopenharmony_ci 17323b3eb3cSopenharmony_cibool SubwindowOhos::InitContainer() 17423b3eb3cSopenharmony_ci{ 17523b3eb3cSopenharmony_ci auto parentContainer = Platform::AceContainer::GetContainer(parentContainerId_); 17623b3eb3cSopenharmony_ci CHECK_NULL_RETURN(parentContainer, false); 17723b3eb3cSopenharmony_ci auto parentPipeline = parentContainer->GetPipelineContext(); 17823b3eb3cSopenharmony_ci CHECK_NULL_RETURN(parentPipeline, false); 17923b3eb3cSopenharmony_ci if (!window_) { 18023b3eb3cSopenharmony_ci OHOS::sptr<OHOS::Rosen::WindowOption> windowOption = new OHOS::Rosen::WindowOption(); 18123b3eb3cSopenharmony_ci auto parentWindowName = parentContainer->GetWindowName(); 18223b3eb3cSopenharmony_ci auto parentWindowId = parentContainer->GetWindowId(); 18323b3eb3cSopenharmony_ci sptr<OHOS::Rosen::Window> parentWindow = parentContainer->GetUIWindow(parentContainerId_); 18423b3eb3cSopenharmony_ci CHECK_NULL_RETURN(parentWindow, false); 18523b3eb3cSopenharmony_ci parentWindow_ = parentWindow; 18623b3eb3cSopenharmony_ci auto windowType = parentWindow->GetType(); 18723b3eb3cSopenharmony_ci std::string windowTag = ""; 18823b3eb3cSopenharmony_ci bool isAppSubwindow = false; 18923b3eb3cSopenharmony_ci if (IsSystemTopMost()) { 19023b3eb3cSopenharmony_ci windowOption->SetWindowType(Rosen::WindowType::WINDOW_TYPE_SYSTEM_TOAST); 19123b3eb3cSopenharmony_ci } else if (GetAboveApps()) { 19223b3eb3cSopenharmony_ci auto toastWindowType = GetToastRosenType(parentContainer->IsSceneBoardEnabled()); 19323b3eb3cSopenharmony_ci isAppSubwindow = toastWindowType == Rosen::WindowType::WINDOW_TYPE_APP_SUB_WINDOW; 19423b3eb3cSopenharmony_ci auto mainWindowId = GetMainWindowId(); 19523b3eb3cSopenharmony_ci SetToastWindowOption(parentContainer, windowOption, toastWindowType, mainWindowId); 19623b3eb3cSopenharmony_ci windowTag = "TOPMOST_TOAST_"; 19723b3eb3cSopenharmony_ci } else if (parentContainer->IsScenceBoardWindow() || windowType == Rosen::WindowType::WINDOW_TYPE_DESKTOP) { 19823b3eb3cSopenharmony_ci windowOption->SetWindowType(Rosen::WindowType::WINDOW_TYPE_SYSTEM_FLOAT); 19923b3eb3cSopenharmony_ci } else if (windowType == Rosen::WindowType::WINDOW_TYPE_UI_EXTENSION) { 20023b3eb3cSopenharmony_ci auto hostWindowId = parentPipeline->GetFocusWindowId(); 20123b3eb3cSopenharmony_ci auto hostWindowRect = parentWindow->GetHostWindowRect(hostWindowId); 20223b3eb3cSopenharmony_ci auto isValid = GreatNotEqual(hostWindowRect.width_, 0) && GreatNotEqual(hostWindowRect.height_, 0); 20323b3eb3cSopenharmony_ci if (!isValid) { 20423b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, 20523b3eb3cSopenharmony_ci "UIExtension Window failed to obtain host window information. Please check if permissions are enabled"); 20623b3eb3cSopenharmony_ci return false; 20723b3eb3cSopenharmony_ci } 20823b3eb3cSopenharmony_ci windowOption->SetIsUIExtFirstSubWindow(true); 20923b3eb3cSopenharmony_ci windowOption->SetWindowType(Rosen::WindowType::WINDOW_TYPE_APP_SUB_WINDOW); 21023b3eb3cSopenharmony_ci windowOption->SetParentId(hostWindowId); 21123b3eb3cSopenharmony_ci SetUIExtensionHostWindowId(hostWindowId); 21223b3eb3cSopenharmony_ci isAppSubwindow = true; 21323b3eb3cSopenharmony_ci } else if (windowType >= Rosen::WindowType::SYSTEM_WINDOW_BASE) { 21423b3eb3cSopenharmony_ci windowOption->SetWindowType(Rosen::WindowType::WINDOW_TYPE_SYSTEM_SUB_WINDOW); 21523b3eb3cSopenharmony_ci windowOption->SetParentId(parentWindowId); 21623b3eb3cSopenharmony_ci } else { 21723b3eb3cSopenharmony_ci windowOption->SetWindowType(Rosen::WindowType::WINDOW_TYPE_APP_SUB_WINDOW); 21823b3eb3cSopenharmony_ci windowOption->SetParentId(parentWindowId); 21923b3eb3cSopenharmony_ci isAppSubwindow = true; 22023b3eb3cSopenharmony_ci } 22123b3eb3cSopenharmony_ci auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay(); 22223b3eb3cSopenharmony_ci if (!defaultDisplay) { 22323b3eb3cSopenharmony_ci TAG_LOGE(AceLogTag::ACE_SUB_WINDOW, "DisplayManager GetDefaultDisplay failed"); 22423b3eb3cSopenharmony_ci return false; 22523b3eb3cSopenharmony_ci } 22623b3eb3cSopenharmony_ci windowOption->SetWindowRect({ 0, 0, defaultDisplay->GetWidth(), defaultDisplay->GetHeight() }); 22723b3eb3cSopenharmony_ci windowOption->SetWindowMode(Rosen::WindowMode::WINDOW_MODE_FLOATING); 22823b3eb3cSopenharmony_ci SetUIExtensionSubwindowFlag(windowOption, isAppSubwindow, parentWindow); 22923b3eb3cSopenharmony_ci window_ = OHOS::Rosen::Window::Create("ARK_APP_SUBWINDOW_" + windowTag + parentWindowName + 23023b3eb3cSopenharmony_ci std::to_string(windowId_), windowOption, parentWindow->GetContext()); 23123b3eb3cSopenharmony_ci if (!window_) { 23223b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, "Window create failed"); 23323b3eb3cSopenharmony_ci return false; 23423b3eb3cSopenharmony_ci } 23523b3eb3cSopenharmony_ci } 23623b3eb3cSopenharmony_ci std::string url = ""; 23723b3eb3cSopenharmony_ci auto subSurface = window_->GetSurfaceNode(); 23823b3eb3cSopenharmony_ci if (!subSurface) { 23923b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, "Window get surface node failed"); 24023b3eb3cSopenharmony_ci window_->Destroy(); 24123b3eb3cSopenharmony_ci return false; 24223b3eb3cSopenharmony_ci } 24323b3eb3cSopenharmony_ci subSurface->SetShadowElevation(0.0f); 24423b3eb3cSopenharmony_ci window_->NapiSetUIContent(url, nullptr, nullptr, Rosen::BackupAndRestoreType::NONE); 24523b3eb3cSopenharmony_ci childContainerId_ = SubwindowManager::GetInstance()->GetContainerId(window_->GetWindowId()); 24623b3eb3cSopenharmony_ci TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "Window child containerId : %{public}d", childContainerId_); 24723b3eb3cSopenharmony_ci SubwindowManager::GetInstance()->AddParentContainerId(childContainerId_, parentContainerId_); 24823b3eb3cSopenharmony_ci 24923b3eb3cSopenharmony_ci auto container = Platform::AceContainer::GetContainer(childContainerId_); 25023b3eb3cSopenharmony_ci if (!container) { 25123b3eb3cSopenharmony_ci TAG_LOGE(AceLogTag::ACE_SUB_WINDOW, "Window get ace container failed"); 25223b3eb3cSopenharmony_ci window_->Destroy(); 25323b3eb3cSopenharmony_ci return false; 25423b3eb3cSopenharmony_ci } 25523b3eb3cSopenharmony_ci 25623b3eb3cSopenharmony_ci auto parentToken = parentContainer->GetToken(); 25723b3eb3cSopenharmony_ci container->SetToken(parentToken); 25823b3eb3cSopenharmony_ci container->SetWindowId(window_->GetWindowId()); 25923b3eb3cSopenharmony_ci container->SetParentId(parentContainerId_); 26023b3eb3cSopenharmony_ci container->GetSettings().SetUsingSharedRuntime(true); 26123b3eb3cSopenharmony_ci container->SetSharedRuntime(parentContainer->GetSharedRuntime()); 26223b3eb3cSopenharmony_ci container->Initialize(); 26323b3eb3cSopenharmony_ci container->SetAssetManager(parentContainer->GetAssetManager()); 26423b3eb3cSopenharmony_ci container->SetResourceConfiguration(parentContainer->GetResourceConfiguration()); 26523b3eb3cSopenharmony_ci container->SetPackagePathStr(parentContainer->GetPackagePathStr()); 26623b3eb3cSopenharmony_ci container->SetHapPath(parentContainer->GetHapPath()); 26723b3eb3cSopenharmony_ci container->SetIsSubContainer(true); 26823b3eb3cSopenharmony_ci container->InitializeSubContainer(parentContainerId_); 26923b3eb3cSopenharmony_ci 27023b3eb3cSopenharmony_ci // create ace_view 27123b3eb3cSopenharmony_ci auto aceView = 27223b3eb3cSopenharmony_ci Platform::AceViewOhos::CreateView(childContainerId_, false, container->GetSettings().usePlatformAsUIThread); 27323b3eb3cSopenharmony_ci Platform::AceViewOhos::SurfaceCreated(aceView, window_); 27423b3eb3cSopenharmony_ci 27523b3eb3cSopenharmony_ci int32_t width = static_cast<int32_t>(window_->GetRequestRect().width_); 27623b3eb3cSopenharmony_ci int32_t height = static_cast<int32_t>(window_->GetRequestRect().height_); 27723b3eb3cSopenharmony_ci auto density = parentPipeline->GetDensity(); 27823b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_SUB_WINDOW, 27923b3eb3cSopenharmony_ci "UIContent Initialize: width: %{public}d, height: %{public}d, density: %{public}lf", width, height, density); 28023b3eb3cSopenharmony_ci 28123b3eb3cSopenharmony_ci Ace::Platform::UIEnvCallback callback = nullptr; 28223b3eb3cSopenharmony_ci // set view 28323b3eb3cSopenharmony_ci Platform::AceContainer::SetView(aceView, density, width, height, window_, callback); 28423b3eb3cSopenharmony_ci ViewportConfig config; 28523b3eb3cSopenharmony_ci Platform::AceViewOhos::SurfaceChanged(aceView, width, height, config.Orientation()); 28623b3eb3cSopenharmony_ci 28723b3eb3cSopenharmony_ci auto uiContentImpl = reinterpret_cast<UIContentImpl*>(window_->GetUIContent()); 28823b3eb3cSopenharmony_ci if (!uiContentImpl) { 28923b3eb3cSopenharmony_ci TAG_LOGE(AceLogTag::ACE_SUB_WINDOW, "Window get ui content failed"); 29023b3eb3cSopenharmony_ci window_->Destroy(); 29123b3eb3cSopenharmony_ci return false; 29223b3eb3cSopenharmony_ci } 29323b3eb3cSopenharmony_ci uiContentImpl->SetFontScaleAndWeightScale(container, childContainerId_); 29423b3eb3cSopenharmony_ci freeMultiWindowListener_ = new SwitchFreeMultiWindowListener(childContainerId_); 29523b3eb3cSopenharmony_ci window_->RegisterSwitchFreeMultiWindowListener(freeMultiWindowListener_); 29623b3eb3cSopenharmony_ci 29723b3eb3cSopenharmony_ci#ifndef NG_BUILD 29823b3eb3cSopenharmony_ci#ifdef ENABLE_ROSEN_BACKEND 29923b3eb3cSopenharmony_ci if (SystemProperties::GetRosenBackendEnabled()) { 30023b3eb3cSopenharmony_ci rsUiDirector = OHOS::Rosen::RSUIDirector::Create(); 30123b3eb3cSopenharmony_ci if (rsUiDirector != nullptr) { 30223b3eb3cSopenharmony_ci rsUiDirector->SetRSSurfaceNode(window_->GetSurfaceNode()); 30323b3eb3cSopenharmony_ci auto context = DynamicCast<PipelineContext>(container->GetPipelineContext()); 30423b3eb3cSopenharmony_ci if (context != nullptr) { 30523b3eb3cSopenharmony_ci context->SetRSUIDirector(rsUiDirector); 30623b3eb3cSopenharmony_ci } 30723b3eb3cSopenharmony_ci rsUiDirector->Init(); 30823b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_SUB_WINDOW, "UIContent Init Rosen Backend"); 30923b3eb3cSopenharmony_ci } 31023b3eb3cSopenharmony_ci } 31123b3eb3cSopenharmony_ci#endif 31223b3eb3cSopenharmony_ci#endif 31323b3eb3cSopenharmony_ci 31423b3eb3cSopenharmony_ci auto subPipelineContext = Platform::AceContainer::GetContainer(childContainerId_)->GetPipelineContext(); 31523b3eb3cSopenharmony_ci if (!subPipelineContext) { 31623b3eb3cSopenharmony_ci TAG_LOGE(AceLogTag::ACE_SUB_WINDOW, "get sub pipeline failed"); 31723b3eb3cSopenharmony_ci window_->Destroy(); 31823b3eb3cSopenharmony_ci return false; 31923b3eb3cSopenharmony_ci } 32023b3eb3cSopenharmony_ci subPipelineContext->SetParentPipeline(parentContainer->GetPipelineContext()); 32123b3eb3cSopenharmony_ci subPipelineContext->SetMinPlatformVersion(parentPipeline->GetMinPlatformVersion()); 32223b3eb3cSopenharmony_ci subPipelineContext->SetupSubRootElement(); 32323b3eb3cSopenharmony_ci subPipelineContext->SetKeyboardAnimationConfig(parentPipeline->GetKeyboardAnimationConfig()); 32423b3eb3cSopenharmony_ci subPipelineContext->SetDragNodeGrayscale(parentPipeline->GetDragNodeGrayscale()); 32523b3eb3cSopenharmony_ci subPipelineContext->SetMaxAppFontScale(parentPipeline->GetMaxAppFontScale()); 32623b3eb3cSopenharmony_ci subPipelineContext->SetFollowSystem(parentPipeline->IsFollowSystem()); 32723b3eb3cSopenharmony_ci subPipelineContext->SetFontScale(parentPipeline->GetFontScale()); 32823b3eb3cSopenharmony_ci return true; 32923b3eb3cSopenharmony_ci} 33023b3eb3cSopenharmony_ci 33123b3eb3cSopenharmony_ciRefPtr<PipelineBase> SubwindowOhos::GetChildPipelineContext() const 33223b3eb3cSopenharmony_ci{ 33323b3eb3cSopenharmony_ci auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_); 33423b3eb3cSopenharmony_ci CHECK_NULL_RETURN(aceContainer, nullptr); 33523b3eb3cSopenharmony_ci return aceContainer->GetPipelineContext(); 33623b3eb3cSopenharmony_ci} 33723b3eb3cSopenharmony_ci 33823b3eb3cSopenharmony_cistd::function<void()> SubwindowOhos::GetInitToastDelayTask(const NG::ToastInfo& toastInfo, 33923b3eb3cSopenharmony_ci std::function<void(int32_t)>&& callback) 34023b3eb3cSopenharmony_ci{ 34123b3eb3cSopenharmony_ci return [toastInfo, callbackParam = std::move(callback)]() { 34223b3eb3cSopenharmony_ci int32_t posX = 0; 34323b3eb3cSopenharmony_ci int32_t posY = 0; 34423b3eb3cSopenharmony_ci int32_t width = 0; 34523b3eb3cSopenharmony_ci int32_t height = 0; 34623b3eb3cSopenharmony_ci float density = 1.0f; 34723b3eb3cSopenharmony_ci auto subwindowOhos = 34823b3eb3cSopenharmony_ci AceType::DynamicCast<SubwindowOhos>(SubwindowManager::GetInstance()->GetCurrentDialogWindow()); 34923b3eb3cSopenharmony_ci CHECK_NULL_VOID(subwindowOhos); 35023b3eb3cSopenharmony_ci subwindowOhos->GetToastDialogWindowProperty(width, height, posX, posY, density); 35123b3eb3cSopenharmony_ci auto childContainerId = subwindowOhos->GetChildContainerId(); 35223b3eb3cSopenharmony_ci auto window = Platform::DialogContainer::GetUIWindow(childContainerId); 35323b3eb3cSopenharmony_ci auto dialogWindow = subwindowOhos->GetDialogWindow(); 35423b3eb3cSopenharmony_ci if (!dialogWindow || !window || !subwindowOhos->IsToastWindow()) { 35523b3eb3cSopenharmony_ci bool ret = subwindowOhos->InitToastDialogWindow(width, height, posX, posY, true); 35623b3eb3cSopenharmony_ci if (!ret) { 35723b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, "init toast dialog window failed"); 35823b3eb3cSopenharmony_ci return; 35923b3eb3cSopenharmony_ci } 36023b3eb3cSopenharmony_ci ret = subwindowOhos->InitToastDialogView(width, height, density); 36123b3eb3cSopenharmony_ci if (!ret) { 36223b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, "init toast dialog view failed"); 36323b3eb3cSopenharmony_ci return; 36423b3eb3cSopenharmony_ci } 36523b3eb3cSopenharmony_ci subwindowOhos->SetIsToastWindow(true); 36623b3eb3cSopenharmony_ci } 36723b3eb3cSopenharmony_ci childContainerId = subwindowOhos->GetChildContainerId(); 36823b3eb3cSopenharmony_ci ContainerScope scope(childContainerId); 36923b3eb3cSopenharmony_ci subwindowOhos->UpdateAceView(width, height, density, childContainerId); 37023b3eb3cSopenharmony_ci TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, 37123b3eb3cSopenharmony_ci "update ace view width : %{public}d, height : %{public}d, density : %{public}f,childContainerId : " 37223b3eb3cSopenharmony_ci "%{public}d", 37323b3eb3cSopenharmony_ci width, height, density, childContainerId); 37423b3eb3cSopenharmony_ci auto container = Platform::DialogContainer::GetContainer(childContainerId); 37523b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 37623b3eb3cSopenharmony_ci container->SetFontScaleAndWeightScale(childContainerId); 37723b3eb3cSopenharmony_ci auto ret = subwindowOhos->InitToastServiceConfig(); 37823b3eb3cSopenharmony_ci if (!ret) { 37923b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, "init toast service conf failed"); 38023b3eb3cSopenharmony_ci } 38123b3eb3cSopenharmony_ci Platform::DialogContainer::ShowToastDialogWindow(childContainerId, posX, posY, width, height, true); 38223b3eb3cSopenharmony_ci Platform::DialogContainer::ShowToast(childContainerId, toastInfo.message, toastInfo.duration, toastInfo.bottom, 38323b3eb3cSopenharmony_ci std::move(const_cast<std::function<void(int32_t)>&&>(callbackParam))); 38423b3eb3cSopenharmony_ci }; 38523b3eb3cSopenharmony_ci} 38623b3eb3cSopenharmony_ci 38723b3eb3cSopenharmony_civoid SubwindowOhos::ResizeWindow() 38823b3eb3cSopenharmony_ci{ 38923b3eb3cSopenharmony_ci auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay(); 39023b3eb3cSopenharmony_ci CHECK_NULL_VOID(defaultDisplay); 39123b3eb3cSopenharmony_ci CHECK_NULL_VOID(window_); 39223b3eb3cSopenharmony_ci auto ret = window_->Resize(defaultDisplay->GetWidth(), defaultDisplay->GetHeight()); 39323b3eb3cSopenharmony_ci if (ret != Rosen::WMError::WM_OK) { 39423b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, "Resize window by default display failed with errCode: %{public}d", 39523b3eb3cSopenharmony_ci static_cast<int32_t>(ret)); 39623b3eb3cSopenharmony_ci return; 39723b3eb3cSopenharmony_ci } 39823b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_SUB_WINDOW, 39923b3eb3cSopenharmony_ci "SubwindowOhos window rect is resized to x: %{public}d, y: %{public}d, width: %{public}u, height: %{public}u", 40023b3eb3cSopenharmony_ci window_->GetRect().posX_, window_->GetRect().posY_, window_->GetRect().width_, window_->GetRect().height_); 40123b3eb3cSopenharmony_ci} 40223b3eb3cSopenharmony_ci 40323b3eb3cSopenharmony_civoid SubwindowOhos::SetRect(const NG::RectF& rect) 40423b3eb3cSopenharmony_ci{ 40523b3eb3cSopenharmony_ci windowRect_ = rect; 40623b3eb3cSopenharmony_ci} 40723b3eb3cSopenharmony_ci 40823b3eb3cSopenharmony_ciNG::RectF SubwindowOhos::GetRect() 40923b3eb3cSopenharmony_ci{ 41023b3eb3cSopenharmony_ci return windowRect_; 41123b3eb3cSopenharmony_ci} 41223b3eb3cSopenharmony_ci 41323b3eb3cSopenharmony_civoid SubwindowOhos::ShowPopup(const RefPtr<Component>& newComponent, bool disableTouchEvent) 41423b3eb3cSopenharmony_ci{ 41523b3eb3cSopenharmony_ci TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "show popup enter"); 41623b3eb3cSopenharmony_ci#ifndef NG_BUILD 41723b3eb3cSopenharmony_ci ShowWindow(); 41823b3eb3cSopenharmony_ci auto stack = GetStack(); 41923b3eb3cSopenharmony_ci CHECK_NULL_VOID(stack); 42023b3eb3cSopenharmony_ci auto popup = AceType::DynamicCast<TweenComponent>(newComponent); 42123b3eb3cSopenharmony_ci CHECK_NULL_VOID(popup); 42223b3eb3cSopenharmony_ci stack->PopPopup(popup->GetId()); 42323b3eb3cSopenharmony_ci stack->PushComponent(newComponent, disableTouchEvent); 42423b3eb3cSopenharmony_ci auto bubble = AceType::DynamicCast<BubbleComponent>(popup->GetChild()); 42523b3eb3cSopenharmony_ci if (bubble) { 42623b3eb3cSopenharmony_ci bubble->SetWeakStack(WeakClaim(RawPtr(stack))); 42723b3eb3cSopenharmony_ci } 42823b3eb3cSopenharmony_ci#endif 42923b3eb3cSopenharmony_ci} 43023b3eb3cSopenharmony_ci 43123b3eb3cSopenharmony_cibool SubwindowOhos::CancelPopup(const std::string& id) 43223b3eb3cSopenharmony_ci{ 43323b3eb3cSopenharmony_ci TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "cancel popup enter"); 43423b3eb3cSopenharmony_ci#ifndef NG_BUILD 43523b3eb3cSopenharmony_ci auto stack = GetStack(); 43623b3eb3cSopenharmony_ci CHECK_NULL_RETURN(stack, false); 43723b3eb3cSopenharmony_ci stack->PopPopup(id); 43823b3eb3cSopenharmony_ci auto context = stack->GetContext().Upgrade(); 43923b3eb3cSopenharmony_ci CHECK_NULL_RETURN(context, false); 44023b3eb3cSopenharmony_ci context->FlushPipelineImmediately(); 44123b3eb3cSopenharmony_ci HideWindow(); 44223b3eb3cSopenharmony_ci#endif 44323b3eb3cSopenharmony_ci return true; 44423b3eb3cSopenharmony_ci} 44523b3eb3cSopenharmony_ci 44623b3eb3cSopenharmony_civoid SubwindowOhos::ShowPopupNG(int32_t targetId, const NG::PopupInfo& popupInfo, 44723b3eb3cSopenharmony_ci const std::function<void(int32_t)>&& onWillDismiss, bool interactiveDismiss) 44823b3eb3cSopenharmony_ci{ 44923b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_SUB_WINDOW, "show popup ng enter, subwindowId: %{public}d", window_->GetWindowId()); 45023b3eb3cSopenharmony_ci popupTargetId_ = targetId; 45123b3eb3cSopenharmony_ci auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_); 45223b3eb3cSopenharmony_ci CHECK_NULL_VOID(aceContainer); 45323b3eb3cSopenharmony_ci auto context = DynamicCast<NG::PipelineContext>(aceContainer->GetPipelineContext()); 45423b3eb3cSopenharmony_ci CHECK_NULL_VOID(context); 45523b3eb3cSopenharmony_ci auto overlayManager = context->GetOverlayManager(); 45623b3eb3cSopenharmony_ci CHECK_NULL_VOID(overlayManager); 45723b3eb3cSopenharmony_ci ResizeWindow(); 45823b3eb3cSopenharmony_ci ShowWindow(popupInfo.focusable); 45923b3eb3cSopenharmony_ci CHECK_NULL_VOID(window_); 46023b3eb3cSopenharmony_ci window_->SetTouchable(true); 46123b3eb3cSopenharmony_ci ContainerScope scope(childContainerId_); 46223b3eb3cSopenharmony_ci overlayManager->ShowPopup(targetId, popupInfo, std::move(onWillDismiss), interactiveDismiss); 46323b3eb3cSopenharmony_ci window_->SetFocusable(true); 46423b3eb3cSopenharmony_ci} 46523b3eb3cSopenharmony_ci 46623b3eb3cSopenharmony_civoid SubwindowOhos::HidePopupNG(int32_t targetId) 46723b3eb3cSopenharmony_ci{ 46823b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_SUB_WINDOW, 46923b3eb3cSopenharmony_ci "hide popup ng enter, subwindowId: %{public}d, subwindowName: %{public}s", 47023b3eb3cSopenharmony_ci window_->GetWindowId(), window_->GetWindowName().c_str()); 47123b3eb3cSopenharmony_ci auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_); 47223b3eb3cSopenharmony_ci CHECK_NULL_VOID(aceContainer); 47323b3eb3cSopenharmony_ci auto context = DynamicCast<NG::PipelineContext>(aceContainer->GetPipelineContext()); 47423b3eb3cSopenharmony_ci CHECK_NULL_VOID(context); 47523b3eb3cSopenharmony_ci auto overlayManager = context->GetOverlayManager(); 47623b3eb3cSopenharmony_ci CHECK_NULL_VOID(overlayManager); 47723b3eb3cSopenharmony_ci auto popupInfo = overlayManager->GetPopupInfo(targetId == -1 ? popupTargetId_ : targetId); 47823b3eb3cSopenharmony_ci popupInfo.markNeedUpdate = true; 47923b3eb3cSopenharmony_ci ContainerScope scope(childContainerId_); 48023b3eb3cSopenharmony_ci overlayManager->HidePopup(targetId == -1 ? popupTargetId_ : targetId, popupInfo); 48123b3eb3cSopenharmony_ci context->FlushPipelineImmediately(); 48223b3eb3cSopenharmony_ci HideEventColumn(); 48323b3eb3cSopenharmony_ci HidePixelMap(); 48423b3eb3cSopenharmony_ci HideFilter(false); 48523b3eb3cSopenharmony_ci} 48623b3eb3cSopenharmony_ci 48723b3eb3cSopenharmony_civoid SubwindowOhos::GetPopupInfoNG(int32_t targetId, NG::PopupInfo& popupInfo) 48823b3eb3cSopenharmony_ci{ 48923b3eb3cSopenharmony_ci TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "get popup info ng enter"); 49023b3eb3cSopenharmony_ci auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_); 49123b3eb3cSopenharmony_ci CHECK_NULL_VOID(aceContainer); 49223b3eb3cSopenharmony_ci auto context = DynamicCast<NG::PipelineContext>(aceContainer->GetPipelineContext()); 49323b3eb3cSopenharmony_ci CHECK_NULL_VOID(context); 49423b3eb3cSopenharmony_ci auto overlayManager = context->GetOverlayManager(); 49523b3eb3cSopenharmony_ci CHECK_NULL_VOID(overlayManager); 49623b3eb3cSopenharmony_ci popupInfo = overlayManager->GetPopupInfo(targetId); 49723b3eb3cSopenharmony_ci} 49823b3eb3cSopenharmony_ci 49923b3eb3cSopenharmony_ciconst RefPtr<NG::OverlayManager> SubwindowOhos::GetOverlayManager() 50023b3eb3cSopenharmony_ci{ 50123b3eb3cSopenharmony_ci auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_); 50223b3eb3cSopenharmony_ci CHECK_NULL_RETURN(aceContainer, nullptr); 50323b3eb3cSopenharmony_ci auto context = DynamicCast<NG::PipelineContext>(aceContainer->GetPipelineContext()); 50423b3eb3cSopenharmony_ci CHECK_NULL_RETURN(context, nullptr); 50523b3eb3cSopenharmony_ci return context->GetOverlayManager(); 50623b3eb3cSopenharmony_ci} 50723b3eb3cSopenharmony_ci 50823b3eb3cSopenharmony_civoid SubwindowOhos::ShowWindow(bool needFocus) 50923b3eb3cSopenharmony_ci{ 51023b3eb3cSopenharmony_ci CHECK_NULL_VOID(window_); 51123b3eb3cSopenharmony_ci if (isShowed_) { 51223b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_SUB_WINDOW, "subwindow id:%{public}u is on display", window_->GetWindowId()); 51323b3eb3cSopenharmony_ci if (needFocus) { 51423b3eb3cSopenharmony_ci window_->SetFocusable(needFocus); 51523b3eb3cSopenharmony_ci RequestFocus(); 51623b3eb3cSopenharmony_ci } 51723b3eb3cSopenharmony_ci return; 51823b3eb3cSopenharmony_ci } 51923b3eb3cSopenharmony_ci // Set min window hot area so that sub window can transparent event. 52023b3eb3cSopenharmony_ci std::vector<Rosen::Rect> hotAreas; 52123b3eb3cSopenharmony_ci Rosen::Rect rosenRect {}; 52223b3eb3cSopenharmony_ci RectConverter(MIN_WINDOW_HOT_AREA, rosenRect); 52323b3eb3cSopenharmony_ci hotAreas.emplace_back(rosenRect); 52423b3eb3cSopenharmony_ci window_->SetTouchHotAreas(hotAreas); 52523b3eb3cSopenharmony_ci 52623b3eb3cSopenharmony_ci window_->SetNeedDefaultAnimation(false); 52723b3eb3cSopenharmony_ci auto ret = window_->SetFocusable(needFocus); 52823b3eb3cSopenharmony_ci if (ret != OHOS::Rosen::WMError::WM_OK) { 52923b3eb3cSopenharmony_ci TAG_LOGE(AceLogTag::ACE_SUB_WINDOW, 53023b3eb3cSopenharmony_ci "subwindow id:%{public}u set focusable %{public}d failed with WMError: %{public}d", window_->GetWindowId(), 53123b3eb3cSopenharmony_ci needFocus, static_cast<int32_t>(ret)); 53223b3eb3cSopenharmony_ci } 53323b3eb3cSopenharmony_ci ret = window_->Show(0, false, needFocus); 53423b3eb3cSopenharmony_ci if (ret != OHOS::Rosen::WMError::WM_OK) { 53523b3eb3cSopenharmony_ci TAG_LOGE(AceLogTag::ACE_SUB_WINDOW, "Show subwindow id:%{public}u failed with WMError: %{public}d", 53623b3eb3cSopenharmony_ci window_->GetWindowId(), static_cast<int32_t>(ret)); 53723b3eb3cSopenharmony_ci return; 53823b3eb3cSopenharmony_ci } 53923b3eb3cSopenharmony_ci if (needFocus) { 54023b3eb3cSopenharmony_ci RequestFocus(); 54123b3eb3cSopenharmony_ci } 54223b3eb3cSopenharmony_ci 54323b3eb3cSopenharmony_ci auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_); 54423b3eb3cSopenharmony_ci CHECK_NULL_VOID(aceContainer); 54523b3eb3cSopenharmony_ci auto context = aceContainer->GetPipelineContext(); 54623b3eb3cSopenharmony_ci CHECK_NULL_VOID(context); 54723b3eb3cSopenharmony_ci AccessibilityEvent event; 54823b3eb3cSopenharmony_ci event.type = AccessibilityEventType::PAGE_CHANGE; 54923b3eb3cSopenharmony_ci event.windowId = context->GetWindowId(); 55023b3eb3cSopenharmony_ci event.windowChangeTypes = WINDOW_UPDATE_ADDED; 55123b3eb3cSopenharmony_ci context->SendEventToAccessibility(event); 55223b3eb3cSopenharmony_ci isShowed_ = true; 55323b3eb3cSopenharmony_ci SubwindowManager::GetInstance()->SetCurrentSubwindow(AceType::Claim(this)); 55423b3eb3cSopenharmony_ci} 55523b3eb3cSopenharmony_ci 55623b3eb3cSopenharmony_civoid SubwindowOhos::HideWindow() 55723b3eb3cSopenharmony_ci{ 55823b3eb3cSopenharmony_ci CHECK_NULL_VOID(window_); 55923b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_SUB_WINDOW, "Hide the subwindow %{public}s", window_->GetWindowName().c_str()); 56023b3eb3cSopenharmony_ci 56123b3eb3cSopenharmony_ci auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_); 56223b3eb3cSopenharmony_ci if (!aceContainer) { 56323b3eb3cSopenharmony_ci TAG_LOGE(AceLogTag::ACE_SUB_WINDOW, "get container failed, child containerId: %{public}d", childContainerId_); 56423b3eb3cSopenharmony_ci return; 56523b3eb3cSopenharmony_ci } 56623b3eb3cSopenharmony_ci 56723b3eb3cSopenharmony_ci#ifdef NG_BUILD 56823b3eb3cSopenharmony_ci auto context = DynamicCast<NG::PipelineContext>(aceContainer->GetPipelineContext()); 56923b3eb3cSopenharmony_ci CHECK_NULL_VOID(context); 57023b3eb3cSopenharmony_ci auto rootNode = context->GetRootElement(); 57123b3eb3cSopenharmony_ci CHECK_NULL_VOID(rootNode); 57223b3eb3cSopenharmony_ci if (!rootNode->GetChildren().empty() && 57323b3eb3cSopenharmony_ci !(rootNode->GetChildren().size() == 1 && rootNode->GetLastChild()->GetTag() == V2::KEYBOARD_ETS_TAG)) { 57423b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, "Subwindow has other node, the last child is %{public}s", 57523b3eb3cSopenharmony_ci rootNode->GetLastChild()->GetTag().c_str()); 57623b3eb3cSopenharmony_ci auto lastChildId = rootNode->GetLastChild()->GetId(); 57723b3eb3cSopenharmony_ci auto iter = hotAreasMap_.find(lastChildId); 57823b3eb3cSopenharmony_ci if (iter != hotAreasMap_.end()) { 57923b3eb3cSopenharmony_ci auto hotAreaRect = iter->second; 58023b3eb3cSopenharmony_ci OHOS::Rosen::WMError ret = window_->SetTouchHotAreas(hotAreaRect); 58123b3eb3cSopenharmony_ci if (ret != OHOS::Rosen::WMError::WM_OK) { 58223b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, "Set hot areas failed with errCode: %{public}d", 58323b3eb3cSopenharmony_ci static_cast<int32_t>(ret)); 58423b3eb3cSopenharmony_ci } 58523b3eb3cSopenharmony_ci } 58623b3eb3cSopenharmony_ci return; 58723b3eb3cSopenharmony_ci } 58823b3eb3cSopenharmony_ci auto focusHub = rootNode->GetFocusHub(); 58923b3eb3cSopenharmony_ci CHECK_NULL_VOID(focusHub); 59023b3eb3cSopenharmony_ci focusHub->SetIsDefaultHasFocused(false); 59123b3eb3cSopenharmony_ci context->SetIsFocusActive(false); 59223b3eb3cSopenharmony_ci#else 59323b3eb3cSopenharmony_ci if (Container::IsCurrentUseNewPipeline()) { 59423b3eb3cSopenharmony_ci auto context = DynamicCast<NG::PipelineContext>(aceContainer->GetPipelineContext()); 59523b3eb3cSopenharmony_ci CHECK_NULL_VOID(context); 59623b3eb3cSopenharmony_ci auto rootNode = context->GetRootElement(); 59723b3eb3cSopenharmony_ci CHECK_NULL_VOID(rootNode); 59823b3eb3cSopenharmony_ci if (!rootNode->GetChildren().empty() && 59923b3eb3cSopenharmony_ci !(rootNode->GetChildren().size() == 1 && rootNode->GetLastChild()->GetTag() == V2::KEYBOARD_ETS_TAG)) { 60023b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, "Subwindow has other node, the last child is %{public}s", 60123b3eb3cSopenharmony_ci rootNode->GetLastChild()->GetTag().c_str()); 60223b3eb3cSopenharmony_ci return; 60323b3eb3cSopenharmony_ci } 60423b3eb3cSopenharmony_ci auto focusHub = rootNode->GetFocusHub(); 60523b3eb3cSopenharmony_ci CHECK_NULL_VOID(focusHub); 60623b3eb3cSopenharmony_ci focusHub->SetIsDefaultHasFocused(false); 60723b3eb3cSopenharmony_ci context->SetIsFocusActive(false); 60823b3eb3cSopenharmony_ci } else { 60923b3eb3cSopenharmony_ci auto context = DynamicCast<PipelineContext>(aceContainer->GetPipelineContext()); 61023b3eb3cSopenharmony_ci CHECK_NULL_VOID(context); 61123b3eb3cSopenharmony_ci auto rootNode = context->GetRootElement(); 61223b3eb3cSopenharmony_ci CHECK_NULL_VOID(rootNode); 61323b3eb3cSopenharmony_ci rootNode->SetIsDefaultHasFocused(false); 61423b3eb3cSopenharmony_ci } 61523b3eb3cSopenharmony_ci#endif 61623b3eb3cSopenharmony_ci if (!window_->IsFocused()) { 61723b3eb3cSopenharmony_ci ContainerModalUnFocus(); 61823b3eb3cSopenharmony_ci } 61923b3eb3cSopenharmony_ci OHOS::Rosen::WMError ret = window_->Hide(); 62023b3eb3cSopenharmony_ci auto parentContainer = Platform::AceContainer::GetContainer(parentContainerId_); 62123b3eb3cSopenharmony_ci if (!parentContainer) { 62223b3eb3cSopenharmony_ci TAG_LOGE(AceLogTag::ACE_SUB_WINDOW, "get container failed, parent containerId: %{public}d", parentContainerId_); 62323b3eb3cSopenharmony_ci return; 62423b3eb3cSopenharmony_ci } 62523b3eb3cSopenharmony_ci if (parentContainer->IsScenceBoardWindow()) { 62623b3eb3cSopenharmony_ci window_->SetTouchable(true); 62723b3eb3cSopenharmony_ci } 62823b3eb3cSopenharmony_ci 62923b3eb3cSopenharmony_ci if (ret != OHOS::Rosen::WMError::WM_OK) { 63023b3eb3cSopenharmony_ci TAG_LOGE(AceLogTag::ACE_SUB_WINDOW, "Hide window failed with errCode: %{public}d", static_cast<int32_t>(ret)); 63123b3eb3cSopenharmony_ci return; 63223b3eb3cSopenharmony_ci } 63323b3eb3cSopenharmony_ci isShowed_ = false; 63423b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_SUB_WINDOW, "Hide the subwindow successfully."); 63523b3eb3cSopenharmony_ci#ifndef NG_BUILD 63623b3eb3cSopenharmony_ci auto context = aceContainer->GetPipelineContext(); 63723b3eb3cSopenharmony_ci CHECK_NULL_VOID(context); 63823b3eb3cSopenharmony_ci#endif 63923b3eb3cSopenharmony_ci AccessibilityEvent event; 64023b3eb3cSopenharmony_ci event.type = AccessibilityEventType::PAGE_CHANGE; 64123b3eb3cSopenharmony_ci event.windowId = context->GetWindowId(); 64223b3eb3cSopenharmony_ci event.windowChangeTypes = WINDOW_UPDATE_REMOVED; 64323b3eb3cSopenharmony_ci context->SendEventToAccessibility(event); 64423b3eb3cSopenharmony_ci} 64523b3eb3cSopenharmony_ci 64623b3eb3cSopenharmony_civoid SubwindowOhos::ContainerModalUnFocus() 64723b3eb3cSopenharmony_ci{ 64823b3eb3cSopenharmony_ci auto parentContainer = Platform::AceContainer::GetContainer(parentContainerId_); 64923b3eb3cSopenharmony_ci CHECK_NULL_VOID(parentContainer); 65023b3eb3cSopenharmony_ci auto parentWindowName = parentContainer->GetWindowName(); 65123b3eb3cSopenharmony_ci sptr<OHOS::Rosen::Window> parentWindow = OHOS::Rosen::Window::Find(parentWindowName); 65223b3eb3cSopenharmony_ci CHECK_NULL_VOID(parentWindow); 65323b3eb3cSopenharmony_ci if (parentWindow->GetFocusable() && !parentWindow->IsFocused()) { 65423b3eb3cSopenharmony_ci auto pipelineContext = parentContainer->GetPipelineContext(); 65523b3eb3cSopenharmony_ci CHECK_NULL_VOID(pipelineContext); 65623b3eb3cSopenharmony_ci pipelineContext->ContainerModalUnFocus(); 65723b3eb3cSopenharmony_ci } 65823b3eb3cSopenharmony_ci} 65923b3eb3cSopenharmony_ci 66023b3eb3cSopenharmony_civoid SubwindowOhos::AddMenu(const RefPtr<Component>& newComponent) 66123b3eb3cSopenharmony_ci{ 66223b3eb3cSopenharmony_ci TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "add menu enter"); 66323b3eb3cSopenharmony_ci#ifndef NG_BUILD 66423b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_SUB_WINDOW, "Subwindow push new component start."); 66523b3eb3cSopenharmony_ci auto stack = GetStack(); 66623b3eb3cSopenharmony_ci CHECK_NULL_VOID(stack); 66723b3eb3cSopenharmony_ci // Push the component 66823b3eb3cSopenharmony_ci stack->PopMenu(); 66923b3eb3cSopenharmony_ci stack->PushComponent(newComponent); 67023b3eb3cSopenharmony_ci popup_ = AceType::DynamicCast<SelectPopupComponent>(newComponent); 67123b3eb3cSopenharmony_ci#endif 67223b3eb3cSopenharmony_ci} 67323b3eb3cSopenharmony_ci 67423b3eb3cSopenharmony_civoid SubwindowOhos::ClearMenu() 67523b3eb3cSopenharmony_ci{ 67623b3eb3cSopenharmony_ci TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "clear menu enter"); 67723b3eb3cSopenharmony_ci if (haveDialog_) { 67823b3eb3cSopenharmony_ci return; 67923b3eb3cSopenharmony_ci } 68023b3eb3cSopenharmony_ci#ifndef NG_BUILD 68123b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_SUB_WINDOW, "Subwindow Clear menu start."); 68223b3eb3cSopenharmony_ci auto stack = GetStack(); 68323b3eb3cSopenharmony_ci CHECK_NULL_VOID(stack); 68423b3eb3cSopenharmony_ci // Pop the component 68523b3eb3cSopenharmony_ci stack->PopMenu(); 68623b3eb3cSopenharmony_ci auto context = stack->GetContext().Upgrade(); 68723b3eb3cSopenharmony_ci CHECK_NULL_VOID(context); 68823b3eb3cSopenharmony_ci context->FlushPipelineImmediately(); 68923b3eb3cSopenharmony_ci HideWindow(); 69023b3eb3cSopenharmony_ci#endif 69123b3eb3cSopenharmony_ci} 69223b3eb3cSopenharmony_ci 69323b3eb3cSopenharmony_cibool SubwindowOhos::ShowPreviewNG(bool isStartDraggingFromSubWindow) 69423b3eb3cSopenharmony_ci{ 69523b3eb3cSopenharmony_ci CHECK_NULL_RETURN(window_, false); 69623b3eb3cSopenharmony_ci ResizeWindow(); 69723b3eb3cSopenharmony_ci ShowWindow(false); 69823b3eb3cSopenharmony_ci if (!isStartDraggingFromSubWindow) { 69923b3eb3cSopenharmony_ci window_->SetTouchable(false); 70023b3eb3cSopenharmony_ci } 70123b3eb3cSopenharmony_ci return true; 70223b3eb3cSopenharmony_ci} 70323b3eb3cSopenharmony_ci 70423b3eb3cSopenharmony_civoid SubwindowOhos::HidePreviewNG() 70523b3eb3cSopenharmony_ci{ 70623b3eb3cSopenharmony_ci auto overlayManager = GetOverlayManager(); 70723b3eb3cSopenharmony_ci CHECK_NULL_VOID(overlayManager); 70823b3eb3cSopenharmony_ci overlayManager->RemovePixelMap(); 70923b3eb3cSopenharmony_ci overlayManager->RemovePreviewBadgeNode(); 71023b3eb3cSopenharmony_ci overlayManager->RemoveGatherNode(); 71123b3eb3cSopenharmony_ci overlayManager->RemoveEventColumn(); 71223b3eb3cSopenharmony_ci auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_); 71323b3eb3cSopenharmony_ci CHECK_NULL_VOID(aceContainer); 71423b3eb3cSopenharmony_ci auto pipeline = DynamicCast<NG::PipelineContext>(aceContainer->GetPipelineContext()); 71523b3eb3cSopenharmony_ci CHECK_NULL_VOID(pipeline); 71623b3eb3cSopenharmony_ci pipeline->FlushPipelineImmediately(); 71723b3eb3cSopenharmony_ci HideSubWindowNG(); 71823b3eb3cSopenharmony_ci} 71923b3eb3cSopenharmony_ci 72023b3eb3cSopenharmony_civoid SubwindowOhos::ShowMenuNG(const RefPtr<NG::FrameNode> customNode, const NG::MenuParam& menuParam, 72123b3eb3cSopenharmony_ci const RefPtr<NG::FrameNode>& targetNode, const NG::OffsetF& offset) 72223b3eb3cSopenharmony_ci{ 72323b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_SUB_WINDOW, "show menu ng enter"); 72423b3eb3cSopenharmony_ci CHECK_NULL_VOID(customNode); 72523b3eb3cSopenharmony_ci CHECK_NULL_VOID(targetNode); 72623b3eb3cSopenharmony_ci ContainerScope scope(childContainerId_); 72723b3eb3cSopenharmony_ci auto container = Container::Current(); 72823b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 72923b3eb3cSopenharmony_ci auto context = DynamicCast<NG::PipelineContext>(container->GetPipelineContext()); 73023b3eb3cSopenharmony_ci CHECK_NULL_VOID(context); 73123b3eb3cSopenharmony_ci auto overlay = context->GetOverlayManager(); 73223b3eb3cSopenharmony_ci CHECK_NULL_VOID(overlay); 73323b3eb3cSopenharmony_ci auto menuNode = customNode; 73423b3eb3cSopenharmony_ci if (customNode->GetTag() != V2::MENU_WRAPPER_ETS_TAG) { 73523b3eb3cSopenharmony_ci menuNode = NG::MenuView::Create(customNode, targetNode->GetId(), targetNode->GetTag(), menuParam, true); 73623b3eb3cSopenharmony_ci auto menuWrapperPattern = menuNode->GetPattern<NG::MenuWrapperPattern>(); 73723b3eb3cSopenharmony_ci CHECK_NULL_VOID(menuWrapperPattern); 73823b3eb3cSopenharmony_ci menuWrapperPattern->RegisterMenuCallback(menuNode, menuParam); 73923b3eb3cSopenharmony_ci menuWrapperPattern->SetMenuTransitionEffect(menuNode, menuParam); 74023b3eb3cSopenharmony_ci } 74123b3eb3cSopenharmony_ci ResizeWindow(); 74223b3eb3cSopenharmony_ci ShowWindow(); 74323b3eb3cSopenharmony_ci CHECK_NULL_VOID(window_); 74423b3eb3cSopenharmony_ci window_->SetTouchable(true); 74523b3eb3cSopenharmony_ci overlay->ShowMenuInSubWindow(targetNode->GetId(), offset, menuNode); 74623b3eb3cSopenharmony_ci} 74723b3eb3cSopenharmony_ci 74823b3eb3cSopenharmony_civoid SubwindowOhos::ShowMenuNG(std::function<void()>&& buildFunc, std::function<void()>&& previewBuildFunc, 74923b3eb3cSopenharmony_ci const NG::MenuParam& menuParam, const RefPtr<NG::FrameNode>& targetNode, const NG::OffsetF& offset) 75023b3eb3cSopenharmony_ci{ 75123b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_SUB_WINDOW, "show menu ng enter"); 75223b3eb3cSopenharmony_ci ContainerScope scope(childContainerId_); 75323b3eb3cSopenharmony_ci auto container = Container::Current(); 75423b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 75523b3eb3cSopenharmony_ci auto context = DynamicCast<NG::PipelineContext>(container->GetPipelineContext()); 75623b3eb3cSopenharmony_ci CHECK_NULL_VOID(context); 75723b3eb3cSopenharmony_ci auto overlay = context->GetOverlayManager(); 75823b3eb3cSopenharmony_ci CHECK_NULL_VOID(overlay); 75923b3eb3cSopenharmony_ci ResizeWindow(); 76023b3eb3cSopenharmony_ci ShowWindow(); 76123b3eb3cSopenharmony_ci CHECK_NULL_VOID(window_); 76223b3eb3cSopenharmony_ci window_->SetTouchable(true); 76323b3eb3cSopenharmony_ci NG::ScopedViewStackProcessor builderViewStackProcessor; 76423b3eb3cSopenharmony_ci buildFunc(); 76523b3eb3cSopenharmony_ci auto customNode = NG::ViewStackProcessor::GetInstance()->Finish(); 76623b3eb3cSopenharmony_ci RefPtr<NG::UINode> previewCustomNode; 76723b3eb3cSopenharmony_ci if (previewBuildFunc && menuParam.previewMode == MenuPreviewMode::CUSTOM) { 76823b3eb3cSopenharmony_ci previewBuildFunc(); 76923b3eb3cSopenharmony_ci previewCustomNode = NG::ViewStackProcessor::GetInstance()->Finish(); 77023b3eb3cSopenharmony_ci } 77123b3eb3cSopenharmony_ci auto menuNode = 77223b3eb3cSopenharmony_ci NG::MenuView::Create(customNode, targetNode->GetId(), targetNode->GetTag(), menuParam, true, previewCustomNode); 77323b3eb3cSopenharmony_ci auto menuWrapperPattern = menuNode->GetPattern<NG::MenuWrapperPattern>(); 77423b3eb3cSopenharmony_ci CHECK_NULL_VOID(menuWrapperPattern); 77523b3eb3cSopenharmony_ci menuWrapperPattern->RegisterMenuCallback(menuNode, menuParam); 77623b3eb3cSopenharmony_ci menuWrapperPattern->SetMenuTransitionEffect(menuNode, menuParam); 77723b3eb3cSopenharmony_ci overlay->ShowMenuInSubWindow(targetNode->GetId(), offset, menuNode); 77823b3eb3cSopenharmony_ci} 77923b3eb3cSopenharmony_ci 78023b3eb3cSopenharmony_civoid SubwindowOhos::HideMenuNG(bool showPreviewAnimation, bool startDrag) 78123b3eb3cSopenharmony_ci{ 78223b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_SUB_WINDOW, "hide menu ng enter"); 78323b3eb3cSopenharmony_ci if (!isShowed_) { 78423b3eb3cSopenharmony_ci return; 78523b3eb3cSopenharmony_ci } 78623b3eb3cSopenharmony_ci ContainerScope scope(childContainerId_); 78723b3eb3cSopenharmony_ci auto container = Container::Current(); 78823b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 78923b3eb3cSopenharmony_ci auto context = DynamicCast<NG::PipelineContext>(container->GetPipelineContext()); 79023b3eb3cSopenharmony_ci CHECK_NULL_VOID(context); 79123b3eb3cSopenharmony_ci auto overlay = context->GetOverlayManager(); 79223b3eb3cSopenharmony_ci CHECK_NULL_VOID(overlay); 79323b3eb3cSopenharmony_ci overlay->HideMenuInSubWindow(showPreviewAnimation, startDrag); 79423b3eb3cSopenharmony_ci HideEventColumn(); 79523b3eb3cSopenharmony_ci HidePixelMap(startDrag, 0, 0, false); 79623b3eb3cSopenharmony_ci HideFilter(false); 79723b3eb3cSopenharmony_ci HideFilter(true); 79823b3eb3cSopenharmony_ci} 79923b3eb3cSopenharmony_ci 80023b3eb3cSopenharmony_civoid SubwindowOhos::HideMenuNG(const RefPtr<NG::FrameNode>& menu, int32_t targetId) 80123b3eb3cSopenharmony_ci{ 80223b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_SUB_WINDOW, "hide menu ng enter"); 80323b3eb3cSopenharmony_ci if (!isShowed_) { 80423b3eb3cSopenharmony_ci return; 80523b3eb3cSopenharmony_ci } 80623b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_SUB_WINDOW, "Subwindow hide menu for target id %{public}d", targetId); 80723b3eb3cSopenharmony_ci targetId_ = targetId; 80823b3eb3cSopenharmony_ci auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_); 80923b3eb3cSopenharmony_ci CHECK_NULL_VOID(aceContainer); 81023b3eb3cSopenharmony_ci auto context = DynamicCast<NG::PipelineContext>(aceContainer->GetPipelineContext()); 81123b3eb3cSopenharmony_ci CHECK_NULL_VOID(context); 81223b3eb3cSopenharmony_ci auto overlay = context->GetOverlayManager(); 81323b3eb3cSopenharmony_ci CHECK_NULL_VOID(overlay); 81423b3eb3cSopenharmony_ci overlay->HideMenuInSubWindow(menu, targetId_); 81523b3eb3cSopenharmony_ci HideEventColumn(); 81623b3eb3cSopenharmony_ci HidePixelMap(false, 0, 0, false); 81723b3eb3cSopenharmony_ci HideFilter(false); 81823b3eb3cSopenharmony_ci HideFilter(true); 81923b3eb3cSopenharmony_ci} 82023b3eb3cSopenharmony_ci 82123b3eb3cSopenharmony_civoid SubwindowOhos::UpdatePreviewPosition() 82223b3eb3cSopenharmony_ci{ 82323b3eb3cSopenharmony_ci ContainerScope scope(childContainerId_); 82423b3eb3cSopenharmony_ci auto pipelineContext = NG::PipelineContext::GetCurrentContext(); 82523b3eb3cSopenharmony_ci CHECK_NULL_VOID(pipelineContext); 82623b3eb3cSopenharmony_ci auto overlay = pipelineContext->GetOverlayManager(); 82723b3eb3cSopenharmony_ci CHECK_NULL_VOID(overlay); 82823b3eb3cSopenharmony_ci if (overlay->GetHasPixelMap()) { 82923b3eb3cSopenharmony_ci return; 83023b3eb3cSopenharmony_ci } 83123b3eb3cSopenharmony_ci overlay->UpdatePixelMapPosition(true); 83223b3eb3cSopenharmony_ci} 83323b3eb3cSopenharmony_ci 83423b3eb3cSopenharmony_cibool SubwindowOhos::GetMenuPreviewCenter(NG::OffsetF& offset) 83523b3eb3cSopenharmony_ci{ 83623b3eb3cSopenharmony_ci ContainerScope scope(childContainerId_); 83723b3eb3cSopenharmony_ci auto pipelineContext = NG::PipelineContext::GetCurrentContext(); 83823b3eb3cSopenharmony_ci CHECK_NULL_RETURN(pipelineContext, false); 83923b3eb3cSopenharmony_ci auto overlay = pipelineContext->GetOverlayManager(); 84023b3eb3cSopenharmony_ci CHECK_NULL_RETURN(overlay, false); 84123b3eb3cSopenharmony_ci return overlay->GetMenuPreviewCenter(offset); 84223b3eb3cSopenharmony_ci} 84323b3eb3cSopenharmony_ci 84423b3eb3cSopenharmony_civoid SubwindowOhos::UpdateHideMenuOffsetNG( 84523b3eb3cSopenharmony_ci const NG::OffsetF& offset, float menuScale, bool isRedragStart, int32_t menuWrapperId) 84623b3eb3cSopenharmony_ci{ 84723b3eb3cSopenharmony_ci ContainerScope scope(childContainerId_); 84823b3eb3cSopenharmony_ci auto pipelineContext = NG::PipelineContext::GetCurrentContext(); 84923b3eb3cSopenharmony_ci CHECK_NULL_VOID(pipelineContext); 85023b3eb3cSopenharmony_ci auto overlay = pipelineContext->GetOverlayManager(); 85123b3eb3cSopenharmony_ci CHECK_NULL_VOID(overlay); 85223b3eb3cSopenharmony_ci if (overlay->IsContextMenuDragHideFinished()) { 85323b3eb3cSopenharmony_ci return; 85423b3eb3cSopenharmony_ci } 85523b3eb3cSopenharmony_ci overlay->UpdateContextMenuDisappearPosition(offset, menuScale, isRedragStart, menuWrapperId); 85623b3eb3cSopenharmony_ci} 85723b3eb3cSopenharmony_ci 85823b3eb3cSopenharmony_civoid SubwindowOhos::ContextMenuSwitchDragPreviewAnimationtNG(const RefPtr<NG::FrameNode>& dragPreviewNode, 85923b3eb3cSopenharmony_ci const NG::OffsetF& offset) 86023b3eb3cSopenharmony_ci{ 86123b3eb3cSopenharmony_ci CHECK_NULL_VOID(dragPreviewNode); 86223b3eb3cSopenharmony_ci ContainerScope scope(childContainerId_); 86323b3eb3cSopenharmony_ci auto pipelineContext = NG::PipelineContext::GetCurrentContext(); 86423b3eb3cSopenharmony_ci CHECK_NULL_VOID(pipelineContext); 86523b3eb3cSopenharmony_ci auto overlay = pipelineContext->GetOverlayManager(); 86623b3eb3cSopenharmony_ci CHECK_NULL_VOID(overlay); 86723b3eb3cSopenharmony_ci overlay->ContextMenuSwitchDragPreviewAnimation(dragPreviewNode, offset); 86823b3eb3cSopenharmony_ci} 86923b3eb3cSopenharmony_ci 87023b3eb3cSopenharmony_civoid SubwindowOhos::ClearMenuNG(int32_t targetId, bool inWindow, bool showAnimation) 87123b3eb3cSopenharmony_ci{ 87223b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_SUB_WINDOW, "clear menu ng enter"); 87323b3eb3cSopenharmony_ci auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_); 87423b3eb3cSopenharmony_ci CHECK_NULL_VOID(aceContainer); 87523b3eb3cSopenharmony_ci auto context = DynamicCast<NG::PipelineContext>(aceContainer->GetPipelineContext()); 87623b3eb3cSopenharmony_ci CHECK_NULL_VOID(context); 87723b3eb3cSopenharmony_ci auto overlay = context->GetOverlayManager(); 87823b3eb3cSopenharmony_ci CHECK_NULL_VOID(overlay); 87923b3eb3cSopenharmony_ci if (showAnimation) { 88023b3eb3cSopenharmony_ci overlay->CleanMenuInSubWindowWithAnimation(); 88123b3eb3cSopenharmony_ci HideFilter(true); 88223b3eb3cSopenharmony_ci } else { 88323b3eb3cSopenharmony_ci overlay->CleanMenuInSubWindow(targetId); 88423b3eb3cSopenharmony_ci overlay->RemoveFilter(); 88523b3eb3cSopenharmony_ci } 88623b3eb3cSopenharmony_ci overlay->EraseMenuInfo(targetId); 88723b3eb3cSopenharmony_ci HideWindow(); 88823b3eb3cSopenharmony_ci context->FlushPipelineImmediately(); 88923b3eb3cSopenharmony_ci if (inWindow) { 89023b3eb3cSopenharmony_ci HideEventColumn(); 89123b3eb3cSopenharmony_ci } 89223b3eb3cSopenharmony_ci HidePixelMap(false, 0, 0, false); 89323b3eb3cSopenharmony_ci HideFilter(false); 89423b3eb3cSopenharmony_ci} 89523b3eb3cSopenharmony_ci 89623b3eb3cSopenharmony_civoid SubwindowOhos::ClearPopupNG() 89723b3eb3cSopenharmony_ci{ 89823b3eb3cSopenharmony_ci TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "clear popup ng enter"); 89923b3eb3cSopenharmony_ci auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_); 90023b3eb3cSopenharmony_ci CHECK_NULL_VOID(aceContainer); 90123b3eb3cSopenharmony_ci auto context = DynamicCast<NG::PipelineContext>(aceContainer->GetPipelineContext()); 90223b3eb3cSopenharmony_ci CHECK_NULL_VOID(context); 90323b3eb3cSopenharmony_ci auto overlay = context->GetOverlayManager(); 90423b3eb3cSopenharmony_ci CHECK_NULL_VOID(overlay); 90523b3eb3cSopenharmony_ci overlay->CleanPopupInSubWindow(); 90623b3eb3cSopenharmony_ci HideWindow(); 90723b3eb3cSopenharmony_ci context->FlushPipelineImmediately(); 90823b3eb3cSopenharmony_ci} 90923b3eb3cSopenharmony_ci 91023b3eb3cSopenharmony_civoid SubwindowOhos::ShowMenu(const RefPtr<Component>& newComponent) 91123b3eb3cSopenharmony_ci{ 91223b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_SUB_WINDOW, "show menu enter"); 91323b3eb3cSopenharmony_ci ShowWindow(); 91423b3eb3cSopenharmony_ci AddMenu(newComponent); 91523b3eb3cSopenharmony_ci} 91623b3eb3cSopenharmony_ci 91723b3eb3cSopenharmony_civoid SubwindowOhos::CloseMenu() 91823b3eb3cSopenharmony_ci{ 91923b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_SUB_WINDOW, "close menu enter"); 92023b3eb3cSopenharmony_ci#ifndef NG_BUILD 92123b3eb3cSopenharmony_ci if (!isShowed_) { 92223b3eb3cSopenharmony_ci return; 92323b3eb3cSopenharmony_ci } 92423b3eb3cSopenharmony_ci if (popup_) { 92523b3eb3cSopenharmony_ci popup_->CloseContextMenu(); 92623b3eb3cSopenharmony_ci } 92723b3eb3cSopenharmony_ci#endif 92823b3eb3cSopenharmony_ci} 92923b3eb3cSopenharmony_ci 93023b3eb3cSopenharmony_ciRefPtr<StackElement> SubwindowOhos::GetStack() 93123b3eb3cSopenharmony_ci{ 93223b3eb3cSopenharmony_ci#ifndef NG_BUILD 93323b3eb3cSopenharmony_ci auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_); 93423b3eb3cSopenharmony_ci CHECK_NULL_RETURN(aceContainer, nullptr); 93523b3eb3cSopenharmony_ci 93623b3eb3cSopenharmony_ci auto context = DynamicCast<PipelineContext>(aceContainer->GetPipelineContext()); 93723b3eb3cSopenharmony_ci CHECK_NULL_RETURN(context, nullptr); 93823b3eb3cSopenharmony_ci return context->GetLastStack(); 93923b3eb3cSopenharmony_ci#else 94023b3eb3cSopenharmony_ci return nullptr; 94123b3eb3cSopenharmony_ci#endif 94223b3eb3cSopenharmony_ci} 94323b3eb3cSopenharmony_ci 94423b3eb3cSopenharmony_civoid SubwindowOhos::DeleteHotAreas(int32_t nodeId) 94523b3eb3cSopenharmony_ci{ 94623b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_SUB_WINDOW, "delete hot area %{public}d", nodeId); 94723b3eb3cSopenharmony_ci hotAreasMap_.erase(nodeId); 94823b3eb3cSopenharmony_ci if (hotAreasMap_.size() == 0) { 94923b3eb3cSopenharmony_ci // Set min window hot area so that sub window can transparent event. 95023b3eb3cSopenharmony_ci std::vector<Rosen::Rect> hotAreas; 95123b3eb3cSopenharmony_ci Rosen::Rect rosenRect {}; 95223b3eb3cSopenharmony_ci RectConverter(MIN_WINDOW_HOT_AREA, rosenRect); 95323b3eb3cSopenharmony_ci hotAreas.emplace_back(rosenRect); 95423b3eb3cSopenharmony_ci window_->SetTouchHotAreas(hotAreas); 95523b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_SUB_WINDOW, "hotAreasMap_ has no item"); 95623b3eb3cSopenharmony_ci return; 95723b3eb3cSopenharmony_ci } 95823b3eb3cSopenharmony_ci std::vector<Rosen::Rect> hotAreas; 95923b3eb3cSopenharmony_ci for (auto it = hotAreasMap_.begin(); it != hotAreasMap_.end(); it++) { 96023b3eb3cSopenharmony_ci hotAreas.insert(hotAreas.end(), it->second.begin(), it->second.end()); 96123b3eb3cSopenharmony_ci } 96223b3eb3cSopenharmony_ci CHECK_NULL_VOID(window_); 96323b3eb3cSopenharmony_ci window_->SetTouchHotAreas(hotAreas); 96423b3eb3cSopenharmony_ci} 96523b3eb3cSopenharmony_ci 96623b3eb3cSopenharmony_civoid SubwindowOhos::SetHotAreas(const std::vector<Rect>& rects, int32_t nodeId) 96723b3eb3cSopenharmony_ci{ 96823b3eb3cSopenharmony_ci TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "set hot areas enter"); 96923b3eb3cSopenharmony_ci CHECK_NULL_VOID(window_); 97023b3eb3cSopenharmony_ci 97123b3eb3cSopenharmony_ci std::vector<Rosen::Rect> hotAreas; 97223b3eb3cSopenharmony_ci Rosen::Rect rosenRect {}; 97323b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_SUB_WINDOW, "set hot area %{public}d", nodeId); 97423b3eb3cSopenharmony_ci for (const auto& rect : rects) { 97523b3eb3cSopenharmony_ci TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "set hot area rect %{public}s", rect.ToString().c_str()); 97623b3eb3cSopenharmony_ci RectConverter(rect, rosenRect); 97723b3eb3cSopenharmony_ci hotAreas.emplace_back(rosenRect); 97823b3eb3cSopenharmony_ci } 97923b3eb3cSopenharmony_ci if (nodeId >= 0) { 98023b3eb3cSopenharmony_ci hotAreasMap_[nodeId] = hotAreas; 98123b3eb3cSopenharmony_ci } 98223b3eb3cSopenharmony_ci 98323b3eb3cSopenharmony_ci std::vector<Rosen::Rect> hotAreasNow; 98423b3eb3cSopenharmony_ci for (auto it = hotAreasMap_.begin(); it != hotAreasMap_.end(); it++) { 98523b3eb3cSopenharmony_ci hotAreasNow.insert(hotAreasNow.end(), it->second.begin(), it->second.end()); 98623b3eb3cSopenharmony_ci } 98723b3eb3cSopenharmony_ci window_->SetTouchHotAreas(hotAreasNow); 98823b3eb3cSopenharmony_ci} 98923b3eb3cSopenharmony_ci 99023b3eb3cSopenharmony_civoid SubwindowOhos::RectConverter(const Rect& rect, Rosen::Rect& rosenRect) 99123b3eb3cSopenharmony_ci{ 99223b3eb3cSopenharmony_ci rosenRect.posX_ = static_cast<int>(rect.GetOffset().GetX()); 99323b3eb3cSopenharmony_ci rosenRect.posY_ = static_cast<int>(rect.GetOffset().GetY()); 99423b3eb3cSopenharmony_ci rosenRect.width_ = static_cast<uint32_t>(rect.GetSize().Width()); 99523b3eb3cSopenharmony_ci rosenRect.height_ = static_cast<uint32_t>(rect.GetSize().Height()); 99623b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_SUB_WINDOW, 99723b3eb3cSopenharmony_ci "Convert rect to rosenRect, x is %{public}d, y is %{public}d, width is %{public}d, height is %{public}d", 99823b3eb3cSopenharmony_ci rosenRect.posX_, rosenRect.posY_, rosenRect.width_, rosenRect.height_); 99923b3eb3cSopenharmony_ci} 100023b3eb3cSopenharmony_ci 100123b3eb3cSopenharmony_ciRefPtr<NG::FrameNode> SubwindowOhos::ShowDialogNG( 100223b3eb3cSopenharmony_ci const DialogProperties& dialogProps, std::function<void()>&& buildFunc) 100323b3eb3cSopenharmony_ci{ 100423b3eb3cSopenharmony_ci TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "show dialog ng enter"); 100523b3eb3cSopenharmony_ci auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_); 100623b3eb3cSopenharmony_ci CHECK_NULL_RETURN(aceContainer, nullptr); 100723b3eb3cSopenharmony_ci auto context = DynamicCast<NG::PipelineContext>(aceContainer->GetPipelineContext()); 100823b3eb3cSopenharmony_ci CHECK_NULL_RETURN(context, nullptr); 100923b3eb3cSopenharmony_ci auto overlay = context->GetOverlayManager(); 101023b3eb3cSopenharmony_ci CHECK_NULL_RETURN(overlay, nullptr); 101123b3eb3cSopenharmony_ci std::map<int32_t, RefPtr<NG::FrameNode>> DialogMap(overlay->GetDialogMap().begin(), overlay->GetDialogMap().end()); 101223b3eb3cSopenharmony_ci int dialogMapSize = static_cast<int>(DialogMap.size()); 101323b3eb3cSopenharmony_ci if (dialogMapSize == 0) { 101423b3eb3cSopenharmony_ci auto parentAceContainer = Platform::AceContainer::GetContainer(parentContainerId_); 101523b3eb3cSopenharmony_ci CHECK_NULL_RETURN(parentAceContainer, nullptr); 101623b3eb3cSopenharmony_ci auto parentcontext = DynamicCast<NG::PipelineContext>(parentAceContainer->GetPipelineContext()); 101723b3eb3cSopenharmony_ci CHECK_NULL_RETURN(parentcontext, nullptr); 101823b3eb3cSopenharmony_ci auto parentOverlay = parentcontext->GetOverlayManager(); 101923b3eb3cSopenharmony_ci CHECK_NULL_RETURN(parentOverlay, nullptr); 102023b3eb3cSopenharmony_ci parentOverlay->SetSubWindowId(SubwindowManager::GetInstance()->GetDialogSubwindowInstanceId(GetSubwindowId())); 102123b3eb3cSopenharmony_ci } 102223b3eb3cSopenharmony_ci ResizeWindow(); 102323b3eb3cSopenharmony_ci ShowWindow(); 102423b3eb3cSopenharmony_ci CHECK_NULL_RETURN(window_, nullptr); 102523b3eb3cSopenharmony_ci window_->SetFullScreen(true); 102623b3eb3cSopenharmony_ci window_->SetTouchable(true); 102723b3eb3cSopenharmony_ci ContainerScope scope(childContainerId_); 102823b3eb3cSopenharmony_ci auto dialog = overlay->ShowDialog(dialogProps, std::move(buildFunc)); 102923b3eb3cSopenharmony_ci CHECK_NULL_RETURN(dialog, nullptr); 103023b3eb3cSopenharmony_ci haveDialog_ = true; 103123b3eb3cSopenharmony_ci return dialog; 103223b3eb3cSopenharmony_ci} 103323b3eb3cSopenharmony_ci 103423b3eb3cSopenharmony_ciRefPtr<NG::FrameNode> SubwindowOhos::ShowDialogNGWithNode( 103523b3eb3cSopenharmony_ci const DialogProperties& dialogProps, const RefPtr<NG::UINode>& customNode) 103623b3eb3cSopenharmony_ci{ 103723b3eb3cSopenharmony_ci TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "show dialog ng enter"); 103823b3eb3cSopenharmony_ci auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_); 103923b3eb3cSopenharmony_ci CHECK_NULL_RETURN(aceContainer, nullptr); 104023b3eb3cSopenharmony_ci auto context = DynamicCast<NG::PipelineContext>(aceContainer->GetPipelineContext()); 104123b3eb3cSopenharmony_ci CHECK_NULL_RETURN(context, nullptr); 104223b3eb3cSopenharmony_ci auto overlay = context->GetOverlayManager(); 104323b3eb3cSopenharmony_ci CHECK_NULL_RETURN(overlay, nullptr); 104423b3eb3cSopenharmony_ci std::map<int32_t, RefPtr<NG::FrameNode>> DialogMap(overlay->GetDialogMap().begin(), overlay->GetDialogMap().end()); 104523b3eb3cSopenharmony_ci int dialogMapSize = static_cast<int>(DialogMap.size()); 104623b3eb3cSopenharmony_ci if (dialogMapSize == 0) { 104723b3eb3cSopenharmony_ci auto parentAceContainer = Platform::AceContainer::GetContainer(parentContainerId_); 104823b3eb3cSopenharmony_ci CHECK_NULL_RETURN(parentAceContainer, nullptr); 104923b3eb3cSopenharmony_ci auto parentcontext = DynamicCast<NG::PipelineContext>(parentAceContainer->GetPipelineContext()); 105023b3eb3cSopenharmony_ci CHECK_NULL_RETURN(parentcontext, nullptr); 105123b3eb3cSopenharmony_ci auto parentOverlay = parentcontext->GetOverlayManager(); 105223b3eb3cSopenharmony_ci CHECK_NULL_RETURN(parentOverlay, nullptr); 105323b3eb3cSopenharmony_ci parentOverlay->SetSubWindowId(SubwindowManager::GetInstance()->GetDialogSubwindowInstanceId(GetSubwindowId())); 105423b3eb3cSopenharmony_ci } 105523b3eb3cSopenharmony_ci ResizeWindow(); 105623b3eb3cSopenharmony_ci ShowWindow(); 105723b3eb3cSopenharmony_ci CHECK_NULL_RETURN(window_, nullptr); 105823b3eb3cSopenharmony_ci window_->SetFullScreen(true); 105923b3eb3cSopenharmony_ci window_->SetTouchable(true); 106023b3eb3cSopenharmony_ci ContainerScope scope(childContainerId_); 106123b3eb3cSopenharmony_ci auto dialog = overlay->ShowDialogWithNode(dialogProps, customNode); 106223b3eb3cSopenharmony_ci CHECK_NULL_RETURN(dialog, nullptr); 106323b3eb3cSopenharmony_ci haveDialog_ = true; 106423b3eb3cSopenharmony_ci return dialog; 106523b3eb3cSopenharmony_ci} 106623b3eb3cSopenharmony_ci 106723b3eb3cSopenharmony_civoid SubwindowOhos::CloseDialogNG(const RefPtr<NG::FrameNode>& dialogNode) 106823b3eb3cSopenharmony_ci{ 106923b3eb3cSopenharmony_ci TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "close dialog ng enter"); 107023b3eb3cSopenharmony_ci auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_); 107123b3eb3cSopenharmony_ci CHECK_NULL_VOID(aceContainer); 107223b3eb3cSopenharmony_ci auto context = DynamicCast<NG::PipelineContext>(aceContainer->GetPipelineContext()); 107323b3eb3cSopenharmony_ci CHECK_NULL_VOID(context); 107423b3eb3cSopenharmony_ci auto overlay = context->GetOverlayManager(); 107523b3eb3cSopenharmony_ci CHECK_NULL_VOID(overlay); 107623b3eb3cSopenharmony_ci ContainerScope scope(childContainerId_); 107723b3eb3cSopenharmony_ci return overlay->CloseDialog(dialogNode); 107823b3eb3cSopenharmony_ci} 107923b3eb3cSopenharmony_ci 108023b3eb3cSopenharmony_civoid SubwindowOhos::OpenCustomDialogNG(const DialogProperties& dialogProps, std::function<void(int32_t)>&& callback) 108123b3eb3cSopenharmony_ci{ 108223b3eb3cSopenharmony_ci TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "open customDialog ng subwindow enter"); 108323b3eb3cSopenharmony_ci auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_); 108423b3eb3cSopenharmony_ci CHECK_NULL_VOID(aceContainer); 108523b3eb3cSopenharmony_ci auto context = DynamicCast<NG::PipelineContext>(aceContainer->GetPipelineContext()); 108623b3eb3cSopenharmony_ci CHECK_NULL_VOID(context); 108723b3eb3cSopenharmony_ci auto overlay = context->GetOverlayManager(); 108823b3eb3cSopenharmony_ci CHECK_NULL_VOID(overlay); 108923b3eb3cSopenharmony_ci std::map<int32_t, RefPtr<NG::FrameNode>> DialogMap(overlay->GetDialogMap().begin(), overlay->GetDialogMap().end()); 109023b3eb3cSopenharmony_ci int dialogMapSize = static_cast<int>(DialogMap.size()); 109123b3eb3cSopenharmony_ci if (dialogMapSize == 0) { 109223b3eb3cSopenharmony_ci auto parentAceContainer = Platform::AceContainer::GetContainer(parentContainerId_); 109323b3eb3cSopenharmony_ci CHECK_NULL_VOID(parentAceContainer); 109423b3eb3cSopenharmony_ci auto parentcontext = DynamicCast<NG::PipelineContext>(parentAceContainer->GetPipelineContext()); 109523b3eb3cSopenharmony_ci CHECK_NULL_VOID(parentcontext); 109623b3eb3cSopenharmony_ci auto parentOverlay = parentcontext->GetOverlayManager(); 109723b3eb3cSopenharmony_ci CHECK_NULL_VOID(parentOverlay); 109823b3eb3cSopenharmony_ci parentOverlay->SetSubWindowId(SubwindowManager::GetInstance()->GetDialogSubwindowInstanceId(GetSubwindowId())); 109923b3eb3cSopenharmony_ci TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "overlay in parent container %{public}d, SetSubWindowId %{public}d", 110023b3eb3cSopenharmony_ci parentContainerId_, GetSubwindowId()); 110123b3eb3cSopenharmony_ci } 110223b3eb3cSopenharmony_ci ResizeWindow(); 110323b3eb3cSopenharmony_ci ShowWindow(); 110423b3eb3cSopenharmony_ci CHECK_NULL_VOID(window_); 110523b3eb3cSopenharmony_ci window_->SetFullScreen(true); 110623b3eb3cSopenharmony_ci window_->SetTouchable(true); 110723b3eb3cSopenharmony_ci ContainerScope scope(childContainerId_); 110823b3eb3cSopenharmony_ci overlay->OpenCustomDialog(dialogProps, std::move(callback)); 110923b3eb3cSopenharmony_ci haveDialog_ = true; 111023b3eb3cSopenharmony_ci} 111123b3eb3cSopenharmony_ci 111223b3eb3cSopenharmony_civoid SubwindowOhos::CloseCustomDialogNG(int32_t dialogId) 111323b3eb3cSopenharmony_ci{ 111423b3eb3cSopenharmony_ci TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "close customDialog ng subwindow enter, child container id %{public}d", 111523b3eb3cSopenharmony_ci childContainerId_); 111623b3eb3cSopenharmony_ci auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_); 111723b3eb3cSopenharmony_ci CHECK_NULL_VOID(aceContainer); 111823b3eb3cSopenharmony_ci auto context = DynamicCast<NG::PipelineContext>(aceContainer->GetPipelineContext()); 111923b3eb3cSopenharmony_ci CHECK_NULL_VOID(context); 112023b3eb3cSopenharmony_ci auto overlay = context->GetOverlayManager(); 112123b3eb3cSopenharmony_ci CHECK_NULL_VOID(overlay); 112223b3eb3cSopenharmony_ci ContainerScope scope(childContainerId_); 112323b3eb3cSopenharmony_ci return overlay->CloseCustomDialog(dialogId); 112423b3eb3cSopenharmony_ci} 112523b3eb3cSopenharmony_ci 112623b3eb3cSopenharmony_civoid SubwindowOhos::CloseCustomDialogNG(const WeakPtr<NG::UINode>& node, std::function<void(int32_t)>&& callback) 112723b3eb3cSopenharmony_ci{ 112823b3eb3cSopenharmony_ci TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "close customDialog ng subwindow enter, child container id %{public}d", 112923b3eb3cSopenharmony_ci childContainerId_); 113023b3eb3cSopenharmony_ci auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_); 113123b3eb3cSopenharmony_ci CHECK_NULL_VOID(aceContainer); 113223b3eb3cSopenharmony_ci auto context = DynamicCast<NG::PipelineContext>(aceContainer->GetPipelineContext()); 113323b3eb3cSopenharmony_ci CHECK_NULL_VOID(context); 113423b3eb3cSopenharmony_ci auto overlay = context->GetOverlayManager(); 113523b3eb3cSopenharmony_ci CHECK_NULL_VOID(overlay); 113623b3eb3cSopenharmony_ci ContainerScope scope(childContainerId_); 113723b3eb3cSopenharmony_ci return overlay->CloseCustomDialog(node, std::move(callback)); 113823b3eb3cSopenharmony_ci} 113923b3eb3cSopenharmony_ci 114023b3eb3cSopenharmony_civoid SubwindowOhos::UpdateCustomDialogNG( 114123b3eb3cSopenharmony_ci const WeakPtr<NG::UINode>& node, const DialogProperties& dialogProps, std::function<void(int32_t)>&& callback) 114223b3eb3cSopenharmony_ci{ 114323b3eb3cSopenharmony_ci TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "update customDialog ng subwindow enter"); 114423b3eb3cSopenharmony_ci auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_); 114523b3eb3cSopenharmony_ci CHECK_NULL_VOID(aceContainer); 114623b3eb3cSopenharmony_ci auto context = DynamicCast<NG::PipelineContext>(aceContainer->GetPipelineContext()); 114723b3eb3cSopenharmony_ci CHECK_NULL_VOID(context); 114823b3eb3cSopenharmony_ci auto overlay = context->GetOverlayManager(); 114923b3eb3cSopenharmony_ci CHECK_NULL_VOID(overlay); 115023b3eb3cSopenharmony_ci ContainerScope scope(childContainerId_); 115123b3eb3cSopenharmony_ci return overlay->UpdateCustomDialog(node, dialogProps, std::move(callback)); 115223b3eb3cSopenharmony_ci} 115323b3eb3cSopenharmony_ci 115423b3eb3cSopenharmony_civoid SubwindowOhos::HideSubWindowNG() 115523b3eb3cSopenharmony_ci{ 115623b3eb3cSopenharmony_ci ContainerScope scope(childContainerId_); 115723b3eb3cSopenharmony_ci auto container = Container::Current(); 115823b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 115923b3eb3cSopenharmony_ci if (container->IsDialogContainer()) { 116023b3eb3cSopenharmony_ci if (IsToastWindow()) { 116123b3eb3cSopenharmony_ci Platform::DialogContainer::HideWindow(Container::CurrentId()); 116223b3eb3cSopenharmony_ci } else { 116323b3eb3cSopenharmony_ci Platform::DialogContainer::CloseWindow(Container::CurrentId()); 116423b3eb3cSopenharmony_ci Platform::DialogContainer::DestroyContainer(Container::CurrentId()); 116523b3eb3cSopenharmony_ci } 116623b3eb3cSopenharmony_ci } else { 116723b3eb3cSopenharmony_ci HideWindow(); 116823b3eb3cSopenharmony_ci } 116923b3eb3cSopenharmony_ci} 117023b3eb3cSopenharmony_ci 117123b3eb3cSopenharmony_civoid SubwindowOhos::GetToastDialogWindowProperty( 117223b3eb3cSopenharmony_ci int32_t& width, int32_t& height, int32_t& posX, int32_t& posY, float& density) const 117323b3eb3cSopenharmony_ci{ 117423b3eb3cSopenharmony_ci TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "get toast dialog window property enter"); 117523b3eb3cSopenharmony_ci auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay(); 117623b3eb3cSopenharmony_ci if (defaultDisplay) { 117723b3eb3cSopenharmony_ci posX = 0; 117823b3eb3cSopenharmony_ci posY = 0; 117923b3eb3cSopenharmony_ci width = defaultDisplay->GetWidth(); 118023b3eb3cSopenharmony_ci height = defaultDisplay->GetHeight(); 118123b3eb3cSopenharmony_ci density = defaultDisplay->GetVirtualPixelRatio(); 118223b3eb3cSopenharmony_ci } 118323b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_SUB_WINDOW, 118423b3eb3cSopenharmony_ci "Toast posX: %{public}d, posY: %{public}d, width: %{public}d, height: %{public}d, density: %{public}f", posX, 118523b3eb3cSopenharmony_ci posY, width, height, density); 118623b3eb3cSopenharmony_ci} 118723b3eb3cSopenharmony_ci 118823b3eb3cSopenharmony_cibool SubwindowOhos::InitToastDialogWindow(int32_t width, int32_t height, int32_t posX, int32_t posY, bool isToast) 118923b3eb3cSopenharmony_ci{ 119023b3eb3cSopenharmony_ci TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "init toast dialog window enter"); 119123b3eb3cSopenharmony_ci OHOS::sptr<OHOS::Rosen::WindowOption> windowOption = new OHOS::Rosen::WindowOption(); 119223b3eb3cSopenharmony_ci if (isToast) { 119323b3eb3cSopenharmony_ci auto windowType = 119423b3eb3cSopenharmony_ci IsSystemTopMost() ? Rosen::WindowType::WINDOW_TYPE_SYSTEM_TOAST : Rosen::WindowType::WINDOW_TYPE_TOAST; 119523b3eb3cSopenharmony_ci windowOption->SetWindowType(windowType); 119623b3eb3cSopenharmony_ci } else { 119723b3eb3cSopenharmony_ci windowOption->SetWindowType(Rosen::WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); 119823b3eb3cSopenharmony_ci } 119923b3eb3cSopenharmony_ci windowOption->SetWindowRect({ posX, posY, width, height }); 120023b3eb3cSopenharmony_ci windowOption->SetWindowMode(Rosen::WindowMode::WINDOW_MODE_FULLSCREEN); 120123b3eb3cSopenharmony_ci windowOption->SetFocusable(!isToast); 120223b3eb3cSopenharmony_ci int32_t dialogId = gToastDialogId.fetch_add(1, std::memory_order_relaxed); 120323b3eb3cSopenharmony_ci std::string windowName = "ARK_APP_SUBWINDOW_TOAST_DIALOG_" + std::to_string(dialogId); 120423b3eb3cSopenharmony_ci if (isToast) { 120523b3eb3cSopenharmony_ci auto context = OHOS::AbilityRuntime::Context::GetApplicationContext(); 120623b3eb3cSopenharmony_ci dialogWindow_ = OHOS::Rosen::Window::Create(windowName, windowOption, context); 120723b3eb3cSopenharmony_ci } else { 120823b3eb3cSopenharmony_ci dialogWindow_ = OHOS::Rosen::Window::Create(windowName, windowOption); 120923b3eb3cSopenharmony_ci } 121023b3eb3cSopenharmony_ci CHECK_NULL_RETURN(dialogWindow_, false); 121123b3eb3cSopenharmony_ci dialogWindow_->SetLayoutFullScreen(true); 121223b3eb3cSopenharmony_ci return true; 121323b3eb3cSopenharmony_ci} 121423b3eb3cSopenharmony_ci 121523b3eb3cSopenharmony_cibool SubwindowOhos::InitToastDialogView(int32_t width, int32_t height, float density) 121623b3eb3cSopenharmony_ci{ 121723b3eb3cSopenharmony_ci TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "init toast dialog view enter"); 121823b3eb3cSopenharmony_ci#ifndef NG_BUILD 121923b3eb3cSopenharmony_ci dialogWindow_->NapiSetUIContent("", nullptr, nullptr, Rosen::BackupAndRestoreType::NONE); 122023b3eb3cSopenharmony_ci childContainerId_ = SubwindowManager::GetInstance()->GetContainerId(dialogWindow_->GetWindowId()); 122123b3eb3cSopenharmony_ci SubwindowManager::GetInstance()->AddParentContainerId(childContainerId_, parentContainerId_); 122223b3eb3cSopenharmony_ci ContainerScope scope(childContainerId_); 122323b3eb3cSopenharmony_ci 122423b3eb3cSopenharmony_ci auto container = Platform::DialogContainer::GetContainer(childContainerId_); 122523b3eb3cSopenharmony_ci CHECK_NULL_RETURN(container, false); 122623b3eb3cSopenharmony_ci // create ace_view 122723b3eb3cSopenharmony_ci auto aceView = Platform::AceViewOhos::CreateView(childContainerId_, true, true); 122823b3eb3cSopenharmony_ci Platform::AceViewOhos::SurfaceCreated(aceView, dialogWindow_); 122923b3eb3cSopenharmony_ci // set view 123023b3eb3cSopenharmony_ci Platform::DialogContainer::SetView(aceView, density, width, height, dialogWindow_); 123123b3eb3cSopenharmony_ci Ace::Platform::DialogContainer::SetUIWindow(childContainerId_, dialogWindow_); 123223b3eb3cSopenharmony_ci ViewportConfig config(width, height, density); 123323b3eb3cSopenharmony_ci Platform::AceViewOhos::SetViewportMetrics(aceView, config); 123423b3eb3cSopenharmony_ci Platform::AceViewOhos::SurfaceChanged(aceView, width, height, 0); 123523b3eb3cSopenharmony_ci 123623b3eb3cSopenharmony_ci#ifdef ENABLE_ROSEN_BACKEND 123723b3eb3cSopenharmony_ci if (SystemProperties::GetRosenBackendEnabled()) { 123823b3eb3cSopenharmony_ci rsUiDirector = OHOS::Rosen::RSUIDirector::Create(); 123923b3eb3cSopenharmony_ci if (rsUiDirector != nullptr) { 124023b3eb3cSopenharmony_ci rsUiDirector->SetRSSurfaceNode(dialogWindow_->GetSurfaceNode()); 124123b3eb3cSopenharmony_ci auto context = DynamicCast<PipelineContext>(container->GetPipelineContext()); 124223b3eb3cSopenharmony_ci if (context != nullptr) { 124323b3eb3cSopenharmony_ci context->SetRSUIDirector(rsUiDirector); 124423b3eb3cSopenharmony_ci } 124523b3eb3cSopenharmony_ci rsUiDirector->Init(); 124623b3eb3cSopenharmony_ci } 124723b3eb3cSopenharmony_ci } 124823b3eb3cSopenharmony_ci#endif 124923b3eb3cSopenharmony_ci 125023b3eb3cSopenharmony_ci auto pipelineContext = container->GetPipelineContext(); 125123b3eb3cSopenharmony_ci CHECK_NULL_RETURN(pipelineContext, false); 125223b3eb3cSopenharmony_ci pipelineContext->SetupRootElement(); 125323b3eb3cSopenharmony_ci auto parentContainer = Platform::AceContainer::GetContainer(parentContainerId_); 125423b3eb3cSopenharmony_ci if (parentContainer) { 125523b3eb3cSopenharmony_ci auto parentPipeline = parentContainer->GetPipelineContext(); 125623b3eb3cSopenharmony_ci CHECK_NULL_RETURN(parentPipeline, false); 125723b3eb3cSopenharmony_ci pipelineContext->SetMinPlatformVersion(parentPipeline->GetMinPlatformVersion()); 125823b3eb3cSopenharmony_ci } else { 125923b3eb3cSopenharmony_ci pipelineContext->SetMinPlatformVersion(PLATFORM_VERSION_TEN); 126023b3eb3cSopenharmony_ci } 126123b3eb3cSopenharmony_ci return true; 126223b3eb3cSopenharmony_ci#else 126323b3eb3cSopenharmony_ci return true; 126423b3eb3cSopenharmony_ci#endif 126523b3eb3cSopenharmony_ci} 126623b3eb3cSopenharmony_ci 126723b3eb3cSopenharmony_cibool SubwindowOhos::InitToastServiceConfig() 126823b3eb3cSopenharmony_ci{ 126923b3eb3cSopenharmony_ci auto context = OHOS::AbilityRuntime::Context::GetApplicationContext(); 127023b3eb3cSopenharmony_ci CHECK_NULL_RETURN(context, false); 127123b3eb3cSopenharmony_ci auto config = context->GetConfiguration(); 127223b3eb3cSopenharmony_ci CHECK_NULL_RETURN(config, false); 127323b3eb3cSopenharmony_ci auto maxAppFontScale = config->GetItem(OHOS::AAFwk::GlobalConfigurationKey::APP_FONT_MAX_SCALE); 127423b3eb3cSopenharmony_ci auto followSystem = config->GetItem(OHOS::AAFwk::GlobalConfigurationKey::APP_FONT_SIZE_SCALE); 127523b3eb3cSopenharmony_ci auto container = Platform::DialogContainer::GetContainer(childContainerId_); 127623b3eb3cSopenharmony_ci CHECK_NULL_RETURN(container, false); 127723b3eb3cSopenharmony_ci auto pipelineContext = container->GetPipelineContext(); 127823b3eb3cSopenharmony_ci CHECK_NULL_RETURN(pipelineContext, false); 127923b3eb3cSopenharmony_ci auto isFollowSystem = followSystem == "followSystem"; 128023b3eb3cSopenharmony_ci if (!followSystem.empty()) { 128123b3eb3cSopenharmony_ci pipelineContext->SetFollowSystem(isFollowSystem); 128223b3eb3cSopenharmony_ci } 128323b3eb3cSopenharmony_ci if (!maxAppFontScale.empty()) { 128423b3eb3cSopenharmony_ci pipelineContext->SetMaxAppFontScale(StringUtils::StringToFloat(maxAppFontScale)); 128523b3eb3cSopenharmony_ci } 128623b3eb3cSopenharmony_ci if (!isFollowSystem) { 128723b3eb3cSopenharmony_ci pipelineContext->SetFontScale(1.0f); 128823b3eb3cSopenharmony_ci } 128923b3eb3cSopenharmony_ci auto fontScale = config->GetItem(OHOS::AAFwk::GlobalConfigurationKey::SYSTEM_FONT_SIZE_SCALE); 129023b3eb3cSopenharmony_ci if (!fontScale.empty()) { 129123b3eb3cSopenharmony_ci pipelineContext->SetFontScale(StringUtils::StringToFloat(fontScale)); 129223b3eb3cSopenharmony_ci } 129323b3eb3cSopenharmony_ci 129423b3eb3cSopenharmony_ci return true; 129523b3eb3cSopenharmony_ci} 129623b3eb3cSopenharmony_ci 129723b3eb3cSopenharmony_cibool SubwindowOhos::CreateEventRunner() 129823b3eb3cSopenharmony_ci{ 129923b3eb3cSopenharmony_ci if (!eventLoop_) { 130023b3eb3cSopenharmony_ci eventLoop_ = AppExecFwk::EventRunner::Create("Subwindow_Toast_Dialog"); 130123b3eb3cSopenharmony_ci CHECK_NULL_RETURN(eventLoop_, false); 130223b3eb3cSopenharmony_ci handler_ = std::make_shared<AppExecFwk::EventHandler>(eventLoop_); 130323b3eb3cSopenharmony_ci CHECK_NULL_RETURN(handler_, false); 130423b3eb3cSopenharmony_ci } 130523b3eb3cSopenharmony_ci return true; 130623b3eb3cSopenharmony_ci} 130723b3eb3cSopenharmony_ci 130823b3eb3cSopenharmony_civoid SubwindowOhos::ClearToast() 130923b3eb3cSopenharmony_ci{ 131023b3eb3cSopenharmony_ci TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "clear toast enter"); 131123b3eb3cSopenharmony_ci if (!IsToastWindow()) { 131223b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, "default toast needs not to be clear"); 131323b3eb3cSopenharmony_ci return; 131423b3eb3cSopenharmony_ci } 131523b3eb3cSopenharmony_ci auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_); 131623b3eb3cSopenharmony_ci CHECK_NULL_VOID(aceContainer); 131723b3eb3cSopenharmony_ci auto context = DynamicCast<NG::PipelineContext>(aceContainer->GetPipelineContext()); 131823b3eb3cSopenharmony_ci CHECK_NULL_VOID(context); 131923b3eb3cSopenharmony_ci auto overlayManager = context->GetOverlayManager(); 132023b3eb3cSopenharmony_ci CHECK_NULL_VOID(overlayManager); 132123b3eb3cSopenharmony_ci ContainerScope scope(childContainerId_); 132223b3eb3cSopenharmony_ci overlayManager->ClearToast(); 132323b3eb3cSopenharmony_ci context->FlushPipelineImmediately(); 132423b3eb3cSopenharmony_ci HideWindow(); 132523b3eb3cSopenharmony_ci} 132623b3eb3cSopenharmony_ci 132723b3eb3cSopenharmony_civoid SubwindowOhos::ShowToastForAbility(const NG::ToastInfo& toastInfo, std::function<void(int32_t)>&& callback) 132823b3eb3cSopenharmony_ci{ 132923b3eb3cSopenharmony_ci TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "show toast for ability enter, containerId : %{public}d", childContainerId_); 133023b3eb3cSopenharmony_ci SetIsToastWindow( 133123b3eb3cSopenharmony_ci toastInfo.showMode == NG::ToastShowMode::TOP_MOST || toastInfo.showMode == NG::ToastShowMode::SYSTEM_TOP_MOST); 133223b3eb3cSopenharmony_ci auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_); 133323b3eb3cSopenharmony_ci if (!aceContainer) { 133423b3eb3cSopenharmony_ci TAG_LOGE(AceLogTag::ACE_SUB_WINDOW, "get container failed, child containerId : %{public}d", childContainerId_); 133523b3eb3cSopenharmony_ci return; 133623b3eb3cSopenharmony_ci } 133723b3eb3cSopenharmony_ci 133823b3eb3cSopenharmony_ci auto engine = EngineHelper::GetEngine(aceContainer->GetInstanceId()); 133923b3eb3cSopenharmony_ci RefPtr<Framework::FrontendDelegate> delegate; 134023b3eb3cSopenharmony_ci if (!engine) { 134123b3eb3cSopenharmony_ci auto frontend = AceType::DynamicCast<DeclarativeFrontend>(aceContainer->GetFrontend()); 134223b3eb3cSopenharmony_ci CHECK_NULL_VOID(frontend); 134323b3eb3cSopenharmony_ci delegate = frontend->GetDelegate(); 134423b3eb3cSopenharmony_ci if (!delegate) { 134523b3eb3cSopenharmony_ci TAG_LOGE(AceLogTag::ACE_SUB_WINDOW, "get engine failed, containerId : %{public}d", 134623b3eb3cSopenharmony_ci aceContainer->GetInstanceId()); 134723b3eb3cSopenharmony_ci return; 134823b3eb3cSopenharmony_ci } 134923b3eb3cSopenharmony_ci } else { 135023b3eb3cSopenharmony_ci delegate = engine->GetFrontend(); 135123b3eb3cSopenharmony_ci if (!delegate) { 135223b3eb3cSopenharmony_ci TAG_LOGE(AceLogTag::ACE_SUB_WINDOW, "get frontend failed, child containerId : %{public}d", 135323b3eb3cSopenharmony_ci childContainerId_); 135423b3eb3cSopenharmony_ci return; 135523b3eb3cSopenharmony_ci } 135623b3eb3cSopenharmony_ci } 135723b3eb3cSopenharmony_ci ContainerScope scope(childContainerId_); 135823b3eb3cSopenharmony_ci auto parentContainer = Platform::AceContainer::GetContainer(parentContainerId_); 135923b3eb3cSopenharmony_ci CHECK_NULL_VOID(parentContainer); 136023b3eb3cSopenharmony_ci if (parentContainer->IsScenceBoardWindow() || toastInfo.showMode == NG::ToastShowMode::TOP_MOST || 136123b3eb3cSopenharmony_ci toastInfo.showMode == NG::ToastShowMode::SYSTEM_TOP_MOST) { 136223b3eb3cSopenharmony_ci ResizeWindow(); 136323b3eb3cSopenharmony_ci // Recover current subwindow in subwindow manager to ensure popup/menu can close the right subwindow 136423b3eb3cSopenharmony_ci auto currentWindow = SubwindowManager::GetInstance()->GetCurrentWindow(); 136523b3eb3cSopenharmony_ci ShowWindow(false); 136623b3eb3cSopenharmony_ci SubwindowManager::GetInstance()->SetCurrentSubwindow(currentWindow); 136723b3eb3cSopenharmony_ci CHECK_NULL_VOID(window_); 136823b3eb3cSopenharmony_ci window_->SetTouchable(false); 136923b3eb3cSopenharmony_ci } 137023b3eb3cSopenharmony_ci delegate->ShowToast(toastInfo, std::move(callback)); 137123b3eb3cSopenharmony_ci} 137223b3eb3cSopenharmony_ci 137323b3eb3cSopenharmony_civoid SubwindowOhos::ShowToastForService(const NG::ToastInfo& toastInfo, std::function<void(int32_t)>&& callback) 137423b3eb3cSopenharmony_ci{ 137523b3eb3cSopenharmony_ci bool ret = CreateEventRunner(); 137623b3eb3cSopenharmony_ci if (!ret) { 137723b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, "create event runner failed"); 137823b3eb3cSopenharmony_ci return; 137923b3eb3cSopenharmony_ci } 138023b3eb3cSopenharmony_ci 138123b3eb3cSopenharmony_ci SubwindowManager::GetInstance()->SetCurrentDialogSubwindow(AceType::Claim(this)); 138223b3eb3cSopenharmony_ci if (!handler_->PostTask(GetInitToastDelayTask(toastInfo, std::move(callback)))) { 138323b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, "create show dialog callback failed"); 138423b3eb3cSopenharmony_ci return; 138523b3eb3cSopenharmony_ci } 138623b3eb3cSopenharmony_ci} 138723b3eb3cSopenharmony_ci 138823b3eb3cSopenharmony_civoid SubwindowOhos::ShowToast(const NG::ToastInfo& toastInfo, std::function<void(int32_t)>&& callback) 138923b3eb3cSopenharmony_ci{ 139023b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_SUB_WINDOW, "show toast, window parent id is %{public}d", parentContainerId_); 139123b3eb3cSopenharmony_ci auto isTopMost = toastInfo.showMode == NG::ToastShowMode::TOP_MOST; 139223b3eb3cSopenharmony_ci // for pa service 139323b3eb3cSopenharmony_ci if ((isTopMost && parentContainerId_ >= MIN_PA_SERVICE_ID && parentContainerId_ < MIN_SUBCONTAINER_ID) || 139423b3eb3cSopenharmony_ci (!isTopMost && parentContainerId_ >= MIN_PA_SERVICE_ID) || parentContainerId_ < 0) { 139523b3eb3cSopenharmony_ci ShowToastForService(toastInfo, std::move(callback)); 139623b3eb3cSopenharmony_ci } else { 139723b3eb3cSopenharmony_ci ShowToastForAbility(toastInfo, std::move(callback)); 139823b3eb3cSopenharmony_ci } 139923b3eb3cSopenharmony_ci} 140023b3eb3cSopenharmony_ci 140123b3eb3cSopenharmony_civoid SubwindowOhos::CloseToast(const int32_t toastId, std::function<void(int32_t)>&& callback) 140223b3eb3cSopenharmony_ci{ 140323b3eb3cSopenharmony_ci TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "close toast enter"); 140423b3eb3cSopenharmony_ci if (parentContainerId_ >= MIN_PA_SERVICE_ID || parentContainerId_ < 0) { 140523b3eb3cSopenharmony_ci auto subwindowOhos = 140623b3eb3cSopenharmony_ci AceType::DynamicCast<SubwindowOhos>(SubwindowManager::GetInstance()->GetCurrentDialogWindow()); 140723b3eb3cSopenharmony_ci CHECK_NULL_VOID(subwindowOhos); 140823b3eb3cSopenharmony_ci auto childContainerId = subwindowOhos->GetChildContainerId(); 140923b3eb3cSopenharmony_ci CHECK_NULL_VOID(childContainerId); 141023b3eb3cSopenharmony_ci ContainerScope scope(childContainerId); 141123b3eb3cSopenharmony_ci Platform::DialogContainer::CloseToast(childContainerId, toastId, std::move(callback)); 141223b3eb3cSopenharmony_ci } else { 141323b3eb3cSopenharmony_ci auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_); 141423b3eb3cSopenharmony_ci CHECK_NULL_VOID(aceContainer); 141523b3eb3cSopenharmony_ci auto engine = EngineHelper::GetEngine(aceContainer->GetInstanceId()); 141623b3eb3cSopenharmony_ci auto delegate = engine->GetFrontend(); 141723b3eb3cSopenharmony_ci CHECK_NULL_VOID(delegate); 141823b3eb3cSopenharmony_ci ContainerScope scope(childContainerId_); 141923b3eb3cSopenharmony_ci delegate->CloseToast(toastId, std::move(callback)); 142023b3eb3cSopenharmony_ci } 142123b3eb3cSopenharmony_ci} 142223b3eb3cSopenharmony_ci 142323b3eb3cSopenharmony_civoid SubwindowOhos::ShowDialogForAbility(const std::string& title, const std::string& message, 142423b3eb3cSopenharmony_ci const std::vector<ButtonInfo>& buttons, bool autoCancel, std::function<void(int32_t, int32_t)>&& callback, 142523b3eb3cSopenharmony_ci const std::set<std::string>& callbacks) 142623b3eb3cSopenharmony_ci{ 142723b3eb3cSopenharmony_ci TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "show dialog for ability enter"); 142823b3eb3cSopenharmony_ci SubwindowManager::GetInstance()->SetCurrentSubwindow(AceType::Claim(this)); 142923b3eb3cSopenharmony_ci 143023b3eb3cSopenharmony_ci auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_); 143123b3eb3cSopenharmony_ci if (!aceContainer) { 143223b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, "get container failed, child containerId : %{public}d", childContainerId_); 143323b3eb3cSopenharmony_ci return; 143423b3eb3cSopenharmony_ci } 143523b3eb3cSopenharmony_ci 143623b3eb3cSopenharmony_ci auto engine = EngineHelper::GetEngine(aceContainer->GetInstanceId()); 143723b3eb3cSopenharmony_ci auto delegate = engine->GetFrontend(); 143823b3eb3cSopenharmony_ci if (!delegate) { 143923b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, "get frontend failed, child containerId : %{public}d", childContainerId_); 144023b3eb3cSopenharmony_ci return; 144123b3eb3cSopenharmony_ci } 144223b3eb3cSopenharmony_ci delegate->ShowDialog(title, message, buttons, autoCancel, std::move(callback), callbacks); 144323b3eb3cSopenharmony_ci} 144423b3eb3cSopenharmony_ci 144523b3eb3cSopenharmony_civoid SubwindowOhos::ShowDialogForService(const std::string& title, const std::string& message, 144623b3eb3cSopenharmony_ci const std::vector<ButtonInfo>& buttons, bool autoCancel, std::function<void(int32_t, int32_t)>&& callback, 144723b3eb3cSopenharmony_ci const std::set<std::string>& callbacks) 144823b3eb3cSopenharmony_ci{ 144923b3eb3cSopenharmony_ci bool ret = CreateEventRunner(); 145023b3eb3cSopenharmony_ci if (!ret) { 145123b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, "create event runner failed"); 145223b3eb3cSopenharmony_ci return; 145323b3eb3cSopenharmony_ci } 145423b3eb3cSopenharmony_ci 145523b3eb3cSopenharmony_ci SubwindowManager::GetInstance()->SetCurrentDialogSubwindow(AceType::Claim(this)); 145623b3eb3cSopenharmony_ci auto showDialogCallback = [title, message, &buttons, autoCancel, callbackParam = std::move(callback), 145723b3eb3cSopenharmony_ci &callbacks]() { 145823b3eb3cSopenharmony_ci int32_t posX = 0; 145923b3eb3cSopenharmony_ci int32_t posY = 0; 146023b3eb3cSopenharmony_ci int32_t width = 0; 146123b3eb3cSopenharmony_ci int32_t height = 0; 146223b3eb3cSopenharmony_ci float density = 1.0f; 146323b3eb3cSopenharmony_ci auto subwindowOhos = 146423b3eb3cSopenharmony_ci AceType::DynamicCast<SubwindowOhos>(SubwindowManager::GetInstance()->GetCurrentDialogWindow()); 146523b3eb3cSopenharmony_ci CHECK_NULL_VOID(subwindowOhos); 146623b3eb3cSopenharmony_ci subwindowOhos->GetToastDialogWindowProperty(width, height, posX, posY, density); 146723b3eb3cSopenharmony_ci bool ret = subwindowOhos->InitToastDialogWindow(width, height, posX, posY); 146823b3eb3cSopenharmony_ci if (!ret) { 146923b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, "init toast dialog window failed"); 147023b3eb3cSopenharmony_ci return; 147123b3eb3cSopenharmony_ci } 147223b3eb3cSopenharmony_ci ret = subwindowOhos->InitToastDialogView(width, height, density); 147323b3eb3cSopenharmony_ci if (!ret) { 147423b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, "init toast dialog view failed"); 147523b3eb3cSopenharmony_ci return; 147623b3eb3cSopenharmony_ci } 147723b3eb3cSopenharmony_ci auto childContainerId = subwindowOhos->GetChildContainerId(); 147823b3eb3cSopenharmony_ci ContainerScope scope(childContainerId); 147923b3eb3cSopenharmony_ci auto container = Platform::DialogContainer::GetContainer(childContainerId); 148023b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 148123b3eb3cSopenharmony_ci container->SetFontScaleAndWeightScale(childContainerId); 148223b3eb3cSopenharmony_ci Platform::DialogContainer::ShowToastDialogWindow(childContainerId, posX, posY, width, height); 148323b3eb3cSopenharmony_ci Platform::DialogContainer::ShowDialog(childContainerId, title, message, buttons, autoCancel, 148423b3eb3cSopenharmony_ci std::move(const_cast<std::function<void(int32_t, int32_t)>&&>(callbackParam)), callbacks); 148523b3eb3cSopenharmony_ci }; 148623b3eb3cSopenharmony_ci isToastWindow_ = false; 148723b3eb3cSopenharmony_ci if (!handler_->PostTask(showDialogCallback)) { 148823b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, "create show dialog callback failed"); 148923b3eb3cSopenharmony_ci return; 149023b3eb3cSopenharmony_ci } 149123b3eb3cSopenharmony_ci} 149223b3eb3cSopenharmony_ci 149323b3eb3cSopenharmony_civoid SubwindowOhos::ShowDialogForAbility(const PromptDialogAttr& dialogAttr, const std::vector<ButtonInfo>& buttons, 149423b3eb3cSopenharmony_ci std::function<void(int32_t, int32_t)>&& callback, const std::set<std::string>& callbacks) 149523b3eb3cSopenharmony_ci{ 149623b3eb3cSopenharmony_ci SubwindowManager::GetInstance()->SetCurrentSubwindow(AceType::Claim(this)); 149723b3eb3cSopenharmony_ci 149823b3eb3cSopenharmony_ci auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_); 149923b3eb3cSopenharmony_ci if (!aceContainer) { 150023b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, "get ace container failed"); 150123b3eb3cSopenharmony_ci return; 150223b3eb3cSopenharmony_ci } 150323b3eb3cSopenharmony_ci 150423b3eb3cSopenharmony_ci auto engine = EngineHelper::GetEngine(aceContainer->GetInstanceId()); 150523b3eb3cSopenharmony_ci auto delegate = engine->GetFrontend(); 150623b3eb3cSopenharmony_ci if (!delegate) { 150723b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, "get frontend failed"); 150823b3eb3cSopenharmony_ci return; 150923b3eb3cSopenharmony_ci } 151023b3eb3cSopenharmony_ci delegate->ShowDialog(dialogAttr, buttons, std::move(callback), callbacks); 151123b3eb3cSopenharmony_ci} 151223b3eb3cSopenharmony_ci 151323b3eb3cSopenharmony_civoid SubwindowOhos::ShowDialogForService(const PromptDialogAttr& dialogAttr, const std::vector<ButtonInfo>& buttons, 151423b3eb3cSopenharmony_ci std::function<void(int32_t, int32_t)>&& callback, const std::set<std::string>& callbacks) 151523b3eb3cSopenharmony_ci{ 151623b3eb3cSopenharmony_ci bool ret = CreateEventRunner(); 151723b3eb3cSopenharmony_ci if (!ret) { 151823b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, "create event runner failed"); 151923b3eb3cSopenharmony_ci return; 152023b3eb3cSopenharmony_ci } 152123b3eb3cSopenharmony_ci 152223b3eb3cSopenharmony_ci SubwindowManager::GetInstance()->SetCurrentDialogSubwindow(AceType::Claim(this)); 152323b3eb3cSopenharmony_ci auto showDialogCallback = [dialogAttr, &buttons, callbackParam = std::move(callback), &callbacks]() { 152423b3eb3cSopenharmony_ci int32_t posX = 0; 152523b3eb3cSopenharmony_ci int32_t posY = 0; 152623b3eb3cSopenharmony_ci int32_t width = 0; 152723b3eb3cSopenharmony_ci int32_t height = 0; 152823b3eb3cSopenharmony_ci float density = 1.0f; 152923b3eb3cSopenharmony_ci auto subwindowOhos = 153023b3eb3cSopenharmony_ci AceType::DynamicCast<SubwindowOhos>(SubwindowManager::GetInstance()->GetCurrentDialogWindow()); 153123b3eb3cSopenharmony_ci CHECK_NULL_VOID(subwindowOhos); 153223b3eb3cSopenharmony_ci subwindowOhos->GetToastDialogWindowProperty(width, height, posX, posY, density); 153323b3eb3cSopenharmony_ci bool ret = subwindowOhos->InitToastDialogWindow(width, height, posX, posY); 153423b3eb3cSopenharmony_ci if (!ret) { 153523b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, "init toast dialog window failed"); 153623b3eb3cSopenharmony_ci return; 153723b3eb3cSopenharmony_ci } 153823b3eb3cSopenharmony_ci ret = subwindowOhos->InitToastDialogView(width, height, density); 153923b3eb3cSopenharmony_ci if (!ret) { 154023b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, "init toast dialog view failed"); 154123b3eb3cSopenharmony_ci return; 154223b3eb3cSopenharmony_ci } 154323b3eb3cSopenharmony_ci auto childContainerId = subwindowOhos->GetChildContainerId(); 154423b3eb3cSopenharmony_ci ContainerScope scope(childContainerId); 154523b3eb3cSopenharmony_ci Platform::DialogContainer::ShowToastDialogWindow(childContainerId, posX, posY, width, height); 154623b3eb3cSopenharmony_ci Platform::DialogContainer::ShowDialog(childContainerId, dialogAttr, buttons, 154723b3eb3cSopenharmony_ci std::move(const_cast<std::function<void(int32_t, int32_t)>&&>(callbackParam)), callbacks); 154823b3eb3cSopenharmony_ci }; 154923b3eb3cSopenharmony_ci isToastWindow_ = false; 155023b3eb3cSopenharmony_ci if (!handler_->PostTask(showDialogCallback)) { 155123b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, "create show dialog callback failed"); 155223b3eb3cSopenharmony_ci return; 155323b3eb3cSopenharmony_ci } 155423b3eb3cSopenharmony_ci} 155523b3eb3cSopenharmony_ci 155623b3eb3cSopenharmony_civoid SubwindowOhos::ShowDialog(const std::string& title, const std::string& message, 155723b3eb3cSopenharmony_ci const std::vector<ButtonInfo>& buttons, bool autoCancel, std::function<void(int32_t, int32_t)>&& callback, 155823b3eb3cSopenharmony_ci const std::set<std::string>& callbacks) 155923b3eb3cSopenharmony_ci{ 156023b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_SUB_WINDOW, "show dialog, window parent id is %{public}d", parentContainerId_); 156123b3eb3cSopenharmony_ci if (parentContainerId_ >= MIN_PA_SERVICE_ID || parentContainerId_ < 0) { 156223b3eb3cSopenharmony_ci ShowDialogForService(title, message, buttons, autoCancel, std::move(callback), callbacks); 156323b3eb3cSopenharmony_ci } else { 156423b3eb3cSopenharmony_ci ShowDialogForAbility(title, message, buttons, autoCancel, std::move(callback), callbacks); 156523b3eb3cSopenharmony_ci } 156623b3eb3cSopenharmony_ci} 156723b3eb3cSopenharmony_ci 156823b3eb3cSopenharmony_civoid SubwindowOhos::ShowDialog(const PromptDialogAttr& dialogAttr, const std::vector<ButtonInfo>& buttons, 156923b3eb3cSopenharmony_ci std::function<void(int32_t, int32_t)>&& callback, const std::set<std::string>& callbacks) 157023b3eb3cSopenharmony_ci{ 157123b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_SUB_WINDOW, "show dialog with attr, window parent id is %{public}d", parentContainerId_); 157223b3eb3cSopenharmony_ci if (parentContainerId_ >= MIN_PA_SERVICE_ID || parentContainerId_ < 0) { 157323b3eb3cSopenharmony_ci ShowDialogForService(dialogAttr, buttons, std::move(callback), callbacks); 157423b3eb3cSopenharmony_ci } else { 157523b3eb3cSopenharmony_ci ShowDialogForAbility(dialogAttr, buttons, std::move(callback), callbacks); 157623b3eb3cSopenharmony_ci } 157723b3eb3cSopenharmony_ci} 157823b3eb3cSopenharmony_ci 157923b3eb3cSopenharmony_civoid SubwindowOhos::OpenCustomDialogForAbility( 158023b3eb3cSopenharmony_ci const PromptDialogAttr& dialogAttr, std::function<void(int32_t)>&& callback) 158123b3eb3cSopenharmony_ci{ 158223b3eb3cSopenharmony_ci SubwindowManager::GetInstance()->SetCurrentSubwindow(AceType::Claim(this)); 158323b3eb3cSopenharmony_ci 158423b3eb3cSopenharmony_ci auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_); 158523b3eb3cSopenharmony_ci if (!aceContainer) { 158623b3eb3cSopenharmony_ci TAG_LOGW( 158723b3eb3cSopenharmony_ci AceLogTag::ACE_SUB_WINDOW, "open dialog fail, the container %{public}d can not find", childContainerId_); 158823b3eb3cSopenharmony_ci return; 158923b3eb3cSopenharmony_ci } 159023b3eb3cSopenharmony_ci 159123b3eb3cSopenharmony_ci auto engine = EngineHelper::GetEngine(aceContainer->GetInstanceId()); 159223b3eb3cSopenharmony_ci auto delegate = engine->GetFrontend(); 159323b3eb3cSopenharmony_ci if (!delegate) { 159423b3eb3cSopenharmony_ci return; 159523b3eb3cSopenharmony_ci } 159623b3eb3cSopenharmony_ci delegate->OpenCustomDialog(dialogAttr, std::move(callback)); 159723b3eb3cSopenharmony_ci} 159823b3eb3cSopenharmony_ci 159923b3eb3cSopenharmony_civoid SubwindowOhos::OpenCustomDialogForService( 160023b3eb3cSopenharmony_ci const PromptDialogAttr& dialogAttr, std::function<void(int32_t)>&& callback) 160123b3eb3cSopenharmony_ci{ 160223b3eb3cSopenharmony_ci // temporary not support 160323b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, "temporary not support for service by promptAction with CustomBuilder"); 160423b3eb3cSopenharmony_ci} 160523b3eb3cSopenharmony_ci 160623b3eb3cSopenharmony_civoid SubwindowOhos::OpenCustomDialog(const PromptDialogAttr& dialogAttr, std::function<void(int32_t)>&& callback) 160723b3eb3cSopenharmony_ci{ 160823b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_SUB_WINDOW, "open custom dialog, window parent id is %{public}d", parentContainerId_); 160923b3eb3cSopenharmony_ci if (parentContainerId_ >= MIN_PA_SERVICE_ID || parentContainerId_ < 0) { 161023b3eb3cSopenharmony_ci OpenCustomDialogForService(dialogAttr, std::move(callback)); 161123b3eb3cSopenharmony_ci } else { 161223b3eb3cSopenharmony_ci OpenCustomDialogForAbility(dialogAttr, std::move(callback)); 161323b3eb3cSopenharmony_ci } 161423b3eb3cSopenharmony_ci} 161523b3eb3cSopenharmony_ci 161623b3eb3cSopenharmony_civoid SubwindowOhos::CloseCustomDialog(const int32_t dialogId) 161723b3eb3cSopenharmony_ci{ 161823b3eb3cSopenharmony_ci auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_); 161923b3eb3cSopenharmony_ci CHECK_NULL_VOID(aceContainer); 162023b3eb3cSopenharmony_ci auto context = DynamicCast<NG::PipelineContext>(aceContainer->GetPipelineContext()); 162123b3eb3cSopenharmony_ci CHECK_NULL_VOID(context); 162223b3eb3cSopenharmony_ci auto overlay = context->GetOverlayManager(); 162323b3eb3cSopenharmony_ci CHECK_NULL_VOID(overlay); 162423b3eb3cSopenharmony_ci ContainerScope scope(childContainerId_); 162523b3eb3cSopenharmony_ci return overlay->CloseCustomDialog(dialogId); 162623b3eb3cSopenharmony_ci} 162723b3eb3cSopenharmony_ci 162823b3eb3cSopenharmony_civoid SubwindowOhos::CloseCustomDialog(const WeakPtr<NG::UINode>& node, std::function<void(int32_t)>&& callback) 162923b3eb3cSopenharmony_ci{ 163023b3eb3cSopenharmony_ci auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_); 163123b3eb3cSopenharmony_ci CHECK_NULL_VOID(aceContainer); 163223b3eb3cSopenharmony_ci auto context = DynamicCast<NG::PipelineContext>(aceContainer->GetPipelineContext()); 163323b3eb3cSopenharmony_ci CHECK_NULL_VOID(context); 163423b3eb3cSopenharmony_ci auto overlay = context->GetOverlayManager(); 163523b3eb3cSopenharmony_ci CHECK_NULL_VOID(overlay); 163623b3eb3cSopenharmony_ci ContainerScope scope(childContainerId_); 163723b3eb3cSopenharmony_ci return overlay->CloseCustomDialog(node, std::move(callback)); 163823b3eb3cSopenharmony_ci} 163923b3eb3cSopenharmony_ci 164023b3eb3cSopenharmony_civoid SubwindowOhos::ShowActionMenuForAbility( 164123b3eb3cSopenharmony_ci const std::string& title, const std::vector<ButtonInfo>& button, std::function<void(int32_t, int32_t)>&& callback) 164223b3eb3cSopenharmony_ci{ 164323b3eb3cSopenharmony_ci TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "show action menu for ability enter"); 164423b3eb3cSopenharmony_ci SubwindowManager::GetInstance()->SetCurrentSubwindow(AceType::Claim(this)); 164523b3eb3cSopenharmony_ci 164623b3eb3cSopenharmony_ci auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_); 164723b3eb3cSopenharmony_ci if (!aceContainer) { 164823b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, "get container failed"); 164923b3eb3cSopenharmony_ci return; 165023b3eb3cSopenharmony_ci } 165123b3eb3cSopenharmony_ci 165223b3eb3cSopenharmony_ci auto engine = EngineHelper::GetEngine(aceContainer->GetInstanceId()); 165323b3eb3cSopenharmony_ci auto delegate = engine->GetFrontend(); 165423b3eb3cSopenharmony_ci if (!delegate) { 165523b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, "get frontend failed"); 165623b3eb3cSopenharmony_ci return; 165723b3eb3cSopenharmony_ci } 165823b3eb3cSopenharmony_ci delegate->ShowActionMenu(title, button, std::move(callback)); 165923b3eb3cSopenharmony_ci} 166023b3eb3cSopenharmony_ci 166123b3eb3cSopenharmony_civoid SubwindowOhos::ShowActionMenuForService( 166223b3eb3cSopenharmony_ci const std::string& title, const std::vector<ButtonInfo>& button, std::function<void(int32_t, int32_t)>&& callback) 166323b3eb3cSopenharmony_ci{ 166423b3eb3cSopenharmony_ci TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "show action menu for service enter"); 166523b3eb3cSopenharmony_ci bool ret = CreateEventRunner(); 166623b3eb3cSopenharmony_ci if (!ret) { 166723b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, "create event runner failed"); 166823b3eb3cSopenharmony_ci return; 166923b3eb3cSopenharmony_ci } 167023b3eb3cSopenharmony_ci 167123b3eb3cSopenharmony_ci SubwindowManager::GetInstance()->SetCurrentDialogSubwindow(AceType::Claim(this)); 167223b3eb3cSopenharmony_ci auto showDialogCallback = [title, &button, callbackParam = std::move(callback)]() { 167323b3eb3cSopenharmony_ci int32_t posX = 0; 167423b3eb3cSopenharmony_ci int32_t posY = 0; 167523b3eb3cSopenharmony_ci int32_t width = 0; 167623b3eb3cSopenharmony_ci int32_t height = 0; 167723b3eb3cSopenharmony_ci float density = 1.0f; 167823b3eb3cSopenharmony_ci auto subwindowOhos = 167923b3eb3cSopenharmony_ci AceType::DynamicCast<SubwindowOhos>(SubwindowManager::GetInstance()->GetCurrentDialogWindow()); 168023b3eb3cSopenharmony_ci CHECK_NULL_VOID(subwindowOhos); 168123b3eb3cSopenharmony_ci subwindowOhos->GetToastDialogWindowProperty(width, height, posX, posY, density); 168223b3eb3cSopenharmony_ci bool ret = subwindowOhos->InitToastDialogWindow(width, height, posX, posY); 168323b3eb3cSopenharmony_ci if (!ret) { 168423b3eb3cSopenharmony_ci return; 168523b3eb3cSopenharmony_ci } 168623b3eb3cSopenharmony_ci ret = subwindowOhos->InitToastDialogView(width, height, density); 168723b3eb3cSopenharmony_ci if (!ret) { 168823b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, "init toast dialog view failed"); 168923b3eb3cSopenharmony_ci return; 169023b3eb3cSopenharmony_ci } 169123b3eb3cSopenharmony_ci auto childContainerId = subwindowOhos->GetChildContainerId(); 169223b3eb3cSopenharmony_ci ContainerScope scope(childContainerId); 169323b3eb3cSopenharmony_ci auto container = Platform::DialogContainer::GetContainer(childContainerId); 169423b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 169523b3eb3cSopenharmony_ci container->SetFontScaleAndWeightScale(childContainerId); 169623b3eb3cSopenharmony_ci Platform::DialogContainer::ShowToastDialogWindow(childContainerId, posX, posY, width, height); 169723b3eb3cSopenharmony_ci Platform::DialogContainer::ShowActionMenu(childContainerId, title, button, 169823b3eb3cSopenharmony_ci std::move(const_cast<std::function<void(int32_t, int32_t)>&&>(callbackParam))); 169923b3eb3cSopenharmony_ci }; 170023b3eb3cSopenharmony_ci isToastWindow_ = false; 170123b3eb3cSopenharmony_ci if (!handler_->PostTask(showDialogCallback)) { 170223b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, "create show dialog callback failed"); 170323b3eb3cSopenharmony_ci return; 170423b3eb3cSopenharmony_ci } 170523b3eb3cSopenharmony_ci} 170623b3eb3cSopenharmony_ci 170723b3eb3cSopenharmony_civoid SubwindowOhos::CloseDialog(int32_t instanceId) 170823b3eb3cSopenharmony_ci{ 170923b3eb3cSopenharmony_ci TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "close dialog enter"); 171023b3eb3cSopenharmony_ci Platform::DialogContainer::CloseWindow(instanceId); 171123b3eb3cSopenharmony_ci} 171223b3eb3cSopenharmony_ci 171323b3eb3cSopenharmony_civoid SubwindowOhos::UpdateAceView(int32_t width, int32_t height, float density, int32_t containerId) 171423b3eb3cSopenharmony_ci{ 171523b3eb3cSopenharmony_ci auto container = Platform::DialogContainer::GetContainer(containerId); 171623b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 171723b3eb3cSopenharmony_ci auto aceView = AceType::DynamicCast<Platform::AceViewOhos>(container->GetAceView()); 171823b3eb3cSopenharmony_ci CHECK_NULL_VOID(aceView); 171923b3eb3cSopenharmony_ci if (aceView->GetWidth() != width || aceView->GetHeight() != height) { 172023b3eb3cSopenharmony_ci ViewportConfig config(width, height, density); 172123b3eb3cSopenharmony_ci Platform::AceViewOhos::SetViewportMetrics(aceView, config); 172223b3eb3cSopenharmony_ci Platform::AceViewOhos::SurfaceChanged(aceView, width, height, 0); 172323b3eb3cSopenharmony_ci } 172423b3eb3cSopenharmony_ci} 172523b3eb3cSopenharmony_ci 172623b3eb3cSopenharmony_civoid SubwindowOhos::ShowActionMenu( 172723b3eb3cSopenharmony_ci const std::string& title, const std::vector<ButtonInfo>& button, std::function<void(int32_t, int32_t)>&& callback) 172823b3eb3cSopenharmony_ci{ 172923b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_SUB_WINDOW, "show custom dialog, window parent id is %{public}d", parentContainerId_); 173023b3eb3cSopenharmony_ci if (parentContainerId_ >= MIN_PA_SERVICE_ID || parentContainerId_ < 0) { 173123b3eb3cSopenharmony_ci ShowActionMenuForService(title, button, std::move(callback)); 173223b3eb3cSopenharmony_ci } else { 173323b3eb3cSopenharmony_ci ShowActionMenuForAbility(title, button, std::move(callback)); 173423b3eb3cSopenharmony_ci } 173523b3eb3cSopenharmony_ci} 173623b3eb3cSopenharmony_ci 173723b3eb3cSopenharmony_ciRect SubwindowOhos::GetParentWindowRect() const 173823b3eb3cSopenharmony_ci{ 173923b3eb3cSopenharmony_ci Rect rect; 174023b3eb3cSopenharmony_ci CHECK_NULL_RETURN(parentWindow_, rect); 174123b3eb3cSopenharmony_ci auto parentWindowRect = parentWindow_->GetRect(); 174223b3eb3cSopenharmony_ci return Rect(parentWindowRect.posX_, parentWindowRect.posY_, parentWindowRect.width_, parentWindowRect.height_); 174323b3eb3cSopenharmony_ci} 174423b3eb3cSopenharmony_ci 174523b3eb3cSopenharmony_ciRect SubwindowOhos::GetUIExtensionHostWindowRect() const 174623b3eb3cSopenharmony_ci{ 174723b3eb3cSopenharmony_ci Rect rect; 174823b3eb3cSopenharmony_ci CHECK_NULL_RETURN(parentWindow_, rect); 174923b3eb3cSopenharmony_ci auto id = GetUIExtensionHostWindowId(); 175023b3eb3cSopenharmony_ci auto hostWindowRect = parentWindow_->GetHostWindowRect(id); 175123b3eb3cSopenharmony_ci return Rect(hostWindowRect.posX_, hostWindowRect.posY_, hostWindowRect.width_, hostWindowRect.height_); 175223b3eb3cSopenharmony_ci} 175323b3eb3cSopenharmony_ci 175423b3eb3cSopenharmony_ciNG::RectF SubwindowOhos::GetWindowRect() const 175523b3eb3cSopenharmony_ci{ 175623b3eb3cSopenharmony_ci NG::RectF rect; 175723b3eb3cSopenharmony_ci CHECK_NULL_RETURN(window_, rect); 175823b3eb3cSopenharmony_ci rect.SetRect(window_->GetRect().posX_, window_->GetRect().posY_, 175923b3eb3cSopenharmony_ci window_->GetRect().width_, window_->GetRect().height_); 176023b3eb3cSopenharmony_ci return rect; 176123b3eb3cSopenharmony_ci} 176223b3eb3cSopenharmony_ci 176323b3eb3cSopenharmony_civoid SubwindowOhos::RequestFocus() 176423b3eb3cSopenharmony_ci{ 176523b3eb3cSopenharmony_ci CHECK_NULL_VOID(window_); 176623b3eb3cSopenharmony_ci if (window_->IsFocused()) { 176723b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_SUB_WINDOW, "subwindow id:%{public}u already focused", window_->GetWindowId()); 176823b3eb3cSopenharmony_ci // already focused, no need to focus 176923b3eb3cSopenharmony_ci return; 177023b3eb3cSopenharmony_ci } 177123b3eb3cSopenharmony_ci OHOS::Rosen::WMError ret = window_->RequestFocus(); 177223b3eb3cSopenharmony_ci if (ret != OHOS::Rosen::WMError::WM_OK) { 177323b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, "subindow id:%{public}u request focus failed with WMError: %{public}d", 177423b3eb3cSopenharmony_ci window_->GetWindowId(), static_cast<int32_t>(ret)); 177523b3eb3cSopenharmony_ci return; 177623b3eb3cSopenharmony_ci } 177723b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_SUB_WINDOW, "subwindow id:%{public}u request focus successfully.", window_->GetWindowId()); 177823b3eb3cSopenharmony_ci} 177923b3eb3cSopenharmony_ci 178023b3eb3cSopenharmony_cibool SubwindowOhos::IsFocused() 178123b3eb3cSopenharmony_ci{ 178223b3eb3cSopenharmony_ci CHECK_NULL_RETURN(window_, false); 178323b3eb3cSopenharmony_ci return window_->IsFocused(); 178423b3eb3cSopenharmony_ci} 178523b3eb3cSopenharmony_ci 178623b3eb3cSopenharmony_civoid SubwindowOhos::HideFilter(bool isInSubWindow) 178723b3eb3cSopenharmony_ci{ 178823b3eb3cSopenharmony_ci RefPtr<Container> aceContainer = nullptr; 178923b3eb3cSopenharmony_ci if (isInSubWindow) { 179023b3eb3cSopenharmony_ci aceContainer = Platform::AceContainer::GetContainer(childContainerId_); 179123b3eb3cSopenharmony_ci } else { 179223b3eb3cSopenharmony_ci aceContainer = Platform::AceContainer::GetContainer(parentContainerId_); 179323b3eb3cSopenharmony_ci } 179423b3eb3cSopenharmony_ci 179523b3eb3cSopenharmony_ci CHECK_NULL_VOID(aceContainer); 179623b3eb3cSopenharmony_ci auto pipelineContext = DynamicCast<NG::PipelineContext>(aceContainer->GetPipelineContext()); 179723b3eb3cSopenharmony_ci CHECK_NULL_VOID(pipelineContext); 179823b3eb3cSopenharmony_ci auto overlayManager = pipelineContext->GetOverlayManager(); 179923b3eb3cSopenharmony_ci CHECK_NULL_VOID(overlayManager); 180023b3eb3cSopenharmony_ci 180123b3eb3cSopenharmony_ci auto containerId = isInSubWindow ? childContainerId_ : parentContainerId_; 180223b3eb3cSopenharmony_ci ContainerScope scope(containerId); 180323b3eb3cSopenharmony_ci overlayManager->RemoveFilterAnimation(); 180423b3eb3cSopenharmony_ci} 180523b3eb3cSopenharmony_ci 180623b3eb3cSopenharmony_civoid SubwindowOhos::HidePixelMap(bool startDrag, double x, double y, bool showAnimation) 180723b3eb3cSopenharmony_ci{ 180823b3eb3cSopenharmony_ci auto parentAceContainer = Platform::AceContainer::GetContainer(parentContainerId_); 180923b3eb3cSopenharmony_ci CHECK_NULL_VOID(parentAceContainer); 181023b3eb3cSopenharmony_ci auto parentPipeline = DynamicCast<NG::PipelineContext>(parentAceContainer->GetPipelineContext()); 181123b3eb3cSopenharmony_ci CHECK_NULL_VOID(parentPipeline); 181223b3eb3cSopenharmony_ci auto manager = parentPipeline->GetOverlayManager(); 181323b3eb3cSopenharmony_ci CHECK_NULL_VOID(manager); 181423b3eb3cSopenharmony_ci ContainerScope scope(parentContainerId_); 181523b3eb3cSopenharmony_ci if (!startDrag) { 181623b3eb3cSopenharmony_ci manager->RemovePreviewBadgeNode(); 181723b3eb3cSopenharmony_ci manager->RemoveGatherNodeWithAnimation(); 181823b3eb3cSopenharmony_ci } 181923b3eb3cSopenharmony_ci if (showAnimation) { 182023b3eb3cSopenharmony_ci manager->RemovePixelMapAnimation(startDrag, x, y, true); 182123b3eb3cSopenharmony_ci } else { 182223b3eb3cSopenharmony_ci manager->RemovePixelMap(); 182323b3eb3cSopenharmony_ci } 182423b3eb3cSopenharmony_ci} 182523b3eb3cSopenharmony_ci 182623b3eb3cSopenharmony_civoid SubwindowOhos::HideEventColumn() 182723b3eb3cSopenharmony_ci{ 182823b3eb3cSopenharmony_ci auto parentAceContainer = Platform::AceContainer::GetContainer(parentContainerId_); 182923b3eb3cSopenharmony_ci CHECK_NULL_VOID(parentAceContainer); 183023b3eb3cSopenharmony_ci auto parentPipeline = DynamicCast<NG::PipelineContext>(parentAceContainer->GetPipelineContext()); 183123b3eb3cSopenharmony_ci CHECK_NULL_VOID(parentPipeline); 183223b3eb3cSopenharmony_ci auto manager = parentPipeline->GetOverlayManager(); 183323b3eb3cSopenharmony_ci CHECK_NULL_VOID(manager); 183423b3eb3cSopenharmony_ci ContainerScope scope(parentContainerId_); 183523b3eb3cSopenharmony_ci manager->RemoveEventColumn(); 183623b3eb3cSopenharmony_ci} 183723b3eb3cSopenharmony_ci 183823b3eb3cSopenharmony_civoid SubwindowOhos::ResizeWindowForFoldStatus(int32_t parentContainerId) 183923b3eb3cSopenharmony_ci{ 184023b3eb3cSopenharmony_ci auto callback = []() { 184123b3eb3cSopenharmony_ci auto subwindowOhos = 184223b3eb3cSopenharmony_ci AceType::DynamicCast<SubwindowOhos>(SubwindowManager::GetInstance()->GetCurrentDialogWindow()); 184323b3eb3cSopenharmony_ci CHECK_NULL_VOID(subwindowOhos); 184423b3eb3cSopenharmony_ci auto childContainerId = subwindowOhos->GetChildContainerId(); 184523b3eb3cSopenharmony_ci ContainerScope scope(childContainerId); 184623b3eb3cSopenharmony_ci auto window = Platform::DialogContainer::GetUIWindow(childContainerId); 184723b3eb3cSopenharmony_ci CHECK_NULL_VOID(window); 184823b3eb3cSopenharmony_ci auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplaySync(); 184923b3eb3cSopenharmony_ci CHECK_NULL_VOID(defaultDisplay); 185023b3eb3cSopenharmony_ci auto ret = window->Resize(defaultDisplay->GetWidth(), defaultDisplay->GetHeight()); 185123b3eb3cSopenharmony_ci if (ret != Rosen::WMError::WM_OK) { 185223b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, "Resize window by default display failed with errCode: %{public}d", 185323b3eb3cSopenharmony_ci static_cast<int32_t>(ret)); 185423b3eb3cSopenharmony_ci return; 185523b3eb3cSopenharmony_ci } 185623b3eb3cSopenharmony_ci auto container = Platform::DialogContainer::GetContainer(childContainerId); 185723b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 185823b3eb3cSopenharmony_ci // get ace_view 185923b3eb3cSopenharmony_ci auto aceView = AceType::DynamicCast<Platform::AceViewOhos>(container->GetAceView()); 186023b3eb3cSopenharmony_ci CHECK_NULL_VOID(aceView); 186123b3eb3cSopenharmony_ci Platform::AceViewOhos::SurfaceChanged(aceView, defaultDisplay->GetWidth(), defaultDisplay->GetHeight(), 0); 186223b3eb3cSopenharmony_ci }; 186323b3eb3cSopenharmony_ci if (parentContainerId > 0) { 186423b3eb3cSopenharmony_ci ResizeWindowForFoldStatus(); 186523b3eb3cSopenharmony_ci return; 186623b3eb3cSopenharmony_ci } 186723b3eb3cSopenharmony_ci if (!handler_->PostTask(callback)) { 186823b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, "Resize Toast Window failed"); 186923b3eb3cSopenharmony_ci } 187023b3eb3cSopenharmony_ci} 187123b3eb3cSopenharmony_ci 187223b3eb3cSopenharmony_civoid SubwindowOhos::ResizeWindowForFoldStatus() 187323b3eb3cSopenharmony_ci{ 187423b3eb3cSopenharmony_ci auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplaySync(); 187523b3eb3cSopenharmony_ci CHECK_NULL_VOID(defaultDisplay); 187623b3eb3cSopenharmony_ci CHECK_NULL_VOID(window_); 187723b3eb3cSopenharmony_ci auto ret = window_->Resize(defaultDisplay->GetWidth(), defaultDisplay->GetHeight()); 187823b3eb3cSopenharmony_ci if (ret != Rosen::WMError::WM_OK) { 187923b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, "Resize window by default display failed with errCode: %{public}d", 188023b3eb3cSopenharmony_ci static_cast<int32_t>(ret)); 188123b3eb3cSopenharmony_ci return; 188223b3eb3cSopenharmony_ci } 188323b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_SUB_WINDOW, 188423b3eb3cSopenharmony_ci "SubwindowOhos window rect is resized to x: %{public}d, y: %{public}d, width: %{public}u, height: %{public}u", 188523b3eb3cSopenharmony_ci window_->GetRect().posX_, window_->GetRect().posY_, window_->GetRect().width_, window_->GetRect().height_); 188623b3eb3cSopenharmony_ci} 188723b3eb3cSopenharmony_ci 188823b3eb3cSopenharmony_civoid SubwindowOhos::MarkDirtyDialogSafeArea() 188923b3eb3cSopenharmony_ci{ 189023b3eb3cSopenharmony_ci auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_); 189123b3eb3cSopenharmony_ci CHECK_NULL_VOID(aceContainer); 189223b3eb3cSopenharmony_ci auto context = DynamicCast<NG::PipelineContext>(aceContainer->GetPipelineContext()); 189323b3eb3cSopenharmony_ci CHECK_NULL_VOID(context); 189423b3eb3cSopenharmony_ci auto rootNode = context->GetRootElement(); 189523b3eb3cSopenharmony_ci CHECK_NULL_VOID(rootNode); 189623b3eb3cSopenharmony_ci auto lastChild = rootNode->GetLastChild(); 189723b3eb3cSopenharmony_ci CHECK_NULL_VOID(lastChild); 189823b3eb3cSopenharmony_ci lastChild->MarkDirtyNode(NG::PROPERTY_UPDATE_MEASURE); 189923b3eb3cSopenharmony_ci} 190023b3eb3cSopenharmony_ci 190123b3eb3cSopenharmony_cibool SubwindowOhos::Close() 190223b3eb3cSopenharmony_ci{ 190323b3eb3cSopenharmony_ci CHECK_NULL_RETURN(window_, false); 190423b3eb3cSopenharmony_ci window_->UnregisterSwitchFreeMultiWindowListener(freeMultiWindowListener_); 190523b3eb3cSopenharmony_ci OHOS::Rosen::WMError ret = window_->Close(); 190623b3eb3cSopenharmony_ci if (ret != OHOS::Rosen::WMError::WM_OK) { 190723b3eb3cSopenharmony_ci TAG_LOGE(AceLogTag::ACE_SUB_WINDOW, "SubwindowOhos failed to close the dialog subwindow."); 190823b3eb3cSopenharmony_ci return false; 190923b3eb3cSopenharmony_ci } 191023b3eb3cSopenharmony_ci sptr<OHOS::Rosen::Window> uiWindow = nullptr; 191123b3eb3cSopenharmony_ci Ace::Platform::DialogContainer::SetUIWindow(childContainerId_, uiWindow); 191223b3eb3cSopenharmony_ci return true; 191323b3eb3cSopenharmony_ci} 191423b3eb3cSopenharmony_ci 191523b3eb3cSopenharmony_cibool SubwindowOhos::IsFreeMultiWindow() const 191623b3eb3cSopenharmony_ci{ 191723b3eb3cSopenharmony_ci if (!parentWindow_) { 191823b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, "Window is null, failed to get freeMultiWindow status"); 191923b3eb3cSopenharmony_ci return false; 192023b3eb3cSopenharmony_ci } 192123b3eb3cSopenharmony_ci 192223b3eb3cSopenharmony_ci return parentWindow_->GetFreeMultiWindowModeEnabledState(); 192323b3eb3cSopenharmony_ci} 192423b3eb3cSopenharmony_ci 192523b3eb3cSopenharmony_civoid SubwindowOhos::OnFreeMultiWindowSwitch(bool enable) 192623b3eb3cSopenharmony_ci{ 192723b3eb3cSopenharmony_ci for (auto&& [id, callback] : freeMultiWindowSwitchCallbackMap_) { 192823b3eb3cSopenharmony_ci if (callback) { 192923b3eb3cSopenharmony_ci callback(enable); 193023b3eb3cSopenharmony_ci } 193123b3eb3cSopenharmony_ci } 193223b3eb3cSopenharmony_ci} 193323b3eb3cSopenharmony_ci 193423b3eb3cSopenharmony_ciint32_t SubwindowOhos::RegisterFreeMultiWindowSwitchCallback(std::function<void(bool)>&& callback) 193523b3eb3cSopenharmony_ci{ 193623b3eb3cSopenharmony_ci if (callback) { 193723b3eb3cSopenharmony_ci freeMultiWindowSwitchCallbackMap_.emplace(++callbackId_, std::move(callback)); 193823b3eb3cSopenharmony_ci return callbackId_; 193923b3eb3cSopenharmony_ci } 194023b3eb3cSopenharmony_ci return 0; 194123b3eb3cSopenharmony_ci} 194223b3eb3cSopenharmony_ci 194323b3eb3cSopenharmony_civoid SubwindowOhos::UnRegisterFreeMultiWindowSwitchCallback(int32_t callbackId) 194423b3eb3cSopenharmony_ci{ 194523b3eb3cSopenharmony_ci freeMultiWindowSwitchCallbackMap_.erase(callbackId); 194623b3eb3cSopenharmony_ci} 194723b3eb3cSopenharmony_ci 194823b3eb3cSopenharmony_cibool SubwindowOhos::IsToastSubWindow() 194923b3eb3cSopenharmony_ci{ 195023b3eb3cSopenharmony_ci CHECK_NULL_RETURN(window_, false); 195123b3eb3cSopenharmony_ci auto windowType = window_->GetType(); 195223b3eb3cSopenharmony_ci return windowType == Rosen::WindowType::WINDOW_TYPE_SYSTEM_TOAST || 195323b3eb3cSopenharmony_ci windowType == Rosen::WindowType::WINDOW_TYPE_TOAST; 195423b3eb3cSopenharmony_ci} 195523b3eb3cSopenharmony_ci 195623b3eb3cSopenharmony_civoid SubwindowOhos::DestroyWindow() 195723b3eb3cSopenharmony_ci{ 195823b3eb3cSopenharmony_ci CHECK_NULL_VOID(window_); 195923b3eb3cSopenharmony_ci OHOS::Rosen::WMError ret = window_->Destroy(); 196023b3eb3cSopenharmony_ci if (ret != OHOS::Rosen::WMError::WM_OK) { 196123b3eb3cSopenharmony_ci TAG_LOGE(AceLogTag::ACE_SUB_WINDOW, "SubwindowOhos failed to destroy the dialog subwindow."); 196223b3eb3cSopenharmony_ci return; 196323b3eb3cSopenharmony_ci } 196423b3eb3cSopenharmony_ci} 196523b3eb3cSopenharmony_ci} // namespace OHOS::Ace 1966