1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_ACE_ACE_ENGINE_FRAMEWORKS_CORE_COMPONENTS_COMMON_PROPERTIES_DIALOG_PROPERTIES_H 17 #define FOUNDATION_ACE_ACE_ENGINE_FRAMEWORKS_CORE_COMPONENTS_COMMON_PROPERTIES_DIALOG_PROPERTIES_H 18 19 #include <cstdint> 20 21 #include "base/geometry/dimension_offset.h" 22 #include "base/geometry/dimension.h" 23 #include "core/components/common/properties/blur_style_option.h" 24 #include "core/components/common/properties/color.h" 25 #include "core/components/common/properties/shadow.h" 26 #include "core/components_ng/event/click_event.h" 27 #include "core/components_ng/property/border_property.h" 28 #include "core/components_ng/property/transition_property.h" 29 #include "core/event/ace_event_handler.h" 30 #include "core/pipeline/base/component.h" 31 #include "core/components/common/properties/text_style.h" 32 33 namespace OHOS::Ace { 34 35 enum class DialogType { 36 COMMON = 0, 37 ALERT_DIALOG, 38 ACTION_SHEET, 39 CHECKBOX_DIALOG, 40 PROGRESS_DIALOG, 41 }; 42 43 class DialogTypeUtils { 44 public: ConvertDialogTypeToString(DialogType type)45 static std::string ConvertDialogTypeToString(DialogType type) 46 { 47 switch (type) { 48 case DialogType::COMMON: 49 return "DialogType.COMMON"; 50 case DialogType::ALERT_DIALOG: 51 return "DialogType.ALERT_DIALOG"; 52 case DialogType::ACTION_SHEET: 53 return "DialogType.ACTION_SHEET"; 54 case DialogType::CHECKBOX_DIALOG: 55 return "DialogType.CHECKBOX_DIALOG"; 56 default: 57 break; 58 } 59 return "DialogType.COMMON"; 60 } 61 }; 62 63 enum class DialogButtonStyle { 64 DEFAULT = 0, 65 HIGHTLIGHT, 66 }; 67 68 // Alignment of dialog in vertical. 69 enum class DialogAlignment { 70 TOP = 0, 71 CENTER, 72 BOTTOM, 73 DEFAULT, 74 TOP_START, 75 TOP_END, 76 CENTER_START, 77 CENTER_END, 78 BOTTOM_START, 79 BOTTOM_END, 80 }; 81 82 // Alignment of toast in vertical. 83 enum class ToastAlignment { 84 TOP_START = 0, 85 TOP, 86 TOP_END, 87 CENTER_START, 88 CENTER, 89 CENTER_END, 90 BOTTOM_START, 91 BOTTOM, 92 BOTTOM_END, 93 DEFAULT, 94 }; 95 96 // Direction of buttons in dialog 97 enum class DialogButtonDirection { 98 AUTO = 0, 99 HORIZONTAL, 100 VERTICAL, 101 }; 102 103 // avoid mode when keyboard shows 104 enum class KeyboardAvoidMode { 105 DEFAULT = 0, 106 NONE, 107 }; 108 109 enum class LevelMode { 110 OVERLAY = 0, 111 EMBEDDED, 112 }; 113 114 enum class ImmersiveMode { 115 DEFAULT = 0, 116 EXTEND, 117 }; 118 119 class DialogAlignmentUtils { 120 public: ConvertDialogAlignmentToString(DialogAlignment dialogAlignment)121 static std::string ConvertDialogAlignmentToString(DialogAlignment dialogAlignment) 122 { 123 std::string Alignment = ""; 124 switch (dialogAlignment) { 125 case DialogAlignment::TOP: 126 Alignment = "DialogAlignment.TOP"; 127 break; 128 case DialogAlignment::CENTER: 129 Alignment = "DialogAlignment.CENTER"; 130 break; 131 case DialogAlignment::BOTTOM: 132 Alignment = "DialogAlignment.BOTTOM"; 133 break; 134 case DialogAlignment::TOP_START: 135 Alignment = "DialogAlignment.TOP_START"; 136 break; 137 case DialogAlignment::TOP_END: 138 Alignment = "DialogAlignment.TOP_END"; 139 break; 140 case DialogAlignment::CENTER_START: 141 Alignment = "DialogAlignment.CENTER_START"; 142 break; 143 case DialogAlignment::CENTER_END: 144 Alignment = "DialogAlignment.CENTER_END"; 145 break; 146 case DialogAlignment::BOTTOM_START: 147 Alignment = "DialogAlignment.BOTTOM_START"; 148 break; 149 case DialogAlignment::BOTTOM_END: 150 Alignment = "DialogAlignment.BOTTOM_END"; 151 break; 152 default: 153 Alignment = "DialogAlignment.DEFAULT"; 154 } 155 return Alignment; 156 } 157 }; 158 159 class DialogButtonDirectionUtils { 160 public: ConvertDialogButtonDirectionToString(DialogButtonDirection buttonDirection)161 static std::string ConvertDialogButtonDirectionToString(DialogButtonDirection buttonDirection) 162 { 163 std::string direction = ""; 164 switch (buttonDirection) { 165 case DialogButtonDirection::HORIZONTAL: 166 direction = "DialogButtonDirection.HORIZONTAL"; 167 break; 168 case DialogButtonDirection::VERTICAL: 169 direction = "DialogButtonDirection.VERTICAL"; 170 break; 171 default: 172 direction = "DialogButtonDirection.AUTO"; 173 } 174 return direction; 175 } 176 }; 177 178 // Information of ActionSheet 179 struct ActionSheetInfo { 180 std::string title; // title of ActionSheet, necessary. 181 std::string icon; // icon of ActionSheet, not necessary. 182 RefPtr<Gesture> gesture; // called when ActionSheet is clicked. 183 RefPtr<NG::ClickEvent> action; // NG sheet item click action 184 185 // Whether sheetInfo is valid, valid if title if not empty. IsValidActionSheetInfo186 bool IsValid() const 187 { 188 return !title.empty(); 189 } 190 }; 191 192 // Information of Button. 193 struct ButtonInfo { 194 std::string text; // text of button. 195 std::string textColor; // style of text in button. 196 bool isBgColorSetted = false; 197 Color bgColor; // background color of button. 198 RefPtr<NG::ClickEvent> action; // NG button click action 199 bool enabled = true; // status of enabled in button. 200 bool defaultFocus = false; // status of defaultFocus in button. 201 std::optional<DialogButtonStyle> dlgButtonStyle; // DialogButtonStyle of dialog. 202 std::optional<ButtonType> type; 203 std::optional<ButtonStyleMode> buttonStyle; 204 std::optional<ButtonRole> role; 205 std::optional<Color> fontColor; 206 std::optional<CalcDimension> fontSize; 207 std::optional<FontWeight> fontWeight; 208 std::optional<FontStyle> fontStyle; 209 std::optional<std::vector<std::string>> fontFamily; 210 std::optional<Color> backgroundColor; 211 std::optional<NG::BorderRadiusProperty> borderRadius; 212 bool isPrimary = false; 213 bool isAcceptButton = false; 214 215 // Whether button info is valid, valid if text is not empty. IsValidButtonInfo216 bool IsValid() const 217 { 218 return !text.empty(); 219 } 220 }; 221 222 struct DialogProperties { 223 DialogType type = DialogType::COMMON; // type of dialog, current support common dialog and alert dialog. 224 std::string title; // title of dialog. 225 std::string subtitle; // subtitle of dialog. 226 std::string content; // message of dialog. 227 std::string checkboxContent; // message of checkbox. 228 bool autoCancel = true; // pop dialog when click mask if autoCancel is true. 229 bool customStyle = false; // when true, dialog doesn't paint background or constraint child size. 230 bool isMenu = false; 231 bool isSelect = false; // init checkbox state 232 std::vector<ButtonInfo> buttons; 233 std::function<void()> onCancel; // NG cancel callback 234 std::function<void(const int32_t& info, const int32_t& instanceId)> onWillDismiss; // Cancel Dismiss Callback 235 std::function<void(int32_t, int32_t)> onSuccess; // NG prompt success callback 236 std::function<void(const bool)> onChange; // onChange success callback 237 std::function<void(DialogProperties&)> onLanguageChange; // onLanguageChange callback 238 DialogAlignment alignment = DialogAlignment::DEFAULT; // Alignment of dialog. 239 DimensionOffset offset; // Offset which base on alignment of Dialog. 240 int32_t gridCount = -1; 241 std::optional<Color> maskColor; 242 std::optional<Color> backgroundColor; 243 std::optional<NG::BorderRadiusProperty> borderRadius; 244 std::optional<AnimationOption> openAnimation; 245 std::optional<AnimationOption> closeAnimation; 246 bool isShowInSubWindow = false; 247 DialogButtonDirection buttonDirection = DialogButtonDirection::AUTO; 248 bool isMask = false; 249 bool isModal = true; 250 bool enableHoverMode = false; 251 bool isScenceBoardDialog = false; 252 bool isSysBlurStyle = true; // init use sysBlurStyle 253 std::function<void()> customBuilder; 254 std::function<void(const int32_t dialogId)> customBuilderWithId; 255 std::optional<int32_t> backgroundBlurStyle; 256 std::optional<BlurStyleOption> blurStyleOption; 257 std::optional<EffectOption> effectOption; 258 std::optional<NG::BorderWidthProperty> borderWidth; 259 std::optional<NG::BorderColorProperty> borderColor; 260 std::optional<NG::BorderStyleProperty> borderStyle; 261 std::optional<Shadow> shadow; 262 std::optional<CalcDimension> width; 263 std::optional<CalcDimension> height; 264 std::optional<HoverModeAreaType> hoverModeArea; 265 std::optional<int32_t> controllerId; 266 267 #ifndef NG_BUILD 268 std::unordered_map<std::string, EventMarker> callbacks; // <callback type(success, cancel, complete), eventId> 269 // These ids is used for AlertDialog of declarative. 270 EventMarker primaryId; // first button's callback. 271 EventMarker secondaryId; // second button's callback. 272 #endif 273 274 // These attributes is used for CustomDialog. 275 RefPtr<AceType> customComponent; // Used for CustomDialog in declarative. 276 std::function<void(bool)> onStatusChanged; // Called when dialog appear or disappear. 277 bool isUserCreatedDialog = false; // used for user create dialog for navdestination lifecycle 278 279 // These attributes is used for ActionSheet. 280 std::vector<ActionSheetInfo> sheetsInfo; 281 282 WeakPtr<NG::UINode> windowScene; 283 std::optional<DimensionRect> maskRect; 284 RefPtr<NG::ChainedTransitionEffect> transitionEffect = nullptr; // Used for AlertDialog and ActionSheet transition 285 RefPtr<NG::ChainedTransitionEffect> dialogTransitionEffect = nullptr; 286 RefPtr<NG::ChainedTransitionEffect> maskTransitionEffect = nullptr; 287 288 WeakPtr<NG::UINode> contentNode; 289 std::function<void()> onDidAppear; 290 std::function<void()> onDidDisappear; 291 std::function<void()> onWillAppear; 292 std::function<void()> onWillDisappear; 293 std::function<bool(int32_t)> onWillDismissCallByNDK; 294 295 WordBreak wordBreak = WordBreak::BREAK_ALL; 296 297 KeyboardAvoidMode keyboardAvoidMode = KeyboardAvoidMode::DEFAULT; 298 std::function<void(RefPtr<NG::FrameNode> dialogNode)> dialogCallback; 299 std::optional<Dimension> keyboardAvoidDistance; 300 std::optional<double> levelOrder; 301 bool focusable = true; 302 LevelMode dialogLevelMode = LevelMode::OVERLAY; 303 int32_t dialogLevelUniqueId = -1; 304 ImmersiveMode dialogImmersiveMode = ImmersiveMode::DEFAULT; 305 WeakPtr<NG::UINode> customCNode; 306 }; 307 308 struct PromptDialogAttr { 309 std::string title; 310 std::string message; 311 bool autoCancel = true; 312 bool showInSubWindow = false; 313 bool isModal = false; 314 bool enableHoverMode = false; 315 bool isUserCreatedDialog = false; 316 std::function<void()> customBuilder; 317 std::function<void(const int32_t dialogId)> customBuilderWithId; 318 std::function<void(const int32_t& info, const int32_t& instanceId)> customOnWillDismiss; 319 320 std::optional<DialogAlignment> alignment; 321 std::optional<DimensionOffset> offset; 322 std::optional<DimensionRect> maskRect; 323 std::optional<Color> backgroundColor; 324 std::optional<int32_t> backgroundBlurStyle; 325 std::optional<BlurStyleOption> blurStyleOption; 326 std::optional<EffectOption> effectOption; 327 std::optional<NG::BorderWidthProperty> borderWidth; 328 std::optional<NG::BorderColorProperty> borderColor; 329 std::optional<NG::BorderStyleProperty> borderStyle; 330 std::optional<NG::BorderRadiusProperty> borderRadius; 331 std::optional<Shadow> shadow; 332 std::optional<CalcDimension> width; 333 std::optional<CalcDimension> height; 334 std::optional<HoverModeAreaType> hoverModeArea; 335 336 WeakPtr<NG::UINode> contentNode; 337 bool customStyle = false; 338 std::optional<Color> maskColor; 339 RefPtr<NG::ChainedTransitionEffect> transitionEffect = nullptr; 340 RefPtr<NG::ChainedTransitionEffect> dialogTransitionEffect = nullptr; 341 RefPtr<NG::ChainedTransitionEffect> maskTransitionEffect = nullptr; 342 std::function<void()> onDidAppear; 343 std::function<void()> onDidDisappear; 344 std::function<void()> onWillAppear; 345 std::function<void()> onWillDisappear; 346 std::function<void(DialogProperties&)> onLanguageChange; 347 KeyboardAvoidMode keyboardAvoidMode = KeyboardAvoidMode::DEFAULT; 348 std::function<void(RefPtr<NG::FrameNode> dialogNode)> dialogCallback; 349 std::optional<Dimension> keyboardAvoidDistance; 350 std::optional<double> levelOrder; 351 bool focusable = true; 352 LevelMode dialogLevelMode = LevelMode::OVERLAY; 353 int32_t dialogLevelUniqueId = -1; 354 ImmersiveMode dialogImmersiveMode = ImmersiveMode::DEFAULT; 355 WeakPtr<NG::UINode> customCNode; 356 }; 357 358 } // namespace OHOS::Ace 359 360 #endif // FOUNDATION_ACE_ACE_ENGINE_FRAMEWORKS_CORE_COMPONENTS_COMMON_PROPERTIES_DIALOG_PROPERTIES_H 361