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 
28 namespace OHOS::Ace::NG {
29 class FrameNode;
30 class OverlayManager;
31 
32 // StageManager is the base class for root render node to perform page switch.
33 class ACE_FORCE_EXPORT StageManager : public virtual AceType {
34     DECLARE_ACE_TYPE(StageManager, AceType);
35 
36 public:
37     explicit StageManager(const RefPtr<FrameNode>& stage);
38     ~StageManager() override = default;
39 
40     // PushUrl and ReplaceUrl both use PushPage function
41     virtual bool PushPage(const RefPtr<FrameNode>& node, bool needHideLast = true, bool needTransition = true);
42     virtual bool InsertPage(const RefPtr<FrameNode>& node, bool bellowTopOrBottom);
43     virtual bool PopPage(bool needShowNext = true, bool needTransition = true);
44     virtual bool PopPageToIndex(int32_t index, bool needShowNext = true, bool needTransition = true);
45     virtual bool CleanPageStack();
46     virtual bool MovePageToFront(const RefPtr<FrameNode>& node, bool needHideLast = true, bool needTransition = true);
47 
48     virtual void StartTransition(const RefPtr<FrameNode>& srcPage, const RefPtr<FrameNode>& destPage, RouteType type);
49 
50     void PageChangeCloseKeyboard();
51 
52     static void FirePageHide(const RefPtr<UINode>& node, PageTransitionType transitionType = PageTransitionType::NONE);
53     static void FirePageShow(const RefPtr<UINode>& node, PageTransitionType transitionType = PageTransitionType::NONE,
54         bool needFocus = true);
55 
56     virtual RefPtr<FrameNode> GetLastPage() const;
57     RefPtr<FrameNode> GetPageById(int32_t pageId);
GetStageNode()58     const RefPtr<FrameNode> GetStageNode() const
59     {
60         return stageNode_;
61     }
62 
63     void ReloadStage();
64 
65     virtual RefPtr<FrameNode> GetLastPageWithTransition() const;
66     virtual RefPtr<FrameNode> GetPrevPageWithTransition() const;
67 
GetFocusPage()68     virtual RefPtr<FrameNode> GetFocusPage() const
69     {
70         return nullptr;
71     }
72 
SetStageInTrasition(bool stageInTrasition)73     void SetStageInTrasition (bool stageInTrasition) {
74         stageInTrasition_ = stageInTrasition;
75     }
76 
77 #if defined(ENABLE_SPLIT_MODE)
IsNewPageReplacing()78     bool IsNewPageReplacing() const
79     {
80         return isNewPageReplacing_;
81     }
82 
SetIsNewPageReplacing(bool replacing)83     void SetIsNewPageReplacing(bool replacing)
84     {
85         isNewPageReplacing_ = replacing;
86     }
87 #endif
88 
89     virtual void SyncPageSafeArea(bool keyboardSafeArea);
90 
91     virtual bool CheckPageFocus();
92 
93 protected:
94     // ace performance check
95     void PerformanceCheck(const RefPtr<FrameNode>& pageNode, int64_t vsyncTimeout, std::string path);
96     void StopPageTransition();
97     void FireAutoSave(const RefPtr<FrameNode>& outPageNode, const RefPtr<FrameNode>& inPageNode);
98     void AddPageTransitionTrace(const RefPtr<FrameNode>& srcPage, const RefPtr<FrameNode>& destPage);
99 
100     RefPtr<FrameNode> stageNode_;
101     RefPtr<StagePattern> stagePattern_;
102     WeakPtr<FrameNode> destPageNode_;
103     WeakPtr<FrameNode> srcPageNode_;
104     bool stageInTrasition_ = false;
105 #if defined(ENABLE_SPLIT_MODE)
106     bool isNewPageReplacing_ = false;
107 #endif
108 
109     ACE_DISALLOW_COPY_AND_MOVE(StageManager);
110 };
111 } // namespace OHOS::Ace::NG
112 
113 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_STAGE_STAGE_MANAGER_H
114