• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 
16 #include "bridge/declarative_frontend/jsview/js_search.h"
17 
18 #include "core/components/search/search_component.h"
19 #include "core/components/search/search_theme.h"
20 #include "core/components/text_field/text_field_component.h"
21 #include "frameworks/bridge/declarative_frontend/jsview/js_view_common_def.h"
22 #include "frameworks/bridge/declarative_frontend/view_stack_processor.h"
23 
24 namespace OHOS::Ace::Framework {
25 
26 namespace {
27 
28 const TextInputAction INPUT_TEXTINPUTACTION_VALUE_DEFAULT = TextInputAction::UNSPECIFIED;
29 const std::vector<std::string> INPUT_FONT_FAMILY_VALUE = {
30     "sans-serif",
31 };
32 
33 Radius defaultRadius;
34 constexpr Dimension BOX_HOVER_RADIUS = 18.0_vp;
35 bool isPaddingChanged;
36 
InitializeDefaultValue(const RefPtr<BoxComponent> & boxComponent,const RefPtr<TextFieldComponent> & component,const RefPtr<TextFieldTheme> & theme)37 void InitializeDefaultValue(const RefPtr<BoxComponent>& boxComponent,
38     const RefPtr<TextFieldComponent>& component, const RefPtr<TextFieldTheme>& theme)
39 {
40     component->SetAction(INPUT_TEXTINPUTACTION_VALUE_DEFAULT);
41     component->SetCursorColor(theme->GetCursorColor());
42     component->SetCursorRadius(theme->GetCursorRadius());
43     component->SetPlaceholderColor(theme->GetPlaceholderColor());
44 
45     component->SetFocusBgColor(theme->GetFocusBgColor());
46     component->SetFocusPlaceholderColor(theme->GetFocusPlaceholderColor());
47     component->SetFocusTextColor(theme->GetFocusTextColor());
48     component->SetBgColor(theme->GetBgColor());
49     component->SetTextColor(theme->GetTextColor());
50     component->SetSelectedColor(theme->GetSelectedColor());
51     component->SetHoverColor(theme->GetHoverColor());
52     component->SetPressColor(theme->GetPressColor());
53     component->SetNeedFade(theme->NeedFade());
54     component->SetShowEllipsis(theme->ShowEllipsis());
55 
56     TextStyle textStyle = component->GetTextStyle();
57     textStyle.SetTextColor(theme->GetTextColor());
58     textStyle.SetFontSize(theme->GetFontSize());
59     textStyle.SetFontWeight(theme->GetFontWeight());
60     textStyle.SetFontFamilies(INPUT_FONT_FAMILY_VALUE);
61     component->SetTextStyle(textStyle);
62 
63     component->SetCountTextStyle(theme->GetCountTextStyle());
64     component->SetOverCountStyle(theme->GetOverCountStyle());
65     component->SetCountTextStyleOuter(theme->GetCountTextStyleOuter());
66     component->SetOverCountStyleOuter(theme->GetOverCountStyleOuter());
67 
68     component->SetErrorTextStyle(theme->GetErrorTextStyle());
69     component->SetErrorSpacing(theme->GetErrorSpacing());
70     component->SetErrorIsInner(theme->GetErrorIsInner());
71     component->SetErrorBorderWidth(theme->GetErrorBorderWidth());
72     component->SetErrorBorderColor(theme->GetErrorBorderColor());
73 
74     RefPtr<Decoration> decoration = AceType::MakeRefPtr<Decoration>();
75     decoration->SetPadding(theme->GetPadding());
76     decoration->SetBackgroundColor(theme->GetBgColor());
77     decoration->SetBorderRadius(theme->GetBorderRadius());
78     defaultRadius = theme->GetBorderRadius();
79     const auto& boxDecoration = boxComponent->GetBackDecoration();
80     if (boxDecoration) {
81         decoration->SetImage(boxDecoration->GetImage());
82         decoration->SetGradient(boxDecoration->GetGradient());
83     }
84     component->SetDecoration(decoration);
85 
86     component->SetIconSize(theme->GetIconSize());
87     component->SetIconHotZoneSize(theme->GetIconHotZoneSize());
88 
89     boxComponent->SetPadding(theme->GetPadding());
90     component->SetHeight(theme->GetHeight());
91 }
92 
UpdateDecorationStyle(const RefPtr<BoxComponent> & boxComponent,const RefPtr<TextFieldComponent> & component,const Border & boxBorder,bool hasBoxRadius)93 void UpdateDecorationStyle(const RefPtr<BoxComponent>& boxComponent,
94     const RefPtr<TextFieldComponent>& component, const Border& boxBorder, bool hasBoxRadius)
95 {
96     RefPtr<Decoration> decoration = component->GetDecoration();
97     if (!decoration) {
98         decoration = AceType::MakeRefPtr<Decoration>();
99     }
100     if (hasBoxRadius) {
101         decoration->SetBorder(boxBorder);
102     } else {
103         Border border = decoration->GetBorder();
104         border.SetLeftEdge(boxBorder.Left());
105         border.SetRightEdge(boxBorder.Right());
106         border.SetTopEdge(boxBorder.Top());
107         border.SetBottomEdge(boxBorder.Bottom());
108         border.SetBorderRadius(defaultRadius);
109         decoration->SetBorder(border);
110     }
111     component->SetOriginBorder(decoration->GetBorder());
112 
113     if (!boxComponent) {
114         return;
115     }
116     RefPtr<Decoration> boxDecoration = boxComponent->GetBackDecoration();
117     if (boxDecoration && (boxDecoration->GetImage() || boxDecoration->GetGradient().IsValid())) {
118         // clear box properties except background image and radius.
119         boxDecoration->SetBackgroundColor(Color::TRANSPARENT);
120         Border border;
121         if (!hasBoxRadius) {
122             border.SetBorderRadius(defaultRadius);
123         } else {
124             border.SetTopLeftRadius(boxBorder.TopLeftRadius());
125             border.SetTopRightRadius(boxBorder.TopRightRadius());
126             border.SetBottomLeftRadius(boxBorder.BottomLeftRadius());
127             border.SetBottomRightRadius(boxBorder.BottomRightRadius());
128         }
129         boxDecoration->SetBorder(border);
130     } else {
131         RefPtr<Decoration> backDecoration = AceType::MakeRefPtr<Decoration>();
132         backDecoration->SetBorderRadius(Radius(BOX_HOVER_RADIUS));
133         boxComponent->SetBackDecoration(backDecoration);
134     }
135     boxComponent->SetPadding(Edge());
136 }
137 
InitializeComponent(OHOS::Ace::RefPtr<OHOS::Ace::SearchComponent> & searchComponent,OHOS::Ace::RefPtr<OHOS::Ace::TextFieldComponent> & textFieldComponent,const OHOS::Ace::RefPtr<OHOS::Ace::SearchTheme> & searchTheme,const OHOS::Ace::RefPtr<OHOS::Ace::TextFieldTheme> & textFieldTheme)138 void InitializeComponent(OHOS::Ace::RefPtr<OHOS::Ace::SearchComponent>& searchComponent,
139                          OHOS::Ace::RefPtr<OHOS::Ace::TextFieldComponent>& textFieldComponent,
140                          const OHOS::Ace::RefPtr<OHOS::Ace::SearchTheme>& searchTheme,
141                          const OHOS::Ace::RefPtr<OHOS::Ace::TextFieldTheme>& textFieldTheme)
142 {
143     textFieldComponent->SetTextFieldController(AceType::MakeRefPtr<TextFieldController>());
144 
145     auto boxComponent = ViewStackProcessor::GetInstance()->GetBoxComponent();
146 
147     InitializeDefaultValue(boxComponent, textFieldComponent, textFieldTheme);
148 
149     boxComponent->SetBackDecoration(nullptr);
150     boxComponent->SetPadding(Edge());
151     textFieldComponent->SetIconSize(searchTheme->GetIconSize());
152     textFieldComponent->SetIconHotZoneSize(searchTheme->GetCloseIconHotZoneSize());
153     Edge decorationPadding;
154     Dimension leftPadding = searchTheme->GetLeftPadding();
155     Dimension rightPadding = searchTheme->GetRightPadding();
156     decorationPadding = Edge(rightPadding.Value(), 0.0, leftPadding.Value(), 0.0, leftPadding.Unit());
157     auto textFieldDecoration = textFieldComponent->GetDecoration();
158     if (textFieldDecoration) {
159         textFieldDecoration->SetPadding(decorationPadding);
160         textFieldDecoration->SetBorderRadius(searchTheme->GetBorderRadius());
161         textFieldComponent->SetOriginBorder(textFieldDecoration->GetBorder());
162     }
163     textFieldComponent->SetAction(TextInputAction::SEARCH);
164     textFieldComponent->SetWidthReserved(searchTheme->GetTextFieldWidthReserved());
165     textFieldComponent->SetTextColor(searchTheme->GetTextColor());
166     textFieldComponent->SetFocusTextColor(searchTheme->GetFocusTextColor());
167     textFieldComponent->SetPlaceholderColor(searchTheme->GetPlaceholderColor());
168     textFieldComponent->SetFocusPlaceholderColor(searchTheme->GetFocusPlaceholderColor());
169     textFieldComponent->SetBlockRightShade(searchTheme->GetBlockRightShade());
170 
171     auto textStyle = textFieldComponent->GetTextStyle();
172     searchComponent->SetPlaceHoldStyle(textStyle);
173     searchComponent->SetEditingStyle(textStyle);
174 
175     std::function<void(const std::string&)> submitEvent;
176     searchComponent->SetSubmitEvent(submitEvent);
177     searchComponent->SetChild(textFieldComponent);
178     searchComponent->SetTextEditController(textFieldComponent->GetTextEditController());
179     searchComponent->SetCloseIconSize(searchTheme->GetCloseIconSize());
180     searchComponent->SetCloseIconHotZoneHorizontal(searchTheme->GetCloseIconHotZoneSize());
181     searchComponent->SetHoverColor(textFieldTheme->GetHoverColor());
182     searchComponent->SetPressColor(textFieldTheme->GetPressColor());
183     isPaddingChanged = false;
184 }
185 
PrepareSpecializedComponent(OHOS::Ace::RefPtr<OHOS::Ace::SearchComponent> & searchComponent,OHOS::Ace::RefPtr<OHOS::Ace::TextFieldComponent> & textFieldComponent)186 void PrepareSpecializedComponent(OHOS::Ace::RefPtr<OHOS::Ace::SearchComponent>& searchComponent,
187                                  OHOS::Ace::RefPtr<OHOS::Ace::TextFieldComponent>& textFieldComponent)
188 {
189     Border boxBorder;
190 
191     auto boxComponent = ViewStackProcessor::GetInstance()->GetBoxComponent();
192 
193     boxComponent->SetMouseAnimationType(HoverAnimationType::OPACITY);
194     if (boxComponent->GetBackDecoration()) {
195         boxBorder = boxComponent->GetBackDecoration()->GetBorder();
196     }
197     UpdateDecorationStyle(boxComponent, textFieldComponent, boxBorder, false);
198     if (GreatOrEqual(boxComponent->GetHeightDimension().Value(), 0.0)) {
199         textFieldComponent->SetHeight(boxComponent->GetHeightDimension());
200     }
201     if (isPaddingChanged) {
202         auto padding = textFieldComponent->GetDecoration()->GetPadding();
203         if (searchComponent->GetTextDirection() == TextDirection::RTL) {
204             padding.SetLeft(padding.Left() + searchComponent->GetCloseIconHotZoneHorizontal());
205         } else {
206             padding.SetRight(padding.Right() + searchComponent->GetCloseIconHotZoneHorizontal());
207         }
208         textFieldComponent->GetDecoration()->SetPadding(padding);
209         searchComponent->SetDecoration(textFieldComponent->GetDecoration());
210         isPaddingChanged = false;
211     }
212 }
213 
214 }
215 
JSBind(BindingTarget globalObj)216 void JSSearch::JSBind(BindingTarget globalObj)
217 {
218     JSClass<JSSearch>::Declare("Search");
219     MethodOptions opt = MethodOptions::NONE;
220 
221     JSClass<JSSearch>::StaticMethod("create", &JSSearch::Create, opt);
222     JSClass<JSSearch>::StaticMethod("searchButton", &JSSearch::SetSearchButton, opt);
223     JSClass<JSSearch>::StaticMethod("placeholderColor", &JSSearch::SetPlaceholderColor, opt);
224     JSClass<JSSearch>::StaticMethod("placeholderFont", &JSSearch::SetPlaceholderFont, opt);
225     JSClass<JSSearch>::StaticMethod("textFont", &JSSearch::SetTextFont, opt);
226     JSClass<JSSearch>::StaticMethod("onSubmit", &JSSearch::OnSubmit, opt);
227     JSClass<JSSearch>::StaticMethod("onChange", &JSSearch::OnChange, opt);
228 
229     JSClass<JSSearch>::StaticMethod("onTouch", &JSInteractableView::JsOnTouch);
230     JSClass<JSSearch>::StaticMethod("height", &JSSearch::SetHeight);
231     JSClass<JSSearch>::StaticMethod("width", &JSViewAbstract::JsWidth);
232     JSClass<JSSearch>::StaticMethod("onKeyEvent", &JSInteractableView::JsOnKey);
233     JSClass<JSSearch>::StaticMethod("onDeleteEvent", &JSInteractableView::JsOnDelete);
234     JSClass<JSSearch>::StaticMethod("onClick", &JSInteractableView::JsOnClick);
235     JSClass<JSSearch>::StaticMethod("onAppear", &JSInteractableView::JsOnAppear);
236     JSClass<JSSearch>::StaticMethod("onDisAppear", &JSInteractableView::JsOnDisAppear);
237     JSClass<JSSearch>::StaticMethod("onCopy", &JSSearch::SetOnCopy);
238     JSClass<JSSearch>::StaticMethod("onCut", &JSSearch::SetOnCut);
239     JSClass<JSSearch>::StaticMethod("onPaste", &JSSearch::SetOnPaste);
240     JSClass<JSSearch>::Inherit<JSViewAbstract>();
241     JSClass<JSSearch>::Bind(globalObj);
242 }
243 
Create(const JSCallbackInfo & info)244 void JSSearch::Create(const JSCallbackInfo& info)
245 {
246     if (info.Length() < 1) {
247         LOGE("The arg is wrong, it is supposed to have at least 1 argument");
248         return;
249     }
250 
251     if (!info[0]->IsObject()) {
252         LOGE("The arg is wrong, it is supposed to be an object");
253         return;
254     }
255 
256     auto searchComponent = AceType::MakeRefPtr<OHOS::Ace::SearchComponent>();
257     ViewStackProcessor::GetInstance()->Push(searchComponent);
258 
259     auto textFieldComponent = AceType::MakeRefPtr<OHOS::Ace::TextFieldComponent>();
260     auto textFieldTheme = GetTheme<TextFieldTheme>();
261     auto searchTheme = GetTheme<SearchTheme>();
262 
263     InitializeComponent(searchComponent, textFieldComponent, searchTheme, textFieldTheme);
264     PrepareSpecializedComponent(searchComponent, textFieldComponent);
265 
266     auto param = JSRef<JSObject>::Cast(info[0]);
267     auto value = param->GetProperty("value");
268     if (!value->IsUndefined() && value->IsString()) {
269         auto key = value->ToString();
270         textFieldComponent->SetValue(key);
271     }
272 
273     auto placeholde = param->GetProperty("placeholder");
274     if (!placeholde->IsUndefined() && placeholde->IsString()) {
275         auto tip = placeholde->ToString();
276         textFieldComponent->SetPlaceholder(tip);
277     }
278 
279     auto controllerObj = param->GetProperty("controller");
280     if (!controllerObj->IsUndefined() && !controllerObj->IsNull()) {
281         JSSearchController* jsController = JSRef<JSObject>::Cast(controllerObj)->Unwrap<JSSearchController>();
282         if (jsController) {
283             jsController->SetController(textFieldComponent->GetTextFieldController());
284         }
285     } else {
286         LOGI("controller is nullptr");
287     }
288 
289     auto icon = param->GetProperty("icon");
290     if (!icon->IsUndefined() && icon->IsString()) {
291         auto src = icon->ToString();
292         textFieldComponent->SetIconImage(src);
293     }
294 }
295 
SetSearchButton(const std::string & text)296 void JSSearch::SetSearchButton(const std::string& text)
297 {
298     auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
299     auto searchComponent = AceType::DynamicCast<SearchComponent>(component);
300     if (!searchComponent) {
301         LOGE("component error");
302         return;
303     }
304 
305     searchComponent->SetSearchText(text);
306 }
307 
SetPlaceholderColor(const JSCallbackInfo & info)308 void JSSearch::SetPlaceholderColor(const JSCallbackInfo& info)
309 {
310     auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
311     auto searchComponent = AceType::DynamicCast<SearchComponent>(component);
312     if (!searchComponent) {
313         LOGE("search component error");
314         return;
315     }
316 
317     auto childComponent = searchComponent->GetChild();
318     if (!childComponent) {
319         LOGE("component error");
320         return;
321     }
322 
323     auto textFieldComponent = AceType::DynamicCast<TextFieldComponent>(childComponent);
324     if (!textFieldComponent) {
325         LOGE("text component error");
326         return;
327     }
328 
329     auto value = JSRef<JSVal>::Cast(info[0]);
330 
331     Color colorVal;
332     if (ParseJsColor(value, colorVal)) {
333         textFieldComponent->SetPlaceholderColor(colorVal);
334         textFieldComponent->SetFocusPlaceholderColor(colorVal);
335     }
336 }
337 
SetPlaceholderFont(const JSCallbackInfo & info)338 void JSSearch::SetPlaceholderFont(const JSCallbackInfo& info)
339 {
340     auto param = JSRef<JSObject>::Cast(info[0]);
341     auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
342     auto searchComponent = AceType::DynamicCast<SearchComponent>(component);
343     if (!searchComponent) {
344         LOGE("search component error");
345         return;
346     }
347 
348     auto size = param->GetProperty("size");
349     TextStyle textStyle = searchComponent->GetPlaceHoldStyle();
350 
351     if (!size->IsNull() && size->IsNumber()) {
352         Dimension fontSize;
353         if (ParseJsDimensionFp(size, fontSize)) {
354             textStyle.SetFontSize(fontSize);
355         }
356     }
357 
358     auto weight = param->GetProperty("weight");
359     if (!weight->IsNull() && weight->IsNumber()) {
360         FontWeight weightVal = static_cast<FontWeight>(weight->ToNumber<int32_t>());
361         textStyle.SetFontWeight(weightVal);
362     }
363 
364     auto family = param->GetProperty("family");
365     if (!family->IsNull() && family->IsString()) {
366         auto familyVal = family->ToString();
367         textStyle.SetFontFamilies(ConvertStrToFontFamilies(familyVal));
368     }
369 
370     auto style = param->GetProperty("style");
371     if (!style->IsNull() && style->IsNumber()) {
372         FontStyle styleVal = static_cast<FontStyle>(style->ToNumber<int32_t>());
373         textStyle.SetFontStyle(styleVal);
374     }
375     searchComponent->SetPlaceHoldStyle(textStyle);
376 }
377 
SetTextFont(const JSCallbackInfo & info)378 void JSSearch::SetTextFont(const JSCallbackInfo& info)
379 {
380     auto param = JSRef<JSObject>::Cast(info[0]);
381     auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
382     auto searchComponent = AceType::DynamicCast<SearchComponent>(component);
383     if (!searchComponent) {
384         LOGE("search component error");
385         return;
386     }
387 
388     auto size = param->GetProperty("size");
389     TextStyle textStyle = searchComponent->GetEditingStyle();
390 
391     if (!size->IsNull() && size->IsNumber()) {
392         Dimension fontSize;
393         if (ParseJsDimensionFp(size, fontSize)) {
394             textStyle.SetFontSize(fontSize);
395         }
396     }
397 
398     auto weight = param->GetProperty("weight");
399     if (!weight->IsNull() && weight->IsNumber()) {
400         FontWeight weightVal = static_cast<FontWeight>(weight->ToNumber<int32_t>());
401         textStyle.SetFontWeight(weightVal);
402     }
403 
404     auto family = param->GetProperty("family");
405     if (!family->IsNull() && family->IsString()) {
406         auto familyVal = family->ToString();
407         textStyle.SetFontFamilies(ConvertStrToFontFamilies(familyVal));
408     }
409 
410     auto style = param->GetProperty("style");
411     if (!style->IsNull() && style->IsNumber()) {
412         FontStyle styleVal = static_cast<FontStyle>(style->ToNumber<int32_t>());
413         textStyle.SetFontStyle(styleVal);
414     }
415     searchComponent->SetEditingStyle(textStyle);
416 }
417 
OnSubmit(const JSCallbackInfo & info)418 void JSSearch::OnSubmit(const JSCallbackInfo& info)
419 {
420     if (!JSViewBindEvent(&SearchComponent::SetOnSubmit, info)) {
421         LOGE("Failed to bind event");
422     }
423     info.ReturnSelf();
424 }
425 
OnChange(const JSCallbackInfo & info)426 void JSSearch::OnChange(const JSCallbackInfo& info)
427 {
428     if (!JSViewBindEvent(&SearchComponent::SetOnChange, info)) {
429         LOGE("Failed to bind event");
430     }
431     info.ReturnSelf();
432 }
433 
SetHeight(const JSCallbackInfo & info)434 void JSSearch::SetHeight(const JSCallbackInfo& info)
435 {
436     JSViewAbstract::JsHeight(info);
437     if (info.Length() < 1) {
438         LOGE("The arg is wrong, it is supposed to have at least 1 arguments");
439         return;
440     }
441     Dimension value;
442     if (!ParseJsDimensionVp(info[0], value)) {
443         LOGE("The arg is wrong, it is supposed to be a number arguments");
444         return;
445     }
446     if (LessNotEqual(value.Value(), 0.0)) {
447         value.SetValue(0.0);
448     }
449 
450     auto stack = ViewStackProcessor::GetInstance();
451     auto searchComponent = AceType::DynamicCast<SearchComponent>(stack->GetMainComponent());
452     if (!searchComponent) {
453         LOGE("SearchComponent set height failed, SearchComponent is null.");
454         return;
455     }
456     auto childComponent = searchComponent->GetChild();
457     if (!childComponent) {
458         LOGE("component error");
459         return;
460     }
461     auto textFieldComponent = AceType::DynamicCast<TextFieldComponent>(childComponent);
462     if (!textFieldComponent) {
463         LOGE("text component error");
464         return;
465     }
466     textFieldComponent->SetHeight(value);
467 }
468 
SetOnCopy(const JSCallbackInfo & info)469 void JSSearch::SetOnCopy(const JSCallbackInfo& info)
470 {
471     if (!JSViewBindEvent(&TextFieldComponent::SetOnCopy, info)) {
472         LOGW("Failed(OnCopy) to bind event");
473     }
474     info.ReturnSelf();
475 }
476 
SetOnCut(const JSCallbackInfo & info)477 void JSSearch::SetOnCut(const JSCallbackInfo& info)
478 {
479     if (!JSViewBindEvent(&TextFieldComponent::SetOnCut, info)) {
480         LOGW("Failed(OnCut) to bind event");
481     }
482     info.ReturnSelf();
483 }
484 
SetOnPaste(const JSCallbackInfo & info)485 void JSSearch::SetOnPaste(const JSCallbackInfo& info)
486 {
487     if (!JSViewBindEvent(&TextFieldComponent::SetOnPaste, info)) {
488         LOGW("Failed(OnPaste) to bind event");
489     }
490     info.ReturnSelf();
491 }
492 
JSBind(BindingTarget globalObj)493 void JSSearchController::JSBind(BindingTarget globalObj)
494 {
495     JSClass<JSSearchController>::Declare("SearchController");
496     JSClass<JSSearchController>::Method("caretPosition", &JSSearchController::CaretPosition);
497     JSClass<JSSearchController>::Bind(globalObj, JSSearchController::Constructor, JSSearchController::Destructor);
498 }
499 
Constructor(const JSCallbackInfo & args)500 void JSSearchController::Constructor(const JSCallbackInfo& args)
501 {
502     auto scroller = Referenced::MakeRefPtr<JSSearchController>();
503     scroller->IncRefCount();
504     args.SetReturnValue(Referenced::RawPtr(scroller));
505 }
506 
Destructor(JSSearchController * scroller)507 void JSSearchController::Destructor(JSSearchController* scroller)
508 {
509     if (scroller != nullptr) {
510         scroller->DecRefCount();
511     }
512 }
513 
CaretPosition(int32_t caretPosition)514 void JSSearchController::CaretPosition(int32_t caretPosition)
515 {
516     auto controller = controller_.Upgrade();
517     if (controller) {
518         controller->CaretPosition(caretPosition);
519     }
520 }
521 
522 } // namespace OHOS::Ace::Framework
523