• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_TEXT_FIELD_RENDER_TEXT_FIELD_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEXT_FIELD_RENDER_TEXT_FIELD_H
18 
19 #include <functional>
20 
21 #include "base/geometry/dimension.h"
22 #include "base/geometry/offset.h"
23 #include "base/geometry/rect.h"
24 #include "base/geometry/size.h"
25 #include "base/memory/referenced.h"
26 #include "base/utils/system_properties.h"
27 #include "core/common/clipboard/clipboard.h"
28 #include "core/common/ime/text_edit_controller.h"
29 #include "core/common/ime/text_input_client.h"
30 #include "core/common/ime/text_input_connection.h"
31 #include "core/common/ime/text_input_formatter.h"
32 #include "core/common/ime/text_input_type.h"
33 #include "core/common/ime/text_selection.h"
34 #include "core/components/common/properties/color.h"
35 #include "core/components/common/properties/decoration.h"
36 #include "core/components/common/properties/text_style.h"
37 #include "core/components/image/render_image.h"
38 #include "core/components/panel/render_sliding_panel.h"
39 #include "core/components/text_field/text_field_component.h"
40 #include "core/components/text_overlay/text_overlay_manager.h"
41 #include "core/gestures/click_recognizer.h"
42 #include "core/gestures/long_press_recognizer.h"
43 #include "core/gestures/raw_recognizer.h"
44 #include "core/pipeline/base/overlay_show_option.h"
45 #include "core/pipeline/base/render_node.h"
46 
47 #if defined(ENABLE_STANDARD_INPUT)
48 #include "commonlibrary/c_utils/base/include/refbase.h"
49 
50 namespace OHOS::MiscServices {
51 class OnTextChangedListener;
52 }
53 #endif
54 
55 namespace OHOS::Ace {
56 
57 class ClickRecognizer;
58 class ClickInfo;
59 class TextOverlayComponent;
60 struct TextEditingValue;
61 
62 // Currently only CHARACTER.
63 enum class CursorMoveSkip {
64     CHARACTER, // Smallest code unit.
65     WORDS,
66     SIBLING_SPACE,
67     PARAGRAPH,
68 };
69 
70 enum class InputAction { UNKNOWN, INSERT, DELETE_FORWARD, DELETE_BACKWARD };
71 
72 enum {
73     ACTION_SELECT_ALL, // Smallest code unit.
74     ACTION_UNDO,
75     ACTION_REDO,
76     ACTION_CUT,
77     ACTION_COPY,
78     ACTION_PASTE,
79     ACTION_SHARE,
80     ACTION_PASTE_AS_PLAIN_TEXT,
81     ACTION_REPLACE,
82     ACTION_ASSIST,
83     ACTION_AUTOFILL,
84 };
85 
86 class RenderTextField : public RenderNode, public TextInputClient, public ValueChangeObserver {
87     DECLARE_ACE_TYPE(RenderTextField, RenderNode, TextInputClient, ValueChangeObserver);
88 
89 public:
90     ~RenderTextField() override;
91 
92     static RefPtr<RenderNode> Create();
93 
94     using TapCallback = std::function<bool(bool)>;
95 
96     void Update(const RefPtr<Component>& component) override;
97     void PerformLayout() override;
98     void UpdateInsertText(std::string insertValue);
99     // Override TextInputClient
100     void UpdateEditingValue(const std::shared_ptr<TextEditingValue>& value, bool needFireChangeEvent = true) override;
101     void PerformDefaultAction();
102     void PerformAction(TextInputAction action, bool forceCloseKeyboard = false) override;
103     void OnStatusChanged(RenderStatus renderStatus) override;
104     void OnValueChanged(bool needFireChangeEvent = true, bool needFireSelectChangeEvent = true) override;
105     void OnPaintFinish() override;
106     void Dump() override;
107 
108     bool OnKeyEvent(const KeyEvent& event);
109     bool RequestKeyboard(bool isFocusViewChanged, bool needStartTwinkling = false, bool needShowSoftKeyboard = true);
110     bool CloseKeyboard(bool forceClose = false);
111     void ShowError(const std::string& errorText, bool resetToStart = true);
112     void ShowTextOverlay(const Offset& showOffset, bool isSingleHandle, bool isUsingMouse = false);
113     void SetOnValueChange(const std::function<void()>& onValueChange);
114     const std::function<void()>& GetOnValueChange() const;
115     void SetOnKeyboardClose(const std::function<void(bool)>& onKeyboardClose);
116     void SetOnClipRectChanged(const std::function<void(const Rect&)>& onClipRectChanged);
117     void SetUpdateHandlePosition(const std::function<void(const OverlayShowOption&)>& updateHandlePosition);
118     void SetUpdateHandleDiameter(const std::function<void(const double&)>& updateHandleDiameter);
119     void SetUpdateHandleDiameterInner(const std::function<void(const double&)>& updateHandleDiameterInner);
120     void SetIsOverlayShowed(bool isOverlayShowed, bool needStartTwinkling = true);
121     void UpdateFocusAnimation();
122     const TextEditingValue& GetEditingValue() const;
123     const TextEditingValue& GetPreEditingValue() const;
124     double GetEditingBoxY() const override;
125     double GetEditingBoxTopY() const override;
126     bool GetEditingBoxModel() const override;
127     void Delete(int32_t start, int32_t end);
128     void CursorMoveLeft(CursorMoveSkip skip = CursorMoveSkip::CHARACTER);
129     void CursorMoveRight(CursorMoveSkip skip = CursorMoveSkip::CHARACTER);
130     void CursorMoveUp();
131     void CursorMoveDown();
132     void Insert(const std::string& text);
133     void StartTwinkling();
134     void StopTwinkling();
135     void EditingValueFilter(TextEditingValue& result);
136     void PopTextOverlay();
137     RefPtr<RenderSlidingPanel> GetSlidingPanelAncest();
138     void ResetOnFocusForTextFieldManager();
139     void ResetSlidingPanelParentHeight();
140     void HandleSetSelection(int32_t start, int32_t end);
141     void HandleExtendAction(int32_t action);
142     void HandleSelect(int32_t keyCode, int32_t cursorMoveSkip);
143 
SetInputFilter(const std::string & inputFilter)144     void SetInputFilter(const std::string& inputFilter)
145     {
146         inputFilter_ = inputFilter;
147     }
148 
SetTextStyle(const TextStyle & style)149     void SetTextStyle(const TextStyle& style)
150     {
151         style_ = style;
152     }
153 
SetOnOverlayFocusChange(const std::function<void (bool)> & onOverlayFocusChange)154     void SetOnOverlayFocusChange(const std::function<void(bool)>& onOverlayFocusChange)
155     {
156         onOverlayFocusChange_ = onOverlayFocusChange;
157     }
158 
159     // Whether textOverlay is showed.
IsOverlayShowed()160     bool IsOverlayShowed() const
161     {
162         return isOverlayShowed_;
163     }
164 
SetOverlayColor(const Color & overlayColor)165     void SetOverlayColor(const Color& overlayColor)
166     {
167         overlayColor_ = overlayColor;
168     }
169 
RegisterTapCallback(const TapCallback & callback)170     void RegisterTapCallback(const TapCallback& callback)
171     {
172         tapCallback_ = callback;
173     }
174 
SetNextFocusEvent(const std::function<void ()> & event)175     void SetNextFocusEvent(const std::function<void()>& event)
176     {
177         moveNextFocusEvent_ = event;
178     }
179 
SetSubmitEvent(std::function<void (const std::string &)> && event)180     void SetSubmitEvent(std::function<void(const std::string&)>&& event)
181     {
182         onSubmitEvent_ = event;
183     }
184 
GetColor()185     const Color& GetColor() const
186     {
187         if (decoration_) {
188             return decoration_->GetBackgroundColor();
189         }
190         return Color::TRANSPARENT;
191     }
192 
SetColor(const Color & color)193     void SetColor(const Color& color)
194     {
195         if (decoration_) {
196             decoration_->SetBackgroundColor(color);
197             MarkNeedRender();
198         }
199     }
200 
GetHeight()201     double GetHeight() const
202     {
203         return height_.Value();
204     }
205 
GetDimensionHeight()206     const Dimension& GetDimensionHeight() const
207     {
208         return height_;
209     }
210 
SetHeight(double height)211     void SetHeight(double height)
212     {
213         if (GreatOrEqual(height, 0.0) && !NearEqual(height_.Value(), height)) {
214             height_.SetValue(height);
215             MarkNeedLayout();
216         }
217     }
218 
GetStackElement()219     const WeakPtr<StackElement> GetStackElement() const
220     {
221         return stackElement_;
222     }
223 
SetWidthReservedForSearch(double widthReservedForSearch)224     void SetWidthReservedForSearch(double widthReservedForSearch)
225     {
226         widthReservedForSearch_ = widthReservedForSearch;
227     }
228 
SetPaddingHorizonForSearch(double paddingHorizon)229     void SetPaddingHorizonForSearch(double paddingHorizon)
230     {
231         paddingHorizonForSearch_ = paddingHorizon;
232     }
233 
HasTextOverlayPushed()234     bool HasTextOverlayPushed() const
235     {
236         return hasTextOverlayPushed_;
237     }
238 
GetIsInEditStatus()239     bool GetIsInEditStatus() const
240     {
241         return isInEditStatus_;
242     }
243 
SetIsInEditStatus(bool isInEditStatus)244     void SetIsInEditStatus(bool isInEditStatus)
245     {
246         isInEditStatus_ = isInEditStatus;
247     }
248 
GetPlaceholder()249     const std::string GetPlaceholder() const
250     {
251         return placeholder_;
252     }
253 
GetValue()254     const std::string GetValue() const
255     {
256         return text_;
257     }
258 
GetAction()259     TextInputAction GetAction() const
260     {
261         return action_;
262     }
263 
GetKeyboard()264     TextInputType GetKeyboard() const
265     {
266         return keyboard_;
267     }
268 
GetInactivePlaceholderColor()269     Color GetInactivePlaceholderColor() const
270     {
271         return inactivePlaceholderColor_;
272     }
273 
GetPlaceHoldStyle()274     TextStyle GetPlaceHoldStyle()
275     {
276         return placeHoldStyle_;
277     }
278 
GetTextAlign()279     TextAlign GetTextAlign()
280     {
281         return textAlign_;
282     }
283 
GetCursorColor()284     Color GetCursorColor() const
285     {
286         return cursorColor_;
287     }
288 
GetEditingStyle()289     TextStyle GetEditingStyle()
290     {
291         return editingStyle_;
292     }
293 
GetMaxLength()294     int32_t GetMaxLength()
295     {
296         return maxLength_;
297     }
298 
GetTextInputFilter()299     const std::string GetTextInputFilter() const
300     {
301         return inputFilter_;
302     }
303 
SetTextOverlayPushed(bool hasTextOverlayPushed)304     void SetTextOverlayPushed(bool hasTextOverlayPushed)
305     {
306         hasTextOverlayPushed_ = hasTextOverlayPushed;
307     }
308 
IsSingleHandle()309     bool IsSingleHandle() const
310     {
311         return isSingleHandle_;
312     }
313 
GetInitIndex()314     int32_t GetInitIndex() const
315     {
316         return initIndex_;
317     }
318 
SetInitIndex(int32_t initIndex)319     void SetInitIndex(int32_t initIndex)
320     {
321         initIndex_ = initIndex;
322     }
323 
SetOnTextChangeEvent(const std::function<void (const std::string &)> & onTextChangeEvent)324     void SetOnTextChangeEvent(const std::function<void(const std::string&)>& onTextChangeEvent)
325     {
326         onTextChangeEvent_ = onTextChangeEvent;
327     }
328 
SetOnValueChangeEvent(const std::function<void (const std::string &)> & onTextChangeEvent)329     void SetOnValueChangeEvent(const std::function<void(const std::string&)>& onTextChangeEvent)
330     {
331         onValueChangeEvent_ = onTextChangeEvent;
332     }
333 
SetNeedNotifyChangeEvent(bool needNotifyChangeEvent)334     void SetNeedNotifyChangeEvent(bool needNotifyChangeEvent)
335     {
336         needNotifyChangeEvent_ = needNotifyChangeEvent;
337     }
338 
339 #if defined(OHOS_STANDARD_SYSTEM) && !defined(PREVIEW)
SetInputMethodStatus(bool imeAttached)340     void SetInputMethodStatus(bool imeAttached)
341     {
342         imeAttached_ = imeAttached;
343     }
344 
345     void UpdateConfiguration();
346 #endif
347 
348     // distribute
349     std::string ProvideRestoreInfo() override;
350 
351     int32_t instanceId_ = -1;
352 
353     bool hasFocus_ = false;
354     void SetEditingValue(TextEditingValue&& newValue, bool needFireChangeEvent = true, bool isClearRecords = true);
355     void SetEditingValue(const std::string& text);
356 
GetOnEditChanged()357     const std::function<void(bool)>& GetOnEditChanged() const
358     {
359         return onEditChanged_;
360     }
361 
362     void OnEditChange(bool isInEditStatus);
363     void GetFieldAndOverlayTouchRect(std::vector<Rect>& resRectList);
364 
SetInputStyle(InputStyle style)365     void SetInputStyle(InputStyle style)
366     {
367         inputStyle_ = style;
368     }
369 
GetInputStyle()370     InputStyle GetInputStyle()
371     {
372         return inputStyle_;
373     }
374 
375     void HandleOnBlur();
376 
SetCanPaintSelection(bool flag)377     void SetCanPaintSelection(bool flag)
378     {
379         canPaintSelection_ = flag;
380     }
381 
GetCanPaintSelection()382     bool GetCanPaintSelection() const
383     {
384         return canPaintSelection_;
385     }
386 
SetLastInputAction(InputAction action)387     void SetLastInputAction(InputAction action)
388     {
389         lastInputAction_ = action;
390     }
391 
GetLastInputAction()392     InputAction GetLastInputAction()
393     {
394         return lastInputAction_;
395     }
396 
397     bool NeedToFilter();
398 
HasSurfaceChangedCallback()399     bool HasSurfaceChangedCallback()
400     {
401         return surfaceChangedCallbackId_.has_value();
402     }
UpdateSurfaceChangedCallbackId(int32_t id)403     void UpdateSurfaceChangedCallbackId(int32_t id)
404     {
405         surfaceChangedCallbackId_ = id;
406     }
407 
HasSurfacePositionChangedCallback()408     bool HasSurfacePositionChangedCallback()
409     {
410         return surfacePositionChangedCallbackId_.has_value();
411     }
UpdateSurfacePositionChangedCallbackId(int32_t id)412     void UpdateSurfacePositionChangedCallbackId(int32_t id)
413     {
414         surfacePositionChangedCallbackId_ = id;
415     }
416 
417 protected:
418     // Describe where caret is and how tall visually.
419     struct CaretMetrics {
ResetCaretMetrics420         void Reset()
421         {
422             offset.Reset();
423             height = 0.0;
424         }
425 
426         Offset offset;
427         // When caret is close to different glyphs, the height will be different.
428         double height = 0.0;
ToStringCaretMetrics429         std::string ToString() const
430         {
431             std::string result = "Offset: ";
432             result += offset.ToString();
433             result += ", height: ";
434             result += std::to_string(height);
435             return result;
436         }
437     };
438 
439     RenderTextField();
440     virtual Size Measure();
441     virtual int32_t GetCursorPositionForMoveUp() = 0;
442     virtual int32_t GetCursorPositionForMoveDown() = 0;
443     virtual int32_t GetCursorPositionForClick(const Offset& offset) = 0;
444     virtual Offset GetHandleOffset(int32_t extend) = 0;
445     virtual double PreferredLineHeight() = 0;
446     virtual int32_t AdjustCursorAndSelection(int32_t currentCursorPosition) = 0;
447     virtual DirectionStatus GetDirectionStatusOfPosition(int32_t position) const = 0;
448     virtual Size ComputeDeflateSizeOfErrorAndCountText() const = 0;
ResetStatus()449     virtual void ResetStatus() {};
450 
451     void OnTouchTestHit(
452         const Offset& coordinateOffset, const TouchRestrict& touchRestrict, TouchTestResult& result) override;
453     void OnHiddenChanged(bool hidden) override;
454     void OnAppHide() override;
455     void OnClick(const ClickInfo& clickInfo);
456     void OnDoubleClick(const ClickInfo& clickInfo);
457     void OnLongPress(const LongPressInfo& longPressInfo);
458     bool HandleMouseEvent(const MouseEvent& event) override;
459     void HandleMouseHoverEvent(MouseState mouseState) override;
460     void AnimateMouseHoverEnter() override;
461     void AnimateMouseHoverExit() override;
462     void HandleValueFilter(TextEditingValue& valueBeforeUpdate, TextEditingValue& valueNeedToUpdate);
463     bool FilterWithRegex(std::string& valueToUpdate, const std::string& filter, bool needToEscape = false);
464     void KeyboardEditingValueFilter(TextEditingValue& valueToUpdate);
465 
466     std::u16string GetTextForDisplay(const std::string& text) const;
467 
468     void UpdateStartSelection(int32_t end, const Offset& pos, bool isSingleHandle, bool isLongPress);
469     void UpdateEndSelection(int32_t start, const Offset& pos);
470     void UpdateSelection(int32_t both);
471     void UpdateSelection(int32_t start, int32_t end);
472     void UpdateDirectionStatus();
473     void UpdateCaretInfoToController();
474     Offset GetPositionForExtend(int32_t extend, bool isSingleHandle);
475     /**
476      * Get grapheme cluster length before or after extend.
477      * For example, here is a sentence: 123����
478      * The emoji character contains 2 code unit. Assumpt that the cursor is at the end (that will be 3+2+2 = 7).
479      * When calling GetGraphemeClusterLength(3, false), '��' is not in Utf16Bmp, so result is 2.
480      * When calling GetGraphemeClusterLength(3, true), '3' is in Utf16Bmp, so result is 1.
481      */
482     int32_t GetGraphemeClusterLength(int32_t extend, bool isPrefix) const;
483 
HasConnection()484     bool HasConnection() const
485     {
486 #if defined(OHOS_STANDARD_SYSTEM) && !defined(PREVIEW)
487         return imeAttached_;
488 #else
489         return connection_;
490 #endif
491     }
492 
493     bool ShowCounter() const;
494 
IsSelectiveDevice()495     static bool IsSelectiveDevice()
496     {
497         return (SystemProperties::GetDeviceType() != DeviceType::TV &&
498                 SystemProperties::GetDeviceType() != DeviceType::WATCH);
499     }
500 
501     void AddOutOfRectCallbackToContext();
502 
503     // Used for compare to the current value and decide whether to UpdateRemoteEditing().
504     std::shared_ptr<TextEditingValue> lastKnownRemoteEditingValue_;
505 
506     // An outline for caret. It is used by default when the actual size cannot be retrieved.
507     Rect caretProto_;
508     Rect innerRect_;
509     // Click region of password icon.
510     Rect passwordIconRect_;
511 
512     std::string placeholder_;
513     std::string inputFilter_;
514     Color placeholderColor_;
515     // Colors when not focused.
516     Color inactivePlaceholderColor_;
517     Color inactiveBgColor_;
518     Color inactiveTextColor_;
519     // Colors when focused.
520     Color focusPlaceholderColor_;
521     Color focusBgColor_;
522     Color focusTextColor_;
523     // Color when selected.
524     Color selectedColor_;
525     Color cursorColor_;
526     // Overlay color for hover and press.
527     Color overlayColor_ = Color::TRANSPARENT;
528     // The interval for caret twinkling, in ms.
529     uint32_t twinklingInterval = 0;
530     bool showPlaceholder_ = false;
531     bool cursorVisibility_ = false;
532     bool showCursor_ = true;
533     bool cursorColorIsSet_ = false;
534     Dimension cursorRadius_;
535     Dimension fontSize_;
536     // Used under case of [obscure_ == true].
537     // When a character input, it will be displayed naked for a while.
538     // The remaining time to naked display the recent character is indicated by [obscureTickPendings_],
539     // multiply by [twinklingInterval]. For example, 3 * 500ms = 1500ms.
540     int32_t obscureTickPendings_ = 0;
541     // What the keyboard should appears.
542     TextInputType keyboard_ = TextInputType::UNSPECIFIED;
543     // Action when "enter" pressed.
544     TextInputAction action_ = TextInputAction::UNSPECIFIED;
545     std::string actionLabel_;
546     uint32_t maxLength_ = std::numeric_limits<uint32_t>::max();
547     // Default to the start of text (according to RTL/LTR).
548     TextAlign textAlign_ = TextAlign::START;
549     // RTL/LTR is inherit from parent.
550     TextDirection textDirection_ = TextDirection::INHERIT;
551     TextDirection realTextDirection_ = TextDirection::INHERIT;
552     TextAffinity textAffinity_ = TextAffinity::DOWNSTREAM;
553 
554     TextStyle countTextStyle_;
555     TextStyle overCountStyle_;
556     TextStyle countTextStyleOuter_;
557     TextStyle overCountStyleOuter_;
558     TextStyle style_;
559     TextStyle placeHoldStyle_;
560     TextStyle editingStyle_;
561     std::string text_;
562     std::string insertValue_;
563     bool insertTextUpdated_ = false;
564     std::string errorText_;
565     TextStyle errorTextStyle_;
566     double errorSpacing_ = 0.0;
567     Dimension errorSpacingInDimension_;
568     // Place error text in or under input. In input when device is TV, under input when device is phone.
569     bool errorIsInner_ = false;
570     Dimension errorBorderWidth_;
571     Color errorBorderColor_;
572 
573     RefPtr<Decoration> decoration_;
574     Border originBorder_;
575 
576     // One line TextField is more common in usual cases.
577     uint32_t maxLines_ = 1;
578     size_t textLines_ = 0;
579     size_t textLinesLast_ = 0;
580     int32_t cursorPositionForShow_ = 0;
581     CursorPositionType cursorPositionType_ = CursorPositionType::NORMAL;
582     DirectionStatus directionStatus_ = DirectionStatus::LEFT_LEFT;
583     CopyOptions copyOption_ = CopyOptions::Distributed;
584 
585     bool showPasswordIcon_ = true; // Whether show password icon, effect only type is password.
586     bool showCounter_ = false;     // Whether show counter, 10/100 means maxlength is 100 and 10 has been inputted.
587     bool overCount_ = false;       // Whether count of text is over limit.
588     bool obscure_ = false;         // Obscure the text, for example, password.
589     bool passwordRecord_ = true;   // Record the status of password display or non-display.
590     bool enabled_ = true;          // Whether input is disable of enable.
591     bool needFade_ = false;        // Fade in/out text when overflow.
592     bool blockRightShade_ = false;
593     bool isValueFromFront_ = false;           // Is value from developer-set.
594     bool isValueFromRemote_ = false;          // Remote value coming form typing, other is from clopboard.
595     bool existStrongDirectionLetter_ = false; // Whether exist strong direction letter in text.
596     bool isVisible_ = true;
597     bool needNotifyChangeEvent_ = false;
598     bool resetToStart_ = true;      // When finish inputting text, whether show header of text.
599     bool showEllipsis_ = false;     // When text is overflow, whether show ellipsis.
600     bool extend_ = false;           // Whether input support extend, this attribute is worked in textarea.
601     bool isCallbackCalled_ = false; // Whether custom font is loaded.
602     bool isOverlayShowed_ = false;  // Whether overlay has showed.
603     bool isLongPressStatus_ = false;
604     double textHeight_ = 0.0; // Height of text.
605     double textHeightLast_ = 0.0;
606     double iconSize_ = 0.0;
607     double iconHotZoneSize_ = 0.0;
608     double extendHeight_ = 0.0;
609     double widthReservedForSearch_ = 0.0;  // Width reserved for delete icon of search.
610     double paddingHorizonForSearch_ = 0.0; // Width reserved for search button of search.
611     double selectHeight_ = 0.0;
612     bool canPaintSelection_ = false;
613     Dimension height_;
614     Dimension iconSizeInDimension_;
615     Dimension iconHotZoneSizeInDimension_;
616     Dimension widthReserved_;
617     std::optional<LayoutParam> lastLayoutParam_;
618     std::optional<Color> imageFill_;
619     std::string iconSrc_;
620     std::string showIconSrc_;
621     std::string hideIconSrc_;
622     RefPtr<RenderImage> iconImage_;
623     RefPtr<RenderImage> renderShowIcon_;
624     RefPtr<RenderImage> renderHideIcon_;
625 
626     Offset clickOffset_;
627     // For ensuring caret is visible on screen, we take a strategy that move the whole text painting area.
628     // It maybe seems rough, and doesn't support scrolling smoothly.
629     Offset textOffsetForShowCaret_;
630     InputStyle inputStyle_;
631     Rect caretRect_;
632 
633 private:
634     void SetCallback(const RefPtr<TextFieldComponent>& textField);
635     void StartPressAnimation(bool isPressDown);
636     void StartHoverAnimation(bool isHovered);
637     void ScheduleCursorTwinkling();
638     void OnCursorTwinkling();
639     void CursorMoveOnClick(const Offset& offset);
640     void UpdateRemoteEditing(bool needFireChangeEvent = true);
641     void UpdateObscure(const RefPtr<TextFieldComponent>& textField);
642     void UpdateFormatters();
643     void UpdateFocusStyles();
644     void UpdateIcon(const RefPtr<TextFieldComponent>& textField);
645     void UpdatePasswordIcon(const RefPtr<TextFieldComponent>& textField);
646     void UpdateOverlay();
647     void RegisterFontCallbacks();
648     void HandleOnSelect(KeyCode keyCode, CursorMoveSkip skip = CursorMoveSkip::CHARACTER);
649     void HandleOnRevoke();
650     void HandleOnInverseRevoke();
651     void HandleOnCut();
652     void HandleOnCopy();
653     void HandleOnPaste();
654     void HandleOnCopyAll(const std::function<void(const Offset&, const Offset&)>& callback);
655     void HandleOnStartHandleMove(int32_t end, const Offset& startHandleOffset,
656         const std::function<void(const Offset&)>& startCallback, bool isSingleHandle = false);
657     void HandleOnEndHandleMove(
658         int32_t start, const Offset& endHandleOffset, const std::function<void(const Offset&)>& endCallback);
659     RefPtr<StackElement> GetLastStack() const;
660     void InitAnimation();
661     void RegisterCallbacksToOverlay();
662     void PushTextOverlayToStack();
663     void UpdateAccessibilityAttr();
664     void InitAccessibilityEventListener();
665     bool HandleKeyEvent(const KeyEvent& event);
666     void ClearEditingValue();
667     virtual bool GetCaretRect(int32_t extent, Rect& caretRect, double caretHeightOffset = 0.0) const = 0;
668     bool SearchAction(const Offset& globalPosition, const Offset& globalOffset);
669     void ChangeCounterStyle(const TextEditingValue& value);
670     void ChangeBorderToErrorStyle();
671     void HandleDeviceOrientationChange();
672     void OnOverlayFocusChange(bool isFocus, bool needCloseKeyboard);
673     void FireSelectChangeIfNeeded(const TextEditingValue& newValue, bool needFireSelectChangeEvent) const;
674     int32_t GetInstanceId() const;
675     void ApplyAspectRatio(); // If aspect ratio is setted, height will follow box parent.
676 
677     /**
678      * @brief Update remote editing value only if text or selection is changed.
679      */
680     void UpdateRemoteEditingIfNeeded(bool needFireChangeEvent = true);
681 
682     void AttachIme();
683 
684     // distribute
685     void ApplyRestoreInfo();
686     void OnTapCallback();
687     void HandleSurfacePositionChanged(int32_t posX, int32_t posY);
688     void HandleSurfaceChanged(int32_t newWidth, int32_t newHeight, int32_t prevWidth, int32_t prevHeight);
689 
690     int32_t initIndex_ = 0;
691     bool isOverlayFocus_ = false;
692     bool isShiftDown_ = false;
693     bool isCtrlDown_ = false;
694     double fontScale_ = 1.0;
695     bool isSingleHandle_ = false;
696     bool hasTextOverlayPushed_ = false;
697     bool softKeyboardEnabled_ = true;
698     bool isInEditStatus_ = false;
699     bool isFocusOnTouch_ = true;
700     bool onTapCallbackResult_ = false;
701     InputAction lastInputAction_ = InputAction::UNKNOWN;
702     Color pressColor_;
703     Color hoverColor_;
704     TextSelection selection_; // Selection from custom.
705     DeviceOrientation deviceOrientation_ = DeviceOrientation::PORTRAIT;
706     std::function<void()> onValueChange_;
707     std::function<void(bool)> onKeyboardClose_;
708     std::function<void(const Rect&)> onClipRectChanged_;
709     std::function<void(const OverlayShowOption&)> updateHandlePosition_;
710     std::function<void(const double&)> updateHandleDiameter_;
711     std::function<void(const double&)> updateHandleDiameterInner_;
712     std::function<void(const std::string&)> onTextChangeEvent_;
713     std::function<void(std::string)> onChange_;
714     std::function<void(const ClickInfo& clickInfo)> onClick_;
715     std::function<void(const std::string&)> onError_;
716     std::function<void(bool)> onEditChanged_;
717     std::function<void(int32_t)> onSubmit_;
718     std::function<void(const std::string&)> onValueChangeEvent_;
719     std::function<void(const std::string&)> onSelectChangeEvent_;
720     std::function<void(const std::string&)> onFinishInputEvent_;
721     std::function<void(const std::string&)> onSubmitEvent_;
722     std::function<void()> onTapEvent_;
723     std::function<void()> onLongPressEvent_;
724     std::function<void()> moveNextFocusEvent_;
725     std::function<void(bool)> onOverlayFocusChange_;
726     std::function<void(std::string)> onCopy_;
727     std::function<void(std::string)> onCut_;
728     std::function<void(std::string)> onPaste_;
729     EventMarker onOptionsClick_;
730     EventMarker onTranslate_;
731     EventMarker onShare_;
732     EventMarker onSearch_;
733     bool catchMode_ = true;
734     TapCallback tapCallback_;
735     CancelableCallback<void()> cursorTwinklingTask_;
736 
737     std::optional<int32_t> surfaceChangedCallbackId_;
738     std::optional<int32_t> surfacePositionChangedCallbackId_;
739     std::vector<InputOption> inputOptions_;
740     std::list<std::unique_ptr<TextInputFormatter>> textInputFormatters_;
741     RefPtr<TextEditController> controller_;
742     RefPtr<TextFieldController> textFieldController_;
743     RefPtr<TextInputConnection> connection_;
744     RefPtr<Clipboard> clipboard_;
745     RefPtr<TextOverlayComponent> textOverlay_;
746     WeakPtr<StackElement> stackElement_;
747     RefPtr<ClickRecognizer> clickRecognizer_;
748     RefPtr<ClickRecognizer> doubleClickRecognizer_;
749     RefPtr<LongPressRecognizer> longPressRecognizer_;
750     RefPtr<RawRecognizer> rawRecognizer_;
751     RefPtr<Animator> pressController_;
752     RefPtr<Animator> hoverController_;
753     RefPtr<Animator> animator_;
754     std::vector<TextEditingValue> operationRecords_;
755     std::vector<TextEditingValue> inverseOperationRecords_;
756 #if defined(OHOS_STANDARD_SYSTEM) && !defined(PREVIEW)
757     bool imeAttached_ = false;
758 #endif
759 
760 #if defined(ENABLE_STANDARD_INPUT)
761     sptr<OHOS::MiscServices::OnTextChangedListener> textChangeListener_;
762 #endif
763 };
764 
765 } // namespace OHOS::Ace
766 
767 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEXT_FIELD_RENDER_TEXT_FIELD_H
768