• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_TEXT_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_TEXT_PATTERN_H
18 
19 #include <limits>
20 #include <optional>
21 #include <string>
22 #include <unordered_map>
23 
24 #include "interfaces/inner_api/ace/ai/data_detector_interface.h"
25 
26 #include "base/geometry/dimension.h"
27 #include "base/geometry/ng/offset_t.h"
28 #include "base/memory/referenced.h"
29 #include "base/utils/noncopyable.h"
30 #include "base/utils/utils.h"
31 #include "core/common/ai/data_detector_adapter.h"
32 #include "core/components_ng/event/long_press_event.h"
33 #include "core/components_ng/pattern/pattern.h"
34 #include "core/components_ng/pattern/rich_editor/paragraph_manager.h"
35 #include "core/components_ng/pattern/rich_editor/selection_info.h"
36 #include "core/components_ng/pattern/rich_editor_drag/preview_menu_controller.h"
37 #include "core/components_ng/pattern/rich_editor_drag/rich_editor_drag_info.h"
38 #include "core/components_ng/pattern/scrollable/scrollable_pattern.h"
39 #include "core/components_ng/pattern/select_overlay/magnifier.h"
40 #include "core/components_ng/pattern/text/layout_info_interface.h"
41 #include "core/components_ng/pattern/text/multiple_click_recognizer.h"
42 #include "core/components_ng/pattern/text/span/mutable_span_string.h"
43 #include "core/components_ng/pattern/text/span/span_object.h"
44 #include "core/components_ng/pattern/text/span/span_string.h"
45 #include "core/components_ng/pattern/text/span_node.h"
46 #include "core/components_ng/pattern/text/text_accessibility_property.h"
47 #include "core/components_ng/pattern/text/text_base.h"
48 #include "core/components_ng/pattern/text/text_content_modifier.h"
49 #include "core/components_ng/pattern/text/text_controller.h"
50 #include "core/components_ng/pattern/text/text_event_hub.h"
51 #include "core/components_ng/pattern/text/text_layout_algorithm.h"
52 #include "core/components_ng/pattern/text/text_layout_property.h"
53 #include "core/components_ng/pattern/text/text_overlay_modifier.h"
54 #include "core/components_ng/pattern/text/text_paint_method.h"
55 #include "core/components_ng/pattern/text/text_select_overlay.h"
56 #include "core/components_ng/pattern/text_drag/text_drag_base.h"
57 #include "core/components_ng/pattern/text_field/text_selector.h"
58 #include "core/components_ng/render/text_effect.h"
59 #include "core/components_ng/property/property.h"
60 #include "core/event/ace_events.h"
61 #include "core/pipeline_ng/ui_task_scheduler.h"
62 
63 namespace OHOS::Ace::NG {
64 namespace {
65 constexpr int32_t MAX_SIZE_OF_LOG = 2000;
66 }
67 
68 class InspectorFilter;
69 class PreviewMenuController;
70 enum class Status { DRAGGING, FLOATING, ON_DROP, NONE };
71 using CalculateHandleFunc = std::function<void()>;
72 using ShowSelectOverlayFunc = std::function<void(const RectF&, const RectF&)>;
73 struct SpanNodeInfo {
74     RefPtr<UINode> node;
75     RefPtr<UINode> containerSpanNode;
76 };
77 enum class SelectionMenuCalblackId { MENU_APPEAR, MENU_SHOW, MENU_HIDE };
78 
79 // TextPattern is the base class for text render node to perform paint text.
80 class TextPattern : public virtual Pattern,
81                     public TextDragBase,
82                     public TextBase,
83                     public TextGestureSelector,
84                     public Magnifier,
85                     public LayoutInfoInterface {
86     DECLARE_ACE_TYPE(TextPattern, Pattern, TextDragBase, TextBase, TextGestureSelector, Magnifier);
87 
88 public:
TextPattern()89     TextPattern()
90     {
91         selectOverlay_ = AceType::MakeRefPtr<TextSelectOverlay>(WeakClaim(this));
92         pManager_ = AceType::MakeRefPtr<ParagraphManager>();
93         ResetOriginCaretPosition();
94     }
95 
96     ~TextPattern() override;
97 
GetContentHost()98     virtual RefPtr<FrameNode> GetContentHost() const
99     {
100         return GetHost();
101     }
102 
103     SelectionInfo GetSpansInfo(int32_t start, int32_t end, GetSpansMethod method);
104     std::list<ResultObject> GetSpansInfoInStyledString(int32_t start, int32_t end);
105 
106     virtual int32_t GetTextContentLength();
107 
108     RefPtr<NodePaintMethod> CreateNodePaintMethod() override;
109 
CreateLayoutProperty()110     RefPtr<LayoutProperty> CreateLayoutProperty() override
111     {
112         return MakeRefPtr<TextLayoutProperty>();
113     }
114 
CreateLayoutAlgorithm()115     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
116     {
117         auto textLayoutProperty = GetLayoutProperty<TextLayoutProperty>();
118         if (textLayoutProperty &&
119             textLayoutProperty->GetTextOverflowValue(TextOverflow::CLIP) == TextOverflow::MARQUEE) {
120             return MakeRefPtr<TextLayoutAlgorithm>(
121                 spans_, pManager_, isSpanStringMode_, textStyle_.value_or(TextStyle()), true);
122         } else {
123             return MakeRefPtr<TextLayoutAlgorithm>(
124                 spans_, pManager_, isSpanStringMode_, textStyle_.value_or(TextStyle()));
125         }
126     }
127 
CreateAccessibilityProperty()128     RefPtr<AccessibilityProperty> CreateAccessibilityProperty() override
129     {
130         return MakeRefPtr<TextAccessibilityProperty>();
131     }
132 
CreateEventHub()133     RefPtr<EventHub> CreateEventHub() override
134     {
135         return MakeRefPtr<TextEventHub>();
136     }
137 
IsDragging()138     virtual bool IsDragging() const
139     {
140         return status_ == Status::DRAGGING;
141     }
142 
IsAtomicNode()143     bool IsAtomicNode() const override
144     {
145         auto host = GetHost();
146         CHECK_NULL_RETURN(host, false);
147         return host->GetTag() == V2::SYMBOL_ETS_TAG;
148     }
149 
IsTextNode()150     bool IsTextNode() const
151     {
152         auto host = GetHost();
153         CHECK_NULL_RETURN(host, false);
154         return host->GetTag() == V2::TEXT_ETS_TAG;
155     }
156 
DefaultSupportDrag()157     bool DefaultSupportDrag() override
158     {
159         return true;
160     }
161 
162     void OnModifyDone() override;
163     void MultiThreadDelayedExecution();
164 
165     void OnWindowHide() override;
166 
167     void OnWindowShow() override;
168 
169     void PreCreateLayoutWrapper();
170 
171     void BeforeCreateLayoutWrapper() override;
172 
173     void AddChildSpanItem(const RefPtr<UINode>& child);
174     void SetSpanItemEvent(const RefPtr<SpanItem>& spanItem, RefPtr<FocusHub>& focusHub);
175     void AddImageToSpanItem(const RefPtr<UINode>& child);
176 
GetFocusPattern()177     FocusPattern GetFocusPattern() const override
178     {
179         return { FocusType::NODE, false };
180     }
181 
182     void DumpAdvanceInfo() override;
183 
184     void DumpInfo() override;
185     void DumpSimplifyInfo(std::shared_ptr<JsonValue>& json) override;
186     void DumpInfo(std::unique_ptr<JsonValue>& json) override;
187     void DumpAdvanceInfo(std::unique_ptr<JsonValue>& json) override;
188     void SetTextStyleDumpInfo(std::unique_ptr<JsonValue>& json);
189     void DumpTextStyleInfo();
190     void DumpTextStyleInfo2();
191     void DumpTextStyleInfo3();
192     void DumpTextStyleInfo4();
193     void DumpSpanItem();
194     void DumpScaleInfo();
195     void DumpTextEngineInfo();
196     void DumpParagraphsInfo();
197 
GetTextSelector()198     TextSelector GetTextSelector() const
199     {
200         return textSelector_;
201     }
202 
GetTextForDisplay()203     const std::u16string& GetTextForDisplay() const
204     {
205         return textForDisplay_;
206     }
207 
GetStartOffset()208     const OffsetF& GetStartOffset() const
209     {
210         return textSelector_.selectionBaseOffset;
211     }
212 
GetEndOffset()213     const OffsetF& GetEndOffset() const
214     {
215         return textSelector_.selectionDestinationOffset;
216     }
217 
GetSelectHeight()218     double GetSelectHeight() const
219     {
220         return textSelector_.GetSelectHeight();
221     }
222 
223     void GetGlobalOffset(Offset& offset);
224 
225     RectF GetTextContentRect(bool isActualText = false) const override;
226 
GetBaselineOffset()227     float GetBaselineOffset() const
228     {
229         return baselineOffset_;
230     }
231 
GetContentModifier()232     RefPtr<TextContentModifier> GetContentModifier()
233     {
234         return contentMod_;
235     }
236 
237     virtual void SetTextDetectEnable(bool enable);
238     void SetTextDetectEnableMultiThread(bool enable);
GetTextDetectEnable()239     bool GetTextDetectEnable()
240     {
241         return textDetectEnable_;
242     }
SetTextDetectTypes(const std::string & types)243     void SetTextDetectTypes(const std::string& types)
244     {
245         CHECK_NULL_VOID(GetDataDetectorAdapter());
246         dataDetectorAdapter_->SetTextDetectTypes(types);
247         textDetectTypes_ = types; // url value is not recorded in dataDetectorAdapter_, need to record it here
248     }
GetTextDetectTypes()249     std::string GetTextDetectTypes()
250     {
251         return textDetectTypes_;
252     }
GetDataDetectorAdapter()253     RefPtr<DataDetectorAdapter> GetDataDetectorAdapter()
254     {
255         if (!dataDetectorAdapter_) {
256             dataDetectorAdapter_ = MakeRefPtr<DataDetectorAdapter>();
257         }
258         return dataDetectorAdapter_;
259     }
GetAISpanMap()260     virtual const std::map<int32_t, AISpan>& GetAISpanMap()
261     {
262         return GetDataDetectorAdapter()->aiSpanMap_;
263     }
GetTextForAI()264     const std::u16string& GetTextForAI()
265     {
266         return GetDataDetectorAdapter()->textForAI_;
267     }
SetOnResult(std::function<void (const std::string &)> && onResult)268     void SetOnResult(std::function<void(const std::string&)>&& onResult)
269     {
270         GetDataDetectorAdapter()->onResult_ = std::move(onResult);
271     }
GetTextDetectResult()272     TextDataDetectResult GetTextDetectResult()
273     {
274         return GetDataDetectorAdapter()->textDetectResult_;
275     }
MarkAISpanStyleChanged()276     virtual void MarkAISpanStyleChanged()
277     {
278         auto host = GetHost();
279         CHECK_NULL_VOID(host);
280         host->MarkDirtyWithOnProChange(PROPERTY_UPDATE_MEASURE);
281     }
SetTextDetectConfig(const TextDetectConfig & textDetectConfig)282     void SetTextDetectConfig(const TextDetectConfig& textDetectConfig)
283     {
284         CHECK_NULL_VOID(GetDataDetectorAdapter());
285         dataDetectorAdapter_->SetTextDetectTypes(textDetectConfig.types);
286         dataDetectorAdapter_->onResult_ = std::move(textDetectConfig.onResult);
287         dataDetectorAdapter_->entityColor_ = textDetectConfig.entityColor;
288         dataDetectorAdapter_->entityDecorationType_ = textDetectConfig.entityDecorationType;
289         dataDetectorAdapter_->entityDecorationColor_ = textDetectConfig.entityDecorationColor;
290         dataDetectorAdapter_->entityDecorationStyle_ = textDetectConfig.entityDecorationStyle;
291         auto textDetectConfigCache = dataDetectorAdapter_->textDetectConfigStr_;
292         dataDetectorAdapter_->enablePreviewMenu_ = textDetectConfig.enablePreviewMenu;
293         dataDetectorAdapter_->textDetectConfigStr_ = textDetectConfig.ToString();
294         if (textDetectConfigCache != dataDetectorAdapter_->textDetectConfigStr_) {
295             MarkAISpanStyleChanged();
296         }
297     }
ModifyAISpanStyle(TextStyle & aiSpanStyle)298     void ModifyAISpanStyle(TextStyle& aiSpanStyle)
299     {
300         CHECK_NULL_VOID(GetDataDetectorAdapter());
301         TextDetectConfig textDetectConfig;
302         aiSpanStyle.SetTextColor(dataDetectorAdapter_->entityColor_.value_or(textDetectConfig.entityColor));
303         aiSpanStyle.SetTextDecoration(
304             dataDetectorAdapter_->entityDecorationType_.value_or(textDetectConfig.entityDecorationType));
305         aiSpanStyle.SetTextDecorationColor(
306             dataDetectorAdapter_->entityDecorationColor_.value_or(textDetectConfig.entityColor));
307         aiSpanStyle.SetTextDecorationStyle(
308             dataDetectorAdapter_->entityDecorationStyle_.value_or(textDetectConfig.entityDecorationStyle));
309     }
310 
311     void OnVisibleChange(bool isVisible) override;
312 
GetSpanItemChildren()313     std::list<RefPtr<SpanItem>> GetSpanItemChildren()
314     {
315         return spans_;
316     }
317 
GetDisplayWideTextLength()318     int32_t GetDisplayWideTextLength()
319     {
320         return textForDisplay_.length();
321     }
322 
323     // ===========================================================
324     // TextDragBase implementations
325 
IsTextArea()326     bool IsTextArea() const override
327     {
328         return false;
329     }
330 
GetTextRect()331     const RectF& GetTextRect() const override
332     {
333         return contentRect_;
334     }
335     float GetLineHeight() const override;
336 
337     std::vector<RectF> GetTextBoxes() override;
338     OffsetF GetParentGlobalOffset() const override;
339 
MoveDragNode()340     const RefPtr<FrameNode>& MoveDragNode() override
341     {
342         return dragNode_;
343     }
344 
GetDragParagraph()345     const RefPtr<Paragraph>& GetDragParagraph() const override
346     {
347         return pManager_->GetParagraphs().front().paragraph;
348     }
349 
CloseKeyboard(bool)350     bool CloseKeyboard(bool /* forceClose */) override
351     {
352         return true;
353     }
354     virtual void CloseSelectOverlay() override;
355     void CloseSelectOverlay(bool animation);
356     void CloseSelectOverlayMultiThread(bool animation);
357     void CloseSelectOverlayMultiThreadAction(bool animation);
358     void CreateHandles() override;
359     bool BetweenSelectedPosition(const Offset& globalOffset) override;
360 
361     // end of TextDragBase implementations
362     // ===========================================================
363 
364     void InitSurfaceChangedCallback();
365     void InitSurfacePositionChangedCallback();
366     virtual void HandleSurfaceChanged(
367         int32_t newWidth, int32_t newHeight, int32_t prevWidth, int32_t prevHeight, WindowSizeChangeReason type);
HandleSurfacePositionChanged(int32_t posX,int32_t posY)368     virtual void HandleSurfacePositionChanged(int32_t posX, int32_t posY) {};
HasSurfaceChangedCallback()369     bool HasSurfaceChangedCallback()
370     {
371         return surfaceChangedCallbackId_.has_value();
372     }
UpdateSurfaceChangedCallbackId(int32_t id)373     void UpdateSurfaceChangedCallbackId(int32_t id)
374     {
375         surfaceChangedCallbackId_ = id;
376     }
377 
HasSurfacePositionChangedCallback()378     bool HasSurfacePositionChangedCallback()
379     {
380         return surfacePositionChangedCallbackId_.has_value();
381     }
UpdateSurfacePositionChangedCallbackId(int32_t id)382     void UpdateSurfacePositionChangedCallbackId(int32_t id)
383     {
384         surfacePositionChangedCallbackId_ = id;
385     }
386 
387     void SetOnClickEvent(GestureEventFunc&& onClick, double distanceThreshold = std::numeric_limits<double>::infinity())
388     {
389         onClick_ = std::move(onClick);
390         distanceThreshold_ = distanceThreshold;
391     }
392 
393     NG::DragDropInfo OnDragStart(const RefPtr<Ace::DragEvent>& event, const std::string& extraParams);
394     DragDropInfo OnDragStartNoChild(const RefPtr<Ace::DragEvent>& event, const std::string& extraParams);
395     void InitDragEvent();
396     void ClearDragEvent();
397     void UpdateSpanItemDragStatus(const std::list<ResultObject>& resultObjects, bool IsDragging);
398     void OnDragMove(const RefPtr<Ace::DragEvent>& event);
399     virtual std::function<void(Offset)> GetThumbnailCallback();
400     std::list<ResultObject> dragResultObjects_;
401     std::list<ResultObject> recoverDragResultObjects_;
402     std::vector<RefPtr<SpanItem>> dragSpanItems_;
403     void OnDragEnd(const RefPtr<Ace::DragEvent>& event);
404     void OnDragEndNoChild(const RefPtr<Ace::DragEvent>& event);
405     void CloseOperate();
406     virtual void AddUdmfData(const RefPtr<Ace::DragEvent>& event);
407     void ProcessNormalUdmfData(const RefPtr<UnifiedData>& unifiedData);
408     void AddPixelMapToUdmfData(const RefPtr<PixelMap>& pixelMap, const RefPtr<UnifiedData>& unifiedData);
409     std::u16string GetSelectedSpanText(std::u16string value, int32_t start, int32_t end, bool includeStartHalf = false,
410         bool includeEndHalf = true, bool getSubstrDirectly = true) const;
411 
412     TextStyleResult GetTextStyleObject(const RefPtr<SpanNode>& node);
413     SymbolSpanStyle GetSymbolSpanStyleObject(const RefPtr<SpanNode>& node);
414     virtual RefPtr<UINode> GetChildByIndex(int32_t index) const;
415     RefPtr<SpanItem> GetSpanItemByIndex(int32_t index) const;
416     ResultObject GetTextResultObject(RefPtr<UINode> uinode, int32_t index, int32_t start, int32_t end);
417     virtual void SetResultObjectText(ResultObject& resultObject, const RefPtr<SpanItem>& spanItem);
418     ResultObject GetSymbolSpanResultObject(RefPtr<UINode> uinode, int32_t index, int32_t start, int32_t end);
419     ResultObject GetImageResultObject(RefPtr<UINode> uinode, int32_t index, int32_t start, int32_t end);
420     std::string GetFontInJson() const;
421     std::string GetBindSelectionMenuInJson() const;
422     std::unique_ptr<JsonValue> GetShaderStyleInJson() const;
FillPreviewMenuInJson(const std::unique_ptr<JsonValue> & jsonValue)423     virtual void FillPreviewMenuInJson(const std::unique_ptr<JsonValue>& jsonValue) const {}
424     std::string GetFontSizeWithThemeInJson(const std::optional<Dimension>& value) const;
425 
GetDragContents()426     const std::vector<std::u16string>& GetDragContents() const
427     {
428         return dragContents_;
429     }
430 
InitSpanImageLayout(const std::vector<int32_t> & placeholderIndex,const std::vector<RectF> & rectsForPlaceholders,OffsetF contentOffset)431     void InitSpanImageLayout(const std::vector<int32_t>& placeholderIndex,
432         const std::vector<RectF>& rectsForPlaceholders, OffsetF contentOffset) override
433     {
434         placeholderIndex_ = placeholderIndex;
435         imageOffset_ = contentOffset;
436         rectsForPlaceholders_ = rectsForPlaceholders;
437     }
438 
GetPlaceHolderIndex()439     const std::vector<int32_t>& GetPlaceHolderIndex()
440     {
441         return placeholderIndex_;
442     }
443 
GetRectsForPlaceholders()444     const std::vector<RectF>& GetRectsForPlaceholders()
445     {
446         return rectsForPlaceholders_;
447     }
448 
GetContentOffset()449     OffsetF GetContentOffset() override
450     {
451         return imageOffset_;
452     }
453 
IsMeasureBoundary()454     bool IsMeasureBoundary() const override
455     {
456         return isMeasureBoundary_;
457     }
458 
SetIsMeasureBoundary(bool isMeasureBoundary)459     void SetIsMeasureBoundary(bool isMeasureBoundary)
460     {
461         isMeasureBoundary_ = isMeasureBoundary;
462     }
463 
SetIsCustomFont(bool isCustomFont)464     void SetIsCustomFont(bool isCustomFont)
465     {
466         isCustomFont_ = isCustomFont;
467     }
468 
GetIsCustomFont()469     bool GetIsCustomFont()
470     {
471         return isCustomFont_;
472     }
473 
SetImageSpanNodeList(std::vector<WeakPtr<FrameNode>> imageNodeList)474     void SetImageSpanNodeList(std::vector<WeakPtr<FrameNode>> imageNodeList)
475     {
476         imageNodeList_ = imageNodeList;
477     }
478 
GetImageSpanNodeList()479     std::vector<WeakPtr<FrameNode>> GetImageSpanNodeList()
480     {
481         return imageNodeList_;
482     }
483     // Deprecated: Use the TextSelectOverlay::ProcessOverlay() instead.
484     // It is currently used by RichEditorPattern.
485     virtual void UpdateSelectOverlayOrCreate(SelectOverlayInfo& selectInfo, bool animation = false);
486     // Deprecated: Use the TextSelectOverlay::CheckHandleVisible() instead.
487     // It is currently used by RichEditorPattern.
CheckHandles(SelectHandleInfo & handleInfo)488     virtual void CheckHandles(SelectHandleInfo& handleInfo) {};
489     OffsetF GetDragUpperLeftCoordinates() override;
490     void SetTextSelection(int32_t selectionStart, int32_t selectionEnd);
491     void SetTextSelectionMultiThread(int32_t selectionStart, int32_t selectionEnd);
492     void SetTextSelectionMultiThreadAction(int32_t selectionStart, int32_t selectionEnd);
493 
494     // Deprecated: Use the TextSelectOverlay::OnHandleMove() instead.
495     // It is currently used by RichEditorPattern.
496     void OnHandleMove(const RectF& handleRect, bool isFirstHandle) override;
497 
GetParagraphs()498     virtual std::vector<ParagraphManager::ParagraphInfo> GetParagraphs() const
499     {
500         std::vector<ParagraphManager::ParagraphInfo> res;
501         CHECK_NULL_RETURN(pManager_, res);
502         return pManager_->GetParagraphs();
503     }
504 
GetParagraphManager()505     const RefPtr<ParagraphManager>& GetParagraphManager() const
506     {
507         return pManager_;
508     }
509 
MarkContentChange()510     void MarkContentChange()
511     {
512         contChange_ = true;
513     }
514 
ResetContChange()515     void ResetContChange()
516     {
517         contChange_ = false;
518     }
519 
GetContChange()520     bool GetContChange() const
521     {
522         return contChange_;
523     }
524 
GetShowSelect()525     bool GetShowSelect() const
526     {
527         return showSelect_;
528     }
529 
GetRecoverStart()530     int32_t GetRecoverStart() const
531     {
532         return recoverStart_;
533     }
534 
GetRecoverEnd()535     int32_t GetRecoverEnd() const
536     {
537         return recoverEnd_;
538     }
539 
540     void OnHandleAreaChanged() override;
541     void RemoveAreaChangeInner();
542 
ResetDragOption()543     void ResetDragOption() override
544     {
545         CloseSelectOverlay();
546         ResetSelection();
547     }
548 
549     virtual bool NeedShowAIDetect();
550 
GetDragRecordSize()551     int32_t GetDragRecordSize() override
552     {
553         return dragRecordSize_;
554     }
555 
ResetDragRecordSize(int32_t size)556     void ResetDragRecordSize(int32_t size)
557     {
558         dragRecordSize_ = size;
559     }
560 
561     void BindSelectionMenu(TextSpanType spanType, TextResponseType responseType, std::function<void()>& menuBuilder,
562         const SelectMenuParam& menuParam);
563 
SetTextController(const RefPtr<TextController> & controller)564     void SetTextController(const RefPtr<TextController>& controller)
565     {
566         textController_ = controller;
567     }
568 
GetTextController()569     const RefPtr<TextController>& GetTextController()
570     {
571         return textController_;
572     }
573 
574     void CloseSelectionMenu();
575 
ClearSelectionMenu()576     void ClearSelectionMenu()
577     {
578         selectionMenuMap_.clear();
579     }
580 
581     virtual const std::list<RefPtr<UINode>>& GetAllChildren() const;
582 
583     void StartVibratorByIndexChange(int32_t currentIndex, int32_t preIndex);
584 
585     void HandleSelectionChange(int32_t start, int32_t end);
586 
GetCopyOptions()587     CopyOptions GetCopyOptions() const
588     {
589         return copyOption_;
590     }
591     bool CheckClickedOnSpanOrText(RectF textContentRect, const Offset& localLocation);
592 
593     // style string
SetSpanItemChildren(const std::list<RefPtr<SpanItem>> & spans)594     void SetSpanItemChildren(const std::list<RefPtr<SpanItem>>& spans)
595     {
596         spans_ = spans;
597     }
SetSpanStringMode(bool isSpanStringMode)598     void SetSpanStringMode(bool isSpanStringMode)
599     {
600         isSpanStringMode_ = isSpanStringMode;
601     }
GetSpanStringMode()602     bool GetSpanStringMode() const
603     {
604         return isSpanStringMode_;
605     }
AllocStyledString()606     void AllocStyledString()
607     {
608         if (!styledString_) {
609             styledString_ = MakeRefPtr<MutableSpanString>(u"");
610         }
611     }
612     void SetStyledString(const RefPtr<SpanString>& value, bool closeSelectOverlay = true);
613     void SetStyledStringMultiThread(const RefPtr<SpanString>& value, bool closeSelectOverlay = true);
614     // select overlay
615     virtual int32_t GetHandleIndex(const Offset& offset) const;
616     std::u16string GetSelectedText(int32_t start, int32_t end, bool includeStartHalf = false,
617         bool includeEndHalf = false, bool getSubstrDirectly = false) const;
618     void UpdateSelectionSpanType(int32_t selectStart, int32_t selectEnd);
619     virtual void CalculateHandleOffsetAndShowOverlay(bool isUsingMouse = false);
620     void ResetSelection();
621     virtual bool IsSelectAll();
622     void HandleOnCopy();
623     virtual void HandleAIMenuOption(const std::string& labelInfo = "");
624 
625     virtual void HandleOnAskCelia();
626 
SetIsAskCeliaEnabled(bool isAskCeliaEnabled)627     void SetIsAskCeliaEnabled(bool isAskCeliaEnabled)
628     {
629         isAskCeliaEnabled_ = isAskCeliaEnabled && IsNeedAskCelia();
630     }
631 
IsAskCeliaEnabled()632     bool IsAskCeliaEnabled() const
633     {
634         return isAskCeliaEnabled_;
635     }
636 
637     void HandleOnCopySpanString();
638     virtual void HandleOnSelectAll();
639     bool IsShowTranslate();
640     bool IsShowSearch();
641     void SetTextSelectableMode(TextSelectableMode value);
642 
GetTextPaintOffset()643     OffsetF GetTextPaintOffset() const override
644     {
645         return parentGlobalOffset_;
646     }
647 
SetTextResponseType(TextResponseType type)648     void SetTextResponseType(TextResponseType type)
649     {
650         textResponseType_ = type;
651     }
652 
IsSelectedTypeChange()653     bool IsSelectedTypeChange()
654     {
655         return selectedType_.has_value() && oldSelectedType_ != selectedType_.value();
656     }
657 
CheckSelectedTypeChange()658     bool CheckSelectedTypeChange()
659     {
660         auto changed = IsSelectedTypeChange();
661         if (changed) {
662             oldSelectedType_ = selectedType_.value();
663         }
664         return changed;
665     }
666 
IsUsingMouse()667     bool IsUsingMouse()
668     {
669         return sourceType_ == SourceType::MOUSE;
670     }
671 
672     void OnSensitiveStyleChange(bool isSensitive) override;
673 
674     bool IsSetObscured() const;
675     bool IsSensitiveEnable();
676 
CopySelectionMenuParams(SelectOverlayInfo & selectInfo)677     void CopySelectionMenuParams(SelectOverlayInfo& selectInfo)
678     {
679         CopySelectionMenuParams(selectInfo, textResponseType_.value_or(TextResponseType::NONE));
680     }
681 
InitCustomSpanPlaceholderInfo(const std::vector<CustomSpanPlaceholderInfo> & customSpanPlaceholder)682     void InitCustomSpanPlaceholderInfo(const std::vector<CustomSpanPlaceholderInfo>& customSpanPlaceholder)
683     {
684         customSpanPlaceholder_ = customSpanPlaceholder;
685     }
686 
GetCustomSpanPlaceholderInfo()687     std::vector<CustomSpanPlaceholderInfo> GetCustomSpanPlaceholderInfo()
688     {
689         return customSpanPlaceholder_;
690     }
691 
ClearCustomSpanPlaceholderInfo()692     void ClearCustomSpanPlaceholderInfo()
693     {
694         customSpanPlaceholder_.clear();
695     }
696 
GetChildNodes()697     const std::list<RefPtr<UINode>>& GetChildNodes() const
698     {
699         return childNodes_;
700     }
701 
702     // add for capi NODE_TEXT_CONTENT_WITH_STYLED_STRING
SetExternalParagraph(void * paragraph)703     void SetExternalParagraph(void* paragraph)
704     {
705         ACE_TEXT_SCOPED_TRACE("SetExternalParagraph");
706         externalParagraph_ = paragraph;
707     }
708 
GetExternalParagraph()709     const std::optional<void*>& GetExternalParagraph()
710     {
711         return externalParagraph_;
712     }
713 
714     void SetExternalSpanItem(const std::list<RefPtr<SpanItem>>& spans);
715     void SetExternalSpanItemMultiThread(const std::list<RefPtr<SpanItem>>& spans);
716 
SetExternalParagraphStyle(std::optional<ParagraphStyle> paragraphStyle)717     void SetExternalParagraphStyle(std::optional<ParagraphStyle> paragraphStyle)
718     {
719         externalParagraphStyle_ = paragraphStyle;
720     }
721 
GetTextStyle()722     TextStyle GetTextStyle()
723     {
724         return textStyle_.value_or(TextStyle());
725     }
726 
727     bool DidExceedMaxLines() const override;
728 
GetExternalParagraphStyle()729     std::optional<ParagraphStyle> GetExternalParagraphStyle()
730     {
731         return externalParagraphStyle_;
732     }
733 
734     size_t GetLineCount() const override;
735     TextLineMetrics GetLineMetrics(int32_t lineNumber) override;
736     std::vector<ParagraphManager::TextBox> GetRectsForRange(int32_t start, int32_t end,
737         RectHeightStyle heightStyle, RectWidthStyle widthStyle) override;
738     PositionWithAffinity GetGlyphPositionAtCoordinate(int32_t x, int32_t y) override;
739 
740     void OnSelectionMenuOptionsUpdate(const NG::OnCreateMenuCallback&& onCreateMenuCallback,
741         const NG::OnMenuItemClickCallback&& onMenuItemClick, const NG::OnPrepareMenuCallback&& onPrepareMenuCallback);
742 
OnCreateMenuCallbackUpdate(const NG::OnCreateMenuCallback && onCreateMenuCallback)743     void OnCreateMenuCallbackUpdate(const NG::OnCreateMenuCallback&& onCreateMenuCallback)
744     {
745         selectOverlay_->OnCreateMenuCallbackUpdate(std::move(onCreateMenuCallback));
746     }
747 
OnMenuItemClickCallbackUpdate(const NG::OnMenuItemClickCallback && onMenuItemClick)748     void OnMenuItemClickCallbackUpdate(const NG::OnMenuItemClickCallback&& onMenuItemClick)
749     {
750         selectOverlay_->OnMenuItemClickCallbackUpdate(std::move(onMenuItemClick));
751     }
752 
OnPrepareMenuCallbackUpdate(const NG::OnPrepareMenuCallback && onPrepareMenuCallback)753     void OnPrepareMenuCallbackUpdate(const NG::OnPrepareMenuCallback&& onPrepareMenuCallback)
754     {
755         selectOverlay_->OnPrepareMenuCallbackUpdate(std::move(onPrepareMenuCallback));
756     }
757 
758     void OnFrameNodeChanged(FrameNodeChangeInfoFlag flag) override;
759 
UpdateParentGlobalOffset()760     void UpdateParentGlobalOffset()
761     {
762         parentGlobalOffset_ = GetParentGlobalOffset();
763     }
764 
SetPrintInfo(const std::string & area,const OffsetF & paintOffset)765     void SetPrintInfo(const std::string& area, const OffsetF& paintOffset)
766     {
767         paintInfo_ = area + paintOffset.ToString();
768     }
769 
770     void DumpRecord(const std::string& record, bool stateChange = false)
771     {
772         if (stateChange || frameRecord_.length() > MAX_SIZE_OF_LOG) {
773             frameRecord_.clear();
774         }
775         frameRecord_.append("[" + record + "]");
776     }
777 
778     void LogForFormRender(const std::string& logTag);
779 
SetIsUserSetResponseRegion(bool isUserSetResponseRegion)780     void SetIsUserSetResponseRegion(bool isUserSetResponseRegion)
781     {
782         isUserSetResponseRegion_ = isUserSetResponseRegion;
783     }
784 
785     size_t GetSubComponentInfos(std::vector<SubComponentInfo>& subComponentInfos);
786 
787     void UpdateFontColor(const Color& value);
788     void BeforeCreatePaintWrapper() override;
789 
790     void OnTextOverflowChanged();
791 
792     void MarkDirtyNodeRender();
793     void MarkDirtyNodeMeasure();
794     void ChangeHandleHeight(const GestureEvent& event, bool isFirst, bool isOverlayMode);
795     void ChangeFirstHandleHeight(const Offset& touchOffset, RectF& handleRect);
796     void ChangeSecondHandleHeight(const Offset& touchOffset, RectF& handleRect);
797     virtual void CalculateDefaultHandleHeight(float& height);
798 
GetSystemTimestamp()799     uint64_t GetSystemTimestamp()
800     {
801         return static_cast<uint64_t>(
802             std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
803                 .count());
804     }
805 
SetEnableHapticFeedback(bool isEnabled)806     void SetEnableHapticFeedback(bool isEnabled)
807     {
808         isEnableHapticFeedback_ = isEnabled;
809     }
810 
811     bool HasContent();
812 
IsEnabledObscured()813     virtual bool IsEnabledObscured() const
814     {
815         return true;
816     }
817     void SetupMagnifier();
818     void DoTextSelectionTouchCancel() override;
819 
820     virtual Color GetUrlSpanColor();
821     void BeforeSyncGeometryProperties(const DirtySwapConfig& config) override;
822 
RegisterAfterLayoutCallback(std::function<void ()> callback)823     void RegisterAfterLayoutCallback(std::function<void()> callback)
824     {
825         afterLayoutCallback_ = callback;
826     }
827 
UnRegisterAfterLayoutCallback()828     void UnRegisterAfterLayoutCallback()
829     {
830         afterLayoutCallback_ = std::nullopt;
831     }
832 
GetOrCreateMagnifier()833     RefPtr<MagnifierController> GetOrCreateMagnifier()
834     {
835         if (!magnifierController_) {
836             magnifierController_ = MakeRefPtr<MagnifierController>(WeakClaim(this));
837         }
838         return magnifierController_;
839     }
840 
841     void UnRegisterResource(const std::string& key) override;
EmplaceSymbolColorIndex(int32_t index)842     void EmplaceSymbolColorIndex(int32_t index)
843     {
844         symbolFontColorResObjIndexArr.emplace_back(index);
845     }
846 
847     std::string GetCaretColor() const;
848     std::string GetSelectedBackgroundColor() const;
849 
850     void ResetCustomFontColor();
851     void OnColorConfigurationUpdate() override;
852     bool OnThemeScopeUpdate(int32_t themeScopeId) override;
853     void OnWindowSizeChanged(int32_t width, int32_t height, WindowSizeChangeReason type) override;
854 
855     bool GetOriginCaretPosition(OffsetF& offset) const;
856     void ResetOriginCaretPosition();
857     bool RecordOriginCaretPosition(const OffsetF& offset);
858     TextDragInfo CreateTextDragInfo();
859 
SetIsShowAIMenuOption(bool isShowAIMenuOption)860     void SetIsShowAIMenuOption(bool isShowAIMenuOption)
861     {
862         isShowAIMenuOption_ = isShowAIMenuOption;
863     }
864 
IsShowAIMenuOption()865     bool IsShowAIMenuOption() const
866     {
867         return isShowAIMenuOption_;
868     }
869 
SetAIItemOption(const std::unordered_map<TextDataDetectType,AISpan> & aiMenuOptions)870     void SetAIItemOption(const std::unordered_map<TextDataDetectType, AISpan>& aiMenuOptions)
871     {
872         aiMenuOptions_ = aiMenuOptions;
873     }
874 
GetAIItemOption()875     const std::unordered_map<TextDataDetectType, AISpan>& GetAIItemOption() const
876     {
877         return aiMenuOptions_;
878     }
879     virtual void UpdateAIMenuOptions();
880     bool PrepareAIMenuOptions(std::unordered_map<TextDataDetectType, AISpan>& aiMenuOptions);
881     bool IsAiSelected();
882     virtual RefPtr<FrameNode> CreateAIEntityMenu();
883     virtual bool CheckAIPreviewMenuEnable();
884     void InitAiSelection(const Offset& globalOffset);
885     bool CanAIEntityDrag() override;
886     RefPtr<PreviewMenuController> GetOrCreatePreviewMenuController();
887     void ResetAISelected(AIResetSelectionReason reason) override;
888     std::function<void()> GetPreviewMenuAISpanClickrCallback(const AISpan& aiSpan);
889 
890     void ShowAIEntityMenuForCancel() override;
891     bool IsPreviewMenuShow() override;
892     void DragNodeDetachFromParent();
893     AISpan GetSelectedAIData();
894     std::pair<bool, bool> GetCopyAndSelectable();
895     std::pair<int32_t, int32_t> GetSelectedStartAndEnd();
896 
GetTextEffect()897     RefPtr<TextEffect> GetTextEffect()
898     {
899         return textEffect_;
900     }
901     RefPtr<TextEffect> GetOrCreateTextEffect(const std::u16string& content, bool& needUpdateTypography);
902     void RelayoutResetOrUpdateTextEffect();
903     void ResetTextEffect();
904     bool ResetTextEffectBeforeLayout(bool onlyReset = true);
IsNeedAskCelia()905     bool IsNeedAskCelia() const
906     {
907         // placeholder and symbol not support
908         auto start = GetTextSelector().GetTextStart();
909         auto end = GetTextSelector().GetTextEnd();
910         auto content = UtfUtils::Str16DebugToStr8(GetSelectedText(start, end));
911         return !std::regex_match(content, std::regex("^\\s*$"));
912     }
UpdateTextSelectorSecondHandle(const RectF & rect)913     void UpdateTextSelectorSecondHandle(const RectF& rect)
914     {
915         textSelector_.secondHandle = rect;
916     }
IsEnableMatchParent()917     bool IsEnableMatchParent() override
918     {
919         return true;
920     }
921 
922 protected:
GetClickedSpanPosition()923     int32_t GetClickedSpanPosition()
924     {
925         return clickedSpanPosition_;
926     }
927     void OnAttachToFrameNode() override;
928     void OnAttachToFrameNodeMultiThread();
929     void OnDetachFromFrameNode(FrameNode* node) override;
930     void OnDetachFromFrameNodeMultiThread(FrameNode* node);
931     void OnAfterModifyDone() override;
932     virtual bool ClickAISpan(const PointF& textOffset, const AISpan& aiSpan);
933     virtual void InitAISpanHoverEvent();
934     virtual void HandleAISpanHoverEvent(const MouseInfo& info);
935     void OnHover(bool isHover);
936     void InitSpanMouseEvent();
937     HoverInfo ConvertHoverInfoFromMouseInfo(const MouseInfo& info) const;
938     void HandleSpanMouseEvent(const MouseInfo& info);
939     void TriggerSpanOnHoverEvent(const HoverInfo& info, const RefPtr<SpanItem>& item, bool isOnHover);
940     void TriggerSpansOnHover(const HoverInfo& info, const PointF& textOffset);
941     void ExitSpansForOnHoverEvent(const HoverInfo& info);
942     bool HasSpanOnHoverEvent();
943     void InitMouseEvent();
944     void InitFocusEvent();
945     void InitHoverEvent();
946     void AddIsFocusActiveUpdateEvent();
947     void RemoveIsFocusActiveUpdateEvent();
948     void OnIsFocusActiveUpdate(bool isFocusAcitve);
949     void RecoverCopyOption();
950     void InitCopyOption(const RefPtr<GestureEventHub>& gestureEventHub, const RefPtr<EventHub>& eventHub);
951     void RecoverSelection();
HandleOnCameraInput()952     virtual void HandleOnCameraInput() {};
953     void InitSelection(const Offset& pos);
954     void GetIndexByOffset(const Offset& pos, int32_t& extend);
955     void StartVibratorByLongPress();
956     void HandleLongPress(GestureEvent& info);
957     void HandleClickEvent(GestureEvent& info);
958     void HandleSingleClickEvent(GestureEvent& info);
959     void HandleClickAISpanEvent(const PointF& info);
960     void HandleDoubleClickEvent(GestureEvent& info);
961     void CheckOnClickEvent(GestureEvent& info);
962     void HandleClickOnTextAndSpan(GestureEvent& info);
963     bool TryLinkJump(const RefPtr<SpanItem>& span);
964     void ActTextOnClick(GestureEvent& info);
965     RectF CalcAIMenuPosition(const AISpan& aiSpan, const CalculateHandleFunc& calculateHandleFunc);
AdjustAIEntityRect(RectF & aiRect)966     virtual void AdjustAIEntityRect(RectF& aiRect) {}
967     bool ShowAIEntityMenu(const AISpan& aiSpan, const CalculateHandleFunc& calculateHandleFunc = nullptr,
968         const ShowSelectOverlayFunc& showSelectOverlayFunc = nullptr);
969     void SetOnClickMenu(const AISpan& aiSpan, const CalculateHandleFunc& calculateHandleFunc,
970         const ShowSelectOverlayFunc& showSelectOverlayFunc);
971     bool IsDraggable(const Offset& localOffset);
972     virtual void InitClickEvent(const RefPtr<GestureEventHub>& gestureHub);
973     virtual void ProcessOverlay(const OverlayRequest& request = OverlayRequest());
974     void ShowSelectOverlay(const OverlayRequest& = OverlayRequest());
975     bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override;
976     virtual void UpdateSelectorOnHandleMove(const OffsetF& localOffset, float handleHeight, bool isFirstHandle);
977     void CalcCaretMetricsByPosition(
978         int32_t extent, CaretMetricsF& caretCaretMetric, TextAffinity textAffinity = TextAffinity::DOWNSTREAM);
979     void UpdateSelectionType(const SelectionInfo& selection);
980     void CopyBindSelectionMenuParams(SelectOverlayInfo& selectInfo, std::shared_ptr<SelectionMenuParams> menuParams);
981     virtual void OnHandleSelectionMenuCallback(
982         SelectionMenuCalblackId callbackId, std::shared_ptr<SelectionMenuParams> menuParams);
983     bool IsSelectedBindSelectionMenu();
984     bool CheckAndClick(const RefPtr<SpanItem>& item);
985     bool CalculateClickedSpanPosition(const PointF& textOffset);
986     void HiddenMenu();
987     std::shared_ptr<SelectionMenuParams> GetMenuParams(TextSpanType type, TextResponseType responseType);
988     void AddUdmfTxtPreProcessor(const ResultObject src, ResultObject& result, bool isAppend);
989     void InitKeyEvent();
990     void UpdateShiftFlag(const KeyEvent& keyEvent);
991     bool HandleKeyEvent(const KeyEvent& keyEvent);
992     void HandleOnSelect(KeyCode code);
993     void HandleSelectionUp();
994     void HandleSelectionDown();
995     void HandleSelection(bool isEmojiStart, int32_t end);
996     double GetTextHeight(int32_t index, bool isNextLine);
997     int32_t GetActualTextLength();
998     bool IsSelectableAndCopy();
999     void SetResponseRegion(const SizeF& frameSize, const SizeF& boundsSize);
1000     virtual bool CanStartAITask() const;
1001 
1002     void MarkDirtySelf();
1003     void OnAttachToMainTree() override;
1004     void OnAttachToMainTreeMultiThread();
1005     void OnDetachFromMainTree() override;
1006     void OnDetachFromMainTreeMultiThread();
1007 
CreateMultipleClickRecognizer()1008     void CreateMultipleClickRecognizer()
1009     {
1010         if (!multipleClickRecognizer_) {
1011             multipleClickRecognizer_ = MakeRefPtr<MultipleClickRecognizer>();
1012         }
1013     }
1014 
1015     bool SetActionExecSubComponent();
1016     void GetSubComponentInfosForAISpans(std::vector<SubComponentInfo>& subComponentInfos);
1017     void GetSubComponentInfosForSpans(std::vector<SubComponentInfo>& subComponentInfos);
1018     bool ExecSubComponent(int32_t spanId);
1019     void AddSubComponentInfosByDataDetectorForSpan(std::vector<SubComponentInfo>& subComponentInfos,
1020         const RefPtr<SpanItem>& span);
1021     void AddSubComponentInfoForAISpan(std::vector<SubComponentInfo>& subComponentInfos, const std::string& content,
1022         const AISpan& aiSpan);
1023     void AddSubComponentInfoForSpan(std::vector<SubComponentInfo>& subComponentInfos, const std::string& content,
1024         const RefPtr<SpanItem>& span);
1025 
1026     int32_t GetTouchIndex(const OffsetF& offset) override;
1027     void OnTextGestureSelectionUpdate(int32_t start, int32_t end, const TouchEventInfo& info) override;
1028     void OnTextGestureSelectionEnd(const TouchLocationInfo& locationInfo) override;
1029     void StartGestureSelection(int32_t start, int32_t end, const Offset& startOffset) override;
1030 
1031     void SetImageNodeGesture(RefPtr<ImageSpanNode> imageNode);
1032     virtual std::pair<int32_t, int32_t> GetStartAndEnd(int32_t start, const RefPtr<SpanItem>& spanItem);
1033     void HandleSpanStringTouchEvent(TouchEventInfo& info);
1034     void ShowAIEntityPreviewMenuTimer();
1035     void PreviewDragNodeHideAnimation();
1036     bool enabled_ = true;
1037     Status status_ = Status::NONE;
1038     bool contChange_ = false;
1039     int32_t recoverStart_ = 0;
1040     int32_t recoverEnd_ = 0;
1041     bool aiSpanHoverEventInitialized_ = false;
1042     bool mouseEventInitialized_ = false;
1043     bool spanMouseEventInitialized_ = false;
1044     bool isHover_ = false;
1045     bool panEventInitialized_ = false;
1046     bool clickEventInitialized_ = false;
1047     bool touchEventInitialized_ = false;
1048     bool focusInitialized_ = false;
1049     bool hoverInitialized_ = false;
1050     bool isSpanStringMode_ = false;
1051     RefPtr<MutableSpanString> styledString_;
1052     bool keyEventInitialized_ = false;
1053     bool isShowAIMenuOption_ = false;
1054     bool isAskCeliaEnabled_ = false;
1055     std::unordered_map<TextDataDetectType, AISpan> aiMenuOptions_;
1056 
1057     RefPtr<FrameNode> dragNode_;
1058     RefPtr<LongPressEvent> longPressEvent_;
1059     // Deprecated: Use the selectOverlay_ instead.
1060     RefPtr<SelectOverlayProxy> selectOverlayProxy_;
1061     RefPtr<Clipboard> clipboard_;
1062     RefPtr<TextContentModifier> contentMod_;
1063     RefPtr<TextOverlayModifier> overlayMod_;
1064     CopyOptions copyOption_ = CopyOptions::None;
1065     std::vector<int32_t> symbolFontColorResObjIndexArr;
1066 
1067     std::u16string textForDisplay_;
1068     std::string paintInfo_ = "NA";
1069     std::string frameRecord_ = "NA";
1070     std::optional<TextStyle> textStyle_;
1071     std::list<RefPtr<SpanItem>> spans_;
1072     mutable std::list<RefPtr<UINode>> childNodes_;
1073     float baselineOffset_ = 0.0f;
1074     int32_t placeholderCount_ = 0;
1075     SelectMenuInfo selectMenuInfo_;
1076     std::vector<RectF> dragBoxes_;
1077     std::map<std::pair<TextSpanType, TextResponseType>, std::shared_ptr<SelectionMenuParams>> selectionMenuMap_;
1078     std::optional<TextSpanType> selectedType_;
1079     SourceType sourceType_ = SourceType::NONE;
1080     std::function<void(bool)> isFocusActiveUpdateEvent_;
1081 
1082     friend class TextContentModifier;
1083     // properties for AI
1084     bool textDetectEnable_ = false;
1085     RefPtr<DataDetectorAdapter> dataDetectorAdapter_;
1086 
1087     OffsetF parentGlobalOffset_;
1088     std::optional<TextResponseType> textResponseType_;
1089 
1090     struct SubComponentInfoEx {
1091         std::optional<AISpan> aiSpan;
1092         WeakPtr<SpanItem> span;
1093     };
1094     std::vector<SubComponentInfoEx> subComponentInfos_;
1095     virtual std::vector<RectF> GetSelectedRects(int32_t start, int32_t end);
1096     MouseFormat currentMouseStyle_ = MouseFormat::DEFAULT;
1097     RefPtr<MultipleClickRecognizer> multipleClickRecognizer_;
1098     bool ShowShadow(const PointF& textOffset, const Color& color);
1099     virtual PointF GetTextOffset(const Offset& localLocation, const RectF& contentRect);
1100     bool hasUrlSpan_ = false;
1101     WeakPtr<PipelineContext> pipeline_;
1102     void UpdatePropertyImpl(const std::string& key, RefPtr<PropertyValueBase> value) override;
1103     bool IsSupportAskCelia();
1104 
1105 private:
1106     void InitLongPressEvent(const RefPtr<GestureEventHub>& gestureHub);
1107     void HandleSpanLongPressEvent(GestureEvent& info);
1108     void HandleMouseEvent(const MouseInfo& info);
1109     void OnHandleTouchUp();
1110     void InitTouchEvent();
1111     void HandleTouchEvent(const TouchEventInfo& info);
1112     void ActSetSelection(int32_t start, int32_t end);
1113     virtual bool IsShowHandle();
1114     void InitUrlMouseEvent();
1115     void InitUrlTouchEvent();
1116     void HandleUrlMouseEvent(const MouseInfo& info);
1117     void HandleUrlTouchEvent(const TouchEventInfo& info);
1118     void InitSpanStringTouchEvent();
1119     void URLOnHover(bool isHover);
1120     bool HandleUrlClick();
1121     Color GetUrlHoverColor();
1122     Color GetUrlPressColor();
1123     void SetAccessibilityAction();
1124     void SetSpanEventFlagValue(
1125         const RefPtr<UINode>& code, bool& isSpanHasClick, bool& isSpanHasLongPress);
1126     void CollectSymbolSpanNodes(const RefPtr<SpanNode>& spanNode, const RefPtr<UINode>& node);
1127     void CollectSpanNodes(std::stack<SpanNodeInfo> nodes, bool& isSpanHasClick, bool& isSpanHasLongPress);
1128     void CollectTextSpanNodes(const RefPtr<SpanNode>& child, bool& isSpanHasClick, bool& isSpanHasLongPress);
1129     void UpdateContainerChildren(const RefPtr<UINode>& parent, const RefPtr<UINode>& child);
1130     RefPtr<RenderContext> GetRenderContext();
1131     void UpdateRectForSymbolShadow(RectF& rect, float offsetX, float offsetY, float blurRadius) const;
1132     void ProcessBoundRectByTextShadow(RectF& rect);
1133     void FireOnSelectionChange(int32_t start, int32_t end);
1134     void FireOnMarqueeStateChange(const TextMarqueeState& state);
1135     void HandleMouseLeftButton(const MouseInfo& info, const Offset& textOffset);
1136     void HandleMouseRightButton(const MouseInfo& info, const Offset& textOffset);
1137     void HandleMouseLeftPressAction(const MouseInfo& info, const Offset& textOffset);
1138     void HandleMouseLeftReleaseAction(const MouseInfo& info, const Offset& textOffset);
1139     void HandleMouseLeftMoveAction(const MouseInfo& info, const Offset& textOffset);
1140     void InitSpanItemEvent(bool& isSpanHasClick, bool& isSpanHasLongPress);
1141     void InitSpanItem(std::stack<SpanNodeInfo> nodes);
1142     int32_t GetSelectionSpanItemIndex(const MouseInfo& info);
1143     void CopySelectionMenuParams(SelectOverlayInfo& selectInfo, TextResponseType responseType);
1144     void ProcessBoundRectByTextMarquee(RectF& rect);
1145     ResultObject GetBuilderResultObject(RefPtr<UINode> uiNode, int32_t index, int32_t start, int32_t end);
1146     void CreateModifier();
1147     void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override;
1148     void ToTreeJson(std::unique_ptr<JsonValue>& json, const InspectorConfig& config) const override;
1149     void ProcessOverlayAfterLayout();
1150     // SpanString
1151     void MountImageNode(const RefPtr<ImageSpanItem>& imageItem);
1152     void ProcessSpanString();
1153     // to check if drag is in progress
SetCurrentDragTool(SourceTool tool)1154     void SetCurrentDragTool(SourceTool tool)
1155     {
1156         lastDragTool_ = tool;
1157     }
1158 
GetContextParam()1159     std::optional<RenderContext::ContextParam> GetContextParam() const override
1160     {
1161         return RenderContext::ContextParam { .type = RenderContext::ContextType::CANVAS,
1162                                              .surfaceName = std::nullopt };
1163     }
1164 
GetCurrentDragTool()1165     SourceTool GetCurrentDragTool() const
1166     {
1167         return lastDragTool_;
1168     }
1169     Offset ConvertGlobalToLocalOffset(const Offset& globalOffset);
1170     Offset ConvertLocalOffsetToParagraphOffset(const Offset& offset);
1171     void ProcessMarqueeVisibleAreaCallback();
1172     void ParseOriText(const std::u16string& currentText);
1173     bool IsMarqueeOverflow() const;
1174     virtual void ResetAfterTextChange();
1175     bool GlobalOffsetInSelectedArea(const Offset& globalOffset);
1176     bool LocalOffsetInSelectedArea(const Offset& localOffset);
1177     bool LocalOffsetInRange(const Offset& localOffset, int32_t start, int32_t end);
1178     void HandleOnCopyWithoutSpanString(const std::string& pasteData);
1179     void CheckPressedSpanPosition(const Offset& textOffset);
1180     void EncodeTlvNoChild(const std::string& pasteData, std::vector<uint8_t>& buff);
1181     void EncodeTlvFontStyleNoChild(std::vector<uint8_t>& buff);
1182     void EncodeTlvTextLineStyleNoChild(std::vector<uint8_t>& buff);
1183     void EncodeTlvSpanItems(const std::string& pasteData, std::vector<uint8_t>& buff);
1184     RefPtr<SpanItem> FindSpanItemByOffset(const PointF& textOffset);
1185     void UpdateMarqueeStartPolicy();
1186     void PauseSymbolAnimation();
1187     void ResumeSymbolAnimation();
1188     bool IsLocationInFrameRegion(const Offset& localOffset) const;
1189     void RegisterFormVisibleChangeCallback();
1190     void RegisterVisibleAreaChangeCallback();
1191     void HandleFormVisibleChange(bool visible);
1192     void RemoveFormVisibleChangeCallback(int32_t id);
1193     void GetSpanItemAttributeUseForHtml(NG::FontStyle& fontStyle,
1194         NG::TextLineStyle& textLineStyle, const std::optional<TextStyle>& textStyle);
1195     RefPtr<TaskExecutor> GetTaskExecutorItem();
1196     void AsyncHandleOnCopySpanStringHtml(RefPtr<SpanString>& subSpanString);
1197     void AsyncHandleOnCopyWithoutSpanStringHtml(const std::string& pasteData);
1198     std::list<RefPtr<SpanItem>> GetSpanSelectedContent();
1199     bool RegularMatchNumbers(const std::u16string& content);
1200     void ResetMouseLeftPressedState();
1201 
1202     bool isMeasureBoundary_ = false;
1203     bool isMousePressed_ = false;
1204     bool leftMousePressed_ = false;
1205     bool isCustomFont_ = false;
1206     bool blockPress_ = false;
1207     bool isDoubleClick_ = false;
1208     bool isSensitive_ = false;
1209     bool hasSpanStringLongPressEvent_ = false;
1210     int32_t clickedSpanPosition_ = -1;
1211     Offset leftMousePressedOffset_;
1212     bool isEnableHapticFeedback_ = true;
1213     bool mouseUpAndDownPointChange_ = false;
1214 
1215     bool urlTouchEventInitialized_ = false;
1216     bool urlMouseEventInitialized_ = false;
1217     bool spanStringTouchInitialized_ = false;
1218     bool moveOverClickThreshold_ = false;
1219     bool isMarqueeRunning_ = false;
1220 
1221     RefPtr<ParagraphManager> pManager_;
1222     RefPtr<TextEffect> textEffect_;
1223     std::vector<int32_t> placeholderIndex_;
1224     std::vector<RectF> rectsForPlaceholders_;
1225     OffsetF imageOffset_;
1226 
1227     OffsetF contentOffset_;
1228     GestureEventFunc onClick_;
1229     double distanceThreshold_ = std::numeric_limits<double>::infinity();
1230     RefPtr<DragWindow> dragWindow_;
1231     RefPtr<DragDropProxy> dragDropProxy_;
1232     RefPtr<PreviewMenuController> previewController_;
1233     std::optional<int32_t> surfaceChangedCallbackId_;
1234     SourceTool lastDragTool_ = SourceTool::UNKNOWN;
1235     std::optional<int32_t> surfacePositionChangedCallbackId_;
1236     int32_t dragRecordSize_ = -1;
1237     RefPtr<TextController> textController_;
1238     TextSpanType oldSelectedType_ = TextSpanType::NONE;
1239     bool isShowMenu_ = true;
1240     RefPtr<TextSelectOverlay> selectOverlay_;
1241     std::vector<WeakPtr<FrameNode>> imageNodeList_;
1242     bool isDetachFromMainTree_ = false;
1243     std::vector<CustomSpanPlaceholderInfo> customSpanPlaceholder_;
1244     std::optional<void*> externalParagraph_;
1245     std::optional<ParagraphStyle> externalParagraphStyle_;
1246     bool isUserSetResponseRegion_ = false;
1247     WeakPtr<ScrollablePattern> scrollableParent_;
1248     ACE_DISALLOW_COPY_AND_MOVE(TextPattern);
1249     std::optional<std::function<void()>> afterLayoutCallback_;
1250     Offset lastLeftMouseMoveLocation_;
1251     bool isAutoScrollByMouse_ = false;
1252     bool shiftFlag_ = false;
1253     std::string textDetectTypes_ = "";
1254     // Used to record original caret position for "shift + up/down"
1255     // Less than 0 is invalid, initialized as invalid in constructor
1256     OffsetF originCaretPosition_;
1257     bool hasRegisterFormVisibleCallback_ = false;
1258     // params for ai/url entity dragging
1259     // left mouse click(lastLeftMouseClickStyle_ = true) ==> dragging(isTryEntityDragging_ = true)
1260     MouseFormat lastLeftMouseClickStyle_ = MouseFormat::DEFAULT;
1261     bool isTryEntityDragging_ = false;
1262     bool isRegisteredAreaCallback_ = false;
1263 
1264     // ----- multi thread state variables -----
1265     bool setTextDetectEnableMultiThread_ = false;
1266     bool setExternalSpanItemMultiThread_ = false;
1267     bool closeSelectOverlayMultiThread_ = false;
1268     bool closeSelectOverlayMultiThreadValue_ = false;
1269     bool setTextSelectionMultiThread_ = true;
1270     int32_t setTextSelectionMultiThreadValue0_ = -1;
1271     int32_t setTextSelectionMultiThreadValue1_ = -1;
1272     // ----- multi thread state variables end -----
1273 };
1274 } // namespace OHOS::Ace::NG
1275 
1276 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_TEXT_PATTERN_H
1277