1 /* 2 * Copyright (c) 2024 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_ENGINE_JSI_NATIVEMODULE_ARKTS_NATIVE_RENDER_NODE_BRIDGE_H 17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JSI_NATIVEMODULE_ARKTS_NATIVE_RENDER_NODE_BRIDGE_H 18 19 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_api_bridge.h" 20 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_utils_bridge.h" 21 22 namespace OHOS::Ace::NG { 23 class RenderNodeBridge { 24 public: 25 static ArkUINativeModuleValue CreateRenderNode(ArkUIRuntimeCallInfo* runtimeCallInfo); 26 static void FireDrawCallback(EcmaVM* vm, JsWeak<panda::CopyableGlobal<panda::ObjectRef>> obj, 27 NG::DrawingContext& context, Local<panda::StringRef> funcName); 28 static void SetOnDraw(const RefPtr<FrameNode>& frameNode, ArkUIRuntimeCallInfo* runtimeCallInfo); 29 static ArkUINativeModuleValue AddBuilderNode(ArkUIRuntimeCallInfo* runtimeCallInfo); 30 static ArkUINativeModuleValue AppendChild(ArkUIRuntimeCallInfo* runtimeCallInfo); 31 static ArkUINativeModuleValue InsertChildAfter(ArkUIRuntimeCallInfo* runtimeCallInfo); 32 static ArkUINativeModuleValue RemoveBuilderNode(ArkUIRuntimeCallInfo* runtimeCallInfo); 33 static ArkUINativeModuleValue RemoveChild(ArkUIRuntimeCallInfo* runtimeCallInfo); 34 static ArkUINativeModuleValue ClearBuilderNode(ArkUIRuntimeCallInfo* runtimeCallInfo); 35 static ArkUINativeModuleValue ClearChildren(ArkUIRuntimeCallInfo* runtimeCallInfo); 36 static ArkUINativeModuleValue SetClipToFrame(ArkUIRuntimeCallInfo* runtimeCallInfo); 37 static ArkUINativeModuleValue SetRotation(ArkUIRuntimeCallInfo* runtimeCallInfo); 38 static ArkUINativeModuleValue SetShadowColor(ArkUIRuntimeCallInfo* runtimeCallInfo); 39 static ArkUINativeModuleValue SetShadowOffset(ArkUIRuntimeCallInfo* runtimeCallInfo); 40 static ArkUINativeModuleValue SetLabel(ArkUIRuntimeCallInfo* runtimeCallInfo); 41 static ArkUINativeModuleValue SetShadowAlpha(ArkUIRuntimeCallInfo* runtimeCallInfo); 42 static ArkUINativeModuleValue SetShadowElevation(ArkUIRuntimeCallInfo* runtimeCallInfo); 43 static ArkUINativeModuleValue SetShadowRadius(ArkUIRuntimeCallInfo* runtimeCallInfo); 44 static ArkUINativeModuleValue SetScale(ArkUIRuntimeCallInfo* runtimeCallInfo); 45 static ArkUINativeModuleValue SetBackgroundColor(ArkUIRuntimeCallInfo* runtimeCallInfo); 46 static ArkUINativeModuleValue SetPivot(ArkUIRuntimeCallInfo* runtimeCallInfo); 47 static ArkUINativeModuleValue SetFrame(ArkUIRuntimeCallInfo* runtimeCallInfo); 48 static ArkUINativeModuleValue SetSize(ArkUIRuntimeCallInfo* runtimeCallInfo); 49 static ArkUINativeModuleValue SetPosition(ArkUIRuntimeCallInfo* runtimeCallInfo); 50 static ArkUINativeModuleValue SetOpacity(ArkUIRuntimeCallInfo* runtimeCallInfo); 51 static ArkUINativeModuleValue SetTranslate(ArkUIRuntimeCallInfo* runtimeCallInfo); 52 static ArkUINativeModuleValue SetBorderStyle(ArkUIRuntimeCallInfo* runtimeCallInfo); 53 static ArkUINativeModuleValue SetBorderWidth(ArkUIRuntimeCallInfo* runtimeCallInfo); 54 static ArkUINativeModuleValue SetBorderColor(ArkUIRuntimeCallInfo* runtimeCallInfo); 55 static ArkUINativeModuleValue SetBorderRadius(ArkUIRuntimeCallInfo* runtimeCallInfo); 56 static ArkUINativeModuleValue SetRectMask(ArkUIRuntimeCallInfo* runtimeCallInfo); 57 static ArkUINativeModuleValue SetCircleMask(ArkUIRuntimeCallInfo* runtimeCallInfo); 58 static ArkUINativeModuleValue SetRoundRectMask(ArkUIRuntimeCallInfo* runtimeCallInfo); 59 static ArkUINativeModuleValue SetOvalMask(ArkUIRuntimeCallInfo* runtimeCallInfo); 60 static ArkUINativeModuleValue SetCommandPathMask(ArkUIRuntimeCallInfo* runtimeCallInfo); 61 static ArkUINativeModuleValue SetRectClip(ArkUIRuntimeCallInfo* runtimeCallInfo); 62 static ArkUINativeModuleValue SetCircleClip(ArkUIRuntimeCallInfo* runtimeCallInfo); 63 static ArkUINativeModuleValue SetRoundRectClip(ArkUIRuntimeCallInfo* runtimeCallInfo); 64 static ArkUINativeModuleValue SetOvalClip(ArkUIRuntimeCallInfo* runtimeCallInfo); 65 static ArkUINativeModuleValue SetCommandPathClip(ArkUIRuntimeCallInfo* runtimeCallInfo); 66 static ArkUINativeModuleValue Invalidate(ArkUIRuntimeCallInfo* runtimeCallInfo); 67 static ArkUINativeModuleValue SetMarkNodeGroup(ArkUIRuntimeCallInfo* runtimeCallInfo); 68 static ArkUINativeModuleValue FireArkUIObjectLifecycleCallback(ArkUIRuntimeCallInfo* runtimeCallInfo); 69 static ArkUINativeModuleValue GetNodeType(ArkUIRuntimeCallInfo* runtimeCallInfo); 70 71 template<typename T> GetNumber(EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,int index,T defaultValue)72 static T GetNumber(EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, int index, T defaultValue) 73 { 74 Local<JSValueRef> jsValueRef = runtimeCallInfo->GetCallArgRef(index); 75 T value = defaultValue; 76 if (jsValueRef->IsNumber()) { 77 if (std::is_same<T, uint32_t>::value) { 78 value = static_cast<uint32_t>(jsValueRef->Uint32Value(vm)); 79 } else if (std::is_same<T, int32_t>::value) { 80 value = jsValueRef->Int32Value(vm); 81 } else if (std::is_same<T, int64_t>::value) { 82 value = jsValueRef->IntegerValue(vm); 83 } else { 84 value = jsValueRef->ToNumber(vm)->Value(); 85 } 86 } 87 return value; 88 } 89 }; 90 } // namespace OHOS::Ace::NG 91 92 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JSI_NATIVEMODULE_ARKTS_NATIVE_RENDER_NODE_BRIDGE_H 93