• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 #include "core/interfaces/native/node/custom_dialog_model.h"
16 
17 #include "interfaces/native/node/dialog_model.h"
18 
19 #include "base/error/error_code.h"
20 #include "core/components_ng/pattern/dialog/custom_dialog_controller_model_ng.h"
21 #include "core/components_ng/pattern/overlay/dialog_manager.h"
22 #include "frameworks/core/components/dialog/dialog_properties.h"
23 #include "frameworks/core/components/theme/shadow_theme.h"
24 #include "bridge/common/utils/engine_helper.h"
25 
26 namespace OHOS::Ace::NG::CustomDialog {
27 namespace {
28     constexpr int32_t DEFAULT_DIALOG_ALIGNMENT = -1;
29     constexpr uint32_t DEFAULT_MASK_COLOR = 0x33000000;
30     constexpr uint32_t DEFAULT_DIALOG_BACKGROUND_COLOR = 0x00000000;
31     constexpr int32_t ARKUI_ALIGNMENT_TOP_START_INDEX = 0;
32     constexpr int32_t ARKUI_ALIGNMENT_TOP_INDEX = 1;
33     constexpr int32_t ARKUI_ALIGNMENT_TOP_END_INDEX = 2;
34     constexpr int32_t ARKUI_ALIGNMENT_START_INDEX = 3;
35     constexpr int32_t ARKUI_ALIGNMENT_CENTER_INDEX = 4;
36     constexpr int32_t ARKUI_ALIGNMENT_END_INDEX = 5;
37     constexpr int32_t ARKUI_ALIGNMENT_BOTTOM_START_INDEX = 6;
38     constexpr int32_t ARKUI_ALIGNMENT_BOTTOM_INDEX = 7;
39     constexpr int32_t ARKUI_ALIGNMENT_BOTTOM_END_INDEX = 8;
40     constexpr float DEFAULT_AVOID_DISTANCE = 16.0f;
41     constexpr int32_t ARKUI_LEVEL_MODE_DEFAULT_VALUE = 0;
42     constexpr int32_t ARKUI_DEFAULT_LEVEL_UNIQUEID = -1;
43     constexpr int32_t ARKUI_IMMERSIVE_MODE_DEFAULT_VALUE = 0;
44     constexpr int32_t ARKUI_BLUR_STYLE_COMPONENT_ULTRA_THICK = 12;
45     constexpr int32_t HAS_COLORSTRATEGY = 1;
46     constexpr int32_t HAS_COLOR = 2;
47     constexpr int NUM_0 = 0;
48     constexpr int NUM_1 = 1;
49     constexpr int NUM_2 = 2;
50     constexpr int NUM_3 = 3;
51     constexpr int NUM_4 = 4;
52     constexpr int NUM_5 = 5;
53     constexpr int NUM_6 = 6;
54     constexpr int NUM_7 = 7;
55     constexpr int32_t DEFAULT_BORDER_WIDTH = 0;
56     constexpr uint32_t DEFAULT_BORDER_COLOR = 0xff000000;
57     constexpr int32_t DEFAULT_BORDER_STYLE = static_cast<int32_t>(OHOS::Ace::BorderStyle::SOLID);
58     DialogProperties g_dialogProperties;
59 } // namespace
60 
CreateDialog()61 ArkUIDialogHandle CreateDialog()
62 {
63     return new _ArkUIDialog({ .dialogHandle = nullptr,
64         .contentHandle = nullptr,
65         .alignment = DEFAULT_DIALOG_ALIGNMENT,
66         .offsetX = 0.0f,
67         .offsetY = 0.0f,
68         .isModal = true,
69         .autoCancel = true,
70         .maskColor = DEFAULT_MASK_COLOR,
71         .maskRect = nullptr,
72         .backgroundColor = DEFAULT_DIALOG_BACKGROUND_COLOR,
73         .cornerRadiusRect = nullptr,
74         .gridCount = -1,
75         .enableCustomStyle = false,
76         .showInSubWindow = false,
77         .enableCustomAnimation = false,
78         .onWillDismissCall = nullptr,
79         .onWillDismissCallByNDK  = nullptr,
80         .userData = nullptr,
81         .keyboardAvoidDistanceValue = std::optional<ArkUI_Float32>(),
82         .keyboardAvoidDistanceUnit = DimensionUnit::VP,
83         .levelMode = ARKUI_LEVEL_MODE_DEFAULT_VALUE,
84         .levelUniqueId = ARKUI_DEFAULT_LEVEL_UNIQUEID,
85         .immersiveMode = ARKUI_IMMERSIVE_MODE_DEFAULT_VALUE,
86         .levelOrder = 0.0f,
87         .onWillAppearData = nullptr,
88         .onDidAppearData = nullptr,
89         .onWillDisappearData = nullptr,
90         .onDidDisappearData = nullptr,
91         .onWillAppear = nullptr,
92         .onDidAppear = nullptr,
93         .onWillDisappear = nullptr,
94         .onDidDisappear = nullptr,
95         .borderWidthEdgeWidths = new ArkUIBorderWidth({ .top = DEFAULT_BORDER_WIDTH,
96             .right = DEFAULT_BORDER_WIDTH,
97             .bottom = DEFAULT_BORDER_WIDTH,
98             .left = DEFAULT_BORDER_WIDTH }),
99         .borderWidthUnit = DimensionUnit::VP,
100         .borderColors = new ArkUIBorderColor({ .top = DEFAULT_BORDER_COLOR,
101             .right = DEFAULT_BORDER_COLOR,
102             .bottom = DEFAULT_BORDER_COLOR,
103             .left = DEFAULT_BORDER_COLOR }),
104         .borderStyles = new ArkUIBorderStyle({ .top = DEFAULT_BORDER_STYLE,
105             .right = DEFAULT_BORDER_STYLE,
106             .bottom = DEFAULT_BORDER_STYLE,
107             .left = DEFAULT_BORDER_STYLE }),
108         .widthValue = std::optional<ArkUI_Float32>(),
109         .widthUnit = DimensionUnit::VP,
110         .heightValue = std::optional<ArkUI_Float32>(),
111         .heightUnit = DimensionUnit::VP,
112         .shadowStyle = ShadowStyle::OuterDefaultMD,
113         .customShadow = Shadow(),
114         .blurStyle = ARKUI_BLUR_STYLE_COMPONENT_ULTRA_THICK,
115         .keyboardAvoidMode = OHOS::Ace::KeyboardAvoidMode::DEFAULT,
116         .enableHoverMode = false,
117         .hoverModeAreaType = OHOS::Ace::HoverModeAreaType::TOP_SCREEN,
118         .focusable = true,
119     });
120 }
121 
DisposeDialog(ArkUIDialogHandle controllerHandler)122 void DisposeDialog(ArkUIDialogHandle controllerHandler)
123 {
124     CHECK_NULL_VOID(controllerHandler);
125     auto* dialog = reinterpret_cast<FrameNode*>(controllerHandler->dialogHandle);
126     if (dialog) {
127         dialog->DecRefCount();
128     }
129     controllerHandler->dialogHandle = nullptr;
130     auto* content = reinterpret_cast<FrameNode*>(controllerHandler->contentHandle);
131     if (content) {
132         content->DecRefCount();
133     }
134     controllerHandler->contentHandle = nullptr;
135     auto* maskRect = controllerHandler->maskRect;
136     if (maskRect) {
137         delete maskRect;
138     }
139     auto* cornerRadiusRect = controllerHandler->cornerRadiusRect;
140     if (cornerRadiusRect) {
141         delete cornerRadiusRect;
142     }
143     controllerHandler->onWillDismissCall = nullptr;
144     controllerHandler->onWillDismissCallByNDK  = nullptr;
145     controllerHandler->userData = nullptr;
146     delete controllerHandler;
147 }
148 
GetDialogAlignment(int32_t alignment)149 DialogAlignment GetDialogAlignment(int32_t alignment)
150 {
151     switch (alignment) {
152         case ARKUI_ALIGNMENT_TOP_START_INDEX:
153             return DialogAlignment::TOP_START;
154         case ARKUI_ALIGNMENT_TOP_INDEX:
155             return DialogAlignment::TOP;
156         case ARKUI_ALIGNMENT_TOP_END_INDEX:
157             return DialogAlignment::TOP_END;
158         case ARKUI_ALIGNMENT_START_INDEX:
159             return DialogAlignment::CENTER_START;
160         case ARKUI_ALIGNMENT_CENTER_INDEX:
161             return DialogAlignment::CENTER;
162         case ARKUI_ALIGNMENT_END_INDEX:
163             return DialogAlignment::CENTER_END;
164         case ARKUI_ALIGNMENT_BOTTOM_START_INDEX:
165             return DialogAlignment::BOTTOM_START;
166         case ARKUI_ALIGNMENT_BOTTOM_INDEX:
167             return DialogAlignment::BOTTOM;
168         case ARKUI_ALIGNMENT_BOTTOM_END_INDEX:
169             return DialogAlignment::BOTTOM_END;
170         default:
171             break;
172     }
173     return DialogAlignment::DEFAULT;
174 }
175 
ParseDialogMask(DialogProperties & dialogProperties,ArkUIDialogHandle controllerHandler)176 void ParseDialogMask(DialogProperties& dialogProperties, ArkUIDialogHandle controllerHandler)
177 {
178     CHECK_NULL_VOID(controllerHandler);
179     dialogProperties.maskColor = Color(controllerHandler->maskColor);
180     if (!controllerHandler->maskRect) {
181         return;
182     }
183     DimensionRect maskRect;
184     maskRect.SetOffset(DimensionOffset(Dimension(controllerHandler->maskRect->x, DimensionUnit::VP),
185         Dimension(controllerHandler->maskRect->y, DimensionUnit::VP)));
186     maskRect.SetSize(DimensionSize(Dimension(controllerHandler->maskRect->width, DimensionUnit::VP),
187         Dimension(controllerHandler->maskRect->height, DimensionUnit::VP)));
188     dialogProperties.maskRect = maskRect;
189 }
190 
ParseDialogOnWillDismiss(DialogProperties & dialogProperties,ArkUIDialogHandle controllerHandler)191 void ParseDialogOnWillDismiss(DialogProperties& dialogProperties, ArkUIDialogHandle controllerHandler)
192 {
193     CHECK_NULL_VOID(controllerHandler);
194     if (!controllerHandler->onWillDismissCall) {
195         return;
196     }
197     dialogProperties.onWillDismiss = [controllerHandler](int32_t reason, int32_t instanceId) {
198         CHECK_NULL_VOID(controllerHandler);
199         CHECK_NULL_VOID(controllerHandler->onWillDismissCall);
200         (*(controllerHandler->onWillDismissCall))(reason);
201     };
202 }
203 
ParseDialogLife(DialogProperties & dialogProperties,ArkUIDialogHandle controllerHandler)204 void ParseDialogLife(DialogProperties& dialogProperties, ArkUIDialogHandle controllerHandler)
205 {
206     CHECK_NULL_VOID(controllerHandler);
207     if (controllerHandler->onWillAppear) {
208         dialogProperties.onWillAppear = [controllerHandler]() {
209             CHECK_NULL_VOID(controllerHandler);
210             CHECK_NULL_VOID(controllerHandler->onWillAppear);
211             (*(controllerHandler->onWillAppear))(controllerHandler->onWillAppearData);
212         };
213     }
214     if (controllerHandler->onDidAppear) {
215         dialogProperties.onDidAppear = [controllerHandler]() {
216             CHECK_NULL_VOID(controllerHandler);
217             CHECK_NULL_VOID(controllerHandler->onDidAppear);
218             (*(controllerHandler->onDidAppear))(controllerHandler->onDidAppearData);
219         };
220     }
221     if (controllerHandler->onWillDisappear) {
222         dialogProperties.onWillDisappear = [controllerHandler]() {
223             CHECK_NULL_VOID(controllerHandler);
224             CHECK_NULL_VOID(controllerHandler->onWillDisappear);
225             (*(controllerHandler->onWillDisappear))(controllerHandler->onWillDisappearData);
226         };
227     }
228     if (controllerHandler->onDidDisappear) {
229         dialogProperties.onDidDisappear = [controllerHandler]() {
230             CHECK_NULL_VOID(controllerHandler);
231             CHECK_NULL_VOID(controllerHandler->onDidDisappear);
232             (*(controllerHandler->onDidDisappear))(controllerHandler->onDidDisappearData);
233         };
234     }
235 }
236 
ParseDialogCornerRadiusRect(DialogProperties & dialogProperties,ArkUIDialogHandle controllerHandler)237 void ParseDialogCornerRadiusRect(DialogProperties& dialogProperties, ArkUIDialogHandle controllerHandler)
238 {
239     CHECK_NULL_VOID(controllerHandler);
240     if (!controllerHandler->cornerRadiusRect) {
241         return;
242     }
243     NG::BorderRadiusProperty radius;
244     radius.radiusTopLeft = Dimension(controllerHandler->cornerRadiusRect->topLeft, DimensionUnit::VP);
245     radius.radiusTopRight = Dimension(controllerHandler->cornerRadiusRect->topRight, DimensionUnit::VP);
246     radius.radiusBottomLeft = Dimension(controllerHandler->cornerRadiusRect->bottomLeft, DimensionUnit::VP);
247     radius.radiusBottomRight = Dimension(controllerHandler->cornerRadiusRect->bottomRight, DimensionUnit::VP);
248     radius.multiValued = true;
249     dialogProperties.borderRadius = radius;
250 }
251 
ParseDialogKeyboardAvoidDistance(DialogProperties & dialogProperties,ArkUIDialogHandle controllerHandler)252 void ParseDialogKeyboardAvoidDistance(DialogProperties& dialogProperties, ArkUIDialogHandle controllerHandler)
253 {
254     CHECK_NULL_VOID(controllerHandler);
255     if (!dialogProperties.keyboardAvoidDistance.has_value() &&
256         controllerHandler->keyboardAvoidDistanceValue.has_value()) {
257         auto unitEnum = controllerHandler->keyboardAvoidDistanceUnit;
258         if (controllerHandler->keyboardAvoidDistanceValue.value() < 0 || unitEnum < OHOS::Ace::DimensionUnit::NONE ||
259             unitEnum > OHOS::Ace::DimensionUnit::CALC || unitEnum == OHOS::Ace::DimensionUnit::PERCENT) {
260             dialogProperties.keyboardAvoidDistance = Dimension(DEFAULT_AVOID_DISTANCE, OHOS::Ace::DimensionUnit::VP);
261         } else if (unitEnum == OHOS::Ace::DimensionUnit::NONE) {
262             dialogProperties.keyboardAvoidDistance = Dimension(controllerHandler->keyboardAvoidDistanceValue.value(),
263                 OHOS::Ace::DimensionUnit::VP);
264         } else {
265             dialogProperties.keyboardAvoidDistance = Dimension(controllerHandler->keyboardAvoidDistanceValue.value(),
266                 unitEnum);
267         }
268     }
269 }
270 
ParseDialogBorderWidth(DialogProperties & dialogProperties,ArkUIDialogHandle controllerHandler)271 void ParseDialogBorderWidth(DialogProperties& dialogProperties, ArkUIDialogHandle controllerHandler)
272 {
273     CHECK_NULL_VOID(controllerHandler);
274     if (!controllerHandler->borderWidthEdgeWidths) {
275         return;
276     }
277     NG::BorderWidthProperty width;
278     auto unitEnum = controllerHandler->borderWidthUnit;
279     if (unitEnum < OHOS::Ace::DimensionUnit::PX || unitEnum > OHOS::Ace::DimensionUnit::CALC) {
280         width.leftDimen = Dimension(controllerHandler->borderWidthEdgeWidths->left, DimensionUnit::VP);
281         width.topDimen = Dimension(controllerHandler->borderWidthEdgeWidths->top, DimensionUnit::VP);
282         width.rightDimen = Dimension(controllerHandler->borderWidthEdgeWidths->right, DimensionUnit::VP);
283         width.bottomDimen = Dimension(controllerHandler->borderWidthEdgeWidths->bottom, DimensionUnit::VP);
284     } else {
285         width.leftDimen = Dimension(controllerHandler->borderWidthEdgeWidths->left, unitEnum);
286         width.topDimen = Dimension(controllerHandler->borderWidthEdgeWidths->top, unitEnum);
287         width.rightDimen = Dimension(controllerHandler->borderWidthEdgeWidths->right, unitEnum);
288         width.bottomDimen = Dimension(controllerHandler->borderWidthEdgeWidths->bottom, unitEnum);
289     }
290     dialogProperties.borderWidth = width;
291 }
292 
ParseDialogBorderColor(DialogProperties & dialogProperties,ArkUIDialogHandle controllerHandler)293 void ParseDialogBorderColor(DialogProperties& dialogProperties, ArkUIDialogHandle controllerHandler)
294 {
295     CHECK_NULL_VOID(controllerHandler);
296     if (!controllerHandler->borderColors) {
297         return;
298     }
299     NG::BorderColorProperty color;
300     color.topColor = Color(controllerHandler->borderColors->top);
301     color.rightColor = Color(controllerHandler->borderColors->right);
302     color.bottomColor = Color(controllerHandler->borderColors->bottom);
303     color.leftColor = Color(controllerHandler->borderColors->left);
304     dialogProperties.borderColor = color;
305 }
306 
ParseDialogBorderStyle(DialogProperties & dialogProperties,ArkUIDialogHandle controllerHandler)307 void ParseDialogBorderStyle(DialogProperties& dialogProperties, ArkUIDialogHandle controllerHandler)
308 {
309     CHECK_NULL_VOID(controllerHandler);
310     if (!controllerHandler->borderStyles) {
311         return;
312     }
313     NG::BorderStyleProperty style;
314     style.styleLeft = static_cast<OHOS::Ace::BorderStyle>(controllerHandler->borderStyles->left);
315     style.styleRight = static_cast<OHOS::Ace::BorderStyle>(controllerHandler->borderStyles->right);
316     style.styleTop = static_cast<OHOS::Ace::BorderStyle>(controllerHandler->borderStyles->top);
317     style.styleBottom = static_cast<OHOS::Ace::BorderStyle>(controllerHandler->borderStyles->bottom);
318     dialogProperties.borderStyle = style;
319 }
320 
ParseDialogWidth(DialogProperties & dialogProperties,ArkUIDialogHandle controllerHandler)321 void ParseDialogWidth(DialogProperties& dialogProperties, ArkUIDialogHandle controllerHandler)
322 {
323     CHECK_NULL_VOID(controllerHandler);
324     if (!dialogProperties.width.has_value() && controllerHandler->widthValue.has_value()) {
325         auto unitEnum = controllerHandler->widthUnit;
326         if (unitEnum < OHOS::Ace::DimensionUnit::PX || unitEnum > OHOS::Ace::DimensionUnit::CALC) {
327             dialogProperties.width = Dimension(controllerHandler->widthValue.value(), OHOS::Ace::DimensionUnit::VP);
328         } else {
329             dialogProperties.width = Dimension(controllerHandler->widthValue.value(), unitEnum);
330         }
331     }
332 }
333 
ParseDialogHeight(DialogProperties & dialogProperties,ArkUIDialogHandle controllerHandler)334 void ParseDialogHeight(DialogProperties& dialogProperties, ArkUIDialogHandle controllerHandler)
335 {
336     CHECK_NULL_VOID(controllerHandler);
337     if (!dialogProperties.height.has_value() && controllerHandler->heightValue.has_value()) {
338         auto unitEnum = controllerHandler->heightUnit;
339         if (unitEnum < OHOS::Ace::DimensionUnit::PX || unitEnum > OHOS::Ace::DimensionUnit::CALC) {
340             dialogProperties.height = Dimension(controllerHandler->heightValue.value(), OHOS::Ace::DimensionUnit::VP);
341         } else {
342             dialogProperties.height = Dimension(controllerHandler->heightValue.value(), unitEnum);
343         }
344     }
345 }
346 
ParseDialogShadowStyle(DialogProperties & dialogProperties,ArkUIDialogHandle controllerHandler)347 void ParseDialogShadowStyle(DialogProperties& dialogProperties, ArkUIDialogHandle controllerHandler)
348 {
349     CHECK_NULL_VOID(controllerHandler);
350     if (controllerHandler->shadowStyle < OHOS::Ace::ShadowStyle::OuterDefaultXS ||
351         controllerHandler->shadowStyle > OHOS::Ace::ShadowStyle::None) {
352         dialogProperties.shadow = Shadow::CreateShadow(OHOS::Ace::ShadowStyle::None);
353     } else {
354         dialogProperties.shadow = Shadow::CreateShadow(controllerHandler->shadowStyle);
355     }
356 }
357 
ParseDialogProperties(DialogProperties & dialogProperties,ArkUIDialogHandle controllerHandler)358 void ParseDialogProperties(DialogProperties& dialogProperties, ArkUIDialogHandle controllerHandler)
359 {
360     CHECK_NULL_VOID(controllerHandler);
361     dialogProperties.autoCancel = controllerHandler->autoCancel;
362     dialogProperties.alignment = GetDialogAlignment(controllerHandler->alignment);
363     dialogProperties.offset = DimensionOffset(Dimension(controllerHandler->offsetX, DimensionUnit::VP),
364         Dimension(controllerHandler->offsetY, DimensionUnit::VP));
365     dialogProperties.isShowInSubWindow = controllerHandler->showInSubWindow;
366     dialogProperties.isModal = controllerHandler->isModal;
367     dialogProperties.backgroundColor = Color(controllerHandler->backgroundColor);
368     dialogProperties.customStyle = controllerHandler->enableCustomStyle;
369     dialogProperties.gridCount = controllerHandler->gridCount;
370     dialogProperties.dialogLevelMode = static_cast<LevelMode>(controllerHandler->levelMode);
371     dialogProperties.dialogLevelUniqueId = controllerHandler->levelUniqueId;
372     dialogProperties.dialogImmersiveMode = static_cast<ImmersiveMode>(controllerHandler->immersiveMode);
373     dialogProperties.backgroundBlurStyle = controllerHandler->blurStyle;
374     dialogProperties.keyboardAvoidMode = controllerHandler->keyboardAvoidMode;
375     dialogProperties.enableHoverMode = controllerHandler->enableHoverMode;
376     dialogProperties.hoverModeArea = controllerHandler->hoverModeAreaType;
377     dialogProperties.shadow = controllerHandler->customShadow;
378     if (!dialogProperties.isShowInSubWindow) {
379         dialogProperties.levelOrder = std::make_optional(controllerHandler->levelOrder);
380     }
381     dialogProperties.focusable = controllerHandler->focusable;
382 
383     ParseDialogMask(dialogProperties, controllerHandler);
384     ParseDialogCornerRadiusRect(dialogProperties, controllerHandler);
385     ParseDialogOnWillDismiss(dialogProperties, controllerHandler);
386     ParseDialogLife(dialogProperties, controllerHandler);
387 
388     if (controllerHandler->onWillDismissCallByNDK) {
389         dialogProperties.onWillDismissCallByNDK = [controllerHandler](int32_t reason) {
390             ArkUI_DialogDismissEvent event = { controllerHandler->userData, reason, false };
391             controllerHandler->onWillDismissCallByNDK(&event);
392             return event.BlockDismiss;
393         };
394     }
395 
396     if (controllerHandler->onWillAppear) {
397         dialogProperties.onWillAppear = [controllerHandler]() {
398             CHECK_NULL_VOID(controllerHandler);
399             CHECK_NULL_VOID(controllerHandler->onWillAppear);
400             (*(controllerHandler->onWillAppear))(controllerHandler->userData);
401         };
402     }
403 
404     if (controllerHandler->onDidAppear) {
405         dialogProperties.onDidAppear = [controllerHandler]() {
406             CHECK_NULL_VOID(controllerHandler);
407             CHECK_NULL_VOID(controllerHandler->onDidAppear);
408             (*(controllerHandler->onDidAppear))(controllerHandler->userData);
409         };
410     }
411 
412     if (controllerHandler->onWillDisappear) {
413         dialogProperties.onWillDisappear = [controllerHandler]() {
414             CHECK_NULL_VOID(controllerHandler);
415             CHECK_NULL_VOID(controllerHandler->onWillDisappear);
416             (*(controllerHandler->onWillDisappear))(controllerHandler->userData);
417         };
418     }
419 
420     if (controllerHandler->onDidDisappear) {
421         dialogProperties.onDidDisappear = [controllerHandler]() {
422             CHECK_NULL_VOID(controllerHandler);
423             CHECK_NULL_VOID(controllerHandler->onDidDisappear);
424             (*(controllerHandler->onDidDisappear))(controllerHandler->userData);
425         };
426     }
427 
428     if (controllerHandler->enableCustomAnimation && !dialogProperties.openAnimation.has_value()) {
429         AnimationOption animation;
430         dialogProperties.openAnimation = animation;
431     }
432     if (controllerHandler->enableCustomAnimation && !dialogProperties.closeAnimation.has_value()) {
433         AnimationOption animation;
434         dialogProperties.closeAnimation = animation;
435     }
436 
437     ParseDialogKeyboardAvoidDistance(dialogProperties, controllerHandler);
438     ParseDialogBorderWidth(dialogProperties, controllerHandler);
439     ParseDialogBorderColor(dialogProperties, controllerHandler);
440     ParseDialogBorderStyle(dialogProperties, controllerHandler);
441     ParseDialogWidth(dialogProperties, controllerHandler);
442     ParseDialogHeight(dialogProperties, controllerHandler);
443     ParseDialogShadowStyle(dialogProperties, controllerHandler);
444 }
445 
ParseDialogPropertiesFromProps(const DialogProperties & dialogProps)446 PromptDialogAttr ParseDialogPropertiesFromProps(const DialogProperties &dialogProps)
447 {
448     PromptDialogAttr dialogAttr = {
449         .autoCancel = dialogProps.autoCancel, .customStyle = dialogProps.customStyle,
450         .customOnWillDismiss = dialogProps.onWillDismiss, .maskColor = dialogProps.maskColor,
451         .backgroundColor = dialogProps.backgroundColor, .borderRadius = dialogProps.borderRadius,
452         .showInSubWindow = dialogProps.isShowInSubWindow, .isModal = dialogProps.isModal,
453         .enableHoverMode = dialogProps.enableHoverMode, .customBuilder = dialogProps.customBuilder,
454         .customBuilderWithId = dialogProps.customBuilderWithId, .borderWidth = dialogProps.borderWidth,
455         .borderColor = dialogProps.borderColor, .borderStyle = dialogProps.borderStyle, .shadow = dialogProps.shadow,
456         .width = dialogProps.width, .height = dialogProps.height, .maskRect = dialogProps.maskRect,
457         .transitionEffect = dialogProps.transitionEffect, .contentNode = dialogProps.contentNode,
458         .onDidAppear = dialogProps.onDidAppear, .onDidDisappear = dialogProps.onDidDisappear,
459         .onWillAppear = dialogProps.onWillAppear, .onWillDisappear = dialogProps.onWillDisappear,
460         .keyboardAvoidMode = dialogProps.keyboardAvoidMode, .dialogCallback = dialogProps.dialogCallback,
461         .keyboardAvoidDistance = dialogProps.keyboardAvoidDistance,
462         .levelOrder = dialogProps.levelOrder,
463         .dialogLevelMode = dialogProps.dialogLevelMode,
464         .dialogLevelUniqueId = dialogProps.dialogLevelUniqueId,
465         .isUserCreatedDialog = dialogProps.isUserCreatedDialog,
466         .dialogImmersiveMode = dialogProps.dialogImmersiveMode,
467         .blurStyleOption = dialogProps.blurStyleOption,
468         .effectOption = dialogProps.effectOption,
469         .customCNode = dialogProps.customCNode
470     };
471 #if defined(PREVIEW)
472     if (dialogAttr.showInSubWindow) {
473         LOGW("[Engine Log] Unable to use the SubWindow in the Previewer. Perform this operation on the "
474              "emulator or a real device instead.");
475         dialogAttr.showInSubWindow = false;
476     }
477 #endif
478     dialogAttr.alignment = dialogProps.alignment;
479     dialogAttr.offset = dialogProps.offset;
480     if (dialogProps.hoverModeArea) {
481         dialogAttr.hoverModeArea = dialogProps.hoverModeArea;
482     }
483     if (!Container::LessThanAPIVersion(PlatformVersion::VERSION_TWELVE)) {
484         if (dialogProps.backgroundBlurStyle) {
485             dialogAttr.backgroundBlurStyle = dialogProps.backgroundBlurStyle;
486         }
487     }
488     return dialogAttr;
489 }
490 
MainWindowOverlay(std::function<void (RefPtr<NG::OverlayManager>)> && task,const std::string & name,const RefPtr<NG::OverlayManager> & overlay)491 void MainWindowOverlay(std::function<void(RefPtr<NG::OverlayManager>)>&& task, const std::string& name,
492     const RefPtr<NG::OverlayManager>& overlay)
493 {
494     auto currentId = Container::CurrentIdSafelyWithCheck();
495     ContainerScope scope(currentId);
496     auto context = NG::PipelineContext::GetCurrentContext();
497     CHECK_NULL_VOID(context);
498     auto overlayManager = context->GetOverlayManager();
499     if (overlay) {
500         overlayManager = overlay;
501     }
502     context->GetTaskExecutor()->PostTask(
503         [task = std::move(task), weak = WeakPtr<NG::OverlayManager>(overlayManager)] {
504             auto overlayManager = weak.Upgrade();
505             task(overlayManager);
506         },
507         TaskExecutor::TaskType::UI, name);
508 }
509 
ContainerIsService()510 bool ContainerIsService()
511 {
512     auto containerId = Container::CurrentIdSafelyWithCheck();
513     if (containerId < 0) {
514         auto container = Container::GetActive();
515         if (container) {
516             containerId = container->GetInstanceId();
517         }
518     }
519     return containerId >= MIN_PA_SERVICE_ID || containerId < 0;
520 }
521 
openCustomDialogWithNewPipeline(std::function<void (int32_t)> && callback)522 void openCustomDialogWithNewPipeline(std::function<void(int32_t)>&& callback)
523 {
524     TAG_LOGI(AceLogTag::ACE_OVERLAY, "Dialog IsCurrentUseNewPipeline.");
525     auto task = [callback](const RefPtr<NG::OverlayManager>& overlayManager) mutable {
526         CHECK_NULL_VOID(overlayManager);
527         TAG_LOGI(AceLogTag::ACE_OVERLAY, "open custom dialog isShowInSubWindow %{public}d",
528             g_dialogProperties.isShowInSubWindow);
529         if (g_dialogProperties.isShowInSubWindow) {
530             SubwindowManager::GetInstance()->OpenCustomDialogNG(g_dialogProperties, std::move(callback));
531             if (g_dialogProperties.isModal) {
532                 TAG_LOGW(AceLogTag::ACE_OVERLAY, "temporary not support isShowInSubWindow and isModal");
533             }
534         } else {
535             overlayManager->OpenCustomDialog(g_dialogProperties, std::move(callback));
536         }
537     };
538     if (g_dialogProperties.dialogLevelMode == LevelMode::EMBEDDED) {
539         NG::DialogManager::ShowInEmbeddedOverlay(
540             std::move(task), "ArkUIOverlayShowDialog", g_dialogProperties.dialogLevelUniqueId);
541     } else {
542         MainWindowOverlay(std::move(task), "ArkUIOverlayShowDialog", nullptr);
543     }
544 }
545 
SetDialogContent(ArkUIDialogHandle controllerHandler,ArkUINodeHandle contentNode)546 ArkUI_Int32 SetDialogContent(ArkUIDialogHandle controllerHandler, ArkUINodeHandle contentNode)
547 {
548     CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID);
549     CHECK_NULL_RETURN(contentNode, ERROR_CODE_PARAM_INVALID);
550     auto* frameNode = reinterpret_cast<FrameNode*>(contentNode);
551     CHECK_NULL_RETURN(frameNode, ERROR_CODE_PARAM_INVALID);
552     frameNode->IncRefCount();
553     controllerHandler->contentHandle = frameNode;
554     return ERROR_CODE_NO_ERROR;
555 }
556 
RemoveDialogContent(ArkUIDialogHandle controllerHandler)557 ArkUI_Int32 RemoveDialogContent(ArkUIDialogHandle controllerHandler)
558 {
559     CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID);
560     if (controllerHandler->contentHandle) {
561         auto* frameNode = reinterpret_cast<FrameNode*>(controllerHandler->contentHandle);
562         CHECK_NULL_RETURN(frameNode, ERROR_CODE_PARAM_INVALID);
563         frameNode->DecRefCount();
564         controllerHandler->contentHandle = nullptr;
565     }
566     return ERROR_CODE_NO_ERROR;
567 }
568 
SetDialogContentAlignment(ArkUIDialogHandle controllerHandler,ArkUI_Int32 alignment,ArkUI_Float32 offsetX,ArkUI_Float32 offsetY)569 ArkUI_Int32 SetDialogContentAlignment(ArkUIDialogHandle controllerHandler,
570     ArkUI_Int32 alignment, ArkUI_Float32 offsetX, ArkUI_Float32 offsetY)
571 {
572     CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID);
573     if (alignment < DEFAULT_DIALOG_ALIGNMENT || alignment > ARKUI_ALIGNMENT_BOTTOM_END_INDEX) {
574         return ERROR_CODE_PARAM_INVALID;
575     }
576     controllerHandler->alignment = alignment;
577     controllerHandler->offsetX = offsetX;
578     controllerHandler->offsetY = offsetY;
579     return ERROR_CODE_NO_ERROR;
580 }
581 
ResetDialogContentAlignment(ArkUIDialogHandle controllerHandler)582 ArkUI_Int32 ResetDialogContentAlignment(ArkUIDialogHandle controllerHandler)
583 {
584     CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID);
585     controllerHandler->alignment = DEFAULT_DIALOG_ALIGNMENT;
586     controllerHandler->offsetX = 0.0f;
587     controllerHandler->offsetY = 0.0f;
588     return ERROR_CODE_NO_ERROR;
589 }
590 
SetDialogModalMode(ArkUIDialogHandle controllerHandler,bool isModal)591 ArkUI_Int32 SetDialogModalMode(ArkUIDialogHandle controllerHandler, bool isModal)
592 {
593     CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID);
594     controllerHandler->isModal = isModal;
595     return ERROR_CODE_NO_ERROR;
596 }
597 
SetDialogAutoCancel(ArkUIDialogHandle controllerHandler,bool autoCancel)598 ArkUI_Int32 SetDialogAutoCancel(ArkUIDialogHandle controllerHandler, bool autoCancel)
599 {
600     CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID);
601     controllerHandler->autoCancel = autoCancel;
602     return ERROR_CODE_NO_ERROR;
603 }
604 
SetDialogMask(ArkUIDialogHandle controllerHandler,ArkUI_Uint32 maskColor,ArkUIRect * rect)605 ArkUI_Int32 SetDialogMask(ArkUIDialogHandle controllerHandler, ArkUI_Uint32 maskColor, ArkUIRect* rect)
606 {
607     CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID);
608     controllerHandler->maskColor = maskColor;
609     if (rect) {
610         controllerHandler->maskRect = new ArkUIRect({ .x = rect->x, .y = rect->y,
611             .width = rect->width, .height = rect->height });
612     }
613     return ERROR_CODE_NO_ERROR;
614 }
615 
SetDialogBackgroundColor(ArkUIDialogHandle controllerHandler,ArkUI_Uint32 backgroundColor)616 ArkUI_Int32 SetDialogBackgroundColor(ArkUIDialogHandle controllerHandler, ArkUI_Uint32 backgroundColor)
617 {
618     CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID);
619     controllerHandler->backgroundColor = backgroundColor;
620     return ERROR_CODE_NO_ERROR;
621 }
622 
SetDialogCornerRadius(ArkUIDialogHandle controllerHandler,ArkUI_Float32 topLeft,ArkUI_Float32 topRight,ArkUI_Float32 bottomLeft,ArkUI_Float32 bottomRight)623 ArkUI_Int32 SetDialogCornerRadius(ArkUIDialogHandle controllerHandler, ArkUI_Float32 topLeft,
624     ArkUI_Float32 topRight, ArkUI_Float32 bottomLeft, ArkUI_Float32 bottomRight)
625 {
626     CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID);
627     controllerHandler->cornerRadiusRect = new ArkUICornerRadius({ .topLeft = topLeft, .topRight = topRight,
628     .bottomLeft = bottomLeft, .bottomRight = bottomRight });
629     return ERROR_CODE_NO_ERROR;
630 }
631 
SetDialogGridColumnCount(ArkUIDialogHandle controllerHandler,ArkUI_Int32 gridCount)632 ArkUI_Int32 SetDialogGridColumnCount(ArkUIDialogHandle controllerHandler, ArkUI_Int32 gridCount)
633 {
634     CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID);
635     controllerHandler->gridCount = gridCount;
636     return ERROR_CODE_NO_ERROR;
637 }
638 
EnableDialogCustomStyle(ArkUIDialogHandle controllerHandler,bool enableCustomStyle)639 ArkUI_Int32 EnableDialogCustomStyle(ArkUIDialogHandle controllerHandler, bool enableCustomStyle)
640 {
641     CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID);
642     controllerHandler->enableCustomStyle = enableCustomStyle;
643     return ERROR_CODE_NO_ERROR;
644 }
645 
EnableDialogCustomAnimation(ArkUIDialogHandle controllerHandler,bool enableCustomAnimation)646 ArkUI_Int32 EnableDialogCustomAnimation(ArkUIDialogHandle controllerHandler, bool enableCustomAnimation)
647 {
648     CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID);
649     controllerHandler->enableCustomAnimation = enableCustomAnimation;
650     return ERROR_CODE_NO_ERROR;
651 }
652 
ShowDialog(ArkUIDialogHandle controllerHandler,bool showInSubWindow)653 ArkUI_Int32 ShowDialog(ArkUIDialogHandle controllerHandler, bool showInSubWindow)
654 {
655     CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID);
656     controllerHandler->showInSubWindow = showInSubWindow;
657     DialogProperties dialogProperties;
658     ParseDialogProperties(dialogProperties, controllerHandler);
659     auto* contentNode = reinterpret_cast<FrameNode*>(controllerHandler->contentHandle);
660     CHECK_NULL_RETURN(contentNode, ERROR_CODE_PARAM_INVALID);
661     auto contentPtr = AceType::Claim<FrameNode>(contentNode);
662     auto dialogNode = CustomDialogControllerModelNG::SetOpenDialogWithNode(dialogProperties, contentPtr);
663     if (dialogNode) {
664         dialogNode->IncRefCount();
665     }
666     controllerHandler->dialogHandle = AceType::RawPtr(dialogNode);
667     return ERROR_CODE_NO_ERROR;
668 }
669 
CloseDialog(ArkUIDialogHandle controllerHandler)670 ArkUI_Int32 CloseDialog(ArkUIDialogHandle controllerHandler)
671 {
672     CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID);
673     auto* dialogNode = reinterpret_cast<FrameNode*>(controllerHandler->dialogHandle);
674     CHECK_NULL_RETURN(dialogNode, ERROR_CODE_PARAM_INVALID);
675     CustomDialogControllerModelNG::SetCloseDialogForNDK(dialogNode);
676     if (dialogNode) {
677         dialogNode->DecRefCount();
678     }
679     controllerHandler->dialogHandle = nullptr;
680     return ERROR_CODE_NO_ERROR;
681 }
682 
RegisterOnWillDialogDismiss(ArkUIDialogHandle controllerHandler,bool (* eventHandler)(ArkUI_Int32))683 ArkUI_Int32 RegisterOnWillDialogDismiss(ArkUIDialogHandle controllerHandler, bool (*eventHandler)(ArkUI_Int32))
684 {
685     CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID);
686     controllerHandler->onWillDismissCall = eventHandler;
687     return ERROR_CODE_NO_ERROR;
688 }
689 
RegisterOnWillDialogDismissWithUserData(ArkUIDialogHandle controllerHandler,void * userData,void (* callback)(ArkUI_DialogDismissEvent * event))690 ArkUI_Int32 RegisterOnWillDialogDismissWithUserData(
691     ArkUIDialogHandle controllerHandler, void* userData, void (*callback)(ArkUI_DialogDismissEvent* event))
692 {
693     CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID);
694     controllerHandler->onWillDismissCallByNDK  = callback;
695     controllerHandler->userData = userData;
696     return ERROR_CODE_NO_ERROR;
697 }
698 
SetKeyboardAvoidDistance(ArkUIDialogHandle controllerHandler,float distance,ArkUI_Int32 unit)699 ArkUI_Int32 SetKeyboardAvoidDistance(
700     ArkUIDialogHandle controllerHandler, float distance, ArkUI_Int32 unit)
701 {
702     CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID);
703     controllerHandler->keyboardAvoidDistanceValue = distance;
704     controllerHandler->keyboardAvoidDistanceUnit = static_cast<OHOS::Ace::DimensionUnit>(unit);
705     return ERROR_CODE_NO_ERROR;
706 }
707 
SetLevelMode(ArkUIDialogHandle controllerHandler,ArkUI_Int32 mode)708 ArkUI_Int32 SetLevelMode(ArkUIDialogHandle controllerHandler, ArkUI_Int32 mode)
709 {
710     CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID);
711     controllerHandler->levelMode = mode;
712     return ERROR_CODE_NO_ERROR;
713 }
714 
SetLevelUniqueId(ArkUIDialogHandle controllerHandler,ArkUI_Int32 uniqueId)715 ArkUI_Int32 SetLevelUniqueId(ArkUIDialogHandle controllerHandler, ArkUI_Int32 uniqueId)
716 {
717     CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID);
718     controllerHandler->levelUniqueId = uniqueId;
719     return ERROR_CODE_NO_ERROR;
720 }
721 
SetImmersiveMode(ArkUIDialogHandle controllerHandler,ArkUI_Int32 mode)722 ArkUI_Int32 SetImmersiveMode(ArkUIDialogHandle controllerHandler, ArkUI_Int32 mode)
723 {
724     CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID);
725     controllerHandler->immersiveMode = mode;
726     return ERROR_CODE_NO_ERROR;
727 }
728 
SetLevelOrder(ArkUIDialogHandle controllerHandler,ArkUI_Float64 levelOrder)729 ArkUI_Int32 SetLevelOrder(ArkUIDialogHandle controllerHandler, ArkUI_Float64 levelOrder)
730 {
731     CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID);
732     controllerHandler->levelOrder = levelOrder;
733     return ERROR_CODE_NO_ERROR;
734 }
735 
RegisterOnWillAppearDialog(ArkUIDialogHandle controllerHandler,void * userData,void (* callback)(void * userData))736 ArkUI_Int32 RegisterOnWillAppearDialog(
737     ArkUIDialogHandle controllerHandler, void* userData, void (*callback)(void* userData))
738 {
739     CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID);
740     controllerHandler->onWillAppear = callback;
741     controllerHandler->onWillAppearData = userData;
742     return ERROR_CODE_NO_ERROR;
743 }
744 
RegisterOnDidAppearDialog(ArkUIDialogHandle controllerHandler,void * userData,void (* callback)(void * userData))745 ArkUI_Int32 RegisterOnDidAppearDialog(
746     ArkUIDialogHandle controllerHandler, void* userData, void (*callback)(void* userData))
747 {
748     CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID);
749     controllerHandler->onDidAppear = callback;
750     controllerHandler->onDidAppearData = userData;
751     return ERROR_CODE_NO_ERROR;
752 }
753 
RegisterOnWillDisappearDialog(ArkUIDialogHandle controllerHandler,void * userData,void (* callback)(void * userData))754 ArkUI_Int32 RegisterOnWillDisappearDialog(
755     ArkUIDialogHandle controllerHandler, void* userData, void (*callback)(void* userData))
756 {
757     CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID);
758     controllerHandler->onWillDisappear = callback;
759     controllerHandler->onWillDisappearData = userData;
760     return ERROR_CODE_NO_ERROR;
761 }
762 
RegisterOnDidDisappearDialog(ArkUIDialogHandle controllerHandler,void * userData,void (* callback)(void * userData))763 ArkUI_Int32 RegisterOnDidDisappearDialog(
764     ArkUIDialogHandle controllerHandler, void* userData, void (*callback)(void* userData))
765 {
766     CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID);
767     controllerHandler->onDidDisappear = callback;
768     controllerHandler->onDidDisappearData = userData;
769     return ERROR_CODE_NO_ERROR;
770 }
771 
OpenCustomDialog(ArkUIDialogHandle handle,void (* callback)(ArkUI_Int32 dialogId))772 ArkUI_Int32 OpenCustomDialog(ArkUIDialogHandle handle, void (*callback)(ArkUI_Int32 dialogId))
773 {
774     CHECK_NULL_RETURN(handle, ERROR_CODE_PARAM_INVALID);
775     ParseDialogProperties(g_dialogProperties, handle);
776     g_dialogProperties.customCNode = reinterpret_cast<FrameNode*>(handle->contentHandle);
777     auto promptDialogAttr = ParseDialogPropertiesFromProps(g_dialogProperties);
778     if (SystemProperties::GetExtSurfaceEnabled() || !ContainerIsService()) {
779         if (Container::IsCurrentUseNewPipeline()) {
780             openCustomDialogWithNewPipeline(std::move(callback));
781         } else {
782             LOGW("not support old pipeline");
783         }
784     } else if (SubwindowManager::GetInstance() != nullptr) {
785         SubwindowManager::GetInstance()->OpenCustomDialog(promptDialogAttr, std::move(callback));
786     }
787     return ERROR_CODE_NO_ERROR;
788 }
789 
CloseCustomDialog(ArkUI_Int32 dialogId)790 ArkUI_Int32 CloseCustomDialog(ArkUI_Int32 dialogId)
791 {
792     if (SystemProperties::GetExtSurfaceEnabled() || !ContainerIsService()) {
793         auto delegate = EngineHelper::GetCurrentDelegateSafely();
794         CHECK_NULL_RETURN(delegate, ERROR_CODE_PARAM_INVALID);
795         delegate->CloseCustomDialog(dialogId);
796     } else if (SubwindowManager::GetInstance() != nullptr) {
797         SubwindowManager::GetInstance()->CloseCustomDialogNG(dialogId);
798     }
799     return ERROR_CODE_NO_ERROR;
800 }
801 
UpdateCustomDialog(ArkUIDialogHandle handle,void (* callback)(ArkUI_Int32 dialogId))802 ArkUI_Int32 UpdateCustomDialog(ArkUIDialogHandle handle, void (*callback)(ArkUI_Int32 dialogId))
803 {
804     CHECK_NULL_RETURN(handle, ERROR_CODE_PARAM_INVALID);
805     ParseDialogProperties(g_dialogProperties, handle);
806     auto promptDialogAttr = ParseDialogPropertiesFromProps(g_dialogProperties);
807     if (SystemProperties::GetExtSurfaceEnabled() || !ContainerIsService()) {
808         g_dialogProperties.autoCancel = promptDialogAttr.autoCancel,
809         g_dialogProperties.maskColor = promptDialogAttr.maskColor, g_dialogProperties.isSysBlurStyle = false;
810         if (promptDialogAttr.alignment.has_value()) {
811             g_dialogProperties.alignment = promptDialogAttr.alignment.value();
812         }
813         if (promptDialogAttr.offset.has_value()) {
814             g_dialogProperties.offset = promptDialogAttr.offset.value();
815         }
816         auto node = g_dialogProperties.customCNode;
817         auto nodePtr = node.Upgrade();
818         CHECK_NULL_RETURN(nodePtr, ERROR_CODE_PARAM_INVALID);
819         auto context = nodePtr->GetContextWithCheck();
820         CHECK_NULL_RETURN(context, ERROR_CODE_PARAM_INVALID);
821         auto overlayManager = context->GetOverlayManager();
822         context->GetTaskExecutor()->PostTask(
823             [node, callback, weak = WeakPtr<NG::OverlayManager>(overlayManager)]() mutable {
824                 auto overlayManager = weak.Upgrade();
825                 CHECK_NULL_VOID(overlayManager);
826                 TAG_LOGI(AceLogTag::ACE_OVERLAY, "begin to update custom dialog.");
827                 overlayManager->UpdateCustomDialog(node, g_dialogProperties, std::move(callback));
828             },
829             TaskExecutor::TaskType::UI, "ArkUIOverlayUpdateCustomDialog");
830     } else if (SubwindowManager::GetInstance() != nullptr) {
831         SubwindowManager::GetInstance()->UpdateCustomDialogNG(
832             g_dialogProperties.customCNode, promptDialogAttr, std::move(callback));
833     }
834     return ERROR_CODE_NO_ERROR;
835 }
836 
SetDialogSubwindowMode(ArkUIDialogHandle controllerHandler,bool showInSubWindow)837 ArkUI_Int32 SetDialogSubwindowMode(ArkUIDialogHandle controllerHandler, bool showInSubWindow)
838 {
839     CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID);
840     controllerHandler->showInSubWindow = showInSubWindow;
841     return ERROR_CODE_NO_ERROR;
842 }
843 
SetDialogBorderWidth(ArkUIDialogHandle controllerHandler,ArkUI_Float32 top,ArkUI_Float32 right,ArkUI_Float32 bottom,ArkUI_Float32 left,ArkUI_Int32 unit)844 ArkUI_Int32 SetDialogBorderWidth(ArkUIDialogHandle controllerHandler, ArkUI_Float32 top, ArkUI_Float32 right,
845     ArkUI_Float32 bottom, ArkUI_Float32 left, ArkUI_Int32 unit)
846 {
847     CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID);
848     controllerHandler->borderWidthEdgeWidths =
849         new ArkUIBorderWidth({ .top = top, .right = right, .bottom = bottom, .left = left });
850     controllerHandler->borderWidthUnit = static_cast<OHOS::Ace::DimensionUnit>(unit);
851     return ERROR_CODE_NO_ERROR;
852 }
853 
SetDialogBorderColor(ArkUIDialogHandle controllerHandler,ArkUI_Uint32 top,ArkUI_Uint32 right,ArkUI_Uint32 bottom,ArkUI_Uint32 left)854 ArkUI_Int32 SetDialogBorderColor(
855     ArkUIDialogHandle controllerHandler, ArkUI_Uint32 top, ArkUI_Uint32 right, ArkUI_Uint32 bottom, ArkUI_Uint32 left)
856 {
857     CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID);
858     controllerHandler->borderColors =
859         new ArkUIBorderColor({ .top = top, .right = right, .bottom = bottom, .left = left });
860     return ERROR_CODE_NO_ERROR;
861 }
862 
SetDialogBorderStyle(ArkUIDialogHandle controllerHandler,ArkUI_Int32 top,ArkUI_Int32 right,ArkUI_Int32 bottom,ArkUI_Int32 left)863 ArkUI_Int32 SetDialogBorderStyle(
864     ArkUIDialogHandle controllerHandler, ArkUI_Int32 top, ArkUI_Int32 right, ArkUI_Int32 bottom, ArkUI_Int32 left)
865 {
866     CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID);
867     controllerHandler->borderStyles =
868         new ArkUIBorderStyle({ .top = top, .right = right, .bottom = bottom, .left = left });
869     return ERROR_CODE_NO_ERROR;
870 }
871 
SetWidth(ArkUIDialogHandle controllerHandler,float width,ArkUI_Int32 unit)872 ArkUI_Int32 SetWidth(ArkUIDialogHandle controllerHandler, float width, ArkUI_Int32 unit)
873 {
874     CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID);
875     controllerHandler->widthValue = width;
876     controllerHandler->widthUnit = static_cast<OHOS::Ace::DimensionUnit>(unit);
877     return ERROR_CODE_NO_ERROR;
878 }
879 
SetHeight(ArkUIDialogHandle controllerHandler,float height,ArkUI_Int32 unit)880 ArkUI_Int32 SetHeight(ArkUIDialogHandle controllerHandler, float height, ArkUI_Int32 unit)
881 {
882     CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID);
883     controllerHandler->heightValue = height;
884     controllerHandler->heightUnit = static_cast<OHOS::Ace::DimensionUnit>(unit);
885     return ERROR_CODE_NO_ERROR;
886 }
887 
SetShadow(ArkUIDialogHandle controllerHandler,ArkUI_Int32 shadow)888 ArkUI_Int32 SetShadow(ArkUIDialogHandle controllerHandler, ArkUI_Int32 shadow)
889 {
890     CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID);
891     controllerHandler->shadowStyle = static_cast<OHOS::Ace::ShadowStyle>(shadow);
892     return ERROR_CODE_NO_ERROR;
893 }
894 
GetShadowFromTheme(ShadowStyle shadowStyle,Shadow & shadow)895 bool GetShadowFromTheme(ShadowStyle shadowStyle, Shadow& shadow)
896 {
897     if (shadowStyle == ShadowStyle::None) {
898         return true;
899     }
900     auto container = Container::Current();
901     CHECK_NULL_RETURN(container, false);
902     auto pipelineContext = container->GetPipelineContext();
903     CHECK_NULL_RETURN(pipelineContext, false);
904 
905     auto shadowTheme = pipelineContext->GetTheme<ShadowTheme>();
906     CHECK_NULL_RETURN(shadowTheme, false);
907     auto colorMode = container->GetColorMode();
908     shadow = shadowTheme->GetShadow(shadowStyle, colorMode);
909     return true;
910 }
911 
SetDialogCustomShadow(ArkUIDialogHandle controllerHandler,const ArkUIInt32orFloat32 * shadows,ArkUI_Int32 length)912 ArkUI_Int32 SetDialogCustomShadow(
913     ArkUIDialogHandle controllerHandler, const ArkUIInt32orFloat32* shadows, ArkUI_Int32 length)
914 {
915     CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID);
916     if (length == NUM_1) {
917         Shadow shadow;
918         auto shadowStyle = static_cast<ShadowStyle>(shadows[NUM_0].i32);
919         auto style = static_cast<ShadowStyle>(shadowStyle);
920         if (GetShadowFromTheme(style, shadow)) {
921             controllerHandler->customShadow = shadow;
922         }
923     }
924     if (length != NUM_7) {
925         return ERROR_CODE_NO_ERROR;
926     }
927     auto blurRadius = shadows[NUM_0].f32;
928     auto hasColorValue = static_cast<int32_t>(shadows[NUM_1].i32);
929     auto offsetX = shadows[NUM_2].f32;
930     auto offsetY = shadows[NUM_3].f32;
931     auto shadowType = shadows[NUM_4].i32;
932     auto color = static_cast<uint32_t>(shadows[NUM_5].u32);
933     auto isFilled = static_cast<uint32_t>(shadows[NUM_6].i32);
934     Shadow shadow;
935     shadow.SetBlurRadius(blurRadius);
936     shadow.SetOffsetX(offsetX);
937     shadow.SetOffsetY(offsetY);
938     if (hasColorValue == HAS_COLORSTRATEGY) {
939         shadow.SetShadowColorStrategy(static_cast<ShadowColorStrategy>(color));
940     } else if (hasColorValue == HAS_COLOR) {
941         shadow.SetColor(Color(color));
942     }
943     shadow.SetShadowType(static_cast<ShadowType>(shadowType));
944     shadow.SetIsFilled(static_cast<bool>(isFilled));
945     controllerHandler->customShadow = shadow;
946     return ERROR_CODE_NO_ERROR;
947 }
948 
SetBackgroundBlurStyle(ArkUIDialogHandle controllerHandler,ArkUI_Int32 blurStyle)949 ArkUI_Int32 SetBackgroundBlurStyle(ArkUIDialogHandle controllerHandler, ArkUI_Int32 blurStyle)
950 {
951     CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID);
952     controllerHandler->blurStyle = blurStyle;
953     return ERROR_CODE_NO_ERROR;
954 }
955 
SetKeyboardAvoidMode(ArkUIDialogHandle controllerHandler,ArkUI_Int32 keyboardAvoidMode)956 ArkUI_Int32 SetKeyboardAvoidMode(ArkUIDialogHandle controllerHandler, ArkUI_Int32 keyboardAvoidMode)
957 {
958     CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID);
959     controllerHandler->keyboardAvoidMode = static_cast<OHOS::Ace::KeyboardAvoidMode>(keyboardAvoidMode);
960     return ERROR_CODE_NO_ERROR;
961 }
962 
EnableHoverMode(ArkUIDialogHandle controllerHandler,bool enableHoverMode)963 ArkUI_Int32 EnableHoverMode(ArkUIDialogHandle controllerHandler, bool enableHoverMode)
964 {
965     CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID);
966     controllerHandler->enableHoverMode = enableHoverMode;
967     return ERROR_CODE_NO_ERROR;
968 }
969 
SetHoverModeArea(ArkUIDialogHandle controllerHandler,ArkUI_Int32 hoverModeAreaType)970 ArkUI_Int32 SetHoverModeArea(ArkUIDialogHandle controllerHandler, ArkUI_Int32 hoverModeAreaType)
971 {
972     CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID);
973     controllerHandler->hoverModeAreaType = static_cast<OHOS::Ace::HoverModeAreaType>(hoverModeAreaType);
974     return ERROR_CODE_NO_ERROR;
975 }
976 
SetFocusable(ArkUIDialogHandle controllerHandler,bool focusable)977 ArkUI_Int32 SetFocusable(ArkUIDialogHandle controllerHandler, bool focusable)
978 {
979     CHECK_NULL_RETURN(controllerHandler, ERROR_CODE_PARAM_INVALID);
980     controllerHandler->focusable = focusable;
981     return ERROR_CODE_NO_ERROR;
982 }
983 
984 } // namespace OHOS::Ace::NG::ViewModel
985