/* * Copyright (c) 20212022 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_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 { 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("padding", &JSTextField::JsPadding); 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", &JSTextField::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("onAppear", &JSInteractableView::JsOnAppear); JSClass::StaticMethod("onDisAppear", &JSInteractableView::JsOnDisAppear); JSClass::StaticMethod("onEditChange", &JSTextField::SetOnEditChanged); JSClass::StaticMethod("copyOption", &JSTextField::SetCopyOption); JSClass::StaticMethod("textMenuOptions", &JSTextField::JsMenuOptionsExtension); JSClass::StaticMethod("foregroundColor", &JSTextField::SetForegroundColor); JSClass::StaticMethod("enableKeyboardOnFocus", &JSTextField::SetEnableKeyboardOnFocus); JSClass::StaticMethod("selectionMenuHidden", &JSTextField::SetSelectionMenuHidden); JSClass::StaticMethod("customKeyboard", &JSTextField::SetCustomKeyboard); JSClass::InheritAndBind(globalObj); } void JSTextArea::Create(const JSCallbackInfo& info) { JSTextField::CreateTextArea(info); } void JSTextAreaController::JSBind(BindingTarget globalObj) { JSClass::Declare("TextAreaController"); JSClass::Method("caretPosition", &JSTextAreaController::CaretPosition); JSClass::Method("setTextSelection", &JSTextAreaController::SetTextSelection); JSClass::CustomMethod("getTextContentRect", &JSTextAreaController::GetTextContentRect); JSClass::CustomMethod("getTextContentLineCount", &JSTextAreaController::GetTextContentLinesNum); JSClass::Method("stopEditing", &JSTextAreaController::StopEditing); JSClass::Bind(globalObj, JSTextAreaController::Constructor, JSTextAreaController::Destructor); } void JSTextAreaController::Constructor(const JSCallbackInfo& args) { auto scroller = Referenced::MakeRefPtr(); scroller->IncRefCount(); args.SetReturnValue(Referenced::RawPtr(scroller)); } void JSTextAreaController::Destructor(JSTextAreaController* scroller) { if (scroller != nullptr) { scroller->DecRefCount(); } } void JSTextAreaController::CaretPosition(int32_t caretPosition) { auto controller = controllerWeak_.Upgrade(); if (controller) { controller->CaretPosition(caretPosition); } } void JSTextAreaController::SetTextSelection(int32_t selectionStart, int32_t selectionEnd) { auto controller = controllerWeak_.Upgrade(); if (controller) { controller->SetTextSelection(selectionStart, selectionEnd); } } JSRef JSTextAreaController::CreateRectangle(const Rect& info) { JSRef rectObj = JSRef::New(); rectObj->SetProperty("x", info.Left()); rectObj->SetProperty("y", info.Top()); rectObj->SetProperty("width", info.Width()); rectObj->SetProperty("height", info.Height()); return rectObj; } void JSTextAreaController::GetTextContentRect(const JSCallbackInfo& info) { auto controller = controllerWeak_.Upgrade(); if (controller) { auto rectObj = CreateRectangle(controller->GetTextContentRect()); JSRef rect = JSRef::Cast(rectObj); info.SetReturnValue(rect); } else { LOGE("GetTextContentRect: The JSTextAreaController is NULL"); } } void JSTextAreaController::GetTextContentLinesNum(const JSCallbackInfo& info) { auto controller = controllerWeak_.Upgrade(); if (controller) { auto lines = controller->GetTextContentLinesNum(); auto linesNum = JSVal(ToJSValue(lines)); auto textLines = JSRef::Make(linesNum); info.SetReturnValue(textLines); } else { LOGE("GetTextContentRect: The JSTextAreaController is NULL"); } } void JSTextAreaController::StopEditing() { auto controller = controllerWeak_.Upgrade(); if (controller) { controller->StopEditing(); } } } // namespace OHOS::Ace::Framework