123b3eb3cSopenharmony_ci/* 223b3eb3cSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 323b3eb3cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 423b3eb3cSopenharmony_ci * you may not use this file except in compliance with the License. 523b3eb3cSopenharmony_ci * You may obtain a copy of the License at 623b3eb3cSopenharmony_ci * 723b3eb3cSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 823b3eb3cSopenharmony_ci * 923b3eb3cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1023b3eb3cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1123b3eb3cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1223b3eb3cSopenharmony_ci * See the License for the specific language governing permissions and 1323b3eb3cSopenharmony_ci * limitations under the License. 1423b3eb3cSopenharmony_ci */ 1523b3eb3cSopenharmony_ci 1623b3eb3cSopenharmony_ci#ifndef FOUNDATION_ACE_ADAPTER_OHOS_CPP_DIALOG_CONTAINER_H 1723b3eb3cSopenharmony_ci#define FOUNDATION_ACE_ADAPTER_OHOS_CPP_DIALOG_CONTAINER_H 1823b3eb3cSopenharmony_ci 1923b3eb3cSopenharmony_ci#include <memory> 2023b3eb3cSopenharmony_ci#include <mutex> 2123b3eb3cSopenharmony_ci 2223b3eb3cSopenharmony_ci#include "adapter/ohos/entrance/ace_container.h" 2323b3eb3cSopenharmony_ci#include "base/resource/asset_manager.h" 2423b3eb3cSopenharmony_ci#include "base/thread/task_executor.h" 2523b3eb3cSopenharmony_ci#include "base/utils/noncopyable.h" 2623b3eb3cSopenharmony_ci#include "core/common/ace_view.h" 2723b3eb3cSopenharmony_ci#include "core/common/container.h" 2823b3eb3cSopenharmony_ci#include "core/common/js_message_dispatcher.h" 2923b3eb3cSopenharmony_ci#include "core/common/window.h" 3023b3eb3cSopenharmony_ci#include "core/components/dialog/dialog_properties.h" 3123b3eb3cSopenharmony_ci#include "core/components_ng/render/adapter/rosen_window.h" 3223b3eb3cSopenharmony_ci 3323b3eb3cSopenharmony_cinamespace OHOS::Ace::Platform { 3423b3eb3cSopenharmony_ciclass DialogContainer : public Container, public JsMessageDispatcher { 3523b3eb3cSopenharmony_ci DECLARE_ACE_TYPE(DialogContainer, Container, JsMessageDispatcher); 3623b3eb3cSopenharmony_ci 3723b3eb3cSopenharmony_cipublic: 3823b3eb3cSopenharmony_ci explicit DialogContainer(int32_t instanceId, FrontendType type = FrontendType::DECLARATIVE_JS); 3923b3eb3cSopenharmony_ci ~DialogContainer() override = default; 4023b3eb3cSopenharmony_ci 4123b3eb3cSopenharmony_ci void Initialize() override {}; 4223b3eb3cSopenharmony_ci void Destroy() override; 4323b3eb3cSopenharmony_ci void DestroyView() override; 4423b3eb3cSopenharmony_ci 4523b3eb3cSopenharmony_ci int32_t GetInstanceId() const override 4623b3eb3cSopenharmony_ci { 4723b3eb3cSopenharmony_ci if (aceView_) { 4823b3eb3cSopenharmony_ci return aceView_->GetInstanceId(); 4923b3eb3cSopenharmony_ci } 5023b3eb3cSopenharmony_ci return -1; 5123b3eb3cSopenharmony_ci } 5223b3eb3cSopenharmony_ci 5323b3eb3cSopenharmony_ci RefPtr<Frontend> GetFrontend() const override 5423b3eb3cSopenharmony_ci { 5523b3eb3cSopenharmony_ci return frontend_; 5623b3eb3cSopenharmony_ci } 5723b3eb3cSopenharmony_ci 5823b3eb3cSopenharmony_ci ResourceConfiguration GetResourceConfiguration() const 5923b3eb3cSopenharmony_ci { 6023b3eb3cSopenharmony_ci return resourceInfo_.GetResourceConfiguration(); 6123b3eb3cSopenharmony_ci } 6223b3eb3cSopenharmony_ci 6323b3eb3cSopenharmony_ci void SetResourceConfiguration(const ResourceConfiguration& config) 6423b3eb3cSopenharmony_ci { 6523b3eb3cSopenharmony_ci resourceInfo_.SetResourceConfiguration(config); 6623b3eb3cSopenharmony_ci } 6723b3eb3cSopenharmony_ci 6823b3eb3cSopenharmony_ci RefPtr<PlatformResRegister> GetPlatformResRegister() const override 6923b3eb3cSopenharmony_ci { 7023b3eb3cSopenharmony_ci return resRegister_; 7123b3eb3cSopenharmony_ci } 7223b3eb3cSopenharmony_ci 7323b3eb3cSopenharmony_ci RefPtr<PipelineBase> GetPipelineContext() const override 7423b3eb3cSopenharmony_ci { 7523b3eb3cSopenharmony_ci return pipelineContext_; 7623b3eb3cSopenharmony_ci } 7723b3eb3cSopenharmony_ci 7823b3eb3cSopenharmony_ci int32_t GetViewPosX() const override 7923b3eb3cSopenharmony_ci { 8023b3eb3cSopenharmony_ci return aceView_ ? aceView_->GetPosX() : 0; 8123b3eb3cSopenharmony_ci } 8223b3eb3cSopenharmony_ci 8323b3eb3cSopenharmony_ci int32_t GetViewPosY() const override 8423b3eb3cSopenharmony_ci { 8523b3eb3cSopenharmony_ci return aceView_ ? aceView_->GetPosY() : 0; 8623b3eb3cSopenharmony_ci } 8723b3eb3cSopenharmony_ci 8823b3eb3cSopenharmony_ci void SetWindowId(uint32_t windowId) override 8923b3eb3cSopenharmony_ci { 9023b3eb3cSopenharmony_ci windowId_ = windowId; 9123b3eb3cSopenharmony_ci } 9223b3eb3cSopenharmony_ci 9323b3eb3cSopenharmony_ci uint32_t GetWindowId() const override 9423b3eb3cSopenharmony_ci { 9523b3eb3cSopenharmony_ci return windowId_; 9623b3eb3cSopenharmony_ci } 9723b3eb3cSopenharmony_ci 9823b3eb3cSopenharmony_ci int32_t GetViewWidth() const override 9923b3eb3cSopenharmony_ci { 10023b3eb3cSopenharmony_ci return aceView_ ? aceView_->GetWidth() : 0; 10123b3eb3cSopenharmony_ci } 10223b3eb3cSopenharmony_ci 10323b3eb3cSopenharmony_ci int32_t GetViewHeight() const override 10423b3eb3cSopenharmony_ci { 10523b3eb3cSopenharmony_ci return aceView_ ? aceView_->GetHeight() : 0; 10623b3eb3cSopenharmony_ci } 10723b3eb3cSopenharmony_ci 10823b3eb3cSopenharmony_ci RefPtr<AceView> GetAceView() const override 10923b3eb3cSopenharmony_ci { 11023b3eb3cSopenharmony_ci std::lock_guard<std::mutex> lock(viewMutex_); 11123b3eb3cSopenharmony_ci return aceView_; 11223b3eb3cSopenharmony_ci } 11323b3eb3cSopenharmony_ci 11423b3eb3cSopenharmony_ci void* GetView() const override 11523b3eb3cSopenharmony_ci { 11623b3eb3cSopenharmony_ci std::lock_guard<std::mutex> lock(viewMutex_); 11723b3eb3cSopenharmony_ci return static_cast<void*>(AceType::RawPtr(aceView_)); 11823b3eb3cSopenharmony_ci } 11923b3eb3cSopenharmony_ci 12023b3eb3cSopenharmony_ci RefPtr<TaskExecutor> GetTaskExecutor() const override 12123b3eb3cSopenharmony_ci { 12223b3eb3cSopenharmony_ci return taskExecutor_; 12323b3eb3cSopenharmony_ci } 12423b3eb3cSopenharmony_ci 12523b3eb3cSopenharmony_ci void Dispatch( 12623b3eb3cSopenharmony_ci const std::string& group, std::vector<uint8_t>&& data, int32_t id, bool replyToComponent) const override {}; 12723b3eb3cSopenharmony_ci 12823b3eb3cSopenharmony_ci void DispatchPluginError(int32_t callbackId, int32_t errorCode, std::string&& errorMessage) const override {}; 12923b3eb3cSopenharmony_ci 13023b3eb3cSopenharmony_ci void DispatchSync( 13123b3eb3cSopenharmony_ci const std::string& group, std::vector<uint8_t>&& data, uint8_t** resData, int64_t& position) const override 13223b3eb3cSopenharmony_ci {} 13323b3eb3cSopenharmony_ci 13423b3eb3cSopenharmony_ci std::string GetHostClassName() const override 13523b3eb3cSopenharmony_ci { 13623b3eb3cSopenharmony_ci return ""; 13723b3eb3cSopenharmony_ci } 13823b3eb3cSopenharmony_ci 13923b3eb3cSopenharmony_ci void DumpHeapSnapshot(bool isPrivate) override; 14023b3eb3cSopenharmony_ci 14123b3eb3cSopenharmony_ci void SetAssetManager(const RefPtr<AssetManager>& assetManager) 14223b3eb3cSopenharmony_ci { 14323b3eb3cSopenharmony_ci assetManager_ = assetManager; 14423b3eb3cSopenharmony_ci if (frontend_) { 14523b3eb3cSopenharmony_ci frontend_->SetAssetManager(assetManager); 14623b3eb3cSopenharmony_ci } 14723b3eb3cSopenharmony_ci } 14823b3eb3cSopenharmony_ci 14923b3eb3cSopenharmony_ci RefPtr<AssetManager> GetAssetManager() const override 15023b3eb3cSopenharmony_ci { 15123b3eb3cSopenharmony_ci return assetManager_; 15223b3eb3cSopenharmony_ci } 15323b3eb3cSopenharmony_ci 15423b3eb3cSopenharmony_ci bool IsSubContainer() const override 15523b3eb3cSopenharmony_ci { 15623b3eb3cSopenharmony_ci return true; 15723b3eb3cSopenharmony_ci } 15823b3eb3cSopenharmony_ci 15923b3eb3cSopenharmony_ci bool IsDialogContainer() const override 16023b3eb3cSopenharmony_ci { 16123b3eb3cSopenharmony_ci return true; 16223b3eb3cSopenharmony_ci } 16323b3eb3cSopenharmony_ci 16423b3eb3cSopenharmony_ci static void ShowToast(int32_t instanceId, const std::string& message, int32_t duration, const std::string& bottom, 16523b3eb3cSopenharmony_ci std::function<void(int32_t)>&& callback); 16623b3eb3cSopenharmony_ci static void CloseToast(int32_t instanceId, const int32_t toastId, std::function<void(int32_t)>&& callback); 16723b3eb3cSopenharmony_ci static void ShowDialog(int32_t instanceId, const std::string& title, const std::string& message, 16823b3eb3cSopenharmony_ci const std::vector<ButtonInfo>& buttons, bool autoCancel, std::function<void(int32_t, int32_t)>&& callback, 16923b3eb3cSopenharmony_ci const std::set<std::string>& callbacks); 17023b3eb3cSopenharmony_ci static void ShowDialog(int32_t instanceId, const PromptDialogAttr& dialogAttr, 17123b3eb3cSopenharmony_ci const std::vector<ButtonInfo>& buttons, std::function<void(int32_t, int32_t)>&& callback, 17223b3eb3cSopenharmony_ci const std::set<std::string>& callbacks); 17323b3eb3cSopenharmony_ci static void ShowActionMenu(int32_t instanceId, const std::string& title, const std::vector<ButtonInfo>& button, 17423b3eb3cSopenharmony_ci std::function<void(int32_t, int32_t)>&& callback); 17523b3eb3cSopenharmony_ci 17623b3eb3cSopenharmony_ci static bool ShowToastDialogWindow( 17723b3eb3cSopenharmony_ci int32_t instanceId, int32_t posX, int32_t posY, int32_t width, int32_t height, bool isToast = false); 17823b3eb3cSopenharmony_ci static bool CloseWindow(int32_t instanceId); 17923b3eb3cSopenharmony_ci static bool HideWindow(int32_t instanceId); 18023b3eb3cSopenharmony_ci 18123b3eb3cSopenharmony_ci static void SetUIWindow(int32_t instanceId, sptr<OHOS::Rosen::Window>& uiWindow); 18223b3eb3cSopenharmony_ci static sptr<OHOS::Rosen::Window> GetUIWindow(int32_t instanceId); 18323b3eb3cSopenharmony_ci 18423b3eb3cSopenharmony_ci static void DestroyContainer(int32_t instanceId, const std::function<void()>& destroyCallback = nullptr); 18523b3eb3cSopenharmony_ci static RefPtr<DialogContainer> GetContainer(int32_t instanceId); 18623b3eb3cSopenharmony_ci static void SetView(const RefPtr<AceView>& view, double density, int32_t width, int32_t height, 18723b3eb3cSopenharmony_ci sptr<OHOS::Rosen::Window>& rsWindow); 18823b3eb3cSopenharmony_ci static void SetViewNew(const RefPtr<AceView>& view, double density, int32_t width, int32_t height, 18923b3eb3cSopenharmony_ci sptr<OHOS::Rosen::Window>& rsWindow); 19023b3eb3cSopenharmony_ci static bool OnBackPressed(int32_t instanceId); 19123b3eb3cSopenharmony_ci 19223b3eb3cSopenharmony_ci void SetFontScaleAndWeightScale(int32_t instanceId); 19323b3eb3cSopenharmony_ci void UpdateConfiguration(const ParsedConfig& parsedConfig); 19423b3eb3cSopenharmony_ci void CheckAndSetFontFamily() override; 19523b3eb3cSopenharmony_ci 19623b3eb3cSopenharmony_ciprivate: 19723b3eb3cSopenharmony_ci void InitPipelineContext(std::shared_ptr<Window> window, int32_t instanceId, double density, int32_t width, 19823b3eb3cSopenharmony_ci int32_t height, uint32_t windowId); 19923b3eb3cSopenharmony_ci void InitializeFrontend(); 20023b3eb3cSopenharmony_ci void InitializeCallback(); 20123b3eb3cSopenharmony_ci void InitializeTouchEventCallback(); 20223b3eb3cSopenharmony_ci void InitializeMouseEventCallback(); 20323b3eb3cSopenharmony_ci void InitializeAxisEventCallback(); 20423b3eb3cSopenharmony_ci void InitializeKeyEventCallback(); 20523b3eb3cSopenharmony_ci void InitializeRotationEventCallback(); 20623b3eb3cSopenharmony_ci void InitializeViewChangeCallback(); 20723b3eb3cSopenharmony_ci void InitializeDensityChangeCallback(); 20823b3eb3cSopenharmony_ci void InitializeSystemBarHeightChangeCallback(); 20923b3eb3cSopenharmony_ci void InitializeSurfaceDestroyCallback(); 21023b3eb3cSopenharmony_ci void InitializeDragEventCallback(); 21123b3eb3cSopenharmony_ci 21223b3eb3cSopenharmony_ci void AttachView(std::shared_ptr<Window> window, const RefPtr<AceView>& view, double density, int32_t width, 21323b3eb3cSopenharmony_ci int32_t height, uint32_t windowId); 21423b3eb3cSopenharmony_ci void SetUIWindowInner(sptr<OHOS::Rosen::Window> uiWindow); 21523b3eb3cSopenharmony_ci sptr<OHOS::Rosen::Window> GetUIWindowInner() const; 21623b3eb3cSopenharmony_ci 21723b3eb3cSopenharmony_ci uint32_t windowId_ = OHOS::Rosen::INVALID_WINDOW_ID; 21823b3eb3cSopenharmony_ci int32_t instanceId_ = -1; 21923b3eb3cSopenharmony_ci RefPtr<AceView> aceView_; 22023b3eb3cSopenharmony_ci RefPtr<TaskExecutor> taskExecutor_; 22123b3eb3cSopenharmony_ci RefPtr<AssetManager> assetManager_; 22223b3eb3cSopenharmony_ci RefPtr<PlatformResRegister> resRegister_; 22323b3eb3cSopenharmony_ci RefPtr<PipelineBase> pipelineContext_; 22423b3eb3cSopenharmony_ci RefPtr<Frontend> frontend_; 22523b3eb3cSopenharmony_ci FrontendType type_ = FrontendType::DECLARATIVE_JS; 22623b3eb3cSopenharmony_ci ResourceInfo resourceInfo_; 22723b3eb3cSopenharmony_ci sptr<OHOS::Rosen::Window> uiWindow_ = nullptr; 22823b3eb3cSopenharmony_ci std::string windowName_; 22923b3eb3cSopenharmony_ci WindowModal windowModal_ { WindowModal::NORMAL }; 23023b3eb3cSopenharmony_ci ColorScheme colorScheme_ { ColorScheme::FIRST_VALUE }; 23123b3eb3cSopenharmony_ci mutable std::mutex viewMutex_; 23223b3eb3cSopenharmony_ci 23323b3eb3cSopenharmony_ci ACE_DISALLOW_COPY_AND_MOVE(DialogContainer); 23423b3eb3cSopenharmony_ci}; 23523b3eb3cSopenharmony_ci 23623b3eb3cSopenharmony_ci} // namespace OHOS::Ace::Platform 23723b3eb3cSopenharmony_ci 23823b3eb3cSopenharmony_ci#endif // FOUNDATION_ACE_ADAPTER_OHOS_CPP_DIALOG_CONTAINER_H 239