• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2024 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_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_RICH_EDITOR_RICH_EDITOR_PATTERN_H
18 
19 #include <cstdint>
20 #include <map>
21 #include <optional>
22 #include <set>
23 #include <string>
24 
25 #include "base/log/event_report.h"
26 #include "base/utils/device_config.h"
27 #include "core/common/ace_application_info.h"
28 #include "core/common/ai/ai_write_adapter.h"
29 #include "core/common/ime/text_edit_controller.h"
30 #include "core/common/ime/text_input_action.h"
31 #include "core/common/ime/text_input_client.h"
32 #include "core/common/ime/text_input_configuration.h"
33 #include "core/common/ime/text_input_connection.h"
34 #include "core/common/ime/text_input_formatter.h"
35 #include "core/common/ime/text_input_proxy.h"
36 #include "core/common/ime/text_input_type.h"
37 #include "core/common/ime/text_selection.h"
38 #include "core/components/common/properties/text_layout_info.h"
39 #include "core/components_ng/pattern/rich_editor/paragraph_manager.h"
40 #include "core/components_ng/pattern/rich_editor/rich_editor_accessibility_property.h"
41 #include "core/components_ng/pattern/rich_editor/rich_editor_content_modifier.h"
42 #include "core/components_ng/pattern/rich_editor/rich_editor_controller.h"
43 #include "core/components_ng/pattern/rich_editor/rich_editor_event_hub.h"
44 #include "core/components_ng/pattern/rich_editor/rich_editor_layout_algorithm.h"
45 #include "core/components_ng/pattern/rich_editor/rich_editor_layout_property.h"
46 #include "core/components_ng/pattern/rich_editor/rich_editor_overlay_modifier.h"
47 #include "core/components_ng/pattern/rich_editor/rich_editor_paint_method.h"
48 #include "core/components_ng/pattern/rich_editor/rich_editor_select_overlay.h"
49 #include "core/components_ng/pattern/rich_editor/rich_editor_styled_string_controller.h"
50 #include "core/components_ng/pattern/rich_editor/selection_info.h"
51 #include "core/components_ng/pattern/scrollable/scrollable_pattern.h"
52 #include "core/components_ng/pattern/select_overlay/magnifier.h"
53 #include "core/components_ng/pattern/select_overlay/magnifier_controller.h"
54 #include "core/components_ng/pattern/text/layout_info_interface.h"
55 #include "core/components_ng/pattern/text/span_node.h"
56 #include "core/components_ng/pattern/text/text_base.h"
57 #include "core/components_ng/pattern/text/text_pattern.h"
58 #include "core/components_ng/pattern/text_field/text_field_model.h"
59 #include "core/text/text_emoji_processor.h"
60 
61 #ifndef ACE_UNITTEST
62 #ifdef ENABLE_STANDARD_INPUT
63 #include "refbase.h"
64 
65 namespace OHOS::MiscServices {
66 class OnTextChangedListener;
67 struct TextConfig;
68 } // namespace OHOS::MiscServices
69 #endif
70 #endif
71 
72 #define COPY_SPAN_STYLE_IF_PRESENT(sourceNode, targetNode, styleType) \
73     do {                                                                            \
74         if ((sourceNode)->Has##styleType()) {                                       \
75             (targetNode)->Update##styleType(*((sourceNode)->Get##styleType()));     \
76         }                                                                           \
77     } while (false)
78 #define CONTENT_MODIFY_LOCK(patternPtr) ContentModifyLock contentModifyLock(patternPtr)
79 #define RICH_EDITOR_SCOPE(scopeFlag) RichEditorScope richEditorScope(scopeFlag)
80 
81 #define IF_TRUE(cond, func) \
82     do {                    \
83         if (cond) {         \
84             func;           \
85         }                   \
86     } while (false)
87 
88 #define IF_PRESENT(opt, func) \
89     do {                      \
90         if (opt) {            \
91             opt->func;        \
92         }                     \
93     } while (false)
94 
95 namespace OHOS::Ace::NG {
96 class InspectorFilter;
97 class OneStepDragController;
98 class RichEditorUndoManager;
99 struct UndoRedoRecord;
100 class RichEditorContentPattern;
101 class StyleManager;
102 using SpanOptions = std::variant<TextSpanOptions, ImageSpanOptions, SymbolSpanOptions, BuilderSpanOptions>;
103 using OptionsList = std::list<SpanOptions>;
104 
105 // TextPattern is the base class for text render node to perform paint text.
106 enum class MoveDirection { FORWARD, BACKWARD };
107 
108 enum class AutoScrollEvent { HANDLE, DRAG, MOUSE, NONE, CARET };
109 enum class EdgeDetectionStrategy { OUT_BOUNDARY, IN_BOUNDARY, DISABLE };
110 struct AutoScrollParam {
111     AutoScrollEvent autoScrollEvent = AutoScrollEvent::NONE;
112     RectF handleRect;
113     bool isFirstHandle = false;
114     float offset = 0.0f;
115     bool showScrollbar = false;
116     Offset eventOffset;
117     bool isFirstRun_ = true;
118 };
119 enum class RecordType { DEL_FORWARD = 0, DEL_BACKWARD = 1, INSERT = 2, UNDO = 3, REDO = 4, DRAG = 5 };
120 enum class SelectorAdjustPolicy { INCLUDE = 0, EXCLUDE };
121 enum class HandleType { FIRST = 0, SECOND };
122 enum class SelectType { SELECT_FORWARD = 0, SELECT_BACKWARD, SELECT_NOTHING };
123 enum class CaretAffinityPolicy { DEFAULT = 0, UPSTREAM_FIRST, DOWNSTREAM_FIRST };
124 enum class OperationType { DEFAULT = 0, DRAG, IME, FINISH_PREVIEW, PASTE, ACCESSIBILITY, AI_WRITE, STYLUS };
125 const std::unordered_map<OperationType, TextChangeReason> OPERATION_REASON_MAP = {
126     { OperationType::DEFAULT, TextChangeReason::INPUT },
127     { OperationType::DRAG, TextChangeReason::DRAG },
128     { OperationType::IME, TextChangeReason::INPUT },
129     { OperationType::FINISH_PREVIEW, TextChangeReason::INPUT },
130     { OperationType::PASTE, TextChangeReason::PASTE },
131     { OperationType::ACCESSIBILITY, TextChangeReason::ACCESSIBILITY },
132     { OperationType::AI_WRITE, TextChangeReason::AI_WRITE },
133     { OperationType::STYLUS, TextChangeReason::STYLUS },
134 };
135 const std::map<std::pair<HandleType, SelectorAdjustPolicy>, MoveDirection> SELECTOR_ADJUST_DIR_MAP = {
136     {{ HandleType::FIRST, SelectorAdjustPolicy::INCLUDE }, MoveDirection::BACKWARD },
137     {{ HandleType::FIRST, SelectorAdjustPolicy::EXCLUDE }, MoveDirection::FORWARD },
138     {{ HandleType::SECOND, SelectorAdjustPolicy::INCLUDE }, MoveDirection::FORWARD },
139     {{ HandleType::SECOND, SelectorAdjustPolicy::EXCLUDE }, MoveDirection::BACKWARD }
140 };
141 struct CaretOffsetInfo {
142     // caret front offset info
143     OffsetF caretOffsetUp;
144     // caret end offset info
145     OffsetF caretOffsetDown;
146     // caret position offset info
147     OffsetF caretOffsetLine;
148     float caretHeightUp = 0.0f;
149     float caretHeightDown = 0.0f;
150     float caretHeightLine = 0.0f;
151 };
152 enum class PositionType { DEFAULT, PARAGRAPH_START, PARAGRAPH_END, LINE_START, LINE_END };
153 struct SysScale {
154     double dipScale = 1.0;
155     double logicScale = 1.0;
156     double fontScale = 1.0;
157     double fontWeightScale = 1.0;
158     bool operator==(const SysScale& rhs) const
159     {
160         return NearEqual(dipScale, rhs.dipScale)
161             && NearEqual(logicScale, rhs.logicScale)
162             && NearEqual(fontScale, rhs.fontScale)
163             && NearEqual(fontWeightScale, rhs.fontWeightScale);
164     }
165     bool operator!=(const SysScale& rhs) const
166     {
167         return !operator==(rhs);
168     }
ToStringSysScale169     std::string ToString()
170     {
171         std::stringstream ss;
172         ss << dipScale << ", " << logicScale << ", " << fontScale << ", " << fontWeightScale;
173         return ss.str();
174     }
175 };
176 
177 class RichEditorScope {
178 public:
RichEditorScope(bool & scopeFlag)179     RichEditorScope(bool& scopeFlag) : scopeFlag_(scopeFlag)
180     {
181         scopeFlag_ = true;
182     }
~RichEditorScope()183     ~RichEditorScope()
184     {
185         scopeFlag_ = false;
186     }
187 private:
188     bool& scopeFlag_;
189 };
190 
191 class RichEditorPattern
192     : public TextPattern, public ScrollablePattern, public TextInputClient, public SpanWatcher {
193     DECLARE_ACE_TYPE(RichEditorPattern, TextPattern, ScrollablePattern, TextInputClient, SpanWatcher);
194 
195 public:
196     RichEditorPattern(bool isStyledStringMode = false);
197     ~RichEditorPattern() override;
198 
199     struct OperationRecord {
OperationRecordOperationRecord200         OperationRecord() : beforeCaretPosition(-1), afterCaretPosition(-1), deleteCaretPosition(-1) {}
201         std::optional<std::u16string> addText;
202         std::optional<std::u16string> deleteText;
203         int32_t beforeCaretPosition;
204         int32_t afterCaretPosition;
205         int32_t deleteCaretPosition;
206 
ResetOperationRecord207         void Reset()
208         {
209             beforeCaretPosition = -1;
210             afterCaretPosition = -1;
211             deleteCaretPosition = -1;
212             addText = std::nullopt;
213             deleteText = std::nullopt;
214         }
215 
ToStringOperationRecord216         std::string ToString() const
217         {
218             auto jsonValue = JsonUtil::Create(true);
219             JSON_STRING_PUT_INT(jsonValue, beforeCaretPosition);
220             JSON_STRING_PUT_INT(jsonValue, afterCaretPosition);
221             JSON_STRING_PUT_INT(jsonValue, deleteCaretPosition);
222             auto addLength = static_cast<int32_t>(addText.value_or(u"").length());
223             auto deleteLength = static_cast<int32_t>(deleteText.value_or(u"").length());
224             JSON_STRING_PUT_INT(jsonValue, addLength);
225             JSON_STRING_PUT_INT(jsonValue, deleteLength);
226             return jsonValue->ToString();
227         }
228     };
229 
230     struct PreviewTextRecord {
231         int32_t startOffset = INVALID_VALUE;
232         int32_t endOffset = INVALID_VALUE;
233         bool previewTextHasStarted = false;
234         std::u16string previewContent;
235         std::u16string newPreviewContent;
236         bool needReplacePreviewText = false;
237         bool needReplaceText = false;
238         PreviewRange replacedRange;
239         bool isSpanSplit = false;
240         bool needUpdateCaret = true;
241         bool previewTextExiting = false;
242 
ToStringPreviewTextRecord243         std::string ToString() const
244         {
245             auto jsonValue = JsonUtil::Create(true);
246             JSON_STRING_PUT_STRING(jsonValue, previewContent);
247             JSON_STRING_PUT_BOOL(jsonValue, previewTextHasStarted);
248             JSON_STRING_PUT_INT(jsonValue, startOffset);
249             JSON_STRING_PUT_INT(jsonValue, endOffset);
250             JSON_STRING_PUT_BOOL(jsonValue, isSpanSplit);
251             JSON_STRING_PUT_BOOL(jsonValue, needUpdateCaret);
252             JSON_STRING_PUT_BOOL(jsonValue, previewTextExiting);
253 
254             return jsonValue->ToString();
255         }
256 
ResetPreviewTextRecord257         void Reset()
258         {
259             startOffset = INVALID_VALUE;
260             endOffset = INVALID_VALUE;
261             previewContent.clear();
262             previewTextHasStarted = false;
263             needReplacePreviewText = false;
264             needReplaceText = false;
265             replacedRange.Set(INVALID_VALUE, INVALID_VALUE);
266             isSpanSplit = false;
267             previewTextExiting = false;
268         }
269 
IsValidPreviewTextRecord270         bool IsValid() const
271         {
272             return !previewContent.empty() && previewTextHasStarted && startOffset >= 0 && endOffset >= startOffset;
273         }
274 
NeedReplacePreviewTextRecord275         bool NeedReplace() const
276         {
277             return needReplacePreviewText || needReplaceText;
278         }
279     };
280 
281     struct TouchAndMoveCaretState {
282         bool isTouchCaret = false;
283         bool isMoveCaret = false;
284         Offset touchDownOffset;
285         const Dimension minDistance = 5.0_vp;
286         std::optional<int32_t> touchFingerId = std::nullopt;
287 
ResetTouchAndMoveCaretState288         void Reset()
289         {
290             isTouchCaret = false;
291             isMoveCaret = false;
292             touchDownOffset.Reset();
293             touchFingerId.reset();
294         }
295     };
296 
297     struct FloatingCaretState {
298         bool isFloatingCaretVisible = false;
299         bool isOriginCaretVisible = false;
300         std::optional<Offset> touchMoveOffset = std::nullopt;
301         Color originCaretColor = Color(0x4D000000);
302         const Dimension showFloatingCaretDistance = 10.0_vp;
303 
ResetFloatingCaretState304         void Reset()
305         {
306             isFloatingCaretVisible = false;
307             isOriginCaretVisible = false;
308             touchMoveOffset.reset();
309         }
310 
UpdateOriginCaretColorFloatingCaretState311         void UpdateOriginCaretColor(ColorMode colorMode)
312         {
313             originCaretColor = colorMode == ColorMode::DARK ? Color(0x4DFFFFFF) : Color(0x4D000000);
314         }
315 
UpdateByTouchMoveFloatingCaretState316         void UpdateByTouchMove(const Offset& offset, double distance, const RectF& boundaryRect)
317         {
318             isFloatingCaretVisible = true;
319             touchMoveOffset = offset;
320             bool isCaretAtBoundaryLeft = LessOrEqual(touchMoveOffset->GetX(), boundaryRect.Left());
321             bool isCaretAtBoundaryRight = GreatOrEqual(touchMoveOffset->GetX(), boundaryRect.Right());
322             if (!isCaretAtBoundaryLeft && !isCaretAtBoundaryRight) {
323                 isOriginCaretVisible = GreatNotEqual(distance, showFloatingCaretDistance.ConvertToPx());
324             } else {
325                 touchMoveOffset->SetX(isCaretAtBoundaryLeft ? boundaryRect.Left() : boundaryRect.Right());
326                 isOriginCaretVisible = true;
327             }
328         }
329     };
330 
GetFloatingCaretState()331     const FloatingCaretState& GetFloatingCaretState() const
332     {
333         return floatingCaretState_;
334     }
335 
ResetFloatingCaretState()336     void ResetFloatingCaretState()
337     {
338         floatingCaretState_.Reset();
339     }
340 
341     class ContentModifyLock {
342     public:
343         ContentModifyLock();
ContentModifyLock(RichEditorPattern * pattern)344         ContentModifyLock(RichEditorPattern* pattern)
345         {
346             pattern->isModifyingContent_ = true;
347             pattern_ = WeakClaim(pattern);
348         }
~ContentModifyLock()349         ~ContentModifyLock()
350         {
351             auto pattern = pattern_.Upgrade();
352             if (!pattern) {
353                 TAG_LOGE(AceLogTag::ACE_RICH_TEXT, "pattern is null, unlock failed");
354                 return;
355             }
356             pattern->isModifyingContent_ = false;
357             auto host = pattern->GetHost();
358             CHECK_NULL_VOID(host);
359             host->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
360         }
361     private:
362         WeakPtr<RichEditorPattern> pattern_;
363     };
364 
365     bool NotUpdateCaretInPreview(int32_t caret, const PreviewTextRecord& record);
366     int32_t SetPreviewText(const std::u16string& previewTextValue, const PreviewRange range) override;
367     bool SetPreviewTextForDelete(int32_t oriLength, bool isBackward, bool isByIME);
368 
369     const PreviewTextInfo GetPreviewTextInfo() const;
370 
371     void FinishTextPreview() override;
372 
ReceivePreviewTextStyle(const std::string & style)373     void ReceivePreviewTextStyle(const std::string& style) override
374     {
375         TAG_LOGI(AceLogTag::ACE_RICH_TEXT, "previewTextStyle: [%{public}s]", style.c_str());
376         auto property = GetLayoutProperty<RichEditorLayoutProperty>();
377         CHECK_NULL_VOID(property && !style.empty());
378         property->UpdatePreviewTextStyle(style);
379     }
380 
381     int32_t CheckPreviewTextValidate(const std::string& previewTextValue, const PreviewRange range) override;
382 
383     int32_t CheckPreviewTextValidate(const std::u16string& previewTextValue, const PreviewRange range) override;
384 
385     const Color& GetPreviewTextDecorationColor() const;
386 
IsPreviewTextInputting()387     bool IsPreviewTextInputting()
388     {
389         return previewTextRecord_.IsValid();
390     }
391 
392     std::vector<RectF> GetPreviewTextRects();
393 
394     float GetPreviewTextUnderlineWidth() const;
395 
396     PreviewTextStyle GetPreviewTextStyle() const;
397 
SetSupportPreviewText(bool isTextPreviewSupported)398     void SetSupportPreviewText(bool isTextPreviewSupported)
399     {
400         TAG_LOGI(AceLogTag::ACE_RICH_TEXT, "enablePreviewText=%{public}d", isTextPreviewSupported);
401         isTextPreviewSupported_ = isTextPreviewSupported;
402     }
403 
404     ACE_DEFINE_PROPERTY_ITEM_FUNC_WITHOUT_GROUP(TextInputAction, TextInputAction)
405     TextInputAction GetDefaultTextInputAction() const;
406 
407     // RichEditor needs softkeyboard, override function.
NeedSoftKeyboard()408     bool NeedSoftKeyboard() const override
409     {
410         return true;
411     }
412 
413     // Support LayoutPolicy.matchParent
IsEnableMatchParent()414     bool IsEnableMatchParent() override
415     {
416         return true;
417     }
418 
419     BlurReason GetBlurReason();
420 
421     uint32_t GetSCBSystemWindowId();
422 
CreateEventHub()423     RefPtr<EventHub> CreateEventHub() override
424     {
425         return MakeRefPtr<RichEditorEventHub>();
426     }
427 
CreateLayoutProperty()428     RefPtr<LayoutProperty> CreateLayoutProperty() override
429     {
430         return MakeRefPtr<RichEditorLayoutProperty>();
431     }
432 
CreateLayoutAlgorithm()433     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
434     {
435         HandleSysScaleChanged();
436         return MakeRefPtr<RichEditorLayoutAlgorithm>(
437             spans_, &paragraphs_, &paragraphCache_, styleManager_, NeedShowPlaceholder(),
438             AISpanLayoutInfo{ GetAISpanMap(), NeedShowAIDetect() });
439     }
440 
HandleSysScaleChanged()441     void HandleSysScaleChanged()
442     {
443         auto ctx = GetContext();
444         if (!ctx) {
445             TAG_LOGW(AceLogTag::ACE_RICH_TEXT, "context is nullptr, handle scale failed");
446             return;
447         }
448         SysScale sysScale{ ctx->GetDipScale(), ctx->GetLogicScale(), ctx->GetFontScale(), ctx->GetFontWeightScale() };
449         if (sysScale != lastSysScale_) {
450             TAG_LOGI(AceLogTag::ACE_RICH_TEXT, "sys scale changed, %{public}s -> %{public}s",
451                 lastSysScale_.ToString().c_str(), sysScale.ToString().c_str());
452             lastSysScale_ = sysScale;
453             paragraphCache_.Clear();
454         }
455     }
456 
GetFocusPattern()457     FocusPattern GetFocusPattern() const override
458     {
459         FocusPattern focusPattern = { FocusType::NODE, true, FocusStyleType::INNER_BORDER };
460         focusPattern.SetIsFocusActiveWhenFocused(true);
461         return focusPattern;
462     }
463 
464     RefPtr<NodePaintMethod> CreateNodePaintMethod() override;
465 
GetRichEditorController()466     const RefPtr<RichEditorController>& GetRichEditorController()
467     {
468         return richEditorController_;
469     }
470 
SetRichEditorController(const RefPtr<RichEditorController> & controller)471     void SetRichEditorController(const RefPtr<RichEditorController>& controller)
472     {
473         richEditorController_ = controller;
474     }
475 
GetRichEditorStyledStringController()476     const RefPtr<RichEditorStyledStringController>& GetRichEditorStyledStringController()
477     {
478         return richEditorStyledStringController_;
479     }
480 
SetRichEditorStyledStringController(const RefPtr<RichEditorStyledStringController> & controller)481     void SetRichEditorStyledStringController(const RefPtr<RichEditorStyledStringController>& controller)
482     {
483         richEditorStyledStringController_ = controller;
484     }
485 
GetTimestamp()486     long long GetTimestamp() const
487     {
488         return timestamp_;
489     }
490 
SetMaxLength(std::optional<int32_t> maxLength)491     void SetMaxLength(std::optional<int32_t> maxLength)
492     {
493         if (maxLength != INT_MAX) {
494             DeleteToMaxLength(maxLength);
495         }
496         maxLength_ = maxLength;
497         TAG_LOGI(AceLogTag::ACE_RICH_TEXT, "maxLength: [%{public}d]", maxLength_.value_or(INT_MAX));
498     }
499 
GetMaxLength()500     int32_t GetMaxLength()
501     {
502         return maxLength_.value_or(INT_MAX);
503     }
504 
SetMaxLines(int32_t maxLines)505     void SetMaxLines(int32_t maxLines)
506     {
507         maxLines_ = maxLines;
508     }
509 
GetMaxLines()510     int32_t GetMaxLines()
511     {
512         return maxLines_;
513     }
514 
SetMaxLinesHeight(float maxLinesHeight)515     void SetMaxLinesHeight(float maxLinesHeight)
516     {
517         maxLinesHeight_ = maxLinesHeight;
518     }
519 
GetMaxLinesHeight()520     float GetMaxLinesHeight()
521     {
522         return maxLinesHeight_;
523     }
524 
UpdateSpanPosition()525     void UpdateSpanPosition()
526     {
527         uint32_t spanTextLength = 0;
528         for (auto& span : spans_) {
529             span->rangeStart = static_cast<int32_t>(spanTextLength);
530             spanTextLength += span->content.length();
531             span->position = static_cast<int32_t>(spanTextLength);
532         }
533     }
534 
SetEnableAutoSpacing(bool enabled)535     void SetEnableAutoSpacing(bool enabled)
536     {
537         CHECK_NULL_VOID(isEnableAutoSpacing_ != enabled);
538         isEnableAutoSpacing_ = enabled;
539         paragraphCache_.Clear();
540         TAG_LOGI(AceLogTag::ACE_RICH_TEXT, "SetEnableAutoSpacing: [%{public}d]", isEnableAutoSpacing_);
541     }
542 
OnAttachToMainTree()543     void OnAttachToMainTree() override
544     {
545         TextPattern::OnAttachToMainTree();
546     }
547 
OnDetachFromMainTree()548     void OnDetachFromMainTree() override
549     {
550         TextPattern::OnDetachFromMainTree();
551     }
552 
RegisterCaretChangeListener(std::function<void (int32_t)> && listener)553     void RegisterCaretChangeListener(std::function<void(int32_t)>&& listener)
554     {
555         caretChangeListener_ = listener;
556     }
557 
558     void SetStyledString(const RefPtr<SpanString>& value);
559 
GetStyledString()560     RefPtr<MutableSpanString> GetStyledString() const
561     {
562         return styledString_;
563     }
564 
IsStyledStringModeEnabled()565     bool IsStyledStringModeEnabled()
566     {
567         return isSpanStringMode_ && styledString_;
568     }
569 
570     void UpdateSpanItems(const std::list<RefPtr<NG::SpanItem>>& spanItems) override;
571     void ProcessStyledString();
572     void MountImageNode(const RefPtr<ImageSpanItem>& imageItem);
573     void SetImageLayoutProperty(RefPtr<ImageSpanNode> imageNode, const ImageSpanOptions& options);
574     void InsertValueInStyledString(
575         const std::u16string& insertValue, bool shouldCommitInput = false, bool isPaste = false);
576     void HandleStyledStringInsertion(RefPtr<SpanString> insertStyledString, const UndoRedoRecord& record,
577         std::u16string& subValue, bool needReplaceInTextPreview, bool shouldCommitInput);
578     RefPtr<SpanString> CreateStyledStringByTextStyle(
579         const std::u16string& insertValue, const struct UpdateSpanStyle& updateSpanStyle, const TextStyle& textStyle);
580     RefPtr<FontSpan> CreateFontSpanByTextStyle(
581         const struct UpdateSpanStyle& updateSpanStyle, const TextStyle& textStyle, int32_t length);
582     RefPtr<DecorationSpan> CreateDecorationSpanByTextStyle(
583         const struct UpdateSpanStyle& updateSpanStyle, const TextStyle& textStyle, int32_t length);
584     void DeleteBackwardInStyledString(int32_t length);
585     void DeleteForwardInStyledString(int32_t length, bool isIME = true);
586     void DeleteValueInStyledString(int32_t start, int32_t length, bool isIME = true, bool isUpdateCaret = true);
587 
588     RefPtr<SpanString> CreateStyledStringByStyleBefore(int32_t start, const std::u16string& string);
589     bool BeforeStyledStringChange(const UndoRedoRecord& record, bool isUndo = false);
590     bool BeforeStyledStringChange(int32_t start, int32_t length, const std::u16string& string);
591     bool BeforeStyledStringChange(int32_t start, int32_t length, const RefPtr<SpanString>& styledString);
592     void AfterStyledStringChange(const UndoRedoRecord& record, bool isUndo = false);
593     void AfterStyledStringChange(int32_t start, int32_t length, const std::u16string& string);
594 
595     void ProcessStyledUndo(const UndoRedoRecord& record);
596     void ProcessStyledRedo(const UndoRedoRecord& record);
597     void ApplyRecordInStyledString(const UndoRedoRecord& record);
598     void ApplyRecordInSpans(const UndoRedoRecord& record, bool isUndo);
599     void ApplyOptions(const OptionsList& optionsList, bool restoreBuilderSpan, bool isUndo);
600 
601     void ResetBeforePaste();
602     void ResetAfterPaste();
603 
604     void OnModifyDone() override;
605     void BeforeCreateLayoutWrapper() override;
606     bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override;
607     void HandleSelectOverlayOnLayoutSwap();
608     void FireOnReady();
609     void MoveCaretOnLayoutSwap();
610 
611     void UpdateEditingValue(const std::shared_ptr<TextEditingValue>& value, bool needFireChangeEvent = true) override;
612     void PerformAction(TextInputAction action, bool forceCloseKeyboard = true) override;
613     bool IsIMEOperation(OperationType operationType);
614     void InsertValue(const std::string& insertValue, bool isIME = false) override;
615     void InsertValue(const std::u16string& insertValue, bool isIME = false) override;
616     void InsertValueByOperationType(const std::u16string& insertValue,
617         OperationType operationType = OperationType::DEFAULT);
618     void DeleteSelectionOrPreviewText(OperationRecord* const record, UndoRedoRecord& styledRecord,
619         bool shouldCommitInput);
620     void InsertValueOperation(const std::u16string& insertValue, OperationRecord* const record = nullptr,
621         OperationType operationType = OperationType::IME, bool shouldCommitInput = false);
622     void DeleteByRange(OperationRecord* const record, int32_t start, int32_t end);
623     void InsertDiffStyleValueInSpan(RefPtr<SpanNode>& spanNode, const TextInsertValueInfo& info,
624         const std::u16string& insertValue);
625     void InsertValueByPaste(const std::u16string& insertValue);
626     bool IsLineSeparatorInLast(RefPtr<SpanNode>& spanNode);
627     void InsertValueToSpanNode(
628         RefPtr<SpanNode>& spanNode, const std::u16string& insertValue, const TextInsertValueInfo& info);
629     void SpanNodeFission(RefPtr<SpanNode>& spanNode, bool needLeadingMargin = false);
630     void CreateTextSpanNode(RefPtr<SpanNode>& spanNode, const TextInsertValueInfo& info,
631         const std::u16string& insertValue);
632     void SetDefaultColor(RefPtr<SpanNode>& spanNode);
633     void HandleOnDelete(bool backward) override;
634     std::pair<bool, bool> IsEmojiOnCaretPosition(int32_t& emojiLength, bool isBackward, int32_t length);
635     int32_t CalculateDeleteLength(int32_t length, bool isBackward);
636     void DeleteBackward(int32_t length = 1) override;
637     void DeleteBackward(int32_t length, TextChangeReason reason, bool isByIME = false);
638 #ifndef ACE_UNITTEST
639     void DeleteSpans(const RangeOptions& options, TextChangeReason reason);
640     void AddPlaceholderSpan(const BuilderSpanOptions& options, bool restoreBuilderSpan, TextChangeReason reason);
641     int32_t AddImageSpan(const ImageSpanOptions& options, TextChangeReason reason, bool isPaste = false,
642         int32_t index = -1, bool updateCaret = true);
643     int32_t AddTextSpan(TextSpanOptions options, TextChangeReason reason, bool isPaste = false, int32_t index = -1);
644     int32_t AddSymbolSpan(SymbolSpanOptions options, TextChangeReason reason, bool isPaste = false, int32_t index = -1);
645     int32_t AddPlaceholderSpan(const RefPtr<UINode>& customNode, const SpanOptionBase& options,
646         TextChangeReason reason);
647 #else
648     void DeleteSpans(const RangeOptions& options, TextChangeReason reason = TextChangeReason::UNKNOWN);
649     void AddPlaceholderSpan(const BuilderSpanOptions& options, bool restoreBuilderSpan,
650         TextChangeReason reason = TextChangeReason::UNKNOWN);
651     int32_t AddImageSpan(const ImageSpanOptions& options, TextChangeReason reason = TextChangeReason::UNKNOWN,
652         bool isPaste = false, int32_t index = -1, bool updateCaret = true);
653     int32_t AddTextSpan(TextSpanOptions options, TextChangeReason reason = TextChangeReason::UNKNOWN,
654         bool isPaste = false, int32_t index = -1);
655     int32_t AddSymbolSpan(SymbolSpanOptions options, TextChangeReason reason = TextChangeReason::UNKNOWN,
656         bool isPaste = false, int32_t index = -1);
657     int32_t AddPlaceholderSpan(const RefPtr<UINode>& customNode, const SpanOptionBase& options,
658         TextChangeReason reason = TextChangeReason::UNKNOWN);
659 #endif
660     std::u16string DeleteBackwardOperation(int32_t length);
661     void DeleteForward(int32_t length = 1) override;
662     void DeleteForward(int32_t length, TextChangeReason reason, bool isByIME = false);
663     std::u16string DeleteForwardOperation(int32_t length, bool isIME = true);
664     void SetInputMethodStatus(bool keyboardShown) override;
665     bool ClickAISpan(const PointF& textOffset, const AISpan& aiSpan) override;
666     RefPtr<FrameNode> CreateAIEntityMenu() override;
667     std::function<void(const RectF& firstHandle, const RectF& secondHandle)> GetAISelectTextFunc();
668     void AdjustAIEntityRect(RectF& aiRect) override;
669     WindowMode GetWindowMode();
670     bool GetIsMidScene();
NotifyKeyboardClosedByUser()671     void NotifyKeyboardClosedByUser() override
672     {
673         TAG_LOGI(AceLogTag::ACE_RICH_TEXT, "KeyboardClosedByUser");
674         FocusHub::LostFocusToViewRoot();
675     }
NotifyKeyboardClosed()676     void NotifyKeyboardClosed() override
677     {
678         TAG_LOGI(AceLogTag::ACE_RICH_TEXT, "KeyboardClosed");
679         lastCaretPos_.reset();
680         CHECK_NULL_VOID(HasFocus());
681         CHECK_NULL_VOID(!customKeyboardBuilder_ || !isCustomKeyboardAttached_);
682 
683         // lost focus in floating window mode
684         auto windowMode = GetWindowMode();
685         TAG_LOGD(AceLogTag::ACE_RICH_TEXT, "KeyboardClosed windowMode = %{public}d", windowMode);
686         if (windowMode == WindowMode::WINDOW_MODE_FLOATING || windowMode == WindowMode::WINDOW_MODE_SPLIT_PRIMARY ||
687             windowMode == WindowMode::WINDOW_MODE_SPLIT_SECONDARY) {
688             FocusHub::LostFocusToViewRoot();
689         }
690     }
691     void ClearOperationRecords();
692     void ClearRedoOperationRecords();
693     void AddInsertOperationRecord(OperationRecord& record);
694     void AddOperationRecord(const OperationRecord& record);
695     void UpdateShiftFlag(const KeyEvent& keyEvent)override;
696     bool HandleOnEscape() override;
697     void HandleOnUndoAction() override;
698 
HandleOnExtendUndoAction()699     void HandleOnExtendUndoAction() override
700     {
701         HandleOnUndoAction();
702     }
703 
704     void HandleOnRedoAction() override;
705     void CursorMove(CaretMoveIntent direction) override;
706     void HandleSetSelection(int32_t start, int32_t end, bool showHandle) override;
707     void HandleExtendAction(int32_t action) override;
708     bool BeforeStatusCursorMove(bool isLeft);
709     bool CursorMoveLeft();
710     bool CursorMoveRight();
711     bool CursorMoveUp();
712     bool CursorMoveDown();
713     void CursorMoveToNextWord(CaretMoveIntent direction);
714     int32_t GetLeftWordIndex(int32_t index);
715     int32_t GetRightWordIndex(int32_t index);
716     bool CursorMoveToParagraphBegin();
717     bool CursorMoveToParagraphEnd();
718     bool CursorMoveHome();
719     bool CursorMoveEnd();
720     void CalcLineSidesIndexByPosition(int32_t& startIndex, int32_t& endIndex);
721     RectF CalcLineInfoByPosition();
722     CaretOffsetInfo GetCaretOffsetInfoByPosition(int32_t position = -1);
723     int32_t CalcMoveUpPos(float& leadingMarginOffset);
724     int32_t CalcMoveDownPos(float& leadingMarginOffset);
725     int32_t CalcLineBeginPosition();
726     float GetTextThemeFontSize();
727     int32_t CalcLineEndPosition(int32_t index = -1);
728     int32_t CalcSingleLineBeginPosition(int32_t fixedPos);
729     int32_t CalcSingleLineEndPosition(int32_t fixedPos);
730     bool CursorMoveLineBegin();
731     bool CursorMoveLineEnd();
732     void HandleSelectFontStyle(KeyCode code) override;
733     void HandleSelectFontStyleWrapper(KeyCode code, TextStyle& spanStyle);
734     void HandleOnShowMenu() override;
735     int32_t HandleKbVerticalSelection(bool isUp);
736     PositionType GetPositionTypeFromLine();
737     int32_t HandleSelectWrapper(CaretMoveIntent direction, int32_t fixedPos);
738     void AIDeleteComb(int32_t start, int32_t end, int32_t& aiPosition, bool direction);
739     bool HandleOnDeleteComb(bool backward) override;
740     void DeleteBackwardWord();
741     void DeleteForwardWord();
742     int32_t GetLeftWordPosition(int32_t caretPosition);
743     int32_t GetRightWordPosition(int32_t caretPosition);
744     int32_t GetParagraphBeginPosition(int32_t caretPosition);
745     int32_t GetParagraphEndPosition(int32_t caretPosition);
746     int32_t CaretPositionSelectEmoji(CaretMoveIntent direction);
747     void HandleSelect(CaretMoveIntent direction) override;
748 
HandleSelectExtend(CaretMoveIntent direction)749     void HandleSelectExtend(CaretMoveIntent direction) override
750     {
751         HandleSelect(direction);
752     }
753 
754     void SetCaretPositionWithAffinity(PositionWithAffinity positionWithAffinity);
755     bool SetCaretPosition(int32_t pos, bool needNotifyImf = true);
756     int32_t GetCaretPosition();
757     int32_t GetTextContentLength() override;
758     bool GetCaretVisible() const;
759     OffsetF CalcCursorOffsetByPosition(int32_t position, float& selectLineHeight,
760         bool downStreamFirst = false, bool needLineHighest = true);
761     void HandleCurrentPositionParagraphInfo(float& lastLineTop, float& paragraphSpacing);
762     bool IsCustomSpanInCaretPos(int32_t position, bool downStreamFirst);
763     void CopyTextSpanStyle(RefPtr<SpanNode>& source, RefPtr<SpanNode>& target, bool needLeadingMargin = false);
764     void CopyTextSpanFontStyle(RefPtr<SpanNode>& source, RefPtr<SpanNode>& target);
765     void CopyTextSpanLineStyle(RefPtr<SpanNode>& source, RefPtr<SpanNode>& target, bool needLeadingMargin = false);
766     void CopyTextSpanUrlStyle(RefPtr<SpanNode>& source, RefPtr<SpanNode>& target);
767     void CopyGestureOption(const RefPtr<SpanNode>& source, RefPtr<SpanNode>& target);
768     int32_t TextSpanSplit(int32_t position, bool needLeadingMargin = false);
769     SpanPositionInfo GetSpanPositionInfo(int32_t position);
770     std::function<ImageSourceInfo()> CreateImageSourceInfo(const ImageSpanOptions& options);
771     void DeleteSpansOperation(int32_t start, int32_t end);
772     void DeleteSpanByRange(int32_t start, int32_t end, SpanPositionInfo info);
773     void DeleteSpansByRange(int32_t start, int32_t end, SpanPositionInfo startInfo, SpanPositionInfo endInfo);
774     void ClearContent(const RefPtr<UINode>& child);
775     void CloseSelectionMenu();
776     bool SetCaretOffset(int32_t caretPosition) override;
777     bool DoDeleteActions(int32_t currentPosition, int32_t length, RichEditorDeleteValue& info, bool isIME = true);
778 
779     void UpdateSpanStyle(int32_t start, int32_t end, const TextStyle& textStyle, const ImageSpanAttribute& imageStyle,
780         bool isExternal = true);
781     void GetContentBySpans(std::u16string& u16Str);
782     void SetSelectSpanStyle(int32_t start, int32_t end, KeyCode code, bool isStart);
783     void GetSelectSpansPositionInfo(
784         int32_t& start, int32_t& end, SpanPositionInfo& startPositionSpanInfo, SpanPositionInfo& endPositionSpanInfo);
785     std::list<RefPtr<UINode>>::const_iterator GetSpanNodeIter(int32_t index);
786     RefPtr<SpanItem> GetSpanItemByIndex(int32_t index);
787     std::list<SpanPosition> GetSelectSpanSplit(
788         SpanPositionInfo& startPositionSpanInfo, SpanPositionInfo& endPositionSpanInfo);
789     std::list<SpanPosition> GetSelectSpanInfo(int32_t start, int32_t end);
790     SelectionInfo GetSpansInfoByRange(int32_t start, int32_t end);
791     void UpdateSelectSpanStyle(int32_t start, int32_t end, KeyCode code);
792     bool CheckStyledStringRangeValid(int32_t start, int32_t length);
793     void UpdateSelectStyledStringStyle(int32_t start, int32_t end, KeyCode code);
794     template<typename T>
795     void UpdateSpansStyleInRange(int32_t start, int32_t end, const RefPtr<SpanBase>& baseSpan,
796         std::function<RefPtr<T>(const RefPtr<T>&)>&& updateSpanFunc);
797     void UpdateStyledStringFontStyle(int32_t start, int32_t end, const Font& font);
798     void UpdateStyledStringDecorationType(int32_t start, int32_t end, const TextDecoration& type);
799     bool SymbolSpanUpdateStyle(RefPtr<SpanNode>& spanNode, struct UpdateSpanStyle updateSpanStyle, TextStyle textStyle);
800     void SetUpdateSpanStyle(struct UpdateSpanStyle updateSpanStyle);
801     struct UpdateSpanStyle GetUpdateSpanStyle();
802     void UpdateParagraphStyle(int32_t start, int32_t end, const struct UpdateParagraphStyle& style);
803     void UpdateParagraphStyle(RefPtr<SpanNode> spanNode, const struct UpdateParagraphStyle& style);
804     std::vector<ParagraphInfo> GetParagraphInfo(int32_t start, int32_t end);
805     void SetTypingStyle(std::optional<struct UpdateSpanStyle> typingStyle, std::optional<TextStyle> textStyle);
806     void SetTypingParagraphStyle(std::optional<struct UpdateParagraphStyle> typingParagraphStyle);
807     std::optional<struct UpdateSpanStyle> GetTypingStyle();
808     int32_t AddImageSpanFromCollaboration(const ImageSpanOptions& options, bool updateCaret);
809     int32_t AddTextSpanOperation(const TextSpanOptions& options, bool isPaste = false, int32_t index = -1,
810         bool needLeadingMargin = false, bool updateCaretPosition = true);
811     void AdjustAddPosition(TextSpanOptions& options);
812     int32_t AddSymbolSpanOperation(const SymbolSpanOptions& options, bool isPaste = false, int32_t index = -1);
813     void AddSpanItem(const RefPtr<SpanItem>& item, int32_t offset);
814     void AddOnPlaceholderHoverEvent(const RefPtr<PlaceholderSpanNode>& placeholderSpanNode);
815     void OnPlaceholderHover(bool isHover);
816     void SetSelection(int32_t start, int32_t end, const std::optional<SelectionOptions>& options = std::nullopt,
817         bool isForward = false) override;
818     bool ResetOnInvalidSelection(int32_t start, int32_t end);
819     bool IsShowHandle() override;
820     void UpdateSelectionInfo(int32_t start, int32_t end);
821     bool IsEditing();
822     std::u16string GetLeftTextOfCursor(int32_t number) override;
823     std::u16string GetRightTextOfCursor(int32_t number) override;
824     int32_t GetTextIndexAtCursor() override;
825     void ProcessOverlay(const OverlayRequest& request = OverlayRequest()) override;
826     void ShowSelectOverlay(const RectF& firstHandle, const RectF& secondHandle, bool isCopyAll = false,
827         TextResponseType responseType = TextResponseType::LONG_PRESS, bool handlReverse = false);
828     void CheckEditorTypeChange();
829     int32_t GetHandleIndex(const Offset& offset) const override;
830     void OnAreaChangedInner() override;
831     void UpdateParentOffsetAndOverlay();
832     void CloseAIMenu();
833     void CreateHandles() override;
834     void ShowHandles(const bool isNeedShowHandles) override;
835     void ShowHandles() override;
836     void HandleMenuCallbackOnSelectAll(bool isShowMenu = true);
837     void HandleOnSelectAll() override;
838     void OnCopyOperation(bool isUsingExternalKeyboard = false);
839     void HandleOnCopy(bool isUsingExternalKeyboard = false) override;
840     void HandleOnShare();
841     void HandleAIMenuOption(const std::string& labelInfo = "") override;
842     void UpdateAIMenuOptions() override;
843     void HandleDraggableFlag(bool isTouchSelectArea);
844     void SetIsTextDraggable(bool isTextDraggable = true) override;
845     bool JudgeContentDraggable();
846     std::pair<OffsetF, float> CalculateCaretOffsetAndHeight();
847     OffsetF CalculateEmptyValueCaretOffset();
848     void UpdateModifierCaretOffsetAndHeight();
849     void NotifyCaretChange();
850     TextAlign GetTextAlignByDirection();
851     void RemoveEmptySpan(std::set<int32_t, std::greater<int32_t>>& deleteSpanIndexs);
852     void RemoveEmptySpanItems();
853     void RemoveEmptySpanNodes();
854     void RemoveEmptySpans();
855     RefPtr<GestureEventHub> GetGestureEventHub();
856     void OnWindowHide() override;
857     bool BeforeAddImage(RichEditorChangeValue& changeValue, const ImageSpanOptions& options, int32_t insertIndex);
858     bool BeforeSpansChange(const UndoRedoRecord& record, bool isUndo);
859     void AfterSpansChange(const UndoRedoRecord& record, bool isUndo);
860     RefPtr<SpanString> ToStyledString(int32_t start, int32_t end);
861     SelectionInfo FromStyledString(const RefPtr<SpanString>& spanString);
862     bool BeforeAddSymbol(RichEditorChangeValue& changeValue, const SymbolSpanOptions& options);
863     void AfterContentChange(RichEditorChangeValue& changeValue);
864     void ReportAfterContentChangeEvent();
865     void DeleteToMaxLength(std::optional<int32_t> length);
866     void DeleteContent(int32_t length);
867 
ResetIsMousePressed()868     void ResetIsMousePressed()
869     {
870         isMousePressed_ = false;
871     }
872 
GetSelectionMenuOffset()873     OffsetF GetSelectionMenuOffset() const
874     {
875         return selectionMenuOffsetByMouse_;
876     }
877 
SetLastClickOffset(const OffsetF & lastClickOffset)878     void SetLastClickOffset(const OffsetF& lastClickOffset)
879     {
880         lastClickOffset_ = lastClickOffset;
881     }
882 
ResetLastClickOffset()883     void ResetLastClickOffset()
884     {
885         lastClickOffset_.SetX(-1);
886         lastClickOffset_.SetY(-1);
887     }
888 
GetCaretSpanIndex()889     int32_t GetCaretSpanIndex()
890     {
891         return caretSpanIndex_;
892     }
893 
GetParagraphs()894     std::vector<ParagraphManager::ParagraphInfo> GetParagraphs() const override
895     {
896         return paragraphs_.GetParagraphs();
897     }
898 
GetFirstHandleInfo()899     std::optional<SelectHandleInfo> GetFirstHandleInfo() const
900     {
901         return selectOverlay_->GetFirstHandleInfo();
902     }
903 
GetSecondHandleInfo()904     std::optional<SelectHandleInfo> GetSecondHandleInfo() const
905     {
906         return selectOverlay_->GetSecondHandleInfo();
907     }
908 
909     RectF GetCaretRect() const override;
910     void OnDragNodeFloating() override;
911     void CloseSelectOverlay() override;
912     void CloseHandleAndSelect() override;
913     void CalculateHandleOffsetAndShowOverlay(bool isUsingMouse = false) override;
914     void CalculateDefaultHandleHeight(float& height) override;
915     bool IsSingleHandle();
916     bool IsHandlesShow() override;
917     void CopySelectionMenuParams(SelectOverlayInfo& selectInfo, TextResponseType responseType);
918     std::function<void(Offset)> GetThumbnailCallback() override;
919     void InitAiSelection(const Offset& globalOffset, bool isBetweenSelection = false);
920     bool CheckAIPreviewMenuEnable() override;
921     void CreateDragNode();
922     float GetMaxSelectedWidth();
923     void InitDragShadow(const RefPtr<FrameNode>& host, const RefPtr<FrameNode>& dragNode, bool isDragShadowNeeded,
924         bool hasDragBackgroundColor);
925     void HandleOnDragStatusCallback(
926         const DragEventType& dragEventType, const RefPtr<NotifyDragEvent>& notifyDragEvent) override;
927     void ResetSelection();
928     bool BetweenSelection(const Offset& globalOffset);
929     bool InRangeRect(const Offset& globalOffset, const std::pair<int32_t, int32_t>& range);
930     bool BetweenSelectedPosition(const Offset& globalOffset) override;
931     void HandleSurfaceChanged(int32_t newWidth, int32_t newHeight, int32_t prevWidth, int32_t prevHeight,
932         WindowSizeChangeReason type) override;
933     void HandleSurfacePositionChanged(int32_t posX, int32_t posY) override;
934     bool RequestCustomKeyboard();
935     bool CloseCustomKeyboard();
936     void UpdateUrlStyle(RefPtr<SpanNode>& spanNode, const std::optional<std::u16string>& urlAddressOpt);
GetPasteStr()937     const std::u16string& GetPasteStr() const
938     {
939         return pasteStr_;
940     }
AddPasteStr(const std::string & addedStr)941     void AddPasteStr(const std::string& addedStr)
942     {
943         pasteStr_.append(UtfUtils::Str8ToStr16(addedStr));
944     }
ClearPasteStr()945     void ClearPasteStr()
946     {
947         pasteStr_.clear();
948     }
SetCustomKeyboard(const std::function<void ()> && keyboardBuilder)949     void SetCustomKeyboard(const std::function<void()>&& keyboardBuilder)
950     {
951         if (customKeyboardBuilder_ && isCustomKeyboardAttached_ && !keyboardBuilder) {
952             // close customKeyboard and request system keyboard
953             CloseCustomKeyboard();
954             customKeyboardBuilder_ = keyboardBuilder; // refresh current keyboard
955             RequestKeyboard(false, true, true);
956             return;
957         }
958         if (!customKeyboardBuilder_ && keyboardBuilder) {
959             // close system keyboard and request custom keyboard
960 #if defined(OHOS_STANDARD_SYSTEM) && !defined(PREVIEW)
961             if (isEditing_) {
962                 CloseKeyboard(true);
963                 customKeyboardBuilder_ = keyboardBuilder; // refresh current keyboard
964                 RequestKeyboard(false, true, true);
965                 return;
966             }
967 #endif
968         }
969         customKeyboardBuilder_ = keyboardBuilder;
970     }
971     void BindSelectionMenu(TextResponseType type, TextSpanType richEditorType, std::function<void()>& menuBuilder,
972         const SelectMenuParam& menuParam);
ClearSelectionMenu()973     void ClearSelectionMenu()
974     {
975         selectionMenuMap_.clear();
976     }
977     void DumpInfo() override;
978     void DumpInfo(std::unique_ptr<JsonValue>& json) override;
DumpSimplifyInfo(std::shared_ptr<JsonValue> & json)979     void DumpSimplifyInfo(std::shared_ptr<JsonValue>& json) override {}
980     void RichEditorErrorReport(RichEditorInfo& info);
981     void MouseDoubleClickParagraphEnd(int32_t& index);
982     void AdjustSelectionExcludeSymbol(int32_t& start, int32_t& end);
983     void InitSelection(const Offset& pos);
984     bool HasFocus() const;
985     void OnColorConfigurationUpdate() override;
986     bool OnThemeScopeUpdate(int32_t themeScopeId) override;
987     void OnCommonColorChange();
988     bool IsDisabled() const;
989     float GetLineHeight() const override;
990     size_t GetLineCount() const override;
991     std::vector<ParagraphManager::TextBox> GetRectsForRange(int32_t start, int32_t end,
992         RectHeightStyle heightStyle, RectWidthStyle widthStyle) override;
993     TextLineMetrics GetLineMetrics(int32_t lineNumber) override;
994     float GetLetterSpacing() const;
995     std::vector<RectF> GetTextBoxes() override;
996     bool OnBackPressed() override;
997 
998     RectF GetCaretRelativeRect();
999     // Add for Scroll
1000 
1001     void OnAttachToFrameNode() override;
1002 
1003     void OnDetachFromFrameNode(FrameNode* node) override;
1004 
1005     bool IsAtBottom(bool considerRepeat = false) const override
1006     {
1007         return true;
1008     }
1009 
IsAtTop()1010     bool IsAtTop() const override
1011     {
1012         return true;
1013     }
1014 
UpdateCurrentOffset(float offset,int32_t source)1015     bool UpdateCurrentOffset(float offset, int32_t source) override
1016     {
1017         return true;
1018     }
1019 
GetTextRect()1020     const RectF& GetTextRect() const override
1021     {
1022         return richTextRect_;
1023     }
1024 
GetScrollOffset()1025     float GetScrollOffset() const
1026     {
1027         return scrollOffset_;
1028     }
1029 
GetScrollControllerBar()1030     RefPtr<ScrollBar> GetScrollControllerBar()
1031     {
1032         return GetScrollBar();
1033     }
1034 
1035     bool OnScrollCallback(float offset, int32_t source) override;
1036     void OnScrollEndCallback() override;
IsScrollable()1037     bool IsScrollable() const override
1038     {
1039         return scrollable_;
1040     }
1041 
IsAtomicNode()1042     bool IsAtomicNode() const override
1043     {
1044         return true;
1045     }
1046 
1047     bool IsShowSelectMenuUsingMouse();
1048 
IsShowPlaceholder()1049     bool IsShowPlaceholder() const
1050     {
1051         return isShowPlaceholder_;
1052     }
1053 
1054     bool IsSelectAreaVisible();
1055 
1056     bool SetPlaceholder(std::vector<std::list<RefPtr<SpanItem>>>& spanItemList);
1057 
1058     std::string GetPlaceHolder() const;
1059 
1060     void HandleOnCameraInput() override;
1061     void HandleOnAIWrite();
1062     void GetAIWriteInfo(AIWriteInfo& info);
1063     void HandleAIWriteResult(int32_t start, int32_t end, std::vector<uint8_t>& buffer);
1064     void InsertSpanByBackData(RefPtr<SpanString>& spanString);
1065     void AddSpansAndReplacePlaceholder(RefPtr<SpanString>& spanString);
1066     void ReplacePlaceholderWithRawSpans(const RefPtr<SpanItem>& spanItem, size_t& index, size_t& textIndex);
1067     void SetSubSpansWithAIWrite(RefPtr<SpanString>& spanString, int32_t start, int32_t end);
1068     struct UpdateParagraphStyle GetParagraphStyle(const RefPtr<SpanItem>& spanItem);
1069     TextSpanOptions GetTextSpanOptions(const RefPtr<SpanItem>& spanItem);
1070     SymbolSpanOptions GetSymbolSpanOptions(const RefPtr<SpanItem>& spanItem);
1071     bool IsShowTranslate();
1072     bool IsShowSearch();
1073     bool IsShowAIWrite();
1074     RefPtr<FocusHub> GetFocusHub() const;
1075     void ResetDragOption() override;
1076     bool NeedShowAIDetect() override;
1077 
GetEditorType()1078     TextSpanType GetEditorType() const
1079     {
1080         return selectedType_.value_or(TextSpanType::NONE);
1081     }
1082     void GetCaretMetrics(CaretMetricsF& caretCaretMetric) override;
1083 
SetShowSelect(bool isShowSelect)1084     void SetShowSelect(bool isShowSelect)
1085     {
1086         showSelect_ = isShowSelect;
1087     }
1088 
1089     const std::list<RefPtr<UINode>>& GetAllChildren() const override;
1090 
1091     void OnVirtualKeyboardAreaChanged() override;
1092 
SetCaretColor(const Color & caretColor)1093     void SetCaretColor(const Color& caretColor)
1094     {
1095         TAG_LOGI(AceLogTag::ACE_RICH_TEXT, "setCaretColor=%{public}s", caretColor.ToString().c_str());
1096         caretColor_ = caretColor;
1097         IF_TRUE(SelectOverlayIsOn(), selectOverlay_->UpdateHandleColor());
1098     }
1099 
1100     Color GetCaretColor() const;
1101 
SetSelectedBackgroundColor(const Color & selectedBackgroundColor)1102     void SetSelectedBackgroundColor(const Color& selectedBackgroundColor)
1103     {
1104         TAG_LOGI(AceLogTag::ACE_RICH_TEXT, "SetSelectedBackgroundColor=%{public}s",
1105             selectedBackgroundColor.ToString().c_str());
1106         selectedBackgroundColor_ = selectedBackgroundColor;
1107     }
1108 
1109     Color GetSelectedBackgroundColor() const;
1110 
1111     void SetCustomKeyboardOption(bool supportAvoidance);
1112     void StopEditing();
1113     void ResetKeyboardIfNeed();
1114 
HandleOnEnter()1115     void HandleOnEnter() override
1116     {
1117         PerformAction(GetTextInputActionValue(GetDefaultTextInputAction()), false);
1118     }
1119 
GetClipboard()1120     RefPtr<Clipboard> GetClipboard() override
1121     {
1122         return clipboard_;
1123     }
1124 
GetCaretIndex()1125     int32_t GetCaretIndex() const override
1126     {
1127         return caretPosition_;
1128     }
1129 
GetContentWideTextLength()1130     int32_t GetContentWideTextLength() override
1131     {
1132         return GetTextContentLength();
1133     }
1134 
GetParentGlobalOffset()1135     OffsetF GetParentGlobalOffset() const override
1136     {
1137         return parentGlobalOffset_;
1138     }
1139 
GetFirstHandleOffset()1140     OffsetF GetFirstHandleOffset() const override
1141     {
1142         return textSelector_.firstHandle.GetOffset();
1143     }
1144 
GetSecondHandleOffset()1145     OffsetF GetSecondHandleOffset() const override
1146     {
1147         return textSelector_.secondHandle.GetOffset();
1148     }
1149 
1150     OffsetF GetTextPaintOffset() const override;
1151     OffsetF GetPaintRectGlobalOffset() const;
1152     // original local point to transformed global point.
1153     void HandlePointWithTransform(OffsetF& point);
1154 
1155     float GetCrossOverHeight() const;
1156 
CreateAccessibilityProperty()1157     RefPtr<AccessibilityProperty> CreateAccessibilityProperty() override
1158     {
1159         return MakeRefPtr<RichEditorAccessibilityProperty>();
1160     }
1161 
1162     void AdjustSelector(int32_t& index, HandleType handleType,
1163         SelectorAdjustPolicy policy = SelectorAdjustPolicy::INCLUDE);
1164     void AdjustSelector(int32_t& start, int32_t& end, SelectorAdjustPolicy policy = SelectorAdjustPolicy::INCLUDE);
1165     bool AdjustSelectorForSymbol(int32_t& index, HandleType handleType, SelectorAdjustPolicy policy);
1166     bool AdjustSelectorForEmoji(int32_t& index, HandleType handleType, SelectorAdjustPolicy policy);
1167     EmojiRelation GetEmojiRelation(int index);
1168     void UpdateSelector(int32_t start, int32_t end);
1169     void UpdateSelectionType(const SelectionInfo& textSelectInfo);
1170     std::list<RefPtr<SpanItem>>::iterator GetSpanIter(int32_t index);
1171     SpanItemType GetSpanType(int32_t index);
1172 
DumpAdvanceInfo()1173     void DumpAdvanceInfo() override {}
DumpAdvanceInfo(std::unique_ptr<JsonValue> & json)1174     void DumpAdvanceInfo(std::unique_ptr<JsonValue>& json) override  {}
1175 
SetContentChange(bool onChange)1176     void SetContentChange(bool onChange)
1177     {
1178         contentChange_ = onChange;
1179     }
1180 
1181     void HideMenu();
1182     PositionWithAffinity GetGlyphPositionAtCoordinate(int32_t x, int32_t y) override;
1183     void OnSelectionMenuOptionsUpdate(const NG::OnCreateMenuCallback&& onCreateMenuCallback,
1184         const NG::OnMenuItemClickCallback&& onMenuItemClick, const NG::OnPrepareMenuCallback&& onPrepareMenuCallback);
1185     RectF GetTextContentRect(bool isActualText = false) const override
1186     {
1187         return contentRect_;
1188     }
1189 
OnFrameNodeChanged(FrameNodeChangeInfoFlag flag)1190     void OnFrameNodeChanged(FrameNodeChangeInfoFlag flag) override
1191     {
1192         selectOverlay_->OnAncestorNodeChanged(flag);
1193     }
1194 
1195     bool IsResponseRegionExpandingNeededForStylus(const TouchEvent& touchEvent) const override;
1196 
1197     RectF ExpandDefaultResponseRegion(RectF& rect) override;
ConsumeChildrenAdjustment(const OffsetF &)1198     bool ConsumeChildrenAdjustment(const OffsetF& /* offset */) override
1199     {
1200         return true;
1201     }
1202 
1203     TextStyle GetDefaultTextStyle();
SetEnableHapticFeedback(bool isEnabled)1204     void SetEnableHapticFeedback(bool isEnabled)
1205     {
1206         TAG_LOGI(AceLogTag::ACE_RICH_TEXT, "setEnableHapticFeedback=%{public}d", isEnabled);
1207         isEnableHapticFeedback_ = isEnabled;
1208     }
1209 
1210     bool InsertOrDeleteSpace(int32_t index) override;
1211 
1212     void DeleteRange(int32_t start, int32_t end, bool isIME = true) override;
1213     void DeleteRange(int32_t start, int32_t end, bool isIME, TextChangeReason reason);
1214     void HandleOnPageUp() override;
1215     void HandleOnPageDown() override;
1216     void HandlePageScroll(bool isPageUp);
1217 
SetRequestKeyboardOnFocus(bool needToRequest)1218     void SetRequestKeyboardOnFocus(bool needToRequest)
1219     {
1220         TAG_LOGI(AceLogTag::ACE_RICH_TEXT, "SetRequestKeyboardOnFocus=%{public}d", needToRequest);
1221         needToRequestKeyboardOnFocus_ = needToRequest;
1222     }
1223 
1224     bool IsTextEditableForStylus() const override;
1225 
1226     NG::DragDropInfo HandleDragStart(const RefPtr<Ace::DragEvent>& event, const std::string& extraParams);
1227 
1228     void SetPreviewMenuParam(TextSpanType spanType, std::function<void()>& builder, const SelectMenuParam& menuParam);
1229 
RequestFocusWhenSelected()1230     void RequestFocusWhenSelected()
1231     {
1232         CHECK_NULL_VOID(!HasFocus());
1233         CHECK_NULL_VOID(IsSelected());
1234         auto focusHub = GetFocusHub();
1235         CHECK_NULL_VOID(focusHub);
1236         isOnlyRequestFocus_ = true;
1237         IF_TRUE(!focusHub->RequestFocusImmediately(), isOnlyRequestFocus_ = false);
1238     }
1239 
GetBarDisplayMode()1240     DisplayMode GetBarDisplayMode() const
1241     {
1242         return barDisplayMode_.value_or(DisplayMode::AUTO);
1243     }
1244 
1245     Color GetUrlSpanColor() override;
1246 
1247     void TriggerAvoidOnCaretChange();
1248 
1249     void ForceTriggerAvoidOnCaretChange(bool isMoveContent = false)
1250     {
1251         auto pipeline = GetContext();
1252         CHECK_NULL_VOID(pipeline && pipeline->UsingCaretAvoidMode());
1253         IF_TRUE(isMoveContent, MoveCaretToContentRect());
1254         isTriggerAvoidOnCaretAvoidMode_ = true;
1255     }
1256 
TriggerAvoidOnCaretChangeNextFrame()1257     void TriggerAvoidOnCaretChangeNextFrame()
1258     {
1259         ForceTriggerAvoidOnCaretChange(true);
1260         isTriggerAvoidOnCaretAvoidMode_ = false;
1261         UpdateModifierCaretOffsetAndHeight();
1262         TriggerAvoidOnCaretChange();
1263     }
1264 
ResetTriggerAvoidFlagOnCaretChange()1265     void ResetTriggerAvoidFlagOnCaretChange()
1266     {
1267         isTriggerAvoidOnCaretAvoidMode_ = false;
1268     }
1269 
1270     void OnWindowSizeChanged(int32_t width, int32_t height, WindowSizeChangeReason type) override;
1271 
IsTriggerAvoidOnCaretAvoidMode()1272     bool IsTriggerAvoidOnCaretAvoidMode()
1273     {
1274         return isTriggerAvoidOnCaretAvoidMode_;
1275     }
1276 
SetAvoidFlagOnCaretAvoidMode(bool isTriggerAvoidOnCaretAvoidMode)1277     void SetAvoidFlagOnCaretAvoidMode(bool isTriggerAvoidOnCaretAvoidMode)
1278     {
1279         auto pipeline = GetContext();
1280         CHECK_NULL_VOID(pipeline && pipeline->UsingCaretAvoidMode());
1281         isTriggerAvoidOnCaretAvoidMode_ = isTriggerAvoidOnCaretAvoidMode;
1282     }
1283 
ChangeLastRichTextRect()1284     void ChangeLastRichTextRect()
1285     {
1286         lastRichTextRect_ = richTextRect_;
1287     }
1288 
GetLastTextRect()1289     const RectF& GetLastTextRect()
1290     {
1291         return lastRichTextRect_;
1292     }
1293     HoverInfo CreateHoverInfo(const MouseInfo& info);
1294     std::pair<int32_t, int32_t> GetSpanRangeByLocalOffset(Offset localOffset);
SetStopBackPress(bool isStopBackPress)1295     void SetStopBackPress(bool isStopBackPress)
1296     {
1297         isStopBackPress_ = isStopBackPress;
1298     }
1299 
IsStopBackPress()1300     bool IsStopBackPress() const override
1301     {
1302         return isStopBackPress_;
1303     }
1304 
SetKeyboardAppearance(KeyboardAppearance value)1305     void SetKeyboardAppearance(KeyboardAppearance value)
1306     {
1307         TAG_LOGI(AceLogTag::ACE_RICH_TEXT, "SetKeyboardAppearance=%{public}d", value);
1308         keyboardAppearance_ = value;
1309     }
1310 
GetKeyboardAppearance()1311     KeyboardAppearance GetKeyboardAppearance() const
1312     {
1313         return keyboardAppearance_;
1314     }
1315 
SetSupportStyledUndo(bool enabled)1316     void SetSupportStyledUndo(bool enabled)
1317     {
1318         TAG_LOGI(AceLogTag::ACE_RICH_TEXT, "SupportStyledUndo:%{public}d->%{public}d", isStyledUndoSupported_, enabled);
1319         CHECK_NULL_VOID(!isSpanStringMode_ && (isStyledUndoSupported_ != enabled));
1320         ClearOperationRecords();
1321         isStyledUndoSupported_ = enabled;
1322     }
1323 
IsSupportStyledUndo()1324     bool IsSupportStyledUndo() const
1325     {
1326         return isSpanStringMode_ || isStyledUndoSupported_;
1327     }
1328 
IsDragging()1329     bool IsDragging() const override
1330     {
1331         return status_ == Status::DRAGGING || status_ == Status::FLOATING;
1332     }
1333 
GetSpanItemByPosition(int32_t position)1334     const RefPtr<SpanItem> GetSpanItemByPosition(int32_t position)
1335     {
1336         CHECK_NULL_RETURN(position >= 0, nullptr);
1337         auto it = GetSpanIter(position);
1338         CHECK_NULL_RETURN(it != spans_.end(), nullptr);
1339         return *it;
1340     }
1341 
GetColorMode()1342     ColorMode GetColorMode()
1343     {
1344         auto host = GetHost();
1345         CHECK_NULL_RETURN(!host, host->GetLocalColorMode());
1346         auto context = GetContext();
1347         CHECK_NULL_RETURN(context, ColorMode::COLOR_MODE_UNDEFINED);
1348         return context->GetLocalColorMode();
1349     }
1350 
GetDisplayColorMode()1351     ColorMode GetDisplayColorMode()
1352     {
1353         auto colorMode = GetColorMode();
1354         return colorMode == ColorMode::COLOR_MODE_UNDEFINED ? Container::CurrentColorMode() : colorMode;
1355     }
1356 
1357     template<typename T>
GetTheme()1358     RefPtr<T> GetTheme() const
1359     {
1360         auto pipelineContext = GetContext();
1361         CHECK_NULL_RETURN(pipelineContext, {});
1362         if (isAPI20Plus) {
1363             return pipelineContext->GetTheme<T>(GetThemeScopeId());
1364         }
1365         return pipelineContext->GetTheme<T>();
1366     }
1367 
GetAISpanMap()1368     const std::map<int32_t, AISpan>& GetAISpanMap() override
1369     {
1370         return dataDetectorAdapter_->aiSpanMap_;
1371     }
1372 
SetTextDetectEnable(bool enable)1373     void SetTextDetectEnable(bool enable) override
1374     {
1375         auto currentEnable = textDetectEnable_;
1376         TextPattern::SetTextDetectEnable(enable);
1377         CHECK_NULL_VOID(enable && !currentEnable && CanStartAITask());
1378         IF_TRUE(!dataDetectorAdapter_->aiDetectInitialized_, dataDetectorAdapter_->StartAITask());
1379     }
1380     void SetContentPattern(const RefPtr<RichEditorContentPattern>& contentPattern);
1381     RefPtr<FrameNode> GetContentHost() const override;
1382 
1383     float GetCaretWidth();
1384     void UpdateCaretStyleByTypingStyle(bool isReset);
1385     void MarkAISpanStyleChanged() override;
1386     void HandleOnAskCelia() override;
1387 
1388 #if defined(IOS_PLATFORM)
1389     const TextEditingValue& GetInputEditingValue() const override;
1390 #endif
1391 
GetLastCaretPos()1392     std::optional<float> GetLastCaretPos() const
1393     {
1394         return lastCaretPos_;
1395     }
1396 
SetLastCaretPos(float lastCaretPos)1397     void SetLastCaretPos(float lastCaretPos)
1398     {
1399         lastCaretPos_ = lastCaretPos;
1400     }
1401 
IsShortCutBlocked()1402     bool IsShortCutBlocked() override { return IsDragging(); }
1403 
1404 protected:
1405     bool CanStartAITask() const override;
1406     std::vector<RectF> GetSelectedRects(int32_t start, int32_t end) override;
1407     PointF GetTextOffset(const Offset& localLocation, const RectF& contentRect) override;
1408     std::pair<int32_t, int32_t> GetStartAndEnd(int32_t start, const RefPtr<SpanItem>& spanItem) override;
1409 
1410 private:
1411     friend class RichEditorSelectOverlay;
1412     friend class OneStepDragController;
1413     friend class RichEditorUndoManager;
1414     friend class RichEditorContentPattern;
1415     friend class StyleManager;
1416     bool HandleUrlSpanClickEvent(const GestureEvent& info);
1417     void HandleUrlSpanForegroundClear();
1418     bool HandleUrlSpanShowShadow(const Offset& localLocation, const Offset& globalOffset, const Color& color);
1419     Color GetUrlHoverColor();
1420     Color GetUrlPressColor();
1421     RefPtr<RichEditorSelectOverlay> selectOverlay_;
1422     Offset ConvertGlobalToLocalOffset(const Offset& globalOffset);
1423     Offset ConvertGlobalToTextOffset(const Offset& globalOffset);
1424     void UpdateSelectMenuInfo(SelectMenuInfo& selectInfo);
1425     void HandleOnPaste() override;
1426     std::function<void(std::vector<std::vector<uint8_t>>&, const std::string&, bool&)> CreatePasteCallback();
1427     void PasteStr(const std::string& text);
1428     void HandleOnCut() override;
1429     void InitClickEvent(const RefPtr<GestureEventHub>& gestureHub) override;
1430     void InitFocusEvent(const RefPtr<FocusHub>& focusHub);
1431     void HandleBlurEvent();
1432     void HandleFocusEvent(FocusReason focusReason = FocusReason::DEFAULT);
1433     void OnFocusNodeChange(FocusReason focusReason) override;
1434     void HandleClickEvent(GestureEvent& info);
1435     void HandleSingleClickEvent(GestureEvent& info);
1436     bool HandleClickSelection(const OHOS::Ace::GestureEvent& info);
1437     bool IsClickEventOnlyForMenuToggle(const OHOS::Ace::GestureEvent& info);
1438     Offset ConvertTouchOffsetToTextOffset(const Offset& touchOffset);
1439     bool IsShowSingleHandleByClick(const OHOS::Ace::GestureEvent& info, int32_t lastCaretPosition,
1440         const RectF& lastCaretRect, bool isCaretTwinkling);
1441     bool RepeatClickCaret(const Offset& offset, const RectF& lastCaretRect);
1442     void CreateAndShowSingleHandle();
1443     void MoveCaretAndStartFocus(const Offset& offset);
1444     void HandleDoubleClickEvent(GestureEvent& info);
1445     bool HandleUserClickEvent(GestureEvent& info);
1446     bool HandleUserLongPressEvent(GestureEvent& info);
1447     bool HandleUserDoubleClickEvent(GestureEvent& info);
1448     bool HandleUserGestureEvent(
1449         GestureEvent& info, std::function<bool(RefPtr<SpanItem> item, GestureEvent& info)>&& gestureFunc);
1450     void CalcCaretInfoByClick(const Offset& touchOffset);
1451     std::pair<OffsetF, float> CalcAndRecordLastClickCaretInfo(const Offset& textOffset);
1452     void HandleEnabled();
1453     void HandleAISpanHoverEvent(const MouseInfo& info) override;
1454     void InitMouseEvent();
1455     void ScheduleCaretTwinkling();
1456     void OnCaretTwinkling();
1457     void StartTwinkling();
1458     void ShowCaretWithoutTwinkling();
1459     void StopTwinkling();
1460     void UpdateFontFeatureTextStyle(
1461         RefPtr<SpanNode>& spanNode, struct UpdateSpanStyle& updateSpanStyle, TextStyle& textStyle);
1462     void UpdateDecoration(RefPtr<SpanNode>& spanNode, struct UpdateSpanStyle& updateSpanStyle, TextStyle& textStyle);
1463     void UpdateTextStyle(RefPtr<SpanNode>& spanNode, struct UpdateSpanStyle updateSpanStyle, TextStyle textStyle);
1464     void UpdateSymbolStyle(RefPtr<SpanNode>& spanNode, struct UpdateSpanStyle updateSpanStyle, TextStyle textStyle);
1465     void UpdateImageStyle(RefPtr<FrameNode>& imageNode, const ImageSpanAttribute& imageStyle);
1466     void UpdateImageAttribute(RefPtr<FrameNode>& imageNode, const ImageSpanAttribute& imageStyle);
1467     TextStyle CreateTextStyleByTypingStyle();
1468     void InitTouchEvent();
1469     void InitPanEvent();
1470     bool SelectOverlayIsOn();
1471     void HandleLongPress(GestureEvent& info);
1472     void HandleDoubleClickOrLongPress(GestureEvent& info);
1473     void HandleDoubleClickOrLongPress(GestureEvent& info, RefPtr<FrameNode> host);
1474     bool HandleLongPressOnAiSelection();
1475     void StartVibratorByLongPress();
1476     std::string GetPositionSpansText(int32_t position, int32_t& startSpan);
1477     void FireOnSelect(int32_t selectStart, int32_t selectEnd);
1478     void FireOnSelectionChange(const int32_t caretPosition);
1479     void FireOnSelectionChange(const TextSelector& selector);
1480     void FireOnSelectionChange(int32_t selectStart, int32_t selectEnd, bool isForced = false);
1481     void MouseRightFocus(const MouseInfo& info);
1482     bool IsScrollBarPressed(const MouseInfo& info);
1483     void HandleMouseLeftButtonMove(const MouseInfo& info);
1484     void AdjustMouseLocalOffset(Offset& offset);
1485     void HandleMouseSelect(const Offset& localOffset);
1486     void HandleMouseLeftButtonPress(const MouseInfo& info);
1487     void HandleShiftSelect(int32_t position);
1488     void HandleMouseLeftButtonRelease(const MouseInfo& info);
1489     void HandleMouseLeftButton(const MouseInfo& info);
1490     void HandleMouseRightButton(const MouseInfo& info);
1491     void HandleMouseEvent(const MouseInfo& info);
1492     void HandleImageHoverEvent(const MouseInfo& info);
1493     void HandleTouchEvent(TouchEventInfo& info);
1494     void HandleUserTouchEvent(TouchEventInfo& info);
1495     std::optional<TouchLocationInfo> GetAcceptedTouchLocationInfo(const TouchEventInfo& info);
1496     void HandleTouchDown(const TouchLocationInfo& info);
1497     void HandleTouchUp();
1498     void StartFloatingCaretLand();
1499     void ResetTouchAndMoveCaretState(bool needAnimation = true);
1500     void ResetTouchSelectState();
1501     void ScheduleFirstClickResetAfterWindowFocus();
1502     void HandleTouchUpAfterLongPress();
1503     void HandleTouchCancelAfterLongPress();
1504     void HandleTouchMove(const TouchLocationInfo& info);
1505     void OnMoveCaretStart(int32_t fingerId);
1506     void UpdateCaretByTouchMove(const Offset& offset);
1507     void SetCaretTouchMoveOffset(const Offset& localOffset);
1508     RectF GetCaretBoundaryRect();
1509     Offset AdjustLocalOffsetOnMoveEvent(const Offset& originalOffset);
1510     void StartVibratorByIndexChange(int32_t currentIndex, int32_t preIndex);
1511     void InitLongPressEvent(const RefPtr<GestureEventHub>& gestureHub);
1512     void UseHostToUpdateTextFieldManager();
1513     void UpdateTextFieldManager(const Offset& offset, float height);
1514     void ScrollToSafeArea() const override;
1515     void InitDragDropEvent();
1516     void OnDragStartAndEnd();
1517     void onDragDropAndLeave();
1518     void ClearDragDropEvent();
1519     void OnDragMove(const RefPtr<OHOS::Ace::DragEvent>& event);
1520     void OnDragEnd(const RefPtr<Ace::DragEvent>& event);
1521     void ResetDragSpanItems();
1522     void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override;
1523     std::string GetPlaceHolderInJson() const;
1524     std::string GetTextColorInJson(const std::optional<Color>& value) const;
1525     std::string GetCustomKeyboardInJson() const;
1526     void FillPreviewMenuInJson(const std::unique_ptr<JsonValue>& jsonValue) const override;
1527     void ResetSelectionAfterAddSpan(bool isPaste);
1528     RefPtr<UINode> GetChildByIndex(int32_t index) const override;
1529     void SetResultObjectText(ResultObject& resultObject, const RefPtr<SpanItem>& spanItem) override;
1530     SelectionInfo GetAdjustedSelectionInfo(const SelectionInfo& textSelectInfo);
ResetAfterTextChange()1531     void ResetAfterTextChange() override {};
1532     void AddOprationWhenAddImage(int32_t beforeCaretPos);
1533     void UpdateSpanNode(RefPtr<SpanNode> spanNode, const TextSpanOptions& options);
1534     void UpdateTextBackgroundStyle(RefPtr<SpanNode>& spanNode, const std::optional<TextBackgroundStyle>& style);
1535     void InitPlaceholderSpansMap(
1536         RefPtr<SpanItem>& newSpanItem, const RefPtr<SpanItem>& spanItem, size_t& index, size_t& placeholderGains);
1537     void ReplacePlaceholderWithCustomSpan(const RefPtr<SpanItem>& spanItem, size_t& index, size_t& textIndex);
1538     void ReplacePlaceholderWithSymbolSpan(const RefPtr<SpanItem>& spanItem, size_t& index, size_t& textIndex);
1539     void ReplacePlaceholderWithImageSpan(const RefPtr<SpanItem>& spanItem, size_t& index, size_t& textIndex);
1540 
1541     void HandleCursorOnDragMoved(const RefPtr<NotifyDragEvent>& notifyDragEvent);
1542     void HandleCursorOnDragLeaved(const RefPtr<NotifyDragEvent>& notifyDragEvent);
1543     void HandleCursorOnDragEnded(const RefPtr<NotifyDragEvent>& notifyDragEvent);
1544 
1545     int32_t GetParagraphLength(const std::list<RefPtr<UINode>>& spans) const;
1546     // REQUIRES: 0 <= start < end
1547     std::vector<RefPtr<SpanNode>> GetParagraphNodes(int32_t start, int32_t end) const;
1548     std::pair<int32_t, int32_t> CalcSpansRange(const std::vector<RefPtr<SpanNode>>& spanNodes) const;
1549     void OnHover(bool isHover, HoverInfo& hoverInfo);
1550     void ChangeMouseStyle(MouseFormat format, bool freeMouseHoldNode = false);
1551     bool RequestKeyboard(bool isFocusViewChanged, bool needStartTwinkling, bool needShowSoftKeyboard,
1552         SourceType sourceType = SourceType::NONE);
1553     void UpdateCaretInfoToController();
1554 #if defined(ENABLE_STANDARD_INPUT)
1555     bool EnableStandardInput(bool needShowSoftKeyboard, SourceType sourceType = SourceType::NONE);
1556     std::optional<MiscServices::TextConfig> GetMiscTextConfig();
1557     float CalcCursorHeight(float& caretHeight);
1558 #else
1559     bool UnableStandardInput(bool isFocusViewChanged);
1560 #endif
1561 
1562     bool HasConnection() const;
1563     bool CloseKeyboard(bool forceClose) override;
1564     void CalcInsertValueObj(TextInsertValueInfo& info);
1565     void CalcDeleteValueObj(int32_t currentPosition, int32_t length, RichEditorDeleteValue& info);
1566     RefPtr<SpanNode> GetSpanNodeBySpanItem(const RefPtr<SpanItem> spanItem);
1567     int32_t DeleteValueSetBuilderSpan(const RefPtr<SpanItem>& spanItem, RichEditorAbstractSpanResult& spanResult);
1568     int32_t DeleteValueSetImageSpan(const RefPtr<SpanItem>& spanItem, RichEditorAbstractSpanResult& spanResult);
1569     int32_t DeleteValueSetSymbolSpan(const RefPtr<SpanItem>& spanItem, RichEditorAbstractSpanResult& spanResult);
1570     int32_t DeleteValueSetTextSpan(const RefPtr<SpanItem>& spanItem, int32_t currentPosition, int32_t length,
1571         RichEditorAbstractSpanResult& spanResult);
1572     void DeleteByDeleteValueInfo(const RichEditorDeleteValue& info);
1573     int32_t ProcessDeleteNodes(std::list<RichEditorAbstractSpanResult>& deleteSpans);
1574     bool OnKeyEvent(const KeyEvent& keyEvent);
1575     void MoveCaretAfterTextChange();
1576     bool BeforeIMEInsertValue(const std::u16string& insertValue);
1577     void AfterInsertValue(
1578         const RefPtr<SpanNode>& spanNode, int32_t insertValueLength, bool isCreate, bool isIme = true);
1579     bool AfterIMEInsertValue(const RefPtr<SpanNode>& spanNode, int32_t moveLength, bool isCreate);
1580     void SetCaretSpanIndex(int32_t index);
1581     bool HasSameTypingStyle(const RefPtr<SpanNode>& spanNode);
1582 
1583     void GetChangeSpanStyle(RichEditorChangeValue& changeValue, std::optional<TextStyle>& spanTextStyle,
1584         std::optional<struct UpdateParagraphStyle>& spanParaStyle, std::optional<std::u16string>& urlAddress,
1585         const RefPtr<SpanNode>& spanNode, int32_t spanIndex, bool useTypingParaStyle = false);
1586     void GetReplacedSpan(RichEditorChangeValue& changeValue, int32_t& innerPosition, const std::u16string& insertValue,
1587         int32_t textIndex, std::optional<TextStyle> textStyle, std::optional<struct UpdateParagraphStyle> paraStyle,
1588         std::optional<std::u16string> urlAddress = std::nullopt, bool isCreate = false, bool fixDel = true);
1589     void GetReplacedSpanFission(RichEditorChangeValue& changeValue, int32_t& innerPosition, std::u16string& content,
1590         int32_t startSpanIndex, int32_t offsetInSpan, std::optional<TextStyle> textStyle,
1591         std::optional<struct UpdateParagraphStyle> paraStyle, const std::optional<std::u16string>& urlAddress);
1592     void CreateSpanResult(RichEditorChangeValue& changeValue, int32_t& innerPosition, int32_t spanIndex,
1593         int32_t offsetInSpan, int32_t endInSpan, std::u16string content, std::optional<TextStyle> textStyle,
1594         std::optional<struct UpdateParagraphStyle> paraStyle, const std::optional<std::u16string>& urlAddress);
1595     void SetTextStyleToRet(RichEditorAbstractSpanResult& retInfo, const TextStyle& textStyle);
1596     void SetThemeTextStyleToRet(RichEditorAbstractSpanResult& retInfo);
1597     void SetParaStyleToRet(RichEditorAbstractSpanResult& retInfo, std::optional<struct UpdateParagraphStyle> paraStyle);
1598 
1599     RichEditorAbstractSpanResult GetResultByImageSpanOptions(const ImageSpanOptions& options, int32_t spanIndex);
1600     RichEditorAbstractSpanResult GetResultByTextSpanOptions(const TextSpanOptions& options, int32_t spanIndex);
1601     RichEditorAbstractSpanResult GetResultBySymbolSpanOptions(const SymbolSpanOptions& options, int32_t spanIndex);
1602     void UpdateSpanResultRange(RichEditorAbstractSpanResult& retInfo, int32_t spanIndex, TextRange spanRange);
1603     void UpdateImageSpanResultByOptions(RichEditorAbstractSpanResult& retInfo, const ImageSpanOptions& options);
1604     void UpdateTextSpanResultByOptions(RichEditorAbstractSpanResult& retInfo, const TextSpanOptions& options);
1605     void UpdateSymbolSpanResultByOptions(RichEditorAbstractSpanResult& retInfo, const SymbolSpanOptions& options);
1606 
1607     void CalcInsertValueObj(TextInsertValueInfo& info, int textIndex, bool isCreate = false);
1608     void GetDeletedSpan(RichEditorChangeValue& changeValue, int32_t& innerPosition, int32_t length,
1609         RichEditorDeleteDirection direction = RichEditorDeleteDirection::FORWARD);
1610     RefPtr<SpanItem> GetDelPartiallySpanItem(
1611         RichEditorChangeValue& changeValue, std::u16string& originalStr, int32_t& originalPos);
1612     void FixMoveDownChange(RichEditorChangeValue& changeValue, int32_t delLength);
1613     bool BeforeChangeText(
1614         RichEditorChangeValue& changeValue, const OperationRecord& record, RecordType type, int32_t delLength = 0);
1615     void BeforeUndo(RichEditorChangeValue& changeValue, int32_t& innerPosition, const OperationRecord& record);
1616     void BeforeRedo(RichEditorChangeValue& changeValue, int32_t& innerPosition, const OperationRecord& record);
1617     void BeforeDrag(RichEditorChangeValue& changeValue, int32_t& innerPosition, const OperationRecord& record);
1618     bool BeforeChangeText(RichEditorChangeValue& changeValue, const TextSpanOptions& options);
1619 
1620     // add for scroll.
1621     void UpdateChildrenOffset();
1622     void MoveFirstHandle(float offset);
1623     void MoveSecondHandle(float offset);
1624     void InitScrollablePattern();
1625     bool IsReachedBoundary(float offset);
1626     void UpdateScrollBarOffset() override;
1627     void CheckScrollable();
1628     void UpdateMagnifierStateAfterLayout(bool frameSizeChange);
1629     void UpdateScrollStateAfterLayout(bool shouldDisappear);
1630     void ScheduleAutoScroll(AutoScrollParam param);
1631     void OnAutoScroll(AutoScrollParam param);
1632     void StopAutoScroll();
1633     void AutoScrollByEdgeDetection(AutoScrollParam param, OffsetF offset, EdgeDetectionStrategy strategy);
1634     float CalcDragSpeed(float hotAreaStart, float hotAreaEnd, float point);
1635     float MoveTextRect(float offset);
1636     void SetNeedMoveCaretToContentRect();
1637     void MoveCaretToContentRect();
1638     void MoveCaretToContentRect(const OffsetF& caretOffset, float caretHeight);
1639     void MoveCaretToContentRect(float offset, int32_t source);
1640     bool IsCaretInContentArea();
IsTextArea()1641     bool IsTextArea() const override
1642     {
1643         return true;
1644     }
1645     void ProcessInnerPadding();
IsReachTop()1646     bool IsReachTop()
1647     {
1648         return NearEqual(richTextRect_.GetY(), contentRect_.GetY());
1649     }
1650 
IsReachBottom()1651     bool IsReachBottom()
1652     {
1653         return NearEqual(richTextRect_.Bottom(), contentRect_.Bottom());
1654     }
1655     // ai analysis fun
1656     bool NeedAiAnalysis(
1657         const CaretUpdateType targeType, const int32_t pos, const int32_t& spanStart, const std::string& content);
1658     bool IsIndexAfterOrInSymbolOrEmoji(int32_t index);
1659     void AdjustCursorPosition(int32_t& pos);
1660     void AdjustPlaceholderSelection(int32_t& start, int32_t& end, const Offset& pos);
1661     bool AdjustWordSelection(int32_t& start, int32_t& end);
1662     bool IsTouchAtLineEnd(int32_t caretPos, const Offset& textOffset);
1663     bool IsTouchBeforeCaret(int32_t caretPos, const Offset& textOffset);
1664     bool IsClickBoundary(const int32_t position);
1665     void SetSelfAndChildDraggableFalse(const RefPtr<UINode>& customNode);
1666     RefPtr<SpanItem> GetSameSpanItem(const RefPtr<SpanItem>& spanItem);
1667     RefPtr<ImageSpanNode> GetImageSpanNodeBySpanItem(const RefPtr<ImageSpanItem>& spanItem);
1668 
1669     void AdjustSelectRects(SelectRectsType pos, std::vector<RectF>& selectRects);
1670     RectF GetSelectArea(SelectRectsType pos);
1671     void AppendSelectRect(std::vector<RectF>& selectRects);
1672     RectF CreateNewLineRect(const int32_t position, const bool downStreamFirst);
1673     bool IsTouchInFrameArea(const PointF& touchPoint);
1674     void HandleOnDragDrop(const RefPtr<OHOS::Ace::DragEvent>& event, bool isCopy = false);
1675     void DeleteForward(int32_t currentPosition, int32_t length);
1676     int32_t HandleOnDragDeleteForward(int32_t currentPosition);
1677     void HandleOnDragDropTextOperation(const std::u16string& insertValue, bool isDeleteSelect, bool isCopy = false);
1678     void UndoDrag(const OperationRecord& record);
1679     void RedoDrag(const OperationRecord& record);
1680     void HandleOnEditChanged(bool isEditing);
1681     void OnTextInputActionUpdate(TextInputAction value);
1682     void CloseSystemMenu();
1683     void SetAccessibilityAction() override;
1684     void SetAccessibilityEditAction();
1685     bool IsAccessibilityClick();
1686     void HandleTripleClickEvent(OHOS::Ace::GestureEvent& info);
1687     void UpdateSelectionByTouchMove(const Offset& offset);
1688     bool CheckTripClickEvent(GestureEvent& info);
1689     void HandleSelect(GestureEvent& info, int32_t selectStart, int32_t selectEnd);
1690     TextStyleResult GetTextStyleBySpanItem(const RefPtr<SpanItem>& spanItem);
1691     void CopyTextLineStyleToTextStyleResult(const RefPtr<SpanItem>& spanItem, TextStyleResult& textStyle);
1692     ImageStyleResult GetImageStyleBySpanItem(const RefPtr<SpanItem>& spanItem);
1693     void SetSubSpans(RefPtr<SpanString>& spanString, int32_t start, int32_t end,
1694         const std::list<RefPtr<SpanItem>>& spans);
1695     void SetSubMap(RefPtr<SpanString>& spanString);
1696     void OnCopyOperationExt(RefPtr<PasteDataMix>& pasteData);
1697     void AddSpanByPasteData(const RefPtr<SpanString>& spanString, TextChangeReason reason = TextChangeReason::PASTE);
1698     void CompleteStyledString(RefPtr<SpanString>& spanString);
1699     void InsertStyledString(const RefPtr<SpanString>& spanString, int32_t insertIndex, bool updateCaret = true);
1700     void InsertStyledStringByPaste(const RefPtr<SpanString>& spanString);
1701     void HandleOnDragInsertStyledString(const RefPtr<SpanString>& spanString, bool isCopy = false);
1702     void AddSpansByPaste(const std::list<RefPtr<NG::SpanItem>>& spans,
1703         TextChangeReason reason = TextChangeReason::PASTE);
1704     void HandleOnCopyStyledString();
1705     void HandleOnDragDropStyledString(const RefPtr<OHOS::Ace::DragEvent>& event, bool isCopy = false);
1706     void NotifyExitTextPreview(bool deletePreviewText = true);
1707     void NotifyImfFinishTextPreview();
1708     int32_t CalculateTruncationLength(const std::u16string& insertValue, int32_t start);
1709     bool ProcessTextTruncationOperation(std::u16string& text, bool shouldCommitInput);
1710     void ProcessInsertValueMore(const std::u16string& text, OperationRecord record, OperationType operationType,
1711         RichEditorChangeValue changeValue, PreviewTextRecord preRecord, bool shouldCommitInput);
1712     void ProcessInsertValue(const std::u16string& insertValue, OperationType operationType = OperationType::DEFAULT,
1713         bool shouldCommitInput = false);
1714     void FinishTextPreviewInner(bool deletePreviewText = true);
1715     void TripleClickSection(GestureEvent& info, int32_t start, int32_t end, int32_t pos);
1716     void ProcessOverlayOnSetSelection(const std::optional<SelectionOptions>& options);
1717     std::pair<int32_t, SelectType> JudgeSelectType(const Offset& pos);
1718     bool IsSelectEmpty(int32_t start, int32_t end);
1719     bool AdjustIndexSkipLineSeparator(int32_t& currentPosition);
1720     bool AdjustIndexSkipSpace(int32_t& currentPosition, const MoveDirection direction);
1721     void RequestKeyboardToEdit();
HandleTasksOnLayoutSwap()1722     void HandleTasksOnLayoutSwap()
1723     {
1724         while (!tasks_.empty()) {
1725             const auto& task = tasks_.front();
1726             if (task) {
1727                 task();
1728             }
1729             tasks_.pop();
1730         }
1731     }
PostTaskToLayutSwap(std::function<void ()> && task)1732     void PostTaskToLayutSwap(std::function<void()>&& task)
1733     {
1734         tasks_.emplace(std::forward<std::function<void()>>(task));
1735     }
1736 
1737     OffsetF GetGlobalOffset() const;
1738     void MergeAdjacentSpans(int32_t caretPosition);
1739     void HandleImageDrag(const RefPtr<ImageSpanNode>& imageNode);
1740     void DisableDrag(const RefPtr<ImageSpanNode>& imageNode);
1741     void SetGestureOptions(UserGestureOptions userGestureOptions, RefPtr<SpanItem> spanItem);
1742     void AddSpanHoverEvent(
1743         RefPtr<SpanItem> spanItem, const RefPtr<FrameNode>& frameNode, const SpanOptionBase& options);
1744     void UpdateGestureHotZone(const RefPtr<LayoutWrapper>& dirty);
1745     void ClearOnFocusTextField(FrameNode* node);
1746     void ProcessResultObject(RefPtr<PasteDataMix> pasteData, const ResultObject& result,
1747         const std::list<RefPtr<SpanItem>>& spans);
1748     RefPtr<SpanString> GetSpanStringByResultObject(const ResultObject& result,
1749         const std::list<RefPtr<SpanItem>>& spans);
1750     bool InitPreviewText(const std::u16string& previewTextValue, const PreviewRange& range);
1751     bool ReplaceText(const std::u16string& previewTextValue, const PreviewRange& range);
1752     bool UpdatePreviewText(const std::u16string& previewTextValue, const PreviewRange& range);
1753     bool IsEnPreview();
1754     void SetMagnifierLocalOffset(Offset localOffset);
1755     void SetMagnifierOffsetWithAnimation(Offset offset);
1756     void UpdateSelectionAndHandleVisibility();
1757     void SetIsEnableSubWindowMenu();
1758     void OnReportRichEditorEvent(const std::string& event);
1759     void AsyncHandleOnCopyStyledStringHtml(RefPtr<SpanString>& subSpanString);
1760     bool NeedShowPlaceholder() const;
1761     bool IsSelectAll() override;
1762     std::pair<int32_t, int32_t> GetSpanRangeByResultObject(const ResultObject& result);
1763     std::list<RefPtr<SpanItem>> CopySpansForClipboard(const std::list<RefPtr<SpanItem>>& spans);
1764 #ifdef CROSS_PLATFORM
1765     bool UnableStandardInputCrossPlatform(TextInputConfiguration& config, bool isFocusViewChanged);
1766 #endif
1767     void OnAccessibilityEventTextChange(const std::string& changeType, const std::string& changeString);
1768     void ReportComponentChangeEvent();
1769 
1770 #if defined(ENABLE_STANDARD_INPUT)
1771     sptr<OHOS::MiscServices::OnTextChangedListener> richEditTextChangeListener_;
1772 #else
1773     RefPtr<TextInputConnection> connection_ = nullptr;
1774 #endif
1775     const bool isAPI14Plus;
1776     const bool isAPI16Plus;
1777     const bool isAPI18Plus;
1778     const bool isAPI20Plus;
1779     bool shiftFlag_ = false;
1780     bool isMouseSelect_ = false;
1781     bool isMousePressed_ = false;
1782     bool isFirstMouseSelect_ = true;
1783     bool leftMousePress_ = false;
1784     bool isLongPress_ = false;
1785 #if defined(OHOS_STANDARD_SYSTEM) && !defined(PREVIEW)
1786     bool imeAttached_ = false;
1787     bool imeShown_ = false;
1788 #endif
1789     bool isTextChange_ = false;
1790     bool caretVisible_ = false;
1791     bool caretTwinkling_ = false;
1792     bool isRichEditorInit_ = false;
1793     bool clickEventInitialized_ = false;
1794     bool focusEventInitialized_ = false;
1795     bool blockPress_ = false;
1796     bool isCustomKeyboardAttached_ = false;
1797     bool usingMouseRightButton_ = false;
1798     bool isCursorAlwaysDisplayed_ = false;
1799     bool isClickOnAISpan_ = false;
1800     bool isOnlyRequestFocus_ = false;
1801 
1802     int32_t moveLength_ = 0;
1803     int32_t insertValueLength_ = 0;
1804     int32_t lastCaretPosition_ = 0;
1805     int32_t caretPosition_ = 0;
1806     int32_t caretSpanIndex_ = -1;
1807     long long timestamp_ = 0;
1808     CaretAffinityPolicy caretAffinityPolicy_ = CaretAffinityPolicy::DEFAULT;
1809     OffsetF selectionMenuOffsetByMouse_;
1810     OffsetF selectionMenuOffsetClick_;
1811     OffsetF lastClickOffset_;
1812     std::u16string pasteStr_;
1813 
1814     // still in progress
1815     RichEditorParagraphManager paragraphs_;
1816     OperationRecord previewInputRecord_;
1817     std::vector<OperationRecord> operationRecords_;
1818     std::vector<OperationRecord> redoOperationRecords_;
1819     std::list<WeakPtr<ImageSpanNode>> hoverableNodes;
1820     RefPtr<ImageSpanItem> lastHoverSpanItem_ = nullptr;
1821     HoverInfo lastHoverInfo_;
1822 
1823     RefPtr<TouchEventImpl> touchListener_;
1824     RefPtr<PanEvent> panEvent_;
1825     struct UpdateSpanStyle updateSpanStyle_;
1826     CancelableCallback<void()> caretTwinklingTask_;
1827     RefPtr<RichEditorController> richEditorController_;
1828     RefPtr<RichEditorStyledStringController> richEditorStyledStringController_;
1829     MoveDirection moveDirection_ = MoveDirection::FORWARD;
1830     RectF frameRect_;
1831     std::optional<struct UpdateSpanStyle> typingStyle_;
1832     std::optional<TextStyle> typingTextStyle_;
1833     std::list<ResultObject> dragResultObjects_;
1834     std::optional<Color> caretColor_;
1835     std::optional<Color> selectedBackgroundColor_;
1836     std::function<void()> customKeyboardBuilder_;
1837     std::function<void(int32_t)> caretChangeListener_;
1838     RefPtr<OverlayManager> keyboardOverlay_;
1839     RefPtr<AIWriteAdapter> aiWriteAdapter_ = MakeRefPtr<AIWriteAdapter>();
1840     Offset selectionMenuOffset_;
1841     // add for scroll
1842     RectF richTextRect_;
1843     float scrollOffset_ = 0.0f;
1844     bool isFirstCallOnReady_ = false;
1845     bool scrollable_ = true;
1846     CancelableCallback<void()> autoScrollTask_;
1847     OffsetF prevAutoScrollOffset_;
1848     AutoScrollParam currentScrollParam_;
1849     bool isAutoScrollRunning_ = false;
1850     // add for ai input analysis
1851     bool hasClicked_ = false;
1852     CaretUpdateType caretUpdateType_ = CaretUpdateType::NONE;
1853     TimeStamp lastClickTimeStamp_;
1854     TimeStamp lastAiPosTimeStamp_;
1855     bool adjusted_ = false;
1856     bool isShowMenu_ = true;
1857     bool isShowPlaceholder_ = false;
1858     bool isSingleHandle_ = false;
1859     TouchAndMoveCaretState moveCaretState_;
1860     FloatingCaretState floatingCaretState_;
1861     std::shared_ptr<AnimationUtils::Animation> magnifierAnimation_;
1862     // Recorded when touch down or mouse left button press.
1863     OffsetF globalOffsetOnMoveStart_;
1864     SelectionRangeInfo lastSelectionRange_{-1, -1};
1865     bool isDragSponsor_ = false;
1866     std::pair<int32_t, int32_t> dragRange_ { 0, 0 };
1867     bool isInterceptMouseRightRelease_ = false;
1868     bool isEditing_ = false;
1869     int32_t dragPosition_ = 0;
1870     // Action when "enter" pressed.
1871     TextInputAction action_ = TextInputAction::NEW_LINE;
1872     // What the keyboard appears.
1873     TextInputType keyboard_ = TextInputType::UNSPECIFIED;
1874     ACE_DISALLOW_COPY_AND_MOVE(RichEditorPattern);
1875     bool keyboardAvoidance_ = false;
1876     int32_t richEditorInstanceId_ = -1;
1877     int32_t frameId_ = -1;
1878     bool contentChange_ = false;
1879     PreviewTextRecord previewTextRecord_;
1880     bool isTextPreviewSupported_ = true;
1881     OffsetF movingHandleOffset_;
1882     std::pair<int32_t, int32_t> initSelector_ = { 0, 0 };
1883     std::vector<TimeStamp> clickInfo_;
1884     int32_t selectingFingerId_ = -1;
1885     bool isTouchSelecting_ = false;
1886     bool previewLongPress_ = false;
1887     bool editingLongPress_ = false;
1888     bool needMoveCaretToContentRect_ = false;
1889     std::queue<std::function<void()>> tasks_;
1890     bool isModifyingContent_ = false;
1891     bool needToRequestKeyboardOnFocus_ = true;
1892     bool isEnableHapticFeedback_ = true;
1893     bool isEnableAutoSpacing_ = false;
1894     float maxLinesHeight_ = FLT_MAX;
1895     int32_t maxLines_ = INT32_MAX;
1896     std::unordered_map<std::u16string, RefPtr<SpanItem>> placeholderSpansMap_;
1897     std::optional<DisplayMode> barDisplayMode_ = std::nullopt;
1898     uint32_t twinklingInterval_ = 0;
1899     bool isTriggerAvoidOnCaretAvoidMode_ = false;
1900     RectF lastRichTextRect_;
1901     std::optional<int32_t> maxLength_ = std::nullopt;
1902     std::unique_ptr<OneStepDragController> oneStepDragController_;
1903     std::unique_ptr<RichEditorUndoManager> undoManager_;
1904     bool isStyledUndoSupported_ = false;
1905     std::list<WeakPtr<ImageSpanNode>> imageNodes;
1906     std::list<WeakPtr<PlaceholderSpanNode>> builderNodes;
1907     bool isStopBackPress_ = true;
1908     bool blockKbInFloatingWindow_ = false;
1909     KeyboardAppearance keyboardAppearance_ = KeyboardAppearance::NONE_IMMERSIVE;
1910     LRUMap<uint64_t, RefPtr<Paragraph>> paragraphCache_;
1911     SysScale lastSysScale_;
1912     std::map<int32_t, AISpan> lastAISpanMap_;
1913     // Used to avoid show single handle by first click after window focus
1914     bool firstClickAfterWindowFocus_ = false;
1915     CancelableCallback<void()> firstClickResetTask_;
1916     RefPtr<RichEditorContentPattern> contentPattern_;
1917     std::unique_ptr<StyleManager> styleManager_;
1918     bool requestFocusBySingleClick_ = false;
1919     std::optional<float> lastCaretPos_ = std::nullopt;
1920     int32_t touchedFingerCount_ = 0;
1921 #if defined(IOS_PLATFORM)
1922     TextCompose compose_;
1923     bool unmarkText_;
1924 #endif
1925 };
1926 } // namespace OHOS::Ace::NG
1927 
1928 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_RICH_EDITOR_RICH_EDITOR_PATTERN_H
1929