• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/memory/ace_type.h"
24 
25 namespace OHOS::Ace::NG {
26 class NavigationStack;
27 struct NavigationInfo {
28     std::string navigationId;
29     WeakPtr<NavigationStack> pathStack;
30 
31     NavigationInfo() = default;
NavigationInfoNavigationInfo32     NavigationInfo(const std::string& id, const WeakPtr<NavigationStack>& navigationStack)
33         : navigationId(std::move(id)), pathStack(navigationStack)
34     {}
35 };
36 class NavigationManager : public virtual AceType {
37     DECLARE_ACE_TYPE(NavigationManager, AceType);
38 public:
39     using DumpLogDepth = int;
40     using DumpCallback = std::function<void(DumpLogDepth)>;
41     NavigationManager() = default;
42     ~NavigationManager() = default;
43 
44     void AddNavigationDumpCallback(int32_t nodeId, int32_t depth, const DumpCallback& callback);
45     void RemoveNavigationDumpCallback(int32_t nodeId, int32_t depth);
46 
47     void OnDumpInfo();
48 
AddNavigationUpdateCallback(std::function<void ()> callback)49     void AddNavigationUpdateCallback(std::function<void()> callback)
50     {
51         updateCallbacks_.emplace_back(callback);
52     }
53 
54     void FireNavigationUpdateCallback();
55     std::shared_ptr<NavigationInfo> GetNavigationInfo(const RefPtr<AceType>& node);
56 
IsInteractive()57     bool IsInteractive() const
58     {
59         return isInteractive_;
60     }
61 
SetInteractive(int32_t frameNodeId)62     void SetInteractive(int32_t frameNodeId)
63     {
64         isInteractive_ = true;
65         interactiveAnimationId_ = frameNodeId;
66     }
67 
FinishInteractiveAnimation()68     void FinishInteractiveAnimation()
69     {
70         isInteractive_ = false;
71     }
72 
73     bool AddInteractiveAnimation(const std::function<void()>& addCallback);
74 
75 private:
76     struct DumpMapKey {
77         int32_t nodeId;
78         int32_t depth;
79 
DumpMapKeyDumpMapKey80         DumpMapKey(int32_t n, int32_t d) : nodeId(n), depth(d) {}
81         bool operator< (const DumpMapKey& o) const
82         {
83             if (depth != o.depth) {
84                 return depth < o.depth;
85             }
86             return nodeId < o.nodeId;
87         }
88     };
89     std::map<DumpMapKey, DumpCallback> dumpMap_;
90     std::vector<std::function<void()>> updateCallbacks_;
91     bool isInteractive_ = false;
92     int32_t interactiveAnimationId_ = -1;
93 };
94 } // namespace OHOS::Ace::NG
95 
96 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_PIPELINE_NG_NAVIGATION_MANAGER_H
97