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 SetBackgroundBorderRadius(const std::optional<Dimension>& topLeft, 57 const std::optional<Dimension>& topRight, const std::optional<Dimension>& bottomLeft, 58 const std::optional<Dimension>& bottomRight); 59 static void SetBackgroundPadding(const std::optional<Dimension>& left, const std::optional<Dimension>& right, 60 const std::optional<Dimension>& top, const std::optional<Dimension>& bottom); 61 static void SetBackgroundPadding(const std::optional<Dimension>& padding); 62 static void SetTextIconSpace(const Dimension& value); 63 static void SetTextIconLayoutDirection(const SecurityComponentLayoutDirection& value); 64 static void SetAlign(const Alignment alignment); 65 GetIconResource(int32_t iconStyle,InternalResource::ResourceId & id)66 virtual bool GetIconResource(int32_t iconStyle, InternalResource::ResourceId& id) 67 { 68 return false; 69 } 70 GetTextResource(int32_t textStyle,std::string & text)71 virtual bool GetTextResource(int32_t textStyle, std::string& text) 72 { 73 return false; 74 } 75 IsClickResultSuccess(GestureEvent & info)76 virtual bool IsClickResultSuccess(GestureEvent& info) 77 { 78 #ifdef SECURITY_COMPONENT_ENABLE 79 auto secEventValue = info.GetSecCompHandleEvent(); 80 if (secEventValue != nullptr) { 81 if (secEventValue->GetInt("handleRes", 82 static_cast<int32_t>(SecurityComponentHandleResult::CLICK_SUCCESS)) == 83 static_cast<int32_t>(SecurityComponentHandleResult::DROP_CLICK)) { 84 return false; 85 } 86 } 87 #endif 88 return true; 89 } 90 91 protected: 92 static RefPtr<SecurityComponentTheme> GetTheme(); 93 94 private: 95 static void SetDefaultIconStyle(const RefPtr<FrameNode>& imageNode, InternalResource::ResourceId id, 96 bool isButtonVisible); 97 static void SetInvisibleBackgroundButton(const RefPtr<FrameNode>& buttonNode); 98 static bool IsBackgroundVisible(); 99 static bool IsArkuiComponent(); 100 static void NotifyFontColorSet(); 101 static bool IsBelowThreshold(const Color& value); 102 static bool IsInReleaseList(uint32_t value); 103 static void SetDefaultBackgroundButton(const RefPtr<FrameNode>& buttonNode, 104 int32_t type); 105 static void SetDefaultTextStyle(const RefPtr<FrameNode>& textNode, const std::string& text, bool isButtonVisible); 106 static void InitLayoutProperty(RefPtr<FrameNode>& node, int32_t text, int32_t icon, 107 int32_t backgroundType); 108 }; 109 } // namespace OHOS::Ace::NG 110 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SECURITY_COMPONENT_SECURITY_COMPONENT_MODEL_NG_H 111