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