• 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 ExecuteLayout(NG::LayoutWrapper* layoutWrapper);
57     void ExecuteAboutToBeDeleted();
58     void ExecuteAboutToRender();
59     void ExecuteOnRenderDone();
60     void ExecuteTransition();
61     bool ExecuteOnBackPress();
62     void ExecuteShow();
63     void ExecuteHide();
64     void ExecuteInitiallyProvidedValue(const std::string& jsonData);
65     void ExecuteUpdateWithValueParams(const std::string& jsonData);
66 #ifdef UICAST_COMPONENT_SUPPORTED
67     void ExecuteCreateChildView(const std::string& jsonData);
68     void ExecuteRouterHandle(const std::string& jsonData);
69     void ExecuteReplayOnEvent(const std::string& jsonData);
70 #endif
71 
72     bool HasPageTransition() const;
73     bool HasMeasure() const;
74     bool HasLayout() const;
75 
76     void ExecuteFunction(JSWeak<JSFunc>& func, const char* debugInfo);
77     void ExecuteFunctionWithParams(JSWeak<JSFunc>& func, const char* debugInfo, const std::string& jsonData);
78     JSRef<JSVal> ExecuteFunctionWithReturn(JSWeak<JSFunc>& func, const char* debugInfo);
79 
SetContext(const JSExecutionContext & context)80     void SetContext(const JSExecutionContext& context)
81     {
82         context_ = context;
83     }
84 
85 protected:
86     void InitViewFunctions(const JSRef<JSObject>& jsObject, const JSRef<JSFunc>& jsRenderFunction, bool partialUpdate);
87 
88 private:
89     JSWeak<JSObject> jsObject_;
90     JSWeak<JSFunc> jsAppearFunc_;
91     JSWeak<JSFunc> jsDisappearFunc_;
92     JSWeak<JSFunc> jsMeasureFunc_;
93     JSWeak<JSFunc> jsLayoutFunc_;
94     JSWeak<JSFunc> jsAboutToRenderFunc_;
95     JSWeak<JSFunc> jsAboutToBeDeletedFunc_;
96     JSWeak<JSFunc> jsRenderDoneFunc_;
97     JSWeak<JSFunc> jsAboutToBuildFunc_;
98     JSWeak<JSFunc> jsBuildDoneFunc_;
99     JSWeak<JSFunc> jsRenderFunc_;
100     JSWeak<JSFunc> jsRerenderFunc_;
101     JSWeak<JSFunc> jsReloadFunc_;
102     JSWeak<JSFunc> jsForceRerenderNodeFunc_;
103     JSWeak<JSFunc> jsTransitionFunc_;
104     JSWeak<JSVal> jsRenderResult_;
105 
106     JSWeak<JSFunc> jsOnHideFunc_;
107     JSWeak<JSFunc> jsOnShowFunc_;
108     JSWeak<JSFunc> jsBackPressFunc_;
109     JSWeak<JSFunc> jsSetInitiallyProvidedValueFunc_;
110     JSWeak<JSFunc> jsUpdateWithValueParamsFunc_;
111 #ifdef UICAST_COMPONENT_SUPPORTED
112     JSWeak<JSFunc> jsCreateChildViewFunc_;
113     JSWeak<JSFunc> jsRouterHandleFunc_;
114     JSWeak<JSFunc> jsReplayOnEventFunc_;
115 #endif
116 
117     JSExecutionContext context_;
118 };
119 
120 } // namespace OHOS::Ace::Framework
121 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_VIEW_FUNCTIONS_H