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 33 namespace OHOS::Ace::Platform { 34 class DialogContainer : public AceContainer { 35 DECLARE_ACE_TYPE(DialogContainer, AceContainer); 36 37 public: 38 explicit DialogContainer(int32_t instanceId, FrontendType type = FrontendType::DECLARATIVE_JS); 39 ~DialogContainer() override = default; 40 IsDialogContainer()41 bool IsDialogContainer() const override 42 { 43 return true; 44 } 45 46 static void ShowToast(int32_t instanceId, const std::string& message, int32_t duration, const std::string& bottom, 47 std::function<void(int32_t)>&& callback); 48 static void CloseToast(int32_t instanceId, const int32_t toastId, std::function<void(int32_t)>&& callback); 49 static void ShowDialog(int32_t instanceId, const std::string& title, const std::string& message, 50 const std::vector<ButtonInfo>& buttons, bool autoCancel, std::function<void(int32_t, int32_t)>&& callback, 51 const std::set<std::string>& callbacks); 52 static void ShowDialog(int32_t instanceId, const PromptDialogAttr& dialogAttr, 53 const std::vector<ButtonInfo>& buttons, std::function<void(int32_t, int32_t)>&& callback, 54 const std::set<std::string>& callbacks); 55 static void ShowActionMenu(int32_t instanceId, const std::string& title, const std::vector<ButtonInfo>& button, 56 std::function<void(int32_t, int32_t)>&& callback); 57 58 static bool ShowToastDialogWindow( 59 int32_t instanceId, int32_t posX, int32_t posY, int32_t width, int32_t height, bool isToast = false); 60 61 static bool OnBackPressed(int32_t instanceId); 62 63 private: 64 ACE_DISALLOW_COPY_AND_MOVE(DialogContainer); 65 }; 66 67 } // namespace OHOS::Ace::Platform 68 69 #endif // FOUNDATION_ACE_ADAPTER_OHOS_CPP_DIALOG_CONTAINER_H 70