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_select_bridge.h"
16
17 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
18 #include "bridge/declarative_frontend/jsview/js_view_abstract.h"
19 #include "core/interfaces/native/node/api.h"
20
21 namespace OHOS::Ace::NG {
22 const int32_t SIZE_OF_TWO = 2;
23 const std::string FORMAT_FONT = "%s|%s|%s";
24 const std::string DEFAULT_STR = "-1";
25
SetSpace(ArkUIRuntimeCallInfo * runtimeCallInfo)26 ArkUINativeModuleValue SelectBridge::SelectBridge::SetSpace(ArkUIRuntimeCallInfo* runtimeCallInfo)
27 {
28 EcmaVM* vm = runtimeCallInfo->GetVM();
29 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
30 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
31 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
32 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
33 auto pipeline = PipelineBase::GetCurrentContext();
34 CHECK_NULL_RETURN(pipeline, panda::NativePointerRef::New(vm, nullptr));
35 auto selectTheme = pipeline->GetTheme<SelectTheme>();
36 CHECK_NULL_RETURN(selectTheme, panda::NativePointerRef::New(vm, nullptr));
37
38 CalcDimension space;
39 if (!ArkTSUtils::ParseJsDimensionVp(vm, secondArg, space)) {
40 space = selectTheme->GetContentSpinnerPadding();
41 }
42 if (LessNotEqual(space.Value(), 0.0) || space.Unit() == DimensionUnit::PERCENT) {
43 space = selectTheme->GetContentSpinnerPadding();
44 }
45
46 GetArkUIInternalNodeAPI()->GetSelectModifier().SetSpace(
47 nativeNode, space.Value(), static_cast<int32_t>(space.Unit()));
48 return panda::JSValueRef::Undefined(vm);
49 }
50
SetValue(ArkUIRuntimeCallInfo * runtimeCallInfo)51 ArkUINativeModuleValue SelectBridge::SetValue(ArkUIRuntimeCallInfo* runtimeCallInfo)
52 {
53 EcmaVM* vm = runtimeCallInfo->GetVM();
54 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
55 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
56 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
57 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
58 std::string value;
59 ArkTSUtils::ParseJsString(vm, secondArg, value);
60 GetArkUIInternalNodeAPI()->GetSelectModifier().SetValue(nativeNode, value.c_str());
61 return panda::JSValueRef::Undefined(vm);
62 }
63
SetSelected(ArkUIRuntimeCallInfo * runtimeCallInfo)64 ArkUINativeModuleValue SelectBridge::SetSelected(ArkUIRuntimeCallInfo* runtimeCallInfo)
65 {
66 EcmaVM* vm = runtimeCallInfo->GetVM();
67 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
68 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
69 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
70 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
71 int32_t value = 0;
72 ArkTSUtils::ParseJsInteger(vm, secondArg, value);
73 GetArkUIInternalNodeAPI()->GetSelectModifier().SetSelected(nativeNode, value);
74 return panda::JSValueRef::Undefined(vm);
75 }
76
SetFontColor(ArkUIRuntimeCallInfo * runtimeCallInfo)77 ArkUINativeModuleValue SelectBridge::SetFontColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
78 {
79 EcmaVM* vm = runtimeCallInfo->GetVM();
80 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
81 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
82 Local<JSValueRef> colorArg = runtimeCallInfo->GetCallArgRef(1);
83 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
84
85 Color fontColor;
86 if (!ArkTSUtils::ParseJsColorAlpha(vm, colorArg, fontColor)) {
87 return ResetFontColor(runtimeCallInfo);
88 }
89 GetArkUIInternalNodeAPI()->GetSelectModifier().SetSelectFontColor(nativeNode, fontColor.GetValue());
90 return panda::JSValueRef::Undefined(vm);
91 }
92
SetSelectedOptionBgColor(ArkUIRuntimeCallInfo * runtimeCallInfo)93 ArkUINativeModuleValue SelectBridge::SetSelectedOptionBgColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
94 {
95 EcmaVM* vm = runtimeCallInfo->GetVM();
96 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
97 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
98 Local<JSValueRef> colorArg = runtimeCallInfo->GetCallArgRef(1);
99 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
100
101 Color selectedOptionBgColor;
102 if (!ArkTSUtils::ParseJsColorAlpha(vm, colorArg, selectedOptionBgColor)) {
103 return ResetSelectedOptionBgColor(runtimeCallInfo);
104 }
105
106 GetArkUIInternalNodeAPI()->GetSelectModifier().SetSelectedOptionBgColor(
107 nativeNode, selectedOptionBgColor.GetValue());
108 return panda::JSValueRef::Undefined(vm);
109 }
110
SetOptionBgColor(ArkUIRuntimeCallInfo * runtimeCallInfo)111 ArkUINativeModuleValue SelectBridge::SetOptionBgColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
112 {
113 EcmaVM* vm = runtimeCallInfo->GetVM();
114 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
115 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
116 Local<JSValueRef> colorArg = runtimeCallInfo->GetCallArgRef(1);
117 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
118
119 Color optionBgColor;
120 if (!ArkTSUtils::ParseJsColorAlpha(vm, colorArg, optionBgColor)) {
121 return ResetOptionBgColor(runtimeCallInfo);
122 }
123 GetArkUIInternalNodeAPI()->GetSelectModifier().SetOptionBgColor(nativeNode, optionBgColor.GetValue());
124 return panda::JSValueRef::Undefined(vm);
125 }
126
SetOptionFontColor(ArkUIRuntimeCallInfo * runtimeCallInfo)127 ArkUINativeModuleValue SelectBridge::SetOptionFontColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
128 {
129 EcmaVM* vm = runtimeCallInfo->GetVM();
130 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
131 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
132 Local<JSValueRef> colorArg = runtimeCallInfo->GetCallArgRef(1);
133 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
134
135 Color optionFontColor;
136 if (!ArkTSUtils::ParseJsColorAlpha(vm, colorArg, optionFontColor)) {
137 return ResetOptionFontColor(runtimeCallInfo);
138 }
139 GetArkUIInternalNodeAPI()->GetSelectModifier().SetOptionFontColor(nativeNode, optionFontColor.GetValue());
140 return panda::JSValueRef::Undefined(vm);
141 }
142
SetSelectedOptionFontColor(ArkUIRuntimeCallInfo * runtimeCallInfo)143 ArkUINativeModuleValue SelectBridge::SetSelectedOptionFontColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
144 {
145 EcmaVM* vm = runtimeCallInfo->GetVM();
146 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
147 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
148 Local<JSValueRef> colorArg = runtimeCallInfo->GetCallArgRef(1);
149 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
150 Color optionFontColor;
151 if (!ArkTSUtils::ParseJsColorAlpha(vm, colorArg, optionFontColor)) {
152 return ResetSelectedOptionFontColor(runtimeCallInfo);
153 }
154 GetArkUIInternalNodeAPI()->GetSelectModifier().SetSelectedOptionFontColor(nativeNode, optionFontColor.GetValue());
155 return panda::JSValueRef::Undefined(vm);
156 }
157
SetArrowPosition(ArkUIRuntimeCallInfo * runtimeCallInfo)158 ArkUINativeModuleValue SelectBridge::SelectBridge::SetArrowPosition(ArkUIRuntimeCallInfo* runtimeCallInfo)
159 {
160 EcmaVM* vm = runtimeCallInfo->GetVM();
161 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
162 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
163 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
164 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
165 int32_t arrowPosition = secondArg->Int32Value(vm);
166 GetArkUIInternalNodeAPI()->GetSelectModifier().SetArrowPosition(nativeNode, arrowPosition);
167 return panda::JSValueRef::Undefined(vm);
168 }
169
SetMenuAlign(ArkUIRuntimeCallInfo * runtimeCallInfo)170 ArkUINativeModuleValue SelectBridge::SetMenuAlign(ArkUIRuntimeCallInfo* runtimeCallInfo)
171 {
172 EcmaVM* vm = runtimeCallInfo->GetVM();
173 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
174 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
175 Local<JSValueRef> alignTypeArg = runtimeCallInfo->GetCallArgRef(1); // 1: index of alignType
176 Local<JSValueRef> offsetDx = runtimeCallInfo->GetCallArgRef(2); // 2: index of offset Dx
177 Local<JSValueRef> offsetDy = runtimeCallInfo->GetCallArgRef(3); // 3: index of offset Dy
178 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
179
180 int32_t alignType = 0;
181 if (alignTypeArg->IsNumber()) {
182 alignType = alignTypeArg->Int32Value(vm);
183 }
184
185 CalcDimension menuAlignOffsetDx = Dimension(0.0);
186 CalcDimension menuAlignOffsetDy = Dimension(0.0);
187 if (offsetDx->IsNull() || !ArkTSUtils::ParseJsDimensionVp(vm, offsetDx, menuAlignOffsetDx)) {
188 menuAlignOffsetDx = Dimension(0.0);
189 }
190
191 if (offsetDy->IsNull() || !ArkTSUtils::ParseJsDimensionVp(vm, offsetDy, menuAlignOffsetDy)) {
192 menuAlignOffsetDy = Dimension(0.0);
193 }
194
195 uint32_t size = SIZE_OF_TWO;
196 float values[size];
197 int32_t units[size];
198 values[0] = menuAlignOffsetDx.Value();
199 units[0] = static_cast<int32_t>(menuAlignOffsetDx.Unit());
200 values[1] = menuAlignOffsetDy.Value();
201 units[1] = static_cast<int32_t>(menuAlignOffsetDy.Unit());
202 GetArkUIInternalNodeAPI()->GetSelectModifier().SetMenuAlign(nativeNode, alignType, values, units, SIZE_OF_TWO);
203 return panda::JSValueRef::Undefined(vm);
204 }
205
SetFont(ArkUIRuntimeCallInfo * runtimeCallInfo)206 ArkUINativeModuleValue SelectBridge::SetFont(ArkUIRuntimeCallInfo* runtimeCallInfo)
207 {
208 EcmaVM* vm = runtimeCallInfo->GetVM();
209 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
210 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
211 Local<JSValueRef> fontSizeArg = runtimeCallInfo->GetCallArgRef(1); // 1: index of font size value
212 Local<JSValueRef> fontWeightArg = runtimeCallInfo->GetCallArgRef(2); // 2: index of font weight value
213 Local<JSValueRef> fontFamilyArg = runtimeCallInfo->GetCallArgRef(3); // 3: index of font family value
214 Local<JSValueRef> styleArg = runtimeCallInfo->GetCallArgRef(4); // 4: index of font style value
215 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
216
217 std::string fontSizeStr = DEFAULT_STR;
218 CalcDimension fontSize;
219 if (!fontSizeArg->IsNull() && !fontSizeArg->IsUndefined() &&
220 ArkTSUtils::ParseJsDimensionFp(vm, fontSizeArg, fontSize)) {
221 fontSizeStr = fontSize.ToString();
222 }
223
224 std::string fontWeight = DEFAULT_STR;
225 if (!fontWeightArg->IsNull() && !fontWeightArg->IsUndefined()) {
226 if (fontWeightArg->IsNumber()) {
227 fontWeight = std::to_string(fontWeightArg->Int32Value(vm));
228 } else {
229 if (!ArkTSUtils::ParseJsString(vm, fontWeightArg, fontWeight) || fontWeight.empty()) {
230 fontWeight = DEFAULT_STR;
231 }
232 }
233 }
234 std::string fontFamily;
235 if (!ArkTSUtils::ParseJsFontFamiliesToString(vm, fontFamilyArg, fontFamily) || fontFamily.empty()) {
236 fontFamily = DEFAULT_STR;
237 }
238 int32_t styleVal = 0;
239 if (!styleArg->IsNull() && !styleArg->IsUndefined() && styleArg->IsNumber()) {
240 styleVal = styleArg->Int32Value(vm);
241 }
242
243 std::string fontInfo =
244 StringUtils::FormatString(FORMAT_FONT.c_str(), fontSizeStr.c_str(), fontWeight.c_str(), fontFamily.c_str());
245
246 GetArkUIInternalNodeAPI()->GetSelectModifier().SetFont(nativeNode, fontInfo.c_str(), styleVal);
247 return panda::JSValueRef::Undefined(vm);
248 }
249
SetOptionFont(ArkUIRuntimeCallInfo * runtimeCallInfo)250 ArkUINativeModuleValue SelectBridge::SetOptionFont(ArkUIRuntimeCallInfo* runtimeCallInfo)
251 {
252 EcmaVM* vm = runtimeCallInfo->GetVM();
253 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
254 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
255 Local<JSValueRef> fontSizeArg = runtimeCallInfo->GetCallArgRef(1); // 1: index of font size value
256 Local<JSValueRef> fontWeightArg = runtimeCallInfo->GetCallArgRef(2); // 2: index of font weight value
257 Local<JSValueRef> fontFamilyArg = runtimeCallInfo->GetCallArgRef(3); // 3: index of font family value
258 Local<JSValueRef> styleArg = runtimeCallInfo->GetCallArgRef(4); // 4: index of font style value
259 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
260 auto pipeline = PipelineBase::GetCurrentContext();
261 CHECK_NULL_RETURN(pipeline, panda::NativePointerRef::New(vm, nullptr));
262 auto selectTheme = pipeline->GetTheme<SelectTheme>();
263
264 CalcDimension fontSize;
265 if (fontSizeArg->IsNull() || fontSizeArg->IsUndefined() ||
266 !ArkTSUtils::ParseJsDimensionFp(vm, fontSizeArg, fontSize)) {
267 fontSize = selectTheme->GetMenuFontSize();
268 }
269
270 std::string fontWeight = DEFAULT_STR;
271 if (!fontWeightArg->IsNull() && !fontWeightArg->IsUndefined()) {
272 if (fontWeightArg->IsNumber()) {
273 fontWeight = std::to_string(fontWeightArg->Int32Value(vm));
274 } else {
275 if (!ArkTSUtils::ParseJsString(vm, fontWeightArg, fontWeight) || fontWeight.empty()) {
276 fontWeight = DEFAULT_STR;
277 }
278 }
279 }
280 std::string fontFamily;
281 if (!ArkTSUtils::ParseJsFontFamiliesToString(vm, fontFamilyArg, fontFamily) || fontFamily.empty()) {
282 fontFamily = DEFAULT_STR;
283 }
284 int32_t styleVal = 0;
285 if (!styleArg->IsNull() && !styleArg->IsUndefined() && styleArg->IsNumber()) {
286 styleVal = styleArg->Int32Value(vm);
287 }
288 std::string fontSizeStr = fontSize.ToString();
289 std::string fontInfo =
290 StringUtils::FormatString(FORMAT_FONT.c_str(), fontSizeStr.c_str(), fontWeight.c_str(), fontFamily.c_str());
291
292 GetArkUIInternalNodeAPI()->GetSelectModifier().SetOptionFont(nativeNode, fontInfo.c_str(), styleVal);
293 return panda::JSValueRef::Undefined(vm);
294 }
295
SetSelectedOptionFont(ArkUIRuntimeCallInfo * runtimeCallInfo)296 ArkUINativeModuleValue SelectBridge::SetSelectedOptionFont(ArkUIRuntimeCallInfo* runtimeCallInfo)
297 {
298 EcmaVM* vm = runtimeCallInfo->GetVM();
299 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
300 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
301 Local<JSValueRef> fontSizeArg = runtimeCallInfo->GetCallArgRef(1); // 1: index of font size value
302 Local<JSValueRef> fontWeightArg = runtimeCallInfo->GetCallArgRef(2); // 2: index of font weight value
303 Local<JSValueRef> fontFamilyArg = runtimeCallInfo->GetCallArgRef(3); // 3: index of font family value
304 Local<JSValueRef> styleArg = runtimeCallInfo->GetCallArgRef(4); // 4: index of font style value
305 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
306
307 auto pipeline = PipelineBase::GetCurrentContext();
308 CHECK_NULL_RETURN(pipeline, panda::NativePointerRef::New(vm, nullptr));
309 auto selectTheme = pipeline->GetTheme<SelectTheme>();
310
311 CalcDimension fontSize;
312 if (fontSizeArg->IsNull() || fontSizeArg->IsUndefined() ||
313 !ArkTSUtils::ParseJsDimensionFp(vm, fontSizeArg, fontSize)) {
314 fontSize = selectTheme->GetFontSize();
315 }
316
317 std::string fontWeight = DEFAULT_STR;
318 if (!fontWeightArg->IsNull() && !fontWeightArg->IsUndefined()) {
319 if (fontWeightArg->IsNumber()) {
320 fontWeight = std::to_string(fontWeightArg->Int32Value(vm));
321 } else {
322 if (!ArkTSUtils::ParseJsString(vm, fontWeightArg, fontWeight) || fontWeight.empty()) {
323 fontWeight = DEFAULT_STR;
324 }
325 }
326 }
327 std::string fontFamily;
328 if (!ArkTSUtils::ParseJsFontFamiliesToString(vm, fontFamilyArg, fontFamily) || fontFamily.empty()) {
329 fontFamily = DEFAULT_STR;
330 }
331 int32_t styleVal = 0;
332 if (!styleArg->IsNull() && !styleArg->IsUndefined() && styleArg->IsNumber()) {
333 styleVal = styleArg->Int32Value(vm);
334 }
335 std::string fontSizeStr = fontSize.ToString();
336 std::string fontInfo =
337 StringUtils::FormatString(FORMAT_FONT.c_str(), fontSizeStr.c_str(), fontWeight.c_str(), fontFamily.c_str());
338
339 GetArkUIInternalNodeAPI()->GetSelectModifier().SetSelectedOptionFont(nativeNode, fontInfo.c_str(), styleVal);
340 return panda::JSValueRef::Undefined(vm);
341 }
342
ResetSpace(ArkUIRuntimeCallInfo * runtimeCallInfo)343 ArkUINativeModuleValue SelectBridge::ResetSpace(ArkUIRuntimeCallInfo* runtimeCallInfo)
344 {
345 EcmaVM* vm = runtimeCallInfo->GetVM();
346 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
347 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
348 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
349 GetArkUIInternalNodeAPI()->GetSelectModifier().ResetSpace(nativeNode);
350 return panda::JSValueRef::Undefined(vm);
351 }
352
ResetValue(ArkUIRuntimeCallInfo * runtimeCallInfo)353 ArkUINativeModuleValue SelectBridge::ResetValue(ArkUIRuntimeCallInfo* runtimeCallInfo)
354 {
355 EcmaVM* vm = runtimeCallInfo->GetVM();
356 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
357 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
358 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
359 GetArkUIInternalNodeAPI()->GetSelectModifier().ResetValue(nativeNode);
360 return panda::JSValueRef::Undefined(vm);
361 }
362
ResetSelected(ArkUIRuntimeCallInfo * runtimeCallInfo)363 ArkUINativeModuleValue SelectBridge::ResetSelected(ArkUIRuntimeCallInfo* runtimeCallInfo)
364 {
365 EcmaVM* vm = runtimeCallInfo->GetVM();
366 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
367 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
368 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
369 GetArkUIInternalNodeAPI()->GetSelectModifier().ResetSelected(nativeNode);
370 return panda::JSValueRef::Undefined(vm);
371 }
372
ResetFontColor(ArkUIRuntimeCallInfo * runtimeCallInfo)373 ArkUINativeModuleValue SelectBridge::ResetFontColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
374 {
375 EcmaVM* vm = runtimeCallInfo->GetVM();
376 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
377 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
378 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
379 GetArkUIInternalNodeAPI()->GetSelectModifier().ResetSelectFontColor(nativeNode);
380 return panda::JSValueRef::Undefined(vm);
381 }
382
ResetSelectedOptionBgColor(ArkUIRuntimeCallInfo * runtimeCallInfo)383 ArkUINativeModuleValue SelectBridge::ResetSelectedOptionBgColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
384 {
385 EcmaVM* vm = runtimeCallInfo->GetVM();
386 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
387 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
388 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
389 GetArkUIInternalNodeAPI()->GetSelectModifier().ResetSelectedOptionBgColor(nativeNode);
390 return panda::JSValueRef::Undefined(vm);
391 }
392
ResetOptionBgColor(ArkUIRuntimeCallInfo * runtimeCallInfo)393 ArkUINativeModuleValue SelectBridge::ResetOptionBgColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
394 {
395 EcmaVM* vm = runtimeCallInfo->GetVM();
396 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
397 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
398 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
399 GetArkUIInternalNodeAPI()->GetSelectModifier().ResetOptionBgColor(nativeNode);
400 return panda::JSValueRef::Undefined(vm);
401 }
402
ResetOptionFontColor(ArkUIRuntimeCallInfo * runtimeCallInfo)403 ArkUINativeModuleValue SelectBridge::ResetOptionFontColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
404 {
405 EcmaVM* vm = runtimeCallInfo->GetVM();
406 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
407 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
408 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
409 GetArkUIInternalNodeAPI()->GetSelectModifier().ResetOptionFontColor(nativeNode);
410 return panda::JSValueRef::Undefined(vm);
411 }
412
ResetSelectedOptionFontColor(ArkUIRuntimeCallInfo * runtimeCallInfo)413 ArkUINativeModuleValue SelectBridge::ResetSelectedOptionFontColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
414 {
415 EcmaVM* vm = runtimeCallInfo->GetVM();
416 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
417 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
418 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
419 GetArkUIInternalNodeAPI()->GetSelectModifier().ResetSelectedOptionFontColor(nativeNode);
420 return panda::JSValueRef::Undefined(vm);
421 }
422
ResetFont(ArkUIRuntimeCallInfo * runtimeCallInfo)423 ArkUINativeModuleValue SelectBridge::ResetFont(ArkUIRuntimeCallInfo* runtimeCallInfo)
424 {
425 EcmaVM* vm = runtimeCallInfo->GetVM();
426 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
427 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
428 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
429 GetArkUIInternalNodeAPI()->GetSelectModifier().ResetFont(nativeNode);
430 return panda::JSValueRef::Undefined(vm);
431 }
432
ResetOptionFont(ArkUIRuntimeCallInfo * runtimeCallInfo)433 ArkUINativeModuleValue SelectBridge::ResetOptionFont(ArkUIRuntimeCallInfo* runtimeCallInfo)
434 {
435 EcmaVM* vm = runtimeCallInfo->GetVM();
436 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
437 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
438 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
439 GetArkUIInternalNodeAPI()->GetSelectModifier().ResetOptionFont(nativeNode);
440 return panda::JSValueRef::Undefined(vm);
441 }
442
ResetSelectedOptionFont(ArkUIRuntimeCallInfo * runtimeCallInfo)443 ArkUINativeModuleValue SelectBridge::ResetSelectedOptionFont(ArkUIRuntimeCallInfo* runtimeCallInfo)
444 {
445 EcmaVM* vm = runtimeCallInfo->GetVM();
446 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
447 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
448 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
449 GetArkUIInternalNodeAPI()->GetSelectModifier().ResetSelectedOptionFont(nativeNode);
450 return panda::JSValueRef::Undefined(vm);
451 }
452
ResetMenuAlign(ArkUIRuntimeCallInfo * runtimeCallInfo)453 ArkUINativeModuleValue SelectBridge::ResetMenuAlign(ArkUIRuntimeCallInfo* runtimeCallInfo)
454 {
455 EcmaVM* vm = runtimeCallInfo->GetVM();
456 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
457 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
458 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
459 GetArkUIInternalNodeAPI()->GetSelectModifier().ResetMenuAlign(nativeNode);
460 return panda::JSValueRef::Undefined(vm);
461 }
462
ResetArrowPosition(ArkUIRuntimeCallInfo * runtimeCallInfo)463 ArkUINativeModuleValue SelectBridge::ResetArrowPosition(ArkUIRuntimeCallInfo* runtimeCallInfo)
464 {
465 EcmaVM* vm = runtimeCallInfo->GetVM();
466 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
467 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
468 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
469 GetArkUIInternalNodeAPI()->GetSelectModifier().ResetArrowPosition(nativeNode);
470 return panda::JSValueRef::Undefined(vm);
471 }
472
SetOptionWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)473 ArkUINativeModuleValue SelectBridge::SetOptionWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
474 {
475 EcmaVM* vm = runtimeCallInfo->GetVM();
476 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
477 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
478 Local<JSValueRef> optionWidthArg = runtimeCallInfo->GetCallArgRef(1);
479 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
480 CalcDimension width;
481 if (optionWidthArg->IsString()) {
482 std::string modeFlag = optionWidthArg->ToString(vm)->ToString();
483 if (modeFlag.compare("fit_content") == 0) {
484 GetArkUIInternalNodeAPI()->GetSelectModifier().SetOptionWidthFitTrigger(nativeNode, false);
485 return panda::JSValueRef::Undefined(vm);
486 } else if (modeFlag.compare("fit_trigger") == 0) {
487 GetArkUIInternalNodeAPI()->GetSelectModifier().SetOptionWidthFitTrigger(nativeNode, true);
488 return panda::JSValueRef::Undefined(vm);
489 } else if (ArkTSUtils::IsPercentStr(modeFlag)) {
490 return panda::JSValueRef::Undefined(vm);
491 } else {
492 ArkTSUtils::ParseJsDimensionVpNG(vm, optionWidthArg, width, false);
493 if (width.IsNegative()) {
494 width.Reset();
495 }
496 }
497 } else {
498 ArkTSUtils::ParseJsDimensionVpNG(vm, optionWidthArg, width, false);
499 if (width.IsNegative()) {
500 width.Reset();
501 }
502 }
503
504 GetArkUIInternalNodeAPI()->GetSelectModifier().SetSelectOptionWidth(
505 nativeNode, width.Value(), static_cast<int32_t>(width.Unit()));
506 return panda::JSValueRef::Undefined(vm);
507 }
508
ResetOptionWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)509 ArkUINativeModuleValue SelectBridge::ResetOptionWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
510 {
511 EcmaVM* vm = runtimeCallInfo->GetVM();
512 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
513 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
514 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
515 GetArkUIInternalNodeAPI()->GetSelectModifier().ResetSelectOptionWidth(nativeNode);
516 return panda::JSValueRef::Undefined(vm);
517 }
518
SetOptionHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)519 ArkUINativeModuleValue SelectBridge::SetOptionHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
520 {
521 EcmaVM* vm = runtimeCallInfo->GetVM();
522 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
523 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
524 Local<JSValueRef> optionHeightArg = runtimeCallInfo->GetCallArgRef(1);
525 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
526 CalcDimension height;
527 if (optionHeightArg->IsString()) {
528 std::string modeFlag = optionHeightArg->ToString(vm)->ToString();
529 if (ArkTSUtils::IsPercentStr(modeFlag)) {
530 return panda::JSValueRef::Undefined(vm);
531 }
532 }
533
534 ArkTSUtils::ParseJsDimensionVpNG(vm, optionHeightArg, height, false);
535 if (height.IsNegative()) {
536 return panda::JSValueRef::Undefined(vm);
537 }
538 if (NEAR_ZERO(height.Value())) {
539 return panda::JSValueRef::Undefined(vm);
540 }
541
542 GetArkUIInternalNodeAPI()->GetSelectModifier().SetSelectOptionHeight(
543 nativeNode, height.Value(), static_cast<int32_t>(height.Unit()));
544 return panda::JSValueRef::Undefined(vm);
545 }
546
ResetOptionHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)547 ArkUINativeModuleValue SelectBridge::ResetOptionHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
548 {
549 EcmaVM* vm = runtimeCallInfo->GetVM();
550 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
551 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
552 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
553 GetArkUIInternalNodeAPI()->GetSelectModifier().ResetSelectOptionHeight(nativeNode);
554 return panda::JSValueRef::Undefined(vm);
555 }
556
SetWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)557 ArkUINativeModuleValue SelectBridge::SetWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
558 {
559 EcmaVM* vm = runtimeCallInfo->GetVM();
560 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
561 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
562 Local<JSValueRef> widthArg = runtimeCallInfo->GetCallArgRef(1);
563 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
564 CalcDimension width;
565 if (!ArkTSUtils::ParseJsDimensionVp(vm, widthArg, width, false)) {
566 return panda::JSValueRef::Undefined(vm);
567 }
568 if (LessNotEqual(width.Value(), 0.0)) {
569 width.SetValue(0.0);
570 }
571 std::string widthCalc = width.CalcValue();
572 GetArkUIInternalNodeAPI()->GetSelectModifier().SetSelectWidth(
573 nativeNode, width.Value(), static_cast<int32_t>(width.Unit()), widthCalc.c_str());
574 return panda::JSValueRef::Undefined(vm);
575 }
576
ResetWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)577 ArkUINativeModuleValue SelectBridge::ResetWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
578 {
579 EcmaVM* vm = runtimeCallInfo->GetVM();
580 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
581 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
582 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
583 GetArkUIInternalNodeAPI()->GetSelectModifier().ResetSelectWidth(nativeNode);
584 return panda::JSValueRef::Undefined(vm);
585 }
586
SetHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)587 ArkUINativeModuleValue SelectBridge::SetHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
588 {
589 EcmaVM* vm = runtimeCallInfo->GetVM();
590 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
591 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
592 Local<JSValueRef> heightArg = runtimeCallInfo->GetCallArgRef(1);
593 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
594 CalcDimension height;
595 if (!ArkTSUtils::ParseJsDimensionVp(vm, heightArg, height, false)) {
596 return panda::JSValueRef::Undefined(vm);
597 }
598 if (LessNotEqual(height.Value(), 0.0)) {
599 height.SetValue(0.0);
600 }
601 std::string heightCalc = height.CalcValue();
602 GetArkUIInternalNodeAPI()->GetSelectModifier().SetSelectHeight(
603 nativeNode, height.Value(), static_cast<int32_t>(height.Unit()), heightCalc.c_str());
604 return panda::JSValueRef::Undefined(vm);
605 }
606
ResetHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)607 ArkUINativeModuleValue SelectBridge::ResetHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
608 {
609 EcmaVM* vm = runtimeCallInfo->GetVM();
610 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
611 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
612 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
613 GetArkUIInternalNodeAPI()->GetSelectModifier().ResetSelectHeight(nativeNode);
614 return panda::JSValueRef::Undefined(vm);
615 }
616
SetSize(ArkUIRuntimeCallInfo * runtimeCallInfo)617 ArkUINativeModuleValue SelectBridge::SetSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
618 {
619 EcmaVM* vm = runtimeCallInfo->GetVM();
620 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
621 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
622 Local<JSValueRef> widthArg = runtimeCallInfo->GetCallArgRef(1); // 1: index of width value
623 Local<JSValueRef> heightArg = runtimeCallInfo->GetCallArgRef(2); // 2: index of heigth value
624 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
625 CalcDimension width;
626 CalcDimension height;
627 if (widthArg->IsUndefined() || !ArkTSUtils::ParseJsDimensionVp(vm, widthArg, width, false)) {
628 return panda::JSValueRef::Undefined(vm);
629 }
630 if (LessNotEqual(width.Value(), 0.0)) {
631 width.SetValue(0.0);
632 }
633
634 if (heightArg->IsUndefined() || !ArkTSUtils::ParseJsDimensionVp(vm, heightArg, height, false)) {
635 return panda::JSValueRef::Undefined(vm);
636 }
637 if (LessNotEqual(height.Value(), 0.0)) {
638 height.SetValue(0.0);
639 }
640
641 std::string widthCalc = width.CalcValue();
642 std::string heightCalc = height.CalcValue();
643 GetArkUIInternalNodeAPI()->GetSelectModifier().SetSelectWidth(
644 nativeNode, width.Value(), static_cast<int32_t>(width.Unit()), widthCalc.c_str());
645 GetArkUIInternalNodeAPI()->GetSelectModifier().SetSelectHeight(
646 nativeNode, height.Value(), static_cast<int32_t>(height.Unit()), heightCalc.c_str());
647 return panda::JSValueRef::Undefined(vm);
648 }
649
ResetSize(ArkUIRuntimeCallInfo * runtimeCallInfo)650 ArkUINativeModuleValue SelectBridge::ResetSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
651 {
652 EcmaVM* vm = runtimeCallInfo->GetVM();
653 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
654 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
655 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
656 GetArkUIInternalNodeAPI()->GetSelectModifier().ResetSelectSize(nativeNode);
657 return panda::JSValueRef::Undefined(vm);
658 }
659 } // namespace OHOS::Ace::NG