• 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 #include <mutex>
21 
22 #include "adapter/ohos/entrance/ace_container.h"
23 #include "base/resource/asset_manager.h"
24 #include "base/thread/task_executor.h"
25 #include "base/utils/noncopyable.h"
26 #include "core/common/ace_view.h"
27 #include "core/common/container.h"
28 #include "core/common/js_message_dispatcher.h"
29 #include "core/common/window.h"
30 #include "core/components/dialog/dialog_properties.h"
31 #include "core/components_ng/render/adapter/rosen_window.h"
32 #include "core/components_ng/pattern/toast/toast_layout_property.h"
33 
34 namespace OHOS::Ace::Platform {
35 class DialogContainer : public AceContainer {
36     DECLARE_ACE_TYPE(DialogContainer, AceContainer);
37 
38 public:
39     explicit DialogContainer(int32_t instanceId, FrontendType type = FrontendType::DECLARATIVE_JS);
40     ~DialogContainer() override = default;
41 
IsDialogContainer()42     bool IsDialogContainer() const override
43     {
44         return true;
45     }
46 
47     static void ShowToast(int32_t instanceId, const NG::ToastInfo& toastInfo,
48         std::function<void(int32_t)>&& callback);
49     static void CloseToast(int32_t instanceId, const int32_t toastId, std::function<void(int32_t)>&& callback);
50     static void ShowDialog(int32_t instanceId, const std::string& title, const std::string& message,
51         const std::vector<ButtonInfo>& buttons, bool autoCancel, std::function<void(int32_t, int32_t)>&& callback,
52         const std::set<std::string>& callbacks);
53     static void ShowDialog(int32_t instanceId, const PromptDialogAttr& dialogAttr,
54         const std::vector<ButtonInfo>& buttons, std::function<void(int32_t, int32_t)>&& callback,
55         const std::set<std::string>& callbacks);
56     static void ShowActionMenu(int32_t instanceId, const std::string& title, const std::vector<ButtonInfo>& button,
57         std::function<void(int32_t, int32_t)>&& callback);
58 
59     static bool ShowToastDialogWindow(
60         int32_t instanceId, int32_t posX, int32_t posY, int32_t width, int32_t height, bool isToast = false);
61 
62     static bool OnBackPressed(int32_t instanceId);
63 
64 #if defined(ACE_STATIC)
65     static void ShowToastStatic(int32_t instanceId, const NG::ToastInfo& toastInfo,
66         std::function<void(int32_t)>&& callback);
67     static void CloseToastStatic(int32_t instanceId, const int32_t toastId, std::function<void(int32_t)>&& callback);
68     static void ShowDialogStatic(int32_t instanceId, const DialogProperties& dialogProps,
69         std::function<void(int32_t, int32_t)>&& callback);
70     static void ShowActionMenuStatic(int32_t instanceId, const DialogProperties& dialogProps,
71         std::function<void(int32_t, int32_t)>&& callback);
72 #endif
73 private:
74     ACE_DISALLOW_COPY_AND_MOVE(DialogContainer);
75 };
76 
77 } // namespace OHOS::Ace::Platform
78 
79 #endif // FOUNDATION_ACE_ADAPTER_OHOS_CPP_DIALOG_CONTAINER_H
80