• 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 #ifdef SECURITY_COMPONENT_ENABLE
20 #include "event_handler.h"
21 #endif
22 #include "core/components_ng/base/view_stack_processor.h"
23 #include "core/components_ng/pattern/image/image_layout_property.h"
24 #include "core/components_ng/pattern/security_component/security_component_accessibility_property.h"
25 #include "core/components_ng/pattern/security_component/security_component_layout_algorithm.h"
26 #include "core/components_ng/pattern/security_component/security_component_layout_property.h"
27 #include "core/components_ng/pattern/security_component/security_component_paint_property.h"
28 #include "core/components_ng/pattern/pattern.h"
29 
30 namespace OHOS::Ace::NG {
31 class InspectorFilter;
32 
33 constexpr int32_t DEFAULT_SECURITY_COMPONENT_CLICK_DISTANCE = 15;
34 constexpr uint64_t MAX_REGISTER_WAITING_TIME = 3000; // 3000ms
35 constexpr int32_t MAX_RETRY_TIMES = 3;
36 constexpr int64_t REGISTER_RETRY_INTERVAL = 30; // 30ms
37 
GetSecCompChildNode(RefPtr<FrameNode> & parent,const std::string & tag)38 static inline RefPtr<FrameNode> GetSecCompChildNode(RefPtr<FrameNode>& parent, const std::string& tag)
39 {
40     CHECK_NULL_RETURN(parent, nullptr);
41     for (const auto& child : parent->GetChildren()) {
42         auto node = AceType::DynamicCast<FrameNode, UINode>(child);
43         CHECK_NULL_RETURN(node, nullptr);
44         if (node->GetTag() == tag) {
45             return node;
46         }
47     }
48     return nullptr;
49 }
50 
GetCurSecCompChildNode(const std::string & tag)51 static inline RefPtr<FrameNode> GetCurSecCompChildNode(const std::string& tag)
52 {
53     auto frameNode = AceType::Claim(ViewStackProcessor::GetInstance()->GetMainFrameNode());
54     CHECK_NULL_RETURN(frameNode, nullptr);
55     return GetSecCompChildNode(frameNode, tag);
56 }
57 
58 class SecurityComponentPattern : public Pattern {
59     DECLARE_ACE_TYPE(SecurityComponentPattern, Pattern);
60 
61 public:
62     SecurityComponentPattern();
63     ~SecurityComponentPattern() override;
64 
CreateLayoutProperty()65     RefPtr<LayoutProperty> CreateLayoutProperty() override
66     {
67         return MakeRefPtr<SecurityComponentLayoutProperty>();
68     }
69 
CreatePaintProperty()70     RefPtr<PaintProperty> CreatePaintProperty() override
71     {
72         return MakeRefPtr<SecurityComponentPaintProperty>();
73     }
74 
CreateLayoutAlgorithm()75     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
76     {
77         return MakeRefPtr<SecurityComponentLayoutAlgorithm>();
78     }
79 
CreateAccessibilityProperty()80     RefPtr<AccessibilityProperty> CreateAccessibilityProperty() override
81     {
82         return MakeRefPtr<SecurityComponentAccessibilityProperty>();
83     }
84 
85     FocusPattern GetFocusPattern() const override;
86 
87     void OnWindowHide() override;
88     void OnWindowShow() override;
89 
90     void OnLanguageConfigurationUpdate() override;
91 
92     SecurityComponentRegisterStatus regStatus_ = SecurityComponentRegisterStatus::UNREGISTERED;
93     std::timed_mutex regMutex_;
94     int32_t scId_ = -1;
95     bool isAppear_ = true;
96 
97 protected:
98     void InitOnTouch(RefPtr<FrameNode>& secCompNode);
99     void InitOnKeyEvent(RefPtr<FrameNode>& secCompNode);
100     bool OnKeyEvent(const KeyEvent& event);
101     void OnTouch(const TouchEventInfo& info);
102     bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override;
103     void OnModifyDone() override;
104     bool IsFontColorSet();
105     void OnColorConfigurationUpdate() override;
106     void SetNodeHitTestMode(RefPtr<FrameNode>& node, HitTestMode mode);
107     void InitOnClick(RefPtr<FrameNode>& secCompNode, RefPtr<FrameNode>& icon,
108         RefPtr<FrameNode>& text, RefPtr<FrameNode>& button);
109     void InitAppearCallback(RefPtr<FrameNode>& frameNode);
110     void ToJsonValueIconNode(std::unique_ptr<JsonValue>& json, const RefPtr<FrameNode>& iconNode,
111         const InspectorFilter& filter) const;
112     void ToJsonValueSymbolIconNode(std::unique_ptr<JsonValue>& json, const RefPtr<FrameNode>& symbolIconNode,
113         const InspectorFilter& filter) const;
114     void ToJsonValueTextNode(std::unique_ptr<JsonValue>& json, const RefPtr<FrameNode>& textNode,
115         const InspectorFilter& filter) const;
116     void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override;
117     void ToJsonValueRect(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const;
118     bool IsParentMenu(RefPtr<FrameNode>& secCompNode);
119 private:
120     void HandleClickEventFromTouch(const TouchEventInfo& info);
121     void UpdateIconProperty(RefPtr<FrameNode>& scNode, RefPtr<FrameNode>& iconNode);
122     void UpdateTextProperty(RefPtr<FrameNode>& scNode, RefPtr<FrameNode>& textNode);
123     void UpdateButtonProperty(RefPtr<FrameNode>& scNode, RefPtr<FrameNode>& buttonNode);
124     void HandleEnabled();
125 #ifdef SECURITY_COMPONENT_ENABLE
126     void RegisterSecurityComponent();
127     void RegisterSecurityComponentRetry();
128     void UnregisterSecurityComponent();
129     int32_t ReportSecurityComponentClickEvent(GestureEvent& event, std::string& message);
130     int32_t ReportSecurityComponentClickEvent(const KeyEvent& event);
131     void DoTriggerOnclick(int32_t result);
132     void DelayReleaseNode(uint64_t index);
133     std::function<int32_t(int32_t)> CreateFirstUseDialogCloseFunc(
134         RefPtr<FrameNode>& frameNode, RefPtr<PipelineContext>& pipeline, const std::string& taskName);
135     void HandleReportSecCompClickEventResult(int32_t& code, std::string& message);
136 #endif
137     std::unique_ptr<Offset> lastTouchOffset_;
138     RefPtr<ClickEvent> clickListener_;
139     RefPtr<TouchEventImpl> onTouchListener_;
140     bool isSetOnKeyEvent = false;
141     bool isAppearCallback_ = false;
142 #ifdef SECURITY_COMPONENT_ENABLE
143     std::shared_ptr<AppExecFwk::EventHandler> uiEventHandler_ = nullptr;
144 #endif
145     ACE_DISALLOW_COPY_AND_MOVE(SecurityComponentPattern);
146 };
147 } // namespace OHOS::Ace::NG
148 
149 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SECURITY_COMPONENT_SECURITY_COMPONENT_PATTERN_H
150