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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_RICH_EDITOR_RICH_EDITOR_MODEL_NG_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_RICH_EDITOR_RICH_EDITOR_MODEL_NG_H
18 
19 #include "core/components_ng/pattern/rich_editor/rich_editor_model.h"
20 #include "core/components_ng/pattern/rich_editor/selection_info.h"
21 
22 namespace OHOS::Ace::NG {
23 class ACE_EXPORT RichEditorModelNG : public OHOS::Ace::RichEditorModel {
24 public:
25     void Create(bool isStyledStringMode = false) override;
26     RefPtr<RichEditorBaseControllerBase> GetRichEditorController() override;
27     void SetOnReady(std::function<void()>&& func) override;
28     void SetOnSelect(std::function<void(const BaseEventInfo*)>&& func) override;
29     void SetOnSelectionChange(std::function<void(const BaseEventInfo*)>&& func) override;
30     void SetAboutToIMEInput(std::function<bool(const RichEditorInsertValue&)>&& func) override;
31     void SetOnIMEInputComplete(std::function<void(const RichEditorAbstractSpanResult&)>&& func) override;
32     void SetOnDidIMEInput(std::function<void(const TextRange&)>&& func) override;
33     void SetAboutToDelete(std::function<bool(const RichEditorDeleteValue&)>&& func) override;
34     void SetOnDeleteComplete(std::function<void()>&& func) override;
35     void SetCustomKeyboard(std::function<void()>&& func, bool supportAvoidance) override;
36     void SetCopyOption(CopyOptions& copyOptions) override;
37     void BindSelectionMenu(TextSpanType& editorType, TextResponseType& responseType,
38         std::function<void()>& buildFunc, SelectMenuParam& menuParam) override;
39     void SetOnPaste(std::function<void(NG::TextCommonEvent&)>&& func) override;
40     void SetPlaceholder(PlaceholderOptions& options) override;
41     void SetTextDetectEnable(bool value) override;
42     void SetSupportPreviewText(bool value) override;
43     void SetTextDetectConfig(const TextDetectConfig& textDetectConfig) override;
44     void SetSelectedBackgroundColor(const Color& selectedColor) override;
45     void SetCaretColor(const Color& color) override;
46     void SetOnEditingChange(std::function<void(const bool&)>&& func) override;
47     void SetOnWillChange(std::function<bool(const RichEditorChangeValue&)>&& func) override;
48     void SetOnDidChange(std::function<void(const RichEditorChangeValue&)>&& func) override;
49     void SetOnCut(std::function<void(NG::TextCommonEvent&)>&& func) override;
50     void SetOnCopy(std::function<void(NG::TextCommonEvent&)>&& func) override;
51     void SetSelectionMenuOptions(const OnCreateMenuCallback&& onCreateMenuCallback,
52         const OnMenuItemClickCallback&& onMenuItemClick) override;
53     void SetRequestKeyboardOnFocus(bool needToRequest) override;
54     void SetEnableHapticFeedback(bool isEnabled) override;
55     void SetBarState(DisplayMode mode) override;
56     void SetImagePreviewMenuParam(std::function<void()>& buildFunc, const SelectMenuParam& menuParam) override;
57 
58     static void SetTextDetectEnable(FrameNode* frameNode, bool value);
59     static void SetTextDetectConfig(FrameNode* frameNode, const TextDetectConfig& textDetectConfig);
60     static void SetOnIMEInputComplete(FrameNode* frameNode,
61         std::function<void(const RichEditorAbstractSpanResult&)>&& callback);
62     static void SetOnDidIMEInput(FrameNode* frameNode, std::function<void(const TextRange&)>&& callback);
63     static void SetCopyOption(FrameNode* frameNode, CopyOptions& copyOptions);
64     static void SetOnSelectionChange(FrameNode* frameNode, std::function<void(const BaseEventInfo*)>&& callback);
65     static void SetCaretColor(FrameNode* frameNode, const Color& color);
66     static void SetOnSelect(FrameNode* frameNode, std::function<void(const BaseEventInfo*)>&& callback);
67     static void SetOnReady(FrameNode* frameNode, std::function<void()>&& callback);
68     static void SetOnDeleteComplete(FrameNode* frameNode, std::function<void()>&& callback);
69     static void SetOnEditingChange(FrameNode* frameNode, std::function<void(const bool&)>&& callback);
70     static void SetSelectedBackgroundColor(FrameNode* frameNode, const Color& selectedColor);
71     static void SetOnPaste(FrameNode* frameNode, std::function<void(NG::TextCommonEvent&)>&& func);
72     static void SetOnCut(FrameNode* frameNode, std::function<void(NG::TextCommonEvent&)>&& func);
73     static void SetOnCopy(FrameNode* frameNode, std::function<void(NG::TextCommonEvent&)>&& func);
74     void SetEnterKeyType(TextInputAction value) override;
75     static void SetEnterKeyType(FrameNode* frameNode, const TextInputAction& action);
76     void SetOnSubmit(std::function<void(int32_t, NG::TextFieldCommonEvent&)>&& func) override;
77     static void SetOnSubmit(FrameNode* frameNode, std::function<void(int32_t, NG::TextFieldCommonEvent&)>&& callback);
78     static void SetAboutToIMEInput(FrameNode* frameNode, std::function<bool(const RichEditorInsertValue&)>&& callback);
79     static void SetRequestKeyboardOnFocus(FrameNode* frameNode, bool needToRequest);
80     static void SetImagePreviewMenuParam(FrameNode* frameNode,
81         std::function<void()>& buildFunc, const SelectMenuParam& menuParam);
82 private:
83     void SetDraggable(bool draggable);
84     bool isStyledStringMode_ = false;
85 };
86 } // namespace OHOS::Ace::NG
87 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_RICH_EDITOR_RICH_EDITOR_MODEL_NG_H
88