• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_STAGE_STAGE_ELEMENT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_STAGE_STAGE_ELEMENT_H
18 
19 #include "core/animation/animator.h"
20 #include "core/animation/page_transition_listener.h"
21 #include "core/components/page/page_element.h"
22 #include "core/components/page_transition/page_transition_element.h"
23 #include "core/components/stack/stack_element.h"
24 
25 namespace OHOS::Ace {
26 
27 enum class StackOperation { NONE, PUSH_PAGE, POP, POP_TO_PAGE, REPLACE, CLEAR, RESTORE };
28 
29 class StageElement : public StackElement, public PageTransitionListenable, public FlushEvent {
30     DECLARE_ACE_TYPE(StageElement, StackElement, FlushEvent);
31 
32 public:
33     void PerformBuild() override;
34 
35     virtual void PushPage(const RefPtr<Component>& newComponent);
36     void Pop();
37     void PopToPage(int32_t pageId);
38     void RestorePopPage(const RefPtr<Component>& newComponent);
39     virtual void Replace(const RefPtr<Component>& newComponent);
40     bool ClearOffStage();
41     bool CanPopPage();
42     bool CanPushPage();
43     bool CanReplacePage();
44     bool CanRouterPage();
45     void PostponePageTransition();
46     void LaunchPageTransition();
47     void RefreshFocus();
48     bool IsFocusable() const override;
49     bool InitTransition(const RefPtr<PageTransitionElement>& transitionIn,
50         const RefPtr<PageTransitionElement>& transitionOut, TransitionEvent event);
51 
GetStackOperation()52     StackOperation GetStackOperation() const
53     {
54         return operation_;
55     }
56 
57     bool IsTransitionStop() const;
58 
isPageElement()59     bool isPageElement() override
60     {
61         return true;
62     }
63 
64 protected:
65     void MarkDirty() override;
66     bool OnKeyEvent(const KeyEvent& keyEvent) override;
67 
68 private:
69     void PerformPushPage();
70     void PerformPop();
71     void PerformReplace();
72     void PerformPopToPage();
73     void PerformClear();
74 #ifndef WEARABLE_PRODUCT
75     void PerformPushMultimodalScene(int32_t pageId);
76     void PerformPopMultimodalScene(int32_t poppedPageId, int32_t incomingPageId);
77     void PerformReplaceActiveScene(int32_t newPageId, int32_t replaceId);
78     void PerformRemoveInactiveScene(int32_t pageId);
79 #endif
80     bool PerformPushPageTransition(const RefPtr<Element>& elementIn, const RefPtr<Element>& elementOut);
81     bool PerformPopPageTransition(const RefPtr<Element>& elementIn, const RefPtr<Element>& elementOut);
82     void AddListenerForPopPage(const WeakPtr<PageElement>& pageInWeak, const WeakPtr<PageElement>& pageOutWeak);
83     static bool CheckPageTransitionElement(
84         const RefPtr<PageTransitionElement>& transitionIn, const RefPtr<PageTransitionElement>& transitionOut);
85     bool InitTransition(const RefPtr<PageTransitionElement>& transition, TransitionDirection direction,
86         TransitionEvent event, const RRect& cardRect);
87     void PerformPushPageInStage(const WeakPtr<PageElement>& pageOutWeak);
88     void PerformPopPageInStage(const RefPtr<PageElement>& pageOut, const RefPtr<PageTransitionElement>& transitionOut);
89     void ProcessStageInPageTransition();
90     // Page transition parameters depend on the existence of shared element transitions,
91     // Only after PerformBuild can we determine if there is a shared element transition.
92     void OnPostFlush() override;
93     void MakeTopPageTouchable();
94     void RestorePop();
95 
96     StackOperation operation_ { StackOperation::NONE };
97     StackOperation pendingOperation_ { StackOperation::NONE };
98     bool postponePageTransition_ { false };
99 
100     RefPtr<Component> newComponent_;
101     RefPtr<Animator> controllerIn_;  // Controller for transition in.
102     RefPtr<Animator> controllerOut_; // Controller for transition out.
103     int32_t directedPageId_ = 0;
104     bool isWaitingForBuild_ = false;
105 };
106 
107 class SectionStageElement : public StageElement {
108     DECLARE_ACE_TYPE(SectionStageElement, StageElement);
109 
110 public:
111     void PushPage(const RefPtr<Component>& newComponent) override;
112     void Replace(const RefPtr<Component>& newComponent) override;
113 
114 private:
115     void AddAsOnlyPage(const RefPtr<Component>& newComponent);
116 };
117 
118 } // namespace OHOS::Ace
119 
120 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_STAGE_STAGE_ELEMENT_H
121