1 /* 2 * Copyright (c) 2022-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 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_PROPERTIES_POPUP_PARAM_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_PROPERTIES_POPUP_PARAM_H 18 19 #include <optional> 20 #include <string> 21 22 #include "base/geometry/dimension.h" 23 #include "core/components/common/properties/border.h" 24 #include "core/components/common/properties/color.h" 25 #include "core/components/common/properties/decoration.h" 26 #include "core/components/common/properties/edge.h" 27 #include "core/components/common/properties/placement.h" 28 #include "core/components_ng/property/transition_property.h" 29 #include "core/event/ace_event_handler.h" 30 #include "core/event/touch_event.h" 31 32 namespace OHOS::Ace { 33 34 struct ButtonProperties { 35 bool showButton = false; 36 std::string value; 37 EventMarker actionId; 38 // touchFunc used in Declarative mode. 39 TouchEventFunc touchFunc; 40 RefPtr<NG::ClickEvent> action; // button click action 41 }; 42 43 enum class PopupKeyboardAvoidMode { 44 DEFAULT, 45 NONE 46 }; 47 48 using StateChangeFunc = std::function<void(const std::string&)>; 49 using OnWillDismiss = std::function<void(int32_t)>; 50 class PopupParam : public AceType { 51 DECLARE_ACE_TYPE(PopupParam, AceType) 52 53 public: 54 PopupParam() = default; 55 ~PopupParam() override = default; 56 SetIsShow(bool isShow)57 void SetIsShow(bool isShow) 58 { 59 isShow_ = isShow; 60 } 61 IsShow()62 bool IsShow() const 63 { 64 return isShow_; 65 } 66 SetHasAction(bool hasAction)67 void SetHasAction(bool hasAction) 68 { 69 hasAction_ = hasAction; 70 } 71 HasAction()72 bool HasAction() const 73 { 74 return hasAction_; 75 } 76 SetPlacement(const Placement & placement)77 void SetPlacement(const Placement& placement) 78 { 79 placement_ = placement; 80 } 81 SetMaskColor(const Color & maskColor)82 void SetMaskColor(const Color& maskColor) 83 { 84 maskColor_ = maskColor; 85 isMaskColorSetted_ = true; 86 } 87 SetBackgroundColor(const Color & backgroundColor)88 void SetBackgroundColor(const Color& backgroundColor) 89 { 90 backgroundColor_ = backgroundColor; 91 isBackgroundColorSetted_ = true; 92 } 93 SetOnVisibilityChange(const EventMarker & onVisibilityChange)94 void SetOnVisibilityChange(const EventMarker& onVisibilityChange) 95 { 96 onVisibilityChange_ = onVisibilityChange; 97 } 98 GetPlacement()99 Placement GetPlacement() const 100 { 101 return placement_; 102 } 103 GetMaskColor()104 const Color& GetMaskColor() const 105 { 106 return maskColor_; 107 } 108 GetBackgroundColor()109 const Color& GetBackgroundColor() const 110 { 111 return backgroundColor_; 112 } 113 GetOnVisibilityChange()114 const EventMarker& GetOnVisibilityChange() const 115 { 116 return onVisibilityChange_; 117 } 118 GetMargin()119 const Edge& GetMargin() const 120 { 121 return margin_; 122 } 123 SetMargin(const Edge & margin)124 void SetMargin(const Edge& margin) 125 { 126 margin_ = margin; 127 } 128 GetTargetMargin()129 const Edge& GetTargetMargin() const 130 { 131 return targetMargin_; 132 } 133 SetTargetMargin(const Edge & targetMargin)134 void SetTargetMargin(const Edge& targetMargin) 135 { 136 targetMargin_ = targetMargin; 137 } 138 GetPadding()139 const Edge& GetPadding() const 140 { 141 return padding_; 142 } 143 SetPadding(const Edge & padding)144 void SetPadding(const Edge& padding) 145 { 146 padding_ = padding; 147 } 148 GetBorder()149 const Border& GetBorder() const 150 { 151 return border_; 152 } 153 SetBorder(const Border & border)154 void SetBorder(const Border& border) 155 { 156 border_ = border; 157 } 158 GetArrowOffset()159 const std::optional<Dimension>& GetArrowOffset() const 160 { 161 return arrowOffset_; 162 } 163 SetArrowOffset(const std::optional<Dimension> & arrowOffset)164 void SetArrowOffset(const std::optional<Dimension>& arrowOffset) 165 { 166 arrowOffset_ = arrowOffset; 167 } 168 GetTargetId()169 const ComposeId& GetTargetId() const 170 { 171 return targetId_; 172 } 173 SetTargetId(const ComposeId & targetId)174 void SetTargetId(const ComposeId& targetId) 175 { 176 targetId_ = targetId; 177 } 178 IsMaskColorSetted()179 bool IsMaskColorSetted() const 180 { 181 return isMaskColorSetted_; 182 } 183 IsBackgroundColorSetted()184 bool IsBackgroundColorSetted() const 185 { 186 return isBackgroundColorSetted_; 187 } 188 EnableArrow()189 bool EnableArrow() const 190 { 191 return enableArrow_; 192 } 193 SetEnableArrow(bool enableArrow)194 void SetEnableArrow(bool enableArrow) 195 { 196 enableArrow_ = enableArrow; 197 } 198 IsBlockEvent()199 bool IsBlockEvent() const 200 { 201 return blockEvent_; 202 } 203 SetBlockEvent(bool blockEvent)204 void SetBlockEvent(bool blockEvent) 205 { 206 blockEvent_ = blockEvent; 207 } 208 IsUseCustom()209 bool IsUseCustom() const 210 { 211 return useCustom_; 212 } 213 SetUseCustomComponent(bool useCustom)214 void SetUseCustomComponent(bool useCustom) 215 { 216 useCustom_ = useCustom; 217 } 218 GetTargetSpace()219 const std::optional<Dimension>& GetTargetSpace() const 220 { 221 return targetSpace_; 222 } 223 GetChildWidth()224 const std::optional<Dimension>& GetChildWidth() const 225 { 226 return childwidth_; 227 } 228 SetTargetSpace(const Dimension & targetSpace)229 void SetTargetSpace(const Dimension& targetSpace) 230 { 231 targetSpace_ = targetSpace; 232 } 233 SetChildWidth(const Dimension & childWidth)234 void SetChildWidth(const Dimension& childWidth) 235 { 236 childwidth_ = childWidth; 237 } 238 SetMessage(const std::string & msg)239 void SetMessage(const std::string& msg) 240 { 241 message_ = msg; 242 } 243 GetMessage()244 std::string GetMessage() const 245 { 246 return message_; 247 } 248 GetOnStateChange()249 StateChangeFunc GetOnStateChange() 250 { 251 return onStateChange_; 252 } 253 SetOnStateChange(StateChangeFunc && onStateChange)254 void SetOnStateChange(StateChangeFunc&& onStateChange) 255 { 256 onStateChange_ = onStateChange; 257 } 258 SetPrimaryButtonProperties(const ButtonProperties & prop)259 void SetPrimaryButtonProperties(const ButtonProperties& prop) 260 { 261 primaryButtonProperties_ = prop; 262 } 263 SetSecondaryButtonProperties(const ButtonProperties & prop)264 void SetSecondaryButtonProperties(const ButtonProperties& prop) 265 { 266 secondaryButtonProperties_ = prop; 267 } 268 GetPrimaryButtonProperties()269 const ButtonProperties& GetPrimaryButtonProperties() const 270 { 271 return primaryButtonProperties_; 272 } 273 GetSecondaryButtonProperties()274 const ButtonProperties& GetSecondaryButtonProperties() const 275 { 276 return secondaryButtonProperties_; 277 } 278 SetShowInSubWindow(bool isShowInSubWindow)279 void SetShowInSubWindow(bool isShowInSubWindow) 280 { 281 isShowInSubWindow_ = isShowInSubWindow; 282 } 283 IsShowInSubWindow()284 bool IsShowInSubWindow() const 285 { 286 return isShowInSubWindow_; 287 } 288 SetTargetSize(const Size & targetSize)289 void SetTargetSize(const Size& targetSize) 290 { 291 targetSize_ = targetSize; 292 } 293 GetTargetSize()294 const Size& GetTargetSize() const 295 { 296 return targetSize_; 297 } 298 SetTargetOffset(const Offset & targetOffset)299 void SetTargetOffset(const Offset& targetOffset) 300 { 301 targetOffset_ = targetOffset; 302 } 303 GetTargetOffset()304 const Offset& GetTargetOffset() const 305 { 306 return targetOffset_; 307 } 308 SetTextColor(const Color & textColor)309 void SetTextColor(const Color& textColor) 310 { 311 textColor_ = textColor; 312 } 313 GetTextColor()314 const std::optional<Color>& GetTextColor() const 315 { 316 return textColor_; 317 } 318 SetFontSize(const Dimension & fontSize)319 void SetFontSize(const Dimension& fontSize) 320 { 321 fontSize_ = fontSize; 322 } 323 GetFontSize()324 const std::optional<Dimension>& GetFontSize() const 325 { 326 return fontSize_; 327 } 328 SetFontWeight(const FontWeight & fontWeight)329 void SetFontWeight(const FontWeight& fontWeight) 330 { 331 fontWeight_ = fontWeight; 332 } 333 GetFontWeight()334 const std::optional<FontWeight>& GetFontWeight() const 335 { 336 return fontWeight_; 337 } 338 SetFontStyle(const FontStyle & fontStyle)339 void SetFontStyle(const FontStyle& fontStyle) 340 { 341 fontStyle_ = fontStyle; 342 } 343 GetFontStyle()344 const std::optional<FontStyle>& GetFontStyle() const 345 { 346 return fontStyle_; 347 } 348 GetArrowWidth()349 const std::optional<Dimension>& GetArrowWidth() const 350 { 351 return arrowWidth_; 352 } 353 SetArrowWidth(const Dimension & arrowWidth)354 void SetArrowWidth(const Dimension& arrowWidth) 355 { 356 arrowWidth_ = arrowWidth; 357 } 358 GetArrowHeight()359 const std::optional<Dimension>& GetArrowHeight() const 360 { 361 return arrowHeight_; 362 } 363 SetArrowHeight(const Dimension & arrowHeight)364 void SetArrowHeight(const Dimension& arrowHeight) 365 { 366 arrowHeight_ = arrowHeight; 367 } 368 GetRadius()369 const std::optional<Dimension>& GetRadius() const 370 { 371 return radius_; 372 } 373 SetRadius(const Dimension & radius)374 void SetRadius(const Dimension& radius) 375 { 376 radius_ = radius; 377 } 378 SetShadow(const Shadow & shadow)379 void SetShadow(const Shadow& shadow) 380 { 381 shadow_ = shadow; 382 } 383 GetShadow()384 const std::optional<Shadow>& GetShadow() const 385 { 386 return shadow_; 387 } 388 SetErrorArrowWidth(bool setErrorArrowWidth)389 void SetErrorArrowWidth(bool setErrorArrowWidth) 390 { 391 setErrorArrowWidth_ = setErrorArrowWidth; 392 } 393 GetErrorArrowWidth()394 bool GetErrorArrowWidth() const 395 { 396 return setErrorArrowWidth_; 397 } 398 SetErrorArrowHeight(bool setErrorArrowHeight)399 void SetErrorArrowHeight(bool setErrorArrowHeight) 400 { 401 setErrorArrowHeight_ = setErrorArrowHeight; 402 } 403 GetErrorArrowHeight()404 bool GetErrorArrowHeight() const 405 { 406 return setErrorArrowHeight_; 407 } 408 SetErrorRadius(bool setErrorRadius)409 void SetErrorRadius(bool setErrorRadius) 410 { 411 setErrorRadius_ = setErrorRadius; 412 } 413 GetErrorRadius()414 bool GetErrorRadius() const 415 { 416 return setErrorRadius_; 417 } 418 SetFocusable(bool focusable)419 void SetFocusable(bool focusable) 420 { 421 focusable_ = focusable; 422 } 423 GetFocusable()424 bool GetFocusable() const 425 { 426 return focusable_; 427 } 428 SetBlurStyle(const BlurStyle & blurStyle)429 void SetBlurStyle(const BlurStyle& blurStyle) 430 { 431 blurStyle_ = blurStyle; 432 } 433 GetBlurStyle()434 BlurStyle GetBlurStyle() const 435 { 436 return blurStyle_; 437 } 438 SetInteractiveDismiss(bool interactiveDismiss)439 void SetInteractiveDismiss(bool interactiveDismiss) 440 { 441 interactiveDismiss_ = interactiveDismiss; 442 } 443 GetInteractiveDismiss()444 bool GetInteractiveDismiss() const 445 { 446 return interactiveDismiss_; 447 } 448 SetOnWillDismiss(const OnWillDismiss && onWillDismiss)449 void SetOnWillDismiss(const OnWillDismiss&& onWillDismiss) 450 { 451 onWillDismiss_ = std::move(onWillDismiss); 452 } 453 GetOnWillDismiss()454 OnWillDismiss GetOnWillDismiss() const 455 { 456 return onWillDismiss_; 457 } SetHasTransition(bool hasTransition)458 void SetHasTransition(bool hasTransition) 459 { 460 hasTransition_ = hasTransition; 461 } 462 GetHasTransition()463 bool GetHasTransition() const 464 { 465 return hasTransition_; 466 } 467 SetTransitionEffects(const RefPtr<NG::ChainedTransitionEffect> & transitionEffects)468 void SetTransitionEffects(const RefPtr<NG::ChainedTransitionEffect>& transitionEffects) 469 { 470 transitionEffects_ = transitionEffects; 471 } 472 GetTransitionEffects()473 const RefPtr<NG::ChainedTransitionEffect> GetTransitionEffects() const 474 { 475 return transitionEffects_; 476 } 477 SetIsCaretMode(bool isCaretMode)478 void SetIsCaretMode (bool isCaretMode) 479 { 480 isCaretMode_ = isCaretMode; 481 } 482 IsCaretMode()483 bool IsCaretMode() const 484 { 485 return isCaretMode_; 486 } 487 SetFollowTransformOfTarget(bool followTransformOfTarget)488 void SetFollowTransformOfTarget (bool followTransformOfTarget) 489 { 490 followTransformOfTarget_ = followTransformOfTarget; 491 } 492 IsFollowTransformOfTarget()493 bool IsFollowTransformOfTarget() const 494 { 495 return followTransformOfTarget_; 496 } 497 SetKeyBoardAvoidMode(PopupKeyboardAvoidMode keyboardAvoidMode)498 void SetKeyBoardAvoidMode (PopupKeyboardAvoidMode keyboardAvoidMode) 499 { 500 keyboardAvoidMode_ = keyboardAvoidMode; 501 } 502 GetKeyBoardAvoidMode()503 PopupKeyboardAvoidMode GetKeyBoardAvoidMode() const 504 { 505 return keyboardAvoidMode_; 506 } 507 508 private: 509 bool isShow_ = true; 510 bool hasAction_ = false; 511 bool enableArrow_ = true; 512 bool isMaskColorSetted_ = false; 513 bool isBackgroundColorSetted_ = false; 514 bool useCustom_ = false; 515 bool isShowInSubWindow_ = false; 516 bool blockEvent_ = true; 517 bool setErrorArrowWidth_ = false; 518 bool setErrorArrowHeight_ = false; 519 bool setErrorRadius_ = false; 520 bool focusable_ = false; 521 bool interactiveDismiss_ = true; 522 bool isCaretMode_ = true; 523 bool followTransformOfTarget_ = false; 524 Color maskColor_; 525 Color backgroundColor_; 526 Placement placement_ = Placement::BOTTOM; 527 BlurStyle blurStyle_ = BlurStyle::COMPONENT_ULTRA_THICK; 528 EventMarker onVisibilityChange_; 529 Edge padding_; 530 Edge margin_; 531 Edge targetMargin_; 532 Border border_; 533 std::optional<Dimension> arrowOffset_; 534 ComposeId targetId_; 535 std::optional<Dimension> targetSpace_; 536 std::optional<Dimension> childwidth_; 537 std::string message_; 538 Offset targetOffset_; 539 Size targetSize_; 540 std::optional<FontWeight> fontWeight_; 541 std::optional<Color> textColor_; 542 std::optional<Dimension> fontSize_; 543 std::optional<FontStyle> fontStyle_; 544 545 std::optional<Dimension> arrowWidth_; 546 std::optional<Dimension> arrowHeight_; 547 std::optional<Dimension> radius_; 548 std::optional<Shadow> shadow_; 549 // Used in NG mode 550 StateChangeFunc onStateChange_; 551 ButtonProperties primaryButtonProperties_; // first button. 552 ButtonProperties secondaryButtonProperties_; // second button. 553 OnWillDismiss onWillDismiss_; 554 bool hasTransition_ = false; 555 RefPtr<NG::ChainedTransitionEffect> transitionEffects_ = nullptr; 556 PopupKeyboardAvoidMode keyboardAvoidMode_ = PopupKeyboardAvoidMode::NONE; 557 }; 558 559 } // namespace OHOS::Ace 560 561 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_PROPERTIES_POPUP_PARAM_H 562