• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_alphabet_indexer_bridge.h"
16 
17 #include "core/interfaces/native/node/api.h"
18 #include "bridge/declarative_frontend/jsview/models/indexer_model_impl.h"
19 #include "frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
20 
21 namespace OHOS::Ace::NG {
22 namespace {
23 constexpr int NUM_0 = 0;
24 constexpr int NUM_1 = 1;
25 constexpr int NUM_2 = 2;
26 constexpr int NUM_3 = 3;
27 constexpr int NUM_4 = 4;
28 const std::string FORMAT_FONT = "%s|%s|%s";
29 const std::string DEFAULT_FAMILY = "HarmonyOS Sans";
30 constexpr double DEFAULT_POPUPITEMFONT_SIZE = 24.0;
31 constexpr Dimension DEFAULT_FONT_SIZE_VAL = 12.0_fp;
32 const std::string DEFAULT_POPUP_ITEM_FONT_WEIGHT = "medium";
33 constexpr Dimension DEFAULT_POPUP_POSITION_X = 60.0_vp;
34 constexpr Dimension DEFAULT_POPUP_POSITION_Y = 48.0_vp;
35 
ParseJsInteger(const EcmaVM * vm,const Local<JSValueRef> & value,int32_t & result)36 bool ParseJsInteger(const EcmaVM* vm, const Local<JSValueRef>& value, int32_t& result)
37 {
38     if (value->IsNumber()) {
39         result = value->Int32Value(vm);
40         return true;
41     }
42     // resouce ignore by design
43     return false;
44 }
45 
ParseJsDimensionVp(const EcmaVM * vm,const Local<JSValueRef> & value,CalcDimension & result)46 bool ParseJsDimensionVp(const EcmaVM* vm, const Local<JSValueRef>& value, CalcDimension& result)
47 {
48     if (value->IsNumber()) {
49         result = CalcDimension(value->ToNumber(vm)->Value(), DimensionUnit::VP);
50         return true;
51     }
52     if (value->IsString()) {
53         result = StringUtils::StringToCalcDimension(value->ToString(vm)->ToString(), false, DimensionUnit::VP);
54         return true;
55     }
56     // resouce ignore by design
57     return false;
58 }
59 } // namespace
60 
SetPopupItemFont(ArkUIRuntimeCallInfo * runtimeCallInfo)61 ArkUINativeModuleValue AlphabetIndexerBridge::SetPopupItemFont(ArkUIRuntimeCallInfo* runtimeCallInfo)
62 {
63     EcmaVM* vm = runtimeCallInfo->GetVM();
64     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
65     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
66     Local<JSValueRef> fontSizeArg = runtimeCallInfo->GetCallArgRef(NUM_1);
67     Local<JSValueRef> weightArg = runtimeCallInfo->GetCallArgRef(NUM_2);
68     void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
69     CalcDimension fontSize;
70     if (fontSizeArg->IsNull() || fontSizeArg->IsUndefined() ||
71         !ArkTSUtils::ParseJsDimensionFp(vm, fontSizeArg, fontSize)) {
72         fontSize = Dimension(DEFAULT_POPUPITEMFONT_SIZE, DimensionUnit::FP);
73     }
74     std::string weight = DEFAULT_POPUP_ITEM_FONT_WEIGHT;
75     if (!weightArg->IsNull() && !weightArg->IsUndefined()) {
76         if (weightArg->IsNumber()) {
77             weight = std::to_string(weightArg->Int32Value(vm));
78         } else {
79             if (ArkTSUtils::ParseJsString(vm, weightArg, weight) || weight.empty()) {
80                 weight = DEFAULT_POPUP_ITEM_FONT_WEIGHT;
81             }
82         }
83     }
84     GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().SetPopupItemFont(
85         nativeNode, fontSize.Value(), static_cast<int>(fontSize.Unit()), weight.c_str());
86     return panda::JSValueRef::Undefined(vm);
87 }
88 
ResetPopupItemFont(ArkUIRuntimeCallInfo * runtimeCallInfo)89 ArkUINativeModuleValue AlphabetIndexerBridge::ResetPopupItemFont(ArkUIRuntimeCallInfo* runtimeCallInfo)
90 {
91     EcmaVM* vm = runtimeCallInfo->GetVM();
92     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
93     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
94     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
95     GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().ResetPopupItemFont(nativeNode);
96     return panda::JSValueRef::Undefined(vm);
97 }
98 
SetSelectedFont(ArkUIRuntimeCallInfo * runtimeCallInfo)99 ArkUINativeModuleValue AlphabetIndexerBridge::SetSelectedFont(ArkUIRuntimeCallInfo* runtimeCallInfo)
100 {
101     EcmaVM* vm = runtimeCallInfo->GetVM();
102     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
103     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
104     Local<JSValueRef> fontSizeArg = runtimeCallInfo->GetCallArgRef(NUM_1);
105     Local<JSValueRef> weightArg = runtimeCallInfo->GetCallArgRef(NUM_2);
106     Local<JSValueRef> fontFamilyArg = runtimeCallInfo->GetCallArgRef(NUM_3);
107     Local<JSValueRef> styleValArg = runtimeCallInfo->GetCallArgRef(NUM_4);
108     void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
109     if ((fontSizeArg->IsNull() || fontSizeArg->IsUndefined()) && (weightArg->IsNull() || weightArg->IsUndefined()) &&
110         (fontFamilyArg->IsNull() || fontFamilyArg->IsUndefined()) &&
111         (styleValArg->IsNull() || styleValArg->IsUndefined())) {
112         GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().ResetSelectedFont(nativeNode);
113     }
114     CalcDimension fontSizeData(DEFAULT_FONT_SIZE_VAL);
115     std::string fontSize = fontSizeData.ToString();
116     if (!fontSizeArg->IsNull() && !fontSizeArg->IsUndefined() &&
117         ArkTSUtils::ParseJsDimensionFp(vm, fontSizeArg, fontSizeData) && !fontSizeData.IsNegative() &&
118         fontSizeData.Unit() != DimensionUnit::PERCENT) {
119         fontSize = fontSizeData.ToString();
120     }
121     std::string weight = "normal";
122     if (!weightArg->IsNull() && !weightArg->IsUndefined() && (weightArg->IsString() || weightArg->IsNumber())) {
123         weight = weightArg->ToString(vm)->ToString();
124     }
125     std::string fontFamily;
126     if (!ArkTSUtils::ParseJsFontFamiliesToString(vm, fontFamilyArg, fontFamily) || fontFamily.empty()) {
127         fontFamily = DEFAULT_FAMILY;
128     }
129     int32_t styleVal = 0;
130     if (!styleValArg->IsNull() && !styleValArg->IsUndefined() && styleValArg->IsNumber()) {
131         styleVal = styleValArg->Int32Value(vm);
132     }
133     std::string fontInfo =
134         StringUtils::FormatString(FORMAT_FONT.c_str(), fontSize.c_str(), weight.c_str(), fontFamily.c_str());
135     GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().SetSelectedFont(nativeNode, fontInfo.c_str(), styleVal);
136     return panda::JSValueRef::Undefined(vm);
137 }
138 
ResetSelectedFont(ArkUIRuntimeCallInfo * runtimeCallInfo)139 ArkUINativeModuleValue AlphabetIndexerBridge::ResetSelectedFont(ArkUIRuntimeCallInfo* runtimeCallInfo)
140 {
141     EcmaVM* vm = runtimeCallInfo->GetVM();
142     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
143     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
144     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
145     GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().ResetSelectedFont(nativeNode);
146     return panda::JSValueRef::Undefined(vm);
147 }
148 
SetPopupFont(ArkUIRuntimeCallInfo * runtimeCallInfo)149 ArkUINativeModuleValue AlphabetIndexerBridge::SetPopupFont(ArkUIRuntimeCallInfo* runtimeCallInfo)
150 {
151     EcmaVM* vm = runtimeCallInfo->GetVM();
152     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
153     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
154     Local<JSValueRef> fontSizeArg = runtimeCallInfo->GetCallArgRef(NUM_1);
155     Local<JSValueRef> weightArg = runtimeCallInfo->GetCallArgRef(NUM_2);
156     Local<JSValueRef> fontFamilyArg = runtimeCallInfo->GetCallArgRef(NUM_3);
157     Local<JSValueRef> styleValArg = runtimeCallInfo->GetCallArgRef(NUM_4);
158     void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
159     if ((fontSizeArg->IsNull() || fontSizeArg->IsUndefined()) && (weightArg->IsNull() || weightArg->IsUndefined()) &&
160         (fontFamilyArg->IsNull() || fontFamilyArg->IsUndefined()) &&
161         (styleValArg->IsNull() || styleValArg->IsUndefined())) {
162         GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().ResetPopupFont(nativeNode);
163     }
164     CalcDimension fontSizeData(DEFAULT_FONT_SIZE_VAL);
165     std::string fontSize = fontSizeData.ToString();
166     if (!fontSizeArg->IsNull() && !fontSizeArg->IsUndefined() &&
167         ArkTSUtils::ParseJsDimensionFp(vm, fontSizeArg, fontSizeData) && !fontSizeData.IsNegative() &&
168         fontSizeData.Unit() != DimensionUnit::PERCENT) {
169         fontSize = fontSizeData.ToString();
170     }
171     std::string weight = "normal";
172     if (!weightArg->IsNull() && !weightArg->IsUndefined() && (weightArg->IsString() || weightArg->IsNumber())) {
173         weight = weightArg->ToString(vm)->ToString();
174     }
175     std::string fontFamily;
176     if (!ArkTSUtils::ParseJsFontFamiliesToString(vm, fontFamilyArg, fontFamily) || fontFamily.empty()) {
177         fontFamily = DEFAULT_FAMILY;
178     }
179     int32_t styleVal = 0;
180     if (!styleValArg->IsNull() && !styleValArg->IsUndefined() && styleValArg->IsNumber()) {
181         styleVal = styleValArg->Int32Value(vm);
182     }
183     std::string fontInfo =
184         StringUtils::FormatString(FORMAT_FONT.c_str(), fontSize.c_str(), weight.c_str(), fontFamily.c_str());
185     GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().SetPopupFont(nativeNode, fontInfo.c_str(), styleVal);
186     return panda::JSValueRef::Undefined(vm);
187 }
188 
ResetPopupFont(ArkUIRuntimeCallInfo * runtimeCallInfo)189 ArkUINativeModuleValue AlphabetIndexerBridge::ResetPopupFont(ArkUIRuntimeCallInfo* runtimeCallInfo)
190 {
191     EcmaVM* vm = runtimeCallInfo->GetVM();
192     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
193     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
194     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
195     GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().ResetPopupFont(nativeNode);
196     return panda::JSValueRef::Undefined(vm);
197 }
198 
SetFont(ArkUIRuntimeCallInfo * runtimeCallInfo)199 ArkUINativeModuleValue AlphabetIndexerBridge::SetFont(ArkUIRuntimeCallInfo* runtimeCallInfo)
200 {
201     EcmaVM* vm = runtimeCallInfo->GetVM();
202     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
203     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
204     Local<JSValueRef> fontSizeArg = runtimeCallInfo->GetCallArgRef(NUM_1);
205     Local<JSValueRef> weightArg = runtimeCallInfo->GetCallArgRef(NUM_2);
206     Local<JSValueRef> fontFamilyArg = runtimeCallInfo->GetCallArgRef(NUM_3);
207     Local<JSValueRef> styleValArg = runtimeCallInfo->GetCallArgRef(NUM_4);
208     void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
209     if ((fontSizeArg->IsNull() || fontSizeArg->IsUndefined()) && (weightArg->IsNull() || weightArg->IsUndefined()) &&
210         (fontFamilyArg->IsNull() || fontFamilyArg->IsUndefined()) &&
211         (styleValArg->IsNull() || styleValArg->IsUndefined())) {
212         GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().ResetAlphabetIndexerFont(nativeNode);
213     }
214     CalcDimension fontSizeData(DEFAULT_FONT_SIZE_VAL);
215     std::string fontSize = fontSizeData.ToString();
216     if (!fontSizeArg->IsNull() && !fontSizeArg->IsUndefined() &&
217         ArkTSUtils::ParseJsDimensionFp(vm, fontSizeArg, fontSizeData) && !fontSizeData.IsNegative() &&
218         fontSizeData.Unit() != DimensionUnit::PERCENT) {
219         fontSize = fontSizeData.ToString();
220     }
221     std::string weight = "normal";
222     if (!weightArg->IsNull() && !weightArg->IsUndefined() && (weightArg->IsString() || weightArg->IsNumber())) {
223         weight = weightArg->ToString(vm)->ToString();
224     }
225     std::string fontFamily;
226     if (!ArkTSUtils::ParseJsFontFamiliesToString(vm, fontFamilyArg, fontFamily) || fontFamily.empty()) {
227         fontFamily = DEFAULT_FAMILY;
228     }
229     int32_t styleVal = 0;
230     if (!styleValArg->IsNull() && !styleValArg->IsUndefined() && styleValArg->IsNumber()) {
231         styleVal = styleValArg->Int32Value(vm);
232     }
233     std::string fontInfo =
234         StringUtils::FormatString(FORMAT_FONT.c_str(), fontSize.c_str(), weight.c_str(), fontFamily.c_str());
235     GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().SetAlphabetIndexerFont(
236         nativeNode, fontInfo.c_str(), styleVal);
237     return panda::JSValueRef::Undefined(vm);
238 }
239 
ResetFont(ArkUIRuntimeCallInfo * runtimeCallInfo)240 ArkUINativeModuleValue AlphabetIndexerBridge::ResetFont(ArkUIRuntimeCallInfo* runtimeCallInfo)
241 {
242     EcmaVM* vm = runtimeCallInfo->GetVM();
243     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
244     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
245     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
246     GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().ResetAlphabetIndexerFont(nativeNode);
247     return panda::JSValueRef::Undefined(vm);
248 }
249 
SetPopupItemBackgroundColor(ArkUIRuntimeCallInfo * runtimeCallInfo)250 ArkUINativeModuleValue AlphabetIndexerBridge::SetPopupItemBackgroundColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
251 {
252     EcmaVM* vm = runtimeCallInfo->GetVM();
253     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
254     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
255     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
256     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
257     Color color;
258     if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) {
259         GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().ResetPopupItemBackgroundColor(nativeNode);
260     } else {
261         GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().SetPopupItemBackgroundColor(
262             nativeNode, color.GetValue());
263     }
264     return panda::JSValueRef::Undefined(vm);
265 }
266 
ResetPopupItemBackgroundColor(ArkUIRuntimeCallInfo * runtimeCallInfo)267 ArkUINativeModuleValue AlphabetIndexerBridge::ResetPopupItemBackgroundColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
268 {
269     EcmaVM* vm = runtimeCallInfo->GetVM();
270     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
271     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
272     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
273     GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().ResetPopupItemBackgroundColor(nativeNode);
274     return panda::JSValueRef::Undefined(vm);
275 }
276 
SetColor(ArkUIRuntimeCallInfo * runtimeCallInfo)277 ArkUINativeModuleValue AlphabetIndexerBridge::SetColor(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     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
283     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
284     Color color;
285     if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) {
286         GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().ResetAlphabetIndexerColor(nativeNode);
287     } else {
288         GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().SetAlphabetIndexerColor(nativeNode, color.GetValue());
289     }
290     return panda::JSValueRef::Undefined(vm);
291 }
292 
ResetColor(ArkUIRuntimeCallInfo * runtimeCallInfo)293 ArkUINativeModuleValue AlphabetIndexerBridge::ResetColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
294 {
295     EcmaVM* vm = runtimeCallInfo->GetVM();
296     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
297     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
298     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
299     GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().ResetAlphabetIndexerColor(nativeNode);
300     return panda::JSValueRef::Undefined(vm);
301 }
302 
SetPopupColor(ArkUIRuntimeCallInfo * runtimeCallInfo)303 ArkUINativeModuleValue AlphabetIndexerBridge::SetPopupColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
304 {
305     EcmaVM* vm = runtimeCallInfo->GetVM();
306     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
307     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
308     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
309     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
310     Color color;
311     if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) {
312         GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().ResetPopupColor(nativeNode);
313     } else {
314         GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().SetPopupColor(nativeNode, color.GetValue());
315     }
316     return panda::JSValueRef::Undefined(vm);
317 }
318 
ResetPopupColor(ArkUIRuntimeCallInfo * runtimeCallInfo)319 ArkUINativeModuleValue AlphabetIndexerBridge::ResetPopupColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
320 {
321     EcmaVM* vm = runtimeCallInfo->GetVM();
322     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
323     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
324     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
325     GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().ResetPopupColor(nativeNode);
326     return panda::JSValueRef::Undefined(vm);
327 }
328 
SetSelectedColor(ArkUIRuntimeCallInfo * runtimeCallInfo)329 ArkUINativeModuleValue AlphabetIndexerBridge::SetSelectedColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
330 {
331     EcmaVM* vm = runtimeCallInfo->GetVM();
332     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
333     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
334     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
335     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
336     Color color;
337     if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) {
338         GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().ResetAlphabetIndexerSelectedColor(nativeNode);
339     } else {
340         GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().SetAlphabetIndexerSelectedColor(
341             nativeNode, color.GetValue());
342     }
343     return panda::JSValueRef::Undefined(vm);
344 }
345 
ResetSelectedColor(ArkUIRuntimeCallInfo * runtimeCallInfo)346 ArkUINativeModuleValue AlphabetIndexerBridge::ResetSelectedColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
347 {
348     EcmaVM* vm = runtimeCallInfo->GetVM();
349     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
350     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
351     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
352     GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().ResetAlphabetIndexerSelectedColor(nativeNode);
353     return panda::JSValueRef::Undefined(vm);
354 }
355 
SetPopupBackground(ArkUIRuntimeCallInfo * runtimeCallInfo)356 ArkUINativeModuleValue AlphabetIndexerBridge::SetPopupBackground(ArkUIRuntimeCallInfo* runtimeCallInfo)
357 {
358     EcmaVM* vm = runtimeCallInfo->GetVM();
359     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
360     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
361     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
362     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
363     Color color;
364     if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) {
365         GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().ResetPopupBackground(nativeNode);
366     } else {
367         GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().SetPopupBackground(nativeNode, color.GetValue());
368     }
369     return panda::JSValueRef::Undefined(vm);
370 }
371 
ResetPopupBackground(ArkUIRuntimeCallInfo * runtimeCallInfo)372 ArkUINativeModuleValue AlphabetIndexerBridge::ResetPopupBackground(ArkUIRuntimeCallInfo* runtimeCallInfo)
373 {
374     EcmaVM* vm = runtimeCallInfo->GetVM();
375     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
376     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
377     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
378     GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().ResetPopupBackground(nativeNode);
379     return panda::JSValueRef::Undefined(vm);
380 }
381 
SetSelectedBackgroundColor(ArkUIRuntimeCallInfo * runtimeCallInfo)382 ArkUINativeModuleValue AlphabetIndexerBridge::SetSelectedBackgroundColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
383 {
384     EcmaVM* vm = runtimeCallInfo->GetVM();
385     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
386     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
387     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
388     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
389     Color color;
390     if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) {
391         GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().ResetSelectedBackgroundColor(nativeNode);
392     } else {
393         GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().SetSelectedBackgroundColor(
394             nativeNode, color.GetValue());
395     }
396     return panda::JSValueRef::Undefined(vm);
397 }
398 
ResetSelectedBackgroundColor(ArkUIRuntimeCallInfo * runtimeCallInfo)399 ArkUINativeModuleValue AlphabetIndexerBridge::ResetSelectedBackgroundColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
400 {
401     EcmaVM* vm = runtimeCallInfo->GetVM();
402     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
403     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
404     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
405     GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().ResetSelectedBackgroundColor(nativeNode);
406     return panda::JSValueRef::Undefined(vm);
407 }
408 
SetPopupUnselectedColor(ArkUIRuntimeCallInfo * runtimeCallInfo)409 ArkUINativeModuleValue AlphabetIndexerBridge::SetPopupUnselectedColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
410 {
411     EcmaVM* vm = runtimeCallInfo->GetVM();
412     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
413     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
414     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
415     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
416     Color color;
417     if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) {
418         GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().ResetPopupUnselectedColor(nativeNode);
419     } else {
420         GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().SetPopupUnselectedColor(nativeNode, color.GetValue());
421     }
422     return panda::JSValueRef::Undefined(vm);
423 }
424 
ResetPopupUnselectedColor(ArkUIRuntimeCallInfo * runtimeCallInfo)425 ArkUINativeModuleValue AlphabetIndexerBridge::ResetPopupUnselectedColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
426 {
427     EcmaVM* vm = runtimeCallInfo->GetVM();
428     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
429     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
430     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
431     GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().ResetPopupUnselectedColor(nativeNode);
432     return panda::JSValueRef::Undefined(vm);
433 }
434 
SetAlignStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)435 ArkUINativeModuleValue AlphabetIndexerBridge::SetAlignStyle(ArkUIRuntimeCallInfo* runtimeCallInfo)
436 {
437     EcmaVM* vm = runtimeCallInfo->GetVM();
438     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
439     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
440     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
441     Local<JSValueRef> thirdArg = runtimeCallInfo->GetCallArgRef(NUM_2);
442     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
443     if (!secondArg->IsNumber()) {
444         GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().ResetAlignStyle(nativeNode);
445         return panda::JSValueRef::Undefined(vm);
446     }
447     int32_t alignValue = secondArg->Int32Value(vm);
448     GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().SetAlignStyle(nativeNode, alignValue);
449     CalcDimension popupHorizontalSpace;
450     if (!thirdArg->IsNull() && !thirdArg->IsUndefined() &&
451         ArkTSUtils::ParseJsDimensionVp(vm, thirdArg, popupHorizontalSpace)) {
452         GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().SetPopupHorizontalSpace(
453             nativeNode, popupHorizontalSpace.Value(), static_cast<int>(popupHorizontalSpace.Unit()));
454     } else {
455         GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().ResetPopupHorizontalSpace(nativeNode);
456     }
457     return panda::JSValueRef::Undefined(vm);
458 }
459 
ResetAlignStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)460 ArkUINativeModuleValue AlphabetIndexerBridge::ResetAlignStyle(ArkUIRuntimeCallInfo* runtimeCallInfo)
461 {
462     EcmaVM* vm = runtimeCallInfo->GetVM();
463     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
464     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
465     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
466     GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().ResetAlignStyle(nativeNode);
467     return panda::JSValueRef::Undefined(vm);
468 }
469 
SetPopupSelectedColor(ArkUIRuntimeCallInfo * runtimeCallInfo)470 ArkUINativeModuleValue AlphabetIndexerBridge::SetPopupSelectedColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
471 {
472     EcmaVM* vm = runtimeCallInfo->GetVM();
473     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
474     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
475     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
476     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
477     Color color;
478     if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) {
479         GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().ResetPopupSelectedColor(nativeNode);
480     } else {
481         GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().SetPopupSelectedColor(nativeNode, color.GetValue());
482     }
483     return panda::JSValueRef::Undefined(vm);
484 }
485 
ResetPopupSelectedColor(ArkUIRuntimeCallInfo * runtimeCallInfo)486 ArkUINativeModuleValue AlphabetIndexerBridge::ResetPopupSelectedColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
487 {
488     EcmaVM* vm = runtimeCallInfo->GetVM();
489     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
490     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
491     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
492     GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().ResetPopupSelectedColor(nativeNode);
493     return panda::JSValueRef::Undefined(vm);
494 }
495 
SetUsingPopup(ArkUIRuntimeCallInfo * runtimeCallInfo)496 ArkUINativeModuleValue AlphabetIndexerBridge::SetUsingPopup(ArkUIRuntimeCallInfo* runtimeCallInfo)
497 {
498     EcmaVM* vm = runtimeCallInfo->GetVM();
499     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
500     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
501     Local<JSValueRef> usingPopupArg = runtimeCallInfo->GetCallArgRef(1);
502     void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
503     if (usingPopupArg->IsNull() || usingPopupArg->IsUndefined()) {
504         GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().ResetUsingPopup(nativeNode);
505     } else {
506         bool usingPopup = usingPopupArg->ToBoolean(vm)->Value();
507         GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().SetUsingPopup(nativeNode, usingPopup);
508     }
509 
510     return panda::JSValueRef::Undefined(vm);
511 }
512 
ResetUsingPopup(ArkUIRuntimeCallInfo * runtimeCallInfo)513 ArkUINativeModuleValue AlphabetIndexerBridge::ResetUsingPopup(ArkUIRuntimeCallInfo* runtimeCallInfo)
514 {
515     EcmaVM* vm = runtimeCallInfo->GetVM();
516     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
517     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
518     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
519     GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().ResetUsingPopup(nativeNode);
520     return panda::JSValueRef::Undefined(vm);
521 }
522 
SetSelected(ArkUIRuntimeCallInfo * runtimeCallInfo)523 ArkUINativeModuleValue AlphabetIndexerBridge::SetSelected(ArkUIRuntimeCallInfo* runtimeCallInfo)
524 {
525     EcmaVM* vm = runtimeCallInfo->GetVM();
526     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
527     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
528     Local<JSValueRef> selectedArg = runtimeCallInfo->GetCallArgRef(1);
529     void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
530     int32_t selected = 0;
531     if (selectedArg->IsNull() || selectedArg->IsUndefined() || !ParseJsInteger(vm, selectedArg, selected)) {
532         GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().ResetAlphabetIndexerSelected(nativeNode);
533     } else {
534         GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().SetAlphabetIndexerSelected(nativeNode, selected);
535     }
536 
537     return panda::JSValueRef::Undefined(vm);
538 }
539 
ResetSelected(ArkUIRuntimeCallInfo * runtimeCallInfo)540 ArkUINativeModuleValue AlphabetIndexerBridge::ResetSelected(ArkUIRuntimeCallInfo* runtimeCallInfo)
541 {
542     EcmaVM* vm = runtimeCallInfo->GetVM();
543     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
544     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
545     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
546     GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().ResetAlphabetIndexerSelected(nativeNode);
547     return panda::JSValueRef::Undefined(vm);
548 }
549 
SetItemSize(ArkUIRuntimeCallInfo * runtimeCallInfo)550 ArkUINativeModuleValue AlphabetIndexerBridge::SetItemSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
551 {
552     EcmaVM* vm = runtimeCallInfo->GetVM();
553     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
554     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
555     Local<JSValueRef> itemSizeArg = runtimeCallInfo->GetCallArgRef(1);
556     void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
557     CalcDimension itemSize;
558 
559     if (itemSizeArg->IsNull() || itemSizeArg->IsUndefined()) {
560         GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().ResetItemSize(nativeNode);
561     }
562 
563     if (ParseJsDimensionVp(vm, itemSizeArg, itemSize) && GreatNotEqual(itemSize.Value(), 0.0) &&
564         itemSize.Unit() != DimensionUnit::PERCENT) {
565         GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().SetItemSize(
566             nativeNode, itemSize.Value(), static_cast<int>(itemSize.Unit()));
567     } else {
568         GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().ResetItemSize(nativeNode);
569     }
570     return panda::JSValueRef::Undefined(vm);
571 }
572 
ResetItemSize(ArkUIRuntimeCallInfo * runtimeCallInfo)573 ArkUINativeModuleValue AlphabetIndexerBridge::ResetItemSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
574 {
575     EcmaVM* vm = runtimeCallInfo->GetVM();
576     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
577     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
578     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
579     GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().ResetItemSize(nativeNode);
580     return panda::JSValueRef::Undefined(vm);
581 }
582 
SetPopupPosition(ArkUIRuntimeCallInfo * runtimeCallInfo)583 ArkUINativeModuleValue AlphabetIndexerBridge::SetPopupPosition(ArkUIRuntimeCallInfo* runtimeCallInfo)
584 {
585     EcmaVM* vm = runtimeCallInfo->GetVM();
586     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
587     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
588     void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
589     Local<JSValueRef> sizeX = runtimeCallInfo->GetCallArgRef(NUM_1);
590     Local<JSValueRef> sizeY = runtimeCallInfo->GetCallArgRef(NUM_2);
591     CalcDimension x;
592     CalcDimension y;
593     if (sizeX->IsNull() || sizeX->IsUndefined() || !ArkTSUtils::ParseJsDimensionVp(vm, sizeX, x)) {
594         x = DEFAULT_POPUP_POSITION_X;
595     }
596     if (sizeY->IsNull() || sizeY->IsUndefined() || !ArkTSUtils::ParseJsDimensionVp(vm, sizeY, y)) {
597         y = DEFAULT_POPUP_POSITION_Y;
598     }
599     GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().SetPopupPosition(
600         nativeNode, x.Value(), static_cast<int>(x.Unit()), y.Value(), static_cast<int>(y.Unit()));
601     return panda::JSValueRef::Undefined(vm);
602 }
603 
ResetPopupPosition(ArkUIRuntimeCallInfo * runtimeCallInfo)604 ArkUINativeModuleValue AlphabetIndexerBridge::ResetPopupPosition(ArkUIRuntimeCallInfo* runtimeCallInfo)
605 {
606     EcmaVM* vm = runtimeCallInfo->GetVM();
607     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
608     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
609     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
610     GetArkUIInternalNodeAPI()->GetAlphabetIndexerModifier().ResetPopupPosition(nativeNode);
611     return panda::JSValueRef::Undefined(vm);
612 }
613 } // namespace OHOS::Ace::NG
614