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_STACK_PROCESSOR_H 17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_STACK_PROCESSOR_H 18 19 #include <map> 20 21 #include "bridge/declarative_frontend/engine/bindings_defines.h" 22 #include "bridge/declarative_frontend/engine/js_ref_ptr.h" 23 #include "bridge/declarative_frontend/engine/js_types.h" 24 #include "core/components/common/properties/state_attributes.h" 25 #include "core/pipeline/base/element_register.h" 26 27 namespace OHOS::Ace::Framework { 28 29 class JSViewStackProcessor { 30 public: 31 JSViewStackProcessor() = default; 32 ~JSViewStackProcessor() = default; 33 34 static void JSBind(BindingTarget globalObj); 35 static VisualState StringToVisualState(const std::string& stateString); 36 JsAllocateNewElmetIdForNextComponent()37 static ElementIdType JsAllocateNewElmetIdForNextComponent() 38 { 39 return ElementRegister::GetInstance()->MakeUniqueId(); 40 } 41 42 static void JsStartGetAccessRecordingFor(ElementIdType elmtId); 43 44 static int32_t JsGetElmtIdToAccountFor(); 45 46 static void JsSetElmtIdToAccountFor(ElementIdType elmtId); 47 48 static void JsStopGetAccessRecording(); 49 50 static void JsImplicitPopBeforeContinue(); 51 52 /** 53 * Returns a globally unique id from ElementRegister 54 * JS signatire: MakeUniqueId() : number 55 */ 56 static void JSMakeUniqueId(const JSCallbackInfo& info); 57 SetViewMap(const std::string & viewId,const JSRef<JSObject> & jsView)58 static void SetViewMap(const std::string& viewId, const JSRef<JSObject>& jsView) 59 { 60 if (viewMap_.find(viewId) != viewMap_.end()) { 61 LOGW("jsView already exists for viewId: %{public}s", viewId.c_str()); 62 return; 63 } 64 65 viewMap_.emplace(viewId, jsView); 66 } 67 GetViewById(const std::string viewId)68 static JSRef<JSObject> GetViewById(const std::string viewId) 69 { 70 auto it = viewMap_.find(viewId); 71 if (it == viewMap_.end()) { 72 LOGW("get view failed with viewId:%{public}s", viewId.c_str()); 73 return JSRef<JSObject>::New(); 74 } 75 LOGI("get view success with viewId:%{public}s", viewId.c_str()); 76 return it->second; 77 } 78 79 /** 80 * return true of current Container uses new Pipeline 81 */ 82 static bool JsUsesNewPipeline(); 83 84 /** 85 * return the API version specified in the manifest.json 86 */ 87 static int32_t JsGetApiVersion(); 88 89 /** 90 * Gets framenode and pushes to VSP. 91 */ 92 static void JsGetAndPushFrameNode(const JSCallbackInfo& info); 93 94 /* 95 move deleted elmtIds from C+ ElementRegistry to this component. 96 JS caller must allocate empty Array<number> and provide as param 97 */ 98 static void JsMoveDeletedElmtIds(const JSCallbackInfo& info); 99 100 private: 101 static void JSVisualState(const JSCallbackInfo& info); 102 static std::map<std::string, JSRef<JSObject>> viewMap_; 103 }; 104 105 } // namespace OHOS::Ace::Framework 106 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_STACK_PROCESSOR_H 107