1 /*
2  * Copyright (c) 2022 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 FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_MODELS_VIEW_STACK_MODEL_IMPL_H
17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_MODELS_VIEW_STACK_MODEL_IMPL_H
18 
19 #include "base/memory/ace_type.h"
20 #include "base/utils/macros.h"
21 #include "bridge/declarative_frontend/view_stack_processor.h"
22 #include "core/components_ng/base/view_stack_model.h"
23 #include "core/pipeline/base/component.h"
24 
25 namespace OHOS::Ace::Framework {
26 
27 class ViewStackModelImpl : public ViewStackModel {
28 public:
Push(const RefPtr<AceType> & node,bool isCustomView)29     void Push(const RefPtr<AceType>& node, bool isCustomView) override
30     {
31         auto uiNode = AceType::DynamicCast<Component>(node);
32         ViewStackProcessor::GetInstance()->Push(uiNode, isCustomView);
33     }
34 
Pop()35     void Pop() override
36     {
37         ViewStackProcessor::GetInstance()->Pop();
38     }
39 
PopContainer()40     void PopContainer() override
41     {
42         ViewStackProcessor::GetInstance()->PopContainer();
43     }
44 
PushKey(const std::string & key)45     void PushKey(const std::string& key) override
46     {
47         ViewStackProcessor::GetInstance()->PushKey(key);
48     }
49 
PopKey()50     void PopKey() override
51     {
52         ViewStackProcessor::GetInstance()->PopKey();
53     }
54 
NewScope()55     void NewScope() override
56     {
57         scopeStack_ = std::make_unique<ScopedViewStackProcessor>();
58     }
59 
Finish()60     RefPtr<AceType> Finish() override
61     {
62         auto node = ViewStackProcessor::GetInstance()->Finish();
63         scopeStack_.reset();
64         return node;
65     }
66 
ProcessViewId(const std::string & viewId)67     std::string ProcessViewId(const std::string& viewId) override
68     {
69         return ViewStackProcessor::GetInstance()->ProcessViewId(viewId);
70     }
71 
GetImplicitAnimationOption()72     AnimationOption GetImplicitAnimationOption() override
73     {
74         return ViewStackProcessor::GetInstance()->GetImplicitAnimationOption();
75     }
76 
ClearVisualState()77     void ClearVisualState() override
78     {
79         ViewStackProcessor::GetInstance()->ClearVisualState();
80     }
81 
SetVisualState(VisualState state)82     void SetVisualState(VisualState state) override
83     {
84         ViewStackProcessor::GetInstance()->SetVisualState(state);
85     }
86 
StartGetAccessRecordingFor(int32_t elmtId)87     void StartGetAccessRecordingFor(int32_t elmtId) override
88     {
89         ViewStackProcessor::GetInstance()->StartGetAccessRecordingFor(elmtId);
90     }
91 
GetElmtIdToAccountFor()92     int32_t GetElmtIdToAccountFor() override
93     {
94         return ViewStackProcessor::GetInstance()->GetElmtIdToAccountFor();
95     }
96 
SetElmtIdToAccountFor(int32_t elmtId)97     void SetElmtIdToAccountFor(int32_t elmtId) override
98     {
99         ViewStackProcessor::GetInstance()->SetElmtIdToAccountFor(elmtId);
100     }
101 
StopGetAccessRecording()102     void StopGetAccessRecording() override
103     {
104         ViewStackProcessor::GetInstance()->StopGetAccessRecording();
105     }
106 
ImplicitPopBeforeContinue()107     void ImplicitPopBeforeContinue() override
108     {
109         if ((ViewStackProcessor::GetInstance()->Size() > 1) &&
110             ViewStackProcessor::GetInstance()->ShouldPopImmediately()) {
111             ViewStackProcessor::GetInstance()->Pop();
112         }
113     }
114 
GetAndPushFrameNode(const std::string & tag,int32_t elmtId)115     void GetAndPushFrameNode(const std::string& tag, int32_t elmtId) override
116     {
117         ViewStackProcessor::GetInstance()->GetAndPushFrameNode(tag, elmtId);
118     }
119 
CheckTopNodeFirstBuilding()120     bool CheckTopNodeFirstBuilding() const override
121     {
122         return false;
123     }
124 
IsEmptyStack()125     bool IsEmptyStack() const override
126     {
127         // not check for old pipeline yet
128         return true;
129     }
130 
131 private:
132     std::unique_ptr<ScopedViewStackProcessor> scopeStack_;
133 };
134 
135 } // namespace OHOS::Ace::Framework
136 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_MODELS_VIEW_STACK_MODEL_IMPL_H
137