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_FORCE_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 CustomNode(int32_t nodeId,const std::string & viewKey)38 CustomNode(int32_t nodeId, const std::string& viewKey) 39 : UINode(V2::JS_VIEW_ETS_TAG, nodeId, MakeRefPtr<CustomNodePattern>()), viewKey_(viewKey) {} ~CustomNode()40 ~CustomNode() override 41 { 42 ACE_SCOPED_TRACE("CustomNode:Destroy [%d]", GetId()); 43 } 44 45 void AdjustLayoutWrapperTree(const RefPtr<LayoutWrapperNode>& parent, bool forceMeasure, bool forceLayout) override; 46 47 RefPtr<LayoutWrapperNode> CreateLayoutWrapper(bool forceMeasure = false, bool forceLayout = false) override; 48 IsAtomicNode()49 bool IsAtomicNode() const override 50 { 51 return true; 52 } 53 IsSyntaxNode()54 bool IsSyntaxNode() const override 55 { 56 return true; 57 } 58 SetRenderFunction(const RenderFunction & renderFunction)59 void SetRenderFunction(const RenderFunction& renderFunction) override 60 { 61 renderFunction_ = renderFunction; 62 } 63 64 void Build(std::shared_ptr<std::list<ExtraInfo>> extraInfos) override; 65 FrameCount()66 int32_t FrameCount() const override 67 { 68 return 1; 69 } 70 CurrentFrameCount()71 int32_t CurrentFrameCount() const override 72 { 73 return 1; 74 } 75 76 bool Render(int64_t deadline = 0); 77 SetCompleteReloadFunc(RenderFunction && func)78 void SetCompleteReloadFunc(RenderFunction&& func) override 79 { 80 completeReloadFunc_ = std::move(func); 81 } 82 ACE_FORCE_EXPORT void FlushReload(); 83 ToJsonValue(std::unique_ptr<JsonValue> & json,const InspectorFilter & filter)84 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override 85 { 86 /* no fixed attr below, just return */ 87 if (filter.IsFastFilter()) { 88 return; 89 } 90 json->PutExtAttr("viewKey", viewKey_.c_str(), filter); 91 } 92 FromJson(const std::unique_ptr<JsonValue> & json)93 void FromJson(const std::unique_ptr<JsonValue>& json) override {} 94 GetCustomTag()95 std::string GetCustomTag() override 96 { 97 return jsViewName_; 98 } 99 100 void MarkNeedSyncRenderTree(bool needRebuild = false) override; 101 RefPtr<UINode> GetFrameChildByIndex(uint32_t index, bool needBuild, bool isCache = false, 102 bool addToRenderTree = false) override; 103 bool RenderCustomChild(int64_t deadline) override; 104 void SetJSViewActive(bool active, bool isLazyForEachNode = false, bool isReuse = false) override; 105 void OnDestroyingStateChange(bool isDestroying, bool cleanStatus) override; 106 GetJsActive()107 bool GetJsActive() 108 { 109 return prevJsActive_; 110 } 111 SetJsActive(bool active)112 void SetJsActive(bool active) 113 { 114 prevJsActive_ = active; 115 } 116 SetExtraInfos(const std::list<ExtraInfo> extraInfos)117 void SetExtraInfos(const std::list<ExtraInfo> extraInfos) 118 { 119 extraInfos_ = std::move(extraInfos); 120 } 121 GetExtraInfos()122 const std::list<ExtraInfo> GetExtraInfos() const 123 { 124 return extraInfos_; 125 } 126 127 void DoSetActiveChildRange( 128 int32_t start, int32_t end, int32_t cacheStart, int32_t cacheEnd, bool showCache = false) override; 129 130 void FireRecycleRenderFunc() override; 131 GetNavigationNode()132 const WeakPtr<UINode>& GetNavigationNode() const 133 { 134 return navigationNode_; 135 } 136 SetNavigationNode(const WeakPtr<UINode> & navigationNode)137 void SetNavigationNode(const WeakPtr<UINode>& navigationNode) 138 { 139 navigationNode_ = navigationNode; 140 } 141 142 std::unique_ptr<JsonValue> GetStateInspectorInfo(); 143 144 void FireCustomDisappear() override; 145 146 // called for DFX 147 void DumpInfo() override; 148 private: 149 // for DFX 150 void DumpComponentInfo(std::unique_ptr<JsonValue>& componentInfo); 151 void DumpDecoratorInfo(std::unique_ptr<JsonValue>& decoratorInfo); 152 153 RefPtr<CustomNode> FindParentCustomNode() const; 154 155 std::string viewKey_; 156 RenderFunction renderFunction_; 157 RenderFunction completeReloadFunc_; 158 bool needMarkParent_ = true; 159 bool prevJsActive_ = true; 160 std::list<ExtraInfo> extraInfos_; 161 WeakPtr<UINode> navigationNode_; 162 std::unique_ptr<ViewStackProcessor> prebuildViewStackProcessor_; 163 int32_t prebuildFrameRounds_ = 0; 164 }; 165 } // namespace OHOS::Ace::NG 166 167 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_BASE_CUSTOM_NODE_H 168