123b3eb3cSopenharmony_ci/* 223b3eb3cSopenharmony_ci * Copyright (c) 2022-2023 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#include "adapter/ohos/entrance/dialog_container.h" 1723b3eb3cSopenharmony_ci 1823b3eb3cSopenharmony_ci#include <mutex> 1923b3eb3cSopenharmony_ci 2023b3eb3cSopenharmony_ci#include "adapter/ohos/entrance/ace_application_info.h" 2123b3eb3cSopenharmony_ci#if defined(ENABLE_ROSEN_BACKEND) and !defined(UPLOAD_GPU_DISABLED) 2223b3eb3cSopenharmony_ci#include "adapter/ohos/entrance/ace_rosen_sync_task.h" 2323b3eb3cSopenharmony_ci#endif 2423b3eb3cSopenharmony_ci#include "adapter/ohos/entrance/ace_view_ohos.h" 2523b3eb3cSopenharmony_ci#include "base/log/frame_report.h" 2623b3eb3cSopenharmony_ci#include "base/log/log.h" 2723b3eb3cSopenharmony_ci#include "base/utils/utils.h" 2823b3eb3cSopenharmony_ci#include "core/common/ace_engine.h" 2923b3eb3cSopenharmony_ci#include "core/common/container_scope.h" 3023b3eb3cSopenharmony_ci#include "core/common/task_executor_impl.h" 3123b3eb3cSopenharmony_ci#include "core/common/text_field_manager.h" 3223b3eb3cSopenharmony_ci#include "core/components/theme/theme_constants.h" 3323b3eb3cSopenharmony_ci#include "core/components/theme/theme_manager_impl.h" 3423b3eb3cSopenharmony_ci#include "core/pipeline/pipeline_context.h" 3523b3eb3cSopenharmony_ci#include "core/pipeline_ng/pipeline_context.h" 3623b3eb3cSopenharmony_ci#include "frameworks/base/subwindow/subwindow_manager.h" 3723b3eb3cSopenharmony_ci#include "frameworks/bridge/common/utils/engine_helper.h" 3823b3eb3cSopenharmony_ci#include "frameworks/bridge/declarative_frontend/declarative_frontend.h" 3923b3eb3cSopenharmony_ci 4023b3eb3cSopenharmony_cinamespace OHOS::Ace::Platform { 4123b3eb3cSopenharmony_ciDialogContainer::DialogContainer(int32_t instanceId, FrontendType type) : instanceId_(instanceId), type_(type) 4223b3eb3cSopenharmony_ci{ 4323b3eb3cSopenharmony_ci auto taskExecutorImpl = Referenced::MakeRefPtr<TaskExecutorImpl>(); 4423b3eb3cSopenharmony_ci taskExecutorImpl->InitPlatformThread(true); 4523b3eb3cSopenharmony_ci taskExecutor_ = taskExecutorImpl; 4623b3eb3cSopenharmony_ci GetSettings().useUIAsJSThread = true; 4723b3eb3cSopenharmony_ci GetSettings().usePlatformAsUIThread = true; 4823b3eb3cSopenharmony_ci GetSettings().usingSharedRuntime = true; 4923b3eb3cSopenharmony_ci} 5023b3eb3cSopenharmony_ci 5123b3eb3cSopenharmony_civoid DialogContainer::InitializeTouchEventCallback() 5223b3eb3cSopenharmony_ci{ 5323b3eb3cSopenharmony_ci ACE_DCHECK(aceView_ && taskExecutor_ && pipelineContext_); 5423b3eb3cSopenharmony_ci auto&& touchEventCallback = [context = pipelineContext_, id = instanceId_]( 5523b3eb3cSopenharmony_ci const TouchEvent& event, const std::function<void()>& markProcess, 5623b3eb3cSopenharmony_ci const RefPtr<OHOS::Ace::NG::FrameNode>& node) { 5723b3eb3cSopenharmony_ci ContainerScope scope(id); 5823b3eb3cSopenharmony_ci context->GetTaskExecutor()->PostTask( 5923b3eb3cSopenharmony_ci [context, event, markProcess]() { 6023b3eb3cSopenharmony_ci context->OnTouchEvent(event); 6123b3eb3cSopenharmony_ci context->NotifyDispatchTouchEventDismiss(event); 6223b3eb3cSopenharmony_ci CHECK_NULL_VOID(markProcess); 6323b3eb3cSopenharmony_ci markProcess(); 6423b3eb3cSopenharmony_ci }, 6523b3eb3cSopenharmony_ci TaskExecutor::TaskType::UI, "ArkUIDialogTouchEvent"); 6623b3eb3cSopenharmony_ci }; 6723b3eb3cSopenharmony_ci aceView_->RegisterTouchEventCallback(touchEventCallback); 6823b3eb3cSopenharmony_ci} 6923b3eb3cSopenharmony_ci 7023b3eb3cSopenharmony_civoid DialogContainer::InitializeMouseEventCallback() 7123b3eb3cSopenharmony_ci{ 7223b3eb3cSopenharmony_ci ACE_DCHECK(aceView_ && taskExecutor_ && pipelineContext_); 7323b3eb3cSopenharmony_ci auto&& mouseEventCallback = [context = pipelineContext_, id = instanceId_]( 7423b3eb3cSopenharmony_ci const MouseEvent& event, const std::function<void()>& markProcess, 7523b3eb3cSopenharmony_ci const RefPtr<OHOS::Ace::NG::FrameNode>& node) { 7623b3eb3cSopenharmony_ci ContainerScope scope(id); 7723b3eb3cSopenharmony_ci context->GetTaskExecutor()->PostTask( 7823b3eb3cSopenharmony_ci [context, event, markProcess]() { 7923b3eb3cSopenharmony_ci context->OnMouseEvent(event); 8023b3eb3cSopenharmony_ci CHECK_NULL_VOID(markProcess); 8123b3eb3cSopenharmony_ci markProcess(); 8223b3eb3cSopenharmony_ci }, 8323b3eb3cSopenharmony_ci TaskExecutor::TaskType::UI, "ArkUIDialogMouseEvent"); 8423b3eb3cSopenharmony_ci }; 8523b3eb3cSopenharmony_ci aceView_->RegisterMouseEventCallback(mouseEventCallback); 8623b3eb3cSopenharmony_ci} 8723b3eb3cSopenharmony_ci 8823b3eb3cSopenharmony_civoid DialogContainer::InitializeAxisEventCallback() 8923b3eb3cSopenharmony_ci{ 9023b3eb3cSopenharmony_ci ACE_DCHECK(aceView_ && taskExecutor_ && pipelineContext_); 9123b3eb3cSopenharmony_ci auto&& axisEventCallback = [context = pipelineContext_, id = instanceId_]( 9223b3eb3cSopenharmony_ci const AxisEvent& event, const std::function<void()>& markProcess, 9323b3eb3cSopenharmony_ci const RefPtr<OHOS::Ace::NG::FrameNode>& node) { 9423b3eb3cSopenharmony_ci ContainerScope scope(id); 9523b3eb3cSopenharmony_ci context->GetTaskExecutor()->PostTask( 9623b3eb3cSopenharmony_ci [context, event, markProcess]() { 9723b3eb3cSopenharmony_ci context->OnAxisEvent(event); 9823b3eb3cSopenharmony_ci CHECK_NULL_VOID(markProcess); 9923b3eb3cSopenharmony_ci markProcess(); 10023b3eb3cSopenharmony_ci }, 10123b3eb3cSopenharmony_ci TaskExecutor::TaskType::UI, "ArkUIDialogAxisEvent"); 10223b3eb3cSopenharmony_ci }; 10323b3eb3cSopenharmony_ci aceView_->RegisterAxisEventCallback(axisEventCallback); 10423b3eb3cSopenharmony_ci} 10523b3eb3cSopenharmony_ci 10623b3eb3cSopenharmony_civoid DialogContainer::InitializeKeyEventCallback() 10723b3eb3cSopenharmony_ci{ 10823b3eb3cSopenharmony_ci ACE_DCHECK(aceView_ && taskExecutor_ && pipelineContext_); 10923b3eb3cSopenharmony_ci auto&& keyEventCallback = [context = pipelineContext_, id = instanceId_](const KeyEvent& event) { 11023b3eb3cSopenharmony_ci ContainerScope scope(id); 11123b3eb3cSopenharmony_ci bool result = false; 11223b3eb3cSopenharmony_ci context->GetTaskExecutor()->PostSyncTask( 11323b3eb3cSopenharmony_ci [context, event, &result]() { result = context->OnKeyEvent(event); }, 11423b3eb3cSopenharmony_ci TaskExecutor::TaskType::UI, "ArkUIDialogKeyEvent"); 11523b3eb3cSopenharmony_ci return result; 11623b3eb3cSopenharmony_ci }; 11723b3eb3cSopenharmony_ci aceView_->RegisterKeyEventCallback(keyEventCallback); 11823b3eb3cSopenharmony_ci} 11923b3eb3cSopenharmony_ci 12023b3eb3cSopenharmony_civoid DialogContainer::InitializeRotationEventCallback() 12123b3eb3cSopenharmony_ci{ 12223b3eb3cSopenharmony_ci ACE_DCHECK(aceView_ && taskExecutor_ && pipelineContext_); 12323b3eb3cSopenharmony_ci auto&& rotationEventCallback = [context = pipelineContext_, id = instanceId_](const RotationEvent& event) { 12423b3eb3cSopenharmony_ci ContainerScope scope(id); 12523b3eb3cSopenharmony_ci bool result = false; 12623b3eb3cSopenharmony_ci context->GetTaskExecutor()->PostSyncTask( 12723b3eb3cSopenharmony_ci [context, event, &result]() { result = context->OnRotationEvent(event); }, 12823b3eb3cSopenharmony_ci TaskExecutor::TaskType::UI, "ArkUIDialogRotationEvent"); 12923b3eb3cSopenharmony_ci return result; 13023b3eb3cSopenharmony_ci }; 13123b3eb3cSopenharmony_ci aceView_->RegisterRotationEventCallback(rotationEventCallback); 13223b3eb3cSopenharmony_ci} 13323b3eb3cSopenharmony_ci 13423b3eb3cSopenharmony_civoid DialogContainer::InitializeViewChangeCallback() 13523b3eb3cSopenharmony_ci{ 13623b3eb3cSopenharmony_ci ACE_DCHECK(aceView_ && taskExecutor_ && pipelineContext_); 13723b3eb3cSopenharmony_ci auto&& viewChangeCallback = [context = pipelineContext_, id = instanceId_](int32_t width, int32_t height, 13823b3eb3cSopenharmony_ci WindowSizeChangeReason type, 13923b3eb3cSopenharmony_ci const std::shared_ptr<Rosen::RSTransaction>& rsTransaction) { 14023b3eb3cSopenharmony_ci ContainerScope scope(id); 14123b3eb3cSopenharmony_ci ACE_SCOPED_TRACE("ViewChangeCallback(%d, %d)", width, height); 14223b3eb3cSopenharmony_ci context->GetTaskExecutor()->PostTask( 14323b3eb3cSopenharmony_ci [context, width, height, type, rsTransaction]() { 14423b3eb3cSopenharmony_ci context->OnSurfaceChanged(width, height, type, rsTransaction); 14523b3eb3cSopenharmony_ci }, 14623b3eb3cSopenharmony_ci TaskExecutor::TaskType::UI, "ArkUIDialogSurfaceChanged"); 14723b3eb3cSopenharmony_ci }; 14823b3eb3cSopenharmony_ci aceView_->RegisterViewChangeCallback(viewChangeCallback); 14923b3eb3cSopenharmony_ci} 15023b3eb3cSopenharmony_ci 15123b3eb3cSopenharmony_civoid DialogContainer::InitializeDensityChangeCallback() 15223b3eb3cSopenharmony_ci{ 15323b3eb3cSopenharmony_ci ACE_DCHECK(aceView_ && taskExecutor_ && pipelineContext_); 15423b3eb3cSopenharmony_ci auto&& densityChangeCallback = [context = pipelineContext_, id = instanceId_](double density) { 15523b3eb3cSopenharmony_ci ContainerScope scope(id); 15623b3eb3cSopenharmony_ci ACE_SCOPED_TRACE("DensityChangeCallback(%lf)", density); 15723b3eb3cSopenharmony_ci context->GetTaskExecutor()->PostTask( 15823b3eb3cSopenharmony_ci [context, density]() { context->OnSurfaceDensityChanged(density); }, 15923b3eb3cSopenharmony_ci TaskExecutor::TaskType::UI, "ArkUIDialogSurfaceDensityChanged"); 16023b3eb3cSopenharmony_ci }; 16123b3eb3cSopenharmony_ci aceView_->RegisterDensityChangeCallback(densityChangeCallback); 16223b3eb3cSopenharmony_ci} 16323b3eb3cSopenharmony_ci 16423b3eb3cSopenharmony_civoid DialogContainer::InitializeSystemBarHeightChangeCallback() 16523b3eb3cSopenharmony_ci{ 16623b3eb3cSopenharmony_ci ACE_DCHECK(aceView_ && taskExecutor_ && pipelineContext_); 16723b3eb3cSopenharmony_ci auto&& systemBarHeightChangeCallback = [context = pipelineContext_, id = instanceId_]( 16823b3eb3cSopenharmony_ci double statusBar, double navigationBar) { 16923b3eb3cSopenharmony_ci ContainerScope scope(id); 17023b3eb3cSopenharmony_ci ACE_SCOPED_TRACE("SystemBarHeightChangeCallback(%lf, %lf)", statusBar, navigationBar); 17123b3eb3cSopenharmony_ci context->GetTaskExecutor()->PostTask( 17223b3eb3cSopenharmony_ci [context, statusBar, navigationBar]() { context->OnSystemBarHeightChanged(statusBar, navigationBar); }, 17323b3eb3cSopenharmony_ci TaskExecutor::TaskType::UI, "ArkUIDialogSystemBarHeightChanged"); 17423b3eb3cSopenharmony_ci }; 17523b3eb3cSopenharmony_ci aceView_->RegisterSystemBarHeightChangeCallback(systemBarHeightChangeCallback); 17623b3eb3cSopenharmony_ci} 17723b3eb3cSopenharmony_ci 17823b3eb3cSopenharmony_civoid DialogContainer::InitializeSurfaceDestroyCallback() 17923b3eb3cSopenharmony_ci{ 18023b3eb3cSopenharmony_ci ACE_DCHECK(aceView_ && taskExecutor_ && pipelineContext_); 18123b3eb3cSopenharmony_ci auto&& surfaceDestroyCallback = [context = pipelineContext_, id = instanceId_]() { 18223b3eb3cSopenharmony_ci ContainerScope scope(id); 18323b3eb3cSopenharmony_ci context->GetTaskExecutor()->PostTask( 18423b3eb3cSopenharmony_ci [context]() { context->OnSurfaceDestroyed(); }, 18523b3eb3cSopenharmony_ci TaskExecutor::TaskType::UI, "ArkUIDialogSurfaceDestroyed"); 18623b3eb3cSopenharmony_ci }; 18723b3eb3cSopenharmony_ci aceView_->RegisterSurfaceDestroyCallback(surfaceDestroyCallback); 18823b3eb3cSopenharmony_ci} 18923b3eb3cSopenharmony_ci 19023b3eb3cSopenharmony_civoid DialogContainer::InitializeDragEventCallback() 19123b3eb3cSopenharmony_ci{ 19223b3eb3cSopenharmony_ci ACE_DCHECK(aceView_ && taskExecutor_ && pipelineContext_); 19323b3eb3cSopenharmony_ci auto&& dragEventCallback = [context = pipelineContext_, id = instanceId_]( 19423b3eb3cSopenharmony_ci const PointerEvent& pointerEvent, const DragEventAction& action, 19523b3eb3cSopenharmony_ci const RefPtr<OHOS::Ace::NG::FrameNode>& node) { 19623b3eb3cSopenharmony_ci ContainerScope scope(id); 19723b3eb3cSopenharmony_ci context->GetTaskExecutor()->PostTask( 19823b3eb3cSopenharmony_ci [context, pointerEvent, action, node]() { context->OnDragEvent(pointerEvent, action, node); }, 19923b3eb3cSopenharmony_ci TaskExecutor::TaskType::UI, "ArkUIDialogDragEvent"); 20023b3eb3cSopenharmony_ci }; 20123b3eb3cSopenharmony_ci aceView_->RegisterDragEventCallback(dragEventCallback); 20223b3eb3cSopenharmony_ci} 20323b3eb3cSopenharmony_ci 20423b3eb3cSopenharmony_civoid DialogContainer::InitializeCallback() 20523b3eb3cSopenharmony_ci{ 20623b3eb3cSopenharmony_ci ACE_FUNCTION_TRACE(); 20723b3eb3cSopenharmony_ci InitializeTouchEventCallback(); 20823b3eb3cSopenharmony_ci InitializeMouseEventCallback(); 20923b3eb3cSopenharmony_ci InitializeAxisEventCallback(); 21023b3eb3cSopenharmony_ci InitializeKeyEventCallback(); 21123b3eb3cSopenharmony_ci InitializeRotationEventCallback(); 21223b3eb3cSopenharmony_ci InitializeViewChangeCallback(); 21323b3eb3cSopenharmony_ci InitializeDensityChangeCallback(); 21423b3eb3cSopenharmony_ci InitializeSystemBarHeightChangeCallback(); 21523b3eb3cSopenharmony_ci InitializeSurfaceDestroyCallback(); 21623b3eb3cSopenharmony_ci InitializeDragEventCallback(); 21723b3eb3cSopenharmony_ci} 21823b3eb3cSopenharmony_ci 21923b3eb3cSopenharmony_ciRefPtr<DialogContainer> DialogContainer::GetContainer(int32_t instanceId) 22023b3eb3cSopenharmony_ci{ 22123b3eb3cSopenharmony_ci auto container = AceEngine::Get().GetContainer(instanceId); 22223b3eb3cSopenharmony_ci CHECK_NULL_RETURN(container, nullptr); 22323b3eb3cSopenharmony_ci auto dialogContainer = AceType::DynamicCast<DialogContainer>(container); 22423b3eb3cSopenharmony_ci return dialogContainer; 22523b3eb3cSopenharmony_ci} 22623b3eb3cSopenharmony_ci 22723b3eb3cSopenharmony_civoid DialogContainer::DestroyContainer(int32_t instanceId, const std::function<void()>& destroyCallback) 22823b3eb3cSopenharmony_ci{ 22923b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_DIALOG, "DialogContainer DestroyContainer begin %{public}d", instanceId); 23023b3eb3cSopenharmony_ci auto container = AceEngine::Get().GetContainer(instanceId); 23123b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 23223b3eb3cSopenharmony_ci container->Destroy(); 23323b3eb3cSopenharmony_ci auto taskExecutor = container->GetTaskExecutor(); 23423b3eb3cSopenharmony_ci CHECK_NULL_VOID(taskExecutor); 23523b3eb3cSopenharmony_ci taskExecutor->PostSyncTask( 23623b3eb3cSopenharmony_ci [] { TAG_LOGI(AceLogTag::ACE_DIALOG, "Wait UI thread..."); }, 23723b3eb3cSopenharmony_ci TaskExecutor::TaskType::UI, "ArkUIDialogWaitLog"); 23823b3eb3cSopenharmony_ci taskExecutor->PostSyncTask( 23923b3eb3cSopenharmony_ci [] { TAG_LOGI(AceLogTag::ACE_DIALOG, "Wait JS thread..."); }, 24023b3eb3cSopenharmony_ci TaskExecutor::TaskType::JS, "ArkUIDialogWaitLog"); 24123b3eb3cSopenharmony_ci container->DestroyView(); // Stop all threads(ui,gpu,io) for current ability. 24223b3eb3cSopenharmony_ci taskExecutor->PostTask( 24323b3eb3cSopenharmony_ci [instanceId, destroyCallback] { 24423b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_DIALOG, "DialogContainer DestroyContainer Remove on Platform thread..."); 24523b3eb3cSopenharmony_ci EngineHelper::RemoveEngine(instanceId); 24623b3eb3cSopenharmony_ci AceEngine::Get().RemoveContainer(instanceId); 24723b3eb3cSopenharmony_ci CHECK_NULL_VOID(destroyCallback); 24823b3eb3cSopenharmony_ci destroyCallback(); 24923b3eb3cSopenharmony_ci }, 25023b3eb3cSopenharmony_ci TaskExecutor::TaskType::PLATFORM, "ArkUIDialogContainerDestroy"); 25123b3eb3cSopenharmony_ci} 25223b3eb3cSopenharmony_ci 25323b3eb3cSopenharmony_civoid DialogContainer::Destroy() 25423b3eb3cSopenharmony_ci{ 25523b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_DIALOG, "DialogContainer Destroy begin"); 25623b3eb3cSopenharmony_ci ContainerScope scope(instanceId_); 25723b3eb3cSopenharmony_ci if (pipelineContext_ && taskExecutor_) { 25823b3eb3cSopenharmony_ci // 1. Destroy Pipeline on UI thread. 25923b3eb3cSopenharmony_ci RefPtr<PipelineBase>& context = pipelineContext_; 26023b3eb3cSopenharmony_ci if (GetSettings().usePlatformAsUIThread) { 26123b3eb3cSopenharmony_ci context->Destroy(); 26223b3eb3cSopenharmony_ci } else { 26323b3eb3cSopenharmony_ci taskExecutor_->PostTask([context]() { context->Destroy(); }, 26423b3eb3cSopenharmony_ci TaskExecutor::TaskType::UI, "ArkUIDialogDestoryPipeline"); 26523b3eb3cSopenharmony_ci } 26623b3eb3cSopenharmony_ci // 2. Destroy Frontend on JS thread. 26723b3eb3cSopenharmony_ci RefPtr<Frontend>& frontend = frontend_; 26823b3eb3cSopenharmony_ci if (GetSettings().usePlatformAsUIThread && GetSettings().useUIAsJSThread) { 26923b3eb3cSopenharmony_ci frontend->UpdateState(Frontend::State::ON_DESTROY); 27023b3eb3cSopenharmony_ci frontend->Destroy(); 27123b3eb3cSopenharmony_ci } else { 27223b3eb3cSopenharmony_ci taskExecutor_->PostTask( 27323b3eb3cSopenharmony_ci [frontend]() { 27423b3eb3cSopenharmony_ci frontend->UpdateState(Frontend::State::ON_DESTROY); 27523b3eb3cSopenharmony_ci frontend->Destroy(); 27623b3eb3cSopenharmony_ci }, 27723b3eb3cSopenharmony_ci TaskExecutor::TaskType::JS, "ArkUIDialogFrontendDestroy"); 27823b3eb3cSopenharmony_ci } 27923b3eb3cSopenharmony_ci } 28023b3eb3cSopenharmony_ci DestroyToastSubwindow(instanceId_); 28123b3eb3cSopenharmony_ci resRegister_.Reset(); 28223b3eb3cSopenharmony_ci assetManager_.Reset(); 28323b3eb3cSopenharmony_ci} 28423b3eb3cSopenharmony_ci 28523b3eb3cSopenharmony_civoid DialogContainer::DestroyView() 28623b3eb3cSopenharmony_ci{ 28723b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_DIALOG, "DialogContainer DestroyView begin"); 28823b3eb3cSopenharmony_ci ContainerScope scope(instanceId_); 28923b3eb3cSopenharmony_ci std::lock_guard<std::mutex> lock(viewMutex_); 29023b3eb3cSopenharmony_ci aceView_ = nullptr; 29123b3eb3cSopenharmony_ci} 29223b3eb3cSopenharmony_ci 29323b3eb3cSopenharmony_civoid DialogContainer::SetView( 29423b3eb3cSopenharmony_ci const RefPtr<AceView>& view, double density, int32_t width, int32_t height, sptr<OHOS::Rosen::Window>& rsWindow) 29523b3eb3cSopenharmony_ci{ 29623b3eb3cSopenharmony_ci CHECK_NULL_VOID(view); 29723b3eb3cSopenharmony_ci auto container = AceType::DynamicCast<DialogContainer>(AceEngine::Get().GetContainer(view->GetInstanceId())); 29823b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 29923b3eb3cSopenharmony_ci#ifdef ENABLE_ROSEN_BACKEND 30023b3eb3cSopenharmony_ci auto taskExecutor = container->GetTaskExecutor(); 30123b3eb3cSopenharmony_ci CHECK_NULL_VOID(taskExecutor); 30223b3eb3cSopenharmony_ci 30323b3eb3cSopenharmony_ci auto window = std::make_shared<NG::RosenWindow>(rsWindow, taskExecutor, view->GetInstanceId()); 30423b3eb3cSopenharmony_ci#else 30523b3eb3cSopenharmony_ci auto platformWindow = PlatformWindow::Create(view); 30623b3eb3cSopenharmony_ci CHECK_NULL_VOID(platformWindow); 30723b3eb3cSopenharmony_ci auto window = std::make_shared<Window>(std::move(platformWindow)); 30823b3eb3cSopenharmony_ci#endif 30923b3eb3cSopenharmony_ci container->AttachView(std::move(window), view, density, width, height, rsWindow->GetWindowId()); 31023b3eb3cSopenharmony_ci} 31123b3eb3cSopenharmony_ci 31223b3eb3cSopenharmony_civoid DialogContainer::SetViewNew( 31323b3eb3cSopenharmony_ci const RefPtr<AceView>& view, double density, int32_t width, int32_t height, sptr<OHOS::Rosen::Window>& rsWindow) 31423b3eb3cSopenharmony_ci{ 31523b3eb3cSopenharmony_ci#ifdef ENABLE_ROSEN_BACKEND 31623b3eb3cSopenharmony_ci CHECK_NULL_VOID(view); 31723b3eb3cSopenharmony_ci auto container = AceType::DynamicCast<DialogContainer>(AceEngine::Get().GetContainer(view->GetInstanceId())); 31823b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 31923b3eb3cSopenharmony_ci auto taskExecutor = container->GetTaskExecutor(); 32023b3eb3cSopenharmony_ci CHECK_NULL_VOID(taskExecutor); 32123b3eb3cSopenharmony_ci 32223b3eb3cSopenharmony_ci auto window = std::make_shared<NG::RosenWindow>(rsWindow, taskExecutor, view->GetInstanceId()); 32323b3eb3cSopenharmony_ci container->AttachView(std::move(window), view, density, width, height, rsWindow->GetWindowId()); 32423b3eb3cSopenharmony_ci#endif 32523b3eb3cSopenharmony_ci} 32623b3eb3cSopenharmony_ci 32723b3eb3cSopenharmony_civoid DialogContainer::AttachView(std::shared_ptr<Window> window, const RefPtr<AceView>& view, double density, 32823b3eb3cSopenharmony_ci int32_t width, int32_t height, uint32_t windowId) 32923b3eb3cSopenharmony_ci{ 33023b3eb3cSopenharmony_ci aceView_ = view; 33123b3eb3cSopenharmony_ci auto instanceId = aceView_->GetInstanceId(); 33223b3eb3cSopenharmony_ci auto taskExecutorImpl = AceType::DynamicCast<TaskExecutorImpl>(taskExecutor_); 33323b3eb3cSopenharmony_ci auto aceView = AceType::DynamicCast<AceViewOhos>(aceView_); 33423b3eb3cSopenharmony_ci ACE_DCHECK(aceView != nullptr); 33523b3eb3cSopenharmony_ci taskExecutorImpl->InitOtherThreads(aceView->GetThreadModelImpl()); 33623b3eb3cSopenharmony_ci ContainerScope scope(instanceId); 33723b3eb3cSopenharmony_ci // For DECLARATIVE_JS frontend display UI in JS thread temporarily. 33823b3eb3cSopenharmony_ci taskExecutorImpl->InitJsThread(false); 33923b3eb3cSopenharmony_ci InitializeFrontend(); 34023b3eb3cSopenharmony_ci SetUseNewPipeline(); 34123b3eb3cSopenharmony_ci 34223b3eb3cSopenharmony_ci InitPipelineContext(std::move(window), instanceId, density, width, height, windowId); 34323b3eb3cSopenharmony_ci InitializeCallback(); 34423b3eb3cSopenharmony_ci CheckAndSetFontFamily(); 34523b3eb3cSopenharmony_ci 34623b3eb3cSopenharmony_ci taskExecutor_->PostTask([] { FrameReport::GetInstance().Init(); }, 34723b3eb3cSopenharmony_ci TaskExecutor::TaskType::UI, "ArkUIDialogFrameReportInit"); 34823b3eb3cSopenharmony_ci ThemeConstants::InitDeviceType(); 34923b3eb3cSopenharmony_ci // Load custom style at UI thread before frontend attach, to make sure style can be loaded before building dom tree. 35023b3eb3cSopenharmony_ci RefPtr<ThemeManagerImpl> themeManager = nullptr; 35123b3eb3cSopenharmony_ci if (SystemProperties::GetResourceDecoupling()) { 35223b3eb3cSopenharmony_ci auto resAdapter = ResourceAdapter::CreateV2(); 35323b3eb3cSopenharmony_ci themeManager = AceType::MakeRefPtr<ThemeManagerImpl>(resAdapter); 35423b3eb3cSopenharmony_ci } else { 35523b3eb3cSopenharmony_ci themeManager = AceType::MakeRefPtr<ThemeManagerImpl>(); 35623b3eb3cSopenharmony_ci } 35723b3eb3cSopenharmony_ci if (themeManager) { 35823b3eb3cSopenharmony_ci pipelineContext_->SetThemeManager(themeManager); 35923b3eb3cSopenharmony_ci // Init resource 36023b3eb3cSopenharmony_ci themeManager->InitResource(resourceInfo_); 36123b3eb3cSopenharmony_ci taskExecutor_->PostTask( 36223b3eb3cSopenharmony_ci [themeManager, assetManager = assetManager_, colorScheme = colorScheme_] { 36323b3eb3cSopenharmony_ci ACE_SCOPED_TRACE("OHOS::LoadThemes()"); 36423b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_DIALOG, "UIContent load theme"); 36523b3eb3cSopenharmony_ci themeManager->SetColorScheme(colorScheme); 36623b3eb3cSopenharmony_ci themeManager->LoadCustomTheme(assetManager); 36723b3eb3cSopenharmony_ci themeManager->LoadResourceThemes(); 36823b3eb3cSopenharmony_ci }, 36923b3eb3cSopenharmony_ci TaskExecutor::TaskType::UI, "ArkUIDialogLoadTheme"); 37023b3eb3cSopenharmony_ci } 37123b3eb3cSopenharmony_ci aceView_->Launch(); 37223b3eb3cSopenharmony_ci // Only MainWindow instance will be registered to watch dog. 37323b3eb3cSopenharmony_ci frontend_->AttachPipelineContext(pipelineContext_); 37423b3eb3cSopenharmony_ci#if defined(ENABLE_ROSEN_BACKEND) and !defined(UPLOAD_GPU_DISABLED) 37523b3eb3cSopenharmony_ci pipelineContext_->SetPostRTTaskCallBack([](std::function<void()>&& task) { 37623b3eb3cSopenharmony_ci auto syncTask = std::make_shared<AceRosenSyncTask>(std::move(task)); 37723b3eb3cSopenharmony_ci Rosen::RSTransactionProxy::GetInstance()->ExecuteSynchronousTask(syncTask); 37823b3eb3cSopenharmony_ci }); 37923b3eb3cSopenharmony_ci#endif 38023b3eb3cSopenharmony_ci} 38123b3eb3cSopenharmony_ci 38223b3eb3cSopenharmony_civoid DialogContainer::InitPipelineContext(std::shared_ptr<Window> window, int32_t instanceId, double density, 38323b3eb3cSopenharmony_ci int32_t width, int32_t height, uint32_t windowId) 38423b3eb3cSopenharmony_ci{ 38523b3eb3cSopenharmony_ci#ifdef NG_BUILD 38623b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_DIALOG, "New pipeline version creating..."); 38723b3eb3cSopenharmony_ci pipelineContext_ = AceType::MakeRefPtr<NG::PipelineContext>( 38823b3eb3cSopenharmony_ci std::move(window), taskExecutor_, assetManager_, resRegister_, frontend_, instanceId); 38923b3eb3cSopenharmony_ci#else 39023b3eb3cSopenharmony_ci if (useNewPipeline_) { 39123b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_DIALOG, "New pipeline version creating..."); 39223b3eb3cSopenharmony_ci pipelineContext_ = AceType::MakeRefPtr<NG::PipelineContext>( 39323b3eb3cSopenharmony_ci std::move(window), taskExecutor_, assetManager_, resRegister_, frontend_, instanceId); 39423b3eb3cSopenharmony_ci } else { 39523b3eb3cSopenharmony_ci pipelineContext_ = AceType::MakeRefPtr<PipelineContext>( 39623b3eb3cSopenharmony_ci std::move(window), taskExecutor_, assetManager_, resRegister_, frontend_, instanceId); 39723b3eb3cSopenharmony_ci } 39823b3eb3cSopenharmony_ci#endif 39923b3eb3cSopenharmony_ci pipelineContext_->SetRootSize(density, width, height); 40023b3eb3cSopenharmony_ci pipelineContext_->SetTextFieldManager(AceType::MakeRefPtr<TextFieldManager>()); 40123b3eb3cSopenharmony_ci pipelineContext_->SetIsRightToLeft(AceApplicationInfo::GetInstance().IsRightToLeft()); 40223b3eb3cSopenharmony_ci pipelineContext_->SetWindowId(windowId); 40323b3eb3cSopenharmony_ci pipelineContext_->SetWindowModal(windowModal_); 40423b3eb3cSopenharmony_ci pipelineContext_->SetDrawDelegate(aceView_->GetDrawDelegate()); 40523b3eb3cSopenharmony_ci pipelineContext_->SetIsSubPipeline(true); 40623b3eb3cSopenharmony_ci} 40723b3eb3cSopenharmony_ci 40823b3eb3cSopenharmony_civoid DialogContainer::InitializeFrontend() 40923b3eb3cSopenharmony_ci{ 41023b3eb3cSopenharmony_ci frontend_ = AceType::MakeRefPtr<DeclarativeFrontend>(); 41123b3eb3cSopenharmony_ci CHECK_NULL_VOID(frontend_); 41223b3eb3cSopenharmony_ci frontend_->Initialize(type_, taskExecutor_); 41323b3eb3cSopenharmony_ci auto front = GetFrontend(); 41423b3eb3cSopenharmony_ci CHECK_NULL_VOID(front); 41523b3eb3cSopenharmony_ci front->UpdateState(Frontend::State::ON_CREATE); 41623b3eb3cSopenharmony_ci front->SetJsMessageDispatcher(AceType::Claim(this)); 41723b3eb3cSopenharmony_ci front->SetAssetManager(assetManager_); 41823b3eb3cSopenharmony_ci} 41923b3eb3cSopenharmony_ci 42023b3eb3cSopenharmony_civoid DialogContainer::DumpHeapSnapshot(bool isPrivate) 42123b3eb3cSopenharmony_ci{ 42223b3eb3cSopenharmony_ci taskExecutor_->PostTask( 42323b3eb3cSopenharmony_ci [isPrivate, frontend = WeakPtr<Frontend>(frontend_)] { 42423b3eb3cSopenharmony_ci auto sp = frontend.Upgrade(); 42523b3eb3cSopenharmony_ci CHECK_NULL_VOID(sp); 42623b3eb3cSopenharmony_ci sp->DumpHeapSnapshot(isPrivate); 42723b3eb3cSopenharmony_ci }, 42823b3eb3cSopenharmony_ci TaskExecutor::TaskType::JS, "ArkUIDialogDumpHeapSnapshot"); 42923b3eb3cSopenharmony_ci} 43023b3eb3cSopenharmony_civoid DialogContainer::SetUIWindow(int32_t instanceId, sptr<OHOS::Rosen::Window>& uiWindow) 43123b3eb3cSopenharmony_ci{ 43223b3eb3cSopenharmony_ci CHECK_NULL_VOID(uiWindow); 43323b3eb3cSopenharmony_ci auto container = AceType::DynamicCast<DialogContainer>(AceEngine::Get().GetContainer(instanceId)); 43423b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 43523b3eb3cSopenharmony_ci container->SetUIWindowInner(uiWindow); 43623b3eb3cSopenharmony_ci} 43723b3eb3cSopenharmony_ci 43823b3eb3cSopenharmony_cisptr<OHOS::Rosen::Window> DialogContainer::GetUIWindow(int32_t instanceId) 43923b3eb3cSopenharmony_ci{ 44023b3eb3cSopenharmony_ci auto container = AceType::DynamicCast<DialogContainer>(AceEngine::Get().GetContainer(instanceId)); 44123b3eb3cSopenharmony_ci CHECK_NULL_RETURN(container, nullptr); 44223b3eb3cSopenharmony_ci return container->GetUIWindowInner(); 44323b3eb3cSopenharmony_ci} 44423b3eb3cSopenharmony_ci 44523b3eb3cSopenharmony_civoid DialogContainer::SetUIWindowInner(sptr<OHOS::Rosen::Window> uiWindow) 44623b3eb3cSopenharmony_ci{ 44723b3eb3cSopenharmony_ci uiWindow_ = std::move(uiWindow); 44823b3eb3cSopenharmony_ci} 44923b3eb3cSopenharmony_ci 45023b3eb3cSopenharmony_cisptr<OHOS::Rosen::Window> DialogContainer::GetUIWindowInner() const 45123b3eb3cSopenharmony_ci{ 45223b3eb3cSopenharmony_ci return uiWindow_; 45323b3eb3cSopenharmony_ci} 45423b3eb3cSopenharmony_ci 45523b3eb3cSopenharmony_civoid DialogContainer::ShowToast(int32_t instanceId, const std::string& message, int32_t duration, 45623b3eb3cSopenharmony_ci const std::string& bottom, std::function<void(int32_t)>&& callback) 45723b3eb3cSopenharmony_ci{ 45823b3eb3cSopenharmony_ci auto container = AceType::DynamicCast<DialogContainer>(AceEngine::Get().GetContainer(instanceId)); 45923b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 46023b3eb3cSopenharmony_ci auto frontend = AceType::DynamicCast<DeclarativeFrontend>(container->GetFrontend()); 46123b3eb3cSopenharmony_ci CHECK_NULL_VOID(frontend); 46223b3eb3cSopenharmony_ci auto delegate = frontend->GetDelegate(); 46323b3eb3cSopenharmony_ci CHECK_NULL_VOID(delegate); 46423b3eb3cSopenharmony_ci delegate->SetToastStopListenerCallback([instanceId = instanceId]() { 46523b3eb3cSopenharmony_ci if (ContainerScope::CurrentId() >= 0) { 46623b3eb3cSopenharmony_ci DialogContainer::HideWindow(instanceId); 46723b3eb3cSopenharmony_ci } 46823b3eb3cSopenharmony_ci }); 46923b3eb3cSopenharmony_ci auto toastInfo = NG::ToastInfo { .message = message, 47023b3eb3cSopenharmony_ci .duration = duration, 47123b3eb3cSopenharmony_ci .bottom = bottom, 47223b3eb3cSopenharmony_ci .showMode = NG::ToastShowMode::DEFAULT, 47323b3eb3cSopenharmony_ci .alignment = -1, 47423b3eb3cSopenharmony_ci .offset = std::nullopt }; 47523b3eb3cSopenharmony_ci delegate->ShowToast(toastInfo, std::move(callback)); 47623b3eb3cSopenharmony_ci} 47723b3eb3cSopenharmony_ci 47823b3eb3cSopenharmony_civoid DialogContainer::CloseToast(int32_t instanceId, int32_t toastId, std::function<void(int32_t)>&& callback) 47923b3eb3cSopenharmony_ci{ 48023b3eb3cSopenharmony_ci auto container = AceType::DynamicCast<DialogContainer>(AceEngine::Get().GetContainer(instanceId)); 48123b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 48223b3eb3cSopenharmony_ci 48323b3eb3cSopenharmony_ci auto frontend = AceType::DynamicCast<DeclarativeFrontend>(container->GetFrontend()); 48423b3eb3cSopenharmony_ci CHECK_NULL_VOID(frontend); 48523b3eb3cSopenharmony_ci 48623b3eb3cSopenharmony_ci auto delegate = frontend->GetDelegate(); 48723b3eb3cSopenharmony_ci CHECK_NULL_VOID(delegate); 48823b3eb3cSopenharmony_ci delegate->SetToastStopListenerCallback([instanceId = instanceId]() { 48923b3eb3cSopenharmony_ci if (ContainerScope::CurrentId() >= 0) { 49023b3eb3cSopenharmony_ci DialogContainer::HideWindow(instanceId); 49123b3eb3cSopenharmony_ci } 49223b3eb3cSopenharmony_ci }); 49323b3eb3cSopenharmony_ci 49423b3eb3cSopenharmony_ci delegate->CloseToast(toastId, std::move(callback)); 49523b3eb3cSopenharmony_ci} 49623b3eb3cSopenharmony_ci 49723b3eb3cSopenharmony_civoid DialogContainer::ShowDialog(int32_t instanceId, const std::string& title, const std::string& message, 49823b3eb3cSopenharmony_ci const std::vector<ButtonInfo>& buttons, bool autoCancel, std::function<void(int32_t, int32_t)>&& callback, 49923b3eb3cSopenharmony_ci const std::set<std::string>& callbacks) 50023b3eb3cSopenharmony_ci{ 50123b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_DIALOG, "DialogContainer ShowDialog begin"); 50223b3eb3cSopenharmony_ci auto container = AceType::DynamicCast<DialogContainer>(AceEngine::Get().GetContainer(instanceId)); 50323b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 50423b3eb3cSopenharmony_ci auto frontend = AceType::DynamicCast<DeclarativeFrontend>(container->GetFrontend()); 50523b3eb3cSopenharmony_ci CHECK_NULL_VOID(frontend); 50623b3eb3cSopenharmony_ci auto delegate = frontend->GetDelegate(); 50723b3eb3cSopenharmony_ci CHECK_NULL_VOID(delegate); 50823b3eb3cSopenharmony_ci delegate->ShowDialog( 50923b3eb3cSopenharmony_ci title, message, buttons, autoCancel, std::move(callback), callbacks, [instanceId = instanceId](bool isShow) { 51023b3eb3cSopenharmony_ci TAG_LOGI( 51123b3eb3cSopenharmony_ci AceLogTag::ACE_DIALOG, "DialogContainer ShowDialog HideWindow instanceId = %{public}d", instanceId); 51223b3eb3cSopenharmony_ci if (!isShow) { 51323b3eb3cSopenharmony_ci DialogContainer::HideWindow(instanceId); 51423b3eb3cSopenharmony_ci } 51523b3eb3cSopenharmony_ci }); 51623b3eb3cSopenharmony_ci} 51723b3eb3cSopenharmony_ci 51823b3eb3cSopenharmony_civoid DialogContainer::ShowDialog(int32_t instanceId, const PromptDialogAttr& dialogAttr, 51923b3eb3cSopenharmony_ci const std::vector<ButtonInfo>& buttons, std::function<void(int32_t, int32_t)>&& callback, 52023b3eb3cSopenharmony_ci const std::set<std::string>& callbacks) 52123b3eb3cSopenharmony_ci{ 52223b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_DIALOG, "DialogContainer ShowDialog with attr begin"); 52323b3eb3cSopenharmony_ci auto container = AceType::DynamicCast<DialogContainer>(AceEngine::Get().GetContainer(instanceId)); 52423b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 52523b3eb3cSopenharmony_ci auto frontend = AceType::DynamicCast<DeclarativeFrontend>(container->GetFrontend()); 52623b3eb3cSopenharmony_ci CHECK_NULL_VOID(frontend); 52723b3eb3cSopenharmony_ci auto delegate = frontend->GetDelegate(); 52823b3eb3cSopenharmony_ci CHECK_NULL_VOID(delegate); 52923b3eb3cSopenharmony_ci delegate->ShowDialog(dialogAttr, buttons, std::move(callback), callbacks, [instanceId = instanceId](bool isShow) { 53023b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_DIALOG, "DialogContainer ShowDialog HideWindow instanceId = %{public}d", instanceId); 53123b3eb3cSopenharmony_ci if (!isShow) { 53223b3eb3cSopenharmony_ci DialogContainer::HideWindow(instanceId); 53323b3eb3cSopenharmony_ci } 53423b3eb3cSopenharmony_ci }); 53523b3eb3cSopenharmony_ci} 53623b3eb3cSopenharmony_ci 53723b3eb3cSopenharmony_civoid DialogContainer::ShowActionMenu(int32_t instanceId, const std::string& title, 53823b3eb3cSopenharmony_ci const std::vector<ButtonInfo>& button, std::function<void(int32_t, int32_t)>&& callback) 53923b3eb3cSopenharmony_ci{ 54023b3eb3cSopenharmony_ci auto container = AceType::DynamicCast<DialogContainer>(AceEngine::Get().GetContainer(instanceId)); 54123b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 54223b3eb3cSopenharmony_ci auto frontend = AceType::DynamicCast<DeclarativeFrontend>(container->GetFrontend()); 54323b3eb3cSopenharmony_ci CHECK_NULL_VOID(frontend); 54423b3eb3cSopenharmony_ci auto delegate = frontend->GetDelegate(); 54523b3eb3cSopenharmony_ci CHECK_NULL_VOID(delegate); 54623b3eb3cSopenharmony_ci delegate->ShowActionMenu(title, button, std::move(callback), [instanceId = instanceId](bool isShow) { 54723b3eb3cSopenharmony_ci if (!isShow) { 54823b3eb3cSopenharmony_ci DialogContainer::HideWindow(instanceId); 54923b3eb3cSopenharmony_ci } 55023b3eb3cSopenharmony_ci }); 55123b3eb3cSopenharmony_ci} 55223b3eb3cSopenharmony_ci 55323b3eb3cSopenharmony_cibool DialogContainer::ShowToastDialogWindow( 55423b3eb3cSopenharmony_ci int32_t instanceId, int32_t posX, int32_t posY, int32_t width, int32_t height, bool isToast) 55523b3eb3cSopenharmony_ci{ 55623b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_DIALOG, "DialogContainer ShowToastDialogWindow begin"); 55723b3eb3cSopenharmony_ci auto container = AceType::DynamicCast<DialogContainer>(AceEngine::Get().GetContainer(instanceId)); 55823b3eb3cSopenharmony_ci CHECK_NULL_RETURN(container, false); 55923b3eb3cSopenharmony_ci auto window = container->GetUIWindowInner(); 56023b3eb3cSopenharmony_ci CHECK_NULL_RETURN(window, false); 56123b3eb3cSopenharmony_ci window->SetTransparent(true); 56223b3eb3cSopenharmony_ci if (isToast) { 56323b3eb3cSopenharmony_ci window->SetTouchable(false); 56423b3eb3cSopenharmony_ci } 56523b3eb3cSopenharmony_ci window->SetNeedDefaultAnimation(false); 56623b3eb3cSopenharmony_ci OHOS::Rosen::WMError ret = window->MoveTo(posX, posY); 56723b3eb3cSopenharmony_ci if (ret != OHOS::Rosen::WMError::WM_OK) { 56823b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_DIALOG, "DialogContainer ShowToastDialogWindow MoveTo window failed code: %{public}d", 56923b3eb3cSopenharmony_ci static_cast<int32_t>(ret)); 57023b3eb3cSopenharmony_ci return false; 57123b3eb3cSopenharmony_ci } 57223b3eb3cSopenharmony_ci ret = window->Resize(width, height); 57323b3eb3cSopenharmony_ci if (ret != OHOS::Rosen::WMError::WM_OK) { 57423b3eb3cSopenharmony_ci TAG_LOGW(AceLogTag::ACE_DIALOG, "DialogContainer ShowToastDialogWindow Resize window failed code: %{public}d", 57523b3eb3cSopenharmony_ci static_cast<int32_t>(ret)); 57623b3eb3cSopenharmony_ci return false; 57723b3eb3cSopenharmony_ci } 57823b3eb3cSopenharmony_ci ret = window->Show(); 57923b3eb3cSopenharmony_ci if (ret != OHOS::Rosen::WMError::WM_OK) { 58023b3eb3cSopenharmony_ci TAG_LOGE(AceLogTag::ACE_DIALOG, "DialogContainer ShowToastDialogWindow Show window failed code: %{public}d", 58123b3eb3cSopenharmony_ci static_cast<int32_t>(ret)); 58223b3eb3cSopenharmony_ci return false; 58323b3eb3cSopenharmony_ci } 58423b3eb3cSopenharmony_ci return true; 58523b3eb3cSopenharmony_ci} 58623b3eb3cSopenharmony_ci 58723b3eb3cSopenharmony_cibool DialogContainer::HideWindow(int32_t instanceId) 58823b3eb3cSopenharmony_ci{ 58923b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_DIALOG, "DialogContainer HideWindow begin"); 59023b3eb3cSopenharmony_ci auto container = AceType::DynamicCast<DialogContainer>(AceEngine::Get().GetContainer(instanceId)); 59123b3eb3cSopenharmony_ci CHECK_NULL_RETURN(container, false); 59223b3eb3cSopenharmony_ci auto window = container->GetUIWindowInner(); 59323b3eb3cSopenharmony_ci CHECK_NULL_RETURN(window, false); 59423b3eb3cSopenharmony_ci OHOS::Rosen::WMError ret = window->Hide(); 59523b3eb3cSopenharmony_ci if (ret != OHOS::Rosen::WMError::WM_OK) { 59623b3eb3cSopenharmony_ci TAG_LOGE(AceLogTag::ACE_DIALOG, "DialogContainer HideWindow Failed to hide the window."); 59723b3eb3cSopenharmony_ci return false; 59823b3eb3cSopenharmony_ci } 59923b3eb3cSopenharmony_ci sptr<OHOS::Rosen::Window> uiWindow = nullptr; 60023b3eb3cSopenharmony_ci DialogContainer::SetUIWindow(instanceId, uiWindow); 60123b3eb3cSopenharmony_ci return true; 60223b3eb3cSopenharmony_ci} 60323b3eb3cSopenharmony_ci 60423b3eb3cSopenharmony_cibool DialogContainer::CloseWindow(int32_t instanceId) 60523b3eb3cSopenharmony_ci{ 60623b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_DIALOG, "DialogContainer CloseWindow begin"); 60723b3eb3cSopenharmony_ci auto container = AceType::DynamicCast<DialogContainer>(AceEngine::Get().GetContainer(instanceId)); 60823b3eb3cSopenharmony_ci CHECK_NULL_RETURN(container, false); 60923b3eb3cSopenharmony_ci auto window = container->GetUIWindowInner(); 61023b3eb3cSopenharmony_ci CHECK_NULL_RETURN(window, false); 61123b3eb3cSopenharmony_ci OHOS::Rosen::WMError ret = window->Close(); 61223b3eb3cSopenharmony_ci if (ret != OHOS::Rosen::WMError::WM_OK) { 61323b3eb3cSopenharmony_ci TAG_LOGE(AceLogTag::ACE_DIALOG, "DialogContainer CloseWindow Failed to close the window."); 61423b3eb3cSopenharmony_ci return false; 61523b3eb3cSopenharmony_ci } 61623b3eb3cSopenharmony_ci sptr<OHOS::Rosen::Window> uiWindow = nullptr; 61723b3eb3cSopenharmony_ci DialogContainer::SetUIWindow(instanceId, uiWindow); 61823b3eb3cSopenharmony_ci return true; 61923b3eb3cSopenharmony_ci} 62023b3eb3cSopenharmony_ci 62123b3eb3cSopenharmony_cibool DialogContainer::OnBackPressed(int32_t instanceId) 62223b3eb3cSopenharmony_ci{ 62323b3eb3cSopenharmony_ci return DialogContainer::CloseWindow(instanceId); 62423b3eb3cSopenharmony_ci} 62523b3eb3cSopenharmony_ci 62623b3eb3cSopenharmony_civoid DialogContainer::SetFontScaleAndWeightScale(int32_t instanceId) 62723b3eb3cSopenharmony_ci{ 62823b3eb3cSopenharmony_ci float fontScale = SystemProperties::GetFontScale(); 62923b3eb3cSopenharmony_ci float fontWeightScale = SystemProperties::GetFontWeightScale(); 63023b3eb3cSopenharmony_ci Container::SetFontScale(instanceId, fontScale); 63123b3eb3cSopenharmony_ci Container::SetFontWeightScale(instanceId, fontWeightScale); 63223b3eb3cSopenharmony_ci} 63323b3eb3cSopenharmony_ci 63423b3eb3cSopenharmony_civoid DialogContainer::UpdateConfiguration(const ParsedConfig& parsedConfig) 63523b3eb3cSopenharmony_ci{ 63623b3eb3cSopenharmony_ci if (!parsedConfig.IsValid()) { 63723b3eb3cSopenharmony_ci LOGW("DialogContainer::OnConfigurationUpdated param is empty"); 63823b3eb3cSopenharmony_ci return; 63923b3eb3cSopenharmony_ci } 64023b3eb3cSopenharmony_ci 64123b3eb3cSopenharmony_ci CHECK_NULL_VOID(pipelineContext_); 64223b3eb3cSopenharmony_ci auto themeManager = pipelineContext_->GetThemeManager(); 64323b3eb3cSopenharmony_ci CHECK_NULL_VOID(themeManager); 64423b3eb3cSopenharmony_ci auto resConfig = GetResourceConfiguration(); 64523b3eb3cSopenharmony_ci if (!parsedConfig.colorMode.empty()) { 64623b3eb3cSopenharmony_ci if (parsedConfig.colorMode == "dark") { 64723b3eb3cSopenharmony_ci SystemProperties::SetColorMode(ColorMode::DARK); 64823b3eb3cSopenharmony_ci resConfig.SetColorMode(ColorMode::DARK); 64923b3eb3cSopenharmony_ci } else { 65023b3eb3cSopenharmony_ci SystemProperties::SetColorMode(ColorMode::LIGHT); 65123b3eb3cSopenharmony_ci resConfig.SetColorMode(ColorMode::LIGHT); 65223b3eb3cSopenharmony_ci } 65323b3eb3cSopenharmony_ci } 65423b3eb3cSopenharmony_ci 65523b3eb3cSopenharmony_ci SetResourceConfiguration(resConfig); 65623b3eb3cSopenharmony_ci themeManager->UpdateConfig(resConfig); 65723b3eb3cSopenharmony_ci themeManager->LoadResourceThemes(); 65823b3eb3cSopenharmony_ci // change color mode and theme to clear image cache 65923b3eb3cSopenharmony_ci pipelineContext_->ClearImageCache(); 66023b3eb3cSopenharmony_ci} 66123b3eb3cSopenharmony_ci 66223b3eb3cSopenharmony_civoid DialogContainer::CheckAndSetFontFamily() 66323b3eb3cSopenharmony_ci{ 66423b3eb3cSopenharmony_ci CHECK_NULL_VOID(pipelineContext_); 66523b3eb3cSopenharmony_ci auto fontManager = pipelineContext_->GetFontManager(); 66623b3eb3cSopenharmony_ci CHECK_NULL_VOID(fontManager); 66723b3eb3cSopenharmony_ci if (fontManager->IsUseAppCustomFont()) { 66823b3eb3cSopenharmony_ci return; 66923b3eb3cSopenharmony_ci } 67023b3eb3cSopenharmony_ci std::string familyName = ""; 67123b3eb3cSopenharmony_ci std::string path = "/data/themes/a/app"; 67223b3eb3cSopenharmony_ci if (!IsFontFileExistInPath(path)) { 67323b3eb3cSopenharmony_ci path = "/data/themes/b/app"; 67423b3eb3cSopenharmony_ci if (!IsFontFileExistInPath(path)) { 67523b3eb3cSopenharmony_ci return; 67623b3eb3cSopenharmony_ci } 67723b3eb3cSopenharmony_ci } 67823b3eb3cSopenharmony_ci path = path.append("/fonts/"); 67923b3eb3cSopenharmony_ci familyName = GetFontFamilyName(path); 68023b3eb3cSopenharmony_ci if (familyName.empty()) { 68123b3eb3cSopenharmony_ci return; 68223b3eb3cSopenharmony_ci } 68323b3eb3cSopenharmony_ci path = path.append(familyName); 68423b3eb3cSopenharmony_ci fontManager->SetFontFamily(familyName.c_str(), path.c_str()); 68523b3eb3cSopenharmony_ci} 68623b3eb3cSopenharmony_ci} // namespace OHOS::Ace::Platform 687