1 /* 2 * Copyright (c) 2023 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 #ifndef FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_RICHEDITOR_H 17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_RICHEDITOR_H 18 19 #include "core/components_ng/pattern/rich_editor/rich_editor_model.h" 20 #include "frameworks/bridge/declarative_frontend/jsview/js_container_base.h" 21 22 namespace OHOS::Ace::Framework { 23 class JSRichEditor : public JSContainerBase { 24 public: 25 static void Create(const JSCallbackInfo& info); 26 static void JSBind(BindingTarget globalObj); 27 static void SetOnReady(const JSCallbackInfo& args); 28 static void SetOnSelect(const JSCallbackInfo& args); 29 static JSRef<JSVal> CreateJSSelection(const RichEditorSelection& selectInfo); 30 static JSRef<JSObject> CreateJSSpanResultObject(const ResultObject& resultObject); 31 static JSRef<JSObject> CreateJSTextStyleResult(const TextStyleResult& textStyleResult); 32 static JSRef<JSObject> CreateJSImageStyleResult(const ImageStyleResult& imageStyleResult); 33 static void SetAboutToIMEInput(const JSCallbackInfo& args); 34 static void SetOnIMEInputComplete(const JSCallbackInfo& args); 35 static void SetAboutToDelete(const JSCallbackInfo& args); 36 static void SetOnDeleteComplete(const JSCallbackInfo& args); 37 static void SetCustomKeyboard(const JSCallbackInfo& args); 38 static JSRef<JSVal> CreateJsAboutToIMEInputObj(const NG::RichEditorInsertValue& insertValue); 39 static JSRef<JSVal> CreateJsOnIMEInputComplete(const NG::RichEditorAbstractSpanResult& textSpanResult); 40 static JSRef<JSVal> CreateJsAboutToDelet(const NG::RichEditorDeleteValue& deleteValue); 41 static void JsFocusable(const JSCallbackInfo& info); 42 static void SetCopyOptions(const JSCallbackInfo& info); 43 static void BindSelectionMenu(const JSCallbackInfo& info); 44 45 private: 46 static void CreateTextStyleObj(JSRef<JSObject>& textStyleObj, const NG::RichEditorAbstractSpanResult& spanResult); 47 static void CreateImageStyleObj(JSRef<JSObject>& imageStyleObj, JSRef<JSObject>& spanResultObj, 48 const NG::RichEditorAbstractSpanResult& spanResult); 49 static void ParseMenuParam( 50 const JSCallbackInfo& info, const JSRef<JSObject>& menuOptions, SelectMenuParam& menuParam); 51 }; 52 53 class JSRichEditorController final : public Referenced { 54 public: 55 JSRichEditorController() = default; 56 ~JSRichEditorController() override = default; 57 58 static void JSBind(BindingTarget globalObj); 59 Constructor(const JSCallbackInfo & args)60 static void Constructor(const JSCallbackInfo& args) 61 { 62 auto controller = Referenced::MakeRefPtr<JSRichEditorController>(); 63 controller->IncRefCount(); 64 args.SetReturnValue(Referenced::RawPtr(controller)); 65 } 66 Destructor(JSRichEditorController * controller)67 static void Destructor(JSRichEditorController* controller) 68 { 69 if (controller != nullptr) { 70 controller->DecRefCount(); 71 } 72 } 73 SetController(const RefPtr<RichEditorControllerBase> & controller)74 void SetController(const RefPtr<RichEditorControllerBase>& controller) 75 { 76 controllerWeak_ = controller; 77 } 78 void AddImageSpan(const JSCallbackInfo& args); 79 void AddTextSpan(const JSCallbackInfo& args); 80 void DeleteSpans(const JSCallbackInfo& args); 81 ImageSpanAttribute ParseJsImageSpanAttribute(JSRef<JSObject> imageAttribute); 82 TextStyle ParseJsTextStyle(JSRef<JSObject> styleObject, struct UpdateSpanStyle& updateSpanStyle); 83 ImageSpanOptions CreateJsImageOptions(const JSCallbackInfo& args); 84 bool IsDrawable(const JSRef<JSVal>& jsValue); 85 void SetCaretOffset(const JSCallbackInfo& args); 86 void GetCaretOffset(const JSCallbackInfo& args); 87 void UpdateSpanStyle(const JSCallbackInfo& info); 88 void GetSpansInfo(const JSCallbackInfo& args); 89 void SetTypingStyle(const JSCallbackInfo& info); 90 void CloseSelectionMenu(); 91 JSRef<JSVal> CreateCreateJSSpansInfo(const RichEditorSelection& info); 92 93 private: 94 WeakPtr<RichEditorControllerBase> controllerWeak_; 95 ACE_DISALLOW_COPY_AND_MOVE(JSRichEditorController); 96 struct UpdateSpanStyle updateSpanStyle_; 97 struct UpdateSpanStyle typingStyle_; 98 }; 99 } // namespace OHOS::Ace::Framework 100 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_RICHEDITOR_H 101