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 const std::function<bool()>&& pushIntentPageCallback = nullptr); 44 virtual bool InsertPage(const RefPtr<FrameNode>& node, bool bellowTopOrBottom); 45 virtual bool PopPage(const RefPtr<FrameNode>& inPageNode, bool needShowNext = true, bool needTransition = true); 46 virtual bool PopPageToIndex(int32_t index, bool needShowNext = true, bool needTransition = true); 47 virtual bool CleanPageStack(); 48 virtual bool MovePageToFront(const RefPtr<FrameNode>& node, bool needHideLast = true, bool needTransition = true); 49 50 virtual void StartTransition(const RefPtr<FrameNode>& srcPage, const RefPtr<FrameNode>& destPage, RouteType type); 51 52 void PageChangeCloseKeyboard(); 53 void UpdateColorModeForPage(const RefPtr<FrameNode>& page); 54 55 static void FirePageHide(const RefPtr<UINode>& node, PageTransitionType transitionType = PageTransitionType::NONE); 56 static void FirePageShow(const RefPtr<UINode>& node, PageTransitionType transitionType = PageTransitionType::NONE, 57 bool needFocus = true); 58 59 virtual RefPtr<FrameNode> GetLastPage() const; 60 RefPtr<FrameNode> GetPageById(int32_t pageId); GetStageNode()61 const RefPtr<FrameNode> GetStageNode() const 62 { 63 return stageNode_; 64 } 65 66 void ReloadStage(); 67 68 virtual RefPtr<FrameNode> GetLastPageWithTransition() const; 69 virtual RefPtr<FrameNode> GetPrevPageWithTransition() const; 70 GetFocusPage()71 virtual RefPtr<FrameNode> GetFocusPage() const 72 { 73 return nullptr; 74 } 75 SetStageInTrasition(bool stageInTrasition)76 void SetStageInTrasition (bool stageInTrasition) { 77 stageInTrasition_ = stageInTrasition; 78 } 79 80 void SetForceSplitEnable(bool isForceSplit, const std::string& homePage, bool ignoreOrientation = false); 81 GetForceSplitEnable()82 bool GetForceSplitEnable() const 83 { 84 return isForceSplit_; 85 } 86 GetHomePageConfig()87 std::string GetHomePageConfig() const 88 { 89 return homePageConfig_; 90 } 91 GetIgnoreOrientation()92 bool GetIgnoreOrientation() const 93 { 94 return ignoreOrientation_; 95 } 96 GetDetectPrimaryPageEnable()97 bool GetDetectPrimaryPageEnable() const 98 { 99 return isDetectPrimaryPage_; 100 } 101 OnForceSplitConfigUpdate()102 void OnForceSplitConfigUpdate() 103 { 104 CHECK_NULL_VOID(stagePattern_); 105 stagePattern_->OnForceSplitConfigUpdate(); 106 } 107 108 #if defined(ENABLE_SPLIT_MODE) IsNewPageReplacing()109 bool IsNewPageReplacing() const 110 { 111 return isNewPageReplacing_; 112 } 113 SetIsNewPageReplacing(bool replacing)114 void SetIsNewPageReplacing(bool replacing) 115 { 116 isNewPageReplacing_ = replacing; 117 } 118 #endif 119 120 virtual void SyncPageSafeArea(bool keyboardSafeArea); 121 122 virtual bool CheckPageFocus(); 123 SetSrcPage(const RefPtr<FrameNode> & pageNode)124 void SetSrcPage(const RefPtr<FrameNode>& pageNode) 125 { 126 srcPageNode_ = pageNode; 127 } 128 AddAnimation(const std::shared_ptr<AnimationUtils::Animation> & animation,bool isPush)129 void AddAnimation(const std::shared_ptr<AnimationUtils::Animation>& animation, bool isPush) 130 { 131 if (isPush) { 132 pushAnimations_.emplace_back(animation); 133 return; 134 } 135 popAnimations_.emplace_back(animation); 136 } 137 138 void AbortAnimation(); 139 GetAnimationId()140 int32_t GetAnimationId() const 141 { 142 return animationId_; 143 } 144 SetGetPagePathCallback(std::function<std::string (const std::string & url)> && callback)145 void SetGetPagePathCallback(std::function<std::string(const std::string& url)>&& callback) 146 { 147 getPagePathCallback_ = std::move(callback); 148 } 149 std::vector<std::string> GetTopPagePaths() const; 150 virtual std::vector<RefPtr<FrameNode>> GetTopPagesWithTransition() const; IsSplitMode()151 virtual bool IsSplitMode() const 152 { 153 return false; 154 } 155 156 protected: 157 // ace performance check 158 void PerformanceCheck(const RefPtr<FrameNode>& pageNode, int64_t vsyncTimeout, std::string path); 159 void FireAutoSave(const RefPtr<FrameNode>& outPageNode, const RefPtr<FrameNode>& inPageNode); 160 void AddPageTransitionTrace(const RefPtr<FrameNode>& srcPage, const RefPtr<FrameNode>& destPage); 161 std::string GetSrcPageInfo(const RefPtr<FrameNode>& srcPage); 162 void UpdatePageNeedRemove(const RefPtr<UINode>& pageNode); 163 bool CheckPageInTransition(const RefPtr<UINode>& pageNode); 164 void StopPageTransition(bool needTransition); 165 std::string GetPagePath(const RefPtr<FrameNode>& pageNode); 166 167 std::list<std::shared_ptr<AnimationUtils::Animation>> pushAnimations_; 168 std::list<std::shared_ptr<AnimationUtils::Animation>> popAnimations_; 169 170 RefPtr<FrameNode> stageNode_; 171 RefPtr<StagePattern> stagePattern_; 172 WeakPtr<FrameNode> destPageNode_; 173 WeakPtr<FrameNode> srcPageNode_; 174 WeakPtr<FrameNode> animationSrcPage_; 175 int32_t animationId_ = -1; 176 bool stageInTrasition_ = false; 177 #if defined(ENABLE_SPLIT_MODE) 178 bool isNewPageReplacing_ = false; 179 #endif 180 std::string replaceSrcPageInfo_; 181 std::function<std::string(const std::string& url)> getPagePathCallback_; 182 183 ACE_DISALLOW_COPY_AND_MOVE(StageManager); 184 185 private: 186 bool isForceSplit_ = false; 187 std::string homePageConfig_; 188 bool isDetectPrimaryPage_ = false; 189 bool ignoreOrientation_ = false; 190 }; 191 } // namespace OHOS::Ace::NG 192 193 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_STAGE_STAGE_MANAGER_H 194