123b3eb3cSopenharmony_ci/* 223b3eb3cSopenharmony_ci * Copyright (c) 2022 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#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_SUBWINDOW_SUBWINDOW_MANAGER_H 1723b3eb3cSopenharmony_ci#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_SUBWINDOW_SUBWINDOW_MANAGER_H 1823b3eb3cSopenharmony_ci 1923b3eb3cSopenharmony_ci#include <mutex> 2023b3eb3cSopenharmony_ci#include <set> 2123b3eb3cSopenharmony_ci#include <unordered_map> 2223b3eb3cSopenharmony_ci#include <array> 2323b3eb3cSopenharmony_ci 2423b3eb3cSopenharmony_ci#include "base/memory/referenced.h" 2523b3eb3cSopenharmony_ci#include "base/subwindow/subwindow.h" 2623b3eb3cSopenharmony_ci#include "base/utils/macros.h" 2723b3eb3cSopenharmony_ci#include "base/utils/noncopyable.h" 2823b3eb3cSopenharmony_ci#include "core/components/dialog/dialog_properties.h" 2923b3eb3cSopenharmony_ci#include "core/components_ng/base/frame_node.h" 3023b3eb3cSopenharmony_ci#include "core/components_ng/pattern/overlay/overlay_manager.h" 3123b3eb3cSopenharmony_ci 3223b3eb3cSopenharmony_cinamespace OHOS::Ace { 3323b3eb3cSopenharmony_ci 3423b3eb3cSopenharmony_ciusing SubwindowMap = std::unordered_map<int32_t, RefPtr<Subwindow>>; 3523b3eb3cSopenharmony_ci 3623b3eb3cSopenharmony_ciclass ACE_EXPORT SubwindowManager final : public NonCopyable { 3723b3eb3cSopenharmony_cipublic: 3823b3eb3cSopenharmony_ci // Get the instance 3923b3eb3cSopenharmony_ci ACE_FORCE_EXPORT static std::shared_ptr<SubwindowManager> GetInstance(); 4023b3eb3cSopenharmony_ci 4123b3eb3cSopenharmony_ci void AddContainerId(uint32_t windowId, int32_t containerId); 4223b3eb3cSopenharmony_ci void RemoveContainerId(uint32_t windowId); 4323b3eb3cSopenharmony_ci int32_t GetContainerId(uint32_t windowId); 4423b3eb3cSopenharmony_ci 4523b3eb3cSopenharmony_ci void AddParentContainerId(int32_t containerId, int32_t parentContainerId); 4623b3eb3cSopenharmony_ci void RemoveParentContainerId(int32_t containerId); 4723b3eb3cSopenharmony_ci int32_t GetParentContainerId(int32_t containerId); 4823b3eb3cSopenharmony_ci int32_t GetSubContainerId(int32_t parentContainerId); 4923b3eb3cSopenharmony_ci 5023b3eb3cSopenharmony_ci void AddSubwindow(int32_t instanceId, RefPtr<Subwindow>); 5123b3eb3cSopenharmony_ci void RemoveSubwindow(int32_t instanceId); 5223b3eb3cSopenharmony_ci 5323b3eb3cSopenharmony_ci // Get the subwindow of instance, return the window or nullptr. 5423b3eb3cSopenharmony_ci const RefPtr<Subwindow> GetSubwindow(int32_t instanceId); 5523b3eb3cSopenharmony_ci const RefPtr<Subwindow> GetOrCreateSubwindow(int32_t instanceId); 5623b3eb3cSopenharmony_ci 5723b3eb3cSopenharmony_ci void SetCurrentSubwindow(const RefPtr<Subwindow>& subwindow); 5823b3eb3cSopenharmony_ci 5923b3eb3cSopenharmony_ci const RefPtr<Subwindow>& GetCurrentWindow(); 6023b3eb3cSopenharmony_ci Rect GetParentWindowRect(); 6123b3eb3cSopenharmony_ci 6223b3eb3cSopenharmony_ci RefPtr<Subwindow> ShowPreviewNG(bool isStartDraggingFromSubWindow); 6323b3eb3cSopenharmony_ci void HidePreviewNG(); 6423b3eb3cSopenharmony_ci void ShowMenu(const RefPtr<Component>& newComponent); 6523b3eb3cSopenharmony_ci void ShowMenuNG(const RefPtr<NG::FrameNode>& menuNode, const NG::MenuParam& menuParam, 6623b3eb3cSopenharmony_ci const RefPtr<NG::FrameNode>& targetNode, const NG::OffsetF& offset); 6723b3eb3cSopenharmony_ci void ShowMenuNG(std::function<void()>&& buildFunc, std::function<void()>&& previewBuildFunc, 6823b3eb3cSopenharmony_ci const NG::MenuParam& menuParam, const RefPtr<NG::FrameNode>& targetNode, const NG::OffsetF& offset); 6923b3eb3cSopenharmony_ci ACE_FORCE_EXPORT void HideMenuNG(const RefPtr<NG::FrameNode>& menu, int32_t targetId); 7023b3eb3cSopenharmony_ci ACE_FORCE_EXPORT void HideMenuNG(bool showPreviewAnimation = true, bool startDrag = false); 7123b3eb3cSopenharmony_ci void UpdateHideMenuOffsetNG(const NG::OffsetF& offset = NG::OffsetF(0.0f, 0.0f), float menuScale = 1.0f, 7223b3eb3cSopenharmony_ci bool isRedragStart = false, int32_t menuWrapperId = -1); 7323b3eb3cSopenharmony_ci void ContextMenuSwitchDragPreviewAnimation(const RefPtr<NG::FrameNode>& dragPreviewNode, 7423b3eb3cSopenharmony_ci const NG::OffsetF& offset = NG::OffsetF(0.0f, 0.0f)); 7523b3eb3cSopenharmony_ci void UpdatePreviewPosition(); 7623b3eb3cSopenharmony_ci bool GetMenuPreviewCenter(NG::OffsetF& offset); 7723b3eb3cSopenharmony_ci void ShowPopup(const RefPtr<Component>& newComponent, bool disableTouchEvent = true); 7823b3eb3cSopenharmony_ci void ShowPopupNG(const RefPtr<NG::FrameNode>& targetNode, const NG::PopupInfo& popupInfo, 7923b3eb3cSopenharmony_ci const std::function<void(int32_t)>&& onWillDismiss = nullptr, bool interactiveDismiss = true); 8023b3eb3cSopenharmony_ci void HidePopupNG(int32_t targetId, int32_t instanceId = -1); 8123b3eb3cSopenharmony_ci bool CancelPopup(const std::string& id); 8223b3eb3cSopenharmony_ci void CloseMenu(); 8323b3eb3cSopenharmony_ci void ClearMenu(); 8423b3eb3cSopenharmony_ci void ClearMenuNG(int32_t instanceId = -1, int32_t targetId = -1, bool inWindow = true, bool showAnimation = false); 8523b3eb3cSopenharmony_ci void ClearPopupInSubwindow(int32_t instanceId = -1); 8623b3eb3cSopenharmony_ci ACE_FORCE_EXPORT RefPtr<NG::FrameNode> ShowDialogNG( 8723b3eb3cSopenharmony_ci const DialogProperties& dialogProps, std::function<void()>&& buildFunc); 8823b3eb3cSopenharmony_ci RefPtr<NG::FrameNode> ShowDialogNGWithNode(const DialogProperties& dialogProps, 8923b3eb3cSopenharmony_ci const RefPtr<NG::UINode>& customNode); 9023b3eb3cSopenharmony_ci void CloseDialogNG(const RefPtr<NG::FrameNode>& dialogNode); 9123b3eb3cSopenharmony_ci ACE_FORCE_EXPORT void OpenCustomDialogNG( 9223b3eb3cSopenharmony_ci const DialogProperties& dialogProps, std::function<void(int32_t)>&& callback); 9323b3eb3cSopenharmony_ci ACE_FORCE_EXPORT void CloseCustomDialogNG(int32_t dialogId); 9423b3eb3cSopenharmony_ci ACE_FORCE_EXPORT void CloseCustomDialogNG(const WeakPtr<NG::UINode>& node, std::function<void(int32_t)>&& callback); 9523b3eb3cSopenharmony_ci ACE_FORCE_EXPORT void UpdateCustomDialogNG( 9623b3eb3cSopenharmony_ci const WeakPtr<NG::UINode>& node, const PromptDialogAttr& dialogAttr, std::function<void(int32_t)>&& callback); 9723b3eb3cSopenharmony_ci void HideSubWindowNG(); 9823b3eb3cSopenharmony_ci void HideDialogSubWindow(int32_t instanceId); 9923b3eb3cSopenharmony_ci void SetHotAreas(const std::vector<Rect>& rects, int32_t nodeId = -1, int32_t instanceId = -1); 10023b3eb3cSopenharmony_ci void AddDialogSubwindow(int32_t instanceId, const RefPtr<Subwindow>& subwindow); 10123b3eb3cSopenharmony_ci // Get the dialog subwindow of instance, return the window or nullptr. 10223b3eb3cSopenharmony_ci int32_t GetDialogSubwindowInstanceId(int32_t SubwindowId); 10323b3eb3cSopenharmony_ci const RefPtr<Subwindow> GetDialogSubwindow(int32_t instanceId); 10423b3eb3cSopenharmony_ci void SetCurrentDialogSubwindow(const RefPtr<Subwindow>& subwindow); 10523b3eb3cSopenharmony_ci const RefPtr<Subwindow>& GetCurrentDialogWindow(); 10623b3eb3cSopenharmony_ci void DeleteHotAreas(int32_t subwindowId, int32_t nodeId); 10723b3eb3cSopenharmony_ci 10823b3eb3cSopenharmony_ci void ClearToastInSubwindow(); 10923b3eb3cSopenharmony_ci ACE_FORCE_EXPORT void ShowToast(const NG::ToastInfo& toastInfo, std::function<void(int32_t)>&& callback); 11023b3eb3cSopenharmony_ci void ShowToastNG(const NG::ToastInfo& toastInfo, std::function<void(int32_t)>&& callback); 11123b3eb3cSopenharmony_ci const RefPtr<Subwindow> GetToastSubwindow(int32_t instanceId); 11223b3eb3cSopenharmony_ci void AddToastSubwindow(int32_t instanceId, RefPtr<Subwindow> subwindow); 11323b3eb3cSopenharmony_ci void HideToastSubWindowNG(); 11423b3eb3cSopenharmony_ci ToastWindowType GetToastWindowType(int32_t instanceId); 11523b3eb3cSopenharmony_ci ACE_FORCE_EXPORT void CloseToast( 11623b3eb3cSopenharmony_ci const int32_t toastId, const NG::ToastShowMode& showMode, std::function<void(int32_t)>&& callback); 11723b3eb3cSopenharmony_ci ACE_FORCE_EXPORT void ShowDialog(const std::string& title, const std::string& message, 11823b3eb3cSopenharmony_ci const std::vector<ButtonInfo>& buttons, bool autoCancel, std::function<void(int32_t, int32_t)>&& napiCallback, 11923b3eb3cSopenharmony_ci const std::set<std::string>& dialogCallbacks); 12023b3eb3cSopenharmony_ci ACE_FORCE_EXPORT void ShowDialog(const PromptDialogAttr& dialogAttr, const std::vector<ButtonInfo>& buttons, 12123b3eb3cSopenharmony_ci std::function<void(int32_t, int32_t)>&& napiCallback, const std::set<std::string>& dialogCallbacks); 12223b3eb3cSopenharmony_ci ACE_FORCE_EXPORT void ShowActionMenu(const std::string& title, const std::vector<ButtonInfo>& button, 12323b3eb3cSopenharmony_ci std::function<void(int32_t, int32_t)>&& callback); 12423b3eb3cSopenharmony_ci void CloseDialog(int32_t instanceId); 12523b3eb3cSopenharmony_ci void RequestFocusSubwindow(int32_t instanceId); 12623b3eb3cSopenharmony_ci ACE_FORCE_EXPORT void OpenCustomDialog(const PromptDialogAttr &dialogAttr, std::function<void(int32_t)> &&callback); 12723b3eb3cSopenharmony_ci void CloseCustomDialog(const int32_t dialogId); 12823b3eb3cSopenharmony_ci void CloseCustomDialog(const WeakPtr<NG::UINode>& node, std::function<void(int32_t)> &&callback); 12923b3eb3cSopenharmony_ci 13023b3eb3cSopenharmony_ci bool GetShown(); 13123b3eb3cSopenharmony_ci void ResizeWindowForFoldStatus(int32_t parentContainerId); 13223b3eb3cSopenharmony_ci void MarkDirtyDialogSafeArea(); 13323b3eb3cSopenharmony_ci void HideSystemTopMostWindow(); 13423b3eb3cSopenharmony_ci const RefPtr<Subwindow> GetSystemToastWindow(int32_t instanceId); 13523b3eb3cSopenharmony_ci void AddSystemToastWindow(int32_t instanceId, RefPtr<Subwindow> subwindow); 13623b3eb3cSopenharmony_ci void ClearToastInSystemSubwindow(); 13723b3eb3cSopenharmony_ci void OnWindowSizeChanged(int32_t instanceId, Rect windowRect, WindowSizeChangeReason reason); 13823b3eb3cSopenharmony_ci bool IsFreeMultiWindow(int32_t instanceId) const; 13923b3eb3cSopenharmony_ci 14023b3eb3cSopenharmony_ci RefPtr<NG::FrameNode> GetSubwindowDialogNodeWithExistContent(const RefPtr<NG::UINode>& node); 14123b3eb3cSopenharmony_ci 14223b3eb3cSopenharmony_ci void SetRect(const NG::RectF& rect, int32_t instanceId); 14323b3eb3cSopenharmony_ci 14423b3eb3cSopenharmony_ciprivate: 14523b3eb3cSopenharmony_ci RefPtr<Subwindow> GetOrCreateSubWindow(); 14623b3eb3cSopenharmony_ci RefPtr<Subwindow> GetOrCreateSystemSubWindow(int32_t containerId); 14723b3eb3cSopenharmony_ci RefPtr<Subwindow> GetOrCreateToastWindow(int32_t containerId, const NG::ToastShowMode& showMode); 14823b3eb3cSopenharmony_ci RefPtr<Subwindow> GetOrCreateToastWindowNG(int32_t containerId, const ToastWindowType& windowType, 14923b3eb3cSopenharmony_ci uint32_t mainWindowId); 15023b3eb3cSopenharmony_ci const std::vector<RefPtr<NG::OverlayManager>> GetAllSubOverlayManager(); 15123b3eb3cSopenharmony_ci static std::mutex instanceMutex_; 15223b3eb3cSopenharmony_ci static std::shared_ptr<SubwindowManager> instance_; 15323b3eb3cSopenharmony_ci 15423b3eb3cSopenharmony_ci std::mutex mutex_; 15523b3eb3cSopenharmony_ci std::unordered_map<uint32_t, int32_t> containerMap_; 15623b3eb3cSopenharmony_ci 15723b3eb3cSopenharmony_ci std::mutex parentMutex_; 15823b3eb3cSopenharmony_ci std::unordered_map<int32_t, int32_t> parentContainerMap_; 15923b3eb3cSopenharmony_ci 16023b3eb3cSopenharmony_ci // Used to save the relationship between container and subwindow, it is 1:1 16123b3eb3cSopenharmony_ci std::mutex subwindowMutex_; 16223b3eb3cSopenharmony_ci SubwindowMap subwindowMap_; 16323b3eb3cSopenharmony_ci static thread_local RefPtr<Subwindow> currentSubwindow_; 16423b3eb3cSopenharmony_ci 16523b3eb3cSopenharmony_ci std::mutex toastMutex_; 16623b3eb3cSopenharmony_ci SubwindowMap toastWindowMap_; 16723b3eb3cSopenharmony_ci // Used to save the relationship between container and dialog subwindow, it is 1:1 16823b3eb3cSopenharmony_ci std::mutex dialogSubwindowMutex_; 16923b3eb3cSopenharmony_ci SubwindowMap dialogSubwindowMap_; 17023b3eb3cSopenharmony_ci std::mutex currentDialogSubwindowMutex_; 17123b3eb3cSopenharmony_ci RefPtr<Subwindow> currentDialogSubwindow_; 17223b3eb3cSopenharmony_ci std::mutex systemToastMutex_; 17323b3eb3cSopenharmony_ci SubwindowMap systemToastWindowMap_; 17423b3eb3cSopenharmony_ci Rect uiExtensionWindowRect_; 17523b3eb3cSopenharmony_ci}; 17623b3eb3cSopenharmony_ci 17723b3eb3cSopenharmony_ci} // namespace OHOS::Ace 17823b3eb3cSopenharmony_ci 17923b3eb3cSopenharmony_ci#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_SUBWINDOW_SUBWINDOW_MANAGER_H 180