/* * Copyright (c) 2021-2022 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_textinput.h" #include #include #include #include "core/common/container.h" #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_textfield.h" #include "frameworks/bridge/declarative_frontend/jsview/js_view_common_def.h" #include "frameworks/bridge/declarative_frontend/view_stack_processor.h" #include "frameworks/core/common/ime/text_input_action.h" #include "frameworks/core/common/ime/text_input_type.h" #include "frameworks/core/components/text_field/text_field_component.h" #include "frameworks/core/components/text_field/textfield_theme.h" namespace OHOS::Ace::Framework { void JSTextInput::JSBind(BindingTarget globalObj) { JSClass::Declare("TextInput"); MethodOptions opt = MethodOptions::NONE; JSClass::StaticMethod("create", &JSTextInput::Create, opt); JSClass::StaticMethod("type", &JSTextField::SetType); JSClass::StaticMethod("placeholderColor", &JSTextField::SetPlaceholderColor); JSClass::StaticMethod("placeholderFont", &JSTextField::SetPlaceholderFont); JSClass::StaticMethod("backgroundColor", &JSTextField::SetBackgroundColor); JSClass::StaticMethod("enterKeyType", &JSTextField::SetEnterKeyType); JSClass::StaticMethod("caretColor", &JSTextField::SetCaretColor); JSClass::StaticMethod("maxLength", &JSTextField::SetMaxLength); JSClass::StaticMethod("width", &JSTextField::JsWidth); 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("showPasswordIcon", &JSTextField::SetShowPasswordIcon); JSClass::StaticMethod("textAlign", &JSTextField::SetTextAlign); JSClass::StaticMethod("style", &JSTextField::SetInputStyle); JSClass::StaticMethod("hoverEffect", &JSTextField::JsHoverEffect); JSClass::StaticMethod("copyOption", &JSTextField::SetCopyOption); // API7 onEditChanged deprecated JSClass::StaticMethod("onEditChanged", &JSTextField::SetOnEditChanged); JSClass::StaticMethod("onEditChange", &JSTextField::SetOnEditChanged); JSClass::StaticMethod("onSubmit", &JSTextField::SetOnSubmit); JSClass::StaticMethod("onChange", &JSTextField::SetOnChange); 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::Inherit(); JSClass::Bind(globalObj); } void JSTextInput::Create(const JSCallbackInfo& info) { JSTextField::CreateTextInput(info); } void JSTextInputController::JSBind(BindingTarget globalObj) { JSClass::Declare("TextInputController"); JSClass::Method("caretPosition", &JSTextInputController::CaretPosition); JSClass::Bind( globalObj, JSTextInputController::Constructor, JSTextInputController::Destructor); } void JSTextInputController::Constructor(const JSCallbackInfo& args) { auto scroller = Referenced::MakeRefPtr(); scroller->IncRefCount(); args.SetReturnValue(Referenced::RawPtr(scroller)); } void JSTextInputController::Destructor(JSTextInputController* scroller) { if (scroller != nullptr) { scroller->DecRefCount(); } } void JSTextInputController::CaretPosition(int32_t caretPosition) { auto controller = controllerWeak_.Upgrade(); if (controller) { controller->CaretPosition(caretPosition); } } } // namespace OHOS::Ace::Framework