• 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_area_bridge.h"
16 
17 #include "bridge/common/utils/utils.h"
18 #include "core/components/common/properties/text_style.h"
19 #include "core/interfaces/native/node/api.h"
20 #include "bridge/declarative_frontend/engine/jsi/jsi_types.h"
21 #include "bridge/declarative_frontend/jsview/js_view_abstract.h"
22 #include "core/components/common/layout/constants.h"
23 #include "core/components/text_field/textfield_theme.h"
24 #include "core/components_ng/pattern/text_field/text_field_model.h"
25 #include "frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
26 
27 namespace OHOS::Ace::NG {
28 constexpr int NUM_0 = 0;
29 constexpr int NUM_1 = 1;
30 constexpr int NUM_2 = 2;
31 constexpr int NUM_3 = 3;
32 constexpr int NUM_4 = 4;
33 constexpr uint32_t KEY_BOARD_FOCUS_DEFAULT = 1;
34 constexpr uint32_t SHOW_COUNTER_DEFAULT = 0;
35 const int32_t MINI_VAILD_VALUE = 1;
36 const int32_t MAX_VAILD_VALUE = 100;
37 const std::string DEFAULT_FONT_WEIGHT = "400";
38 const std::vector<OHOS::Ace::TextAlign> TEXT_ALIGNS = { OHOS::Ace::TextAlign::START, OHOS::Ace::TextAlign::CENTER,
39     OHOS::Ace::TextAlign::END, OHOS::Ace::TextAlign::JUSTIFY };
40 const std::vector<OHOS::Ace::FontStyle> FONT_STYLES = { OHOS::Ace::FontStyle::NORMAL, OHOS::Ace::FontStyle::ITALIC };
41 
SetStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)42 ArkUINativeModuleValue TextAreaBridge::SetStyle(ArkUIRuntimeCallInfo *runtimeCallInfo)
43 {
44     EcmaVM *vm = runtimeCallInfo->GetVM();
45     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
46     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
47     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
48     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
49     if (secondArg->IsString()) {
50         auto str = secondArg->ToString(vm)->ToString();
51         if (str == "Inline") {
52             GetArkUIInternalNodeAPI()->GetTextAreaModifier().SetTextAreaStyle(nativeNode,
53                 static_cast<int32_t>(InputStyle::INLINE));
54         } else {
55             GetArkUIInternalNodeAPI()->GetTextAreaModifier().SetTextAreaStyle(nativeNode,
56                 static_cast<int32_t>(InputStyle::DEFAULT));
57         }
58     } else {
59         GetArkUIInternalNodeAPI()->GetTextAreaModifier().ResetTextAreaStyle(nativeNode);
60     }
61     return panda::JSValueRef::Undefined(vm);
62 }
63 
ResetStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)64 ArkUINativeModuleValue TextAreaBridge::ResetStyle(ArkUIRuntimeCallInfo *runtimeCallInfo)
65 {
66     EcmaVM *vm = runtimeCallInfo->GetVM();
67     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
68     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
69     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
70     GetArkUIInternalNodeAPI()->GetTextAreaModifier().ResetTextAreaStyle(nativeNode);
71     return panda::JSValueRef::Undefined(vm);
72 }
73 
SetSelectionMenuHidden(ArkUIRuntimeCallInfo * runtimeCallInfo)74 ArkUINativeModuleValue TextAreaBridge::SetSelectionMenuHidden(ArkUIRuntimeCallInfo *runtimeCallInfo)
75 {
76     EcmaVM *vm = runtimeCallInfo->GetVM();
77     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
78     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
79     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
80     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
81     uint32_t contextMenuHidden = 0;
82     if (secondArg->IsBoolean()) {
83         contextMenuHidden = static_cast<uint32_t>(secondArg->ToBoolean(vm)->Value());
84     }
85     GetArkUIInternalNodeAPI()->GetTextAreaModifier().SetTextAreaSelectionMenuHidden(nativeNode, contextMenuHidden);
86     return panda::JSValueRef::Undefined(vm);
87 }
88 
ResetSelectionMenuHidden(ArkUIRuntimeCallInfo * runtimeCallInfo)89 ArkUINativeModuleValue TextAreaBridge::ResetSelectionMenuHidden(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()->GetTextAreaModifier().ResetTextAreaSelectionMenuHidden(nativeNode);
96     return panda::JSValueRef::Undefined(vm);
97 }
98 
SetMaxLines(ArkUIRuntimeCallInfo * runtimeCallInfo)99 ArkUINativeModuleValue TextAreaBridge::SetMaxLines(ArkUIRuntimeCallInfo *runtimeCallInfo)
100 {
101     EcmaVM *vm = runtimeCallInfo->GetVM();
102     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
103     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
104     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
105     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
106     if (secondArg->IsNumber() && secondArg->Int32Value(vm) > 0) {
107         GetArkUIInternalNodeAPI()->GetTextAreaModifier().SetTextAreaMaxLines(nativeNode, secondArg->Uint32Value(vm));
108     } else {
109         GetArkUIInternalNodeAPI()->GetTextAreaModifier().ResetTextAreaMaxLines(nativeNode);
110     }
111     return panda::JSValueRef::Undefined(vm);
112 }
113 
ResetMaxLines(ArkUIRuntimeCallInfo * runtimeCallInfo)114 ArkUINativeModuleValue TextAreaBridge::ResetMaxLines(ArkUIRuntimeCallInfo *runtimeCallInfo)
115 {
116     EcmaVM *vm = runtimeCallInfo->GetVM();
117     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
118     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
119     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
120     GetArkUIInternalNodeAPI()->GetTextAreaModifier().ResetTextAreaMaxLines(nativeNode);
121     return panda::JSValueRef::Undefined(vm);
122 }
123 
SetCopyOption(ArkUIRuntimeCallInfo * runtimeCallInfo)124 ArkUINativeModuleValue TextAreaBridge::SetCopyOption(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     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
130     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
131     int32_t copyOptions = static_cast<int32_t>(OHOS::Ace::CopyOptions::None);
132     int32_t copyOptionsDistributed = static_cast<int32_t>(OHOS::Ace::CopyOptions::Distributed);
133     if (secondArg->IsNumber() && secondArg->Int32Value(vm) >= copyOptions &&
134         secondArg->Int32Value(vm) <= copyOptionsDistributed) {
135         copyOptions = secondArg->Int32Value(vm);
136         GetArkUIInternalNodeAPI()->GetTextAreaModifier().SetTextAreaCopyOption(nativeNode, copyOptions);
137     } else {
138         GetArkUIInternalNodeAPI()->GetTextAreaModifier().ResetTextAreaCopyOption(nativeNode);
139     }
140     return panda::JSValueRef::Undefined(vm);
141 }
142 
ResetCopyOption(ArkUIRuntimeCallInfo * runtimeCallInfo)143 ArkUINativeModuleValue TextAreaBridge::ResetCopyOption(ArkUIRuntimeCallInfo *runtimeCallInfo)
144 {
145     EcmaVM *vm = runtimeCallInfo->GetVM();
146     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
147     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
148     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
149     GetArkUIInternalNodeAPI()->GetTextAreaModifier().ResetTextAreaCopyOption(nativeNode);
150     return panda::JSValueRef::Undefined(vm);
151 }
152 
SetPlaceholderColor(ArkUIRuntimeCallInfo * runtimeCallInfo)153 ArkUINativeModuleValue TextAreaBridge::SetPlaceholderColor(ArkUIRuntimeCallInfo *runtimeCallInfo)
154 {
155     EcmaVM *vm = runtimeCallInfo->GetVM();
156     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
157     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
158     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
159     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
160     Color color;
161     if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) {
162         GetArkUIInternalNodeAPI()->GetTextAreaModifier().ResetTextAreaPlaceholderColor(nativeNode);
163     } else {
164         GetArkUIInternalNodeAPI()->GetTextAreaModifier().SetTextAreaPlaceholderColor(nativeNode, color.GetValue());
165     }
166     return panda::JSValueRef::Undefined(vm);
167 }
168 
ResetPlaceholderColor(ArkUIRuntimeCallInfo * runtimeCallInfo)169 ArkUINativeModuleValue TextAreaBridge::ResetPlaceholderColor(ArkUIRuntimeCallInfo *runtimeCallInfo)
170 {
171     EcmaVM *vm = runtimeCallInfo->GetVM();
172     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
173     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
174     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
175     GetArkUIInternalNodeAPI()->GetTextAreaModifier().ResetTextAreaPlaceholderColor(nativeNode);
176     return panda::JSValueRef::Undefined(vm);
177 }
178 
SetTextAreaTextAlign(ArkUIRuntimeCallInfo * runtimeCallInfo)179 ArkUINativeModuleValue TextAreaBridge::SetTextAreaTextAlign(ArkUIRuntimeCallInfo *runtimeCallInfo)
180 {
181     EcmaVM *vm = runtimeCallInfo->GetVM();
182     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
183     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
184     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
185     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
186     if (secondArg->IsNumber()) {
187         int32_t value = secondArg->Int32Value(vm);
188         if (value >= 0 && value < static_cast<int32_t>(TEXT_ALIGNS.size())) {
189             GetArkUIInternalNodeAPI()->GetTextAreaModifier().SetTextAreaTextAlign(nativeNode, value);
190         } else {
191             return panda::JSValueRef::Undefined(vm);
192         }
193     } else {
194         GetArkUIInternalNodeAPI()->GetTextAreaModifier().ResetTextAreaTextAlign(nativeNode);
195     }
196     return panda::JSValueRef::Undefined(vm);
197 }
198 
ResetTextAreaTextAlign(ArkUIRuntimeCallInfo * runtimeCallInfo)199 ArkUINativeModuleValue TextAreaBridge::ResetTextAreaTextAlign(ArkUIRuntimeCallInfo *runtimeCallInfo)
200 {
201     EcmaVM *vm = runtimeCallInfo->GetVM();
202     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
203     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
204     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
205     GetArkUIInternalNodeAPI()->GetTextAreaModifier().ResetTextAreaTextAlign(nativeNode);
206     return panda::JSValueRef::Undefined(vm);
207 }
208 
SetPlaceholderFont(ArkUIRuntimeCallInfo * runtimeCallInfo)209 ArkUINativeModuleValue TextAreaBridge::SetPlaceholderFont(ArkUIRuntimeCallInfo *runtimeCallInfo)
210 {
211     EcmaVM *vm = runtimeCallInfo->GetVM();
212     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
213     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
214     Local<JSValueRef> fontSzieArg = runtimeCallInfo->GetCallArgRef(NUM_1);
215     Local<JSValueRef> fontWeightArg = runtimeCallInfo->GetCallArgRef(NUM_2);
216     Local<JSValueRef> fontFamilyArg = runtimeCallInfo->GetCallArgRef(NUM_3);
217     Local<JSValueRef> fontStyleArg = runtimeCallInfo->GetCallArgRef(NUM_4);
218     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
219     struct ArkUIResourceLength fontSize = { 0.0, -1, nullptr };
220     CalcDimension size;
221     std::string calcStr;
222     if (ArkTSUtils::ParseJsDimensionNG(vm, fontSzieArg, size, DimensionUnit::FP, false)) {
223         if (size.Unit() == DimensionUnit::CALC) {
224             fontSize.unit = static_cast<int32_t>(DimensionUnit::CALC);
225             calcStr = size.CalcValue();
226             fontSize.string = calcStr.c_str();
227         } else {
228             fontSize.value = size.Value();
229             fontSize.unit = static_cast<int32_t>(size.Unit());
230             fontSize.string = calcStr.c_str();
231         }
232     }
233     std::string fontWeight;
234     if (!fontWeightArg->IsNull()) {
235         if (fontWeightArg->IsNumber()) {
236             fontWeight = std::to_string(fontWeightArg->Int32Value(vm));
237         } else if (fontWeightArg->IsString()) {
238             fontWeight = fontWeightArg->ToString(vm)->ToString();
239         }
240     }
241     std::vector<std::string> fontFamilies;
242     std::string family;
243     if (ArkTSUtils::ParseJsFontFamilies(vm, fontFamilyArg, fontFamilies)) {
244         for (uint32_t i = 0; i < fontFamilies.size(); i++) {
245             family += fontFamilies.at(i);
246             family += ',';
247         }
248         family.pop_back();
249     }
250     int32_t style = -1;
251     if (fontStyleArg->IsNumber()) {
252         style = fontStyleArg->Int32Value(vm);
253         if (style <= 0 || style > static_cast<int32_t>(FONT_STYLES.size())) {
254             style = -1;
255         }
256     }
257     GetArkUIInternalNodeAPI()->GetTextAreaModifier().SetTextAreaPlaceholderFont(nativeNode, &fontSize,
258         fontWeight.c_str(), family.c_str(), style);
259     return panda::JSValueRef::Undefined(vm);
260 }
261 
ResetPlaceholderFont(ArkUIRuntimeCallInfo * runtimeCallInfo)262 ArkUINativeModuleValue TextAreaBridge::ResetPlaceholderFont(ArkUIRuntimeCallInfo *runtimeCallInfo)
263 {
264     EcmaVM *vm = runtimeCallInfo->GetVM();
265     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
266     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
267     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
268     GetArkUIInternalNodeAPI()->GetTextAreaModifier().ResetTextAreaPlaceholderFont(nativeNode);
269     return panda::JSValueRef::Undefined(vm);
270 }
271 
SetBarState(ArkUIRuntimeCallInfo * runtimeCallInfo)272 ArkUINativeModuleValue TextAreaBridge::SetBarState(ArkUIRuntimeCallInfo *runtimeCallInfo)
273 {
274     EcmaVM *vm = runtimeCallInfo->GetVM();
275     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
276     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
277     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
278     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
279     if (secondArg->IsNumber()) {
280         uint32_t barStateValue = secondArg->Uint32Value(vm);
281         GetArkUIInternalNodeAPI()->GetTextAreaModifier().SetTextAreaBarState(nativeNode, barStateValue);
282     } else {
283         GetArkUIInternalNodeAPI()->GetTextAreaModifier().ResetTextAreaBarState(nativeNode);
284     }
285     return panda::JSValueRef::Undefined(vm);
286 }
287 
ResetBarState(ArkUIRuntimeCallInfo * runtimeCallInfo)288 ArkUINativeModuleValue TextAreaBridge::ResetBarState(ArkUIRuntimeCallInfo *runtimeCallInfo)
289 {
290     EcmaVM *vm = runtimeCallInfo->GetVM();
291     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
292     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
293     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
294     GetArkUIInternalNodeAPI()->GetTextAreaModifier().ResetTextAreaBarState(nativeNode);
295     return panda::JSValueRef::Undefined(vm);
296 }
297 
SetEnableKeyboardOnFocus(ArkUIRuntimeCallInfo * runtimeCallInfo)298 ArkUINativeModuleValue TextAreaBridge::SetEnableKeyboardOnFocus(ArkUIRuntimeCallInfo *runtimeCallInfo)
299 {
300     EcmaVM *vm = runtimeCallInfo->GetVM();
301     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
302     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
303     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
304     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
305     uint32_t keyboardOnFocusValue = KEY_BOARD_FOCUS_DEFAULT;
306     if (secondArg->IsBoolean()) {
307         keyboardOnFocusValue = static_cast<uint32_t>(secondArg->ToBoolean(vm)->Value());
308     }
309     GetArkUIInternalNodeAPI()->GetTextAreaModifier().SetTextAreaEnableKeyboardOnFocus(nativeNode, keyboardOnFocusValue);
310     return panda::JSValueRef::Undefined(vm);
311 }
312 
ResetEnableKeyboardOnFocus(ArkUIRuntimeCallInfo * runtimeCallInfo)313 ArkUINativeModuleValue TextAreaBridge::ResetEnableKeyboardOnFocus(ArkUIRuntimeCallInfo *runtimeCallInfo)
314 {
315     EcmaVM *vm = runtimeCallInfo->GetVM();
316     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
317     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
318     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
319     GetArkUIInternalNodeAPI()->GetTextAreaModifier().ResetTextAreaEnableKeyboardOnFocus(nativeNode);
320     return panda::JSValueRef::Undefined(vm);
321 }
322 
SetFontFamily(ArkUIRuntimeCallInfo * runtimeCallInfo)323 ArkUINativeModuleValue TextAreaBridge::SetFontFamily(ArkUIRuntimeCallInfo *runtimeCallInfo)
324 {
325     EcmaVM *vm = runtimeCallInfo->GetVM();
326     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
327     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
328     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
329     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
330     std::vector<std::string> fontFamilies;
331     if (!ArkTSUtils::ParseJsFontFamilies(vm, secondArg, fontFamilies)) {
332         GetArkUIInternalNodeAPI()->GetTextAreaModifier().ResetTextAreaFontFamily(nativeNode);
333         return panda::JSValueRef::Undefined(vm);
334     }
335     std::string families;
336     for (uint32_t i = 0; i < fontFamilies.size(); i++) {
337         families += fontFamilies.at(i);
338         families += ',';
339     }
340     families.pop_back();
341     GetArkUIInternalNodeAPI()->GetTextAreaModifier().SetTextAreaFontFamily(nativeNode, families.c_str());
342     return panda::JSValueRef::Undefined(vm);
343 }
344 
ResetFontFamily(ArkUIRuntimeCallInfo * runtimeCallInfo)345 ArkUINativeModuleValue TextAreaBridge::ResetFontFamily(ArkUIRuntimeCallInfo *runtimeCallInfo)
346 {
347     EcmaVM *vm = runtimeCallInfo->GetVM();
348     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
349     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
350     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
351     GetArkUIInternalNodeAPI()->GetTextAreaModifier().ResetTextAreaFontFamily(nativeNode);
352     return panda::JSValueRef::Undefined(vm);
353 }
354 
SetShowCounter(ArkUIRuntimeCallInfo * runtimeCallInfo)355 ArkUINativeModuleValue TextAreaBridge::SetShowCounter(ArkUIRuntimeCallInfo *runtimeCallInfo)
356 {
357     EcmaVM *vm = runtimeCallInfo->GetVM();
358     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
359     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
360     Local<JSValueRef> showCounterArg = runtimeCallInfo->GetCallArgRef(NUM_1);
361     Local<JSValueRef> inputNumberArg = runtimeCallInfo->GetCallArgRef(NUM_2);
362     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
363     uint32_t value = SHOW_COUNTER_DEFAULT;
364     if (showCounterArg->IsBoolean()) {
365         value = static_cast<uint32_t>(showCounterArg->ToBoolean(vm)->Value());
366         if (inputNumberArg->IsNumber() && inputNumberArg->Int32Value(vm) > MINI_VAILD_VALUE &&
367             inputNumberArg->Int32Value(vm) < MAX_VAILD_VALUE) {
368             GetArkUIInternalNodeAPI()->GetTextAreaModifier().SetCounterType(nativeNode, inputNumberArg->Int32Value(vm));
369         }
370         GetArkUIInternalNodeAPI()->GetTextAreaModifier().SetTextAreaShowCounter(nativeNode, value);
371     } else {
372         GetArkUIInternalNodeAPI()->GetTextAreaModifier().ResetTextAreaShowCounter(nativeNode);
373     }
374     return panda::JSValueRef::Undefined(vm);
375 }
376 
ResetShowCounter(ArkUIRuntimeCallInfo * runtimeCallInfo)377 ArkUINativeModuleValue TextAreaBridge::ResetShowCounter(ArkUIRuntimeCallInfo *runtimeCallInfo)
378 {
379     EcmaVM *vm = runtimeCallInfo->GetVM();
380     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
381     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
382     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
383     GetArkUIInternalNodeAPI()->GetTextAreaModifier().ResetTextAreaShowCounter(nativeNode);
384     return panda::JSValueRef::Undefined(vm);
385 }
386 
SetCaretColor(ArkUIRuntimeCallInfo * runtimeCallInfo)387 ArkUINativeModuleValue TextAreaBridge::SetCaretColor(ArkUIRuntimeCallInfo *runtimeCallInfo)
388 {
389     EcmaVM *vm = runtimeCallInfo->GetVM();
390     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
391     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
392     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
393     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
394     Color color;
395     if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) {
396         GetArkUIInternalNodeAPI()->GetTextAreaModifier().ResetTextAreaCaretColor(nativeNode);
397     } else {
398         GetArkUIInternalNodeAPI()->GetTextAreaModifier().SetTextAreaCaretColor(nativeNode, color.GetValue());
399     }
400     return panda::JSValueRef::Undefined(vm);
401 }
402 
ResetCaretColor(ArkUIRuntimeCallInfo * runtimeCallInfo)403 ArkUINativeModuleValue TextAreaBridge::ResetCaretColor(ArkUIRuntimeCallInfo *runtimeCallInfo)
404 {
405     EcmaVM *vm = runtimeCallInfo->GetVM();
406     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
407     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
408     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
409     GetArkUIInternalNodeAPI()->GetTextAreaModifier().ResetTextAreaCaretColor(nativeNode);
410     return panda::JSValueRef::Undefined(vm);
411 }
412 
SetMaxLength(ArkUIRuntimeCallInfo * runtimeCallInfo)413 ArkUINativeModuleValue TextAreaBridge::SetMaxLength(ArkUIRuntimeCallInfo *runtimeCallInfo)
414 {
415     EcmaVM *vm = runtimeCallInfo->GetVM();
416     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
417     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
418     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
419     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
420     if (secondArg->IsNumber() && secondArg->Int32Value(vm) >= 0) {
421         GetArkUIInternalNodeAPI()->GetTextAreaModifier().SetTextAreaMaxLength(nativeNode, secondArg->Int32Value(vm));
422     } else {
423         GetArkUIInternalNodeAPI()->GetTextAreaModifier().ResetTextAreaMaxLength(nativeNode);
424     }
425     return panda::JSValueRef::Undefined(vm);
426 }
427 
ResetMaxLength(ArkUIRuntimeCallInfo * runtimeCallInfo)428 ArkUINativeModuleValue TextAreaBridge::ResetMaxLength(ArkUIRuntimeCallInfo *runtimeCallInfo)
429 {
430     EcmaVM *vm = runtimeCallInfo->GetVM();
431     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
432     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
433     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
434     GetArkUIInternalNodeAPI()->GetTextAreaModifier().ResetTextAreaMaxLength(nativeNode);
435     return panda::JSValueRef::Undefined(vm);
436 }
437 
SetFontColor(ArkUIRuntimeCallInfo * runtimeCallInfo)438 ArkUINativeModuleValue TextAreaBridge::SetFontColor(ArkUIRuntimeCallInfo *runtimeCallInfo)
439 {
440     EcmaVM *vm = runtimeCallInfo->GetVM();
441     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
442     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
443     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
444     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
445     Color color;
446     if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) {
447         GetArkUIInternalNodeAPI()->GetTextAreaModifier().ResetTextAreaFontColor(nativeNode);
448     } else {
449         GetArkUIInternalNodeAPI()->GetTextAreaModifier().SetTextAreaFontColor(nativeNode, color.GetValue());
450     }
451     return panda::JSValueRef::Undefined(vm);
452 }
453 
ResetFontColor(ArkUIRuntimeCallInfo * runtimeCallInfo)454 ArkUINativeModuleValue TextAreaBridge::ResetFontColor(ArkUIRuntimeCallInfo *runtimeCallInfo)
455 {
456     EcmaVM *vm = runtimeCallInfo->GetVM();
457     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
458     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
459     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
460     GetArkUIInternalNodeAPI()->GetTextAreaModifier().ResetTextAreaFontColor(nativeNode);
461     return panda::JSValueRef::Undefined(vm);
462 }
463 
SetFontStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)464 ArkUINativeModuleValue TextAreaBridge::SetFontStyle(ArkUIRuntimeCallInfo *runtimeCallInfo)
465 {
466     EcmaVM *vm = runtimeCallInfo->GetVM();
467     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
468     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
469     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
470     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
471     if (secondArg->IsNumber()) {
472         int32_t fontStyle = secondArg->Int32Value(vm);
473         if (fontStyle >= 0 && fontStyle < static_cast<int32_t>(FONT_STYLES.size())) {
474             GetArkUIInternalNodeAPI()->GetTextAreaModifier().SetTextAreaFontStyle(nativeNode,
475                 static_cast<uint32_t>(fontStyle));
476         } else {
477             return panda::JSValueRef::Undefined(vm);
478         }
479     } else {
480         GetArkUIInternalNodeAPI()->GetTextAreaModifier().ResetTextAreaFontStyle(nativeNode);
481     }
482     return panda::JSValueRef::Undefined(vm);
483 }
484 
ResetFontStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)485 ArkUINativeModuleValue TextAreaBridge::ResetFontStyle(ArkUIRuntimeCallInfo *runtimeCallInfo)
486 {
487     EcmaVM *vm = runtimeCallInfo->GetVM();
488     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
489     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
490     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
491     GetArkUIInternalNodeAPI()->GetTextAreaModifier().ResetTextAreaFontStyle(nativeNode);
492     return panda::JSValueRef::Undefined(vm);
493 }
494 
SetFontWeight(ArkUIRuntimeCallInfo * runtimeCallInfo)495 ArkUINativeModuleValue TextAreaBridge::SetFontWeight(ArkUIRuntimeCallInfo *runtimeCallInfo)
496 {
497     EcmaVM *vm = runtimeCallInfo->GetVM();
498     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
499     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
500     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
501     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
502     std::string fontWeight = DEFAULT_FONT_WEIGHT;
503     if (!secondArg->IsNull()) {
504         if (secondArg->IsNumber()) {
505             fontWeight = std::to_string(secondArg->Int32Value(vm));
506         } else if (secondArg->IsString()) {
507             fontWeight = secondArg->ToString(vm)->ToString();
508         }
509     }
510     GetArkUIInternalNodeAPI()->GetTextAreaModifier().SetTextAreaFontWeight(nativeNode, fontWeight.c_str());
511     return panda::JSValueRef::Undefined(vm);
512 }
513 
ResetFontWeight(ArkUIRuntimeCallInfo * runtimeCallInfo)514 ArkUINativeModuleValue TextAreaBridge::ResetFontWeight(ArkUIRuntimeCallInfo *runtimeCallInfo)
515 {
516     EcmaVM *vm = runtimeCallInfo->GetVM();
517     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
518     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
519     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
520     GetArkUIInternalNodeAPI()->GetTextAreaModifier().ResetTextAreaFontWeight(nativeNode);
521     return panda::JSValueRef::Undefined(vm);
522 }
523 
SetFontSize(ArkUIRuntimeCallInfo * runtimeCallInfo)524 ArkUINativeModuleValue TextAreaBridge::SetFontSize(ArkUIRuntimeCallInfo *runtimeCallInfo)
525 {
526     EcmaVM *vm = runtimeCallInfo->GetVM();
527     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
528     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
529     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
530     Local<JSValueRef> jsValue = runtimeCallInfo->GetCallArgRef(NUM_1);
531     struct ArkUIResourceLength fontSize = { 0.0, 0, nullptr };
532     CalcDimension size;
533     std::string calcStr;
534     if (jsValue->IsUndefined() || !ArkTSUtils::ParseJsDimensionNG(vm, jsValue, size, DimensionUnit::FP, false)) {
535         GetArkUIInternalNodeAPI()->GetTextAreaModifier().ResetTextAreaFontSize(nativeNode);
536     } else {
537         if (size.Unit() == DimensionUnit::CALC) {
538             fontSize.unit = static_cast<int32_t>(DimensionUnit::CALC);
539             calcStr = size.CalcValue();
540             fontSize.string = calcStr.c_str();
541             GetArkUIInternalNodeAPI()->GetTextAreaModifier().SetTextAreaFontSize(nativeNode, &fontSize);
542         } else {
543             fontSize.value = size.Value();
544             fontSize.unit = static_cast<int32_t>(size.Unit());
545             fontSize.string = calcStr.c_str();
546             GetArkUIInternalNodeAPI()->GetTextAreaModifier().SetTextAreaFontSize(nativeNode, &fontSize);
547         }
548     }
549     return panda::JSValueRef::Undefined(vm);
550 }
551 
ResetFontSize(ArkUIRuntimeCallInfo * runtimeCallInfo)552 ArkUINativeModuleValue TextAreaBridge::ResetFontSize(ArkUIRuntimeCallInfo *runtimeCallInfo)
553 {
554     EcmaVM *vm = runtimeCallInfo->GetVM();
555     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
556     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
557     void *nativeNode = firstArg->ToNativePointer(vm)->Value();
558     GetArkUIInternalNodeAPI()->GetTextAreaModifier().ResetTextAreaFontSize(nativeNode);
559     return panda::JSValueRef::Undefined(vm);
560 }
561 } // namespace OHOS::Ace::NG
562