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