1 /*
2  * Copyright (c) 2022-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_TEXT_TEXT_VIEW_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_TEXT_VIEW_H
18 
19 #include <functional>
20 #include <string>
21 
22 #include "interfaces/native/node/styled_string.h"
23 
24 #include "core/components/common/properties/text_style.h"
25 #include "core/components_ng/pattern/text/text_model.h"
26 
27 namespace OHOS::Ace::NG {
28 
29 class ACE_EXPORT TextModelNG : public TextModel {
30 public:
31     void Create(const std::string& content) override;
32     void Create(const RefPtr<SpanStringBase>& spanString) override;
33     void SetFont(const Font& value) override;
34     void SetFontSize(const Dimension& value) override;
35     void SetTextColor(const Color& value) override;
36     void SetTextSelection(int32_t startIndex, int32_t endIndex) override;
37     void SetTextShadow(const std::vector<Shadow>& value) override;
38     void SetTextCaretColor(const Color& value) override;
39     void SetSelectedBackgroundColor(const Color& value) override;
40     void SetItalicFontStyle(Ace::FontStyle value) override;
41     void SetFontWeight(FontWeight value) override;
42     void SetVariableFontWeight(int32_t value) override;
43     void SetEnableVariableFontWeight(bool value) override;
44     void SetMinFontScale(const float value) override;
45     void SetMaxFontScale(const float value) override;
46     void SetFontFamily(const std::vector<std::string>& value) override;
47     void SetTextAlign(TextAlign value) override;
48     void SetTextOverflow(TextOverflow value) override;
49     void SetMaxLines(uint32_t value) override;
50     void SetTextIndent(const Dimension& value) override;
51     void SetLineHeight(const Dimension& value) override;
52     void SetLineSpacing(const Dimension& value) override;
53     void SetTextDecoration(TextDecoration value) override;
54     void SetTextDecorationColor(const Color& value) override;
55     void SetTextDecorationStyle(TextDecorationStyle value) override;
56     void SetBaselineOffset(const Dimension& value) override;
57     void SetWordBreak(WordBreak value) override;
58     void SetLineBreakStrategy(LineBreakStrategy value) override;
59     void SetTextSelectableMode(TextSelectableMode value) override;
60     void SetEllipsisMode(EllipsisMode modal) override;
61     void SetTextCase(TextCase value) override;
62     void SetLetterSpacing(const Dimension& value) override;
63     void SetAdaptMinFontSize(const Dimension& value) override;
64     void SetAdaptMaxFontSize(const Dimension& value) override;
65     void SetHeightAdaptivePolicy(TextHeightAdaptivePolicy value) override;
66     void SetTextDetectEnable(bool value) override;
67     void SetTextDetectConfig(const TextDetectConfig& textDetectConfig) override;
68     void SetOnClick(std::function<void(BaseEventInfo* info)>&& click) override;
69     void ClearOnClick() override;
70     void SetRemoteMessage(std::function<void()>&& event) override;
71     void SetCopyOption(CopyOptions copyOption) override;
72     void SetOnCopy(std::function<void(const std::string&)>&& func) override;
73     void SetOnDragStart(NG::OnDragStartFunc&& onDragStart) override;
74     void SetOnDragEnter(NG::OnDragDropFunc&& onDragEnter) override;
75     void SetOnDragMove(NG::OnDragDropFunc&& onDragMove) override;
76     void SetOnDragLeave(NG::OnDragDropFunc&& onDragLeave) override;
77     void SetOnDrop(NG::OnDragDropFunc&& onDrop) override;
78     void BindSelectionMenu(TextSpanType& spanType, TextResponseType& responseType, std::function<void()>& buildFunc,
79         SelectMenuParam& menuParam) override;
80     void SetOnTextSelectionChange(std::function<void(int32_t, int32_t)>&& func) override;
81     RefPtr<TextControllerBase> GetTextController() override;
82     void SetClipEdge(bool clip) override;
83     void SetFontFeature(const FONT_FEATURES_LIST& value) override;
84     void SetSelectionMenuOptions(const NG::OnCreateMenuCallback&& onCreateMenuCallback,
85         const NG::OnMenuItemClickCallback&& onMenuItemClick) override;
86     void SetResponseRegion(bool isUserSetResponseRegion) override;
87     void SetHalfLeading(bool halfLeading) override;
88     void SetEnableHapticFeedback(bool state) override;
89 
90     static RefPtr<FrameNode> CreateFrameNode(int32_t nodeId, const std::string& content);
91     static void InitText(FrameNode* frameNode, std::string& value);
92     static void InitSpanStringController(FrameNode* frameNode, const RefPtr<SpanStringBase>& spanBase);
93     static RefPtr<TextControllerBase> InitTextController(FrameNode* frameNode);
94     static void SetFontWeight(FrameNode* frameNode, Ace::FontWeight value);
95     static void SetVariableFontWeight(FrameNode* frameNode, int32_t value);
96     static void SetEnableVariableFontWeight(FrameNode* frameNode, bool value);
97     static void SetMinFontScale(FrameNode* frameNode, const float value);
98     static void SetMaxFontScale(FrameNode* frameNode, const float value);
99     static void SetItalicFontStyle(FrameNode* frameNode, Ace::FontStyle value);
100     static void SetTextAlign(FrameNode* frameNode, Ace::TextAlign value);
101     static void SetTextColor(FrameNode* frameNode, const Color& value);
102     static void SetFontSize(FrameNode* frameNode, const Dimension& value);
103     static void SetLineHeight(FrameNode* frameNode, const Dimension& value);
104     static void SetLineSpacing(FrameNode* frameNode, const Dimension& value);
105     static void SetTextOverflow(FrameNode* frameNode, TextOverflow value);
106     static void SetTextDecoration(FrameNode* frameNode, TextDecoration value);
107     static void SetTextDecorationColor(FrameNode* frameNode, const Color& value);
108     static void SetTextDecorationStyle(FrameNode* frameNode, TextDecorationStyle value);
109     static void SetTextCase(FrameNode* frameNode, TextCase value);
110     static void SetMaxLines(FrameNode* frameNode, uint32_t value);
111     static void SetAdaptMinFontSize(FrameNode* frameNode, const Dimension& value);
112     static void SetAdaptMaxFontSize(FrameNode* frameNode, const Dimension& value);
113     static void SetFontFamily(FrameNode* frameNode, const std::vector<std::string>& value);
114     static void SetCopyOption(FrameNode* frameNode, CopyOptions copyOption);
115     static void SetTextShadow(FrameNode* frameNode, const std::vector<Shadow>& value);
116     static void SetHeightAdaptivePolicy(FrameNode* frameNode, TextHeightAdaptivePolicy value);
117     static void SetTextIndent(FrameNode* frameNode, const Dimension& value);
118     static void SetBaselineOffset(FrameNode* frameNode, const Dimension& value);
119     static void SetLetterSpacing(FrameNode* frameNode, const Dimension& value);
120     static void SetFont(FrameNode* frameNode, const Font& value);
121     static void SetWordBreak(FrameNode* frameNode, WordBreak value);
122     static void SetLineBreakStrategy(FrameNode* frameNode, LineBreakStrategy value);
123     static void SetEllipsisMode(FrameNode* frameNode, EllipsisMode value);
124     static void SetTextDetectEnable(FrameNode* frameNode, bool value);
125     static void SetFontFeature(FrameNode* frameNode, const FONT_FEATURES_LIST& value);
126     static void SetTextDetectConfig(FrameNode* frameNode, const std::string& value);
127     static void SetOnClick(FrameNode* frameNode, GestureEventFunc&& click);
128     static void ClearOnClick(FrameNode* frameNode);
129     static void SetResponseRegion(FrameNode* frameNode, std::vector<DimensionRect> regions);
130     static void ClearResponseRegion(FrameNode* frameNode);
131     static void SetOnDetectResultUpdate(FrameNode* frameNode, std::function<void(const std::string&)>&& onResult);
132     static void SetCaretColor(FrameNode* frameNode, const Color& value);
133     static void SetSelectedBackgroundColor(FrameNode* frameNode, const Color& value);
134     static void SetTextContentWithStyledString(FrameNode* frameNode, ArkUI_StyledString* value);
135     static std::vector<std::string> GetFontFamily(FrameNode* frameNode);
136     static CopyOptions GetCopyOption(FrameNode* frameNode);
137     static TextHeightAdaptivePolicy GetHeightAdaptivePolicy(FrameNode* frameNode);
138     static Dimension GetAdaptMinFontSize(FrameNode* frameNode);
139     static Dimension GetAdaptMaxFontSize(FrameNode* frameNode);
140     static Font GetFont(FrameNode* frameNode);
141     static std::string GetContent(FrameNode* frameNode);
142     static float GetLineHeight(FrameNode* frameNode);
143     static float GetLineSpacing(FrameNode* frameNode);
144     static TextDecoration GetDecoration(FrameNode* frameNode);
145     static Color GetTextDecorationColor(FrameNode* frameNode);
146     static TextDecorationStyle GetTextDecorationStyle(FrameNode* frameNode);
147     static TextCase GetTextCase(FrameNode* frameNode);
148     static Dimension GetLetterSpacing(FrameNode* frameNode);
149     static uint32_t GetMaxLines(FrameNode* frameNode);
150     static TextAlign GetTextAlign(FrameNode* frameNode);
151     static TextOverflow GetTextOverflow(FrameNode* frameNode);
152     static Dimension GetTextIndent(FrameNode* frameNode);
153 
154     static Dimension GetFontSize(FrameNode* frameNode);
155     static Ace::FontWeight GetFontWeight(FrameNode* frameNode);
156     static Ace::FontStyle GetItalicFontStyle(FrameNode* frameNode);
157     static Color GetDefaultColor();
158     static Color GetFontColor(FrameNode* frameNode);
159     static Dimension GetTextBaselineOffset(FrameNode* frameNode);
160     static std::vector<Shadow> GetTextShadow(FrameNode* frameNode);
161     static Ace::WordBreak GetWordBreak(FrameNode* frameNode);
162     static EllipsisMode GetEllipsisMode(FrameNode* frameNode);
163     static bool GetTextDetectEnable(FrameNode* frameNode);
164     static std::string GetTextDetectConfig(FrameNode* frameNode);
165     static FONT_FEATURES_LIST GetFontFeature(FrameNode* frameNode);
166     static TextSelectableMode GetTextSelectableMode(FrameNode* frameNode);
167     static Color GetCaretColor(FrameNode* frameNode);
168     static void ResetCaretColor(FrameNode* frameNode);
169     static Color GetSelectedBackgroundColor(FrameNode* frameNode);
170     static void ResetSelectedBackgroundColor(FrameNode* frameNode);
171     static LineBreakStrategy GetLineBreakStrategy(FrameNode* frameNode);
172     static void SetTextSelection(FrameNode* frameNode, int32_t startIndex, int32_t endIndex);
173     static void SetTextSelectableMode(FrameNode* frameNode, TextSelectableMode value);
174     static void SetTextDetectConfig(FrameNode* frameNode, const TextDetectConfig& textDetectConfig);
175     static void SetOnCopy(FrameNode* frameNode, std::function<void(const std::string&)>&& func);
176     static void SetOnTextSelectionChange(FrameNode* frameNode, std::function<void(int32_t, int32_t)>&& func);
177     static void SetSelectionMenuOptions(FrameNode* frameNode, const NG::OnCreateMenuCallback&& onCreateMenuCallback,
178         const NG::OnMenuItemClickCallback&& onMenuItemClick);
179     static void SetHalfLeading(FrameNode* frameNode, bool halfLeading);
180     static bool GetHalfLeading(FrameNode* frameNode);
181 };
182 } // namespace OHOS::Ace::NG
183 
184 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_TEXT_VIEW_H
185