• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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_STAGE_STAGE_MANAGER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_STAGE_STAGE_MANAGER_H
18 
19 #include <cstdint>
20 
21 #include "base/memory/ace_type.h"
22 #include "base/memory/referenced.h"
23 #include "base/utils/noncopyable.h"
24 #include "core/animation/page_transition_common.h"
25 #include "core/components_ng/base/ui_node.h"
26 #include "core/components_ng/pattern/stage/stage_pattern.h"
27 #include "core/components_ng/pattern/stage/page_transition_effect.h"
28 
29 namespace OHOS::Ace::NG {
30 class FrameNode;
31 class OverlayManager;
32 
33 // StageManager is the base class for root render node to perform page switch.
34 class ACE_FORCE_EXPORT StageManager : public virtual AceType {
35     DECLARE_ACE_TYPE(StageManager, AceType);
36 
37 public:
38     explicit StageManager(const RefPtr<FrameNode>& stage);
39     ~StageManager() override = default;
40 
41     // PushUrl and ReplaceUrl both use PushPage function
42     virtual bool PushPage(const RefPtr<FrameNode>& node, bool needHideLast = true, bool needTransition = true);
43     virtual bool InsertPage(const RefPtr<FrameNode>& node, bool bellowTopOrBottom);
44     virtual bool PopPage(const RefPtr<FrameNode>& inPageNode, bool needShowNext = true, bool needTransition = true);
45     virtual bool PopPageToIndex(int32_t index, bool needShowNext = true, bool needTransition = true);
46     virtual bool CleanPageStack();
47     virtual bool MovePageToFront(const RefPtr<FrameNode>& node, bool needHideLast = true, bool needTransition = true);
48 
49     virtual void StartTransition(const RefPtr<FrameNode>& srcPage, const RefPtr<FrameNode>& destPage, RouteType type);
50 
51     void PageChangeCloseKeyboard();
52 
53     static void FirePageHide(const RefPtr<UINode>& node, PageTransitionType transitionType = PageTransitionType::NONE);
54     static void FirePageShow(const RefPtr<UINode>& node, PageTransitionType transitionType = PageTransitionType::NONE,
55         bool needFocus = true);
56 
57     virtual RefPtr<FrameNode> GetLastPage() const;
58     RefPtr<FrameNode> GetPageById(int32_t pageId);
GetStageNode()59     const RefPtr<FrameNode> GetStageNode() const
60     {
61         return stageNode_;
62     }
63 
64     void ReloadStage();
65 
66     virtual RefPtr<FrameNode> GetLastPageWithTransition() const;
67     virtual RefPtr<FrameNode> GetPrevPageWithTransition() const;
68 
GetFocusPage()69     virtual RefPtr<FrameNode> GetFocusPage() const
70     {
71         return nullptr;
72     }
73 
SetStageInTrasition(bool stageInTrasition)74     void SetStageInTrasition (bool stageInTrasition) {
75         stageInTrasition_ = stageInTrasition;
76     }
77 
78 #if defined(ENABLE_SPLIT_MODE)
IsNewPageReplacing()79     bool IsNewPageReplacing() const
80     {
81         return isNewPageReplacing_;
82     }
83 
SetIsNewPageReplacing(bool replacing)84     void SetIsNewPageReplacing(bool replacing)
85     {
86         isNewPageReplacing_ = replacing;
87     }
88 #endif
89 
90     virtual void SyncPageSafeArea(bool keyboardSafeArea);
91 
92     virtual bool CheckPageFocus();
93 
SetSrcPage(const RefPtr<FrameNode> & pageNode)94     void SetSrcPage(const RefPtr<FrameNode>& pageNode)
95     {
96         srcPageNode_ = pageNode;
97     }
98 
AddAnimation(const std::shared_ptr<AnimationUtils::Animation> & animation,bool isPush)99     void AddAnimation(const std::shared_ptr<AnimationUtils::Animation>& animation, bool isPush)
100     {
101         if (isPush) {
102             pushAnimations_.emplace_back(animation);
103             return;
104         }
105         popAnimations_.emplace_back(animation);
106     }
107 
108     void AbortAnimation();
109 
GetAnimationId()110     int32_t GetAnimationId() const
111     {
112         return animationId_;
113     }
114 
SetGetPagePathCallback(std::function<std::string (const std::string & url)> && callback)115     void SetGetPagePathCallback(std::function<std::string(const std::string& url)>&& callback)
116     {
117         getPagePathCallback_ = std::move(callback);
118     }
119     std::vector<std::string> GetTopPagePaths() const;
120     virtual std::vector<RefPtr<FrameNode>> GetTopPagesWithTransition() const;
IsSplitMode()121     virtual bool IsSplitMode() const
122     {
123         return false;
124     }
125 
126 protected:
127     // ace performance check
128     void PerformanceCheck(const RefPtr<FrameNode>& pageNode, int64_t vsyncTimeout, std::string path);
129     void FireAutoSave(const RefPtr<FrameNode>& outPageNode, const RefPtr<FrameNode>& inPageNode);
130     void AddPageTransitionTrace(const RefPtr<FrameNode>& srcPage, const RefPtr<FrameNode>& destPage);
131     std::string GetSrcPageInfo(const RefPtr<FrameNode>& srcPage);
132     void UpdatePageNeedRemove(const RefPtr<UINode>& pageNode);
133     bool CheckPageInTransition(const RefPtr<UINode>& pageNode);
134     void StopPageTransition(bool needTransition);
135     std::string GetPagePath(const RefPtr<FrameNode>& pageNode);
136 
137     std::list<std::shared_ptr<AnimationUtils::Animation>> pushAnimations_;
138     std::list<std::shared_ptr<AnimationUtils::Animation>> popAnimations_;
139 
140     RefPtr<FrameNode> stageNode_;
141     RefPtr<StagePattern> stagePattern_;
142     WeakPtr<FrameNode> destPageNode_;
143     WeakPtr<FrameNode> srcPageNode_;
144     WeakPtr<FrameNode> animationSrcPage_;
145     int32_t animationId_ = -1;
146     bool stageInTrasition_ = false;
147 #if defined(ENABLE_SPLIT_MODE)
148     bool isNewPageReplacing_ = false;
149 #endif
150     std::string replaceSrcPageInfo_;
151     std::function<std::string(const std::string& url)> getPagePathCallback_;
152 
153     ACE_DISALLOW_COPY_AND_MOVE(StageManager);
154 };
155 } // namespace OHOS::Ace::NG
156 
157 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_STAGE_STAGE_MANAGER_H
158