• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_JS_VIEW_FUNCTIONS_H
17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_VIEW_FUNCTIONS_H
18 
19 #include <string>
20 
21 #include "core/components_ng/layout/layout_wrapper.h"
22 #include "core/pipeline/base/composed_component.h"
23 #include "frameworks/bridge/declarative_frontend/engine/js_ref_ptr.h"
24 #include "frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h"
25 #include "frameworks/bridge/declarative_frontend/jsview/js_view_measure_layout.h"
26 
27 namespace OHOS::Ace {
28 class ComposedElement;
29 } // namespace OHOS::Ace
30 
31 namespace OHOS::Ace::Framework {
32 enum class PrebuildPhase : int32_t {
33     NONE = 0,
34     BUILD_PREBUILD_CMD = 1,
35     EXECUTE_PREBUILD_CMD = 2,
36     PREBUILD_DONE = 3,
37 };
38 
39 class JSView;
40 
41 class ViewFunctions : public AceType {
42     DECLARE_ACE_TYPE(ViewFunctions, AceType);
43 
44 public:
45     ViewFunctions(const JSRef<JSObject>& jsObject, const JSRef<JSFunc>& jsRenderFunction);
46     explicit ViewFunctions(const JSRef<JSObject>& jsObject);
~ViewFunctions()47     ~ViewFunctions() override {}
48 
49     void Destroy();
50     void Destroy(JSView* parentCustomView);
51 
52     void ExecuteRender();
53     void ExecuteRerender();
54     void ExecuteReload(bool deep);
55     void ExecuteForceNodeRerender(int32_t elemId);
56     bool ExecuteHasNodeUpdateFunc(int32_t elmtId);
57     void ExecuteAppear();
58     void ExecuteDisappear();
59     void ExecuteDidBuild();
60     void ExecuteMeasure(NG::LayoutWrapper* layoutWrapper);
61     void ExecuteMeasureSize(NG::LayoutWrapper* layoutWrapper);
62     void ExecuteLayout(NG::LayoutWrapper* layoutWrapper);
63     void ExecutePlaceChildren(NG::LayoutWrapper* layoutWrapper);
64     void InitJsParam(NG::LayoutWrapper* layoutWrapper);
65     void ExecuteAboutToBeDeleted();
66     void ExecuteAboutToRender();
67     void ExecuteOnRenderDone();
68     void ExecuteTransition();
69     bool ExecuteOnBackPress();
70     void ExecuteShow();
71     void ExecuteHide();
72     void ExecuteInitiallyProvidedValue(const std::string& jsonData);
73     void ExecuteUpdateWithValueParams(const std::string& jsonData);
74     void ExecuteRecycle(const std::string& viewName);
75     void ExecuteAboutToRecycle();
76     void ExecuteAboutToReuse(void* params);
77     void ExecuteSetActive(bool active, bool isReuse = false);
78     void ExecuteOnDumpInfo(const std::vector<std::string>& params);
79     std::string ExecuteOnDumpInfo();
80     void ExecuteClearAllRecycle();
81     std::string ExecuteOnFormRecycle();
82     void ExecuteOnFormRecover(const std::string &statusData);
83     void ExecutePrebuildComponent();
84     bool ExecuteSetPrebuildPhase(PrebuildPhase prebuildPhase);
85     bool ExecuteIsEnablePrebuildInMultiFrame();
86     void ExecuteOnNewParam(const std::string &newParam);
87 
88     bool HasPageTransition() const;
89     bool HasMeasure() const;
90     bool HasMeasureSize() const;
91     bool HasLayout() const;
92     bool HasPlaceChildren() const;
93 
94     void ExecuteFunction(JSWeak<JSFunc>& func, const char* debugInfo);
95     void ExecuteFunctionWithParams(JSWeak<JSFunc>& func, const char* debugInfo, const std::string& jsonData);
96     JSRef<JSVal> ExecuteFunctionWithReturn(JSWeak<JSFunc>& func, const char* debugInfo);
97 
SetContext(const JSExecutionContext & context)98     void SetContext(const JSExecutionContext& context)
99     {
100         context_ = context;
101     }
102 
103 protected:
104     void InitViewFunctions(const JSRef<JSObject>& jsObject, const JSRef<JSFunc>& jsRenderFunction, bool partialUpdate);
105 
106 private:
107     JSWeak<JSObject> jsObject_;
108     JSWeak<JSFunc> jsAppearFunc_;
109     JSWeak<JSFunc> jsDisappearFunc_;
110     JSWeak<JSFunc> jsDidBuildFunc_;
111     JSWeak<JSFunc> jsMeasureFunc_;
112     JSWeak<JSFunc> jsMeasureSizeFunc_;
113     JSWeak<JSFunc> jsLayoutFunc_;
114     JSWeak<JSFunc> jsPlaceChildrenFunc_;
115     JSWeak<JSFunc> jsAboutToRenderFunc_;
116     JSWeak<JSFunc> jsAboutToBeDeletedFunc_;
117     JSWeak<JSFunc> jsRenderDoneFunc_;
118     JSWeak<JSFunc> jsAboutToBuildFunc_;
119     JSWeak<JSFunc> jsBuildDoneFunc_;
120     JSWeak<JSFunc> jsRenderFunc_;
121     JSWeak<JSFunc> jsRerenderFunc_;
122     JSWeak<JSFunc> jsReloadFunc_;
123     JSWeak<JSFunc> jsForceRerenderNodeFunc_;
124     JSWeak<JSFunc> jsHasNodeUpdateFunc_;
125     JSWeak<JSFunc> jsTransitionFunc_;
126     JSWeak<JSVal> jsRenderResult_;
127 
128     JSWeak<JSFunc> jsOnHideFunc_;
129     JSWeak<JSFunc> jsOnShowFunc_;
130     JSWeak<JSFunc> jsBackPressFunc_;
131     JSWeak<JSFunc> jsUpdateWithValueParamsFunc_;
132     JSWeak<JSFunc> jsSetInitiallyProvidedValueFunc_;
133     JSWeak<JSFunc> jsRecycleFunc_;
134     JSWeak<JSFunc> jsAboutToRecycleFunc_;
135     JSWeak<JSFunc> jsAboutToReuseFunc_;
136     JSWeak<JSFunc> jsSetActive_;
137     JSWeak<JSFunc> jsOnDumpInfo_;
138     JSWeak<JSFunc> jsOnDumpInspector_;
139     JSWeak<JSFunc> jsClearAllRecycle_;
140     JSWeak<JSFunc> jsPrebuildComponent_;
141     JSWeak<JSFunc> jsSetPrebuildPhase_;
142     JSWeak<JSFunc> jsIsEnablePrebuildInMultiFrame_;
143     JSWeak<JSFunc> jsOnFormRecycleFunc_;
144     JSWeak<JSFunc> jsOnFormRecoverFunc_;
145     JSWeak<JSFunc> jsOnNewParam_;
146 
147     JSExecutionContext context_;
148 };
149 
150 } // namespace OHOS::Ace::Framework
151 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_VIEW_FUNCTIONS_H
152