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_panel_bridge.h"
16 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
17 #include "core/interfaces/native/node/api.h"
18 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
19
20 namespace OHOS::Ace::NG {
SetPanelBackgroundMask(ArkUIRuntimeCallInfo * runtimeCallInfo)21 ArkUINativeModuleValue PanelBridge::SetPanelBackgroundMask(ArkUIRuntimeCallInfo* runtimeCallInfo)
22 {
23 EcmaVM* vm = runtimeCallInfo->GetVM();
24 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
25 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
26 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
27 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
28
29 Color color;
30 if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) {
31 GetArkUIInternalNodeAPI()->GetPanelModifier().ResetPanelBackgroundMask(nativeNode);
32 } else {
33 GetArkUIInternalNodeAPI()->GetPanelModifier().SetPanelBackgroundMask(nativeNode, color.GetValue());
34 }
35 return panda::JSValueRef::Undefined(vm);
36 }
37
ResetPanelBackgroundMask(ArkUIRuntimeCallInfo * runtimeCallInfo)38 ArkUINativeModuleValue PanelBridge::ResetPanelBackgroundMask(ArkUIRuntimeCallInfo* runtimeCallInfo)
39 {
40 EcmaVM* vm = runtimeCallInfo->GetVM();
41 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
42 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
43 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
44 GetArkUIInternalNodeAPI()->GetPanelModifier().ResetPanelBackgroundMask(nativeNode);
45 return panda::JSValueRef::Undefined(vm);
46 }
47
SetPanelMode(ArkUIRuntimeCallInfo * runtimeCallInfo)48 ArkUINativeModuleValue PanelBridge::SetPanelMode(ArkUIRuntimeCallInfo* runtimeCallInfo)
49 {
50 EcmaVM* vm = runtimeCallInfo->GetVM();
51 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
52 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
53 Local<JSValueRef> modeArg = runtimeCallInfo->GetCallArgRef(1);
54 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
55 if (modeArg->IsNumber()) {
56 int32_t mode = modeArg->Int32Value(vm);
57 GetArkUIInternalNodeAPI()->GetPanelModifier().SetPanelMode(nativeNode, mode);
58 } else {
59 GetArkUIInternalNodeAPI()->GetPanelModifier().ResetPanelMode(nativeNode);
60 }
61 return panda::JSValueRef::Undefined(vm);
62 }
63
ResetPanelMode(ArkUIRuntimeCallInfo * runtimeCallInfo)64 ArkUINativeModuleValue PanelBridge::ResetPanelMode(ArkUIRuntimeCallInfo* runtimeCallInfo)
65 {
66 EcmaVM* vm = runtimeCallInfo->GetVM();
67 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
68 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
69 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
70 GetArkUIInternalNodeAPI()->GetPanelModifier().ResetPanelMode(nativeNode);
71 return panda::JSValueRef::Undefined(vm);
72 }
73
SetPanelType(ArkUIRuntimeCallInfo * runtimeCallInfo)74 ArkUINativeModuleValue PanelBridge::SetPanelType(ArkUIRuntimeCallInfo* runtimeCallInfo)
75 {
76 EcmaVM* vm = runtimeCallInfo->GetVM();
77 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
78 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
79 Local<JSValueRef> typeArg = runtimeCallInfo->GetCallArgRef(1);
80 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
81 if (typeArg->IsNumber()) {
82 int32_t type = typeArg->Int32Value(vm);
83 GetArkUIInternalNodeAPI()->GetPanelModifier().SetPanelType(nativeNode, type);
84 } else {
85 GetArkUIInternalNodeAPI()->GetPanelModifier().ResetPanelType(nativeNode);
86 }
87 return panda::JSValueRef::Undefined(vm);
88 }
89
ResetPanelType(ArkUIRuntimeCallInfo * runtimeCallInfo)90 ArkUINativeModuleValue PanelBridge::ResetPanelType(ArkUIRuntimeCallInfo* runtimeCallInfo)
91 {
92 EcmaVM* vm = runtimeCallInfo->GetVM();
93 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
94 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
95 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
96 GetArkUIInternalNodeAPI()->GetPanelModifier().ResetPanelType(nativeNode);
97 return panda::JSValueRef::Undefined(vm);
98 }
99
ResetPanelFullHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)100 ArkUINativeModuleValue PanelBridge::ResetPanelFullHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
101 {
102 EcmaVM* vm = runtimeCallInfo->GetVM();
103 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
104 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
105 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
106 GetArkUIInternalNodeAPI()->GetPanelModifier().ResetPanelFullHeight(nativeNode);
107 return panda::JSValueRef::Undefined(vm);
108 }
109
SetPanelFullHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)110 ArkUINativeModuleValue PanelBridge::SetPanelFullHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
111 {
112 EcmaVM* vm = runtimeCallInfo->GetVM();
113 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
114 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
115 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
116 Local<JSValueRef> jsValue = runtimeCallInfo->GetCallArgRef(1);
117 CalcDimension height;
118
119 if (jsValue->IsUndefined() || !ArkTSUtils::ParseJsDimensionVpNG(vm, jsValue, height, true)) {
120 GetArkUIInternalNodeAPI()->GetPanelModifier().ResetPanelFullHeight(nativeNode);
121 } else {
122 if (LessNotEqual(height.Value(), 0.0)) {
123 height.SetValue(0.0);
124 }
125 GetArkUIInternalNodeAPI()->GetPanelModifier().SetPanelFullHeight(
126 nativeNode, height.Value(), static_cast<int>(height.Unit()));
127 }
128 return panda::JSValueRef::Undefined(vm);
129 }
130
ResetPanelHalfHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)131 ArkUINativeModuleValue PanelBridge::ResetPanelHalfHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
132 {
133 EcmaVM* vm = runtimeCallInfo->GetVM();
134 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
135 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
136 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
137 GetArkUIInternalNodeAPI()->GetPanelModifier().ResetPanelHalfHeight(nativeNode);
138 return panda::JSValueRef::Undefined(vm);
139 }
140
SetPanelHalfHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)141 ArkUINativeModuleValue PanelBridge::SetPanelHalfHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
142 {
143 EcmaVM* vm = runtimeCallInfo->GetVM();
144 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
145 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
146 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
147 Local<JSValueRef> jsValue = runtimeCallInfo->GetCallArgRef(1);
148 CalcDimension height;
149
150 if (jsValue->IsUndefined() || !ArkTSUtils::ParseJsDimensionVpNG(vm, jsValue, height, true)) {
151 GetArkUIInternalNodeAPI()->GetPanelModifier().ResetPanelHalfHeight(nativeNode);
152 } else {
153 if (LessNotEqual(height.Value(), 0.0)) {
154 height.SetValue(0.0);
155 }
156 GetArkUIInternalNodeAPI()->GetPanelModifier().SetPanelHalfHeight(
157 nativeNode, height.Value(), static_cast<int>(height.Unit()));
158 }
159 return panda::JSValueRef::Undefined(vm);
160 }
161
ResetPanelMiniHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)162 ArkUINativeModuleValue PanelBridge::ResetPanelMiniHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
163 {
164 EcmaVM* vm = runtimeCallInfo->GetVM();
165 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
166 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
167 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
168 GetArkUIInternalNodeAPI()->GetPanelModifier().ResetPanelMiniHeight(nativeNode);
169 return panda::JSValueRef::Undefined(vm);
170 }
171
SetPanelMiniHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)172 ArkUINativeModuleValue PanelBridge::SetPanelMiniHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
173 {
174 EcmaVM* vm = runtimeCallInfo->GetVM();
175 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
176 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
177 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
178 Local<JSValueRef> jsValue = runtimeCallInfo->GetCallArgRef(1);
179 CalcDimension height;
180
181 if (jsValue->IsUndefined() || !ArkTSUtils::ParseJsDimensionVpNG(vm, jsValue, height, true)) {
182 GetArkUIInternalNodeAPI()->GetPanelModifier().ResetPanelMiniHeight(nativeNode);
183 } else {
184 if (LessNotEqual(height.Value(), 0.0)) {
185 height.SetValue(0.0);
186 }
187 GetArkUIInternalNodeAPI()->GetPanelModifier().SetPanelMiniHeight(
188 nativeNode, height.Value(), static_cast<int>(height.Unit()));
189 }
190 return panda::JSValueRef::Undefined(vm);
191 }
192
SetPanelCustomHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)193 ArkUINativeModuleValue PanelBridge::SetPanelCustomHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
194 {
195 EcmaVM* vm = runtimeCallInfo->GetVM();
196 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
197 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
198 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
199 Local<JSValueRef> jsValue = runtimeCallInfo->GetCallArgRef(1);
200 CalcDimension customHeight;
201
202 if (jsValue->IsUndefined()) {
203 GetArkUIInternalNodeAPI()->GetPanelModifier().ResetPanelCustomHeight(nativeNode);
204 return panda::JSValueRef::Undefined(vm);
205 }
206 if (jsValue->IsString() && jsValue->ToString(vm)->ToString().find("wrapContent") != std::string::npos) {
207 GetArkUIInternalNodeAPI()->GetPanelModifier().SetPanelCustomHeightByString(
208 nativeNode, jsValue->ToString(vm)->ToString().c_str());
209 return panda::JSValueRef::Undefined(vm);
210 } else if (!ArkTSUtils::ParseJsDimensionVp(vm, jsValue, customHeight)) {
211 customHeight = Dimension(0.0);
212 }
213 GetArkUIInternalNodeAPI()->GetPanelModifier().SetPanelCustomHeight(
214 nativeNode, customHeight.Value(), static_cast<int>(customHeight.Unit()));
215
216 return panda::JSValueRef::Undefined(vm);
217 }
218
ResetPanelCustomHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)219 ArkUINativeModuleValue PanelBridge::ResetPanelCustomHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
220 {
221 EcmaVM* vm = runtimeCallInfo->GetVM();
222 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
223 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
224 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
225 GetArkUIInternalNodeAPI()->GetPanelModifier().ResetPanelCustomHeight(nativeNode);
226 return panda::JSValueRef::Undefined(vm);
227 }
228
SetShowCloseIcon(ArkUIRuntimeCallInfo * runtimeCallInfo)229 ArkUINativeModuleValue PanelBridge::SetShowCloseIcon(ArkUIRuntimeCallInfo* runtimeCallInfo)
230 {
231 EcmaVM* vm = runtimeCallInfo->GetVM();
232 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
233 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
234 Local<JSValueRef> showCloseArg = runtimeCallInfo->GetCallArgRef(1);
235 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
236 if (showCloseArg->IsNull()) {
237 GetArkUIInternalNodeAPI()->GetPanelModifier().ResetShowCloseIcon(nativeNode);
238 return panda::JSValueRef::Undefined(vm);
239 }
240 bool boolValue = false;
241 if (showCloseArg->IsBoolean()) {
242 boolValue = showCloseArg->ToBoolean(vm)->Value();
243 }
244 GetArkUIInternalNodeAPI()->GetPanelModifier().SetShowCloseIcon(nativeNode, boolValue);
245 return panda::JSValueRef::Undefined(vm);
246 }
247
ResetShowCloseIcon(ArkUIRuntimeCallInfo * runtimeCallInfo)248 ArkUINativeModuleValue PanelBridge::ResetShowCloseIcon(ArkUIRuntimeCallInfo* runtimeCallInfo)
249 {
250 EcmaVM* vm = runtimeCallInfo->GetVM();
251 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
252 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
253 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
254 GetArkUIInternalNodeAPI()->GetPanelModifier().ResetShowCloseIcon(nativeNode);
255 return panda::JSValueRef::Undefined(vm);
256 }
257
SetDragBar(ArkUIRuntimeCallInfo * runtimeCallInfo)258 ArkUINativeModuleValue PanelBridge::SetDragBar(ArkUIRuntimeCallInfo* runtimeCallInfo)
259 {
260 EcmaVM* vm = runtimeCallInfo->GetVM();
261 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
262 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
263 Local<JSValueRef> dragBarArg = runtimeCallInfo->GetCallArgRef(1);
264 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
265 if (dragBarArg->IsNull()) {
266 GetArkUIInternalNodeAPI()->GetPanelModifier().ResetDragBar(nativeNode);
267 return panda::JSValueRef::Undefined(vm);
268 }
269 bool boolValue = true;
270 if (dragBarArg->IsBoolean()) {
271 boolValue = dragBarArg->ToBoolean(vm)->Value();
272 }
273 GetArkUIInternalNodeAPI()->GetPanelModifier().SetDragBar(nativeNode, boolValue);
274 return panda::JSValueRef::Undefined(vm);
275 }
276
ResetDragBar(ArkUIRuntimeCallInfo * runtimeCallInfo)277 ArkUINativeModuleValue PanelBridge::ResetDragBar(ArkUIRuntimeCallInfo* runtimeCallInfo)
278 {
279 EcmaVM* vm = runtimeCallInfo->GetVM();
280 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
281 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
282 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
283 GetArkUIInternalNodeAPI()->GetPanelModifier().ResetDragBar(nativeNode);
284 return panda::JSValueRef::Undefined(vm);
285 }
286
SetShow(ArkUIRuntimeCallInfo * runtimeCallInfo)287 ArkUINativeModuleValue PanelBridge::SetShow(ArkUIRuntimeCallInfo* runtimeCallInfo)
288 {
289 EcmaVM* vm = runtimeCallInfo->GetVM();
290 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
291 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
292 Local<JSValueRef> showArg = runtimeCallInfo->GetCallArgRef(1);
293 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
294 if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TEN) &&
295 (showArg->IsUndefined() || showArg->IsNull())) {
296 GetArkUIInternalNodeAPI()->GetPanelModifier().SetShow(nativeNode, true);
297 return panda::JSValueRef::Undefined(vm);
298 } else {
299 bool boolValue = true;
300 if (showArg->IsBoolean()) {
301 boolValue = showArg->ToBoolean(vm)->Value();
302 }
303 GetArkUIInternalNodeAPI()->GetPanelModifier().SetShow(nativeNode, boolValue);
304 return panda::JSValueRef::Undefined(vm);
305 }
306 }
307
ResetShow(ArkUIRuntimeCallInfo * runtimeCallInfo)308 ArkUINativeModuleValue PanelBridge::ResetShow(ArkUIRuntimeCallInfo* runtimeCallInfo)
309 {
310 EcmaVM* vm = runtimeCallInfo->GetVM();
311 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
312 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
313 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
314 GetArkUIInternalNodeAPI()->GetPanelModifier().ResetShow(nativeNode);
315 return panda::JSValueRef::Undefined(vm);
316 }
317 } // namespace OHOS::Ace::NG