• 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_ADAPTER_OHOS_ENTRANCE_SUBWINDOW_OHOS_H
17 #define FOUNDATION_ACE_ADAPTER_OHOS_ENTRANCE_SUBWINDOW_OHOS_H
18 
19 #include <unordered_map>
20 
21 #include "event_handler.h"
22 #include "event_runner.h"
23 #include "resource_manager.h"
24 #include "wm/window.h"
25 
26 #include "adapter/ohos/entrance/platform_event_callback.h"
27 #include "base/resource/asset_manager.h"
28 #include "base/subwindow/subwindow.h"
29 #include "base/subwindow/subwindow_manager.h"
30 #include "base/thread/task_executor.h"
31 #include "core/common/ace_view.h"
32 #include "core/common/js_message_dispatcher.h"
33 #include "core/components/dialog/dialog_properties.h"
34 #include "core/components/select_popup/select_popup_component.h"
35 #include "core/components/stack/stack_element.h"
36 #include "core/components/tween/tween_component.h"
37 #include "core/components_ng/base/frame_node.h"
38 #include "core/components_ng/pattern/overlay/overlay_manager.h"
39 #include "core/pipeline/pipeline_base.h"
40 #include "core/pipeline_ng/pipeline_context.h"
41 
42 namespace OHOS::Rosen {
43 class Window;
44 class WindowOption;
45 class RSUIDirector;
46 } // namespace OHOS::Rosen
47 
48 namespace OHOS::Ace {
49 
50 class SubwindowOhos : public Subwindow {
51     DECLARE_ACE_TYPE(SubwindowOhos, Subwindow)
52 
53 public:
54     explicit SubwindowOhos(int32_t instanceId);
55     ~SubwindowOhos() = default;
56 
57     void InitContainer() override;
58     void ResizeWindow() override;
59     void ResizeWindowForMenu() override;
60     NG::RectF GetRect() override;
61     void ShowMenu(const RefPtr<Component>& newComponent) override;
62     void ShowMenuNG(const RefPtr<NG::FrameNode> customNode, const NG::MenuParam& menuParam,
63         const RefPtr<NG::FrameNode>& targetNode, const NG::OffsetF& offset) override;
64     void ShowMenuNG(std::function<void()>&& buildFunc, std::function<void()>&& previewBuildFunc,
65         const NG::MenuParam& menuParam, const RefPtr<NG::FrameNode>& targetNode, const NG::OffsetF& offset) override;
66     bool ShowPreviewNG(bool isStartDraggingFromSubWindow = false) override;
67     void HidePreviewNG() override;
68     void HideMenuNG(const RefPtr<NG::FrameNode>& menu, int32_t targetId) override;
69     void HideMenuNG(bool showPreviewAnimation, bool startDrag) override;
70     void UpdateHideMenuOffsetNG(
71         const NG::OffsetF& offset, float menuScale, bool isRedragStart, int32_t menuWrapperId = -1) override;
72     void UpdatePreviewPosition() override;
73     bool GetMenuPreviewCenter(NG::OffsetF& offset) override;
74     void ContextMenuSwitchDragPreviewAnimationtNG(const RefPtr<NG::FrameNode>& dragPreviewNode,
75         const NG::OffsetF& offset) override;
76     void ShowPopup(const RefPtr<Component>& newComponent, bool disableTouchEvent = true) override;
77     void ShowPopupNG(int32_t targetId, const NG::PopupInfo& popupInfo,
78         const std::function<void(int32_t)>&& onWillDismiss = nullptr, bool interactiveDismiss = true) override;
79     void HidePopupNG(int32_t targetId) override;
80     void GetPopupInfoNG(int32_t targetId, NG::PopupInfo& popupInfo) override;
81     bool CancelPopup(const std::string& id) override;
82     void CloseMenu() override;
83     void ClearMenu() override;
84     void ClearMenuNG(int32_t targetId, bool inWindow, bool showAnimation = false) override;
85     void ClearPopupNG() override;
86     RefPtr<NG::FrameNode> ShowDialogNG(const DialogProperties& dialogProps, std::function<void()>&& buildFunc) override;
87     RefPtr<NG::FrameNode> ShowDialogNGWithNode(const DialogProperties& dialogProps,
88         const RefPtr<NG::UINode>& customNode) override;
89     void CloseDialogNG(const RefPtr<NG::FrameNode>& dialogNode) override;
90     void OpenCustomDialogNG(const DialogProperties& dialogProps, std::function<void(int32_t)>&& callback) override;
91     void CloseCustomDialogNG(int32_t dialogId) override;
92     void CloseCustomDialogNG(const WeakPtr<NG::UINode>& node, std::function<void(int32_t)>&& callback) override;
93     void UpdateCustomDialogNG(const WeakPtr<NG::UINode>& node, const DialogProperties& dialogProps,
94         std::function<void(int32_t)>&& callback) override;
95     void HideSubWindowNG() override;
GetShown()96     bool GetShown() override
97     {
98         return isShowed_;
99     }
100 
101     void SetHotAreas(const std::vector<Rect>& rects, int32_t nodeId) override;
102     void DeleteHotAreas(int32_t nodeId) override;
103     void ClearToast() override;
104     void ShowToast(const NG::ToastInfo& toastInfo) override;
105     void ShowDialog(const std::string& title, const std::string& message, const std::vector<ButtonInfo>& buttons,
106         bool autoCancel, std::function<void(int32_t, int32_t)>&& callback,
107         const std::set<std::string>& callbacks) override;
108     void ShowDialog(const PromptDialogAttr& dialogAttr, const std::vector<ButtonInfo>& buttons,
109         std::function<void(int32_t, int32_t)>&& callback, const std::set<std::string>& callbacks) override;
110     void ShowActionMenu(const std::string& title, const std::vector<ButtonInfo>& button,
111         std::function<void(int32_t, int32_t)>&& callback) override;
112     void CloseDialog(int32_t instanceId) override;
113     void OpenCustomDialog(const PromptDialogAttr& dialogAttr, std::function<void(int32_t)>&& callback) override;
114     void CloseCustomDialog(const int32_t dialogId) override;
115     void CloseCustomDialog(const WeakPtr<NG::UINode>& node, std::function<void(int32_t)>&& callback) override;
116     const RefPtr<NG::OverlayManager> GetOverlayManager() override;
117 
GetChildContainerId()118     int32_t GetChildContainerId() const override
119     {
120         return childContainerId_;
121     }
GetDialogWindow()122     sptr<OHOS::Rosen::Window> GetDialogWindow() const
123     {
124         return dialogWindow_;
125     }
IsToastWindow()126     bool IsToastWindow() const
127     {
128         return isToastWindow_;
129     }
SetIsToastWindow(bool isToastWindow)130     void SetIsToastWindow(bool isToastWindow)
131     {
132         isToastWindow_ = isToastWindow;
133     }
134 
135     void UpdateAceView(int32_t width, int32_t height, float density, int32_t containerId);
136 
137     // Gets parent window's size and offset
138     Rect GetParentWindowRect() const override;
139     Rect GetUIExtensionHostWindowRect() const override;
140     bool CheckHostWindowStatus() const override;
141     bool IsFreeMultiWindow() const override;
142     void OnFreeMultiWindowSwitch(bool enable) override;
143     int32_t RegisterFreeMultiWindowSwitchCallback(std::function<void(bool)>&& callback) override;
144     void UnRegisterFreeMultiWindowSwitchCallback(int32_t callbackId) override;
145 
NeedAvoidKeyboard()146     bool NeedAvoidKeyboard() override
147     {
148         return needAvoidKeyboard_;
149     }
150 
151     bool IsFocused() override;
152     void RequestFocus() override;
GetSubWindow()153     const sptr<OHOS::Rosen::Window>& GetSubWindow() const
154     {
155         return window_;
156     }
157     void ResizeWindowForFoldStatus() override;
158     void ResizeWindowForFoldStatus(int32_t parentContainerId) override;
159     void MarkDirtyDialogSafeArea() override;
160 
161     bool Close() override;
162 
163 private:
164     RefPtr<StackElement> GetStack();
165     void AddMenu(const RefPtr<Component>& newComponent);
166     void ShowWindow(bool needFocus = true);
167     void HideWindow();
168 
169     // Convert Rect to Rosen::Rect
170     void RectConverter(const Rect& rect, Rosen::Rect& rosenRect);
171 
172     bool CreateEventRunner();
173     void GetToastDialogWindowProperty(
174         int32_t& width, int32_t& height, int32_t& posX, int32_t& posY, float& density) const;
175     bool InitToastDialogWindow(int32_t width, int32_t height, int32_t posX, int32_t posY, bool isToast = false);
176     bool InitToastDialogView(int32_t width, int32_t height, float density);
177     bool InitToastServiceConfig();
178     void ShowToastForAbility(const NG::ToastInfo& toastInfo);
179     void ShowToastForService(const NG::ToastInfo& toastInfo);
180     void ShowDialogForAbility(const std::string& title, const std::string& message,
181         const std::vector<ButtonInfo>& buttons, bool autoCancel, std::function<void(int32_t, int32_t)>&& callback,
182         const std::set<std::string>& callbacks);
183     void ShowDialogForService(const std::string& title, const std::string& message,
184         const std::vector<ButtonInfo>& buttons, bool autoCancel, std::function<void(int32_t, int32_t)>&& callback,
185         const std::set<std::string>& callbacks);
186     void ShowDialogForAbility(const PromptDialogAttr& dialogAttr, const std::vector<ButtonInfo>& buttons,
187         std::function<void(int32_t, int32_t)>&& callback, const std::set<std::string>& callbacks);
188     void ShowDialogForService(const PromptDialogAttr& dialogAttr, const std::vector<ButtonInfo>& buttons,
189         std::function<void(int32_t, int32_t)>&& callback, const std::set<std::string>& callbacks);
190     void OpenCustomDialogForAbility(const PromptDialogAttr& dialogAttr, std::function<void(int32_t)>&& callback);
191     void OpenCustomDialogForService(const PromptDialogAttr& dialogAttr, std::function<void(int32_t)>&& callback);
192     void ShowActionMenuForAbility(const std::string& title, const std::vector<ButtonInfo>& button,
193         std::function<void(int32_t, int32_t)>&& callback);
194     void ShowActionMenuForService(const std::string& title, const std::vector<ButtonInfo>& button,
195         std::function<void(int32_t, int32_t)>&& callback);
196 
197     RefPtr<PipelineBase> GetChildPipelineContext() const;
198     std::function<void()> GetInitToastDelayTask(const NG::ToastInfo& toastInfo);
199     void ContainerModalUnFocus();
200 
201     void HideFilter(bool isInSubWindow);
202     void HidePixelMap(bool startDrag = false, double x = 0, double y = 0, bool showAnimation = true);
203     void HideEventColumn();
204     Rosen::WindowType GetToastRosenType(bool IsSceneBoardEnabled);
205 
206     static int32_t id_;
207     int32_t windowId_ = 0;
208     int32_t parentContainerId_ = -1;
209     int32_t childContainerId_ = -1;
210     std::shared_ptr<OHOS::Rosen::RSUIDirector> rsUiDirector;
211     sptr<OHOS::Rosen::Window> window_ = nullptr;
212     RefPtr<SelectPopupComponent> popup_;
213     std::unordered_map<int32_t, std::vector<Rosen::Rect>> hotAreasMap_;
214 
215     sptr<OHOS::Rosen::Window> dialogWindow_;
216     std::shared_ptr<AppExecFwk::EventRunner> eventLoop_;
217     std::shared_ptr<AppExecFwk::EventHandler> handler_;
218     int32_t targetId_ = -1;
219     bool isToastWindow_ = false;
220     int32_t popupTargetId_ = -1;
221     bool haveDialog_ = false;
222     bool isShowed_ = false;
223     bool needAvoidKeyboard_ = false;
224     sptr<OHOS::Rosen::Window> parentWindow_ = nullptr;
225     int32_t callbackId_ = 0;
226     sptr<OHOS::Rosen::ISwitchFreeMultiWindowListener> freeMultiWindowListener_ = nullptr;
227     std::unordered_map<int32_t, std::function<void(bool)>> freeMultiWindowSwitchCallbackMap_;
228 };
229 
230 } // namespace OHOS::Ace
231 
232 #endif // FOUNDATION_ACE_ADAPTER_OHOS_ENTRANCE_SUBWINDOW_OHOS_H
233