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 AppendChild(ArkUIRuntimeCallInfo* runtimeCallInfo); 30 static ArkUINativeModuleValue InsertChildAfter(ArkUIRuntimeCallInfo* runtimeCallInfo); 31 static ArkUINativeModuleValue RemoveChild(ArkUIRuntimeCallInfo* runtimeCallInfo); 32 static ArkUINativeModuleValue ClearChildren(ArkUIRuntimeCallInfo* runtimeCallInfo); 33 static ArkUINativeModuleValue SetClipToFrame(ArkUIRuntimeCallInfo* runtimeCallInfo); 34 static ArkUINativeModuleValue SetRotation(ArkUIRuntimeCallInfo* runtimeCallInfo); 35 static ArkUINativeModuleValue SetShadowColor(ArkUIRuntimeCallInfo* runtimeCallInfo); 36 static ArkUINativeModuleValue SetShadowOffset(ArkUIRuntimeCallInfo* runtimeCallInfo); 37 static ArkUINativeModuleValue SetLabel(ArkUIRuntimeCallInfo* runtimeCallInfo); 38 static ArkUINativeModuleValue SetShadowAlpha(ArkUIRuntimeCallInfo* runtimeCallInfo); 39 static ArkUINativeModuleValue SetShadowElevation(ArkUIRuntimeCallInfo* runtimeCallInfo); 40 static ArkUINativeModuleValue SetShadowRadius(ArkUIRuntimeCallInfo* runtimeCallInfo); 41 static ArkUINativeModuleValue SetScale(ArkUIRuntimeCallInfo* runtimeCallInfo); 42 static ArkUINativeModuleValue SetBackgroundColor(ArkUIRuntimeCallInfo* runtimeCallInfo); 43 static ArkUINativeModuleValue SetPivot(ArkUIRuntimeCallInfo* runtimeCallInfo); 44 static ArkUINativeModuleValue SetFrame(ArkUIRuntimeCallInfo* runtimeCallInfo); 45 static ArkUINativeModuleValue SetSize(ArkUIRuntimeCallInfo* runtimeCallInfo); 46 static ArkUINativeModuleValue SetPosition(ArkUIRuntimeCallInfo* runtimeCallInfo); 47 static ArkUINativeModuleValue SetOpacity(ArkUIRuntimeCallInfo* runtimeCallInfo); 48 static ArkUINativeModuleValue SetTranslate(ArkUIRuntimeCallInfo* runtimeCallInfo); 49 static ArkUINativeModuleValue SetBorderStyle(ArkUIRuntimeCallInfo* runtimeCallInfo); 50 static ArkUINativeModuleValue SetBorderWidth(ArkUIRuntimeCallInfo* runtimeCallInfo); 51 static ArkUINativeModuleValue SetBorderColor(ArkUIRuntimeCallInfo* runtimeCallInfo); 52 static ArkUINativeModuleValue SetBorderRadius(ArkUIRuntimeCallInfo* runtimeCallInfo); 53 static ArkUINativeModuleValue SetRectMask(ArkUIRuntimeCallInfo* runtimeCallInfo); 54 static ArkUINativeModuleValue SetCircleMask(ArkUIRuntimeCallInfo* runtimeCallInfo); 55 static ArkUINativeModuleValue SetRoundRectMask(ArkUIRuntimeCallInfo* runtimeCallInfo); 56 static ArkUINativeModuleValue SetOvalMask(ArkUIRuntimeCallInfo* runtimeCallInfo); 57 static ArkUINativeModuleValue SetCommandPathMask(ArkUIRuntimeCallInfo* runtimeCallInfo); 58 static ArkUINativeModuleValue SetRectClip(ArkUIRuntimeCallInfo* runtimeCallInfo); 59 static ArkUINativeModuleValue SetCircleClip(ArkUIRuntimeCallInfo* runtimeCallInfo); 60 static ArkUINativeModuleValue SetRoundRectClip(ArkUIRuntimeCallInfo* runtimeCallInfo); 61 static ArkUINativeModuleValue SetOvalClip(ArkUIRuntimeCallInfo* runtimeCallInfo); 62 static ArkUINativeModuleValue SetCommandPathClip(ArkUIRuntimeCallInfo* runtimeCallInfo); 63 static ArkUINativeModuleValue Invalidate(ArkUIRuntimeCallInfo* runtimeCallInfo); 64 static ArkUINativeModuleValue SetMarkNodeGroup(ArkUIRuntimeCallInfo* runtimeCallInfo); 65 66 template<typename T> GetNumber(EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,int index,T defaultValue)67 static T GetNumber(EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, int index, T defaultValue) 68 { 69 Local<JSValueRef> jsValueRef = runtimeCallInfo->GetCallArgRef(index); 70 T value = defaultValue; 71 if (jsValueRef->IsNumber()) { 72 if (std::is_same<T, uint32_t>::value) { 73 value = static_cast<uint32_t>(jsValueRef->Uint32Value(vm)); 74 } else if (std::is_same<T, int32_t>::value) { 75 value = jsValueRef->Int32Value(vm); 76 } else if (std::is_same<T, int64_t>::value) { 77 value = jsValueRef->IntegerValue(vm); 78 } else { 79 value = jsValueRef->ToNumber(vm)->Value(); 80 } 81 } 82 return value; 83 } 84 }; 85 } // namespace OHOS::Ace::NG 86 87 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JSI_NATIVEMODULE_ARKTS_NATIVE_RENDER_NODE_BRIDGE_H 88