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 };
32 
33 class ACE_EXPORT SecurityComponentModelNG {
34 public:
35     virtual ~SecurityComponentModelNG() = default;
36     virtual void Create(int32_t text, int32_t icon,
37         int32_t backgroundType, bool isArkuiComponent) = 0;
38     void CreateCommon(const std::string& tag, int32_t text, int32_t icon,
39         int32_t backgroundType,
40         const std::function<RefPtr<Pattern>(void)>& patternCreator, bool isArkuiComponent);
41     RefPtr<FrameNode> CreateNode(const std::string& tag, int32_t nodeId,
42         SecurityComponentElementStyle& style,
43         const std::function<RefPtr<Pattern>(void)>& patternCreator, bool isArkuiComponent);
44     static void SetIconSize(const Dimension& value);
45     static void SetIconColor(const Color& value);
46     static void SetFontSize(const Dimension& value);
47     static void SetFontStyle(const Ace::FontStyle& value);
48     static void SetFontWeight(const FontWeight& value);
49     static void SetFontFamily(const std::vector<std::string>& fontFamilies);
50     static void SetFontColor(const Color& value);
51     static void SetBackgroundColor(const Color& value);
52     static void SetBackgroundBorderWidth(const Dimension& value);
53     static void SetBackgroundBorderColor(const Color& value);
54     static void SetBackgroundBorderStyle(const BorderStyle& value);
55     static void SetBackgroundBorderRadius(const Dimension& value);
56     static void SetBackgroundPadding(const std::optional<Dimension>& left, const std::optional<Dimension>& right,
57         const std::optional<Dimension>& top, const std::optional<Dimension>& bottom);
58     static void SetBackgroundPadding(const std::optional<Dimension>& padding);
59     static void SetTextIconSpace(const Dimension& value);
60     static void SetTextIconLayoutDirection(const SecurityComponentLayoutDirection& value);
61 
GetIconResource(int32_t iconStyle,InternalResource::ResourceId & id)62     virtual bool GetIconResource(int32_t iconStyle, InternalResource::ResourceId& id)
63     {
64         return false;
65     }
66 
GetTextResource(int32_t textStyle,std::string & text)67     virtual bool GetTextResource(int32_t textStyle,  std::string& text)
68     {
69         return false;
70     }
71 
IsClickResultSuccess(GestureEvent & info)72     virtual bool IsClickResultSuccess(GestureEvent& info)
73     {
74 #ifdef SECURITY_COMPONENT_ENABLE
75         auto secEventValue = info.GetSecCompHandleEvent();
76         if (secEventValue != nullptr) {
77             if (secEventValue->GetInt("handleRes",
78                 static_cast<int32_t>(SecurityComponentHandleResult::CLICK_SUCCESS)) ==
79                 static_cast<int32_t>(SecurityComponentHandleResult::DROP_CLICK)) {
80                 return false;
81             }
82         }
83 #endif
84         return true;
85     }
86 
87 protected:
88     static RefPtr<SecurityComponentTheme> GetTheme();
89 
90 private:
91     static void SetDefaultIconStyle(const RefPtr<FrameNode>& imageNode, InternalResource::ResourceId id,
92         bool isButtonVisible);
93     static void SetInvisibleBackgroundButton(const RefPtr<FrameNode>& buttonNode);
94     static bool IsBackgroundVisible();
95     static bool IsArkuiComponent();
96     static void NotifyFontColorSet();
97     static bool IsBelowThreshold(const Color& value);
98     static bool IsInReleaseList(uint32_t value);
99     static void SetDefaultBackgroundButton(const RefPtr<FrameNode>& buttonNode,
100         int32_t type);
101     static void SetDefaultTextStyle(const RefPtr<FrameNode>& textNode, const std::string& text, bool isButtonVisible);
102     static void InitLayoutProperty(RefPtr<FrameNode>& node, int32_t text, int32_t icon,
103         int32_t backgroundType);
104 };
105 } // namespace OHOS::Ace::NG
106 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SECURITY_COMPONENT_SECURITY_COMPONENT_MODEL_NG_H
107