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_BASE_SUBWINDOW_SUBWINDOW_H
17 #define FOUNDATION_ACE_FRAMEWORKS_BASE_SUBWINDOW_SUBWINDOW_H
18 
19 #include <set>
20 
21 #include "base/geometry/ng/rect_t.h"
22 #include "base/memory/ace_type.h"
23 #include "base/memory/referenced.h"
24 #include "core/components/dialog/dialog_properties.h"
25 #include "core/components_ng/base/frame_node.h"
26 #include "core/components_ng/pattern/overlay/overlay_manager.h"
27 #include "core/components_ng/property/menu_property.h"
28 #include "core/pipeline/base/component.h"
29 
30 namespace OHOS::Ace {
31 enum class ToastWindowType {
32     TOAST_IN_TYPE_APP_SUB_WINDOW = 0,
33     TOAST_IN_TYPE_SYSTEM_SUB_WINDOW,
34     TOAST_IN_TYPE_TOAST,
35     TOAST_IN_TYPE_SYSTEM_FLOAT,
36     TOAST_WINDOW_COUNT
37 };
38 
39 class ACE_EXPORT Subwindow : public AceType {
40     DECLARE_ACE_TYPE(Subwindow, AceType)
41 
42 public:
43     static RefPtr<Subwindow> CreateSubwindow(int32_t instanceId);
44 
45     virtual void InitContainer() = 0;
46     virtual void ResizeWindow() = 0;
47     virtual NG::RectF GetRect() = 0;
48     virtual void ShowMenu(const RefPtr<Component>& newComponent) = 0;
49     virtual void ShowMenuNG(const RefPtr<NG::FrameNode> menuNode, const NG::MenuParam& menuParam,
50         const RefPtr<NG::FrameNode>& targetNode, const NG::OffsetF& offset) = 0;
51     virtual void ShowMenuNG(std::function<void()>&& buildFunc, std::function<void()>&& previewBuildFunc,
52         const NG::MenuParam& menuParam, const RefPtr<NG::FrameNode>& targetNode, const NG::OffsetF& offset) = 0;
53     virtual bool ShowPreviewNG(bool isStartDraggingFromSubWindow) = 0;
54     virtual void HidePreviewNG() = 0;
55     virtual void HideMenuNG(const RefPtr<NG::FrameNode>& menu, int32_t targetId) = 0;
56     virtual void HideMenuNG(bool showPreviewAnimation = true, bool startDrag = false) = 0;
57     virtual void UpdateHideMenuOffsetNG(const NG::OffsetF& offset = NG::OffsetF(0.0f, 0.0f),
58         float meunuScale = 1.0f, bool isRedragStart = false, int32_t menuWrapperId = -1) = 0;
59     virtual void UpdatePreviewPosition() = 0;
60     virtual bool GetMenuPreviewCenter(NG::OffsetF& offset) = 0;
61     virtual void ContextMenuSwitchDragPreviewAnimationtNG(const RefPtr<NG::FrameNode>& dragPreviewNode,
62         const NG::OffsetF& offset = NG::OffsetF(0.0f, 0.0f)) = 0;
63     virtual void ShowPopup(const RefPtr<Component>& newComponent, bool disableTouchEvent = true) = 0;
64     virtual void ShowPopupNG(int32_t targetId, const NG::PopupInfo& popupInfo,
65         const std::function<void(int32_t)>&& onWillDismiss = nullptr, bool interactiveDismiss = true) = 0;
66     virtual void HidePopupNG(int32_t targetId) = 0;
67     virtual void GetPopupInfoNG(int32_t targetId, NG::PopupInfo& popupInfo) = 0;
68     virtual bool CancelPopup(const std::string& id) = 0;
69     virtual void CloseMenu() = 0;
ClearMenu()70     virtual void ClearMenu() {};
71     virtual void ClearMenuNG(int32_t targetId = -1, bool inWindow = true, bool showAnimation = false) = 0;
72     virtual void ClearPopupNG() = 0;
73     virtual RefPtr<NG::FrameNode> ShowDialogNG(
74         const DialogProperties& dialogProps, std::function<void()>&& buildFunc) = 0;
75     virtual RefPtr<NG::FrameNode> ShowDialogNGWithNode(
76         const DialogProperties& dialogProps, const RefPtr<NG::UINode>& customNode) = 0;
77     virtual void CloseDialogNG(const RefPtr<NG::FrameNode>& dialogNode) = 0;
78     virtual void OpenCustomDialogNG(const DialogProperties& dialogProps, std::function<void(int32_t)>&& callback) = 0;
79     virtual void CloseCustomDialogNG(int32_t dialogId) = 0;
80     virtual void CloseCustomDialogNG(const WeakPtr<NG::UINode>& node, std::function<void(int32_t)>&& callback) = 0;
81     virtual void UpdateCustomDialogNG(const WeakPtr<NG::UINode>& node, const DialogProperties& dialogProps,
82         std::function<void(int32_t)>&& callback) = 0;
83     virtual void HideSubWindowNG() = 0;
84     virtual int32_t GetChildContainerId() const = 0;
85     virtual bool GetShown() = 0;
86     virtual void MarkDirtyDialogSafeArea() = 0;
87 
88     // Add interface for hot regions
SetHotAreas(const std::vector<Rect> & rects,int32_t nodeId)89     virtual void SetHotAreas(const std::vector<Rect>& rects, int32_t nodeId) {};
DeleteHotAreas(int32_t nodeId)90     virtual void DeleteHotAreas(int32_t nodeId) {};
91 
92     // Add interface to provide the size and offset of the parent window
93     virtual Rect GetParentWindowRect() const = 0;
94     virtual Rect GetUIExtensionHostWindowRect() const = 0;
95     virtual bool CheckHostWindowStatus() const = 0;
96     virtual bool IsFreeMultiWindow() const = 0;
97     virtual void OnFreeMultiWindowSwitch(bool enable) = 0;
98     virtual int32_t RegisterFreeMultiWindowSwitchCallback(std::function<void(bool)>&& callback) = 0;
99     virtual void UnRegisterFreeMultiWindowSwitchCallback(int32_t callbackId) = 0;
100 
GetSubwindowId()101     int32_t GetSubwindowId() const
102     {
103         return subwindowId_;
104     }
105 
SetSubwindowId(int32_t id)106     void SetSubwindowId(int32_t id)
107     {
108         subwindowId_ = id;
109     }
110 
GetUIExtensionHostWindowId()111     int32_t GetUIExtensionHostWindowId() const
112     {
113         return uiExtensionHostWindowId_;
114     }
115 
SetUIExtensionHostWindowId(int32_t id)116     void SetUIExtensionHostWindowId(int32_t id)
117     {
118         uiExtensionHostWindowId_ = id;
119     }
120 
SetAboveApps(bool isAboveApps)121     void SetAboveApps(bool isAboveApps)
122     {
123         isAboveApps_ = isAboveApps;
124     }
125 
GetAboveApps()126     bool GetAboveApps() const
127     {
128         return isAboveApps_;
129     }
130 
SetToastWindowType(const ToastWindowType & type)131     void SetToastWindowType(const ToastWindowType& type)
132     {
133         toastWindowType_ = type;
134         SetAboveApps(true);
135     }
136 
SetMainWindowId(uint32_t mainWindowId)137     void SetMainWindowId(uint32_t mainWindowId)
138     {
139         mainWindowId_ = mainWindowId;
140     }
141 
GetMainWindowId()142     uint32_t GetMainWindowId() const
143     {
144         return mainWindowId_;
145     }
146 
GetToastWindowType()147     ToastWindowType GetToastWindowType() const
148     {
149         return toastWindowType_;
150     }
151 
SetIsSystemTopMost(bool isSystemTopMost)152     void SetIsSystemTopMost(bool isSystemTopMost)
153     {
154         isSystemTopMost_ = isSystemTopMost;
155     }
156 
IsSystemTopMost()157     bool IsSystemTopMost() const
158     {
159         return isSystemTopMost_;
160     }
161 
SetIsRosenWindowCreate(bool isRosenWindowCreate)162     void SetIsRosenWindowCreate(bool isRosenWindowCreate)
163     {
164         isRosenWindowCreate_ = isRosenWindowCreate;
165     }
166 
GetIsRosenWindowCreate()167     bool GetIsRosenWindowCreate() const
168     {
169         return isRosenWindowCreate_;
170     }
171 
172     virtual void ClearToast() = 0;
173     virtual void ShowToast(const NG::ToastInfo& toastInfo) = 0;
174     virtual void ShowDialog(const std::string& title, const std::string& message,
175         const std::vector<ButtonInfo>& buttons, bool autoCancel, std::function<void(int32_t, int32_t)>&& callback,
176         const std::set<std::string>& callbacks) = 0;
177     virtual void ShowDialog(const PromptDialogAttr& dialogAttr, const std::vector<ButtonInfo>& buttons,
178         std::function<void(int32_t, int32_t)>&& callback, const std::set<std::string>& callbacks) = 0;
179     virtual void ShowActionMenu(const std::string& title, const std::vector<ButtonInfo>& button,
180         std::function<void(int32_t, int32_t)>&& callback) = 0;
181     virtual void CloseDialog(int32_t instanceId) = 0;
182     virtual void OpenCustomDialog(const PromptDialogAttr& dialogAttr, std::function<void(int32_t)>&& callback) = 0;
183     virtual void CloseCustomDialog(const int32_t dialogId) = 0;
184     virtual void CloseCustomDialog(const WeakPtr<NG::UINode>& node, std::function<void(int32_t)> &&callback) = 0;
185     virtual const RefPtr<NG::OverlayManager> GetOverlayManager() = 0;
186     virtual bool IsFocused() = 0;
187     virtual void RequestFocus() = 0;
188     virtual void ResizeWindowForFoldStatus() = 0;
189     virtual void ResizeWindowForFoldStatus(int32_t parentContainerId) = 0;
190     virtual bool Close() = 0;
191 
192 private:
193     int32_t subwindowId_ = 0;
194     int32_t uiExtensionHostWindowId_ = 0;
195     bool isAboveApps_ = false;
196     bool isSystemTopMost_ = false;
197     bool isRosenWindowCreate_ = false;
198     ToastWindowType toastWindowType_ = ToastWindowType::TOAST_IN_TYPE_TOAST;
199     // toast main window ID
200     uint32_t mainWindowId_ = 0;
201 };
202 
203 } // namespace OHOS::Ace
204 
205 #endif // FOUNDATION_ACE_FRAMEWORKS_BASE_SUBWINDOW_SUBWINDOW_H
206