• 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/security_component_common.h"
22 #include "core/components_ng/pattern/security_component/security_component_theme.h"
23 #include "core/components/common/layout/constants.h"
24 #include "core/components/common/properties/text_style.h"
25 
26 namespace OHOS::Ace::NG {
27 struct SecurityComponentElementStyle {
28     int32_t text;
29     int32_t icon;
30     int32_t backgroundType;
31     uint32_t symbolIcon;
32 };
33 
34 class ACE_EXPORT SecurityComponentModelNG {
35 public:
36     virtual ~SecurityComponentModelNG() = default;
37     virtual void Create(int32_t text, int32_t icon,
38         int32_t backgroundType, bool isArkuiComponent) = 0;
39     void CreateCommon(const std::string& tag, int32_t text, int32_t icon,
40         int32_t backgroundType,
41         const std::function<RefPtr<Pattern>(void)>& patternCreator, bool isArkuiComponent);
42     RefPtr<FrameNode> CreateNode(const std::string& tag, int32_t nodeId,
43         SecurityComponentElementStyle& style,
44         const std::function<RefPtr<Pattern>(void)>& patternCreator, bool isArkuiComponent);
45     static void SetIconSize(const Dimension& value);
46     static void SetSymbolIconSize(const Dimension& value);
47     static void SetIconColor(const Color& value);
48     static void SetSymbolIconColor(const std::vector<Color>& value);
49     static void SetFontSize(const Dimension& value);
50     static void SetFontStyle(const Ace::FontStyle& value);
51     static void SetFontWeight(const FontWeight& value);
52     static void SetFontFamily(const std::vector<std::string>& fontFamilies);
53     static void SetFontColor(const Color& value);
54     static void SetBackgroundColor(const Color& value);
55     static void SetBackgroundBorderWidth(const Dimension& value);
56     static void SetBackgroundBorderColor(const Color& value);
57     static void SetBackgroundBorderStyle(const BorderStyle& value);
58     static void SetBackgroundBorderRadius(const Dimension& value);
59     static void SetBackgroundBorderRadius(const std::optional<Dimension>& topLeft,
60         const std::optional<Dimension>& topRight, const std::optional<Dimension>& bottomLeft,
61         const std::optional<Dimension>& bottomRight);
62     static void SetBackgroundPadding(const std::optional<Dimension>& left, const std::optional<Dimension>& right,
63         const std::optional<Dimension>& top, const std::optional<Dimension>& bottom);
64     static void SetBackgroundPadding(const std::optional<Dimension>& padding);
65     static void SetTextIconSpace(const Dimension& value);
66     static void SetTextIconLayoutDirection(const SecurityComponentLayoutDirection& value);
67     static void SetAlign(const Alignment alignment);
68     static void SetMaxFontScale(const float value);
69     static void SetMinFontScale(const float value);
70     static void SetMaxLines(const int32_t value);
71     static void SetAdaptMaxFontSize(const Dimension& value);
72     static void SetAdaptMinFontSize(const Dimension& value);
73     static void SetHeightAdaptivePolicy(TextHeightAdaptivePolicy value);
74 
GetIconResource(int32_t iconStyle,InternalResource::ResourceId & id)75     virtual bool GetIconResource(int32_t iconStyle, InternalResource::ResourceId& id)
76     {
77         return false;
78     }
79 
GetTextResource(int32_t textStyle,std::string & text)80     virtual bool GetTextResource(int32_t textStyle,  std::string& text)
81     {
82         return false;
83     }
84 
IsClickResultSuccess(GestureEvent & info)85     virtual bool IsClickResultSuccess(GestureEvent& info)
86     {
87 #ifdef SECURITY_COMPONENT_ENABLE
88         auto secEventValue = info.GetSecCompHandleEvent();
89         if (secEventValue != nullptr) {
90             if (secEventValue->GetInt("handleRes",
91                 static_cast<int32_t>(SecurityComponentHandleResult::CLICK_SUCCESS)) ==
92                 static_cast<int32_t>(SecurityComponentHandleResult::DROP_CLICK)) {
93                 return false;
94             }
95         }
96 #endif
97         return true;
98     }
99 
100 protected:
101     static RefPtr<SecurityComponentTheme> GetTheme();
102 
103 private:
104     static void SetDefaultIconStyle(const RefPtr<FrameNode>& imageNode, InternalResource::ResourceId id,
105         bool isButtonVisible);
106     static void SetDefaultSymbolIconStyle(const RefPtr<FrameNode>& symbolNode, uint32_t symbolId,
107         bool isButtonVisible);
108     static void SetInvisibleBackgroundButton(const RefPtr<FrameNode>& buttonNode);
109     static bool IsBackgroundVisible();
110     static bool IsArkuiComponent();
111     static void NotifyFontColorSet();
112     static bool IsBelowThreshold(const Color& value);
113     static bool IsInReleaseList(uint32_t value);
114     static void SetDefaultBackgroundButton(const RefPtr<FrameNode>& buttonNode,
115         int32_t type);
116     static void SetDefaultTextStyle(const RefPtr<FrameNode>& textNode, const std::string& text, bool isButtonVisible);
117     static void InitLayoutProperty(RefPtr<FrameNode>& node, int32_t text, int32_t icon, uint32_t symbolIcon,
118         int32_t backgroundType);
119     RefPtr<FrameNode> InitChild(const std::string& tag, int32_t nodeId,
120         SecurityComponentElementStyle& style, const std::function<RefPtr<Pattern>(void)>& patternCreator);
121 };
122 } // namespace OHOS::Ace::NG
123 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SECURITY_COMPONENT_SECURITY_COMPONENT_MODEL_NG_H
124