1 /* 2 * Copyright (c) 2024 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_COMMON_PIPELINE_NG_NAVIGATION_MANAGER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_PIPELINE_NG_NAVIGATION_MANAGER_H 18 19 #include <cstdint> 20 #include <functional> 21 #include <map> 22 23 #include "base/json/json_util.h" 24 #include "base/memory/ace_type.h" 25 #include "core/components_ng/base/frame_node.h" 26 27 namespace OHOS::Ace::NG { 28 class NavigationStack; 29 struct NavigationInfo { 30 std::string navigationId; 31 WeakPtr<NavigationStack> pathStack; 32 33 NavigationInfo() = default; NavigationInfoNavigationInfo34 NavigationInfo(const std::string& id, const WeakPtr<NavigationStack>& navigationStack) 35 : navigationId(std::move(id)), pathStack(navigationStack) 36 {} 37 }; 38 39 struct NavdestinationRecoveryInfo { 40 std::string name; 41 std::string param; 42 // mode of navdestination, 0 for standard page and 1 for dialog page 43 int32_t mode; 44 NavdestinationRecoveryInfoNavdestinationRecoveryInfo45 NavdestinationRecoveryInfo(const std::string& name, const std::string& param, int32_t mode) 46 : name(std::move(name)), param(std::move(param)), mode(mode) {} 47 }; 48 49 class NavigationManager : public virtual AceType { 50 DECLARE_ACE_TYPE(NavigationManager, AceType); 51 public: 52 using DumpLogDepth = int; 53 using DumpCallback = std::function<void(DumpLogDepth)>; NavigationManager()54 NavigationManager() 55 { 56 #ifdef PREVIEW 57 hasCacheNavigationNodeEnable_ = false; 58 #else 59 hasCacheNavigationNodeEnable_ = SystemProperties::GetCacheNavigationNodeEnable(); 60 #endif 61 } 62 ~NavigationManager() = default; 63 SetPipelineContext(const WeakPtr<PipelineContext> & pipeline)64 void SetPipelineContext(const WeakPtr<PipelineContext>& pipeline) 65 { 66 pipeline_ = pipeline; 67 } 68 69 void AddNavigationDumpCallback(int32_t nodeId, int32_t depth, const DumpCallback& callback); 70 void RemoveNavigationDumpCallback(int32_t nodeId, int32_t depth); 71 72 void OnDumpInfo(); 73 AddNavigationUpdateCallback(std::function<void ()> callback)74 void AddNavigationUpdateCallback(std::function<void()> callback) 75 { 76 updateCallbacks_.emplace_back(callback); 77 } 78 79 void FireNavigationUpdateCallback(); 80 std::shared_ptr<NavigationInfo> GetNavigationInfo(const RefPtr<AceType>& node); 81 IsInteractive()82 bool IsInteractive() const 83 { 84 return isInteractive_; 85 } 86 SetInteractive(int32_t frameNodeId)87 void SetInteractive(int32_t frameNodeId) 88 { 89 isInteractive_ = true; 90 interactiveAnimationId_ = frameNodeId; 91 } 92 FinishInteractiveAnimation()93 void FinishInteractiveAnimation() 94 { 95 isInteractive_ = false; 96 } 97 SetNodeAddAnimation(bool isNodeAddAnimation)98 void SetNodeAddAnimation(bool isNodeAddAnimation) 99 { 100 isNodeAddAnimation_ = isNodeAddAnimation; 101 } 102 SetCurNodeAnimationCached(bool curNodeAnimationCached)103 void SetCurNodeAnimationCached(bool curNodeAnimationCached) 104 { 105 curNodeAnimationCached_ = curNodeAnimationCached; 106 } 107 SetCurrentNodeNeverSet(bool currentNodeNeverSet)108 void SetCurrentNodeNeverSet(bool currentNodeNeverSet) 109 { 110 currentNodeNeverSet_ = currentNodeNeverSet; 111 } 112 SetPreNodeNeverSet(bool preNodeNeverSet)113 void SetPreNodeNeverSet(bool preNodeNeverSet) 114 { 115 preNodeNeverSet_ = preNodeNeverSet; 116 } 117 SetPreNodeAnimationCached(bool preNodeAnimationCached)118 void SetPreNodeAnimationCached(bool preNodeAnimationCached) 119 { 120 preNodeAnimationCached_ = preNodeAnimationCached; 121 } 122 SetNavNodeInTransition(const RefPtr<FrameNode> & curNode,const RefPtr<FrameNode> & preNode)123 void SetNavNodeInTransition(const RefPtr<FrameNode>& curNode, const RefPtr<FrameNode>& preNode) 124 { 125 curNavNode_ = curNode; 126 preNavNode_ = preNode; 127 } 128 SetIsNavigationOnAnimation(bool isInAnimation)129 void SetIsNavigationOnAnimation(bool isInAnimation) 130 { 131 isInAnimation_ = isInAnimation; 132 } 133 IsNavigationInAnimation()134 bool IsNavigationInAnimation() const 135 { 136 return isInAnimation_; 137 } 138 HasCacheNavigationNodeEnable()139 bool HasCacheNavigationNodeEnable() 140 { 141 return hasCacheNavigationNodeEnable_; 142 } 143 144 void UpdateAnimationCachedRenderGroup(const RefPtr<FrameNode>& curNode, bool isSet); 145 void UpdatePreNavNodeRenderGroupProperty(); 146 void ResetCurNavNodeRenderGroupProperty(); 147 void UpdateCurNavNodeRenderGroupProperty(); 148 void CacheNavigationNodeAnimation(); 149 bool CheckNodeNeedCache(const RefPtr<FrameNode>& node); 150 RefPtr<FrameNode> GetNavDestContentFrameNode(const RefPtr<FrameNode>& node); 151 bool AddInteractiveAnimation(const std::function<void()>& addCallback); 152 153 bool AddRecoverableNavigation(std::string id, RefPtr<AceType> navigationNode); 154 std::unique_ptr<JsonValue> GetNavigationJsonInfo(); 155 void StorageNavigationRecoveryInfo(std::unique_ptr<JsonValue> allNavigationInfo); 156 const std::vector<NavdestinationRecoveryInfo> GetNavigationRecoveryInfo(std::string navigationId); 157 158 void AddNavigation(int32_t pageId, int32_t navigationId); 159 160 void RemoveNavigation(int32_t pageId); 161 162 std::vector<int32_t> FindNavigationInTargetParent(int32_t targetId); 163 164 void FireNavigationLifecycle(const RefPtr<UINode>& node, int32_t lifecycle, int32_t reason); 165 166 void FireOverlayLifecycle(const RefPtr<UINode>& node, int32_t lifecycle, int32_t reason); 167 168 void FireLowerLayerLifecycle(const RefPtr<UINode>& node, int lifecycle, int32_t reason); 169 170 void FireSubWindowLifecycle(const RefPtr<UINode>& node, int32_t lifecycle, int32_t reason); 171 172 private: 173 struct DumpMapKey { 174 int32_t nodeId; 175 int32_t depth; 176 DumpMapKeyDumpMapKey177 DumpMapKey(int32_t n, int32_t d) : nodeId(n), depth(d) {} 178 bool operator< (const DumpMapKey& o) const 179 { 180 if (depth != o.depth) { 181 return depth < o.depth; 182 } 183 return nodeId < o.nodeId; 184 } 185 }; 186 187 bool IsOverlayValid(const RefPtr<UINode>& frameNode); 188 189 bool IsCustomDialogValid(const RefPtr<UINode>& node); 190 191 std::unordered_map<std::string, WeakPtr<AceType>> recoverableNavigationMap_; 192 std::unordered_map<std::string, std::vector<NavdestinationRecoveryInfo>> navigationRecoveryInfo_; 193 std::unordered_map<int32_t, std::vector<int32_t>> navigationMaps_; 194 std::map<DumpMapKey, DumpCallback> dumpMap_; 195 std::vector<std::function<void()>> updateCallbacks_; 196 bool isInteractive_ = false; 197 198 RefPtr<FrameNode> curNavNode_; 199 RefPtr<FrameNode> preNavNode_; 200 bool currentNodeNeverSet_ = true; 201 bool curNodeAnimationCached_ = false; 202 bool preNodeNeverSet_ = true; 203 bool preNodeAnimationCached_ = false; 204 bool isInAnimation_ = false; 205 bool isNodeAddAnimation_ = false; 206 bool hasCacheNavigationNodeEnable_ = true; 207 int32_t interactiveAnimationId_ = -1; 208 209 WeakPtr<PipelineContext> pipeline_; 210 }; 211 } // namespace OHOS::Ace::NG 212 213 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_PIPELINE_NG_NAVIGATION_MANAGER_H 214