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 void Destroy(); 44 void Destroy(JSView* parentCustomView); 45 46 void ExecuteRender(); 47 void ExecuteRerender(); 48 void ExecuteReload(bool deep); 49 void ExecuteForceNodeRerender(int32_t elemId); 50 bool ExecuteHasNodeUpdateFunc(int32_t elmtId); 51 void ExecuteAppear(); 52 void ExecuteDisappear(); 53 void ExecuteDidBuild(); 54 void ExecuteMeasure(NG::LayoutWrapper* layoutWrapper); 55 void ExecuteMeasureSize(NG::LayoutWrapper* layoutWrapper); 56 void ExecuteLayout(NG::LayoutWrapper* layoutWrapper); 57 void ExecutePlaceChildren(NG::LayoutWrapper* layoutWrapper); 58 void InitJsParam(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 void ExecuteOnDumpInfo(const std::vector<std::string>& params); 72 std::string ExecuteOnDumpInfo(); 73 std::string ExecuteOnFormRecycle(); 74 void ExecuteOnFormRecover(const std::string &statusData); 75 76 bool HasPageTransition() const; 77 bool HasMeasure() const; 78 bool HasMeasureSize() const; 79 bool HasLayout() const; 80 bool HasPlaceChildren() const; 81 82 void ExecuteFunction(JSWeak<JSFunc>& func, const char* debugInfo); 83 void ExecuteFunctionWithParams(JSWeak<JSFunc>& func, const char* debugInfo, const std::string& jsonData); 84 JSRef<JSVal> ExecuteFunctionWithReturn(JSWeak<JSFunc>& func, const char* debugInfo); 85 SetContext(const JSExecutionContext & context)86 void SetContext(const JSExecutionContext& context) 87 { 88 context_ = context; 89 } 90 91 protected: 92 void InitViewFunctions(const JSRef<JSObject>& jsObject, const JSRef<JSFunc>& jsRenderFunction, bool partialUpdate); 93 94 private: 95 JSWeak<JSObject> jsObject_; 96 JSWeak<JSFunc> jsAppearFunc_; 97 JSWeak<JSFunc> jsDisappearFunc_; 98 JSWeak<JSFunc> jsDidBuildFunc_; 99 JSWeak<JSFunc> jsMeasureFunc_; 100 JSWeak<JSFunc> jsMeasureSizeFunc_; 101 JSWeak<JSFunc> jsLayoutFunc_; 102 JSWeak<JSFunc> jsPlaceChildrenFunc_; 103 JSWeak<JSFunc> jsAboutToRenderFunc_; 104 JSWeak<JSFunc> jsAboutToBeDeletedFunc_; 105 JSWeak<JSFunc> jsRenderDoneFunc_; 106 JSWeak<JSFunc> jsAboutToBuildFunc_; 107 JSWeak<JSFunc> jsBuildDoneFunc_; 108 JSWeak<JSFunc> jsRenderFunc_; 109 JSWeak<JSFunc> jsRerenderFunc_; 110 JSWeak<JSFunc> jsReloadFunc_; 111 JSWeak<JSFunc> jsForceRerenderNodeFunc_; 112 JSWeak<JSFunc> jsHasNodeUpdateFunc_; 113 JSWeak<JSFunc> jsTransitionFunc_; 114 JSWeak<JSVal> jsRenderResult_; 115 116 JSWeak<JSFunc> jsOnHideFunc_; 117 JSWeak<JSFunc> jsOnShowFunc_; 118 JSWeak<JSFunc> jsBackPressFunc_; 119 JSWeak<JSFunc> jsUpdateWithValueParamsFunc_; 120 JSWeak<JSFunc> jsSetInitiallyProvidedValueFunc_; 121 JSWeak<JSFunc> jsRecycleFunc_; 122 JSWeak<JSFunc> jsAboutToRecycleFunc_; 123 JSWeak<JSFunc> jsSetActive_; 124 JSWeak<JSFunc> jsOnDumpInfo_; 125 JSWeak<JSFunc> jsOnDumpInspector_; 126 JSWeak<JSFunc>jsOnFormRecycleFunc_; 127 JSWeak<JSFunc>jsOnFormRecoverFunc_; 128 129 JSExecutionContext context_; 130 }; 131 132 } // namespace OHOS::Ace::Framework 133 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_VIEW_FUNCTIONS_H 134