1 /* 2 * Copyright (c) 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_NG_BASE_CUSTOM_NODE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_BASE_CUSTOM_NODE_H 18 19 #include <functional> 20 #include <string> 21 22 #include "base/utils/macros.h" 23 #include "core/components_ng/base/frame_node.h" 24 #include "core/components_ng/base/inspector_filter.h" 25 #include "core/components_ng/pattern/custom/custom_node_base.h" 26 #include "core/components_ng/pattern/custom/custom_node_pattern.h" 27 28 namespace OHOS::Ace::NG { 29 class InspectorFilter; 30 31 // CustomNode is the frame node of @Component struct. 32 class ACE_EXPORT CustomNode : public UINode, public CustomNodeBase { 33 DECLARE_ACE_TYPE(CustomNode, UINode, CustomNodeBase); 34 35 public: 36 static RefPtr<CustomNode> CreateCustomNode(int32_t nodeId, const std::string& viewKey); 37 38 CustomNode(int32_t nodeId, const std::string& viewKey); 39 ~CustomNode() override = default; 40 41 void AdjustLayoutWrapperTree(const RefPtr<LayoutWrapperNode>& parent, bool forceMeasure, bool forceLayout) override; 42 43 RefPtr<LayoutWrapperNode> CreateLayoutWrapper(bool forceMeasure = false, bool forceLayout = false) override; 44 IsAtomicNode()45 bool IsAtomicNode() const override 46 { 47 return true; 48 } 49 SetRenderFunction(const RenderFunction & renderFunction)50 void SetRenderFunction(const RenderFunction& renderFunction) override 51 { 52 renderFunction_ = renderFunction; 53 } 54 55 void Build(std::shared_ptr<std::list<ExtraInfo>> extraInfos) override; 56 FrameCount()57 int32_t FrameCount() const override 58 { 59 return 1; 60 } 61 CurrentFrameCount()62 int32_t CurrentFrameCount() const override 63 { 64 return 1; 65 } 66 67 void Render(); 68 SetCompleteReloadFunc(RenderFunction && func)69 void SetCompleteReloadFunc(RenderFunction&& func) override 70 { 71 completeReloadFunc_ = std::move(func); 72 } 73 ACE_FORCE_EXPORT void FlushReload(); 74 ToJsonValue(std::unique_ptr<JsonValue> & json,const InspectorFilter & filter)75 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override 76 { 77 /* no fixed attr below, just return */ 78 if (filter.IsFastFilter()) { 79 return; 80 } 81 json->PutExtAttr("viewKey", viewKey_.c_str(), filter); 82 } 83 FromJson(const std::unique_ptr<JsonValue> & json)84 void FromJson(const std::unique_ptr<JsonValue>& json) override {} 85 GetCustomTag()86 std::string GetCustomTag() override 87 { 88 return jsViewName_; 89 } 90 91 void MarkNeedSyncRenderTree(bool needRebuild = false) override; 92 RefPtr<UINode> GetFrameChildByIndex(uint32_t index, bool needBuild, bool isCache = false, 93 bool addToRenderTree = false) override; 94 bool RenderCustomChild(int64_t deadline) override; 95 void SetJSViewActive(bool active, bool isLazyForEachNode = false) override; 96 GetJsActive()97 bool GetJsActive() 98 { 99 return prevJsActive_; 100 } 101 SetJsActive(bool active)102 void SetJsActive(bool active) 103 { 104 prevJsActive_ = active; 105 } 106 SetExtraInfos(const std::list<ExtraInfo> extraInfos)107 void SetExtraInfos(const std::list<ExtraInfo> extraInfos) 108 { 109 extraInfos_ = std::move(extraInfos); 110 } 111 GetExtraInfos()112 const std::list<ExtraInfo> GetExtraInfos() const 113 { 114 return extraInfos_; 115 } 116 117 void DoSetActiveChildRange( 118 int32_t start, int32_t end, int32_t cacheStart, int32_t cacheEnd, bool showCache = false) override; 119 GetNavigationNode()120 const WeakPtr<UINode>& GetNavigationNode() const 121 { 122 return navigationNode_; 123 } 124 SetNavigationNode(const WeakPtr<UINode> & navigationNode)125 void SetNavigationNode(const WeakPtr<UINode>& navigationNode) 126 { 127 navigationNode_ = navigationNode; 128 } 129 130 std::unique_ptr<JsonValue> GetStateInspectorInfo(); 131 132 void FireCustomDisappear() override; 133 134 private: 135 std::string viewKey_; 136 RenderFunction renderFunction_; 137 RenderFunction completeReloadFunc_; 138 bool needMarkParent_ = true; 139 bool prevJsActive_ = true; 140 std::list<ExtraInfo> extraInfos_; 141 WeakPtr<UINode> navigationNode_; 142 }; 143 } // namespace OHOS::Ace::NG 144 145 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_BASE_CUSTOM_NODE_H 146