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