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