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