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_COMPONENTS_NG_PATTERNS_NAVROUTER_NAVDESTINATION_CONTEXT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVROUTER_NAVDESTINATION_CONTEXT_H 18 19 #include <string> 20 21 #include "base/memory/ace_type.h" 22 #include "core/components_ng/pattern/navigation/navigation_stack.h" 23 24 namespace OHOS::Ace::NG { 25 class NavigationStack; 26 class NavDestinationPattern; 27 class NavPathInfo : public virtual AceType { 28 DECLARE_ACE_TYPE(NavPathInfo, AceType); 29 public: 30 NavPathInfo() = default; NavPathInfo(const std::string & name)31 explicit NavPathInfo(const std::string& name) : name_(name) {} NavPathInfo(const std::string & name,bool isEntry)32 NavPathInfo(const std::string& name, bool isEntry) : name_(name), isEntry_(isEntry) {} 33 virtual ~NavPathInfo() = default; 34 SetName(const std::string & name)35 void SetName(const std::string& name) 36 { 37 name_ = name; 38 } 39 GetName()40 std::string GetName() const 41 { 42 return name_; 43 } 44 GetParamObj()45 virtual napi_value GetParamObj() const 46 { 47 return nullptr; 48 } 49 GetIsEntry()50 bool GetIsEntry() const 51 { 52 return isEntry_; 53 } 54 SetIsEntry(bool isEntry)55 void SetIsEntry(bool isEntry) 56 { 57 isEntry_ = isEntry; 58 } 59 UpdateNavPathInfo(const RefPtr<NG::NavPathInfo> & info)60 virtual void UpdateNavPathInfo(const RefPtr<NG::NavPathInfo>& info) 61 { 62 if (!info) { 63 return; 64 } 65 name_ = info->GetName(); 66 isEntry_ = info->GetIsEntry(); 67 } 68 OpenScope()69 virtual void OpenScope() {} CloseScope()70 virtual void CloseScope() {} 71 72 protected: 73 std::string name_; 74 bool isEntry_ = false; 75 }; 76 77 class NavDestinationContext : public virtual AceType { 78 DECLARE_ACE_TYPE(NavDestinationContext, AceType); 79 public: 80 NavDestinationContext() = default; 81 virtual ~NavDestinationContext() = default; 82 SetNavPathInfo(RefPtr<NavPathInfo> info)83 void SetNavPathInfo(RefPtr<NavPathInfo> info) 84 { 85 pathInfo_ = info; 86 } 87 GetNavPathInfo()88 RefPtr<NavPathInfo> GetNavPathInfo() const 89 { 90 return pathInfo_; 91 } 92 SetNavigationStack(WeakPtr<NavigationStack> stack)93 void SetNavigationStack(WeakPtr<NavigationStack> stack) 94 { 95 navigationStack_ = stack; 96 } 97 GetNavigationStack()98 WeakPtr<NavigationStack> GetNavigationStack() const 99 { 100 return navigationStack_; 101 } 102 GetIndex()103 int32_t GetIndex() const 104 { 105 return index_; 106 } 107 SetIndex(int32_t index)108 void SetIndex(int32_t index) 109 { 110 index_ = index; 111 } 112 GetPreIndex()113 int32_t GetPreIndex() const 114 { 115 return preIndex_; 116 } 117 SetPreIndex(int32_t index)118 void SetPreIndex(int32_t index) 119 { 120 preIndex_ = index; 121 } 122 GetNavDestinationId()123 uint64_t GetNavDestinationId() const 124 { 125 return navDestinationId_; 126 } 127 SetNavDestinationId(uint64_t id)128 void SetNavDestinationId(uint64_t id) 129 { 130 navDestinationId_ = id; 131 } 132 SetIsEmpty(bool isEmpty)133 void SetIsEmpty(bool isEmpty) 134 { 135 isEmpty_ = isEmpty; 136 } 137 GetIsEmpty()138 bool GetIsEmpty() const 139 { 140 return isEmpty_; 141 } 142 SetMode(NavDestinationMode mode)143 void SetMode(NavDestinationMode mode) 144 { 145 mode_ = mode; 146 } 147 GetMode()148 NavDestinationMode GetMode() const 149 { 150 return mode_; 151 } 152 SetUniqueId(int32_t uniqueId)153 void SetUniqueId(int32_t uniqueId) 154 { 155 uniqueId_ = uniqueId; 156 } 157 GetUniqueId()158 int32_t GetUniqueId() const 159 { 160 return uniqueId_; 161 } 162 163 void SetNavDestinationPattern(const WeakPtr<NavDestinationPattern>& pattern); 164 RefPtr<NavDestinationPattern> GetNavDestinationPattern() const; 165 166 protected: 167 int32_t index_ = -1; 168 int32_t preIndex_ = -1; 169 uint64_t navDestinationId_ = 0; 170 NavDestinationMode mode_; 171 RefPtr<NavPathInfo> pathInfo_; 172 bool isEmpty_ = false; 173 WeakPtr<NavigationStack> navigationStack_; 174 WeakPtr<NavDestinationPattern> navDestinationPattern_; 175 int32_t uniqueId_ = -1; 176 }; 177 } // namespace OHOS::Ace::NG 178 179 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVROUTER_NAVDESTINATION_CONTEXT_H 180