• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 20212022 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 "frameworks/bridge/declarative_frontend/jsview/js_textarea.h"
17 
18 #include <vector>
19 
20 #include "frameworks/bridge/common/utils/utils.h"
21 #include "frameworks/bridge/declarative_frontend/engine/functions/js_clipboard_function.h"
22 #include "frameworks/bridge/declarative_frontend/engine/functions/js_function.h"
23 #include "frameworks/bridge/declarative_frontend/jsview/js_container_base.h"
24 #include "frameworks/bridge/declarative_frontend/jsview/js_interactable_view.h"
25 #include "frameworks/bridge/declarative_frontend/jsview/js_textfield.h"
26 #include "frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h"
27 #include "frameworks/bridge/declarative_frontend/jsview/js_view_common_def.h"
28 #include "frameworks/bridge/declarative_frontend/view_stack_processor.h"
29 
30 namespace OHOS::Ace::Framework {
31 
JSBind(BindingTarget globalObj)32 void JSTextArea::JSBind(BindingTarget globalObj)
33 {
34     JSClass<JSTextArea>::Declare("TextArea");
35     MethodOptions opt = MethodOptions::NONE;
36     JSClass<JSTextArea>::StaticMethod("create", &JSTextArea::Create, opt);
37     JSClass<JSTextArea>::StaticMethod("placeholderColor", &JSTextField::SetPlaceholderColor);
38     JSClass<JSTextArea>::StaticMethod("placeholderFont", &JSTextField::SetPlaceholderFont);
39     JSClass<JSTextArea>::StaticMethod("backgroundColor", &JSTextField::SetBackgroundColor);
40     JSClass<JSTextArea>::StaticMethod("textAlign", &JSTextField::SetTextAlign);
41     JSClass<JSTextArea>::StaticMethod("caretColor", &JSTextField::SetCaretColor);
42     JSClass<JSTextArea>::StaticMethod("height", &JSTextField::JsHeight);
43     JSClass<JSTextArea>::StaticMethod("padding", &JSTextField::JsPadding);
44     JSClass<JSTextArea>::StaticMethod("border", &JSTextField::JsBorder);
45     JSClass<JSTextArea>::StaticMethod("borderWidth", &JSTextField::JsBorderWidth);
46     JSClass<JSTextArea>::StaticMethod("borderColor", &JSTextField::JsBorderColor);
47     JSClass<JSTextArea>::StaticMethod("borderStyle", &JSTextField::JsBorderStyle);
48     JSClass<JSTextArea>::StaticMethod("borderRadius", &JSTextField::JsBorderRadius);
49     JSClass<JSTextArea>::StaticMethod("fontSize", &JSTextField::SetFontSize);
50     JSClass<JSTextArea>::StaticMethod("fontColor", &JSTextField::SetTextColor);
51     JSClass<JSTextArea>::StaticMethod("fontWeight", &JSTextField::SetFontWeight);
52     JSClass<JSTextArea>::StaticMethod("fontStyle", &JSTextField::SetFontStyle);
53     JSClass<JSTextArea>::StaticMethod("fontFamily", &JSTextField::SetFontFamily);
54     JSClass<JSTextArea>::StaticMethod("inputFilter", &JSTextField::SetInputFilter);
55     JSClass<JSTextArea>::StaticMethod("hoverEffect", &JSTextField::JsHoverEffect);
56     JSClass<JSTextArea>::StaticMethod("onChange", &JSTextField::SetOnChange);
57     JSClass<JSTextArea>::StaticMethod("onCopy", &JSTextField::SetOnCopy);
58     JSClass<JSTextArea>::StaticMethod("onCut", &JSTextField::SetOnCut);
59     JSClass<JSTextArea>::StaticMethod("onPaste", &JSTextField::SetOnPaste);
60     JSClass<JSTextArea>::StaticMethod("onClick", &JSTextField::SetOnClick);
61     JSClass<JSTextArea>::StaticMethod("onTouch", &JSInteractableView::JsOnTouch);
62     JSClass<JSTextArea>::StaticMethod("onHover", &JSInteractableView::JsOnHover);
63     JSClass<JSTextArea>::StaticMethod("onKeyEvent", &JSInteractableView::JsOnKey);
64     JSClass<JSTextArea>::StaticMethod("onDeleteEvent", &JSInteractableView::JsOnDelete);
65     JSClass<JSTextArea>::StaticMethod("onAppear", &JSInteractableView::JsOnAppear);
66     JSClass<JSTextArea>::StaticMethod("onDisAppear", &JSInteractableView::JsOnDisAppear);
67     JSClass<JSTextArea>::StaticMethod("copyOption", &JSTextField::SetCopyOption);
68     JSClass<JSTextArea>::Inherit<JSViewAbstract>();
69     JSClass<JSTextArea>::Bind(globalObj);
70 }
71 
Create(const JSCallbackInfo & info)72 void JSTextArea::Create(const JSCallbackInfo& info)
73 {
74     JSTextField::CreateTextArea(info);
75 }
76 
JSBind(BindingTarget globalObj)77 void JSTextAreaController::JSBind(BindingTarget globalObj)
78 {
79     JSClass<JSTextAreaController>::Declare("TextAreaController");
80     JSClass<JSTextAreaController>::Method("caretPosition", &JSTextAreaController::CaretPosition);
81     JSClass<JSTextAreaController>::Bind(globalObj, JSTextAreaController::Constructor, JSTextAreaController::Destructor);
82 }
83 
Constructor(const JSCallbackInfo & args)84 void JSTextAreaController::Constructor(const JSCallbackInfo& args)
85 {
86     auto scroller = Referenced::MakeRefPtr<JSTextAreaController>();
87     scroller->IncRefCount();
88     args.SetReturnValue(Referenced::RawPtr(scroller));
89 }
90 
Destructor(JSTextAreaController * scroller)91 void JSTextAreaController::Destructor(JSTextAreaController* scroller)
92 {
93     if (scroller != nullptr) {
94         scroller->DecRefCount();
95     }
96 }
97 
CaretPosition(int32_t caretPosition)98 void JSTextAreaController::CaretPosition(int32_t caretPosition)
99 {
100     auto controller = controllerWeak_.Upgrade();
101     if (controller) {
102         controller->CaretPosition(caretPosition);
103     }
104 }
105 
106 } // namespace OHOS::Ace::Framework