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