/* * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_SUBWINDOW_SUBWINDOW_MANAGER_H #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_SUBWINDOW_SUBWINDOW_MANAGER_H #include #include #include #include #include "base/memory/referenced.h" #include "base/subwindow/subwindow.h" #include "base/utils/macros.h" #include "base/utils/noncopyable.h" #include "core/components/dialog/dialog_properties.h" #include "core/components_ng/base/frame_node.h" #include "core/components_ng/pattern/overlay/overlay_manager.h" namespace OHOS::Ace { using SubwindowMap = std::unordered_map>; class ACE_FORCE_EXPORT SubwindowManager final : public NonCopyable { public: // Get the instance static std::shared_ptr GetInstance(); void AddContainerId(uint32_t windowId, int32_t containerId); void RemoveContainerId(uint32_t windowId); int32_t GetContainerId(uint32_t windowId); void AddParentContainerId(int32_t containerId, int32_t parentContainerId); void RemoveParentContainerId(int32_t containerId); int32_t GetParentContainerId(int32_t containerId); int32_t GetSubContainerId(int32_t parentContainerId); void AddSubwindow(int32_t instanceId, RefPtr); void RemoveSubwindow(int32_t instanceId); // Get the subwindow of instance, return the window or nullptr. const RefPtr GetSubwindow(int32_t instanceId); void HideCurrentSubwindow(); void SetCurrentSubwindowName(const std::string& currentSubwindow); std::string GetCurrentSubWindowName(); void SetCurrentSubwindow(const RefPtr& subwindow); const RefPtr& GetCurrentWindow(); Rect GetParentWindowRect(); RefPtr ShowPreviewNG(bool isStartDraggingFromSubWindow); void HidePreviewNG(); void ShowMenu(const RefPtr& newComponent); void ShowMenuNG(const RefPtr& menuNode, const NG::MenuParam& menuParam, const RefPtr& targetNode, const NG::OffsetF& offset); void ShowMenuNG(std::function&& buildFunc, std::function&& previewBuildFunc, const NG::MenuParam& menuParam, const RefPtr& targetNode, const NG::OffsetF& offset); void HideMenuNG(const RefPtr& menu, int32_t targetId); void HideMenuNG(bool showPreviewAnimation = true, bool startDrag = false); void UpdateHideMenuOffsetNG(const NG::OffsetF& offset = NG::OffsetF(0.0f, 0.0f), float menuScale = 1.0f, bool isRedragStart = false, int32_t menuWrapperId = -1); void UpdatePreviewPosition(); bool GetMenuPreviewCenter(NG::OffsetF& offset); void ContextMenuSwitchDragPreviewAnimation(const RefPtr& dragPreviewNode, const NG::OffsetF& offset = NG::OffsetF(0.0f, 0.0f)); void ShowPopup(const RefPtr& newComponent, bool disableTouchEvent = true); void ShowPopupNG(const RefPtr& targetNode, const NG::PopupInfo& popupInfo, const std::function&& onWillDismiss = nullptr, bool interactiveDismiss = true); void HidePopupNG(int32_t targetId, int32_t instanceId = -1); bool CancelPopup(const std::string& id); void CloseMenu(); void ClearMenu(); void ClearMenuNG(int32_t instanceId = -1, int32_t targetId = -1, bool inWindow = true, bool showAnimation = false); void ClearPopupInSubwindow(int32_t instanceId = -1); RefPtr ShowDialogNG(const DialogProperties& dialogProps, std::function&& buildFunc); RefPtr ShowDialogNGWithNode(const DialogProperties& dialogProps, const RefPtr& customNode); void CloseDialogNG(const RefPtr& dialogNode); void OpenCustomDialogNG(const DialogProperties& dialogProps, std::function&& callback); void CloseCustomDialogNG(int32_t dialogId); void CloseCustomDialogNG(const WeakPtr& node, std::function&& callback); void UpdateCustomDialogNG(const WeakPtr& node, const PromptDialogAttr &dialogAttr, std::function&& callback); void HideSubWindowNG(); void HideDialogSubWindow(int32_t instanceId); void SetHotAreas(const std::vector& rects, int32_t nodeId = -1, int32_t instanceId = -1); int32_t GetDialogSubWindowId() { return dialogSubWindowId_; } void SetDialogSubWindowId(int32_t dialogSubWindowId) { dialogSubWindowId_ = dialogSubWindowId; } void AddDialogSubwindow(int32_t instanceId, const RefPtr& subwindow); // Get the dialog subwindow of instance, return the window or nullptr. int32_t GetDialogSubwindowInstanceId(int32_t SubwindowId); const RefPtr GetDialogSubwindow(int32_t instanceId); void SetCurrentDialogSubwindow(const RefPtr& subwindow); const RefPtr& GetCurrentDialogWindow(); void DeleteHotAreas(int32_t subwindowId, int32_t nodeId); void ClearToastInSubwindow(); void ShowToast(const NG::ToastInfo& toastInfo); void ShowToastNG(const NG::ToastInfo& toastInfo); const RefPtr GetToastSubwindow(int32_t instanceId); void AddToastSubwindow(int32_t instanceId, RefPtr subwindow); void HideToastSubWindowNG(); ToastWindowType GetToastWindowType(int32_t instanceId); void ShowDialog(const std::string& title, const std::string& message, const std::vector& buttons, bool autoCancel, std::function&& napiCallback, const std::set& dialogCallbacks); void ShowDialog(const PromptDialogAttr& dialogAttr, const std::vector& buttons, std::function&& napiCallback, const std::set& dialogCallbacks); void ShowActionMenu(const std::string& title, const std::vector& button, std::function&& callback); void CloseDialog(int32_t instanceId); void RequestFocusSubwindow(int32_t instanceId); void OpenCustomDialog(const PromptDialogAttr &dialogAttr, std::function &&callback); void CloseCustomDialog(const int32_t dialogId); void CloseCustomDialog(const WeakPtr& node, std::function &&callback); bool GetShown(); void ResizeWindowForFoldStatus(int32_t parentContainerId); void MarkDirtyDialogSafeArea(); void OnWindowSizeChanged(int32_t instanceId, Rect windowRect, WindowSizeChangeReason reason); void HideSystemTopMostWindow(); const RefPtr GetSystemToastWindow(int32_t instanceId); void AddSystemToastWindow(int32_t instanceId, RefPtr subwindow); void ClearToastInSystemSubwindow(); bool IsSubwindowExist(RefPtr subwindow); bool IsFreeMultiWindow(int32_t instanceId) const; RefPtr GetSubwindowDialogNodeWithExistContent(const RefPtr& node); private: RefPtr GetOrCreateSubWindow(bool isDialog = false); RefPtr GetOrCreateSystemSubWindow(int32_t containerId); RefPtr GetOrCreateToastWindow(int32_t containerId, const NG::ToastShowMode& showMode); RefPtr GetOrCreateToastWindowNG(int32_t containerId, const ToastWindowType& windowType, uint32_t mainWindowId); static std::mutex instanceMutex_; static std::shared_ptr instance_; std::mutex mutex_; std::unordered_map containerMap_; std::mutex parentMutex_; std::unordered_map parentContainerMap_; // Used to save the relationship between container and subwindow, it is 1:1 std::mutex subwindowMutex_; SubwindowMap subwindowMap_; int32_t dialogSubWindowId_; std::mutex currentSubwindowMutex_; std::string currentSubwindowName_; RefPtr currentSubwindow_; std::mutex toastMutex_; SubwindowMap toastWindowMap_; // Used to save the relationship between container and dialog subwindow, it is 1:1 std::mutex dialogSubwindowMutex_; SubwindowMap dialogSubwindowMap_; std::mutex currentDialogSubwindowMutex_; RefPtr currentDialogSubwindow_; Rect uiExtensionWindowRect_; std::mutex systemToastMutex_; SubwindowMap systemToastWindowMap_; }; } // namespace OHOS::Ace #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_SUBWINDOW_SUBWINDOW_MANAGER_H