• 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_PATTERNS_SECURITY_COMPONENT_SECURITY_COMPONENT_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SECURITY_COMPONENT_SECURITY_COMPONENT_PATTERN_H
18 
19 #include "core/components_ng/base/view_stack_processor.h"
20 #include "core/components_ng/pattern/image/image_layout_property.h"
21 #include "core/components_ng/pattern/security_component/security_component_accessibility_property.h"
22 #include "core/components_ng/pattern/security_component/security_component_layout_algorithm.h"
23 #include "core/components_ng/pattern/security_component/security_component_layout_property.h"
24 #include "core/components_ng/pattern/pattern.h"
25 
26 namespace OHOS::Ace::NG {
GetSecCompChildNode(RefPtr<FrameNode> & parent,const std::string & tag)27 static inline RefPtr<FrameNode> GetSecCompChildNode(RefPtr<FrameNode>& parent, const std::string& tag)
28 {
29     for (const auto& child : parent->GetChildren()) {
30         auto node = AceType::DynamicCast<FrameNode, UINode>(child);
31         CHECK_NULL_RETURN(node, nullptr);
32         if (node->GetTag() == tag) {
33             return node;
34         }
35     }
36     return nullptr;
37 }
38 
GetCurSecCompChildNode(const std::string & tag)39 static inline RefPtr<FrameNode> GetCurSecCompChildNode(const std::string& tag)
40 {
41     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
42     CHECK_NULL_RETURN(frameNode, nullptr);
43     return GetSecCompChildNode(frameNode, tag);
44 }
45 
46 class SecurityComponentPattern : public Pattern {
47     DECLARE_ACE_TYPE(SecurityComponentPattern, Pattern);
48 
49 public:
SecurityComponentPattern()50     SecurityComponentPattern() {};
51     ~SecurityComponentPattern() override = default;
52 
CreateLayoutProperty()53     RefPtr<LayoutProperty> CreateLayoutProperty() override
54     {
55         return MakeRefPtr<SecurityComponentLayoutProperty>();
56     }
57 
CreateLayoutAlgorithm()58     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
59     {
60         return MakeRefPtr<SecurityComponentLayoutAlgorithm>();
61     }
62 
CreateAccessibilityProperty()63     RefPtr<AccessibilityProperty> CreateAccessibilityProperty() override
64     {
65         return MakeRefPtr<SecurityComponentAccessibilityProperty>();
66     }
67 
68     int32_t scId_ = -1;
69 protected:
70     bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override;
71     void OnModifyDone() override;
72     void SetNodeHitTestMode(RefPtr<FrameNode>& node, HitTestMode mode);
73     void InitSecurityComponentOnClick(RefPtr<FrameNode>& secCompNode, RefPtr<FrameNode>& icon,
74         RefPtr<FrameNode>& text, RefPtr<FrameNode>& button);
75     void RegisterOrUpdateSecurityComponent(RefPtr<FrameNode>& frameNode, int32_t& scId);
76     void UnregisterSecurityComponent();
77     void InitSecurityComponentAppearCallback(RefPtr<FrameNode>& frameNode);
78 #ifdef SECURITY_COMPONENT_ENABLE
79     void ToJsonValue(std::unique_ptr<JsonValue>& json) const override;
80     void ToJsonValueRect(std::unique_ptr<JsonValue>& json) const;
81 #endif
82 private:
83     RefPtr<ClickEvent> clickListener_;
84     bool isAppearCallback_ = false;
85     ACE_DISALLOW_COPY_AND_MOVE(SecurityComponentPattern);
86 };
87 } // namespace OHOS::Ace::NG
88 
89 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SECURITY_COMPONENT_SECURITY_COMPONENT_PATTERN_H
90