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::u16string& content) override; 32 void Create(const std::string& content) override; 33 void Create(const RefPtr<SpanStringBase>& spanString) override; 34 void SetFont(const Font& value) override; 35 void SetFontSize(const Dimension& value) override; 36 void SetTextColor(const Color& value) override; 37 void ResetTextColor() override; 38 void SetTextSelection(int32_t startIndex, int32_t endIndex) override; 39 void SetTextShadow(const std::vector<Shadow>& value) override; 40 void SetTextCaretColor(const Color& value) override; 41 void SetSelectedBackgroundColor(const Color& value) override; 42 void SetItalicFontStyle(Ace::FontStyle value) override; 43 void SetFontWeight(FontWeight value) override; 44 void SetVariableFontWeight(int32_t value) override; 45 void SetEnableVariableFontWeight(bool value) override; 46 void SetMinFontScale(const float value) override; 47 void SetMaxFontScale(const float value) override; 48 void SetFontFamily(const std::vector<std::string>& value) override; 49 void SetTextAlign(TextAlign value) override; 50 void SetTextOverflow(TextOverflow value) override; 51 void SetMaxLines(uint32_t value) override; 52 void SetTextIndent(const Dimension& value) override; 53 void SetLineHeight(const Dimension& value) override; 54 void SetLineSpacing(const Dimension& value) override; 55 void SetIsOnlyBetweenLines(bool isOnlyBetweenLines) override; 56 void SetTextDecoration(TextDecoration value) override; 57 void SetTextDecorationColor(const Color& value) override; 58 void SetTextDecorationStyle(TextDecorationStyle value) override; 59 void SetBaselineOffset(const Dimension& value) override; 60 void SetWordBreak(WordBreak value) override; 61 void SetLineBreakStrategy(LineBreakStrategy value) override; 62 void SetTextSelectableMode(TextSelectableMode value) override; 63 void SetEllipsisMode(EllipsisMode modal) override; 64 void SetTextCase(TextCase value) override; 65 void SetLetterSpacing(const Dimension& value) override; 66 void SetAdaptMinFontSize(const Dimension& value) override; 67 void SetAdaptMaxFontSize(const Dimension& value) override; 68 void SetHeightAdaptivePolicy(TextHeightAdaptivePolicy value) override; 69 void SetContentTransition(TextEffectStrategy value, TextFlipDirection direction, bool enableBlur) override; 70 void ResetContentTransition() override; 71 void SetTextDetectEnable(bool value) override; 72 void SetTextDetectConfig(const TextDetectConfig& textDetectConfig) override; 73 void SetOnClick(std::function<void(BaseEventInfo* info)>&& click, double distanceThreshold) override; 74 void ClearOnClick() override; 75 void SetRemoteMessage(std::function<void()>&& event) override; 76 void SetCopyOption(CopyOptions copyOption) override; 77 void SetOnCopy(std::function<void(const std::u16string&)>&& func) override; 78 void SetOnDragStart(NG::OnDragStartFunc&& onDragStart) override; 79 void BindSelectionMenu(TextSpanType& spanType, TextResponseType& responseType, std::function<void()>& buildFunc, 80 SelectMenuParam& menuParam) override; 81 void SetOnTextSelectionChange(std::function<void(int32_t, int32_t)>&& func) override; 82 RefPtr<TextControllerBase> GetTextController() override; 83 void SetClipEdge(bool clip) override; 84 void SetFontFeature(const FONT_FEATURES_LIST& value) override; 85 void SetMarqueeOptions(const TextMarqueeOptions& options) override; 86 void SetOnMarqueeStateChange(std::function<void(int32_t)>&& func) override; 87 void SetSelectionMenuOptions(const NG::OnCreateMenuCallback&& onCreateMenuCallback, 88 const NG::OnMenuItemClickCallback&& onMenuItemClick, 89 const NG::OnPrepareMenuCallback&& onPrepareMenuCallback) override; 90 void SetResponseRegion(bool isUserSetResponseRegion) override; 91 void SetHalfLeading(bool halfLeading) override; 92 void SetEnableHapticFeedback(bool state) override; 93 void SetEnableAutoSpacing(bool enabled) override; 94 void SetLineThicknessScale(float value) override; 95 void SetOptimizeTrailingSpace(bool trim) override; 96 void SetGradientShaderStyle(NG::Gradient& gradient) override; 97 void SetColorShaderStyle(const Color& value) override; 98 void ResetGradientShaderStyle() override; 99 void SetTextVerticalAlign(TextVerticalAlign verticalAlign) override; 100 101 static RefPtr<FrameNode> CreateFrameNode(int32_t nodeId, const std::u16string& content); 102 static void InitText(FrameNode* frameNode, std::u16string& value); 103 static void InitSpanStringController(FrameNode* frameNode, const RefPtr<SpanStringBase>& spanBase); 104 static RefPtr<TextControllerBase> InitTextController(FrameNode* frameNode); 105 static void SetFontWeight(FrameNode* frameNode, Ace::FontWeight value); 106 static void SetVariableFontWeight(FrameNode* frameNode, int32_t value); 107 static void SetEnableVariableFontWeight(FrameNode* frameNode, bool value); 108 static void SetMinFontScale(FrameNode* frameNode, const float value); 109 static void SetMaxFontScale(FrameNode* frameNode, const float value); 110 static void SetItalicFontStyle(FrameNode* frameNode, Ace::FontStyle value); 111 static void SetTextAlign(FrameNode* frameNode, Ace::TextAlign value); 112 static void SetTextColor(FrameNode* frameNode, const Color& value); 113 static void ResetTextColor(FrameNode* frameNode); 114 static void SetFontSize(FrameNode* frameNode, const Dimension& value); 115 static void SetLineHeight(FrameNode* frameNode, const Dimension& value); 116 static void SetLineSpacing(FrameNode* frameNode, const Dimension& value, bool isOnlyBetweenLines); 117 static void SetTextOverflow(FrameNode* frameNode, TextOverflow value); 118 static void SetTextDecoration(FrameNode* frameNode, TextDecoration value); 119 static void SetTextDecorationColor(FrameNode* frameNode, const Color& value); 120 static void SetTextDecorationStyle(FrameNode* frameNode, TextDecorationStyle value); 121 static void SetTextCase(FrameNode* frameNode, TextCase value); 122 static void SetMaxLines(FrameNode* frameNode, uint32_t value); 123 static void SetAdaptMinFontSize(FrameNode* frameNode, const Dimension& value); 124 static void SetAdaptMaxFontSize(FrameNode* frameNode, const Dimension& value); 125 static void SetFontFamily(FrameNode* frameNode, const std::vector<std::string>& value); 126 static void SetCopyOption(FrameNode* frameNode, CopyOptions copyOption); 127 static void SetTextShadow(FrameNode* frameNode, const std::vector<Shadow>& value); 128 static void SetHeightAdaptivePolicy(FrameNode* frameNode, TextHeightAdaptivePolicy value); 129 static void SetTextIndent(FrameNode* frameNode, const Dimension& value); 130 static void SetBaselineOffset(FrameNode* frameNode, const Dimension& value); 131 static void SetLetterSpacing(FrameNode* frameNode, const Dimension& value); 132 static void SetFont(FrameNode* frameNode, const Font& value); 133 static void SetWordBreak(FrameNode* frameNode, WordBreak value); 134 static void SetLineBreakStrategy(FrameNode* frameNode, LineBreakStrategy value); 135 static void SetEllipsisMode(FrameNode* frameNode, EllipsisMode value); 136 static void SetTextDetectEnable(FrameNode* frameNode, bool value); 137 static void SetFontFeature(FrameNode* frameNode, const FONT_FEATURES_LIST& value); 138 static void SetMarqueeOptions(FrameNode* frameNode, const TextMarqueeOptions& options); 139 static void SetOnMarqueeStateChange(FrameNode* frameNode, std::function<void(int32_t)>&& func); 140 static void SetTextDetectConfig(FrameNode* frameNode, const std::string& value); 141 static void SetOnClick(FrameNode* frameNode, GestureEventFunc&& click); 142 static void ClearOnClick(FrameNode* frameNode); 143 static void SetResponseRegion(FrameNode* frameNode, std::vector<DimensionRect> regions); 144 static void ClearResponseRegion(FrameNode* frameNode); 145 static void SetOnDetectResultUpdate(FrameNode* frameNode, std::function<void(const std::string&)>&& onResult); 146 static void SetCaretColor(FrameNode* frameNode, const Color& value); 147 static void SetSelectedBackgroundColor(FrameNode* frameNode, const Color& value); 148 static void SetTextContentWithStyledString(FrameNode* frameNode, ArkUI_StyledString* value); 149 static std::vector<std::string> GetFontFamily(FrameNode* frameNode); 150 static CopyOptions GetCopyOption(FrameNode* frameNode); 151 static TextMarqueeOptions GetMarqueeOptions(FrameNode* frameNode); 152 static TextHeightAdaptivePolicy GetHeightAdaptivePolicy(FrameNode* frameNode); 153 static Dimension GetAdaptMinFontSize(FrameNode* frameNode); 154 static Dimension GetAdaptMaxFontSize(FrameNode* frameNode); 155 static Font GetFont(FrameNode* frameNode); 156 static std::u16string GetContent(FrameNode* frameNode); 157 static float GetLineHeight(FrameNode* frameNode); 158 static float GetLineSpacing(FrameNode* frameNode); 159 static TextDecoration GetDecoration(FrameNode* frameNode); 160 static Color GetTextDecorationColor(FrameNode* frameNode); 161 static TextDecorationStyle GetTextDecorationStyle(FrameNode* frameNode); 162 static TextCase GetTextCase(FrameNode* frameNode); 163 static Dimension GetLetterSpacing(FrameNode* frameNode); 164 static uint32_t GetMaxLines(FrameNode* frameNode); 165 static TextAlign GetTextAlign(FrameNode* frameNode); 166 static TextOverflow GetTextOverflow(FrameNode* frameNode); 167 static Dimension GetTextIndent(FrameNode* frameNode); 168 169 static Dimension GetFontSize(FrameNode* frameNode); 170 static Ace::FontWeight GetFontWeight(FrameNode* frameNode); 171 static Ace::FontStyle GetItalicFontStyle(FrameNode* frameNode); 172 static Color GetDefaultColor(int32_t themeScopeId); 173 static Color GetFontColor(FrameNode* frameNode); 174 static Dimension GetTextBaselineOffset(FrameNode* frameNode); 175 static std::vector<Shadow> GetTextShadow(FrameNode* frameNode); 176 static Ace::WordBreak GetWordBreak(FrameNode* frameNode); 177 static EllipsisMode GetEllipsisMode(FrameNode* frameNode); 178 static bool GetTextDetectEnable(FrameNode* frameNode); 179 static std::string GetTextDetectConfig(FrameNode* frameNode); 180 static FONT_FEATURES_LIST GetFontFeature(FrameNode* frameNode); 181 static TextSelectableMode GetTextSelectableMode(FrameNode* frameNode); 182 static Color GetCaretColor(FrameNode* frameNode); 183 static void ResetCaretColor(FrameNode* frameNode); 184 static Color GetSelectedBackgroundColor(FrameNode* frameNode); 185 static void ResetSelectedBackgroundColor(FrameNode* frameNode); 186 static LineBreakStrategy GetLineBreakStrategy(FrameNode* frameNode); 187 static void SetTextSelection(FrameNode* frameNode, int32_t startIndex, int32_t endIndex); 188 static void SetTextSelectableMode(FrameNode* frameNode, TextSelectableMode value); 189 static void SetTextDetectConfig(FrameNode* frameNode, const TextDetectConfig& textDetectConfig); 190 static void SetOnCopy(FrameNode* frameNode, std::function<void(const std::u16string&)>&& func); 191 static void SetOnTextSelectionChange(FrameNode* frameNode, std::function<void(int32_t, int32_t)>&& func); 192 static void OnCreateMenuCallbackUpdate(FrameNode* frameNode, const NG::OnCreateMenuCallback&& onCreateMenuCallback); 193 static void OnMenuItemClickCallbackUpdate( 194 FrameNode* frameNode, const NG::OnMenuItemClickCallback&& onMenuItemClick); 195 static void OnPrepareMenuCallbackUpdate( 196 FrameNode* frameNode, const NG::OnPrepareMenuCallback&& onPrepareMenuCallback); 197 static void SetHalfLeading(FrameNode* frameNode, bool halfLeading); 198 static bool GetHalfLeading(FrameNode* frameNode); 199 static void SetEnableHapticFeedback(FrameNode* frameNode, bool state); 200 static size_t GetLineCount(FrameNode* frameNode); 201 static void SetEnableAutoSpacing(FrameNode* frameNode, bool enabled); 202 static bool GetEnableAutoSpacing(FrameNode* frameNode); 203 static void SetLineThicknessScale(FrameNode* frameNode, float value); 204 static void SetOptimizeTrailingSpace(FrameNode* frameNode, bool trim); 205 static bool GetOptimizeTrailingSpace(FrameNode* frameNode); 206 static void SetGradientStyle(FrameNode* frameNode, NG::Gradient& gradient); 207 static void SetColorShaderStyle(FrameNode* frameNode, const Color& value); 208 static NG::Gradient GetGradientStyle(FrameNode* frameNode); 209 static void ResetTextGradient(FrameNode* frameNode); 210 static void SetTextVerticalAlign(FrameNode* frameNode, TextVerticalAlign verticalAlign); 211 static TextVerticalAlign GetTextVerticalAlign(FrameNode* frameNode); 212 static void SetContentTransition( 213 FrameNode* frameNode, TextEffectStrategy value, TextFlipDirection direction, bool enableBlur); 214 static void ResetContentTransition(FrameNode* frameNode); 215 }; 216 } // namespace OHOS::Ace::NG 217 218 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_TEXT_VIEW_H 219