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
16 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_form_component_bridge.h"
17 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.h"
18 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
19
20 namespace OHOS::Ace::NG {
SetVisibility(ArkUIRuntimeCallInfo * runtimeCallInfo)21 ArkUINativeModuleValue FormComponentBridge::SetVisibility(ArkUIRuntimeCallInfo* runtimeCallInfo)
22 {
23 EcmaVM* vm = runtimeCallInfo->GetVM();
24 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
25 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
26 Local<JSValueRef> visibilityArg = runtimeCallInfo->GetCallArgRef(1);
27 CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
28 CHECK_NULL_RETURN(visibilityArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
29 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
30 int32_t visibility = visibilityArg->Int32Value(vm);
31 GetArkUINodeModifiers()->getFormComponentModifier()->setFormVisibility(nativeNode, visibility);
32 return panda::JSValueRef::Undefined(vm);
33 }
34
ResetVisibility(ArkUIRuntimeCallInfo * runtimeCallInfo)35 ArkUINativeModuleValue FormComponentBridge::ResetVisibility(ArkUIRuntimeCallInfo* runtimeCallInfo)
36 {
37 EcmaVM* vm = runtimeCallInfo->GetVM();
38 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
39 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
40 CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
41 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
42 GetArkUINodeModifiers()->getFormComponentModifier()->resetFormVisibility(nativeNode);
43 return panda::JSValueRef::Undefined(vm);
44 }
45
AllowUpdate(ArkUIRuntimeCallInfo * runtimeCallInfo)46 ArkUINativeModuleValue FormComponentBridge::AllowUpdate(ArkUIRuntimeCallInfo* runtimeCallInfo)
47 {
48 EcmaVM* vm = runtimeCallInfo->GetVM();
49 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
50 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
51 Local<JSValueRef> allowUpdateArg = runtimeCallInfo->GetCallArgRef(1);
52 CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
53 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
54 bool allowUpdate = allowUpdateArg->ToBoolean(vm)->Value();
55 GetArkUINodeModifiers()->getFormComponentModifier()->allowUpdate(nativeNode, allowUpdate);
56 return panda::JSValueRef::Undefined(vm);
57 }
58
DisallowUpdate(ArkUIRuntimeCallInfo * runtimeCallInfo)59 ArkUINativeModuleValue FormComponentBridge::DisallowUpdate(ArkUIRuntimeCallInfo* runtimeCallInfo)
60 {
61 EcmaVM* vm = runtimeCallInfo->GetVM();
62 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
63 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
64 CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
65 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
66 GetArkUINodeModifiers()->getFormComponentModifier()->disallowUpdate(nativeNode);
67 return panda::JSValueRef::Undefined(vm);
68 }
69
SetDimension(ArkUIRuntimeCallInfo * runtimeCallInfo)70 ArkUINativeModuleValue FormComponentBridge::SetDimension(ArkUIRuntimeCallInfo* runtimeCallInfo)
71 {
72 EcmaVM* vm = runtimeCallInfo->GetVM();
73 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
74 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
75 Local<JSValueRef> dimensionArg = runtimeCallInfo->GetCallArgRef(1);
76 CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
77 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
78 if (dimensionArg->IsNull() || dimensionArg->IsUndefined()) {
79 GetArkUINodeModifiers()->getFormComponentModifier()->resetDimension(nativeNode);
80 } else {
81 int32_t dimension = dimensionArg->Int32Value(vm);
82 GetArkUINodeModifiers()->getFormComponentModifier()->setDimension(nativeNode, dimension);
83 }
84 return panda::JSValueRef::Undefined(vm);
85 }
86
ResetDimension(ArkUIRuntimeCallInfo * runtimeCallInfo)87 ArkUINativeModuleValue FormComponentBridge::ResetDimension(ArkUIRuntimeCallInfo* runtimeCallInfo)
88 {
89 EcmaVM* vm = runtimeCallInfo->GetVM();
90 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
91 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
92 CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
93 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
94 GetArkUINodeModifiers()->getFormComponentModifier()->resetDimension(nativeNode);
95 return panda::JSValueRef::Undefined(vm);
96 }
97
SetModuleName(ArkUIRuntimeCallInfo * runtimeCallInfo)98 ArkUINativeModuleValue FormComponentBridge::SetModuleName(ArkUIRuntimeCallInfo* runtimeCallInfo)
99 {
100 EcmaVM* vm = runtimeCallInfo->GetVM();
101 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
102 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
103 Local<JSValueRef> moduleNameArg = runtimeCallInfo->GetCallArgRef(1);
104 CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
105 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
106 if (moduleNameArg->IsNull() || moduleNameArg->IsUndefined()) {
107 GetArkUINodeModifiers()->getFormComponentModifier()->resetModuleName(nativeNode);
108 } else {
109 std::string moduleName = moduleNameArg->ToString(vm)->ToString(vm);
110 GetArkUINodeModifiers()->getFormComponentModifier()->setModuleName(nativeNode, moduleName.c_str());
111 }
112 return panda::JSValueRef::Undefined(vm);
113 }
114
ResetModuleName(ArkUIRuntimeCallInfo * runtimeCallInfo)115 ArkUINativeModuleValue FormComponentBridge::ResetModuleName(ArkUIRuntimeCallInfo* runtimeCallInfo)
116 {
117 EcmaVM* vm = runtimeCallInfo->GetVM();
118 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
119 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
120 CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
121 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
122 GetArkUINodeModifiers()->getFormComponentModifier()->resetModuleName(nativeNode);
123 return panda::JSValueRef::Undefined(vm);
124 }
125
SetSize(ArkUIRuntimeCallInfo * runtimeCallInfo)126 ArkUINativeModuleValue FormComponentBridge::SetSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
127 {
128 EcmaVM* vm = runtimeCallInfo->GetVM();
129 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
130 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
131 Local<JSValueRef> widthValue = runtimeCallInfo->GetCallArgRef(1);
132 Local<JSValueRef> heightValue = runtimeCallInfo->GetCallArgRef(2);
133 CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
134 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
135 CommonBridge::SetSize(runtimeCallInfo);
136 CalcDimension width = 0.0_vp;
137 CalcDimension height = 0.0_vp;
138 bool hasWidth = (!widthValue->IsNull() && !widthValue->IsUndefined() &&
139 ArkTSUtils::ParseJsDimensionVp(vm, widthValue, width));
140 bool hasHeight = (!heightValue->IsNull() && !heightValue->IsUndefined() &&
141 ArkTSUtils::ParseJsDimensionVp(vm, heightValue, height));
142 if (!hasWidth && !hasHeight) {
143 GetArkUINodeModifiers()->getFormComponentModifier()->resetFormSize(nativeNode);
144 } else {
145 GetArkUINodeModifiers()->getFormComponentModifier()->setFormSize(nativeNode,
146 width.Value(), static_cast<int>(width.Unit()), height.Value(), static_cast<int>(height.Unit()));
147 }
148 return panda::JSValueRef::Undefined(vm);
149 }
150
ResetSize(ArkUIRuntimeCallInfo * runtimeCallInfo)151 ArkUINativeModuleValue FormComponentBridge::ResetSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
152 {
153 EcmaVM* vm = runtimeCallInfo->GetVM();
154 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
155 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
156 CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
157 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
158 CommonBridge::ResetSize(runtimeCallInfo);
159 GetArkUINodeModifiers()->getFormComponentModifier()->resetFormSize(nativeNode);
160 return panda::JSValueRef::Undefined(vm);
161 }
162 }