• 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_text_input_bridge.h"
16 
17 #include "base/utils/utils.h"
18 #include "core/interfaces/native/node/api.h"
19 #include "core/components/common/layout/constants.h"
20 #include "core/components/text_field/textfield_theme.h"
21 #include "core/components_ng/pattern/text_field/text_field_model.h"
22 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
23 namespace OHOS::Ace::NG {
24 constexpr int16_t DEFAULT_APLHA = 255;
25 constexpr double DEFAULT_OPACITY = 0.2;
26 constexpr double DEFAULT_FONT_SIZE = 16.0;
27 constexpr Ace::FontStyle DEFAULT_FONT_STYLE = Ace::FontStyle::NORMAL;
28 const std::string DEFAULT_FONT_WEIGHT = "400";
SetCaretColor(ArkUIRuntimeCallInfo * runtimeCallInfo)29 ArkUINativeModuleValue TextInputBridge::SetCaretColor(ArkUIRuntimeCallInfo *runtimeCallInfo)
30 {
31     EcmaVM *vm = runtimeCallInfo->GetVM();
32     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
33     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
34     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
35     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
36     Color color;
37     if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) {
38         GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputCaretColor(nativeNode);
39     } else {
40         GetArkUIInternalNodeAPI()->GetTextInputModifier().SetTextInputCaretColor(nativeNode, color.GetValue());
41     }
42     return panda::JSValueRef::Undefined(vm);
43 }
44 
ResetCaretColor(ArkUIRuntimeCallInfo * runtimeCallInfo)45 ArkUINativeModuleValue TextInputBridge::ResetCaretColor(ArkUIRuntimeCallInfo *runtimeCallInfo)
46 {
47     EcmaVM *vm = runtimeCallInfo->GetVM();
48     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
49     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
50     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
51     GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputCaretColor(nativeNode);
52     return panda::JSValueRef::Undefined(vm);
53 }
54 
SetType(ArkUIRuntimeCallInfo * runtimeCallInfo)55 ArkUINativeModuleValue TextInputBridge::SetType(ArkUIRuntimeCallInfo *runtimeCallInfo)
56 {
57     EcmaVM *vm = runtimeCallInfo->GetVM();
58     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
59     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
60     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
61     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
62     if (secondArg->IsNumber()) {
63         int32_t value = secondArg->Int32Value(vm);
64         GetArkUIInternalNodeAPI()->GetTextInputModifier().SetTextInputType(nativeNode, value);
65     } else {
66         GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputType(nativeNode);
67     }
68 
69     return panda::JSValueRef::Undefined(vm);
70 }
71 
ResetType(ArkUIRuntimeCallInfo * runtimeCallInfo)72 ArkUINativeModuleValue TextInputBridge::ResetType(ArkUIRuntimeCallInfo *runtimeCallInfo)
73 {
74     EcmaVM *vm = runtimeCallInfo->GetVM();
75     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
76     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
77     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
78     GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputType(nativeNode);
79     return panda::JSValueRef::Undefined(vm);
80 }
81 
SetMaxLines(ArkUIRuntimeCallInfo * runtimeCallInfo)82 ArkUINativeModuleValue TextInputBridge::SetMaxLines(ArkUIRuntimeCallInfo *runtimeCallInfo)
83 {
84     EcmaVM *vm = runtimeCallInfo->GetVM();
85     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
86     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
87     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
88     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
89     if (secondArg->IsNumber()) {
90         uint32_t value = secondArg->Uint32Value(vm);
91         GetArkUIInternalNodeAPI()->GetTextInputModifier().SetTextInputMaxLines(nativeNode, value);
92     } else {
93         GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputMaxLines(nativeNode);
94     }
95     return panda::JSValueRef::Undefined(vm);
96 }
97 
ResetMaxLines(ArkUIRuntimeCallInfo * runtimeCallInfo)98 ArkUINativeModuleValue TextInputBridge::ResetMaxLines(ArkUIRuntimeCallInfo *runtimeCallInfo)
99 {
100     EcmaVM *vm = runtimeCallInfo->GetVM();
101     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
102     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
103     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
104     GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputMaxLines(nativeNode);
105     return panda::JSValueRef::Undefined(vm);
106 }
107 
SetPlaceholderColor(ArkUIRuntimeCallInfo * runtimeCallInfo)108 ArkUINativeModuleValue TextInputBridge::SetPlaceholderColor(ArkUIRuntimeCallInfo *runtimeCallInfo)
109 {
110     EcmaVM *vm = runtimeCallInfo->GetVM();
111     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
112     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
113     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
114     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
115     Color color;
116     if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) {
117         GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputPlaceholderColor(nativeNode);
118     } else {
119         GetArkUIInternalNodeAPI()->GetTextInputModifier().SetTextInputPlaceholderColor(nativeNode, color.GetValue());
120     }
121     return panda::JSValueRef::Undefined(vm);
122 }
123 
ResetPlaceholderColor(ArkUIRuntimeCallInfo * runtimeCallInfo)124 ArkUINativeModuleValue TextInputBridge::ResetPlaceholderColor(ArkUIRuntimeCallInfo *runtimeCallInfo)
125 {
126     EcmaVM *vm = runtimeCallInfo->GetVM();
127     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
128     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
129     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
130     GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputPlaceholderColor(nativeNode);
131     return panda::JSValueRef::Undefined(vm);
132 }
133 
SetCaretPosition(ArkUIRuntimeCallInfo * runtimeCallInfo)134 ArkUINativeModuleValue TextInputBridge::SetCaretPosition(ArkUIRuntimeCallInfo *runtimeCallInfo)
135 {
136     EcmaVM *vm = runtimeCallInfo->GetVM();
137     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
138     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
139     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
140     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
141     if (secondArg->IsInt() && secondArg->Int32Value(vm) >= 0) {
142         int32_t caretPosition = secondArg->Int32Value(vm);
143         GetArkUIInternalNodeAPI()->GetTextInputModifier().SetTextInputCaretPosition(nativeNode, caretPosition);
144     } else {
145         GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputCaretPosition(nativeNode);
146     }
147     return panda::JSValueRef::Undefined(vm);
148 }
149 
ResetCaretPosition(ArkUIRuntimeCallInfo * runtimeCallInfo)150 ArkUINativeModuleValue TextInputBridge::ResetCaretPosition(ArkUIRuntimeCallInfo *runtimeCallInfo)
151 {
152     EcmaVM *vm = runtimeCallInfo->GetVM();
153     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
154     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
155     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
156     GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputCaretPosition(nativeNode);
157     return panda::JSValueRef::Undefined(vm);
158 }
159 
SetCopyOption(ArkUIRuntimeCallInfo * runtimeCallInfo)160 ArkUINativeModuleValue TextInputBridge::SetCopyOption(ArkUIRuntimeCallInfo *runtimeCallInfo)
161 {
162     EcmaVM *vm = runtimeCallInfo->GetVM();
163     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
164     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
165     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
166     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
167     if (secondArg->IsNumber()) {
168         int32_t option = secondArg->Int32Value(vm);
169         GetArkUIInternalNodeAPI()->GetTextInputModifier().SetTextInputCopyOption(nativeNode, option);
170     } else {
171         GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputCopyOption(nativeNode);
172     }
173 
174     return panda::JSValueRef::Undefined(vm);
175 }
176 
ResetCopyOption(ArkUIRuntimeCallInfo * runtimeCallInfo)177 ArkUINativeModuleValue TextInputBridge::ResetCopyOption(ArkUIRuntimeCallInfo *runtimeCallInfo)
178 {
179     EcmaVM *vm = runtimeCallInfo->GetVM();
180     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
181     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
182     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
183     GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputCopyOption(nativeNode);
184     return panda::JSValueRef::Undefined(vm);
185 }
186 
SetShowPasswordIcon(ArkUIRuntimeCallInfo * runtimeCallInfo)187 ArkUINativeModuleValue TextInputBridge::SetShowPasswordIcon(ArkUIRuntimeCallInfo *runtimeCallInfo)
188 {
189     EcmaVM *vm = runtimeCallInfo->GetVM();
190     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
191     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
192     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
193     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
194 
195     if (secondArg->IsBoolean()) {
196         uint32_t value = static_cast<uint32_t>(secondArg->ToBoolean(vm)->Value());
197         GetArkUIInternalNodeAPI()->GetTextInputModifier().SetTextInputShowPasswordIcon(nativeNode, value);
198     } else {
199         GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputShowPasswordIcon(nativeNode);
200     }
201     return panda::JSValueRef::Undefined(vm);
202 }
203 
ResetShowPasswordIcon(ArkUIRuntimeCallInfo * runtimeCallInfo)204 ArkUINativeModuleValue TextInputBridge::ResetShowPasswordIcon(ArkUIRuntimeCallInfo *runtimeCallInfo)
205 {
206     EcmaVM *vm = runtimeCallInfo->GetVM();
207     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
208     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
209     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
210     GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputShowPasswordIcon(nativeNode);
211     return panda::JSValueRef::Undefined(vm);
212 }
213 
SetPasswordIcon(ArkUIRuntimeCallInfo * runtimeCallInfo)214 ArkUINativeModuleValue TextInputBridge::SetPasswordIcon(ArkUIRuntimeCallInfo *runtimeCallInfo)
215 {
216     EcmaVM *vm = runtimeCallInfo->GetVM();
217     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
218     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
219     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
220     Local<JSValueRef> thirdArg = runtimeCallInfo->GetCallArgRef(2);
221     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
222 
223     PasswordIcon passwordIcon;
224     struct ArkUIPasswordIconType value = {"", "", "", "", "", ""};
225     if (!ArkTSUtils::GetJsPasswordIcon(vm, secondArg, thirdArg, passwordIcon)) {
226         GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputPasswordIcon(nativeNode);
227     } else {
228         value.showResult = passwordIcon.showResult.c_str();
229         value.hideResult = passwordIcon.hideResult.c_str();
230         value.showBundleName = passwordIcon.showBundleName.c_str();
231         value.showModuleName = passwordIcon.showModuleName.c_str();
232         value.hideBundleName = passwordIcon.hideBundleName.c_str();
233         value.hideModuleName = passwordIcon.hideModuleName.c_str();
234         GetArkUIInternalNodeAPI()->GetTextInputModifier().SetTextInputPasswordIcon(nativeNode, &value);
235     }
236     return panda::JSValueRef::Undefined(vm);
237 }
238 
ResetPasswordIcon(ArkUIRuntimeCallInfo * runtimeCallInfo)239 ArkUINativeModuleValue TextInputBridge::ResetPasswordIcon(ArkUIRuntimeCallInfo *runtimeCallInfo)
240 {
241     EcmaVM *vm = runtimeCallInfo->GetVM();
242     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
243     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
244     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
245     GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputPasswordIcon(nativeNode);
246     return panda::JSValueRef::Undefined(vm);
247 }
248 
SetTextAlign(ArkUIRuntimeCallInfo * runtimeCallInfo)249 ArkUINativeModuleValue TextInputBridge::SetTextAlign(ArkUIRuntimeCallInfo *runtimeCallInfo)
250 {
251     EcmaVM *vm = runtimeCallInfo->GetVM();
252     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
253     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
254     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
255     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
256 
257     if (secondArg->IsNumber()) {
258         int32_t value = secondArg->Int32Value(vm);
259         GetArkUIInternalNodeAPI()->GetTextInputModifier().SetTextInputTextAlign(nativeNode, value);
260     } else {
261         GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputTextAlign(nativeNode);
262     }
263     return panda::JSValueRef::Undefined(vm);
264 }
265 
ResetTextAlign(ArkUIRuntimeCallInfo * runtimeCallInfo)266 ArkUINativeModuleValue TextInputBridge::ResetTextAlign(ArkUIRuntimeCallInfo *runtimeCallInfo)
267 {
268     EcmaVM *vm = runtimeCallInfo->GetVM();
269     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
270     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
271     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
272     GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputTextAlign(nativeNode);
273     return panda::JSValueRef::Undefined(vm);
274 }
275 
SetStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)276 ArkUINativeModuleValue TextInputBridge::SetStyle(ArkUIRuntimeCallInfo *runtimeCallInfo)
277 {
278     EcmaVM *vm = runtimeCallInfo->GetVM();
279     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
280     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
281     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
282     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
283     if (secondArg->IsString() && secondArg->ToString(vm)->ToString() == "Inline") {
284         GetArkUIInternalNodeAPI()->GetTextInputModifier().SetTextInputStyle(nativeNode,
285             static_cast<int32_t>(InputStyle::INLINE));
286     } else {
287         GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputStyle(nativeNode);
288     }
289     return panda::JSValueRef::Undefined(vm);
290 }
291 
ResetStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)292 ArkUINativeModuleValue TextInputBridge::ResetStyle(ArkUIRuntimeCallInfo *runtimeCallInfo)
293 {
294     EcmaVM *vm = runtimeCallInfo->GetVM();
295     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
296     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
297     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
298     GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputStyle(nativeNode);
299     return panda::JSValueRef::Undefined(vm);
300 }
301 
SetSelectionMenuHidden(ArkUIRuntimeCallInfo * runtimeCallInfo)302 ArkUINativeModuleValue TextInputBridge::SetSelectionMenuHidden(ArkUIRuntimeCallInfo *runtimeCallInfo)
303 {
304     EcmaVM *vm = runtimeCallInfo->GetVM();
305     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
306     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
307     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
308     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
309 
310     if (secondArg->IsBoolean()) {
311         uint32_t menuHiddenValue = static_cast<uint32_t>(secondArg->ToBoolean(vm)->Value());
312         GetArkUIInternalNodeAPI()->GetTextInputModifier().SetTextInputSelectionMenuHidden(nativeNode, menuHiddenValue);
313     } else {
314         GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputSelectionMenuHidden(nativeNode);
315     }
316 
317     return panda::JSValueRef::Undefined(vm);
318 }
319 
ResetSelectionMenuHidden(ArkUIRuntimeCallInfo * runtimeCallInfo)320 ArkUINativeModuleValue TextInputBridge::ResetSelectionMenuHidden(ArkUIRuntimeCallInfo *runtimeCallInfo)
321 {
322     EcmaVM *vm = runtimeCallInfo->GetVM();
323     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
324     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
325     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
326     GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputSelectionMenuHidden(nativeNode);
327     return panda::JSValueRef::Undefined(vm);
328 }
329 
SetTextInputShowUnderline(ArkUIRuntimeCallInfo * runtimeCallInfo)330 ArkUINativeModuleValue TextInputBridge::SetTextInputShowUnderline(ArkUIRuntimeCallInfo *runtimeCallInfo)
331 {
332     EcmaVM *vm = runtimeCallInfo->GetVM();
333     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
334     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
335     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
336     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
337 
338     if (secondArg->IsBoolean()) {
339         uint32_t showUnderLine = static_cast<uint32_t>(secondArg->ToBoolean(vm)->Value());
340         GetArkUIInternalNodeAPI()->GetTextInputModifier().SetTextInputShowUnderline(nativeNode, showUnderLine);
341     } else {
342         GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputShowUnderline(nativeNode);
343     }
344 
345     return panda::JSValueRef::Undefined(vm);
346 }
347 
ResetTextInputShowUnderline(ArkUIRuntimeCallInfo * runtimeCallInfo)348 ArkUINativeModuleValue TextInputBridge::ResetTextInputShowUnderline(ArkUIRuntimeCallInfo *runtimeCallInfo)
349 {
350     EcmaVM *vm = runtimeCallInfo->GetVM();
351     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
352     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
353     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
354     GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputShowUnderline(nativeNode);
355     return panda::JSValueRef::Undefined(vm);
356 }
357 
SetCaretStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)358 ArkUINativeModuleValue TextInputBridge::SetCaretStyle(ArkUIRuntimeCallInfo *runtimeCallInfo)
359 {
360     EcmaVM *vm = runtimeCallInfo->GetVM();
361     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
362     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
363     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
364     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
365     CalcDimension width;
366     struct ArkUILengthType length = { nullptr, 0.0, static_cast<int8_t>(DimensionUnit::VP) };
367     if (!ArkTSUtils::ParseJsDimensionVpNG(vm, secondArg, width, false) || LessNotEqual(width.Value(), 0.0)) {
368         GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputCaretStyle(nativeNode);
369     } else {
370         length.unit = static_cast<int8_t>(width.Unit());
371         if (width.CalcValue() != "") {
372             length.string = width.CalcValue().c_str();
373         } else {
374             length.number = width.Value();
375         }
376         GetArkUIInternalNodeAPI()->GetTextInputModifier().SetTextInputCaretStyle(nativeNode, &length);
377     }
378 
379     return panda::JSValueRef::Undefined(vm);
380 }
381 
ResetCaretStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)382 ArkUINativeModuleValue TextInputBridge::ResetCaretStyle(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     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
388     GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputCaretStyle(nativeNode);
389     return panda::JSValueRef::Undefined(vm);
390 }
391 
SetEnableKeyboardOnFocus(ArkUIRuntimeCallInfo * runtimeCallInfo)392 ArkUINativeModuleValue TextInputBridge::SetEnableKeyboardOnFocus(ArkUIRuntimeCallInfo *runtimeCallInfo)
393 {
394     EcmaVM *vm = runtimeCallInfo->GetVM();
395     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
396     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
397     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
398     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
399 
400     if (secondArg->IsBoolean()) {
401         uint32_t value = static_cast<uint32_t>(secondArg->ToBoolean(vm)->Value());
402         GetArkUIInternalNodeAPI()->GetTextInputModifier().SetTextInputEnableKeyboardOnFocus(nativeNode, value);
403     } else {
404         GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputShowPasswordIcon(nativeNode);
405     }
406 
407     return panda::JSValueRef::Undefined(vm);
408 }
409 
ResetEnableKeyboardOnFocus(ArkUIRuntimeCallInfo * runtimeCallInfo)410 ArkUINativeModuleValue TextInputBridge::ResetEnableKeyboardOnFocus(ArkUIRuntimeCallInfo *runtimeCallInfo)
411 {
412     EcmaVM *vm = runtimeCallInfo->GetVM();
413     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
414     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
415     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
416     GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputEnableKeyboardOnFocus(nativeNode);
417     return panda::JSValueRef::Undefined(vm);
418 }
419 
SetBarState(ArkUIRuntimeCallInfo * runtimeCallInfo)420 ArkUINativeModuleValue TextInputBridge::SetBarState(ArkUIRuntimeCallInfo *runtimeCallInfo)
421 {
422     EcmaVM *vm = runtimeCallInfo->GetVM();
423     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
424     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
425     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
426     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
427 
428     if (secondArg->IsNumber()) {
429         int32_t value = secondArg->Int32Value(vm);
430         GetArkUIInternalNodeAPI()->GetTextInputModifier().SetTextInputBarState(nativeNode, value);
431     } else {
432         GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputBarState(nativeNode);
433     }
434 
435     return panda::JSValueRef::Undefined(vm);
436 }
437 
ResetBarState(ArkUIRuntimeCallInfo * runtimeCallInfo)438 ArkUINativeModuleValue TextInputBridge::ResetBarState(ArkUIRuntimeCallInfo *runtimeCallInfo)
439 {
440     EcmaVM *vm = runtimeCallInfo->GetVM();
441     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
442     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
443     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
444     GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputBarState(nativeNode);
445     return panda::JSValueRef::Undefined(vm);
446 }
447 
SetTextInputEnterKeyType(ArkUIRuntimeCallInfo * runtimeCallInfo)448 ArkUINativeModuleValue TextInputBridge::SetTextInputEnterKeyType(ArkUIRuntimeCallInfo *runtimeCallInfo)
449 {
450     EcmaVM *vm = runtimeCallInfo->GetVM();
451     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
452     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
453     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
454     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
455 
456     if (secondArg->IsNumber()) {
457         int32_t value = secondArg->Int32Value(vm);
458         GetArkUIInternalNodeAPI()->GetTextInputModifier().SetTextInputEnterKeyType(nativeNode, value);
459     } else {
460         GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputEnterKeyType(nativeNode);
461     }
462     return panda::JSValueRef::Undefined(vm);
463 }
464 
ResetTextInputEnterKeyType(ArkUIRuntimeCallInfo * runtimeCallInfo)465 ArkUINativeModuleValue TextInputBridge::ResetTextInputEnterKeyType(ArkUIRuntimeCallInfo *runtimeCallInfo)
466 {
467     EcmaVM *vm = runtimeCallInfo->GetVM();
468     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
469     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
470     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
471     GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputEnterKeyType(nativeNode);
472     return panda::JSValueRef::Undefined(vm);
473 }
474 
SetTextInputFontWeight(ArkUIRuntimeCallInfo * runtimeCallInfo)475 ArkUINativeModuleValue TextInputBridge::SetTextInputFontWeight(ArkUIRuntimeCallInfo *runtimeCallInfo)
476 {
477     EcmaVM *vm = runtimeCallInfo->GetVM();
478     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
479     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
480     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
481     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
482     std::string weight;
483     if (secondArg->IsString()) {
484         weight = secondArg->ToString(vm)->ToString();
485         GetArkUIInternalNodeAPI()->GetTextInputModifier().SetTextInputFontWeight(nativeNode, weight.c_str());
486     } else if (secondArg->IsNumber()) {
487         weight = std::to_string(secondArg->Int32Value(vm));
488         GetArkUIInternalNodeAPI()->GetTextInputModifier().SetTextInputFontWeight(nativeNode, weight.c_str());
489     } else {
490         GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputFontWeight(nativeNode);
491     }
492 
493     return panda::JSValueRef::Undefined(vm);
494 }
495 
ResetTextInputFontWeight(ArkUIRuntimeCallInfo * runtimeCallInfo)496 ArkUINativeModuleValue TextInputBridge::ResetTextInputFontWeight(ArkUIRuntimeCallInfo *runtimeCallInfo)
497 {
498     EcmaVM *vm = runtimeCallInfo->GetVM();
499     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
500     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
501     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
502     GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputFontWeight(nativeNode);
503     return panda::JSValueRef::Undefined(vm);
504 }
505 
SetFontSize(ArkUIRuntimeCallInfo * runtimeCallInfo)506 ArkUINativeModuleValue TextInputBridge::SetFontSize(ArkUIRuntimeCallInfo *runtimeCallInfo)
507 {
508     EcmaVM *vm = runtimeCallInfo->GetVM();
509     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
510     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
511     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
512     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
513 
514     CalcDimension fontSize;
515     ArkUILengthType value{ nullptr, 0.0, static_cast<int8_t>(DimensionUnit::FP) };
516     if (!ArkTSUtils::ParseJsDimensionNG(vm, secondArg, fontSize, DimensionUnit::FP, false)) {
517         GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputFontSize(nativeNode);
518     } else {
519         value.unit = static_cast<int8_t>(fontSize.Unit());
520         if (fontSize.CalcValue() != "") {
521             value.string = fontSize.CalcValue().c_str();
522         } else {
523             value.number = fontSize.Value();
524         }
525         GetArkUIInternalNodeAPI()->GetTextInputModifier().SetTextInputFontSize(nativeNode, &value);
526     }
527     return panda::JSValueRef::Undefined(vm);
528 }
529 
ResetFontSize(ArkUIRuntimeCallInfo * runtimeCallInfo)530 ArkUINativeModuleValue TextInputBridge::ResetFontSize(ArkUIRuntimeCallInfo *runtimeCallInfo)
531 {
532     EcmaVM *vm = runtimeCallInfo->GetVM();
533     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
534     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
535     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
536     GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputFontSize(nativeNode);
537     return panda::JSValueRef::Undefined(vm);
538 }
539 
SetMaxLength(ArkUIRuntimeCallInfo * runtimeCallInfo)540 ArkUINativeModuleValue TextInputBridge::SetMaxLength(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     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
546     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
547     if (!secondArg->IsNumber()) {
548         GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputMaxLength(nativeNode);
549     } else {
550         uint32_t maxLength = secondArg->Uint32Value(vm);
551         if (GreatOrEqual(maxLength, 0)) {
552             GetArkUIInternalNodeAPI()->GetTextInputModifier().SetTextInputMaxLength(nativeNode, maxLength);
553         } else {
554             GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputMaxLength(nativeNode);
555         }
556     }
557     return panda::JSValueRef::Undefined(vm);
558 }
559 
ResetMaxLength(ArkUIRuntimeCallInfo * runtimeCallInfo)560 ArkUINativeModuleValue TextInputBridge::ResetMaxLength(ArkUIRuntimeCallInfo *runtimeCallInfo)
561 {
562     EcmaVM *vm = runtimeCallInfo->GetVM();
563     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
564     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
565     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
566     GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputMaxLength(nativeNode);
567     return panda::JSValueRef::Undefined(vm);
568 }
569 
SetSelectedBackgroundColor(ArkUIRuntimeCallInfo * runtimeCallInfo)570 ArkUINativeModuleValue TextInputBridge::SetSelectedBackgroundColor(ArkUIRuntimeCallInfo *runtimeCallInfo)
571 {
572     EcmaVM *vm = runtimeCallInfo->GetVM();
573     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
574     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
575     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
576     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
577     Color color;
578     if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) {
579         GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputSelectedBackgroundColor(nativeNode);
580     } else {
581         if (color.GetAlpha() == DEFAULT_APLHA) {
582             color = color.ChangeOpacity(DEFAULT_OPACITY);
583         }
584         GetArkUIInternalNodeAPI()->GetTextInputModifier().SetTextInputSelectedBackgroundColor(
585             nativeNode, color.GetValue());
586     }
587     return panda::JSValueRef::Undefined(vm);
588 }
589 
ResetSelectedBackgroundColor(ArkUIRuntimeCallInfo * runtimeCallInfo)590 ArkUINativeModuleValue TextInputBridge::ResetSelectedBackgroundColor(ArkUIRuntimeCallInfo *runtimeCallInfo)
591 {
592     EcmaVM *vm = runtimeCallInfo->GetVM();
593     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
594     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
595     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
596     GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputSelectedBackgroundColor(nativeNode);
597     return panda::JSValueRef::Undefined(vm);
598 }
599 
SetShowError(ArkUIRuntimeCallInfo * runtimeCallInfo)600 ArkUINativeModuleValue TextInputBridge::SetShowError(ArkUIRuntimeCallInfo *runtimeCallInfo)
601 {
602     EcmaVM *vm = runtimeCallInfo->GetVM();
603     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
604     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
605     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
606     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
607     bool visible;
608     std::string error = "";
609     if (secondArg->IsString()) {
610         visible = true;
611         error = secondArg->ToString(vm)->ToString();
612     } else {
613         visible = false;
614     }
615 
616     GetArkUIInternalNodeAPI()->GetTextInputModifier().SetTextInputShowError(nativeNode, error.c_str(),
617         static_cast<uint32_t>(visible));
618 
619     return panda::JSValueRef::Undefined(vm);
620 }
621 
ResetShowError(ArkUIRuntimeCallInfo * runtimeCallInfo)622 ArkUINativeModuleValue TextInputBridge::ResetShowError(ArkUIRuntimeCallInfo *runtimeCallInfo)
623 {
624     EcmaVM *vm = runtimeCallInfo->GetVM();
625     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
626     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
627     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
628     GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputShowError(nativeNode);
629     return panda::JSValueRef::Undefined(vm);
630 }
631 
SetPlaceholderFont(ArkUIRuntimeCallInfo * runtimeCallInfo)632 ArkUINativeModuleValue TextInputBridge::SetPlaceholderFont(ArkUIRuntimeCallInfo *runtimeCallInfo)
633 {
634     EcmaVM *vm = runtimeCallInfo->GetVM();
635     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
636     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
637     Local<JSValueRef> jsSize = runtimeCallInfo->GetCallArgRef(1);
638     Local<JSValueRef> jsWeight = runtimeCallInfo->GetCallArgRef(2);
639     Local<JSValueRef> jsFamily = runtimeCallInfo->GetCallArgRef(3);
640     Local<JSValueRef> jsStyle = runtimeCallInfo->GetCallArgRef(4);
641     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
642     ArkUILengthType length{ nullptr, DEFAULT_FONT_SIZE, static_cast<int8_t>(DimensionUnit::FP) };
643     CalcDimension size(DEFAULT_FONT_SIZE, DimensionUnit::FP);
644     if (!ArkTSUtils::ParseJsDimensionFp(vm, jsSize, size) || size.Unit() == DimensionUnit::PERCENT) {
645         auto theme = ArkTSUtils::GetTheme<TextFieldTheme>();
646         if (theme != nullptr) {
647             size = theme->GetFontSize();
648         }
649     }
650     length.unit = static_cast<int8_t>(size.Unit());
651     if (size.CalcValue() != "") {
652         length.string = size.CalcValue().c_str();
653     } else {
654         length.number = size.Value();
655     }
656 
657     std::string weight = DEFAULT_FONT_WEIGHT;
658     if (!jsWeight->IsNull()) {
659         if (jsWeight->IsString()) {
660             weight = jsWeight->ToString(vm)->ToString();
661         }
662         if (jsWeight->IsNumber()) {
663             weight = std::to_string(jsWeight->Int32Value(vm));
664         }
665     }
666 
667     int32_t style = static_cast<int32_t>(DEFAULT_FONT_STYLE);
668     if (jsStyle->IsNumber()) {
669         style = jsStyle->ToNumber(vm)->Value();
670     }
671 
672     struct ArkUIPlaceholderFontType placeholderFont;
673     placeholderFont.size = &length;
674     placeholderFont.weight = weight.c_str();
675     placeholderFont.style = style;
676     std::vector<std::string> fontFamilies;
677     if (!ArkTSUtils::ParseJsFontFamilies(vm, jsFamily, fontFamilies)) {
678         placeholderFont.fontFamilies = nullptr;
679         placeholderFont.length = 0;
680     } else {
681         auto families = std::make_unique<char* []>(fontFamilies.size());
682         for (uint32_t i = 0; i < fontFamilies.size(); i++) {
683             families[i] = const_cast<char*>(fontFamilies.at(i).c_str());
684         }
685         placeholderFont.fontFamilies = const_cast<const char**>(families.get());
686         placeholderFont.length = fontFamilies.size();
687     }
688 
689     GetArkUIInternalNodeAPI()->GetTextInputModifier().SetTextInputPlaceholderFont(
690         nativeNode, &placeholderFont);
691     return panda::JSValueRef::Undefined(vm);
692 }
693 
ResetPlaceholderFont(ArkUIRuntimeCallInfo * runtimeCallInfo)694 ArkUINativeModuleValue TextInputBridge::ResetPlaceholderFont(ArkUIRuntimeCallInfo *runtimeCallInfo)
695 {
696     EcmaVM *vm = runtimeCallInfo->GetVM();
697     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
698     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
699     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
700     GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputPlaceholderFont(nativeNode);
701     return panda::JSValueRef::Undefined(vm);
702 }
703 
SetFontColor(ArkUIRuntimeCallInfo * runtimeCallInfo)704 ArkUINativeModuleValue TextInputBridge::SetFontColor(ArkUIRuntimeCallInfo *runtimeCallInfo)
705 {
706     EcmaVM *vm = runtimeCallInfo->GetVM();
707     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
708     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
709     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
710     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
711     Color color;
712     if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) {
713         GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputFontColor(nativeNode);
714     } else {
715         GetArkUIInternalNodeAPI()->GetTextInputModifier().SetTextInputFontColor(nativeNode, color.GetValue());
716     }
717     return panda::JSValueRef::Undefined(vm);
718 }
719 
ResetFontColor(ArkUIRuntimeCallInfo * runtimeCallInfo)720 ArkUINativeModuleValue TextInputBridge::ResetFontColor(ArkUIRuntimeCallInfo *runtimeCallInfo)
721 {
722     EcmaVM *vm = runtimeCallInfo->GetVM();
723     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
724     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
725     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
726     GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputFontColor(nativeNode);
727     return panda::JSValueRef::Undefined(vm);
728 }
729 
SetFontStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)730 ArkUINativeModuleValue TextInputBridge::SetFontStyle(ArkUIRuntimeCallInfo *runtimeCallInfo)
731 {
732     EcmaVM *vm = runtimeCallInfo->GetVM();
733     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
734     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
735     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
736     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
737     if (secondArg->IsNumber()) {
738         uint32_t fontStyle = secondArg->Uint32Value(vm);
739         if (fontStyle < static_cast<uint32_t>(OHOS::Ace::FontStyle::NORMAL) ||
740             fontStyle > static_cast<uint32_t>(OHOS::Ace::FontStyle::ITALIC)) {
741             fontStyle = static_cast<uint32_t>(OHOS::Ace::FontStyle::NORMAL);
742         }
743         GetArkUIInternalNodeAPI()->GetTextInputModifier().SetTextInputFontStyle(nativeNode, fontStyle);
744     } else {
745         GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputFontStyle(nativeNode);
746     }
747     return panda::JSValueRef::Undefined(vm);
748 }
749 
ResetFontStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)750 ArkUINativeModuleValue TextInputBridge::ResetFontStyle(ArkUIRuntimeCallInfo *runtimeCallInfo)
751 {
752     EcmaVM *vm = runtimeCallInfo->GetVM();
753     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
754     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
755     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
756     GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputFontStyle(nativeNode);
757     return panda::JSValueRef::Undefined(vm);
758 }
759 
SetFontFamily(ArkUIRuntimeCallInfo * runtimeCallInfo)760 ArkUINativeModuleValue TextInputBridge::SetFontFamily(ArkUIRuntimeCallInfo *runtimeCallInfo)
761 {
762     EcmaVM *vm = runtimeCallInfo->GetVM();
763     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
764     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
765     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
766     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
767 
768     std::vector<std::string> fontFamilies;
769     if (!ArkTSUtils::ParseJsFontFamilies(vm, secondArg, fontFamilies)) {
770         GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputFontFamily(nativeNode);
771     } else {
772         auto families = std::make_unique<char* []>(fontFamilies.size());
773         for (uint32_t i = 0; i < fontFamilies.size(); i++) {
774             families[i] = const_cast<char*>(fontFamilies.at(i).c_str());
775         }
776         GetArkUIInternalNodeAPI()->GetTextInputModifier().SetTextInputFontFamily(nativeNode,
777             const_cast<const char**>(families.get()), fontFamilies.size());
778     }
779     return panda::JSValueRef::Undefined(vm);
780 }
781 
ResetFontFamily(ArkUIRuntimeCallInfo * runtimeCallInfo)782 ArkUINativeModuleValue TextInputBridge::ResetFontFamily(ArkUIRuntimeCallInfo *runtimeCallInfo)
783 {
784     EcmaVM *vm = runtimeCallInfo->GetVM();
785     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
786     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
787     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
788     GetArkUIInternalNodeAPI()->GetTextInputModifier().ResetTextInputFontFamily(nativeNode);
789     return panda::JSValueRef::Undefined(vm);
790 }
791 }
792