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