• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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_NG_PATTERN_SECURITY_COMPONENT_SECURITY_COMPONENT_MODEL_NG_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SECURITY_COMPONENT_SECURITY_COMPONENT_MODEL_NG_H
18 
19 #include "core/components_ng/base/frame_node.h"
20 #include "core/components_ng/base/view_abstract_model.h"
21 #include "core/components_ng/pattern/security_component/save_button/save_button_common.h"
22 #include "core/components_ng/pattern/security_component/security_component_common.h"
23 #include "core/components_ng/pattern/security_component/security_component_theme.h"
24 #include "core/components/common/layout/constants.h"
25 #include "core/components/common/properties/text_style.h"
26 
27 namespace OHOS::Ace::NG {
28 struct SecurityComponentElementStyle {
29     int32_t text;
30     int32_t icon;
31     int32_t backgroundType;
32     uint32_t symbolIcon;
33 };
34 
35 class ACE_FORCE_EXPORT SecurityComponentModelNG {
36 public:
37     typedef bool (*GetIconResourceFuncType) (int32_t iconStyle, InternalResource::ResourceId& id);
38     typedef bool (*GetTextResourceFuncType) (int32_t textStyle, std::string& text);
39     virtual ~SecurityComponentModelNG() = default;
40     virtual void Create(int32_t text, int32_t icon,
41         int32_t backgroundType, bool isArkuiComponent) = 0;
42     void CreateCommon(const std::string& tag, int32_t text, int32_t icon,
43         int32_t backgroundType,
44         const std::function<RefPtr<Pattern>(void)>& patternCreator, bool isArkuiComponent);
45     RefPtr<FrameNode> CreateNode(const std::string& tag, int32_t nodeId,
46         SecurityComponentElementStyle& style,
47         const std::function<RefPtr<Pattern>(void)>& patternCreator, bool isArkuiComponent);
48     static void SetIconSize(const Dimension& value);
49     static void SetIconSize(const NG::CalcSize& value);
50     static void SetSymbolIconSize(const Dimension& value);
51     static void SetIconColor(const Color& value);
52     static void SetIconBorderRadius(const Dimension& value);
53     static void SetIconBorderRadius(const std::optional<Dimension>& topLeft,
54         const std::optional<Dimension>& topRight, const std::optional<Dimension>& bottomLeft,
55         const std::optional<Dimension>& bottomRight);
56     static void SetIcon(const ImageSourceInfo& value);
57     static void SetText(const std::string& value);
58     static void SetIconSize(FrameNode* frameNode, const std::optional<Dimension>& value);
59     static void SetIconColor(FrameNode* frameNode, const std::optional<Color>& value);
60     static void SetSymbolIconColor(const std::vector<Color>& value);
61     static void SetFontSize(const Dimension& value);
62     static void SetFontSize(FrameNode* frameNode, const std::optional<Dimension>& value);
63     static void SetFontStyle(const Ace::FontStyle& value);
64     static void SetFontStyle(FrameNode* frameNode, const std::optional<Ace::FontStyle>& value);
65     static void SetFontWeight(const FontWeight& value);
66     static void SetFontWeight(FrameNode* frameNode, const std::optional<FontWeight>& value);
67     static void SetFontFamily(const std::vector<std::string>& fontFamilies);
68     static void SetFontFamily(FrameNode* frameNode, const std::optional<std::vector<std::string>>& fontFamilies);
69     static void SetStateEffect(const bool& value);
70     static void SetTipPosition(const TipPosition& value);
71     static void SetFontColor(const Color& value);
72     static void SetFontColor(FrameNode* frameNode, const std::optional<Color>& value);
73     static void SetBackgroundColor(const Color& value);
74     static void SetBackgroundColor(FrameNode* frameNode, const std::optional<Color>& valueOpt);
75     static void SetBackgroundBorderWidth(const Dimension& value);
76     static void SetBackgroundBorderWidth(FrameNode* frameNode, const std::optional<Dimension>& value);
77     static void SetBackgroundBorderColor(const Color& value);
78     static void SetBackgroundBorderColor(FrameNode* frameNode, const std::optional<Color>& value);
79     static void SetBackgroundBorderStyle(const BorderStyle& value);
80     static void SetBackgroundBorderStyle(FrameNode* frameNode, const std::optional<BorderStyle>& value);
81     static void SetBackgroundBorderRadius(const Dimension& value);
82     static void SetBackgroundBorderRadius(FrameNode* frameNode, const std::optional<Dimension>& value);
83     static void SetBackgroundBorderRadius(const std::optional<Dimension>& topLeft,
84         const std::optional<Dimension>& topRight, const std::optional<Dimension>& bottomLeft,
85         const std::optional<Dimension>& bottomRight);
86     static void SetBackgroundPadding(const std::optional<Dimension>& left, const std::optional<Dimension>& right,
87         const std::optional<Dimension>& top, const std::optional<Dimension>& bottom);
88     static void SetBackgroundPadding(FrameNode* frameNode,
89         const std::optional<Dimension>& left, const std::optional<Dimension>& right,
90         const std::optional<Dimension>& top, const std::optional<Dimension>& bottom);
91     static void SetBackgroundPadding(const std::optional<Dimension>& padding);
92     static void SetTextIconSpace(const Dimension& value);
93     static void SetTextIconSpace(FrameNode* frameNode, const std::optional<Dimension>& value);
94     static void SetTextIconLayoutDirection(const SecurityComponentLayoutDirection& value);
95     static void SetTextIconLayoutDirection(FrameNode* frameNode,
96         const std::optional<SecurityComponentLayoutDirection>& value);
97     static void SetAlign(const Alignment alignment);
98     static void SetMaxFontScale(const float value);
99     static void SetMinFontScale(const float value);
100     static void SetMaxLines(const int32_t value);
101     static void SetAdaptMaxFontSize(const Dimension& value);
102     static void SetAdaptMinFontSize(const Dimension& value);
103     static void SetHeightAdaptivePolicy(TextHeightAdaptivePolicy value);
104 
GetIconResource(int32_t iconStyle,InternalResource::ResourceId & id)105     virtual bool GetIconResource(int32_t iconStyle, InternalResource::ResourceId& id)
106     {
107         return false;
108     }
109 
GetTextResource(int32_t textStyle,std::string & text)110     virtual bool GetTextResource(int32_t textStyle,  std::string& text)
111     {
112         return false;
113     }
114 
IsClickResultSuccess(GestureEvent & info)115     virtual bool IsClickResultSuccess(GestureEvent& info)
116     {
117 #ifdef SECURITY_COMPONENT_ENABLE
118         auto secEventValue = info.GetSecCompHandleEvent();
119         if (secEventValue != nullptr) {
120             if (secEventValue->GetInt("handleRes",
121                 static_cast<int32_t>(SecurityComponentHandleResult::CLICK_SUCCESS)) ==
122                 static_cast<int32_t>(SecurityComponentHandleResult::DROP_CLICK)) {
123                 return false;
124             }
125         }
126 #endif
127         return true;
128     }
129 
130 protected:
131     static RefPtr<SecurityComponentTheme> GetTheme();
132     static void InitChildNode(FrameNode* frameNode, const SecurityComponentElementStyle& style,
133     GetIconResourceFuncType getIconResource, GetTextResourceFuncType getTextResource);
134     static bool InitSecurityComponent(FrameNode* frameNode,
135         const SecurityComponentElementStyle& style, bool isArkuiComponent,
136         GetIconResourceFuncType getIconResource, GetTextResourceFuncType getTextResource);
137 
138 private:
139     static void SetDefaultIconStyle(const RefPtr<FrameNode>& imageNode, InternalResource::ResourceId id,
140         bool isButtonVisible);
141     static void SetDefaultSymbolIconStyle(const RefPtr<FrameNode>& symbolNode, uint32_t symbolId,
142         bool isButtonVisible);
143     static void SetInvisibleBackgroundButton(const RefPtr<FrameNode>& buttonNode);
144     static bool IsBackgroundVisible();
145     static bool IsBackgroundVisible(FrameNode* frameNode);
146     static bool IsArkuiComponent();
147     static bool IsArkuiComponent(FrameNode* frameNode);
148     static void NotifyFontColorSet();
149     static bool IsBelowThreshold(const Color& value);
150     static bool IsInReleaseList(uint32_t value);
151     static void SetDefaultBackgroundButton(const RefPtr<FrameNode>& buttonNode,
152         int32_t type);
153     static void SetDefaultTextStyle(const RefPtr<FrameNode>& textNode, const std::string& text, bool isButtonVisible);
154     static void InitLayoutProperty(RefPtr<FrameNode>& node, int32_t text, int32_t icon, uint32_t symbolIcon,
155         int32_t backgroundType);
156     RefPtr<FrameNode> InitChild(const std::string& tag, int32_t nodeId,
157         SecurityComponentElementStyle& style, const std::function<RefPtr<Pattern>(void)>& patternCreator);
158 };
159 } // namespace OHOS::Ace::NG
160 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SECURITY_COMPONENT_SECURITY_COMPONENT_MODEL_NG_H
161