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_search_bridge.h"
16
17 #include "base/geometry/dimension.h"
18 #include "base/utils/utils.h"
19 #include "core/interfaces/native/node/api.h"
20 #include "core/components/common/layout/constants.h"
21 #include "core/components/text_field/textfield_theme.h"
22 #include "frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
23 #include "core/components/search/search_theme.h"
24
25 namespace OHOS::Ace::NG {
26 constexpr int NUM_0 = 0;
27 constexpr int NUM_1 = 1;
28 constexpr int NUM_2 = 2;
29 constexpr int NUM_3 = 3;
30 constexpr int NUM_4 = 4;
31 const std::vector<TextAlign> TEXT_ALIGNS = { TextAlign::START, TextAlign::CENTER, TextAlign::END };
32
SetTextFont(ArkUIRuntimeCallInfo * runtimeCallInfo)33 ArkUINativeModuleValue SearchBridge::SetTextFont(ArkUIRuntimeCallInfo* runtimeCallInfo)
34 {
35 EcmaVM* vm = runtimeCallInfo->GetVM();
36 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
37 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
38 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
39 Local<JSValueRef> threeArg = runtimeCallInfo->GetCallArgRef(NUM_2);
40 Local<JSValueRef> fourArg = runtimeCallInfo->GetCallArgRef(NUM_3);
41 Local<JSValueRef> fiveArg = runtimeCallInfo->GetCallArgRef(NUM_4);
42 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
43
44 const char* fontFamilies[1];
45 struct ArkUIFontStruct value = {0.0, 0, 0, INVALID_FONT_STYLE, fontFamilies, 0};
46 auto container = Container::Current();
47 CHECK_NULL_RETURN(container, panda::JSValueRef::Undefined(vm));
48 auto pipelineContext = container->GetPipelineContext();
49 CHECK_NULL_RETURN(pipelineContext, panda::JSValueRef::Undefined(vm));
50 auto themeManager = pipelineContext->GetThemeManager();
51 CHECK_NULL_RETURN(themeManager, panda::JSValueRef::Undefined(vm));
52 auto theme = themeManager->GetTheme<SearchTheme>();
53 CHECK_NULL_RETURN(theme, panda::JSValueRef::Undefined(vm));
54 auto themeFontSize = theme->GetFontSize();
55 CalcDimension size;
56 if (secondArg->IsNull() || secondArg->IsUndefined() ||
57 !ArkTSUtils::ParseJsDimensionFp(vm, secondArg, size) || size.Unit() == DimensionUnit::PERCENT) {
58 value.fontSizeNumber = themeFontSize.Value();
59 value.fontSizeUnit = static_cast<int8_t>(themeFontSize.Unit());
60 } else {
61 value.fontSizeNumber = size.Value();
62 value.fontSizeUnit = static_cast<int8_t>(size.Unit());
63 }
64
65 if (threeArg->IsString() || threeArg->IsNumber()) {
66 if (threeArg->IsString()) {
67 auto weightStr = threeArg->ToString(vm)->ToString();
68 value.fontWeight = std::stoi(weightStr);
69 }
70
71 if (threeArg->IsNumber()) {
72 value.fontWeight = threeArg->Int32Value(vm);
73 }
74 }
75
76 if (fourArg->IsString()) {
77 auto familyStr = fourArg->ToString(vm)->ToString();
78 value.fontFamilies[0] = familyStr.c_str();
79 value.familyLength = 1;
80 }
81
82 if (!fiveArg->IsNull() && fiveArg->IsNumber()) {
83 value.fontStyle = fiveArg->Int32Value(vm);
84 }
85
86 GetArkUIInternalNodeAPI()->GetSearchModifier().SetSearchTextFont(nativeNode, &value);
87 return panda::JSValueRef::Undefined(vm);
88 }
89
ResetTextFont(ArkUIRuntimeCallInfo * runtimeCallInfo)90 ArkUINativeModuleValue SearchBridge::ResetTextFont(ArkUIRuntimeCallInfo* runtimeCallInfo)
91 {
92 EcmaVM* vm = runtimeCallInfo->GetVM();
93 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
94 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
95 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
96 GetArkUIInternalNodeAPI()->GetSearchModifier().ResetSearchTextFont(nativeNode);
97 return panda::JSValueRef::Undefined(vm);
98 }
99
SetPlaceholderColor(ArkUIRuntimeCallInfo * runtimeCallInfo)100 ArkUINativeModuleValue SearchBridge::SetPlaceholderColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
101 {
102 EcmaVM* vm = runtimeCallInfo->GetVM();
103 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
104 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
105 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
106 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
107 Color color;
108 uint32_t result;
109 if (ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) {
110 result = color.GetValue();
111 GetArkUIInternalNodeAPI()->GetSearchModifier().SetSearchPlaceholderColor(nativeNode, result);
112 } else {
113 GetArkUIInternalNodeAPI()->GetSearchModifier().ResetSearchPlaceholderColor(nativeNode);
114 }
115 return panda::JSValueRef::Undefined(vm);
116 }
ResetPlaceholderColor(ArkUIRuntimeCallInfo * runtimeCallInfo)117 ArkUINativeModuleValue SearchBridge::ResetPlaceholderColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
118 {
119 EcmaVM* vm = runtimeCallInfo->GetVM();
120 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
121 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
122 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
123 GetArkUIInternalNodeAPI()->GetSearchModifier().ResetSearchPlaceholderColor(nativeNode);
124 return panda::JSValueRef::Undefined(vm);
125 }
126
SetSelectionMenuHidden(ArkUIRuntimeCallInfo * runtimeCallInfo)127 ArkUINativeModuleValue SearchBridge::SetSelectionMenuHidden(ArkUIRuntimeCallInfo* runtimeCallInfo)
128 {
129 EcmaVM* vm = runtimeCallInfo->GetVM();
130 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
131 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
132 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
133 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
134 if (secondArg->IsBoolean()) {
135 uint32_t selectionMenuHidden = static_cast<uint32_t>(secondArg->ToBoolean(vm)->Value());
136 GetArkUIInternalNodeAPI()->GetSearchModifier().SetSearchSelectionMenuHidden(nativeNode, selectionMenuHidden);
137 } else {
138 GetArkUIInternalNodeAPI()->GetSearchModifier().ResetSearchSelectionMenuHidden(nativeNode);
139 }
140 return panda::JSValueRef::Undefined(vm);
141 }
142
ResetSelectionMenuHidden(ArkUIRuntimeCallInfo * runtimeCallInfo)143 ArkUINativeModuleValue SearchBridge::ResetSelectionMenuHidden(ArkUIRuntimeCallInfo* runtimeCallInfo)
144 {
145 EcmaVM* vm = runtimeCallInfo->GetVM();
146 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
147 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
148 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
149 GetArkUIInternalNodeAPI()->GetSearchModifier().ResetSearchSelectionMenuHidden(nativeNode);
150 return panda::JSValueRef::Undefined(vm);
151 }
152
SetCaretStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)153 ArkUINativeModuleValue SearchBridge::SetCaretStyle(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> caretWidthArg = runtimeCallInfo->GetCallArgRef(NUM_1);
159 Local<JSValueRef> caretColorArg = runtimeCallInfo->GetCallArgRef(NUM_2);
160 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
161
162 auto textFieldTheme = ArkTSUtils::GetTheme<TextFieldTheme>();
163 CHECK_NULL_RETURN(textFieldTheme, panda::JSValueRef::Undefined(vm));
164 CalcDimension caretWidth = textFieldTheme->GetCursorWidth();
165 if (!ArkTSUtils::ParseJsDimensionVpNG(vm, caretWidthArg, caretWidth, false) ||
166 LessNotEqual(caretWidth.Value(), 0.0)) {
167 caretWidth = textFieldTheme->GetCursorWidth();
168 }
169 Color color;
170 uint32_t caretColor;
171 if (ArkTSUtils::ParseJsColorAlpha(vm, caretColorArg, color)) {
172 caretColor = color.GetValue();
173 } else {
174 caretColor = textFieldTheme->GetCursorColor().GetValue();
175 }
176 GetArkUIInternalNodeAPI()->GetSearchModifier().SetSearchCaretStyle(
177 nativeNode, caretWidth.Value(), static_cast<int8_t>(caretWidth.Unit()), caretColor);
178 return panda::JSValueRef::Undefined(vm);
179 }
180
ResetCaretStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)181 ArkUINativeModuleValue SearchBridge::ResetCaretStyle(ArkUIRuntimeCallInfo* runtimeCallInfo)
182 {
183 EcmaVM* vm = runtimeCallInfo->GetVM();
184 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
185 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
186 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
187 GetArkUIInternalNodeAPI()->GetSearchModifier().ResetSearchCaretStyle(nativeNode);
188 return panda::JSValueRef::Undefined(vm);
189 }
190
SetSearchTextAlign(ArkUIRuntimeCallInfo * runtimeCallInfo)191 ArkUINativeModuleValue SearchBridge::SetSearchTextAlign(ArkUIRuntimeCallInfo* runtimeCallInfo)
192 {
193 EcmaVM* vm = runtimeCallInfo->GetVM();
194 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
195 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
196 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
197 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
198
199 if (secondArg->IsNumber()) {
200 int32_t value = secondArg->Int32Value(vm);
201 if (value >= 0 && value < static_cast<int32_t>(TEXT_ALIGNS.size())) {
202 GetArkUIInternalNodeAPI()->GetSearchModifier().SetSearchTextAlign(nativeNode, value);
203 }
204 }
205 return panda::JSValueRef::Undefined(vm);
206 }
207
ResetSearchTextAlign(ArkUIRuntimeCallInfo * runtimeCallInfo)208 ArkUINativeModuleValue SearchBridge::ResetSearchTextAlign(ArkUIRuntimeCallInfo* runtimeCallInfo)
209 {
210 EcmaVM* vm = runtimeCallInfo->GetVM();
211 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
212 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
213 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
214 GetArkUIInternalNodeAPI()->GetSearchModifier().ResetSearchTextAlign(nativeNode);
215 return panda::JSValueRef::Undefined(vm);
216 }
217
ConvertStrToCancelButtonStyle(const std::string & value)218 static CancelButtonStyle ConvertStrToCancelButtonStyle(const std::string& value)
219 {
220 if (value == "CONSTANT") {
221 return CancelButtonStyle::CONSTANT;
222 } else if (value == "INVISIBLE") {
223 return CancelButtonStyle::INVISIBLE;
224 } else {
225 return CancelButtonStyle::INPUT;
226 }
227 }
228
SetCancelButton(ArkUIRuntimeCallInfo * runtimeCallInfo)229 ArkUINativeModuleValue SearchBridge::SetCancelButton(ArkUIRuntimeCallInfo* runtimeCallInfo)
230 {
231 EcmaVM* vm = runtimeCallInfo->GetVM();
232 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
233 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
234 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
235 Local<JSValueRef> thirdArg = runtimeCallInfo->GetCallArgRef(NUM_2);
236 Local<JSValueRef> forthArg = runtimeCallInfo->GetCallArgRef(NUM_3);
237 Local<JSValueRef> fifthArg = runtimeCallInfo->GetCallArgRef(NUM_4);
238 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
239 auto container = Container::Current();
240 CHECK_NULL_RETURN(container, panda::JSValueRef::Undefined(vm));
241 auto pipelineContext = container->GetPipelineContext();
242 CHECK_NULL_RETURN(pipelineContext, panda::JSValueRef::Undefined(vm));
243 auto themeManager = pipelineContext->GetThemeManager();
244 CHECK_NULL_RETURN(themeManager, panda::JSValueRef::Undefined(vm));
245 auto theme = themeManager->GetTheme<SearchTheme>();
246 CHECK_NULL_RETURN(theme, panda::JSValueRef::Undefined(vm));
247 int32_t style = static_cast<int32_t>(theme->GetCancelButtonStyle());
248 if (secondArg->IsString()) {
249 CancelButtonStyle cancelButtonStyle = ConvertStrToCancelButtonStyle(secondArg->ToString(vm)->ToString());
250 style = static_cast<int32_t>(cancelButtonStyle);
251 }
252 struct ArkUISizeType size = {0.0, 0};
253 CalcDimension iconSize;
254 if (!thirdArg->IsUndefined() && !thirdArg->IsNull() &&
255 ArkTSUtils::ParseJsDimensionVpNG(vm, thirdArg, iconSize, false)) {
256 if (LessNotEqual(iconSize.Value(), 0.0) || iconSize.Unit() == DimensionUnit::PERCENT) {
257 iconSize = theme->GetIconHeight();
258 }
259 } else {
260 iconSize = theme->GetIconHeight();
261 }
262 size.value = iconSize.Value();
263 size.unit = static_cast<int8_t>(iconSize.Unit());
264 Color value;
265 uint32_t color;
266 if (!forthArg->IsUndefined() && !forthArg->IsNull() &&
267 ArkTSUtils::ParseJsColorAlpha(vm, forthArg, value)) {
268 color = value.GetValue();
269 } else {
270 color = theme->GetSearchIconColor().GetValue();
271 }
272 std::string srcStr;
273 if (fifthArg->IsUndefined() || fifthArg->IsNull() ||
274 !ArkTSUtils::ParseJsMedia(vm, fifthArg, srcStr)) {
275 srcStr = "";
276 }
277 const char* src = srcStr.c_str();
278 GetArkUIInternalNodeAPI()->GetSearchModifier().SetSearchCancelButton(nativeNode, style, &size, color, src);
279 return panda::JSValueRef::Undefined(vm);
280 }
281
ResetCancelButton(ArkUIRuntimeCallInfo * runtimeCallInfo)282 ArkUINativeModuleValue SearchBridge::ResetCancelButton(ArkUIRuntimeCallInfo* runtimeCallInfo)
283 {
284 EcmaVM* vm = runtimeCallInfo->GetVM();
285 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
286 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
287 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
288 GetArkUIInternalNodeAPI()->GetSearchModifier().ResetSearchCancelButton(nativeNode);
289 return panda::JSValueRef::Undefined(vm);
290 }
291
SetEnableKeyboardOnFocus(ArkUIRuntimeCallInfo * runtimeCallInfo)292 ArkUINativeModuleValue SearchBridge::SetEnableKeyboardOnFocus(ArkUIRuntimeCallInfo* runtimeCallInfo)
293 {
294 EcmaVM* vm = runtimeCallInfo->GetVM();
295 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
296 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
297 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
298 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
299
300 if (secondArg->IsBoolean()) {
301 uint32_t value = static_cast<uint32_t>(secondArg->ToBoolean(vm)->Value());
302 GetArkUIInternalNodeAPI()->GetSearchModifier().SetSearchEnableKeyboardOnFocus(nativeNode, value);
303 } else {
304 GetArkUIInternalNodeAPI()->GetSearchModifier().ResetSearchEnableKeyboardOnFocus(nativeNode);
305 }
306
307 return panda::JSValueRef::Undefined(vm);
308 }
309
ResetEnableKeyboardOnFocus(ArkUIRuntimeCallInfo * runtimeCallInfo)310 ArkUINativeModuleValue SearchBridge::ResetEnableKeyboardOnFocus(ArkUIRuntimeCallInfo* runtimeCallInfo)
311 {
312 EcmaVM* vm = runtimeCallInfo->GetVM();
313 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
314 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
315 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
316 GetArkUIInternalNodeAPI()->GetSearchModifier().ResetSearchEnableKeyboardOnFocus(nativeNode);
317 return panda::JSValueRef::Undefined(vm);
318 }
319
SetPlaceholderFont(ArkUIRuntimeCallInfo * runtimeCallInfo)320 ArkUINativeModuleValue SearchBridge::SetPlaceholderFont(ArkUIRuntimeCallInfo* runtimeCallInfo)
321 {
322 EcmaVM* vm = runtimeCallInfo->GetVM();
323 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
324 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
325 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
326 Local<JSValueRef> threeArg = runtimeCallInfo->GetCallArgRef(NUM_2);
327 Local<JSValueRef> fourArg = runtimeCallInfo->GetCallArgRef(NUM_3);
328 Local<JSValueRef> fiveArg = runtimeCallInfo->GetCallArgRef(NUM_4);
329 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
330
331 const char* fontFamilies[1];
332 struct ArkUIFontStruct value = {0.0, 0, 0, INVALID_FONT_STYLE, fontFamilies, 0};
333 auto container = Container::Current();
334 CHECK_NULL_RETURN(container, panda::JSValueRef::Undefined(vm));
335 auto pipelineContext = container->GetPipelineContext();
336 CHECK_NULL_RETURN(pipelineContext, panda::JSValueRef::Undefined(vm));
337 auto themeManager = pipelineContext->GetThemeManager();
338 CHECK_NULL_RETURN(themeManager, panda::JSValueRef::Undefined(vm));
339 auto theme = themeManager->GetTheme<SearchTheme>();
340 CHECK_NULL_RETURN(theme, panda::JSValueRef::Undefined(vm));
341 auto themeFontSize = theme->GetFontSize();
342 CalcDimension size;
343 if (secondArg->IsNull() || secondArg->IsUndefined() ||
344 !ArkTSUtils::ParseJsDimensionFp(vm, secondArg, size) || size.Unit() == DimensionUnit::PERCENT) {
345 value.fontSizeNumber = themeFontSize.Value();
346 value.fontSizeUnit = static_cast<int8_t>(themeFontSize.Unit());
347 } else {
348 value.fontSizeNumber = size.Value();
349 value.fontSizeUnit = static_cast<int8_t>(size.Unit());
350 }
351
352 if (threeArg->IsString() || threeArg->IsNumber()) {
353 if (threeArg->IsString()) {
354 auto weightStr = threeArg->ToString(vm)->ToString();
355 value.fontWeight = std::stoi(weightStr);
356 }
357
358 if (threeArg->IsNumber()) {
359 value.fontWeight = threeArg->Int32Value(vm);
360 }
361 }
362
363 if (fourArg->IsString()) {
364 auto familyStr = fourArg->ToString(vm)->ToString();
365 value.fontFamilies[0] = familyStr.c_str();
366 value.familyLength = 1;
367 }
368
369 if (!fiveArg->IsNull() && fiveArg->IsNumber()) {
370 value.fontStyle = fiveArg->Int32Value(vm);
371 }
372 GetArkUIInternalNodeAPI()->GetSearchModifier().SetSearchPlaceholderFont(nativeNode, &value);
373 return panda::JSValueRef::Undefined(vm);
374 }
375
ResetPlaceholderFont(ArkUIRuntimeCallInfo * runtimeCallInfo)376 ArkUINativeModuleValue SearchBridge::ResetPlaceholderFont(ArkUIRuntimeCallInfo* runtimeCallInfo)
377 {
378 EcmaVM* vm = runtimeCallInfo->GetVM();
379 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
380 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
381 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
382 GetArkUIInternalNodeAPI()->GetSearchModifier().ResetSearchPlaceholderFont(nativeNode);
383 return panda::JSValueRef::Undefined(vm);
384 }
385
SetSearchIcon(ArkUIRuntimeCallInfo * runtimeCallInfo)386 ArkUINativeModuleValue SearchBridge::SetSearchIcon(ArkUIRuntimeCallInfo* runtimeCallInfo)
387 {
388 EcmaVM* vm = runtimeCallInfo->GetVM();
389 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
390 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
391 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
392 Local<JSValueRef> threeArg = runtimeCallInfo->GetCallArgRef(NUM_2);
393 Local<JSValueRef> fourArg = runtimeCallInfo->GetCallArgRef(NUM_3);
394 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
395
396 struct ArkUIIconOptionsStruct value = {0.0, 0, INVALID_COLOR_VALUE, nullptr};
397
398 CalcDimension size;
399 auto container = Container::Current();
400 CHECK_NULL_RETURN(container, panda::JSValueRef::Undefined(vm));
401 auto pipelineContext = container->GetPipelineContext();
402 CHECK_NULL_RETURN(pipelineContext, panda::JSValueRef::Undefined(vm));
403 auto themeManager = pipelineContext->GetThemeManager();
404 CHECK_NULL_RETURN(themeManager, panda::JSValueRef::Undefined(vm));
405 auto theme = themeManager->GetTheme<SearchTheme>();
406 CHECK_NULL_RETURN(theme, panda::JSValueRef::Undefined(vm));
407 if (!secondArg->IsUndefined() && !secondArg->IsNull() &&
408 ArkTSUtils::ParseJsDimensionVpNG(vm, secondArg, size, false)) {
409 if (LessNotEqual(size.Value(), 0.0) || size.Unit() == DimensionUnit::PERCENT) {
410 size = theme->GetIconHeight();
411 }
412 } else {
413 size = theme->GetIconHeight();
414 }
415 value.value = size.Value();
416 value.unit = static_cast<int8_t>(size.Unit());
417
418 Color color;
419 if (ArkTSUtils::ParseJsColorAlpha(vm, threeArg, color)) {
420 value.color = static_cast<int32_t>(color.GetValue());
421 } else {
422 value.color = INVALID_COLOR_VALUE;
423 }
424
425 std::string srcStr;
426 if (fourArg->IsUndefined() || fourArg->IsNull() || !ArkTSUtils::ParseJsMedia(vm, fourArg, srcStr)) {
427 srcStr = "";
428 }
429 value.src = srcStr.c_str();
430
431 GetArkUIInternalNodeAPI()->GetSearchModifier().SetSearchSearchIcon(nativeNode, &value);
432 return panda::JSValueRef::Undefined(vm);
433 }
434
ResetSearchIcon(ArkUIRuntimeCallInfo * runtimeCallInfo)435 ArkUINativeModuleValue SearchBridge::ResetSearchIcon(ArkUIRuntimeCallInfo* runtimeCallInfo)
436 {
437 EcmaVM* vm = runtimeCallInfo->GetVM();
438 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
439 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
440 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
441 GetArkUIInternalNodeAPI()->GetSearchModifier().ResetSearchSearchIcon(nativeNode);
442 return panda::JSValueRef::Undefined(vm);
443 }
444
SetSearchButton(ArkUIRuntimeCallInfo * runtimeCallInfo)445 ArkUINativeModuleValue SearchBridge::SetSearchButton(ArkUIRuntimeCallInfo* runtimeCallInfo)
446 {
447 EcmaVM* vm = runtimeCallInfo->GetVM();
448 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
449 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
450 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
451 Local<JSValueRef> threeArg = runtimeCallInfo->GetCallArgRef(NUM_2);
452 Local<JSValueRef> fourArg = runtimeCallInfo->GetCallArgRef(NUM_3);
453 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
454
455 struct ArkUISearchButtonOptionsStruct value = {"", 0.0, 0, INVALID_COLOR_VALUE};
456
457 std::string valueString = "";
458 if (secondArg->IsString()) {
459 valueString = secondArg->ToString(vm)->ToString();
460 value.value = valueString.c_str();
461 }
462
463 auto container = Container::Current();
464 CHECK_NULL_RETURN(container, panda::JSValueRef::Undefined(vm));
465 auto pipelineContext = container->GetPipelineContext();
466 CHECK_NULL_RETURN(pipelineContext, panda::JSValueRef::Undefined(vm));
467 auto themeManager = pipelineContext->GetThemeManager();
468 CHECK_NULL_RETURN(themeManager, panda::JSValueRef::Undefined(vm));
469 auto theme = themeManager->GetTheme<SearchTheme>();
470 CHECK_NULL_RETURN(theme, panda::JSValueRef::Undefined(vm));
471 CalcDimension size = theme->GetFontSize();
472 if (ArkTSUtils::ParseJsDimensionVpNG(vm, threeArg, size) && size.Unit() != DimensionUnit::PERCENT &&
473 GreatOrEqual(size.Value(), 0.0)) {
474 ArkTSUtils::ParseJsDimensionFp(vm, threeArg, size);
475 } else {
476 size = theme->GetFontSize();
477 }
478 value.sizeValue = size.Value();
479 value.sizeUnit = static_cast<int8_t>(size.Unit());
480
481 Color fontColor;
482 if (ArkTSUtils::ParseJsColorAlpha(vm, fourArg, fontColor)) {
483 value.fontColor = static_cast<int32_t>(fontColor.GetValue());
484 } else {
485 value.fontColor = static_cast<int32_t>(theme->GetSearchButtonTextColor().GetValue());
486 }
487 GetArkUIInternalNodeAPI()->GetSearchModifier().SetSearchSearchButton(nativeNode, &value);
488 return panda::JSValueRef::Undefined(vm);
489 }
490
ResetSearchButton(ArkUIRuntimeCallInfo * runtimeCallInfo)491 ArkUINativeModuleValue SearchBridge::ResetSearchButton(ArkUIRuntimeCallInfo* runtimeCallInfo)
492 {
493 EcmaVM* vm = runtimeCallInfo->GetVM();
494 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
495 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
496 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
497 GetArkUIInternalNodeAPI()->GetSearchModifier().ResetSearchSearchButton(nativeNode);
498 return panda::JSValueRef::Undefined(vm);
499 }
500
SetFontColor(ArkUIRuntimeCallInfo * runtimeCallInfo)501 ArkUINativeModuleValue SearchBridge::SetFontColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
502 {
503 EcmaVM* vm = runtimeCallInfo->GetVM();
504 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
505 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
506 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
507 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
508 auto container = Container::Current();
509 CHECK_NULL_RETURN(container, panda::JSValueRef::Undefined(vm));
510 auto pipelineContext = container->GetPipelineContext();
511 CHECK_NULL_RETURN(pipelineContext, panda::JSValueRef::Undefined(vm));
512 auto themeManager = pipelineContext->GetThemeManager();
513 CHECK_NULL_RETURN(themeManager, panda::JSValueRef::Undefined(vm));
514 auto theme = themeManager->GetTheme<SearchTheme>();
515 CHECK_NULL_RETURN(theme, panda::JSValueRef::Undefined(vm));
516 Color value;
517 uint32_t color = theme->GetTextColor().GetValue();
518 if (ArkTSUtils::ParseJsColorAlpha(vm, secondArg, value)) {
519 color = value.GetValue();
520 }
521 GetArkUIInternalNodeAPI()->GetSearchModifier().SetSearchFontColor(nativeNode, color);
522 return panda::JSValueRef::Undefined(vm);
523 }
524
ResetFontColor(ArkUIRuntimeCallInfo * runtimeCallInfo)525 ArkUINativeModuleValue SearchBridge::ResetFontColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
526 {
527 EcmaVM* vm = runtimeCallInfo->GetVM();
528 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
529 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
530 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
531 GetArkUIInternalNodeAPI()->GetSearchModifier().ResetSearchFontColor(nativeNode);
532 return panda::JSValueRef::Undefined(vm);
533 }
534
SetCopyOption(ArkUIRuntimeCallInfo * runtimeCallInfo)535 ArkUINativeModuleValue SearchBridge::SetCopyOption(ArkUIRuntimeCallInfo* runtimeCallInfo)
536 {
537 EcmaVM* vm = runtimeCallInfo->GetVM();
538 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
539 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
540 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
541 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
542
543 auto copyOptions = CopyOptions::Local;
544 uint32_t value = static_cast<uint32_t>(copyOptions);
545 if (secondArg->IsNumber()) {
546 value = secondArg->Uint32Value(vm);
547 } else if (!secondArg->IsNumber() && !secondArg->IsUndefined()) {
548 copyOptions = CopyOptions::None;
549 value = static_cast<uint32_t>(copyOptions);
550 }
551 GetArkUIInternalNodeAPI()->GetSearchModifier().SetSearchCopyOption(nativeNode, value);
552 return panda::JSValueRef::Undefined(vm);
553 }
554
ResetCopyOption(ArkUIRuntimeCallInfo * runtimeCallInfo)555 ArkUINativeModuleValue SearchBridge::ResetCopyOption(ArkUIRuntimeCallInfo* runtimeCallInfo)
556 {
557 EcmaVM* vm = runtimeCallInfo->GetVM();
558 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
559 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
560 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
561 GetArkUIInternalNodeAPI()->GetSearchModifier().ResetSearchCopyOption(nativeNode);
562 return panda::JSValueRef::Undefined(vm);
563 }
564
SetSearchHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)565 ArkUINativeModuleValue SearchBridge::SetSearchHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
566 {
567 EcmaVM* vm = runtimeCallInfo->GetVM();
568 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
569 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
570 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
571 Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(1);
572 CalcDimension height;
573 std::string calcStr;
574 if (!ArkTSUtils::ParseJsDimensionVpNG(vm, valueArg, height)) {
575 GetArkUIInternalNodeAPI()->GetCommonModifier().ResetHeight(nativeNode);
576 } else {
577 if (LessNotEqual(height.Value(), 0.0)) {
578 height.SetValue(0.0);
579 }
580 if (height.Unit() == DimensionUnit::CALC) {
581 GetArkUIInternalNodeAPI()->GetCommonModifier().SetHeight(
582 nativeNode, height.Value(), static_cast<int>(height.Unit()), height.CalcValue().c_str());
583 } else {
584 GetArkUIInternalNodeAPI()->GetCommonModifier().SetHeight(
585 nativeNode, height.Value(), static_cast<int>(height.Unit()), calcStr.c_str());
586 }
587 GetArkUIInternalNodeAPI()->GetSearchModifier().SetSearchHeight(
588 nativeNode, height.Value(), static_cast<int>(height.Unit()));
589 }
590 return panda::JSValueRef::Undefined(vm);
591 }
592
ResetSearchHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)593 ArkUINativeModuleValue SearchBridge::ResetSearchHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
594 {
595 EcmaVM* vm = runtimeCallInfo->GetVM();
596 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
597 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
598 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
599 GetArkUIInternalNodeAPI()->GetSearchModifier().ResetSearchHeight(nativeNode);
600 return panda::JSValueRef::Undefined(vm);
601 }
602 } // namespace OHOS::Ace::NG
603