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