• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_SUBWINDOW_SUBWINDOW_MANAGER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_SUBWINDOW_SUBWINDOW_MANAGER_H
18 
19 #include <mutex>
20 #include <set>
21 #include <unordered_map>
22 
23 #include "base/memory/referenced.h"
24 #include "base/subwindow/subwindow.h"
25 #include "base/utils/macros.h"
26 #include "base/utils/noncopyable.h"
27 #include "core/components/dialog/dialog_properties.h"
28 #include "core/components_ng/base/frame_node.h"
29 #include "core/components_ng/pattern/overlay/overlay_manager.h"
30 
31 namespace OHOS::Ace {
32 
33 constexpr int32_t MIN_SUBCONTAINER_ID = 1000000;
34 constexpr int32_t MIN_PA_SERVICE_ID = 100000;
35 
36 using SubwindowMap = std::unordered_map<int32_t, RefPtr<Subwindow>>;
37 
38 class ACE_FORCE_EXPORT SubwindowManager final : public NonCopyable {
39 public:
40     // Get the instance
41     static std::shared_ptr<SubwindowManager> GetInstance();
42 
43     void AddContainerId(uint32_t windowId, int32_t containerId);
44     void RemoveContainerId(uint32_t windowId);
45     int32_t GetContainerId(uint32_t windowId);
46 
47     void AddParentContainerId(int32_t containerId, int32_t parentContainerId);
48     void RemoveParentContainerId(int32_t containerId);
49     int32_t GetParentContainerId(int32_t containerId);
50 
51     void AddSubwindow(int32_t instanceId, RefPtr<Subwindow>);
52     void RemoveSubwindow(int32_t instanceId);
53 
54     // Get the subwindow of instance, return the window or nullptr.
55     const RefPtr<Subwindow> GetSubwindow(int32_t instanceId);
56 
57     void HideCurrentSubwindow();
58 
59     void SetCurrentSubwindowName(const std::string& currentSubwindow);
60     std::string GetCurrentSubWindowName();
61 
62     void SetCurrentSubwindow(const RefPtr<Subwindow>& subwindow);
63 
64     const RefPtr<Subwindow>& GetCurrentWindow();
65 
66     void ShowMenu(const RefPtr<Component>& newComponent);
67     void ShowMenuNG(const RefPtr<NG::FrameNode> menuNode, int32_t targetId, const NG::OffsetF& offset);
68     void HideMenuNG(int32_t targetId);
69     void HideMenuNG();
70     void ShowPopup(const RefPtr<Component>& newComponent, bool disableTouchEvent = true);
71     void ShowPopupNG(int32_t targetId, const NG::PopupInfo& popupInfo);
72     void HidePopupNG(int32_t targetId);
73     void HidePopupNG();
74     bool CancelPopup(const std::string& id);
75     void CloseMenu();
76     void ClearMenu();
77     void ClearMenuNG();
78     RefPtr<NG::FrameNode> ShowDialogNG(const DialogProperties& dialogProps, const RefPtr<NG::UINode>& customNode);
79     void HideSubWindowNG();
80 
81     void SetHotAreas(const std::vector<Rect>& rects);
82 
83     void AddDialogSubwindow(int32_t instanceId, const RefPtr<Subwindow>& subwindow);
84     // Get the dialog subwindow of instance, return the window or nullptr.
85     const RefPtr<Subwindow> GetDialogSubwindow(int32_t instanceId);
86     void SetCurrentDialogSubwindow(const RefPtr<Subwindow>& subwindow);
87     const RefPtr<Subwindow>& GetCurrentDialogWindow();
88 
89     void ShowToast(const std::string& message, int32_t duration, const std::string& bottom);
90     void ShowDialog(const std::string& title, const std::string& message, const std::vector<ButtonInfo>& buttons,
91         bool autoCancel, std::function<void(int32_t, int32_t)>&& napiCallback,
92         const std::set<std::string>& dialogCallbacks);
93     void ShowActionMenu(const std::string& title, const std::vector<ButtonInfo>& button,
94         std::function<void(int32_t, int32_t)>&& callback);
95     void CloseDialog(int32_t instanceId);
96 
97 private:
98     RefPtr<Subwindow> GetOrCreateSubWindow();
99 
100     static std::mutex instanceMutex_;
101     static std::shared_ptr<SubwindowManager> instance_;
102 
103     std::mutex mutex_;
104     std::unordered_map<uint32_t, int32_t> containerMap_;
105 
106     std::mutex parentMutex_;
107     std::unordered_map<int32_t, int32_t> parentContainerMap_;
108 
109     // Used to save the relationship between container and subwindow, it is 1:1
110     std::mutex subwindowMutex_;
111     SubwindowMap subwindowMap_;
112 
113     std::mutex currentSubwindowMutex_;
114     std::string currentSubwindowName_;
115 
116     RefPtr<Subwindow> currentSubwindow_;
117 
118     // Used to save the relationship between container and dialog subwindow, it is 1:1
119     std::mutex dialogSubwindowMutex_;
120     SubwindowMap dialogSubwindowMap_;
121     std::mutex currentDialogSubwindowMutex_;
122     RefPtr<Subwindow> currentDialogSubwindow_;
123 };
124 
125 } // namespace OHOS::Ace
126 
127 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_SUBWINDOW_SUBWINDOW_MANAGER_H
128