1 /* 2 * Copyright (c) 2021-2022 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_BASE_INSPECTOR_COMPOSED_COMPONENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_INSPECTOR_COMPOSED_COMPONENT_H 18 19 #include <functional> 20 #include <string> 21 22 #include "core/accessibility/accessibility_manager.h" 23 #include "core/event/ace_event_handler.h" 24 #include "core/pipeline/base/composed_component.h" 25 26 namespace OHOS::Ace::V2 { 27 28 class ACE_EXPORT InspectorFunctionImpl : public AceType { 29 DECLARE_ACE_TYPE(InspectorFunctionImpl, AceType); 30 31 public: 32 InspectorFunctionImpl() = default; 33 ~InspectorFunctionImpl() override = default; 34 UpdateEventInfo(BaseEventInfo & info)35 void UpdateEventInfo(BaseEventInfo& info) 36 { 37 if (updateEventInfoimpl_) { 38 updateEventInfoimpl_(info); 39 } 40 } 41 SetUpdateEventInfoImpl(const std::function<void (BaseEventInfo &)> & impl)42 void SetUpdateEventInfoImpl(const std::function<void(BaseEventInfo&)>& impl) 43 { 44 updateEventInfoimpl_ = impl; 45 } 46 47 private: 48 std::function<void(BaseEventInfo&)> updateEventInfoimpl_; 49 }; 50 51 class ACE_EXPORT InspectorComposedComponent : public ComposedComponent { 52 DECLARE_ACE_TYPE(InspectorComposedComponent, ComposedComponent); 53 54 public: 55 using ComposedComponent::ComposedComponent; 56 ~InspectorComposedComponent() override = default; 57 58 RefPtr<Element> CreateElement() override; IsInspector()59 bool IsInspector() override 60 { 61 return true; 62 } 63 void AddElementToAccessibilityManager(const RefPtr<ComposedElement>& composedElement); 64 SetAccessibilityGroup(bool accessibilitygroup)65 void SetAccessibilityGroup(bool accessibilitygroup) 66 { 67 accessibilitygroup_ = accessibilitygroup; 68 } 69 SetAccessibilitytext(const std::string & accessibilitytext)70 void SetAccessibilitytext(const std::string& accessibilitytext) 71 { 72 accessibilitytext_ = accessibilitytext; 73 } 74 SetAccessibilityDescription(const std::string & accessibilitydescription)75 void SetAccessibilityDescription(const std::string& accessibilitydescription) 76 { 77 accessibilitydescription_ = accessibilitydescription; 78 } 79 SetAccessibilityImportance(const std::string & accessibilityimportance)80 void SetAccessibilityImportance(const std::string& accessibilityimportance) 81 { 82 accessibilityimportance_ = accessibilityimportance; 83 } 84 SetAccessibilityEvent(const EventMarker & accessibilityEvent)85 void SetAccessibilityEvent(const EventMarker& accessibilityEvent) 86 { 87 accessibilityEvent_ = accessibilityEvent; 88 } 89 IsAccessibilityGroup()90 bool IsAccessibilityGroup() const 91 { 92 return accessibilitygroup_; 93 } 94 GetAccessibilityText()95 const std::string& GetAccessibilityText() const 96 { 97 return accessibilitytext_; 98 } 99 GetAccessibilityDescription()100 const std::string& GetAccessibilityDescription() const 101 { 102 return accessibilitydescription_; 103 } 104 GetAccessibilityImportance()105 const std::string& GetAccessibilityImportance() const 106 { 107 return accessibilityimportance_; 108 } 109 GetAccessibilityEvent()110 const EventMarker& GetAccessibilityEvent() const 111 { 112 return accessibilityEvent_; 113 } 114 GetInspectorFunctionImpl()115 const RefPtr<InspectorFunctionImpl>& GetInspectorFunctionImpl() const 116 { 117 return inspectorFunctionImpl_; 118 } 119 SetDebugLine(std::string debugLine)120 void SetDebugLine(std::string debugLine) 121 { 122 debugLine_ = debugLine; 123 } 124 GetDebugLine()125 std::string GetDebugLine() 126 { 127 return debugLine_; 128 } 129 SetViewId(std::string viewId)130 void SetViewId(std::string viewId) 131 { 132 viewId_ = viewId; 133 } 134 135 static bool HasInspectorFinished(std::string tag); 136 static std::string GetEtsTag(const std::string& tag); 137 static RefPtr<AccessibilityManager> GetAccessibilityManager(); 138 static RefPtr<AccessibilityNode> CreateAccessibilityNode( 139 const std::string& tag, int32_t nodeId, int32_t parentNodeId, int32_t itemIndex); 140 static std::string GenerateId(); 141 142 private: 143 bool accessibilitygroup_ = false; 144 std::string accessibilitytext_ = ""; 145 std::string accessibilitydescription_ = ""; 146 std::string accessibilityimportance_ = ""; 147 EventMarker accessibilityEvent_; 148 RefPtr<InspectorFunctionImpl> inspectorFunctionImpl_ = MakeRefPtr<InspectorFunctionImpl>(); 149 static thread_local int32_t composedElementId_; 150 151 std::string debugLine_; 152 std::string viewId_; 153 }; 154 155 } // namespace OHOS::Ace::V2 156 157 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_INSPECTOR_COMPOSED_COMPONENT_H 158