• 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_CPP_DIALOG_CONTAINER_H
17 #define FOUNDATION_ACE_ADAPTER_OHOS_CPP_DIALOG_CONTAINER_H
18 
19 #include <memory>
20 
21 #include "base/resource/asset_manager.h"
22 #include "base/thread/task_executor.h"
23 #include "base/utils/noncopyable.h"
24 #include "core/common/ace_view.h"
25 #include "core/common/container.h"
26 #include "core/common/js_message_dispatcher.h"
27 #include "core/common/window.h"
28 #include "core/components/dialog/dialog_properties.h"
29 #include "core/components_ng/render/adapter/rosen_window.h"
30 
31 namespace OHOS::Ace::Platform {
32 class DialogContainer : public Container, public JsMessageDispatcher {
33     DECLARE_ACE_TYPE(DialogContainer, Container, JsMessageDispatcher);
34 
35 public:
36     explicit DialogContainer(int32_t instanceId, FrontendType type = FrontendType::DECLARATIVE_JS);
37     ~DialogContainer() override = default;
38 
Initialize()39     void Initialize() override {};
40     void Destroy() override;
41     void DestroyView() override;
42 
GetInstanceId()43     int32_t GetInstanceId() const override
44     {
45         if (aceView_) {
46             return aceView_->GetInstanceId();
47         }
48         return -1;
49     }
50 
GetFrontend()51     RefPtr<Frontend> GetFrontend() const override
52     {
53         return frontend_;
54     }
55 
GetPlatformResRegister()56     RefPtr<PlatformResRegister> GetPlatformResRegister() const override
57     {
58         return resRegister_;
59     }
60 
GetPipelineContext()61     RefPtr<PipelineBase> GetPipelineContext() const override
62     {
63         return pipelineContext_;
64     }
65 
GetViewPosX()66     int32_t GetViewPosX() const override
67     {
68         return aceView_ ? aceView_->GetPosX() : 0;
69     }
70 
GetViewPosY()71     int32_t GetViewPosY() const override
72     {
73         return aceView_ ? aceView_->GetPosY() : 0;
74     }
75 
SetWindowId(uint32_t windowId)76     void SetWindowId(uint32_t windowId) override
77     {
78         windowId_ = windowId;
79     }
80 
GetWindowId()81     uint32_t GetWindowId() const override
82     {
83         return windowId_;
84     }
85 
GetViewWidth()86     int32_t GetViewWidth() const override
87     {
88         return aceView_ ? aceView_->GetWidth() : 0;
89     }
90 
GetViewHeight()91     int32_t GetViewHeight() const override
92     {
93         return aceView_ ? aceView_->GetHeight() : 0;
94     }
95 
GetAceView()96     AceView* GetAceView() const
97     {
98         return aceView_;
99     }
100 
GetView()101     void* GetView() const override
102     {
103         return static_cast<void*>(aceView_);
104     }
105 
GetTaskExecutor()106     RefPtr<TaskExecutor> GetTaskExecutor() const override
107     {
108         return taskExecutor_;
109     }
110 
Dispatch(const std::string & group,std::vector<uint8_t> && data,int32_t id,bool replyToComponent)111     void Dispatch(
112         const std::string& group, std::vector<uint8_t>&& data, int32_t id, bool replyToComponent) const override {};
113 
DispatchPluginError(int32_t callbackId,int32_t errorCode,std::string && errorMessage)114     void DispatchPluginError(int32_t callbackId, int32_t errorCode, std::string&& errorMessage) const override {};
115 
DispatchSync(const std::string & group,std::vector<uint8_t> && data,uint8_t ** resData,int64_t & position)116     void DispatchSync(
117         const std::string& group, std::vector<uint8_t>&& data, uint8_t** resData, int64_t& position) const override
118     {}
119 
GetHostClassName()120     std::string GetHostClassName() const override
121     {
122         return "";
123     }
124 
125     void DumpHeapSnapshot(bool isPrivate) override;
126 
SetAssetManager(const RefPtr<AssetManager> & assetManager)127     void SetAssetManager(const RefPtr<AssetManager>& assetManager)
128     {
129         assetManager_ = assetManager;
130         if (frontend_) {
131             frontend_->SetAssetManager(assetManager);
132         }
133     }
134 
GetAssetManager()135     RefPtr<AssetManager> GetAssetManager() const override
136     {
137         return assetManager_;
138     }
139 
IsSubContainer()140     bool IsSubContainer() const override
141     {
142         return true;
143     }
144 
IsDialogContainer()145     bool IsDialogContainer() const override
146     {
147         return true;
148     }
149 
150     static void ShowToast(int32_t instanceId, const std::string& message, int32_t duration, const std::string& bottom);
151     static void ShowDialog(int32_t instanceId, const std::string& title, const std::string& message,
152         const std::vector<ButtonInfo>& buttons, bool autoCancel, std::function<void(int32_t, int32_t)>&& callback,
153         const std::set<std::string>& callbacks);
154     static void ShowDialog(int32_t instanceId, const PromptDialogAttr& dialogAttr,
155         const std::vector<ButtonInfo>& buttons, std::function<void(int32_t, int32_t)>&& callback,
156         const std::set<std::string>& callbacks);
157     static void ShowActionMenu(int32_t instanceId, const std::string& title, const std::vector<ButtonInfo>& button,
158         std::function<void(int32_t, int32_t)>&& callback);
159 
160     static bool ShowToastDialogWindow(
161         int32_t instanceId, int32_t posX, int32_t posY, int32_t width, int32_t height, bool isToast = false);
162     static bool CloseWindow(int32_t instanceId);
163     static bool HideWindow(int32_t instanceId);
164 
165     static void SetUIWindow(int32_t instanceId, sptr<OHOS::Rosen::Window>& uiWindow);
166     static sptr<OHOS::Rosen::Window> GetUIWindow(int32_t instanceId);
167 
168     static void DestroyContainer(int32_t instanceId, const std::function<void()>& destroyCallback = nullptr);
169     static RefPtr<DialogContainer> GetContainer(int32_t instanceId);
170     static void SetView(
171         AceView* view, double density, int32_t width, int32_t height, sptr<OHOS::Rosen::Window>& rsWindow);
172     static void SetViewNew(
173         AceView* view, double density, int32_t width, int32_t height, sptr<OHOS::Rosen::Window>& rsWindow);
174     static bool OnBackPressed(int32_t instanceId);
175 
176 private:
177     void InitPipelineContext(std::unique_ptr<Window> window, int32_t instanceId, double density, int32_t width,
178         int32_t height, uint32_t windowId);
179     void InitializeFrontend();
180     void InitializeCallback();
181     void InitializeTouchEventCallback();
182     void InitializeMouseEventCallback();
183     void InitializeAxisEventCallback();
184     void InitializeKeyEventCallback();
185     void InitializeRotationEventCallback();
186     void InitializeViewChangeCallback();
187     void InitializeDensityChangeCallback();
188     void InitializeSystemBarHeightChangeCallback();
189     void InitializeSurfaceDestroyCallback();
190     void InitializeDragEventCallback();
191 
192     void AttachView(std::unique_ptr<Window> window, AceView* view, double density, int32_t width, int32_t height,
193         uint32_t windowId);
194     void SetUIWindowInner(sptr<OHOS::Rosen::Window> uiWindow);
195     sptr<OHOS::Rosen::Window> GetUIWindowInner() const;
196 
197     uint32_t windowId_ = OHOS::Rosen::INVALID_WINDOW_ID;
198     int32_t instanceId_ = -1;
199     AceView* aceView_ = nullptr;
200     RefPtr<TaskExecutor> taskExecutor_;
201     RefPtr<AssetManager> assetManager_;
202     RefPtr<PlatformResRegister> resRegister_;
203     RefPtr<PipelineBase> pipelineContext_;
204     RefPtr<Frontend> frontend_;
205     FrontendType type_ = FrontendType::DECLARATIVE_JS;
206     ResourceInfo resourceInfo_;
207     sptr<OHOS::Rosen::Window> uiWindow_ = nullptr;
208     std::string windowName_;
209     WindowModal windowModal_ { WindowModal::NORMAL };
210     ColorScheme colorScheme_ { ColorScheme::FIRST_VALUE };
211 
212     ACE_DISALLOW_COPY_AND_MOVE(DialogContainer);
213 };
214 
215 } // namespace OHOS::Ace::Platform
216 
217 #endif // FOUNDATION_ACE_ADAPTER_OHOS_CPP_DIALOG_CONTAINER_H
218