/* * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "frameworks/bridge/declarative_frontend/jsview/js_textarea.h" #include #include "frameworks/bridge/common/utils/utils.h" #include "frameworks/bridge/declarative_frontend/engine/functions/js_clipboard_function.h" #include "frameworks/bridge/declarative_frontend/engine/functions/js_function.h" #include "frameworks/bridge/declarative_frontend/jsview/js_container_base.h" #include "frameworks/bridge/declarative_frontend/jsview/js_interactable_view.h" #include "frameworks/bridge/declarative_frontend/jsview/js_text_editable_controller.h" #include "frameworks/bridge/declarative_frontend/jsview/js_textfield.h" #include "frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h" #include "frameworks/bridge/declarative_frontend/jsview/js_view_common_def.h" #include "frameworks/bridge/declarative_frontend/view_stack_processor.h" namespace OHOS::Ace::Framework { namespace { constexpr uint32_t MAX_LINES = 3; } void JSTextArea::JSBind(BindingTarget globalObj) { JSClass::Declare("TextArea"); MethodOptions opt = MethodOptions::NONE; JSClass::StaticMethod("create", &JSTextArea::Create, opt); JSClass::StaticMethod("placeholderColor", &JSTextField::SetPlaceholderColor); JSClass::StaticMethod("placeholderFont", &JSTextField::SetPlaceholderFont); JSClass::StaticMethod("backgroundColor", &JSTextField::SetBackgroundColor); JSClass::StaticMethod("textAlign", &JSTextField::SetTextAlign); JSClass::StaticMethod("caretColor", &JSTextField::SetCaretColor); JSClass::StaticMethod("height", &JSTextField::JsHeight); JSClass::StaticMethod("width", &JSTextField::JsWidth); JSClass::StaticMethod("padding", &JSTextField::JsPadding); JSClass::StaticMethod("margin", &JSTextField::JsMargin); JSClass::StaticMethod("border", &JSTextField::JsBorder); JSClass::StaticMethod("borderWidth", &JSTextField::JsBorderWidth); JSClass::StaticMethod("borderColor", &JSTextField::JsBorderColor); JSClass::StaticMethod("borderStyle", &JSTextField::JsBorderStyle); JSClass::StaticMethod("borderRadius", &JSTextField::JsBorderRadius); JSClass::StaticMethod("fontSize", &JSTextField::SetFontSize); JSClass::StaticMethod("fontColor", &JSTextField::SetTextColor); JSClass::StaticMethod("fontWeight", &JSTextField::SetFontWeight); JSClass::StaticMethod("fontStyle", &JSTextField::SetFontStyle); JSClass::StaticMethod("fontFamily", &JSTextField::SetFontFamily); JSClass::StaticMethod("inputFilter", &JSTextField::SetInputFilter); JSClass::StaticMethod("hoverEffect", &JSTextField::JsHoverEffect); JSClass::StaticMethod("maxLength", &JSTextField::SetMaxLength); JSClass::StaticMethod("showCounter", &JSTextField::SetShowCounter); JSClass::StaticMethod("barState", &JSTextField::SetBarState); JSClass::StaticMethod("maxLines", &JSTextArea::SetMaxLines); JSClass::StaticMethod("style", &JSTextField::SetInputStyle); JSClass::StaticMethod("onChange", &JSTextField::SetOnChange); JSClass::StaticMethod("onTextSelectionChange", &JSTextField::SetOnTextSelectionChange); JSClass::StaticMethod("onContentScroll", &JSTextField::SetOnContentScroll); JSClass::StaticMethod("onCopy", &JSTextField::SetOnCopy); JSClass::StaticMethod("onCut", &JSTextField::SetOnCut); JSClass::StaticMethod("onPaste", &JSTextField::SetOnPaste); JSClass::StaticMethod("onClick", &JSTextField::SetOnClick); JSClass::StaticMethod("onTouch", &JSInteractableView::JsOnTouch); JSClass::StaticMethod("onHover", &JSInteractableView::JsOnHover); JSClass::StaticMethod("onKeyEvent", &JSInteractableView::JsOnKey); JSClass::StaticMethod("onDeleteEvent", &JSInteractableView::JsOnDelete); JSClass::StaticMethod("onAttach", &JSInteractableView::JsOnAttach); JSClass::StaticMethod("onAppear", &JSInteractableView::JsOnAppear); JSClass::StaticMethod("onDetach", &JSInteractableView::JsOnDetach); JSClass::StaticMethod("onDisAppear", &JSInteractableView::JsOnDisAppear); JSClass::StaticMethod("onEditChange", &JSTextField::SetOnEditChanged); JSClass::StaticMethod("copyOption", &JSTextField::SetCopyOption); JSClass::StaticMethod("foregroundColor", &JSTextField::SetForegroundColor); JSClass::StaticMethod("enableKeyboardOnFocus", &JSTextField::SetEnableKeyboardOnFocus); JSClass::StaticMethod("selectionMenuHidden", &JSTextField::SetSelectionMenuHidden); JSClass::StaticMethod("customKeyboard", &JSTextField::SetCustomKeyboard); JSClass::StaticMethod("onSubmit", &JSTextField::SetOnSubmit); JSClass::StaticMethod("enterKeyType", &JSTextField::SetEnterKeyType); JSClass::StaticMethod("type", &JSTextField::SetType); JSClass::StaticMethod("fontFeature", &JSTextField::SetFontFeature); JSClass::StaticMethod("lineBreakStrategy", &JSTextField::SetLineBreakStrategy); JSClass::StaticMethod("decoration", &JSTextField::SetDecoration); JSClass::StaticMethod("minFontSize", &JSTextField::SetMinFontSize); JSClass::StaticMethod("maxFontSize", &JSTextField::SetMaxFontSize); JSClass::StaticMethod("heightAdaptivePolicy", &JSTextField::SetHeightAdaptivePolicy); JSClass::StaticMethod("letterSpacing", &JSTextField::SetLetterSpacing); JSClass::StaticMethod("lineHeight", &JSTextField::SetLineHeight); JSClass::StaticMethod("lineSpacing", &JSTextField::SetLineSpacing); JSClass::StaticMethod("wordBreak", &JSTextField::SetWordBreak); JSClass::StaticMethod("contentType", &JSTextField::SetContentType); JSClass::StaticMethod("enableAutoFill", &JSTextField::SetEnableAutoFill); JSClass::StaticMethod("selectedBackgroundColor", &JSTextField::SetSelectedBackgroundColor); JSClass::StaticMethod("caretStyle", &JSTextField::SetCaretStyle); JSClass::StaticMethod("textIndent", &JSTextField::SetTextIndent); JSClass::StaticMethod("textOverflow", &JSTextField::SetTextOverflow); JSClass::StaticMethod("onWillInsert", &JSTextField::OnWillInsertValue); JSClass::StaticMethod("onDidInsert", &JSTextField::OnDidInsertValue); JSClass::StaticMethod("onWillDelete", &JSTextField::OnWillDelete); JSClass::StaticMethod("onDidDelete", &JSTextField::OnDidDelete); JSClass::StaticMethod("editMenuOptions", &JSTextField::EditMenuOptions); JSClass::StaticMethod("enablePreviewText", &JSTextField::SetEnablePreviewText); JSClass::StaticMethod("enableHapticFeedback", &JSTextField::SetEnableHapticFeedback); JSClass::InheritAndBind(globalObj); } void JSTextArea::Create(const JSCallbackInfo& info) { JSTextField::CreateTextArea(info); } void JSTextArea::SetMaxLines(const JSCallbackInfo& info) { auto normalMaxViewLines = Infinity(); auto inlineMaxViewLines = MAX_LINES; auto isValid = !(info.Length() < 1 || !info[0]->IsNumber() || info[0]->ToNumber() <= 0); if (isValid) { inlineMaxViewLines = info[0]->ToNumber(); normalMaxViewLines = info[0]->ToNumber(); } TextFieldModel::GetInstance()->SetNormalMaxViewLines(normalMaxViewLines); TextFieldModel::GetInstance()->SetMaxViewLines(inlineMaxViewLines); } void JSTextAreaController::JSBind(BindingTarget globalObj) { JSClass::Declare("TextAreaController"); JSTextEditableController::JSBind(globalObj); } } // namespace OHOS::Ace::Framework