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_ANIMATION_SHARED_TRANSITION_CONTROLLER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_ANIMATION_SHARED_TRANSITION_CONTROLLER_H
18 
19 #include <list>
20 
21 #include "base/memory/ace_type.h"
22 #include "core/animation/animation_pub.h"
23 #include "core/components/page/page_element.h"
24 #include "core/pipeline/pipeline_context.h"
25 
26 namespace OHOS::Ace {
27 
28 class Animator;
29 class SharedTransitionElement;
30 class SharedTransitionEffect;
31 
32 class SharedTransitionController : public AceType {
33     DECLARE_ACE_TYPE(SharedTransitionController, AceType);
34 
35 public:
36     explicit SharedTransitionController(const WeakPtr<PipelineContext>& context);
37     ~SharedTransitionController() override = default;
38     void RegisterTransitionListener();
39     bool HasSharedTransition(TransitionEvent event);
GetAnimators()40     const std::list<RefPtr<Animator>>& GetAnimators() const
41     {
42         return controllers_;
43     }
44 
45 private:
46     void StartSharedTransition();
47     void KickoffSharedTransition(TransitionEvent event, RefPtr<OverlayElement>& overlay);
48     bool PrepareTransition(RefPtr<OverlayElement> overlay, bool preCheck = false);
49     bool CheckAndCreateTransition(
50         std::vector<RefPtr<SharedTransitionEffect>>& effects, RefPtr<OverlayElement>& overlay);
51     bool PrepareEachTransition(
52         const ShareId& shareId, RefPtr<SharedTransitionEffect>& effect, RefPtr<OverlayElement>& overlay);
53     WeakPtr<PipelineContext> context_;
54     WeakPtr<PageElement> pageDest_;
55     WeakPtr<PageElement> pageSrc_;
56     std::list<RefPtr<Animator>> controllers_;
57     int32_t stopControllerCount_ = 0;
58     TransitionEvent event_ { TransitionEvent::PUSH_START };
59     bool hasSharedTransition_ = { false };
60 };
61 
62 } // namespace OHOS::Ace
63 
64 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_ANIMATION_SHARED_TRANSITION_CONTROLLER_H
65