1 /*
2 * Copyright (c) 2023 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 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_plugin_bridge.h"
16 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
17
18 namespace OHOS::Ace::NG {
19
SetSize(ArkUIRuntimeCallInfo * runtimeCallInfo)20 ArkUINativeModuleValue PluginBridge::SetSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
21 {
22 EcmaVM* vm = runtimeCallInfo->GetVM();
23 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
24 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0); // 0: index of parameter frameNode
25 Local<JSValueRef> widthArg = runtimeCallInfo->GetCallArgRef(1); // 1: index of parameter width
26 Local<JSValueRef> heightArg = runtimeCallInfo->GetCallArgRef(2); // 2: index of parameter height
27 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
28
29 CalcDimension width = 0.0_vp;
30 CalcDimension height = 0.0_vp;
31 if (!(ArkTSUtils::ParseJsDimensionVp(vm, widthArg, width, false)) ||
32 !(ArkTSUtils::ParseJsDimensionVp(vm, heightArg, height, false))) {
33 GetArkUINodeModifiers()->getPluginModifier()->resetPluginSize(nativeNode);
34 return panda::JSValueRef::Undefined(vm);
35 }
36 if (LessNotEqual(width.Value(), 0.0)) {
37 width.SetValue(0.0);
38 }
39 if (LessNotEqual(height.Value(), 0.0)) {
40 height.SetValue(0.0);
41 }
42
43 GetArkUINodeModifiers()->getPluginModifier()->setPluginSize(nativeNode, width.Value(), height.Value(),
44 static_cast<int32_t>(width.Unit()), static_cast<int32_t>(height.Unit()));
45 return panda::JSValueRef::Undefined(vm);
46 }
47
SetWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)48 ArkUINativeModuleValue PluginBridge::SetWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
49 {
50 EcmaVM* vm = runtimeCallInfo->GetVM();
51 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
52 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
53 Local<JSValueRef> widthArg = runtimeCallInfo->GetCallArgRef(1);
54 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
55
56 CalcDimension width = 0.0_vp;
57 if (!ArkTSUtils::ParseJsDimensionVp(vm, widthArg, width)) {
58 GetArkUINodeModifiers()->getPluginModifier()->resetPluginWidth(nativeNode);
59 }
60 if (LessNotEqual(width.Value(), 0.0)) {
61 width.SetValue(0.0);
62 }
63
64 GetArkUINodeModifiers()->getPluginModifier()->setPluginWidth(
65 nativeNode, width.Value(), static_cast<int32_t>(width.Unit()));
66 return panda::JSValueRef::Undefined(vm);
67 }
68
SetHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)69 ArkUINativeModuleValue PluginBridge::SetHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
70 {
71 EcmaVM* vm = runtimeCallInfo->GetVM();
72 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
73 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
74 Local<JSValueRef> heightArg = runtimeCallInfo->GetCallArgRef(1);
75 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
76
77 CalcDimension height = 0.0_vp;
78 if (!ArkTSUtils::ParseJsDimensionVp(vm, heightArg, height)) {
79 GetArkUINodeModifiers()->getPluginModifier()->resetPluginHeight(nativeNode);
80 }
81 if (LessNotEqual(height.Value(), 0.0)) {
82 height.SetValue(0.0);
83 }
84
85 GetArkUINodeModifiers()->getPluginModifier()->setPluginHeight(
86 nativeNode, height.Value(), static_cast<int32_t>(height.Unit()));
87 return panda::JSValueRef::Undefined(vm);
88 }
89
ResetSize(ArkUIRuntimeCallInfo * runtimeCallInfo)90 ArkUINativeModuleValue PluginBridge::ResetSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
91 {
92 EcmaVM* vm = runtimeCallInfo->GetVM();
93 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
94 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
95 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
96 GetArkUINodeModifiers()->getPluginModifier()->resetPluginSize(nativeNode);
97 return panda::JSValueRef::Undefined(vm);
98 }
99
ResetWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)100 ArkUINativeModuleValue PluginBridge::ResetWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
101 {
102 EcmaVM* vm = runtimeCallInfo->GetVM();
103 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
104 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
105 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
106 GetArkUINodeModifiers()->getPluginModifier()->resetPluginWidth(nativeNode);
107 return panda::JSValueRef::Undefined(vm);
108 }
109
ResetHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)110 ArkUINativeModuleValue PluginBridge::ResetHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
111 {
112 EcmaVM* vm = runtimeCallInfo->GetVM();
113 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
114 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
115 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
116 GetArkUINodeModifiers()->getPluginModifier()->resetPluginHeight(nativeNode);
117 return panda::JSValueRef::Undefined(vm);
118 }
119 } // namespace OHOS::Ace::NG