1 /*
2 * Copyright (c) 2021-2024 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_text_editable_controller.h"
26 #include "frameworks/bridge/declarative_frontend/jsview/js_textfield.h"
27 #include "frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h"
28 #include "frameworks/bridge/declarative_frontend/jsview/js_view_common_def.h"
29 #include "frameworks/bridge/declarative_frontend/view_stack_processor.h"
30
31 namespace OHOS::Ace::Framework {
32 namespace {
33 constexpr uint32_t MAX_LINES = 3;
34 }
35
JSBind(BindingTarget globalObj)36 void JSTextArea::JSBind(BindingTarget globalObj)
37 {
38 JSClass<JSTextArea>::Declare("TextArea");
39 MethodOptions opt = MethodOptions::NONE;
40 JSClass<JSTextArea>::StaticMethod("create", &JSTextArea::Create, opt);
41 JSClass<JSTextArea>::StaticMethod("placeholderColor", &JSTextField::SetPlaceholderColor);
42 JSClass<JSTextArea>::StaticMethod("placeholderFont", &JSTextField::SetPlaceholderFont);
43 JSClass<JSTextArea>::StaticMethod("backgroundColor", &JSTextField::SetBackgroundColor);
44 JSClass<JSTextArea>::StaticMethod("textAlign", &JSTextField::SetTextAlign);
45 JSClass<JSTextArea>::StaticMethod("caretColor", &JSTextField::SetCaretColor);
46 JSClass<JSTextArea>::StaticMethod("height", &JSTextField::JsHeight);
47 JSClass<JSTextArea>::StaticMethod("width", &JSTextField::JsWidth);
48 JSClass<JSTextArea>::StaticMethod("padding", &JSTextField::JsPadding);
49 JSClass<JSTextArea>::StaticMethod("margin", &JSTextField::JsMargin);
50 JSClass<JSTextArea>::StaticMethod("border", &JSTextField::JsBorder);
51 JSClass<JSTextArea>::StaticMethod("borderWidth", &JSTextField::JsBorderWidth);
52 JSClass<JSTextArea>::StaticMethod("borderColor", &JSTextField::JsBorderColor);
53 JSClass<JSTextArea>::StaticMethod("borderStyle", &JSTextField::JsBorderStyle);
54 JSClass<JSTextArea>::StaticMethod("borderRadius", &JSTextField::JsBorderRadius);
55 JSClass<JSTextArea>::StaticMethod("fontSize", &JSTextField::SetFontSize);
56 JSClass<JSTextArea>::StaticMethod("fontColor", &JSTextField::SetTextColor);
57 JSClass<JSTextArea>::StaticMethod("fontWeight", &JSTextField::SetFontWeight);
58 JSClass<JSTextArea>::StaticMethod("fontStyle", &JSTextField::SetFontStyle);
59 JSClass<JSTextArea>::StaticMethod("fontFamily", &JSTextField::SetFontFamily);
60 JSClass<JSTextArea>::StaticMethod("minFontScale", &JSTextField::SetMinFontScale);
61 JSClass<JSTextArea>::StaticMethod("maxFontScale", &JSTextField::SetMaxFontScale);
62 JSClass<JSTextArea>::StaticMethod("inputFilter", &JSTextField::SetInputFilter);
63 JSClass<JSTextArea>::StaticMethod("hoverEffect", &JSTextField::JsHoverEffect);
64 JSClass<JSTextArea>::StaticMethod("maxLength", &JSTextField::SetMaxLength);
65 JSClass<JSTextArea>::StaticMethod("showCounter", &JSTextField::SetShowCounter);
66 JSClass<JSTextArea>::StaticMethod("barState", &JSTextField::SetBarState);
67 JSClass<JSTextArea>::StaticMethod("maxLines", &JSTextArea::SetMaxLines);
68 JSClass<JSTextArea>::StaticMethod("style", &JSTextField::SetInputStyle);
69 JSClass<JSTextArea>::StaticMethod("onWillChange", &JSTextField::SetOnWillChange);
70 JSClass<JSTextArea>::StaticMethod("onChange", &JSTextField::SetOnChange);
71 JSClass<JSTextArea>::StaticMethod("onTextSelectionChange", &JSTextField::SetOnTextSelectionChange);
72 JSClass<JSTextArea>::StaticMethod("onContentScroll", &JSTextField::SetOnContentScroll);
73 JSClass<JSTextArea>::StaticMethod("onCopy", &JSTextField::SetOnCopy);
74 JSClass<JSTextArea>::StaticMethod("onCut", &JSTextField::SetOnCut);
75 JSClass<JSTextArea>::StaticMethod("onPaste", &JSTextField::SetOnPaste);
76 JSClass<JSTextArea>::StaticMethod("onClick", &JSTextField::SetOnClick);
77 JSClass<JSTextArea>::StaticMethod("onTouch", &JSInteractableView::JsOnTouch);
78 JSClass<JSTextArea>::StaticMethod("onHover", &JSInteractableView::JsOnHover);
79 JSClass<JSTextArea>::StaticMethod("onKeyEvent", &JSInteractableView::JsOnKey);
80 JSClass<JSTextArea>::StaticMethod("onDeleteEvent", &JSInteractableView::JsOnDelete);
81 JSClass<JSTextArea>::StaticMethod("onAttach", &JSInteractableView::JsOnAttach);
82 JSClass<JSTextArea>::StaticMethod("onAppear", &JSInteractableView::JsOnAppear);
83 JSClass<JSTextArea>::StaticMethod("onDetach", &JSInteractableView::JsOnDetach);
84 JSClass<JSTextArea>::StaticMethod("onDisAppear", &JSInteractableView::JsOnDisAppear);
85 JSClass<JSTextArea>::StaticMethod("onEditChange", &JSTextField::SetOnEditChanged);
86 JSClass<JSTextArea>::StaticMethod("copyOption", &JSTextField::SetCopyOption);
87 JSClass<JSTextArea>::StaticMethod("foregroundColor", &JSTextField::SetForegroundColor);
88 JSClass<JSTextArea>::StaticMethod("enableKeyboardOnFocus", &JSTextField::SetEnableKeyboardOnFocus);
89 JSClass<JSTextArea>::StaticMethod("selectionMenuHidden", &JSTextField::SetSelectionMenuHidden);
90 JSClass<JSTextArea>::StaticMethod("customKeyboard", &JSTextField::SetCustomKeyboard);
91 JSClass<JSTextArea>::StaticMethod("onSubmit", &JSTextField::SetOnSubmit);
92 JSClass<JSTextArea>::StaticMethod("enterKeyType", &JSTextField::SetEnterKeyType);
93 JSClass<JSTextArea>::StaticMethod("type", &JSTextField::SetType);
94 JSClass<JSTextArea>::StaticMethod("fontFeature", &JSTextField::SetFontFeature);
95 JSClass<JSTextArea>::StaticMethod("lineBreakStrategy", &JSTextField::SetLineBreakStrategy);
96 JSClass<JSTextArea>::StaticMethod("decoration", &JSTextField::SetDecoration);
97 JSClass<JSTextArea>::StaticMethod("minFontSize", &JSTextField::SetMinFontSize);
98 JSClass<JSTextArea>::StaticMethod("maxFontSize", &JSTextField::SetMaxFontSize);
99 JSClass<JSTextArea>::StaticMethod("heightAdaptivePolicy", &JSTextField::SetHeightAdaptivePolicy);
100 JSClass<JSTextArea>::StaticMethod("letterSpacing", &JSTextField::SetLetterSpacing);
101 JSClass<JSTextArea>::StaticMethod("lineHeight", &JSTextField::SetLineHeight);
102 JSClass<JSTextArea>::StaticMethod("halfLeading", &JSTextField::SetHalfLeading);
103 JSClass<JSTextArea>::StaticMethod("lineSpacing", &JSTextField::SetLineSpacing);
104 JSClass<JSTextArea>::StaticMethod("wordBreak", &JSTextField::SetWordBreak);
105 JSClass<JSTextArea>::StaticMethod("contentType", &JSTextField::SetContentType);
106 JSClass<JSTextArea>::StaticMethod("enableAutoFill", &JSTextField::SetEnableAutoFill);
107 JSClass<JSTextArea>::StaticMethod("selectedBackgroundColor", &JSTextField::SetSelectedBackgroundColor);
108 JSClass<JSTextArea>::StaticMethod("caretStyle", &JSTextField::SetCaretStyle);
109 JSClass<JSTextArea>::StaticMethod("textIndent", &JSTextField::SetTextIndent);
110 JSClass<JSTextArea>::StaticMethod("textOverflow", &JSTextField::SetTextOverflow);
111 JSClass<JSTextArea>::StaticMethod("onWillInsert", &JSTextField::OnWillInsertValue);
112 JSClass<JSTextArea>::StaticMethod("onDidInsert", &JSTextField::OnDidInsertValue);
113 JSClass<JSTextArea>::StaticMethod("onWillDelete", &JSTextField::OnWillDelete);
114 JSClass<JSTextArea>::StaticMethod("onDidDelete", &JSTextField::OnDidDelete);
115 JSClass<JSTextArea>::StaticMethod("editMenuOptions", &JSTextField::EditMenuOptions);
116 JSClass<JSTextArea>::StaticMethod("enablePreviewText", &JSTextField::SetEnablePreviewText);
117 JSClass<JSTextArea>::StaticMethod("enableHapticFeedback", &JSTextField::SetEnableHapticFeedback);
118 JSClass<JSTextArea>::StaticMethod("ellipsisMode", &JSTextField::SetEllipsisMode);
119 JSClass<JSTextArea>::StaticMethod("stopBackPress", &JSTextField::SetStopBackPress);
120 JSClass<JSTextArea>::StaticMethod("keyboardAppearance", &JSTextField::SetKeyboardAppearance);
121 JSClass<JSTextArea>::InheritAndBind<JSViewAbstract>(globalObj);
122 }
123
Create(const JSCallbackInfo & info)124 void JSTextArea::Create(const JSCallbackInfo& info)
125 {
126 JSTextField::CreateTextArea(info);
127 }
128
SetMaxLines(const JSCallbackInfo & info)129 void JSTextArea::SetMaxLines(const JSCallbackInfo& info)
130 {
131 auto normalMaxViewLines = Infinity<uint32_t>();
132 auto inlineMaxViewLines = MAX_LINES;
133 auto isValid = !(info.Length() < 1 || !info[0]->IsNumber() || info[0]->ToNumber<int32_t>() <= 0);
134 if (isValid) {
135 inlineMaxViewLines = info[0]->ToNumber<uint32_t>();
136 normalMaxViewLines = info[0]->ToNumber<uint32_t>();
137 }
138 TextFieldModel::GetInstance()->SetNormalMaxViewLines(normalMaxViewLines);
139 TextFieldModel::GetInstance()->SetMaxViewLines(inlineMaxViewLines);
140 }
141
JSBind(BindingTarget globalObj)142 void JSTextAreaController::JSBind(BindingTarget globalObj)
143 {
144 JSClass<JSTextEditableController>::Declare("TextAreaController");
145 JSTextEditableController::JSBind(globalObj);
146 }
147 } // namespace OHOS::Ace::Framework
148