• 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_PATTERN_TEXT_FIELD_TEXT_FIELD_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_FIELD_TEXT_FIELD_PATTERN_H
18 
19 #include <cstdint>
20 #include <optional>
21 #include <queue>
22 #include <string>
23 #include <utility>
24 #include <vector>
25 
26 #include "base/geometry/ng/offset_t.h"
27 #include "base/geometry/ng/rect_t.h"
28 #include "base/geometry/rect.h"
29 #include "base/memory/referenced.h"
30 #include "base/mousestyle/mouse_style.h"
31 #include "base/view_data/view_data_wrap.h"
32 #include "core/common/clipboard/clipboard.h"
33 #include "core/common/ime/text_edit_controller.h"
34 #include "core/common/ime/text_input_action.h"
35 #include "core/common/ime/text_input_client.h"
36 #include "core/common/ime/text_input_configuration.h"
37 #include "core/common/ime/text_input_connection.h"
38 #include "core/common/ime/text_input_formatter.h"
39 #include "core/common/ime/text_input_proxy.h"
40 #include "core/common/ime/text_input_type.h"
41 #include "core/common/ime/text_selection.h"
42 #include "core/components_ng/base/frame_node.h"
43 #include "core/components_ng/image_provider/image_loading_context.h"
44 #include "core/components_ng/pattern/pattern.h"
45 #include "core/components_ng/pattern/scroll/inner/scroll_bar.h"
46 #include "core/components_ng/pattern/scroll_bar/proxy/scroll_bar_proxy.h"
47 #include "core/components_ng/pattern/scrollable/scrollable_pattern.h"
48 #include "core/components_ng/pattern/text/text_base.h"
49 #include "core/components_ng/pattern/text/text_menu_extension.h"
50 #include "core/components_ng/pattern/text_area/text_area_layout_algorithm.h"
51 #include "core/components_ng/pattern/text_drag/text_drag_base.h"
52 #include "core/components_ng/pattern/text_field/content_controller.h"
53 #include "core/components_ng/pattern/text_field/magnifier_controller.h"
54 #include "core/components_ng/pattern/text_field/text_editing_value_ng.h"
55 #include "core/components_ng/pattern/text_field/text_field_accessibility_property.h"
56 #include "core/components_ng/pattern/text_field/text_field_controller.h"
57 #include "core/components_ng/pattern/text_field/text_field_event_hub.h"
58 #include "core/components_ng/pattern/text_field/text_field_layout_property.h"
59 #include "core/components_ng/pattern/text_field/text_field_paint_method.h"
60 #include "core/components_ng/pattern/text_field/text_field_paint_property.h"
61 #include "core/components_ng/pattern/text_field/text_input_response_area.h"
62 #include "core/components_ng/pattern/text_field/text_select_controller.h"
63 #include "core/components_ng/pattern/text_field/text_selector.h"
64 #include "core/components_ng/pattern/text_input/text_input_layout_algorithm.h"
65 #include "core/components_ng/property/property.h"
66 
67 #if not defined(ACE_UNITTEST)
68 #if defined(ENABLE_STANDARD_INPUT)
69 #include "commonlibrary/c_utils/base/include/refbase.h"
70 
71 namespace OHOS::MiscServices {
72 class OnTextChangedListener;
73 struct TextConfig;
74 } // namespace OHOS::MiscServices
75 #endif
76 #endif
77 
78 namespace OHOS::Ace::NG {
79 
80 enum class FocuseIndex { TEXT = 0, CANCEL, UNIT };
81 
82 enum class SelectionMode { SELECT, SELECT_ALL, NONE };
83 
84 enum class DragStatus { DRAGGING, ON_DROP, NONE };
85 
86 enum class CaretStatus { SHOW, HIDE, NONE };
87 
88 enum class InputOperation {
89     INSERT,
90     DELETE_BACKWARD,
91     DELETE_FORWARD,
92     CURSOR_UP,
93     CURSOR_DOWN,
94     CURSOR_LEFT,
95     CURSOR_RIGHT
96 };
97 
98 enum {
99     ACTION_SELECT_ALL, // Smallest code unit.
100     ACTION_UNDO,
101     ACTION_REDO,
102     ACTION_CUT,
103     ACTION_COPY,
104     ACTION_PASTE,
105     ACTION_SHARE,
106     ACTION_PASTE_AS_PLAIN_TEXT,
107     ACTION_REPLACE,
108     ACTION_ASSIST,
109     ACTION_AUTOFILL,
110 };
111 
112 struct PasswordModeStyle {
113     Color bgColor;
114     Color textColor;
115     BorderWidthProperty borderwidth;
116     BorderColorProperty borderColor;
117     BorderRadiusProperty radius;
118     PaddingProperty padding;
119     MarginProperty margin;
120 };
121 
122 struct PreState {
123     Color textColor;
124     Color bgColor;
125     BorderRadiusProperty radius;
126     BorderWidthProperty borderWidth;
127     BorderColorProperty borderColor;
128     PaddingProperty padding;
129     MarginProperty margin;
130     RectF frameRect;
131     bool setHeight = false;
132     bool saveState = false;
133     bool hasBorderColor = false;
134 };
135 
136 struct ShowSelectOverlayParams {
137     std::optional<RectF> firstHandle;
138     std::optional<RectF> secondHandle;
139     bool animation = false;
140     bool isShowMenu = true;
141     bool isUpdateMenu = true;
142 };
143 
144 class TextFieldPattern : public ScrollablePattern,
145                          public TextDragBase,
146                          public ValueChangeObserver,
147                          public TextInputClient,
148                          public TextBase {
149     DECLARE_ACE_TYPE(TextFieldPattern, ScrollablePattern, TextDragBase, ValueChangeObserver, TextInputClient, TextBase);
150 
151 public:
152     TextFieldPattern();
153     ~TextFieldPattern() override;
154 
155     // TextField needs softkeyboard, override function.
NeedSoftKeyboard()156     bool NeedSoftKeyboard() const override
157     {
158         return true;
159     }
160 
GetNeedToRequestKeyboardOnFocus()161     bool GetNeedToRequestKeyboardOnFocus() const
162     {
163         return needToRequestKeyboardOnFocus_;
164     }
165 
166     bool CheckBlurReason();
167 
168     RefPtr<NodePaintMethod> CreateNodePaintMethod() override;
169 
CreateLayoutProperty()170     RefPtr<LayoutProperty> CreateLayoutProperty() override
171     {
172         return MakeRefPtr<TextFieldLayoutProperty>();
173     }
174 
CreateEventHub()175     RefPtr<EventHub> CreateEventHub() override
176     {
177         return MakeRefPtr<TextFieldEventHub>();
178     }
179 
CreatePaintProperty()180     RefPtr<PaintProperty> CreatePaintProperty() override
181     {
182         return MakeRefPtr<TextFieldPaintProperty>();
183     }
184 
CreateAccessibilityProperty()185     RefPtr<AccessibilityProperty> CreateAccessibilityProperty() override
186     {
187         return MakeRefPtr<TextFieldAccessibilityProperty>();
188     }
189 
CreateLayoutAlgorithm()190     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
191     {
192         if (IsTextArea()) {
193             return MakeRefPtr<TextAreaLayoutAlgorithm>();
194         }
195         return MakeRefPtr<TextInputLayoutAlgorithm>();
196     }
197 
198     void OnModifyDone() override;
199     void UpdateSelectionOffset();
200     void CalcCaretMetricsByPosition(
201         int32_t extent, CaretMetricsF& caretCaretMetric, TextAffinity textAffinity = TextAffinity::DOWNSTREAM);
202     int32_t ConvertTouchOffsetToCaretPosition(const Offset& localOffset);
203     int32_t ConvertTouchOffsetToCaretPositionNG(const Offset& localOffset);
204 
205     // Obtain the systemWindowsId when switching between windows
206     uint32_t GetSCBSystemWindowId();
207 
208     void InsertValue(const std::string& insertValue) override;
209     void InsertValueOperation(const std::string& insertValue);
210     void UpdateOverCounterColor();
211     void UpdateCounterMargin();
212     void CleanCounterNode();
213     void UltralimitShake();
214     void HandleInputCounterBorder(int32_t& textLength, uint32_t& maxLength);
215     void UpdateCounterBorderStyle(int32_t& textLength, uint32_t& maxLength);
216     void UpdateAreaBorderStyle(BorderWidthProperty& currentBorderWidth, BorderWidthProperty& overCountBorderWidth,
217         BorderColorProperty& overCountBorderColor, BorderColorProperty& currentBorderColor);
218     void DeleteBackward(int32_t length) override;
219     void DeleteBackwardOperation(int32_t length);
220     void DeleteForward(int32_t length) override;
221     void DeleteForwardOperation(int32_t length);
222     void HandleOnDelete(bool backward) override;
223     void UpdateRecordCaretIndex(int32_t index);
224     void CreateHandles() override;
225 
GetCounterNode()226     WeakPtr<LayoutWrapper> GetCounterNode()
227     {
228         return counterTextNode_;
229     }
230 
GetCounterState()231     bool GetCounterState() const
232     {
233         return counterChange_;
234     }
235 
SetCounterState(bool counterChange)236     void SetCounterState(bool counterChange)
237     {
238         counterChange_ = counterChange;
239     }
240 
241     float GetTextOrPlaceHolderFontSize();
242 
SetTextFieldController(const RefPtr<TextFieldController> & controller)243     void SetTextFieldController(const RefPtr<TextFieldController>& controller)
244     {
245         textFieldController_ = controller;
246     }
247 
GetTextFieldController()248     const RefPtr<TextFieldController>& GetTextFieldController()
249     {
250         return textFieldController_;
251     }
252 
SetTextEditController(const RefPtr<TextEditController> & textEditController)253     void SetTextEditController(const RefPtr<TextEditController>& textEditController)
254     {
255         textEditingController_ = textEditController;
256     }
257 
GetTextValue()258     std::string GetTextValue() const
259     {
260         return contentController_->GetTextValue();
261     }
262 
263 #if defined(IOS_PLATFORM)
GetInputEditingValue()264     const TextEditingValue& GetInputEditingValue() const override
265     {
266         static TextEditingValue value;
267         value.text = contentController_->GetTextValue();
268         value.hint = GetPlaceHolder();
269         value.selection.Update(selectController_->GetStartIndex(), selectController_->GetEndIndex());
270         return value;
271     };
272     Offset GetGlobalOffset() const;
273     double GetEditingBoxY() const override;
274     double GetEditingBoxTopY() const override;
275     bool GetEditingBoxModel() const override;
276 #endif
277 
ShouldDelayChildPressedState()278     bool ShouldDelayChildPressedState() const override
279     {
280         return false;
281     }
282 
UpdateEditingValue(const std::string & value,int32_t caretPosition)283     void UpdateEditingValue(const std::string& value, int32_t caretPosition)
284     {
285         contentController_->SetTextValue(value);
286         selectController_->UpdateCaretIndex(caretPosition);
287     }
288     void UpdateCaretPositionByTouch(const Offset& offset);
289     bool IsReachedBoundary(float offset);
290 
291     virtual TextInputAction GetDefaultTextInputAction() const;
292     bool RequestKeyboard(bool isFocusViewChanged, bool needStartTwinkling, bool needShowSoftKeyboard);
293     bool CloseKeyboard(bool forceClose) override;
294     bool CloseKeyboard(bool forceClose, bool isStopTwinkling);
295 
GetFocusPattern()296     FocusPattern GetFocusPattern() const override
297     {
298         FocusPattern focusPattern = { FocusType::NODE, true };
299         focusPattern.SetIsFocusActiveWhenFocused(true);
300         return focusPattern;
301     }
302 
303     void PerformAction(TextInputAction action, bool forceCloseKeyboard = false) override;
304     void UpdateEditingValue(const std::shared_ptr<TextEditingValue>& value, bool needFireChangeEvent = true) override;
305     void UpdateInputFilterErrorText(const std::string& errorText) override;
306 
307     void OnValueChanged(bool needFireChangeEvent = true, bool needFireSelectChangeEvent = true) override;
308 
309     void OnAreaChangedInner() override;
310     void OnVisibleChange(bool isVisible) override;
311     void ClearEditingValue();
312     void HandleCounterBorder();
GetWideText()313     std::wstring GetWideText()
314     {
315         return contentController_->GetWideText();
316     }
317 
GetCaretIndex()318     int32_t GetCaretIndex() const
319     {
320         return selectController_->GetCaretIndex();
321     }
322 
ACE_DEFINE_PROPERTY_ITEM_FUNC_WITHOUT_GROUP(TextInputAction,TextInputAction)323     ACE_DEFINE_PROPERTY_ITEM_FUNC_WITHOUT_GROUP(TextInputAction, TextInputAction)
324 
325     const RefPtr<Paragraph>& GetParagraph() const
326     {
327         return paragraph_;
328     }
329 
GetErrorParagraph()330     const RefPtr<Paragraph>& GetErrorParagraph() const
331     {
332         return errorParagraph_;
333     }
334 
GetCursorVisible()335     bool GetCursorVisible() const
336     {
337         return cursorVisible_;
338     }
339 
340 #if defined(OHOS_STANDARD_SYSTEM) && !defined(PREVIEW)
GetImeAttached()341     bool GetImeAttached() const
342     {
343         return imeAttached_;
344     }
345 #endif
346 
GetLastTouchOffset()347     const OffsetF& GetLastTouchOffset()
348     {
349         return lastTouchOffset_;
350     }
351 
GetRightClickOffset()352     const OffsetF& GetRightClickOffset()
353     {
354         return rightClickOffset_;
355     }
356 
GetCaretOffset()357     OffsetF GetCaretOffset() const
358     {
359         return selectController_->GetCaretRect().GetOffset();
360     }
361 
GetCaretOffsetX()362     float GetCaretOffsetX() const
363     {
364         return selectController_->GetCaretRect().GetX();
365     }
366 
GetCaretUpdateType()367     CaretUpdateType GetCaretUpdateType() const
368     {
369         return caretUpdateType_;
370     }
371 
SetCaretUpdateType(CaretUpdateType type)372     void SetCaretUpdateType(CaretUpdateType type)
373     {
374         caretUpdateType_ = type;
375     }
376 
GetPaddingTop()377     float GetPaddingTop() const
378     {
379         return utilPadding_.top.value_or(0.0f);
380     }
381 
GetPaddingBottom()382     float GetPaddingBottom() const
383     {
384         return utilPadding_.bottom.value_or(0.0f);
385     }
386 
GetPaddingLeft()387     float GetPaddingLeft() const
388     {
389         return utilPadding_.left.value_or(0.0f);
390     }
391 
GetPaddingRight()392     float GetPaddingRight() const
393     {
394         return utilPadding_.right.value_or(0.0f);
395     }
396 
GetUtilPadding()397     const PaddingPropertyF& GetUtilPadding() const
398     {
399         return utilPadding_;
400     }
401 
GetHorizontalPaddingAndBorderSum()402     float GetHorizontalPaddingAndBorderSum() const
403     {
404         return utilPadding_.left.value_or(0.0f) + utilPadding_.right.value_or(0.0f) + GetBorderLeft() +
405                GetBorderRight();
406     }
407 
GetVerticalPaddingAndBorderSum()408     float GetVerticalPaddingAndBorderSum() const
409     {
410         return utilPadding_.top.value_or(0.0f) + utilPadding_.bottom.value_or(0.0f) + GetBorderTop() +
411                GetBorderBottom();
412     }
413 
GetBorderLeft()414     float GetBorderLeft() const
415     {
416         return lastBorderWidth_.leftDimen.value_or(Dimension(0.0f)).ConvertToPx();
417     }
418 
GetBorderTop()419     float GetBorderTop() const
420     {
421         return lastBorderWidth_.topDimen.value_or(Dimension(0.0f)).ConvertToPx();
422     }
423 
GetBorderBottom()424     float GetBorderBottom() const
425     {
426         return lastBorderWidth_.bottomDimen.value_or(Dimension(0.0f)).ConvertToPx();
427     }
428 
GetBorderRight()429     float GetBorderRight() const
430     {
431         return lastBorderWidth_.rightDimen.value_or(Dimension(0.0f)).ConvertToPx();
432     }
433 
GetTextRect()434     const RectF& GetTextRect() override
435     {
436         return textRect_;
437     }
438 
SetTextRect(const RectF & textRect)439     void SetTextRect(const RectF& textRect)
440     {
441         textRect_ = textRect;
442     }
443 
GetContentRect()444     const RectF& GetContentRect() const
445     {
446         return contentRect_;
447     }
448 
GetFrameRect()449     const RectF& GetFrameRect() const
450     {
451         return frameRect_;
452     }
453 
GetCountHeight()454     float GetCountHeight() const
455     {
456         return countHeight_;
457     }
458 
GetTextSelectController()459     const RefPtr<TextSelectController>& GetTextSelectController()
460     {
461         return selectController_;
462     }
463 
SetInSelectMode(SelectionMode selectionMode)464     void SetInSelectMode(SelectionMode selectionMode)
465     {
466         selectionMode_ = selectionMode;
467     }
468 
GetSelectMode()469     SelectionMode GetSelectMode() const
470     {
471         return selectionMode_;
472     }
473 
IsSelected()474     bool IsSelected() const override
475     {
476         return selectController_->IsSelected();
477     }
478 
IsUsingMouse()479     bool IsUsingMouse() const
480     {
481         return isUsingMouse_;
482     }
483     int32_t GetWordLength(int32_t originCaretPosition, int32_t directionalMove);
484     int32_t GetLineBeginPosition(int32_t originCaretPosition, bool needToCheckLineChanged = true);
485     int32_t GetLineEndPosition(int32_t originCaretPosition, bool needToCheckLineChanged = true);
IsOperation()486     bool IsOperation() const
487     {
488         return !contentController_->IsEmpty();
489     }
490 
491     void CursorMove(CaretMoveIntent direction) override;
492     bool CursorMoveLeft();
493     bool CursorMoveLeftOperation();
494     bool CursorMoveLeftWord();
495     bool CursorMoveLineBegin();
496     bool CursorMoveToParagraphBegin();
497     bool CursorMoveHome();
498     bool CursorMoveRight();
499     bool CursorMoveRightOperation();
500     bool CursorMoveRightWord();
501     bool CursorMoveLineEnd();
502     bool CursorMoveToParagraphEnd();
503     bool CursorMoveEnd();
504     bool CursorMoveUp();
505     bool CursorMoveDown();
506     bool CursorMoveUpOperation();
507     bool CursorMoveDownOperation();
508     void SetCaretPosition(int32_t position);
509     void HandleSetSelection(int32_t start, int32_t end, bool showHandle = true) override;
510     void HandleExtendAction(int32_t action) override;
511     void HandleSelect(CaretMoveIntent direction) override;
512     OffsetF GetDragUpperLeftCoordinates() override;
513 
GetTextBoxes()514     std::vector<RectF> GetTextBoxes() override
515     {
516         return selectController_->GetSelectedRects();
517     }
518     void ToJsonValue(std::unique_ptr<JsonValue>& json) const override;
519     void FromJson(const std::unique_ptr<JsonValue>& json) override;
520     void InitEditingValueText(std::string content);
521     void InitValueText(std::string content);
522 
523     void CloseSelectOverlay() override;
524     void CloseSelectOverlay(bool animation);
SetInputMethodStatus(bool keyboardShown)525     void SetInputMethodStatus(bool keyboardShown) override
526     {
527 #if defined(OHOS_STANDARD_SYSTEM) && !defined(PREVIEW)
528         imeShown_ = keyboardShown;
529 #endif
530     }
NotifyKeyboardClosedByUser()531     void NotifyKeyboardClosedByUser() override
532     {
533         isKeyboardClosedByUser_ = true;
534         FocusHub::LostFocusToViewRoot();
535         isKeyboardClosedByUser_ = false;
536     }
537     std::u16string GetLeftTextOfCursor(int32_t number) override;
538     std::u16string GetRightTextOfCursor(int32_t number) override;
539     int32_t GetTextIndexAtCursor() override;
540 
HasConnection()541     bool HasConnection() const
542     {
543 #if defined(OHOS_STANDARD_SYSTEM) && !defined(PREVIEW)
544         return imeShown_;
545 #else
546         return connection_;
547 #endif
548     }
549     float PreferredLineHeight(bool isAlgorithmMeasure = false);
550 
551     void SearchRequestKeyboard();
552 
GetTextObscured()553     bool GetTextObscured() const
554     {
555         return textObscured_;
556     }
557 
558     static std::u16string CreateObscuredText(int32_t len);
559     static std::u16string CreateDisplayText(
560         const std::string& content, int32_t nakedCharPosition, bool needObscureText);
561     bool IsTextArea() const override;
562 
GetTouchListener()563     const RefPtr<TouchEventImpl>& GetTouchListener()
564     {
565         return touchListener_;
566     }
567 
NeedShowPasswordIcon()568     bool NeedShowPasswordIcon()
569     {
570         auto layoutProperty = GetLayoutProperty<TextFieldLayoutProperty>();
571         CHECK_NULL_RETURN(layoutProperty, false);
572         return IsInPasswordMode() && layoutProperty->GetShowPasswordIconValue(true);
573     }
574 
SetEnableTouchAndHoverEffect(bool enable)575     void SetEnableTouchAndHoverEffect(bool enable)
576     {
577         enableTouchAndHoverEffect_ = enable;
578     }
579 
GetCaretRect()580     RectF GetCaretRect() const override
581     {
582         return selectController_->GetCaretRect();
583     }
584 
585     void HandleSurfaceChanged(int32_t newWidth, int32_t newHeight, int32_t prevWidth, int32_t prevHeight);
586     void HandleSurfacePositionChanged(int32_t posX, int32_t posY) const;
587 
588     void InitSurfaceChangedCallback();
589     void InitSurfacePositionChangedCallback();
590 
HasSurfaceChangedCallback()591     bool HasSurfaceChangedCallback()
592     {
593         return surfaceChangedCallbackId_.has_value();
594     }
UpdateSurfaceChangedCallbackId(int32_t id)595     void UpdateSurfaceChangedCallbackId(int32_t id)
596     {
597         surfaceChangedCallbackId_ = id;
598     }
599 
HasSurfacePositionChangedCallback()600     bool HasSurfacePositionChangedCallback()
601     {
602         return surfacePositionChangedCallbackId_.has_value();
603     }
UpdateSurfacePositionChangedCallbackId(int32_t id)604     void UpdateSurfacePositionChangedCallbackId(int32_t id)
605     {
606         surfacePositionChangedCallbackId_ = id;
607     }
608 
609     void ProcessInnerPadding();
610     void OnCursorMoveDone(TextAffinity textAffinity = TextAffinity::UPSTREAM);
611     bool IsDisabled();
612     bool AllowCopy();
613 
GetIsMousePressed()614     bool GetIsMousePressed() const
615     {
616         return isMousePressed_;
617     }
618 
GetMouseStatus()619     MouseStatus GetMouseStatus() const
620     {
621         return mouseStatus_;
622     }
623 
SetMenuOptionItems(std::vector<MenuOptionsParam> && menuOptionItems)624     void SetMenuOptionItems(std::vector<MenuOptionsParam>&& menuOptionItems)
625     {
626         menuOptionItems_ = std::move(menuOptionItems);
627     }
628 
GetMenuOptionItems()629     const std::vector<MenuOptionsParam>&& GetMenuOptionItems() const
630     {
631         return std::move(menuOptionItems_);
632     }
633 
634     void UpdateEditingValueToRecord();
635     void UpdateScrollBarOffset() override;
636 
UpdateCurrentOffset(float offset,int32_t source)637     bool UpdateCurrentOffset(float offset, int32_t source) override
638     {
639         OnScrollCallback(offset, source);
640         return true;
641     }
642 
IsAtTop()643     bool IsAtTop() const override
644     {
645         return contentRect_.GetY() == textRect_.GetY();
646     }
647 
IsAtBottom()648     bool IsAtBottom() const override
649     {
650         return contentRect_.GetY() + contentRect_.Height() == textRect_.GetY() + textRect_.Height();
651     }
652 
IsScrollable()653     bool IsScrollable() const override
654     {
655         return scrollable_;
656     }
657 
IsAtomicNode()658     bool IsAtomicNode() const override
659     {
660         return true;
661     }
662 
GetCurrentOffset()663     float GetCurrentOffset() const
664     {
665         return currentOffset_;
666     }
667 
GetContentModifier()668     RefPtr<TextFieldContentModifier> GetContentModifier()
669     {
670         return textFieldContentModifier_;
671     }
672 
673     double GetScrollBarWidth();
674 
GetLineHeight()675     float GetLineHeight() const override
676     {
677         return selectController_->GetCaretRect().Height();
678     }
679 
GetParentGlobalOffset()680     OffsetF GetParentGlobalOffset() const override
681     {
682         return parentGlobalOffset_;
683     }
684 
GetTextContentRect()685     const RectF& GetTextContentRect() const override
686     {
687         return contentRect_;
688     }
689 
GetDragParagraph()690     ParagraphT GetDragParagraph() const override
691     {
692         return { dragParagraph_ };
693     }
694 
MoveDragNode()695     const RefPtr<FrameNode>& MoveDragNode() override
696     {
697         return dragNode_;
698     }
699 
GetDragContents()700     const std::vector<std::string>& GetDragContents() const
701     {
702         return dragContents_;
703     }
704 
AddDragFrameNodeToManager(const RefPtr<FrameNode> & frameNode)705     void AddDragFrameNodeToManager(const RefPtr<FrameNode>& frameNode)
706     {
707         auto context = PipelineContext::GetCurrentContext();
708         CHECK_NULL_VOID(context);
709         auto dragDropManager = context->GetDragDropManager();
710         CHECK_NULL_VOID(dragDropManager);
711         dragDropManager->AddDragFrameNode(frameNode->GetId(), AceType::WeakClaim(AceType::RawPtr(frameNode)));
712     }
713 
RemoveDragFrameNodeFromManager(const RefPtr<FrameNode> & frameNode)714     void RemoveDragFrameNodeFromManager(const RefPtr<FrameNode>& frameNode)
715     {
716         auto context = PipelineContext::GetCurrentContext();
717         CHECK_NULL_VOID(context);
718         auto dragDropManager = context->GetDragDropManager();
719         CHECK_NULL_VOID(dragDropManager);
720         dragDropManager->RemoveDragFrameNode(frameNode->GetId());
721     }
722 
IsDragging()723     bool IsDragging() const
724     {
725         return dragStatus_ == DragStatus::DRAGGING;
726     }
727 
IsTouchTestPointInArea(const Offset & touchOffset,bool isTouchPointHits)728     bool IsTouchTestPointInArea(const Offset& touchOffset, bool isTouchPointHits) override
729     {
730         return isTouchPointHits && BetweenSelectedPosition(touchOffset);
731     }
732 
BetweenSelectedPosition(const Offset & globalOffset)733     bool BetweenSelectedPosition(const Offset& globalOffset) override
734     {
735         if (!IsSelected()) {
736             return false;
737         }
738         Offset offset = globalOffset -
739                         Offset(IsTextArea() ? contentRect_.GetX() : textRect_.GetX(),
740                             IsTextArea() ? textRect_.GetY() : contentRect_.GetY()) -
741                         Offset(parentGlobalOffset_.GetX(), parentGlobalOffset_.GetY());
742         for (const auto& rect : selectController_->GetSelectedRects()) {
743             bool isInRange = rect.IsInRegion({ offset.GetX(), offset.GetY() });
744             if (isInRange) {
745                 return true;
746             }
747         }
748         return false;
749     }
750 
751     bool RequestCustomKeyboard();
752     bool CloseCustomKeyboard();
753 
754     // xts
755     std::string TextInputTypeToString() const;
756     std::string TextInputActionToString() const;
757     std::string GetPlaceholderFont() const;
758     RefPtr<TextFieldTheme> GetTheme() const;
759     std::string GetTextColor() const;
760     std::string GetCaretColor() const;
761     std::string GetPlaceholderColor() const;
762     std::string GetFontSize() const;
763     Ace::FontStyle GetItalicFontStyle() const;
764     FontWeight GetFontWeight() const;
765     std::string GetFontFamily() const;
766     TextAlign GetTextAlign() const;
767     std::string GetPlaceHolder() const;
768     uint32_t GetMaxLength() const;
769     uint32_t GetMaxLines() const;
770     std::string GetInputFilter() const;
771     std::string GetCopyOptionString() const;
772     std::string GetInputStyleString() const;
773     std::string GetErrorTextString() const;
774     std::string GetBarStateString() const;
775     bool GetErrorTextState() const;
776     std::string GetShowPasswordIconString() const;
777     int32_t GetNakedCharPosition() const;
778     void SetSelectionFlag(int32_t selectionStart, int32_t selectionEnd);
779     void HandleBlurEvent();
780     void HandleFocusEvent();
781     bool OnBackPressed() override;
782     void CheckScrollable();
783     void HandleClickEvent(GestureEvent& info);
784     bool CheckClickLocation(GestureEvent& info);
785     void HandleDoubleClickEvent(GestureEvent& info);
786     void HandleSingleClickEvent(GestureEvent& info);
787 
788     void HandleSelectionUp();
789     void HandleSelectionDown();
790     void HandleSelectionLeft();
791     void HandleSelectionLeftWord();
792     void HandleSelectionLineBegin();
793     void HandleSelectionHome();
794     void HandleSelectionRight();
795     void HandleSelectionRightWord();
796     void HandleSelectionLineEnd();
797     void HandleSelectionEnd();
798     bool HandleOnEscape() override;
799     bool HandleOnTab(bool backward) override;
HandleOnEnter()800     void HandleOnEnter() override
801     {
802         PerformAction(GetTextInputActionValue(GetDefaultTextInputAction()), false);
803     }
804     void HandleOnUndoAction() override;
805     void HandleOnRedoAction() override;
806     void HandleOnSelectAll(bool isKeyEvent, bool inlineStyle = false);
HandleOnSelectAll()807     void HandleOnSelectAll() override
808     {
809         HandleOnSelectAll(true);
810     }
811     void HandleOnCopy(bool isUsingExternalKeyboard = false) override;
812     void HandleOnPaste() override;
813     void HandleOnCut() override;
814     void HandleOnCameraInput();
815     void StripNextLine(std::wstring& data);
816     bool OnKeyEvent(const KeyEvent& event);
817     int32_t GetLineCount() const;
GetKeyboard()818     TextInputType GetKeyboard()
819     {
820         return keyboard_;
821     }
GetAction()822     TextInputAction GetAction()
823     {
824         return action_;
825     }
826 
SetNeedToRequestKeyboardOnFocus(bool needToRequest)827     void SetNeedToRequestKeyboardOnFocus(bool needToRequest)
828     {
829         needToRequestKeyboardOnFocus_ = needToRequest;
830     }
SetUnitNode(const RefPtr<NG::UINode> & unitNode)831     void SetUnitNode(const RefPtr<NG::UINode>& unitNode)
832     {
833         unitNode_ = unitNode;
834     }
835     void AddCounterNode();
836     void ClearCounterNode();
837     void SetShowError();
838 
GetUnderlineWidth()839     float GetUnderlineWidth() const
840     {
841         return static_cast<float>(underlineWidth_.Value());
842     }
843 
GetUnderlineColor()844     const Color& GetUnderlineColor() const
845     {
846         return underlineColor_;
847     }
848 
849     float GetMarginBottom() const;
850 
SetUnderlineColor(Color underlineColor)851     void SetUnderlineColor(Color underlineColor)
852     {
853         underlineColor_ = underlineColor;
854     }
855 
SetUnderlineWidth(Dimension underlineWidth)856     void SetUnderlineWidth(Dimension underlineWidth)
857     {
858         underlineWidth_ = underlineWidth;
859     }
860 
IsSelectAll()861     bool IsSelectAll()
862     {
863         return abs(selectController_->GetStartIndex() - selectController_->GetEndIndex()) >=
864                static_cast<int32_t>(contentController_->GetWideText().length());
865     }
866 
867     void StopEditing();
868 
MarkContentChange()869     void MarkContentChange()
870     {
871         contChange_ = true;
872     }
873 
ResetContChange()874     void ResetContChange()
875     {
876         contChange_ = false;
877     }
878 
GetContChange()879     bool GetContChange() const
880     {
881         return contChange_;
882     }
883     std::string GetShowResultImageSrc() const;
884     std::string GetHideResultImageSrc() const;
885     void OnAttachToFrameNode() override;
886 
GetTextInputFlag()887     bool GetTextInputFlag() const
888     {
889         return isTextInput_;
890     }
891 
SetSingleLineHeight(float height)892     void SetSingleLineHeight(float height)
893     {
894         inlineSingleLineHeight_ = height;
895     }
896 
GetSingleLineHeight()897     float GetSingleLineHeight() const
898     {
899         return inlineSingleLineHeight_;
900     }
901 
GetInlinePadding()902     float GetInlinePadding() const
903     {
904         return inlinePadding_;
905     }
906 
GetScrollBarVisible()907     bool GetScrollBarVisible() const
908     {
909         return scrollBarVisible_;
910     }
911 
GetPreviewWidth()912     float GetPreviewWidth() const
913     {
914         return inlineState_.frameRect.Width();
915     }
916 
917     bool IsNormalInlineState() const;
918     bool IsUnspecifiedOrTextType() const;
919     void TextIsEmptyRect(RectF& rect);
920     void TextAreaInputRectUpdate(RectF& rect);
921     void UpdateRectByTextAlign(RectF& rect);
922 
923     void EditingValueFilterChange();
924 
SetCustomKeyboard(const std::function<void ()> && keyboardBuilder)925     void SetCustomKeyboard(const std::function<void()>&& keyboardBuilder)
926     {
927         if (customKeyboardBuilder_ && isCustomKeyboardAttached_ && !keyboardBuilder) {
928             // close customKeyboard and request system keyboard
929             CloseCustomKeyboard();
930             customKeyboardBuilder_ = keyboardBuilder; // refresh current keyboard
931             RequestKeyboard(false, true, true);
932             return;
933         }
934         if (!customKeyboardBuilder_ && keyboardBuilder) {
935             // close system keyboard and request custom keyboard
936 #if defined(OHOS_STANDARD_SYSTEM) && !defined(PREVIEW)
937             if (imeShown_) {
938                 CloseKeyboard(true);
939                 customKeyboardBuilder_ = keyboardBuilder; // refresh current keyboard
940                 RequestKeyboard(false, true, true);
941                 return;
942             }
943 #endif
944         }
945         customKeyboardBuilder_ = keyboardBuilder;
946     }
947 
948     void DumpInfo() override;
949     void DumpAdvanceInfo() override;
950     void DumpViewDataPageNode(RefPtr<ViewDataWrap> viewDataWrap) override;
951     void NotifyFillRequestSuccess(RefPtr<PageNodeInfoWrap> nodeWrap, AceAutoFillType autoFillType) override;
952     void NotifyFillRequestFailed(int32_t errCode) override;
953     bool CheckAutoSave() override;
954     void OnColorConfigurationUpdate() override;
955     bool NeedPaintSelect();
956 
SetIsCustomFont(bool isCustomFont)957     void SetIsCustomFont(bool isCustomFont)
958     {
959         isCustomFont_ = isCustomFont;
960     }
961 
GetIsCustomFont()962     bool GetIsCustomFont() const
963     {
964         return isCustomFont_;
965     }
966 
SetISCounterIdealHeight(bool IsIdealHeight)967     void SetISCounterIdealHeight(bool IsIdealHeight)
968     {
969         isCounterIdealheight_ = IsIdealHeight;
970     }
971 
GetIsCounterIdealHeight()972     bool GetIsCounterIdealHeight() const
973     {
974         return isCounterIdealheight_;
975     }
976 
977     virtual RefPtr<FocusHub> GetFocusHub() const;
978 
979     // override SelectOverlayClient methods.
980     void OnHandleMove(const RectF& handleRect, bool isFirstHandle) override;
981     void OnHandleMoveDone(const RectF& handleRect, bool isFirstHandle) override;
982     void OnHandleClosed(bool closedByGlobalEvent) override;
983     bool CheckHandleVisible(const RectF& paintRect) override;
984     void UpdateCaretInfoToController() const;
985     bool OnPreShowSelectOverlay(
986         SelectOverlayInfo& overlayInfo, const ClientOverlayInfo& clientInfo, bool isSelectOverlayOn) override;
987     void OnObscuredChanged(bool isObscured);
OnSelectOverlayMenuClicked(SelectOverlayMenuId menuId)988     void OnSelectOverlayMenuClicked(SelectOverlayMenuId menuId) override
989     {
990         switch (menuId) {
991             case SelectOverlayMenuId::COPY:
992                 HandleOnCopy();
993                 return;
994             case SelectOverlayMenuId::CUT:
995                 HandleOnCut();
996                 return;
997             case SelectOverlayMenuId::SELECT_ALL:
998                 HandleOnSelectAll(false);
999                 return;
1000             case SelectOverlayMenuId::PASTE:
1001                 HandleOnPaste();
1002                 return;
1003             case SelectOverlayMenuId::CAMERA_INPUT:
1004                 HandleOnCameraInput();
1005                 return;
1006         }
1007     }
1008 
GetClientHost()1009     RefPtr<FrameNode> GetClientHost() const override
1010     {
1011         return GetHost();
1012     }
1013 
GetResponseArea()1014     const RefPtr<TextInputResponseArea>& GetResponseArea()
1015     {
1016         return responseArea_;
1017     }
1018 
GetCleanNodeResponseArea()1019     const RefPtr<TextInputResponseArea>& GetCleanNodeResponseArea()
1020     {
1021         return cleanNodeResponseArea_;
1022     }
1023 
1024     bool IsShowUnit() const;
1025     bool IsShowPasswordIcon() const;
1026     bool IsInPasswordMode() const;
1027     bool IsShowCancelButtonMode() const;
1028 
GetShowSelect()1029     bool GetShowSelect() const
1030     {
1031         return showSelect_;
1032     }
1033 
1034     bool UpdateFocusForward();
1035 
1036     bool UpdateFocusBackward();
1037 
1038     bool HandleSpaceEvent();
1039 
1040     RefPtr<PixelMap> GetPixelMap();
1041 
1042     void UpdateShowMagnifier(bool isShowMagnifier = false)
1043     {
1044         isShowMagnifier_ = isShowMagnifier;
1045         if (isShowMagnifier_) {
1046             magnifierController_->OpenMagnifier();
1047         } else {
1048             magnifierController_->CloseMagnifier();
1049         }
1050     }
1051 
GetShowMagnifier()1052     bool GetShowMagnifier() const
1053     {
1054         return isShowMagnifier_;
1055     }
1056 
1057     virtual void InitBackGroundColorAndBorderRadius();
1058 
1059     void SavePreUnderLineState();
1060 
SetLocalOffset(OffsetF localOffset)1061     void SetLocalOffset(OffsetF localOffset)
1062     {
1063         localOffset_.SetX(localOffset.GetX());
1064         localOffset_.SetY(localOffset.GetY());
1065         UpdateShowMagnifier(true);
1066     }
1067 
GetLocalOffset()1068     OffsetF GetLocalOffset() const
1069     {
1070         return localOffset_;
1071     }
1072 
GetContentWideTextLength()1073     int32_t GetContentWideTextLength()
1074     {
1075         return static_cast<int32_t>(contentController_->GetWideText().length());
1076     }
1077 
1078     void ShowMenu();
HandleOnShowMenu()1079     void HandleOnShowMenu() override
1080     {
1081         ShowMenu();
1082     }
1083     bool HasFocus() const;
1084     void StopTwinkling();
1085     void StartTwinkling();
1086 
IsModifyDone()1087     bool IsModifyDone()
1088     {
1089         return isModifyDone_;
1090     }
SetModifyDoneStatus(bool value)1091     void SetModifyDoneStatus(bool value)
1092     {
1093         isModifyDone_ = value;
1094     }
1095 
GetLastClickTime()1096     const TimeStamp& GetLastClickTime()
1097     {
1098         return lastClickTimeStamp_;
1099     }
1100 
1101     void CheckTextAlignByDirection(TextAlign& textAlign, TextDirection direction);
1102 
1103     void HandleOnDragStatusCallback(
1104         const DragEventType& dragEventType, const RefPtr<NotifyDragEvent>& notifyDragEvent) override;
1105 
1106     void GetCaretMetrics(CaretMetricsF& caretCaretMetric) override;
1107 
SetMagnifierRect(MagnifierRect magnifierRect)1108     void SetMagnifierRect(MagnifierRect magnifierRect)
1109     {
1110         magnifierRect_ = magnifierRect;
1111     }
1112 
GetMagnifierRect()1113     MagnifierRect GetMagnifierRect()
1114     {
1115         return magnifierRect_;
1116     }
1117 
1118     OffsetF GetTextPaintOffset() const;
1119 
GetMagnifierController()1120     const RefPtr<MagnifierController>& GetMagnifierController()
1121     {
1122         return magnifierController_;
1123     }
1124 
NeedRequestKeyboard()1125     void NeedRequestKeyboard()
1126     {
1127         needToRequestKeyboardInner_ = true;
1128     }
1129 
1130     void CleanNodeResponseKeyEvent();
1131 
1132     void OnVirtualKeyboardAreaChanged() override;
1133 
1134 protected:
1135     virtual void InitDragEvent();
1136 
1137 private:
1138     void GetTextSelectRectsInRangeAndWillChange();
1139     void OnAfterModifyDone() override;
1140     void HandleTouchEvent(const TouchEventInfo& info);
1141     void HandleTouchDown(const Offset& offset);
1142     void HandleTouchUp();
1143     void HandleTouchMove(const TouchEventInfo& info);
1144     void UpdateCaretByTouchMove(const TouchEventInfo& info);
1145     void InitDisableColor();
1146     void InitFocusEvent();
1147     void InitTouchEvent();
1148     void InitLongPressEvent();
1149     void InitClickEvent();
1150     void InitDragDropEvent();
1151     std::function<DragDropInfo(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)> OnDragStart();
1152     std::function<void(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)> OnDragDrop();
1153     void ShowSelectAfterDragEvent();
1154     void ClearDragDropEvent();
1155     std::function<void(Offset)> GetThumbnailCallback();
1156     void HandleCursorOnDragMoved(const RefPtr<NotifyDragEvent>& notifyDragEvent);
1157     void HandleCursorOnDragLeaved(const RefPtr<NotifyDragEvent>& notifyDragEvent);
1158     void HandleCursorOnDragEnded(const RefPtr<NotifyDragEvent>& notifyDragEvent);
1159     int32_t UpdateCaretPositionOnHandleMove(const OffsetF& localOffset);
1160     bool HasStateStyle(UIState state) const;
1161 
1162     void OnTextInputScroll(float offset);
1163     void OnTextAreaScroll(float offset);
1164     bool OnScrollCallback(float offset, int32_t source) override;
1165     void OnScrollEndCallback() override;
1166     void InitMouseEvent();
1167     void HandleHoverEffect(MouseInfo& info, bool isHover);
1168     void OnHover(bool isHover);
1169     void ChangeMouseState(const Offset location, const RefPtr<PipelineContext>& pipeline, int32_t frameId);
1170     void HandleMouseEvent(MouseInfo& info);
1171     void FocusAndUpdateCaretByMouse(MouseInfo& info);
1172     void HandleRightMouseEvent(MouseInfo& info);
1173     void HandleRightMousePressEvent(MouseInfo& info);
1174     void HandleRightMouseReleaseEvent(MouseInfo& info);
1175     void HandleLeftMouseEvent(MouseInfo& info);
1176     void HandleLeftMousePressEvent(MouseInfo& info);
1177     void HandleLeftMouseMoveEvent(MouseInfo& info);
1178     void HandleLeftMouseReleaseEvent(MouseInfo& info);
1179     void HandleLongPress(GestureEvent& info);
1180     void UpdateCaretPositionWithClamp(const int32_t& pos);
1181     void ShowSelectOverlay(const ShowSelectOverlayParams& params);
1182     void PushSelectedByMouseInfoToManager();
1183     void CursorMoveOnClick(const Offset& offset);
1184 
1185     void ProcessOverlay(
1186         bool isUpdateMenu = true, bool animation = false, bool isShowMenu = true, bool isHiddenHandle = false);
1187     void DelayProcessOverlay(bool isUpdateMenu = true, bool animation = false, bool isShowMenu = true);
1188     SelectHandleInfo GetSelectHandleInfo(OffsetF info);
1189     void UpdateSelectOverlaySecondHandle(bool needLayout = false);
1190     void UpdateSelectOverlayDoubleHandle(bool firstNeedLayout = false, bool secondNeedLayout = false);
1191 
1192     // when moving one handle causes shift of textRect, update x position of the other handle
1193     void SetHandlerOnMoveDone();
1194     void OnDetachFromFrameNode(FrameNode* node) override;
1195     void UpdateSelectionByMouseDoubleClick();
1196 
1197     void AfterSelection();
1198 
1199     void FireEventHubOnChange(const std::string& text);
1200     // The return value represents whether the editor content has change.
1201     bool FireOnTextChangeEvent();
1202 
1203     void FilterInitializeText();
1204 
1205     void UpdateSelection(int32_t both);
1206     void UpdateSelection(int32_t start, int32_t end);
1207     void FireOnSelectionChange(int32_t start, int32_t end);
1208     void UpdateCaretPositionByLastTouchOffset();
1209     bool UpdateCaretPosition();
1210     void UpdateCaretRect(bool isEditorValueChanged);
1211     void AdjustTextInReasonableArea();
1212     bool CharLineChanged(int32_t caretPosition);
1213 
1214     void ScheduleCursorTwinkling();
1215     void OnCursorTwinkling();
1216     void CheckIfNeedToResetKeyboard();
1217 
1218     float PreferredTextHeight(bool isPlaceholder, bool isAlgorithmMeasure = false);
1219 
1220     void SetCaretOffsetForEmptyTextOrPositionZero();
1221     void UpdateTextFieldManager(const Offset& offset, float height);
1222     void OnTextInputActionUpdate(TextInputAction value);
1223 
1224     void Delete(int32_t start, int32_t end);
1225     void BeforeCreateLayoutWrapper() override;
1226     bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override;
1227     bool CursorInContentRegion();
1228     bool OffsetInContentRegion(const Offset& offset);
1229     void SetDisabledStyle();
1230 
1231     void CalculateDefaultCursor();
1232     void RequestKeyboardOnFocus();
1233     void SetNeedToRequestKeyboardOnFocus();
1234     void SaveUnderlineStates();
1235     void ApplyUnderlineStates();
1236     void SavePasswordModeStates();
1237     void SetAccessibilityAction();
1238     void SetAccessibilityMoveTextAction();
1239     void SetAccessibilityScrollAction();
1240 
1241     void UpdateCopyAllStatus();
1242     void SaveInlineStates();
1243     void ApplyInlineStates();
1244     void RestorePreInlineStates();
1245     void RestoreUnderlineStates();
1246     void CalcInlineScrollRect(Rect& inlineScrollRect);
1247 
1248     bool ResetObscureTickCountDown();
1249 
1250     bool IsTouchAtLeftOffset(float currentOffsetX);
1251     void FilterExistText();
1252     void CreateErrorParagraph(const std::string& content);
1253     void UpdateErrorTextMargin();
1254     void UpdateSelectController();
1255     void UpdateHandlesOffsetOnScroll(float offset);
1256     void CloseHandleAndSelect() override;
1257     bool RepeatClickCaret(const Offset& offset, int32_t lastCaretIndex, const RectF& lastCaretRect);
1258     void PaintTextRect();
1259     void GetIconPaintRect(const RefPtr<TextInputResponseArea>& responseArea, RoundRect& paintRect);
1260     void GetInnerFocusPaintRect(RoundRect& paintRect);
1261     void PaintResponseAreaRect();
1262     void PaintCancelRect();
1263     void PaintUnitRect();
1264     void PaintPasswordRect();
CancelNodeIsShow()1265     bool CancelNodeIsShow()
1266     {
1267         auto cleanNodeArea = AceType::DynamicCast<CleanNodeResponseArea>(cleanNodeResponseArea_);
1268         CHECK_NULL_RETURN(cleanNodeArea, false);
1269         return cleanNodeArea->IsShow();
1270     }
1271 
1272     void PasswordResponseKeyEvent();
1273     void UnitResponseKeyEvent();
1274     void ProcNormalInlineStateInBlurEvent();
1275 #if defined(ENABLE_STANDARD_INPUT)
1276     std::optional<MiscServices::TextConfig> GetMiscTextConfig() const;
1277 #endif
1278     bool IsSingleHandle() const;
SetIsSingleHandle(bool isSingleHandle)1279     void SetIsSingleHandle(bool isSingleHandle)
1280     {
1281         isSingleHandle_ = isSingleHandle;
1282     }
1283     void NotifyOnEditChanged(bool isChanged);
1284     void StartRequestSelectOverlay(const ShowSelectOverlayParams& params, bool isShowPaste = false);
1285     void ProcessResponseArea();
1286     bool HasInputOperation();
1287     AceAutoFillType ConvertToAceAutoFillType(TextInputType type);
1288     bool CheckAutoFill();
1289     bool ProcessAutoFill();
1290     void ScrollToSafeArea() const override;
1291     void RecordSubmitEvent() const;
1292     void UpdateCancelNode();
1293     void RequestKeyboardAfterLongPress();
1294     void UpdatePasswordModeState();
1295     void InitDragDropCallBack();
1296     void InitDragDropEventWithOutDragStart();
1297     void UpdateBlurReason();
1298     RectF GetSelectArea();
1299     void UpdateOverlaySelectArea();
1300 
1301     RectF frameRect_;
1302     RectF contentRect_;
1303     RectF textRect_;
1304     RefPtr<Paragraph> paragraph_;
1305     RefPtr<Paragraph> errorParagraph_;
1306     RefPtr<Paragraph> dragParagraph_;
1307     InlineMeasureItem inlineMeasureItem_;
1308     TextStyle nextLineUtilTextStyle_;
1309 
1310     RefPtr<ClickEvent> clickListener_;
1311     RefPtr<TouchEventImpl> touchListener_;
1312     RefPtr<ScrollableEvent> scrollableEvent_;
1313     RefPtr<InputEvent> mouseEvent_;
1314     RefPtr<InputEvent> hoverEvent_;
1315     RefPtr<LongPressEvent> longPressEvent_;
1316     CursorPositionType cursorPositionType_ = CursorPositionType::NORMAL;
1317 
1318     // What the keyboard should appears.
1319     TextInputType keyboard_ = TextInputType::UNSPECIFIED;
1320     // Action when "enter" pressed.
1321     TextInputAction action_ = TextInputAction::UNSPECIFIED;
1322     TextDirection textDirection_ = TextDirection::LTR;
1323 
1324     OffsetF parentGlobalOffset_;
1325     OffsetF lastTouchOffset_;
1326     PaddingPropertyF utilPadding_;
1327     OffsetF rightClickOffset_;
1328 
1329     BorderWidthProperty lastBorderWidth_;
1330 
1331     bool setBorderFlag_ = true;
1332     BorderWidthProperty lastDiffBorderWidth_;
1333     BorderColorProperty lastDiffBorderColor_;
1334 
1335     HandleMoveStatus handleMoveStatus_;
1336     bool cursorVisible_ = false;
1337     bool focusEventInitialized_ = false;
1338     bool isMousePressed_ = false;
1339     bool textObscured_ = true;
1340     bool enableTouchAndHoverEffect_ = true;
1341     bool isUsingMouse_ = false;
1342     bool isOnHover_ = false;
1343     bool needToRefreshSelectOverlay_ = false;
1344     bool needToRequestKeyboardInner_ = false;
1345     bool needToRequestKeyboardOnFocus_ = false;
1346     bool isTransparent_ = false;
1347     bool contChange_ = false;
1348     bool counterChange_ = false;
1349     WeakPtr<LayoutWrapper> counterTextNode_;
1350     bool isCursorAlwaysDisplayed_ = false;
1351     std::optional<int32_t> surfaceChangedCallbackId_;
1352     std::optional<int32_t> surfacePositionChangedCallbackId_;
1353 
1354     SelectionMode selectionMode_ = SelectionMode::NONE;
1355     CaretUpdateType caretUpdateType_ = CaretUpdateType::NONE;
1356     bool scrollable_ = true;
1357     bool blockPress_ = false;
1358     float previewWidth_ = 0.0f;
1359     float lastTextRectY_ = 0.0f;
1360     std::optional<DisplayMode> barState_;
1361     bool preInline = false;
1362     bool preUnderline = false;
1363     bool preErrorState_ = false;
1364     float preErrorMargin_ = 0.0f;
1365     bool restoreMarginState_ = false;
1366 
1367     uint32_t twinklingInterval_ = 0;
1368     int32_t obscureTickCountDown_ = 0;
1369     int32_t nakedCharPosition_ = -1;
1370     bool obscuredChange_ = false;
1371     float currentOffset_ = 0.0f;
1372     float countHeight_ = 0.0f;
1373     Dimension underlineWidth_ = 1.0_px;
1374     Color underlineColor_;
1375     bool scrollBarVisible_ = false;
1376     bool isCounterIdealheight_ = false;
1377     float maxFrameOffsetY_ = 0.0f;
1378     float maxFrameHeight_ = 0.0f;
1379 
1380     CancelableCallback<void()> cursorTwinklingTask_;
1381 
1382     std::list<std::unique_ptr<TextInputFormatter>> textInputFormatters_;
1383 
1384     RefPtr<TextFieldController> textFieldController_;
1385     RefPtr<TextEditController> textEditingController_;
1386     TextEditingValueNG textEditingValue_;
1387     // controls redraw of overlay modifier, update when need to redraw
1388     bool changeSelectedRects_ = false;
1389     RefPtr<TextFieldOverlayModifier> textFieldOverlayModifier_;
1390     RefPtr<TextFieldContentModifier> textFieldContentModifier_;
1391     ACE_DISALLOW_COPY_AND_MOVE(TextFieldPattern);
1392 
1393     int32_t dragTextStart_ = 0;
1394     int32_t dragTextEnd_ = 0;
1395     RefPtr<FrameNode> dragNode_;
1396     DragStatus dragStatus_ = DragStatus::NONE; // The status of the dragged initiator
1397     DragStatus dragRecipientStatus_ = DragStatus::NONE; // Drag the recipient's state
1398     RefPtr<Clipboard> clipboard_;
1399     std::vector<TextEditingValueNG> operationRecords_;
1400     std::vector<TextEditingValueNG> redoOperationRecords_;
1401     std::vector<MenuOptionsParam> menuOptionItems_;
1402     BorderRadiusProperty borderRadius_;
1403     PasswordModeStyle passwordModeStyle_;
1404     SelectMenuInfo selectMenuInfo_;
1405 
1406     // inline
1407     bool isTextInput_ = false;
1408     bool inlineSelectAllFlag_ = false;
1409     bool inlineFocusState_ = false;
1410     float inlineSingleLineHeight_ = 0.0f;
1411     float inlinePadding_ = 0.0f;
1412     bool needApplyInlineSize_ = false;
1413     PreState inlineState_;
1414     // inline --end
1415     PreState preUnderlineState_;
1416 
1417 #if defined(ENABLE_STANDARD_INPUT)
1418     sptr<OHOS::MiscServices::OnTextChangedListener> textChangeListener_;
1419 #else
1420     RefPtr<TextInputConnection> connection_;
1421 #endif
1422 #if defined(OHOS_STANDARD_SYSTEM) && !defined(PREVIEW)
1423     bool imeAttached_ = false;
1424     bool imeShown_ = false;
1425 #endif
1426     BlurReason blurReason_ = BlurReason::FOCUS_SWITCH;
1427     bool isFocusedBeforeClick_ = false;
1428     bool isCustomKeyboardAttached_ = false;
1429     std::function<void()> customKeyboardBuilder_;
1430     RefPtr<OverlayManager> keyboardOverlay_;
1431     bool isCustomFont_ = false;
1432     bool hasClicked_ = false;
1433     bool isDoubleClick_ = false;
1434     TimeStamp lastClickTimeStamp_;
1435     float paragraphWidth_ = 0.0f;
1436 
1437     std::queue<int32_t> deleteBackwardOperations_;
1438     std::queue<int32_t> deleteForwardOperations_;
1439     std::queue<std::string> insertValueOperations_;
1440     std::queue<InputOperation> inputOperations_;
1441     bool leftMouseCanMove_ = false;
1442     bool isSingleHandle_ = true;
1443     bool showSelect_ = false;
1444     bool isLongPress_ = false;
1445     RefPtr<ContentController> contentController_;
1446     RefPtr<TextSelectController> selectController_;
1447     RefPtr<NG::UINode> unitNode_;
1448     RefPtr<TextInputResponseArea> responseArea_;
1449     RefPtr<TextInputResponseArea> cleanNodeResponseArea_;
1450     std::string lastAutoFillPasswordTextValue_;
1451     bool isSupportCameraInput_ = false;
1452     std::function<void()> processOverlayDelayTask_;
1453     FocuseIndex focusIndex_ = FocuseIndex::TEXT;
1454     bool isShowMagnifier_ = false;
1455     OffsetF localOffset_;
1456     bool isTouchCaret_ = false;
1457     bool needSelectAll_ = false;
1458     bool isModifyDone_ = false;
1459     bool initTextRect_ = false;
1460     bool colorModeChange_ = false;
1461     Offset clickLocation_;
1462     MagnifierRect magnifierRect_;
1463     RefPtr<MagnifierController> magnifierController_;
1464     bool isKeyboardClosedByUser_ = false;
1465     bool lockRecord_ = false;
1466 };
1467 } // namespace OHOS::Ace::NG
1468 
1469 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_FIELD_TEXT_FIELD_PATTERN_H
1470