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