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 120 #if defined(PREVIEW) SetDebugLine(std::string debugLine)121 void SetDebugLine(std::string debugLine) 122 { 123 debugLine_ = debugLine; 124 } 125 GetDebugLine()126 std::string GetDebugLine() 127 { 128 return debugLine_; 129 } 130 SetViewId(std::string viewId)131 void SetViewId(std::string viewId) 132 { 133 viewId_ = viewId; 134 } 135 #endif 136 137 static bool HasInspectorFinished(std::string tag); 138 static std::string GetEtsTag(const std::string& tag); 139 static RefPtr<AccessibilityManager> GetAccessibilityManager(); 140 static RefPtr<AccessibilityNode> CreateAccessibilityNode( 141 const std::string& tag, int32_t nodeId, int32_t parentNodeId, int32_t itemIndex); 142 static std::string GenerateId(); 143 144 private: 145 bool accessibilitygroup_ = false; 146 std::string accessibilitytext_ = ""; 147 std::string accessibilitydescription_ = ""; 148 std::string accessibilityimportance_ = ""; 149 EventMarker accessibilityEvent_; 150 RefPtr<InspectorFunctionImpl> inspectorFunctionImpl_ = MakeRefPtr<InspectorFunctionImpl>(); 151 static thread_local int32_t composedElementId_; 152 153 #if defined(PREVIEW) 154 std::string debugLine_; 155 std::string viewId_; 156 #endif 157 }; 158 159 } // namespace OHOS::Ace::V2 160 161 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_INSPECTOR_COMPOSED_COMPONENT_H 162