1 /* 2 * Copyright (c) 2021-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_ADAPTER_PREVIEW_INSPECTOR_JS_INSPECTOR_MANAGER_H 17 #define FOUNDATION_ACE_ADAPTER_PREVIEW_INSPECTOR_JS_INSPECTOR_MANAGER_H 18 19 #include <cstdint> 20 #include <unordered_map> 21 #include <unordered_set> 22 #include <vector> 23 24 #include "core/components_ng/base/group_node.h" 25 #include "core/components_ng/base/ui_node.h" 26 #include "core/components_v2/inspector/inspector_composed_element.h" 27 #include "core/pipeline/pipeline_context.h" 28 #include "frameworks/bridge/common/accessibility/accessibility_node_manager.h" 29 30 namespace OHOS::Ace::Framework { 31 32 class JsInspectorManager : public AccessibilityNodeManager { 33 DECLARE_ACE_TYPE(JsInspectorManager, AccessibilityNodeManager); 34 35 public: 36 JsInspectorManager() = default; 37 ~JsInspectorManager() override = default; 38 39 void InitializeCallback() override; 40 41 private: 42 void AssembleJSONTree(std::string& jsonStr); 43 std::unique_ptr<JsonValue> GetChildrenJson(RefPtr<AccessibilityNode> node); 44 std::unique_ptr<JsonValue> GetChildJson(RefPtr<AccessibilityNode> node); 45 void AssembleDefaultJSONTree(std::string& jsonStr); 46 47 bool OperateComponent(const std::string& attrsJson); 48 bool OperateRootComponent(RefPtr<Component> newComponent); 49 bool OperateGeneralComponent( 50 int32_t parentID, int32_t slot, std::string& operateType, RefPtr<Component> newComponent); 51 bool OperateGeneralUINode(RefPtr<NG::UINode> parent, int32_t slot, RefPtr<NG::UINode> newChild); 52 RefPtr<Component> GetNewComponentWithJsCode(const std::unique_ptr<JsonValue>& root); 53 RefPtr<NG::UINode> GetNewFrameNodeWithJsCode(const std::unique_ptr<JsonValue>& root); 54 RefPtr<V2::InspectorComposedElement> GetInspectorElementById(NodeId nodeId); 55 WeakPtr<Element> GetRootElement(); 56 const RefPtr<NG::UINode> GetRootUINode(); 57 void GetAttrsAndStyles(std::unique_ptr<JsonValue>& jsonNode, const RefPtr<AccessibilityNode>& node); 58 void GetAttrsAndStylesV2(std::unique_ptr<JsonValue>& jsonNode, const RefPtr<AccessibilityNode>& node); 59 std::string UpdateNodeRectStrInfo(const RefPtr<AccessibilityNode> node); 60 std::string UpdateNodeRectStrInfoV2(const RefPtr<AccessibilityNode> node); 61 std::string ConvertStrToPropertyType(std::string& typeValue); 62 std::string ConvertPseudoClassStyle(const std::string pseudoClassValue); 63 Rect deviceRect_; 64 std::unordered_map<int32_t, int32_t> slots_; 65 std::unordered_map<int32_t, WeakPtr<NG::UINode>> parents_; 66 }; 67 68 } // namespace OHOS::Ace::Framework 69 70 #endif // FOUNDATION_ACE_ADAPTER_PREVIEW_INSPECTOR_JS_INSPECTOR_MANAGER_H 71