• 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     NG::RectF GetRect() override;
60     void ShowMenu(const RefPtr<Component>& newComponent) override;
61     void ShowMenuNG(const RefPtr<NG::FrameNode> menuNode, int32_t targetId, const NG::OffsetF& offset) override;
62     void HideMenuNG(const RefPtr<NG::FrameNode>& menu, int32_t targetId) override;
63     void HideMenuNG() override;
64     void ShowPopup(const RefPtr<Component>& newComponent, bool disableTouchEvent = true) override;
65     void ShowPopupNG(int32_t targetId, const NG::PopupInfo& popupInfo) override;
66     void HidePopupNG(int32_t targetId) override;
67     void GetPopupInfoNG(int32_t targetId, NG::PopupInfo& popupInfo) override;
68     bool CancelPopup(const std::string& id) override;
69     void CloseMenu() override;
70     void ClearMenu() override;
71     void ClearMenuNG(bool inWindow) override;
72     RefPtr<NG::FrameNode> ShowDialogNG(const DialogProperties& dialogProps, std::function<void()>&& buildFunc) override;
73     void HideSubWindowNG() override;
GetShown()74     bool GetShown() override
75     {
76         return isShowed_;
77     }
78 
79     void SetHotAreas(const std::vector<Rect>& rects, int32_t overlayId) override;
80 
81     void ShowToast(const std::string& message, int32_t duration, const std::string& bottom) override;
82     void ShowDialog(const std::string& title, const std::string& message, const std::vector<ButtonInfo>& buttons,
83         bool autoCancel, std::function<void(int32_t, int32_t)>&& callback,
84         const std::set<std::string>& callbacks) override;
85     void ShowDialog(const PromptDialogAttr& dialogAttr, const std::vector<ButtonInfo>& buttons,
86         std::function<void(int32_t, int32_t)>&& callback, const std::set<std::string>& callbacks) override;
87     void ShowActionMenu(const std::string& title, const std::vector<ButtonInfo>& button,
88         std::function<void(int32_t, int32_t)>&& callback) override;
89     void CloseDialog(int32_t instanceId) override;
90     const RefPtr<NG::OverlayManager> GetOverlayManager() override;
91 
GetChildContainerId()92     int32_t GetChildContainerId() const override
93     {
94         return childContainerId_;
95     }
GetDialogWindow()96     sptr<OHOS::Rosen::Window> GetDialogWindow() const
97     {
98         return dialogWindow_;
99     }
IsToastWindow()100     bool IsToastWindow() const
101     {
102         return isToastWindow_;
103     }
SetIsToastWindow(bool isToastWindow)104     void SetIsToastWindow(bool isToastWindow)
105     {
106         isToastWindow_ = isToastWindow;
107     }
108 
109     void UpdateAceView(int32_t width, int32_t height, float density, int32_t containerId);
110 
111     // Gets parent window's size and offset
112     Rect GetParentWindowRect() const override;
113 
114     void RequestFocus() override;
115 
116 private:
117     RefPtr<StackElement> GetStack();
118     void AddMenu(const RefPtr<Component>& newComponent);
119     void ShowWindow(bool needFocus = true);
120     void HideWindow();
121 
122     // Convert Rect to Rosen::Rect
123     void RectConverter(const Rect& rect, Rosen::Rect& rosenRect);
124 
125     bool CreateEventRunner();
126     void GetToastDialogWindowProperty(
127         int32_t& width, int32_t& height, int32_t& posX, int32_t& posY, float& density) const;
128     bool InitToastDialogWindow(int32_t width, int32_t height, int32_t posX, int32_t posY, bool isToast = false);
129     bool InitToastDialogView(int32_t width, int32_t height, float density);
130     void ShowToastForAbility(const std::string& message, int32_t duration, const std::string& bottom);
131     void ShowToastForService(const std::string& message, int32_t duration, const std::string& bottom);
132     void ShowDialogForAbility(const std::string& title, const std::string& message,
133         const std::vector<ButtonInfo>& buttons, bool autoCancel, std::function<void(int32_t, int32_t)>&& callback,
134         const std::set<std::string>& callbacks);
135     void ShowDialogForService(const std::string& title, const std::string& message,
136         const std::vector<ButtonInfo>& buttons, bool autoCancel, std::function<void(int32_t, int32_t)>&& callback,
137         const std::set<std::string>& callbacks);
138     void ShowDialogForAbility(const PromptDialogAttr& dialogAttr, const std::vector<ButtonInfo>& buttons,
139         std::function<void(int32_t, int32_t)>&& callback, const std::set<std::string>& callbacks);
140     void ShowDialogForService(const PromptDialogAttr& dialogAttr, const std::vector<ButtonInfo>& buttons,
141         std::function<void(int32_t, int32_t)>&& callback, const std::set<std::string>& callbacks);
142     void ShowActionMenuForAbility(const std::string& title, const std::vector<ButtonInfo>& button,
143         std::function<void(int32_t, int32_t)>&& callback);
144     void ShowActionMenuForService(const std::string& title, const std::vector<ButtonInfo>& button,
145         std::function<void(int32_t, int32_t)>&& callback);
146 
147     RefPtr<PipelineBase> GetChildPipelineContext() const;
148 
149 #ifdef ENABLE_DRAG_FRAMEWORK
150     void HideFilter();
151     void HidePixelMap(bool startDrag = false, double x = 0, double y = 0, bool showAnimation = true);
152     void HideEventColumn();
153 #endif // ENABLE_DRAG_FRAMEWORK
154     static int32_t id_;
155     int32_t windowId_ = 0;
156     int32_t parentContainerId_ = -1;
157     int32_t childContainerId_ = -1;
158     std::shared_ptr<OHOS::Rosen::RSUIDirector> rsUiDirector;
159     sptr<OHOS::Rosen::Window> window_ = nullptr;
160     RefPtr<SelectPopupComponent> popup_;
161     std::unordered_map<int32_t, std::vector<Rosen::Rect>> hotAreasMap_;
162 
163     sptr<OHOS::Rosen::Window> dialogWindow_;
164     std::shared_ptr<AppExecFwk::EventRunner> eventLoop_;
165     std::shared_ptr<AppExecFwk::EventHandler> handler_;
166     int32_t targetId_ = -1;
167     bool isToastWindow_ = false;
168     int32_t popupTargetId_ = -1;
169     bool isShowed_ = false;
170     sptr<OHOS::Rosen::Window> parentWindow_ = nullptr;
171 };
172 
173 } // namespace OHOS::Ace
174 
175 #endif // FOUNDATION_ACE_ADAPTER_OHOS_ENTRANCE_SUBWINDOW_OHOS_H
176