• 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 
33 class JSView;
34 
35 class ViewFunctions : public AceType {
36     DECLARE_ACE_TYPE(ViewFunctions, AceType);
37 
38 public:
39     ViewFunctions(const JSRef<JSObject>& jsObject, const JSRef<JSFunc>& jsRenderFunction);
40     explicit ViewFunctions(const JSRef<JSObject>& jsObject);
~ViewFunctions()41     ~ViewFunctions() override
42     {
43         LOGD("Destroy: ViewFunctions");
44     }
45 
46     void Destroy();
47     void Destroy(JSView* parentCustomView);
48 
49     void ExecuteRender();
50     void ExecuteRerender();
51     void ExecuteReload(bool deep);
52     void ExecuteForceNodeRerender(int32_t elemId);
53     void ExecuteAppear();
54     void ExecuteDisappear();
55     void ExecuteMeasure(NG::LayoutWrapper* layoutWrapper);
56     void ExecuteMeasureSize(NG::LayoutWrapper* layoutWrapper);
57     void ExecuteLayout(NG::LayoutWrapper* layoutWrapper);
58     void ExecutePlaceChildren(NG::LayoutWrapper* layoutWrapper);
59     void ExecuteAboutToBeDeleted();
60     void ExecuteAboutToRender();
61     void ExecuteOnRenderDone();
62     void ExecuteTransition();
63     bool ExecuteOnBackPress();
64     void ExecuteShow();
65     void ExecuteHide();
66     void ExecuteInitiallyProvidedValue(const std::string& jsonData);
67     void ExecuteUpdateWithValueParams(const std::string& jsonData);
68     void ExecuteRecycle(const std::string& viewName);
69     void ExecuteAboutToRecycle();
70     void ExecuteSetActive(bool active);
71 
72     bool HasPageTransition() const;
73     bool HasMeasure() const;
74     bool HasMeasureSize() const;
75     bool HasLayout() const;
76     bool HasPlaceChildren() const;
77 
78     void ExecuteFunction(JSWeak<JSFunc>& func, const char* debugInfo);
79     void ExecuteFunctionWithParams(JSWeak<JSFunc>& func, const char* debugInfo, const std::string& jsonData);
80     JSRef<JSVal> ExecuteFunctionWithReturn(JSWeak<JSFunc>& func, const char* debugInfo);
81 
SetContext(const JSExecutionContext & context)82     void SetContext(const JSExecutionContext& context)
83     {
84         context_ = context;
85     }
86 
87 protected:
88     void InitViewFunctions(const JSRef<JSObject>& jsObject, const JSRef<JSFunc>& jsRenderFunction, bool partialUpdate);
89 
90 private:
91     JSWeak<JSObject> jsObject_;
92     JSWeak<JSFunc> jsAppearFunc_;
93     JSWeak<JSFunc> jsDisappearFunc_;
94     JSWeak<JSFunc> jsMeasureFunc_;
95     JSWeak<JSFunc> jsMeasureSizeFunc_;
96     JSWeak<JSFunc> jsLayoutFunc_;
97     JSWeak<JSFunc> jsPlaceChildrenFunc_;
98     JSWeak<JSFunc> jsAboutToRenderFunc_;
99     JSWeak<JSFunc> jsAboutToBeDeletedFunc_;
100     JSWeak<JSFunc> jsRenderDoneFunc_;
101     JSWeak<JSFunc> jsAboutToBuildFunc_;
102     JSWeak<JSFunc> jsBuildDoneFunc_;
103     JSWeak<JSFunc> jsRenderFunc_;
104     JSWeak<JSFunc> jsRerenderFunc_;
105     JSWeak<JSFunc> jsReloadFunc_;
106     JSWeak<JSFunc> jsForceRerenderNodeFunc_;
107     JSWeak<JSFunc> jsTransitionFunc_;
108     JSWeak<JSVal> jsRenderResult_;
109 
110     JSWeak<JSFunc> jsOnHideFunc_;
111     JSWeak<JSFunc> jsOnShowFunc_;
112     JSWeak<JSFunc> jsBackPressFunc_;
113     JSWeak<JSFunc> jsUpdateWithValueParamsFunc_;
114     JSWeak<JSFunc> jsSetInitiallyProvidedValueFunc_;
115     JSWeak<JSFunc> jsRecycleFunc_;
116     JSWeak<JSFunc> jsAboutToRecycleFunc_;
117     JSWeak<JSFunc> jsSetActive_;
118 
119     JSExecutionContext context_;
120 };
121 
122 } // namespace OHOS::Ace::Framework
123 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_VIEW_FUNCTIONS_H
124