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