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