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 <string> 22 #include <utility> 23 #include <vector> 24 25 #include "base/geometry/ng/offset_t.h" 26 #include "base/geometry/ng/rect_t.h" 27 #include "base/geometry/rect.h" 28 #include "base/mousestyle/mouse_style.h" 29 #include "core/common/clipboard/clipboard.h" 30 #include "core/common/ime/text_edit_controller.h" 31 #include "core/common/ime/text_input_action.h" 32 #include "core/common/ime/text_input_client.h" 33 #include "core/common/ime/text_input_configuration.h" 34 #include "core/common/ime/text_input_connection.h" 35 #include "core/common/ime/text_input_formatter.h" 36 #include "core/common/ime/text_input_proxy.h" 37 #include "core/common/ime/text_input_type.h" 38 #include "core/common/ime/text_selection.h" 39 #include "core/components_ng/image_provider/image_loading_context.h" 40 #include "core/components_ng/pattern/pattern.h" 41 #include "core/components_ng/pattern/scroll/inner/scroll_bar.h" 42 #include "core/components_ng/pattern/scroll_bar/proxy/scroll_bar_proxy.h" 43 #include "core/components_ng/pattern/scrollable/scrollable_pattern.h" 44 #include "core/components_ng/pattern/text/text_base.h" 45 #include "core/components_ng/pattern/text/text_menu_extension.h" 46 #include "core/components_ng/pattern/text_drag/text_drag_base.h" 47 #include "core/components_ng/pattern/text_field/text_editing_value_ng.h" 48 #include "core/components_ng/pattern/text_field/text_field_accessibility_property.h" 49 #include "core/components_ng/pattern/text_field/text_field_controller.h" 50 #include "core/components_ng/pattern/text_field/text_field_event_hub.h" 51 #include "core/components_ng/pattern/text_field/text_field_layout_algorithm.h" 52 #include "core/components_ng/pattern/text_field/text_field_layout_property.h" 53 #include "core/components_ng/pattern/text_field/text_field_paint_method.h" 54 #include "core/components_ng/pattern/text_field/text_field_paint_property.h" 55 #include "core/components_ng/pattern/text_field/text_selector.h" 56 #include "core/components_ng/property/property.h" 57 #include "core/gestures/gesture_info.h" 58 59 #if not defined(ACE_UNITTEST) 60 #if defined(ENABLE_STANDARD_INPUT) 61 #include "commonlibrary/c_utils/base/include/refbase.h" 62 63 namespace OHOS::MiscServices { 64 class OnTextChangedListener; 65 struct TextConfig; 66 } // namespace OHOS::MiscServices 67 #endif 68 #endif 69 70 namespace OHOS::Ace::NG { 71 72 constexpr Dimension CURSOR_WIDTH = 1.5_vp; 73 constexpr Dimension SCROLL_BAR_MIN_HEIGHT = 4.0_vp; 74 constexpr Dimension UNDERLINE_WIDTH = 1.0_px; 75 constexpr Dimension ERROR_UNDERLINE_WIDTH = 2.0_px; 76 constexpr Dimension ACTIVED_UNDERLINE_WIDTH = 2.0_px; 77 constexpr Dimension TYPING_UNDERLINE_WIDTH = 2.0_px; 78 constexpr uint32_t INLINE_DEFAULT_VIEW_MAXLINE = 3; 79 80 enum class SelectionMode { SELECT, SELECT_ALL, NONE }; 81 82 enum class DragStatus { DRAGGING, ON_DROP, NONE }; 83 84 enum { 85 ACTION_SELECT_ALL, // Smallest code unit. 86 ACTION_UNDO, 87 ACTION_REDO, 88 ACTION_CUT, 89 ACTION_COPY, 90 ACTION_PASTE, 91 ACTION_SHARE, 92 ACTION_PASTE_AS_PLAIN_TEXT, 93 ACTION_REPLACE, 94 ACTION_ASSIST, 95 ACTION_AUTOFILL, 96 }; 97 98 struct CaretMetricsF { ResetCaretMetricsF99 void Reset() 100 { 101 offset.Reset(); 102 height = 0.0; 103 } 104 105 OffsetF offset; 106 // When caret is close to different glyphs, the height will be different. 107 float height = 0.0; ToStringCaretMetricsF108 std::string ToString() const 109 { 110 std::string result = "Offset: "; 111 result += offset.ToString(); 112 result += ", height: "; 113 result += std::to_string(height); 114 return result; 115 } 116 }; 117 118 struct PasswordModeStyle { 119 Color bgColor; 120 Color textColor; 121 BorderWidthProperty borderwidth; 122 BorderColorProperty borderColor; 123 BorderRadiusProperty radius; 124 PaddingProperty padding; 125 }; 126 127 struct PreInlineState { 128 Color textColor; 129 Color bgColor; 130 BorderRadiusProperty radius; 131 BorderWidthProperty borderWidth; 132 BorderColorProperty borderColor; 133 PaddingProperty padding; 134 MarginProperty margin; 135 RectF frameRect; 136 bool setHeight = false; 137 bool saveInlineState = false; 138 bool hasBorderColor = false; 139 }; 140 141 class TextFieldPattern : public ScrollablePattern, 142 public TextDragBase, 143 public ValueChangeObserver, 144 public TextInputClient, 145 public TextBase { 146 DECLARE_ACE_TYPE(TextFieldPattern, ScrollablePattern, TextDragBase, ValueChangeObserver, TextInputClient, TextBase); 147 148 public: 149 TextFieldPattern(); 150 ~TextFieldPattern() override; 151 CreateNodePaintMethod()152 RefPtr<NodePaintMethod> CreateNodePaintMethod() override 153 { 154 if (!textFieldContentModifier_) { 155 textFieldContentModifier_ = AceType::MakeRefPtr<TextFieldContentModifier>(WeakClaim(this)); 156 } 157 auto textFieldOverlayModifier = AceType::DynamicCast<TextFieldOverlayModifier>(GetScrollBarOverlayModifier()); 158 if (!textFieldOverlayModifier) { 159 textFieldOverlayModifier = 160 AceType::MakeRefPtr<TextFieldOverlayModifier>(WeakClaim(this), GetScrollEdgeEffect()); 161 SetScrollBarOverlayModifier(textFieldOverlayModifier); 162 } 163 if (isCustomFont_) { 164 textFieldContentModifier_->SetIsCustomFont(true); 165 } 166 auto paint = 167 MakeRefPtr<TextFieldPaintMethod>(WeakClaim(this), textFieldOverlayModifier, textFieldContentModifier_); 168 auto scrollBar = GetScrollBar(); 169 if (scrollBar) { 170 paint->SetScrollBar(scrollBar); 171 if (scrollBar->NeedPaint()) { 172 textFieldOverlayModifier->SetRect(scrollBar->GetActiveRect(), scrollBar->GetBarRect()); 173 } 174 } 175 return paint; 176 } 177 CreateLayoutProperty()178 RefPtr<LayoutProperty> CreateLayoutProperty() override 179 { 180 return MakeRefPtr<TextFieldLayoutProperty>(); 181 } 182 CreateEventHub()183 RefPtr<EventHub> CreateEventHub() override 184 { 185 return MakeRefPtr<TextFieldEventHub>(); 186 } 187 CreatePaintProperty()188 RefPtr<PaintProperty> CreatePaintProperty() override 189 { 190 return MakeRefPtr<TextFieldPaintProperty>(); 191 } 192 CreateAccessibilityProperty()193 RefPtr<AccessibilityProperty> CreateAccessibilityProperty() override 194 { 195 return MakeRefPtr<TextFieldAccessibilityProperty>(); 196 } 197 CreateLayoutAlgorithm()198 RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override 199 { 200 return MakeRefPtr<TextFieldLayoutAlgorithm>(); 201 } 202 203 void OnModifyDone() override; GetInstanceId()204 int32_t GetInstanceId() const 205 { 206 return instanceId_; 207 } 208 209 void UpdateCaretPositionByTextEdit(); 210 void UpdateCaretPositionByPressOffset(); 211 void UpdateSelectionOffset(); 212 213 CaretMetricsF CalcCursorOffsetByPosition(int32_t position, bool isStart = true); 214 215 bool ComputeOffsetForCaretDownstream(int32_t extent, CaretMetricsF& result); 216 217 bool ComputeOffsetForCaretUpstream(int32_t extent, CaretMetricsF& result) const; 218 GetDrawOverlayFlag()219 uint32_t GetDrawOverlayFlag() const 220 { 221 return drawOverlayFlag_; 222 } 223 224 OffsetF MakeEmptyOffset() const; 225 226 int32_t ConvertTouchOffsetToCaretPosition(const Offset& localOffset); 227 228 void InsertValue(const std::string& insertValue); 229 void DeleteBackward(int32_t length); 230 void DeleteForward(int32_t length); 231 232 float GetTextOrPlaceHolderFontSize(); 233 SetTextFieldController(const RefPtr<TextFieldController> & controller)234 void SetTextFieldController(const RefPtr<TextFieldController>& controller) 235 { 236 textFieldController_ = controller; 237 } 238 GetTextFieldController()239 const RefPtr<TextFieldController>& GetTextFieldController() 240 { 241 return textFieldController_; 242 } 243 SetTextEditController(const RefPtr<TextEditController> & textEditController)244 void SetTextEditController(const RefPtr<TextEditController>& textEditController) 245 { 246 textEditingController_ = textEditController; 247 } 248 249 const TextEditingValueNG& GetEditingValue() const; 250 251 #if defined(IOS_PLATFORM) GetInputEditingValue()252 const TextEditingValue& GetInputEditingValue() const override 253 { 254 static TextEditingValue value; 255 return value; 256 }; 257 Offset GetGlobalOffset() const; 258 double GetEditingBoxY() const override; 259 double GetEditingBoxTopY() const override; 260 bool GetEditingBoxModel() const override; 261 #endif 262 UpdateEditingValue(std::string value,int32_t caretPosition)263 void UpdateEditingValue(std::string value, int32_t caretPosition) 264 { 265 textEditingValue_.text = std::move(value); 266 textEditingValue_.caretPosition = caretPosition; 267 } 268 void SetEditingValueToProperty(const std::string& newValueText); 269 270 void UpdatePositionOfParagraph(int32_t pos); 271 void UpdateCaretPositionByTouch(const Offset& offset); 272 void UpdateCaretOffsetByEvent(); 273 274 TextInputAction GetDefaultTextInputAction(); 275 std::string GetInputFilterWithInputType(); 276 bool RequestKeyboard(bool isFocusViewChanged, bool needStartTwinkling, bool needShowSoftKeyboard); 277 bool CloseKeyboard(bool forceClose) override; 278 GetFocusPattern()279 FocusPattern GetFocusPattern() const override 280 { 281 return { FocusType::NODE, true }; 282 } 283 284 void PerformAction(TextInputAction action, bool forceCloseKeyboard = true) override; 285 void UpdateEditingValue(const std::shared_ptr<TextEditingValue>& value, bool needFireChangeEvent = true) override; 286 void UpdateInputFilterErrorText(const std::string& errorText) override; 287 288 void OnValueChanged(bool needFireChangeEvent = true, bool needFireSelectChangeEvent = true) override; 289 290 void OnAreaChangedInner() override; 291 void OnVisibleChange(bool isVisible) override; 292 void ClearEditingValue(); 293 void HandleCounterBorder(); 294 ACE_DEFINE_PROPERTY_ITEM_FUNC_WITHOUT_GROUP(TextInputAction,TextInputAction)295 ACE_DEFINE_PROPERTY_ITEM_FUNC_WITHOUT_GROUP(TextInputAction, TextInputAction) 296 297 float GetBaseLineOffset() const 298 { 299 return baselineOffset_; 300 } 301 GetParagraph()302 const std::shared_ptr<RSParagraph>& GetParagraph() const 303 { 304 return paragraph_; 305 } 306 GetCounterParagraph()307 const std::shared_ptr<RSParagraph>& GetCounterParagraph() const 308 { 309 return counterParagraph_; 310 } 311 GetErrorParagraph()312 const std::shared_ptr<RSParagraph>& GetErrorParagraph() const 313 { 314 return errorParagraph_; 315 } 316 GetCursorVisible()317 bool GetCursorVisible() const 318 { 319 return cursorVisible_; 320 } 321 322 #if defined(OHOS_STANDARD_SYSTEM) && !defined(PREVIEW) GetImeAttached()323 bool GetImeAttached() const 324 { 325 return imeAttached_; 326 } 327 #endif 328 329 bool DisplayPlaceHolder(); 330 GetLastTouchOffset()331 const Offset& GetLastTouchOffset() 332 { 333 return lastTouchOffset_; 334 } 335 GetRightClickOffset()336 const OffsetF& GetRightClickOffset() 337 { 338 return rightClickOffset_; 339 } 340 GetSelectionBaseOffsetX()341 float GetSelectionBaseOffsetX() const 342 { 343 return textSelector_.selectionBaseOffset.GetX(); 344 } 345 GetSelectionDestinationOffsetX()346 float GetSelectionDestinationOffsetX() const 347 { 348 return textSelector_.selectionDestinationOffset.GetX(); 349 } 350 GetCaretOffset()351 OffsetF GetCaretOffset() const 352 { 353 return OffsetF(caretRect_.GetX(), caretRect_.GetY()); 354 } 355 GetCaretOffsetX()356 float GetCaretOffsetX() const 357 { 358 return caretRect_.GetX(); 359 } 360 SetCaretOffsetX(float offsetX)361 void SetCaretOffsetX(float offsetX) 362 { 363 caretRect_.SetLeft(offsetX); 364 } 365 GetSelectOverlay()366 const RefPtr<SelectOverlayProxy>& GetSelectOverlay() 367 { 368 return selectOverlayProxy_; 369 } 370 SetSelectOverlay(const RefPtr<SelectOverlayProxy> & proxy)371 void SetSelectOverlay(const RefPtr<SelectOverlayProxy>& proxy) 372 { 373 selectOverlayProxy_ = proxy; 374 } 375 GetCaretUpdateType()376 CaretUpdateType GetCaretUpdateType() const 377 { 378 return caretUpdateType_; 379 } 380 SetCaretUpdateType(CaretUpdateType type)381 void SetCaretUpdateType(CaretUpdateType type) 382 { 383 caretUpdateType_ = type; 384 } 385 386 float AdjustTextRectOffsetX(); 387 float AdjustTextAreaOffsetY(); 388 void AdjustTextSelectionRectOffsetX(); 389 GetPaddingTop()390 float GetPaddingTop() const 391 { 392 return utilPadding_.top.value_or(0.0f); 393 } 394 GetPaddingBottom()395 float GetPaddingBottom() const 396 { 397 return utilPadding_.bottom.value_or(0.0f); 398 } 399 GetPaddingLeft()400 float GetPaddingLeft() const 401 { 402 return utilPadding_.left.value_or(0.0f); 403 } 404 GetPaddingRight()405 float GetPaddingRight() const 406 { 407 return utilPadding_.right.value_or(0.0f); 408 } 409 GetUtilPadding()410 const PaddingPropertyF& GetUtilPadding() const 411 { 412 return utilPadding_; 413 } 414 GetHorizontalPaddingSum()415 float GetHorizontalPaddingSum() const 416 { 417 return utilPadding_.left.value_or(0.0f) + utilPadding_.right.value_or(0.0f); 418 } 419 GetVerticalPaddingSum()420 float GetVerticalPaddingSum() const 421 { 422 return utilPadding_.top.value_or(0.0f) + utilPadding_.bottom.value_or(0.0f); 423 } 424 GetBorderLeft()425 float GetBorderLeft() const 426 { 427 return lastBorderWidth_.leftDimen.value_or(Dimension(0.0f)).ConvertToPx(); 428 } 429 GetBorderTop()430 float GetBorderTop() const 431 { 432 return lastBorderWidth_.topDimen.value_or(Dimension(0.0f)).ConvertToPx(); 433 } 434 GetBorderBottom()435 float GetBorderBottom() const 436 { 437 return lastBorderWidth_.bottomDimen.value_or(Dimension(0.0f)).ConvertToPx(); 438 } 439 GetBorderRight()440 float GetBorderRight() const 441 { 442 return lastBorderWidth_.rightDimen.value_or(Dimension(0.0f)).ConvertToPx(); 443 } 444 GetTextRect()445 const RectF& GetTextRect() override 446 { 447 return textRect_; 448 } 449 SetTextRect(const RectF & textRect)450 void SetTextRect(const RectF& textRect) 451 { 452 textRect_ = textRect; 453 } 454 GetContentRect()455 const RectF& GetContentRect() const 456 { 457 return contentRect_; 458 } 459 GetFrameRect()460 const RectF& GetFrameRect() const 461 { 462 return frameRect_; 463 } 464 GetCountHeight()465 float GetCountHeight() const 466 { 467 return countHeight_; 468 } 469 GetTextSelector()470 const TextSelector& GetTextSelector() 471 { 472 return textSelector_; 473 } 474 SetInSelectMode(SelectionMode selectionMode)475 void SetInSelectMode(SelectionMode selectionMode) 476 { 477 selectionMode_ = selectionMode; 478 } 479 GetSelectMode()480 SelectionMode GetSelectMode() const 481 { 482 return selectionMode_; 483 } 484 IsSelected()485 bool IsSelected() const override 486 { 487 return selectionMode_ != SelectionMode::NONE && !textSelector_.StartEqualToDest(); 488 } 489 IsUsingMouse()490 bool IsUsingMouse() const 491 { 492 return isUsingMouse_; 493 } 494 int32_t GetWordLength(int32_t originCaretPosition, int32_t directionalMove); 495 int32_t GetLineBeginPosition(int32_t originCaretPosition, bool needToCheckLineChanged = true); 496 int32_t GetLineEndPosition(int32_t originCaretPosition, bool needToCheckLineChanged = true); IsOperation()497 bool IsOperation() const 498 { 499 return textEditingValue_.ToString().length() > 1; 500 } 501 502 bool CursorMoveLeft(); 503 bool CursorMoveLeftWord(); 504 bool CursorMoveLineBegin(); 505 bool CursorMoveToParagraphBegin(); 506 bool CursorMoveHome(); 507 bool CursorMoveRight(); 508 bool CursorMoveRightWord(); 509 bool CursorMoveLineEnd(); 510 bool CursorMoveToParagraphEnd(); 511 bool CursorMoveEnd(); 512 bool CursorMoveUp(); 513 bool CursorMoveDown(); 514 void SetCaretPosition(int32_t position); 515 void SetTextSelection(int32_t selectionStart, int32_t selectionEnd); 516 void HandleSetSelection(int32_t start, int32_t end, bool showHandle = true); 517 void HandleExtendAction(int32_t action); 518 void HandleSelect(int32_t keyCode, int32_t cursorMoveSkip); 519 OffsetF GetDragUpperLeftCoordinates() override; 520 GetTextBoxes()521 std::vector<RSTypographyProperties::TextBox> GetTextBoxes() override 522 { 523 return textBoxes_; 524 } 525 void CaretMoveToLastNewLineChar(); 526 void ToJsonValue(std::unique_ptr<JsonValue>& json) const override; 527 void FromJson(const std::unique_ptr<JsonValue>& json) override; 528 void InitEditingValueText(std::string content); 529 void InitCaretPosition(std::string content); GetTextEditingValue()530 const TextEditingValueNG& GetTextEditingValue() 531 { 532 return textEditingValue_; 533 } 534 535 bool SelectOverlayIsOn(); 536 void CloseSelectOverlay() override; 537 void CloseSelectOverlay(bool animation); SetInputMethodStatus(bool keyboardShown)538 void SetInputMethodStatus(bool keyboardShown) 539 { 540 #if defined(OHOS_STANDARD_SYSTEM) && !defined(PREVIEW) 541 imeShown_ = keyboardShown; 542 #endif 543 } 544 std::u16string GetLeftTextOfCursor(int32_t number); 545 std::u16string GetRightTextOfCursor(int32_t number); 546 int32_t GetTextIndexAtCursor(); 547 HasConnection()548 bool HasConnection() const 549 { 550 #if defined(OHOS_STANDARD_SYSTEM) && !defined(PREVIEW) 551 return imeAttached_; 552 #else 553 return connection_; 554 #endif 555 } 556 float PreferredLineHeight(); SetNeedCloseOverlay(bool needClose)557 void SetNeedCloseOverlay(bool needClose) 558 { 559 needCloseOverlay_ = needClose; 560 } GetShowPasswordIconCtx()561 const RefPtr<ImageLoadingContext>& GetShowPasswordIconCtx() const 562 { 563 return showPasswordImageLoadingCtx_; 564 } 565 566 void SearchRequestKeyboard(); 567 GetShowPasswordIconCanvasImage()568 const RefPtr<CanvasImage>& GetShowPasswordIconCanvasImage() const 569 { 570 return showPasswordCanvasImage_; 571 } 572 GetHidePasswordIconCtx()573 const RefPtr<ImageLoadingContext>& GetHidePasswordIconCtx() const 574 { 575 return hidePasswordImageLoadingCtx_; 576 } 577 GetHidePasswordIconCanvasImage()578 const RefPtr<CanvasImage>& GetHidePasswordIconCanvasImage() const 579 { 580 return hidePasswordCanvasImage_; 581 } 582 GetTextObscured()583 bool GetTextObscured() const 584 { 585 return textObscured_; 586 } 587 SetTextObscured(bool obscured)588 void SetTextObscured(bool obscured) 589 { 590 textObscured_ = obscured; 591 } 592 593 static std::u16string CreateObscuredText(int32_t len); 594 static std::u16string CreateDisplayText( 595 const std::string& content, int32_t nakedCharPosition, bool needObscureText); 596 bool IsTextArea() const override; GetImageRect()597 const RectF& GetImageRect() const 598 { 599 return imageRect_; 600 } 601 GetTouchListener()602 const RefPtr<TouchEventImpl>& GetTouchListener() 603 { 604 return touchListener_; 605 } 606 NeedShowPasswordIcon()607 bool NeedShowPasswordIcon() 608 { 609 auto layoutProperty = GetLayoutProperty<TextFieldLayoutProperty>(); 610 CHECK_NULL_RETURN_NOLOG(layoutProperty, false); 611 return layoutProperty->GetTextInputTypeValue(TextInputType::UNSPECIFIED) == TextInputType::VISIBLE_PASSWORD && 612 layoutProperty->GetShowPasswordIconValue(true); 613 } 614 SetShowUserDefinedIcon(bool enable)615 void SetShowUserDefinedIcon(bool enable) 616 { 617 showUserDefinedIcon_ = enable; 618 } 619 SetHideUserDefinedIcon(bool enable)620 void SetHideUserDefinedIcon(bool enable) 621 { 622 hideUserDefinedIcon_ = enable; 623 } 624 SetShowUserDefinedIconSrc(const std::string & iconSrc)625 void SetShowUserDefinedIconSrc(const std::string& iconSrc) 626 { 627 showUserDefinedIconSrc_ = iconSrc; 628 } 629 SetHideUserDefinedIconSrc(const std::string & iconSrc)630 void SetHideUserDefinedIconSrc(const std::string& iconSrc) 631 { 632 hideUserDefinedIconSrc_ = iconSrc; 633 } 634 SetEnableTouchAndHoverEffect(bool enable)635 void SetEnableTouchAndHoverEffect(bool enable) 636 { 637 enableTouchAndHoverEffect_ = enable; 638 } 639 GetCaretRect()640 const RectF& GetCaretRect() const 641 { 642 return caretRect_; 643 } 644 645 void UpdateCaretRectByPosition(int32_t position); 646 float GetIconRightOffset(); 647 float GetIconHotZoneSize(); 648 float GetIconSize(); 649 650 void HandleSurfaceChanged(int32_t newWidth, int32_t newHeight, int32_t prevWidth, int32_t prevHeight); 651 void HandleSurfacePositionChanged(int32_t posX, int32_t posY) const; 652 653 void InitSurfaceChangedCallback(); 654 void InitSurfacePositionChangedCallback(); 655 HasSurfaceChangedCallback()656 bool HasSurfaceChangedCallback() 657 { 658 return surfaceChangedCallbackId_.has_value(); 659 } UpdateSurfaceChangedCallbackId(int32_t id)660 void UpdateSurfaceChangedCallbackId(int32_t id) 661 { 662 surfaceChangedCallbackId_ = id; 663 } 664 HasSurfacePositionChangedCallback()665 bool HasSurfacePositionChangedCallback() 666 { 667 return surfacePositionChangedCallbackId_.has_value(); 668 } UpdateSurfacePositionChangedCallbackId(int32_t id)669 void UpdateSurfacePositionChangedCallbackId(int32_t id) 670 { 671 surfacePositionChangedCallbackId_ = id; 672 } 673 674 void ProcessInnerPadding(); 675 void OnCursorMoveDone(); 676 bool IsDisabled(); 677 bool AllowCopy(); 678 GetIsMousePressed()679 bool GetIsMousePressed() const 680 { 681 return isMousePressed_; 682 } GetMouseStatus()683 MouseStatus GetMouseStatus() const 684 { 685 return mouseStatus_; 686 } 687 SetMenuOptionItems(std::vector<MenuOptionsParam> && menuOptionItems)688 void SetMenuOptionItems(std::vector<MenuOptionsParam>&& menuOptionItems) 689 { 690 menuOptionItems_ = std::move(menuOptionItems); 691 } 692 GetMenuOptionItems()693 const std::vector<MenuOptionsParam>&& GetMenuOptionItems() const 694 { 695 return std::move(menuOptionItems_); 696 } 697 698 void UpdateEditingValueToRecord(); 699 void UpdateEditingValueCaretPositionToRecord(); 700 void UpdateScrollBarOffset() override; 701 UpdateCurrentOffset(float offset,int32_t source)702 bool UpdateCurrentOffset(float offset, int32_t source) override 703 { 704 return true; 705 } 706 IsAtTop()707 bool IsAtTop() const override 708 { 709 return true; 710 } 711 IsAtBottom()712 bool IsAtBottom() const override 713 { 714 return true; 715 } 716 IsScrollable()717 bool IsScrollable() const override 718 { 719 return scrollable_; 720 } 721 IsAtomicNode()722 bool IsAtomicNode() const override 723 { 724 return true; 725 } 726 GetCurrentOffset()727 float GetCurrentOffset() const 728 { 729 return currentOffset_; 730 } 731 GetContentModifier()732 RefPtr<TextFieldContentModifier> GetContentModifier() 733 { 734 return textFieldContentModifier_; 735 } 736 737 double GetScrollBarWidth(); 738 GetLineHeight()739 float GetLineHeight() const override 740 { 741 return caretRect_.Height(); 742 } 743 GetParentGlobalOffset()744 OffsetF GetParentGlobalOffset() const override 745 { 746 return parentGlobalOffset_; 747 } 748 GetTextContentRect()749 const RectF& GetTextContentRect() const override 750 { 751 return contentRect_; 752 } 753 GetDragParagraph()754 ParagraphT GetDragParagraph() const override 755 { 756 return { dragParagraph_ }; 757 } 758 MoveDragNode()759 RefPtr<FrameNode> MoveDragNode() override 760 { 761 return std::move(dragNode_); 762 } 763 GetDragContents()764 const std::vector<std::string>& GetDragContents() const 765 { 766 return dragContents_; 767 } 768 AddDragFrameNodeToManager(const RefPtr<FrameNode> & frameNode)769 void AddDragFrameNodeToManager(const RefPtr<FrameNode>& frameNode) 770 { 771 auto context = PipelineContext::GetCurrentContext(); 772 CHECK_NULL_VOID(context); 773 auto dragDropManager = context->GetDragDropManager(); 774 CHECK_NULL_VOID(dragDropManager); 775 dragDropManager->AddDragFrameNode(frameNode->GetId(), AceType::WeakClaim(AceType::RawPtr(frameNode))); 776 } 777 RemoveDragFrameNodeFromManager(const RefPtr<FrameNode> & frameNode)778 void RemoveDragFrameNodeFromManager(const RefPtr<FrameNode>& frameNode) 779 { 780 auto context = PipelineContext::GetCurrentContext(); 781 CHECK_NULL_VOID(context); 782 auto dragDropManager = context->GetDragDropManager(); 783 CHECK_NULL_VOID(dragDropManager); 784 dragDropManager->RemoveDragFrameNode(frameNode->GetId()); 785 } 786 787 void CreateHandles() override; 788 789 void CreateHandles(bool animation); 790 IsDragging()791 bool IsDragging() const 792 { 793 return dragStatus_ == DragStatus::DRAGGING; 794 } 795 IsTouchTestPointInArea(const Offset & touchOffset,bool isTouchPointHits)796 bool IsTouchTestPointInArea(const Offset& touchOffset, bool isTouchPointHits) override 797 { 798 return isTouchPointHits && BetweenSelectedPosition(touchOffset); 799 } 800 BetweenSelectedPosition(const Offset & globalOffset)801 bool BetweenSelectedPosition(const Offset& globalOffset) override 802 { 803 if (!IsSelected()) { 804 return false; 805 } 806 Offset offset = globalOffset - 807 Offset(IsTextArea() ? contentRect_.GetX() : textRect_.GetX(), 808 IsTextArea() ? textRect_.GetY() : contentRect_.GetY()) - 809 Offset(parentGlobalOffset_.GetX(), parentGlobalOffset_.GetY()); 810 for (const auto& textBoxes : textBoxes_) { 811 bool isInRange = LessOrEqual(textBoxes.rect_.GetLeft(), offset.GetX()) && 812 LessOrEqual(offset.GetX(), textBoxes.rect_.GetRight()) && 813 LessOrEqual(textBoxes.rect_.GetTop(), offset.GetY()) && 814 LessOrEqual(offset.GetY(), textBoxes.rect_.GetBottom()); 815 if (isInRange) { 816 return true; 817 } 818 } 819 return false; 820 } 821 822 bool RequestCustomKeyboard(); 823 bool CloseCustomKeyboard(); 824 825 // xts 826 std::string TextInputTypeToString() const; 827 std::string TextInputActionToString() const; 828 std::string GetPlaceholderFont() const; 829 RefPtr<TextFieldTheme> GetTheme() const; 830 std::string GetTextColor() const; 831 std::string GetCaretColor() const; 832 std::string GetPlaceholderColor() const; 833 std::string GetFontSize() const; 834 Ace::FontStyle GetItalicFontStyle() const; 835 FontWeight GetFontWeight() const; 836 std::string GetFontFamily() const; 837 TextAlign GetTextAlign() const; 838 std::string GetPlaceHolder() const; 839 uint32_t GetMaxLength() const; 840 uint32_t GetMaxLines() const; 841 std::string GetInputFilter() const; 842 std::string GetCopyOptionString() const; 843 std::string GetInputStyleString() const; 844 std::string GetErrorTextString() const; 845 std::string GetBarStateString() const; 846 bool GetErrorTextState() const; 847 std::string GetShowPasswordIconString() const; 848 int32_t GetNakedCharPosition() const; 849 void SetSelectionFlag(int32_t selectionStart, int32_t selectionEnd); 850 void HandleBlurEvent(); 851 void HandleFocusEvent(); 852 bool OnBackPressed(); 853 void CheckScrollable(); 854 void HandleClickEvent(GestureEvent& info); 855 856 void HandleSelectionUp(); 857 void HandleSelectionDown(); 858 void HandleSelectionLeft(); 859 void HandleSelectionLeftWord(); 860 void HandleSelectionLineBegin(); 861 void HandleSelectionHome(); 862 void HandleSelectionRight(); 863 void HandleSelectionRightWord(); 864 void HandleSelectionLineEnd(); 865 void HandleSelectionEnd(); 866 void HandleOnUndoAction(); 867 void HandleOnRedoAction(); 868 void HandleOnSelectAll(bool isKeyEvent, bool inlineStyle = false); 869 void HandleOnCopy(); 870 void HandleOnPaste(); 871 void HandleOnCut(); 872 void StripNextLine(std::wstring& data); 873 bool OnKeyEvent(const KeyEvent& event); GetKeyboard()874 TextInputType GetKeyboard() 875 { 876 return keyboard_; 877 } GetAction()878 TextInputAction GetAction() 879 { 880 return action_; 881 } 882 SetNeedToRequestKeyboardOnFocus(bool needToRequest)883 void SetNeedToRequestKeyboardOnFocus(bool needToRequest) 884 { 885 needToRequestKeyboardOnFocus_ = needToRequest; 886 } 887 static int32_t GetGraphemeClusterLength(const std::wstring& text, int32_t extend, bool checkPrev = false); 888 void SetUnitNode(const RefPtr<NG::UINode>& unitNode); 889 void SetShowError(); 890 GetUnitWidth()891 float GetUnitWidth() const 892 { 893 return unitWidth_; 894 } 895 GetUnderlineWidth()896 float GetUnderlineWidth() const 897 { 898 return static_cast<float>(underlineWidth_.Value()); 899 } 900 GetUnderlineColor()901 const Color& GetUnderlineColor() const 902 { 903 return underlineColor_; 904 } 905 906 float GetMarginBottom() const; 907 SetUnderlineColor(Color underlineColor)908 void SetUnderlineColor(Color underlineColor) 909 { 910 underlineColor_ = underlineColor; 911 } 912 SetUnderlineWidth(Dimension underlineWidth)913 void SetUnderlineWidth(Dimension underlineWidth) 914 { 915 underlineWidth_ = underlineWidth; 916 } 917 IsSelectAll()918 bool IsSelectAll() 919 { 920 return abs(textSelector_.GetStart() - textSelector_.GetEnd()) >= 921 static_cast<int32_t>(StringUtils::ToWstring(textEditingValue_.text).length()); 922 } 923 GetSelectMenuInfo()924 SelectMenuInfo GetSelectMenuInfo() const 925 { 926 return selectMenuInfo_; 927 } 928 UpdateSelectMenuInfo(bool hasData,bool isHideSelectionMenu)929 void UpdateSelectMenuInfo(bool hasData, bool isHideSelectionMenu) 930 { 931 selectMenuInfo_.showCopy = !GetEditingValue().text.empty() && AllowCopy() && IsSelected(); 932 selectMenuInfo_.showCut = selectMenuInfo_.showCopy && !GetEditingValue().text.empty() && IsSelected(); 933 selectMenuInfo_.showCopyAll = !GetEditingValue().text.empty() && !IsSelectAll(); 934 selectMenuInfo_.showPaste = hasData; 935 selectMenuInfo_.menuIsShow = (!GetEditingValue().text.empty() || hasData) && !isHideSelectionMenu; 936 } 937 938 bool IsSearchParentNode() const; 939 MarkRedrawOverlay()940 void MarkRedrawOverlay() 941 { 942 ++drawOverlayFlag_; 943 } 944 945 void StopEditing(); 946 MarkContentChange()947 void MarkContentChange() 948 { 949 contChange_ = true; 950 } 951 ResetContChange()952 void ResetContChange() 953 { 954 contChange_ = false; 955 } 956 GetContChange()957 bool GetContChange() 958 { 959 return contChange_; 960 } 961 std::string GetShowResultImageSrc() const; 962 std::string GetHideResultImageSrc() const; OnAttachToFrameNode()963 void OnAttachToFrameNode() override 964 { 965 caretUpdateType_ = CaretUpdateType::EVENT; 966 } 967 GetTextInputFlag()968 bool GetTextInputFlag() const 969 { 970 return isTextInput_; 971 } 972 SetSingleLineHeight(float height)973 void SetSingleLineHeight(float height) 974 { 975 inlineSingleLineHeight_ = height; 976 } 977 GetSingleLineHeight()978 float GetSingleLineHeight() const 979 { 980 return inlineSingleLineHeight_; 981 } 982 GetInlinePadding()983 float GetInlinePadding() const 984 { 985 return inlinePadding_; 986 } 987 GetScrollBarVisible()988 bool GetScrollBarVisible() const 989 { 990 return scrollBarVisible_; 991 } 992 GetPreviewWidth()993 float GetPreviewWidth() const 994 { 995 return inlineState_.frameRect.Width(); 996 } 997 ResetTouchAtLeftOffsetFlag()998 void ResetTouchAtLeftOffsetFlag() 999 { 1000 isTouchAtLeftOffset_ = true; 1001 } 1002 1003 bool IsNormalInlineState() const; 1004 void TextIsEmptyRect(RectF& rect); 1005 void TextAreaInputRectUpdate(RectF& rect); 1006 void UpdateRectByAlignment(RectF& rect); 1007 1008 void EditingValueFilterChange(); 1009 SetCustomKeyboard(const std::function<void ()> && keyboardBuilder)1010 void SetCustomKeyboard(const std::function<void()>&& keyboardBuilder) 1011 { 1012 if (customKeyboardBulder_ && isCustomKeyboardAttached_ && !keyboardBuilder) { 1013 CloseCustomKeyboard(); 1014 } 1015 customKeyboardBulder_ = keyboardBuilder; 1016 } 1017 1018 void DumpInfo() override; 1019 void OnColorConfigurationUpdate() override; 1020 ShowPasswordIconChange()1021 void ShowPasswordIconChange() 1022 { 1023 caretUpdateType_ = CaretUpdateType::VISIBLE_PASSWORD_ICON; 1024 } 1025 SetIsCustomFont(bool isCustomFont)1026 void SetIsCustomFont(bool isCustomFont) 1027 { 1028 isCustomFont_ = isCustomFont; 1029 } 1030 GetIsCustomFont()1031 bool GetIsCustomFont() 1032 { 1033 return isCustomFont_; 1034 } 1035 SetISCounterIdealHeight(bool IsIdealHeight)1036 void SetISCounterIdealHeight(bool IsIdealHeight) 1037 { 1038 isCounterIdealheight_ = IsIdealHeight; 1039 } 1040 GetIsCounterIdealHeight()1041 bool GetIsCounterIdealHeight() const 1042 { 1043 return isCounterIdealheight_; 1044 } 1045 1046 private: 1047 bool HasFocus() const; 1048 void HandleTouchEvent(const TouchEventInfo& info); 1049 void HandleTouchDown(const Offset& offset); 1050 void HandleTouchUp(); 1051 1052 void InitFocusEvent(); 1053 void InitTouchEvent(); 1054 void InitLongPressEvent(); 1055 void InitClickEvent(); 1056 #ifdef ENABLE_DRAG_FRAMEWORK 1057 void InitDragDropEvent(); 1058 void ClearDragDropEvent(); 1059 std::function<void(Offset)> GetThumbnailCallback(); 1060 #endif 1061 bool CaretPositionCloseToTouchPosition(); 1062 void CreateSingleHandle(bool animation = false, bool isMenuShow = true); 1063 int32_t UpdateCaretPositionOnHandleMove(const OffsetF& localOffset); 1064 bool HasStateStyle(UIState state) const; 1065 1066 void OnTextInputScroll(float offset); 1067 void OnTextAreaScroll(float offset); 1068 bool OnScrollCallback(float offset, int32_t source) override; 1069 void OnScrollEndCallback() override; 1070 void InitMouseEvent(); 1071 void HandleHoverEffect(MouseInfo& info, bool isHover); 1072 void OnHover(bool isHover); 1073 void HandleMouseEvent(MouseInfo& info); 1074 void HandleLongPress(GestureEvent& info); 1075 void UpdateCaretPositionWithClamp(const int32_t& pos); 1076 void UpdateSelectorByPosition(const int32_t& pos); 1077 // assert handles are inside the contentRect, reset them if not 1078 void CheckHandles(std::optional<RectF>& firstHandle, std::optional<RectF>& secondHandle, 1079 float firstHandleSize = 0.0f, float secondHandleSize = 0.0f); 1080 void ShowSelectOverlay(const std::optional<RectF>& firstHandle, const std::optional<RectF>& secondHandle, 1081 bool animation = false, bool isMenuShow = true); 1082 1083 void CursorMoveOnClick(const Offset& offset); 1084 void UpdateCaretInfoToController() const; 1085 1086 void ProcessOverlay(bool animation = false); 1087 void OnHandleMove(const RectF& handleRect, bool isFirstHandle); 1088 void OnHandleMoveDone(const RectF& handleRect, bool isFirstHandle); 1089 // when moving one handle causes shift of textRect, update x position of the other handle 1090 void UpdateOtherHandleOnMove(float dx, float dy); 1091 void SetHandlerOnMoveDone(); 1092 void OnDetachFromFrameNode(FrameNode* node) override; 1093 bool UpdateCaretByPressOrLongPress(); 1094 void UpdateTextSelectorByHandleMove(bool isMovingBase, int32_t position, OffsetF& offsetToParagraphBeginning); 1095 void UpdateCaretByRightClick(); 1096 1097 void AfterSelection(); 1098 1099 void FireEventHubOnChange(const std::string& text); 1100 void FireOnChangeIfNeeded(); 1101 1102 void UpdateSelection(int32_t both); 1103 void UpdateSelection(int32_t start, int32_t end); 1104 void FireOnSelectionChange(int32_t start, int32_t end); 1105 void UpdateDestinationToCaretByEvent(); 1106 void UpdateCaretPositionByLastTouchOffset(); 1107 bool UpdateCaretPositionByMouseMovement(); 1108 bool UpdateCaretPosition(); 1109 bool UpdateCaretRect(); 1110 bool CharLineChanged(int32_t caretPosition); 1111 1112 void ScheduleCursorTwinkling(); 1113 void OnCursorTwinkling(); 1114 void StartTwinkling(); 1115 void StopTwinkling(); 1116 void CheckIfNeedToResetKeyboard(); 1117 1118 float PreferredTextHeight(bool isPlaceholder); 1119 1120 void SetCaretOffsetForEmptyTextOrPositionZero(); 1121 void UpdateTextFieldManager(const Offset& offset, float height); 1122 void OnTextInputActionUpdate(TextInputAction value); 1123 1124 void Delete(int32_t start, int32_t end); 1125 bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override; 1126 void BeforeCreateLayoutWrapper() override; 1127 bool LastTouchIsInSelectRegion(const std::vector<RSTypographyProperties::TextBox>& boxes); 1128 1129 bool FilterWithRegex( 1130 const std::string& filter, const std::string& valueToUpdate, std::string& result, bool needToEscape = false); 1131 bool FilterWithAscii(const std::string& valueToUpdate, std::string& result); 1132 bool FilterWithEmail(std::string& result); 1133 void EditingValueFilter(std::string& valueToUpdate, std::string& result, bool isInsertValue = false); 1134 void GetTextRectsInRange(int32_t begin, int32_t end, std::vector<RSTypographyProperties::TextBox>& textBoxes); 1135 bool CursorInContentRegion(); 1136 float FitCursorInSafeArea(); 1137 bool OffsetInContentRegion(const Offset& offset); 1138 void SetDisabledStyle(); 1139 1140 void ProcessPasswordIcon(); 1141 void UpdateUserDefineResource(ImageSourceInfo& sourceInfo); 1142 void UpdateInternalResource(ImageSourceInfo& sourceInfo); 1143 ImageSourceInfo GetImageSourceInfoFromTheme(bool checkHidePasswordIcon); 1144 LoadSuccessNotifyTask CreateLoadSuccessCallback(bool checkHidePasswordIcon); 1145 DataReadyNotifyTask CreateDataReadyCallback(bool checkHidePasswordIcon); 1146 LoadFailNotifyTask CreateLoadFailCallback(bool checkHidePasswordIcon); 1147 void OnImageDataReady(bool checkHidePasswordIcon); 1148 void OnImageLoadSuccess(bool checkHidePasswordIcon); 1149 void OnImageLoadFail(bool checkHidePasswordIcon); 1150 void CalculateDefaultCursor(); 1151 void RequestKeyboardOnFocus(); 1152 void SetNeedToRequestKeyboardOnFocus(); 1153 void SaveUnderlineStates(); 1154 void ApplyUnderlineStates(); 1155 void SavePasswordModeStates(); 1156 void SetAccessibilityAction(); 1157 void SetAccessibilityMoveTextAction(); 1158 void SetAccessibilityScrollAction(); 1159 1160 void UpdateCopyAllStatus(); 1161 void SaveInlineStates(); 1162 void ApplyInlineStates(bool focusStatus); 1163 void RestorePreInlineStates(); 1164 bool CheckHandleVisible(const RectF& paintRect); 1165 void SetTextRectOffset(); 1166 1167 bool ResetObscureTickCountDown(); 1168 bool IsInPasswordMode() const; 1169 void GetWordBoundaryPositon(int32_t offset, int32_t& start, int32_t& end); 1170 bool IsTouchAtLeftOffset(float currentOffsetX); 1171 void FilterExistText(); 1172 void UpdateErrorTextMargin(); 1173 #if defined(ENABLE_STANDARD_INPUT) 1174 std::optional<MiscServices::TextConfig> GetMiscTextConfig() const; 1175 #endif 1176 1177 RectF frameRect_; 1178 RectF contentRect_; 1179 RectF textRect_; 1180 RectF imageRect_; 1181 std::shared_ptr<RSParagraph> paragraph_; 1182 std::shared_ptr<RSParagraph> counterParagraph_; 1183 std::shared_ptr<RSParagraph> errorParagraph_; 1184 std::shared_ptr<RSParagraph> dragParagraph_; 1185 std::shared_ptr<RSParagraph> textLineHeightUtilParagraph_; 1186 std::shared_ptr<RSParagraph> placeholderLineHeightUtilParagraph_; 1187 TextStyle nextLineUtilTextStyle_; 1188 std::shared_ptr<RSParagraph> nextLineUtilParagraph_; 1189 1190 RefPtr<ImageLoadingContext> showPasswordImageLoadingCtx_; 1191 RefPtr<ImageLoadingContext> hidePasswordImageLoadingCtx_; 1192 1193 // password icon image related 1194 RefPtr<CanvasImage> showPasswordCanvasImage_; 1195 RefPtr<CanvasImage> hidePasswordCanvasImage_; 1196 1197 RefPtr<ClickEvent> clickListener_; 1198 RefPtr<TouchEventImpl> touchListener_; 1199 RefPtr<ScrollableEvent> scrollableEvent_; 1200 RefPtr<InputEvent> mouseEvent_; 1201 RefPtr<InputEvent> hoverEvent_; 1202 RefPtr<LongPressEvent> longPressEvent_; 1203 CursorPositionType cursorPositionType_ = CursorPositionType::NORMAL; 1204 1205 // What the keyboard should appears. 1206 TextInputType keyboard_ = TextInputType::UNSPECIFIED; 1207 // Action when "enter" pressed. 1208 TextInputAction action_ = TextInputAction::UNSPECIFIED; 1209 TextDirection textDirection_ = TextDirection::LTR; 1210 1211 OffsetF parentGlobalOffset_; 1212 Offset lastTouchOffset_; 1213 PaddingPropertyF utilPadding_; 1214 OffsetF rightClickOffset_; 1215 OffsetF offsetDifference_; 1216 1217 BorderWidthProperty lastBorderWidth_; 1218 1219 bool setBorderFlag_ = true; 1220 BorderWidthProperty lastDiffBorderWidth_; 1221 BorderColorProperty lastDiffBorderColor_; 1222 1223 bool showUserDefinedIcon_ = false; 1224 bool hideUserDefinedIcon_ = false; 1225 std::string showUserDefinedIconSrc_; 1226 std::string hideUserDefinedIconSrc_; 1227 bool isSingleHandle_ = false; 1228 bool isFirstHandle_ = false; 1229 float baselineOffset_ = 0.0f; 1230 // relative to frameRect 1231 RectF caretRect_; 1232 bool cursorVisible_ = false; 1233 bool focusEventInitialized_ = false; 1234 bool isMousePressed_ = false; 1235 bool needCloseOverlay_ = true; 1236 bool textObscured_ = true; 1237 bool enableTouchAndHoverEffect_ = true; 1238 bool isUsingMouse_ = false; 1239 bool isOnHover_ = false; 1240 bool needToRefreshSelectOverlay_ = false; 1241 bool needToRequestKeyboardInner_ = false; 1242 bool needToRequestKeyboardOnFocus_ = false; 1243 bool isTransparent_ = false; 1244 bool contChange_ = false; 1245 std::optional<int32_t> surfaceChangedCallbackId_; 1246 std::optional<int32_t> surfacePositionChangedCallbackId_; 1247 float paragraphWidth_ = 0.0f; 1248 1249 SelectionMode selectionMode_ = SelectionMode::NONE; 1250 CaretUpdateType caretUpdateType_ = CaretUpdateType::NONE; 1251 bool scrollable_ = true; 1252 // controls redraw of overlay modifier, update when need to redraw 1253 int32_t drawOverlayFlag_ = 0; 1254 bool isTextInput_ = false; 1255 bool inlineSelectAllFlag_ = false; 1256 bool inlineFocusState_ = false; 1257 bool blockPress_ = false; 1258 float inlineSingleLineHeight_ = 0.0f; 1259 float inlinePadding_ = 0.0f; 1260 float previewWidth_ = 0.0f; 1261 float lastTextRectY_ = 0.0f; 1262 std::optional<DisplayMode> barState_; 1263 InputStyle preInputStyle_ = InputStyle::DEFAULT; 1264 bool preErrorState_ = false; 1265 float preErrorMargin_ = 0.0f; 1266 bool restoreMarginState_ = false; 1267 1268 uint32_t twinklingInterval_ = 0; 1269 int32_t obscureTickCountDown_ = 0; 1270 int32_t nakedCharPosition_ = -1; 1271 bool updateSelectionAfterObscure_ = false; 1272 float currentOffset_ = 0.0f; 1273 float unitWidth_ = 0.0f; 1274 float countHeight_ = 0.0f; 1275 Dimension underlineWidth_ = UNDERLINE_WIDTH; 1276 Color underlineColor_; 1277 bool scrollBarVisible_ = false; 1278 bool isCounterIdealheight_ = false; 1279 1280 CancelableCallback<void()> cursorTwinklingTask_; 1281 1282 std::list<std::unique_ptr<TextInputFormatter>> textInputFormatters_; 1283 1284 RefPtr<TextFieldController> textFieldController_; 1285 RefPtr<TextEditController> textEditingController_; 1286 TextEditingValueNG textEditingValue_; 1287 RefPtr<SelectOverlayProxy> selectOverlayProxy_; 1288 std::vector<RSTypographyProperties::TextBox> textBoxes_; 1289 RefPtr<TextFieldOverlayModifier> textFieldOverlayModifier_; 1290 RefPtr<TextFieldContentModifier> textFieldContentModifier_; 1291 ACE_DISALLOW_COPY_AND_MOVE(TextFieldPattern); 1292 1293 int32_t dragTextStart_ = 0; 1294 int32_t dragTextEnd_ = 0; 1295 RefPtr<FrameNode> dragNode_; 1296 DragStatus dragStatus_ = DragStatus::NONE; // The status of the dragged initiator 1297 DragStatus dragRecipientStatus_ = DragStatus::NONE; // Drag the recipient's state 1298 std::vector<std::string> dragContents_; 1299 RefPtr<Clipboard> clipboard_; 1300 std::vector<TextEditingValueNG> operationRecords_; 1301 std::vector<TextEditingValueNG> redoOperationRecords_; 1302 std::vector<TextSelector> textSelectorRecords_; 1303 std::vector<TextSelector> redoTextSelectorRecords_; 1304 std::vector<MenuOptionsParam> menuOptionItems_; 1305 BorderRadiusProperty borderRadius_; 1306 PasswordModeStyle passwordModeStyle_; 1307 PreInlineState inlineState_; 1308 1309 SelectMenuInfo selectMenuInfo_; 1310 1311 #if defined(ENABLE_STANDARD_INPUT) 1312 sptr<OHOS::MiscServices::OnTextChangedListener> textChangeListener_; 1313 #else 1314 RefPtr<TextInputConnection> connection_; 1315 #endif 1316 #if defined(OHOS_STANDARD_SYSTEM) && !defined(PREVIEW) 1317 bool imeAttached_ = false; 1318 bool imeShown_ = false; 1319 #endif 1320 int32_t instanceId_ = -1; 1321 bool isFocusedBeforeClick_ = false; 1322 bool originalIsMenuShow_ = false; 1323 bool isCustomKeyboardAttached_ = false; 1324 std::function<void()> customKeyboardBulder_; 1325 bool isTouchAtLeftOffset_ = true; 1326 bool isCustomFont_ = false; 1327 }; 1328 } // namespace OHOS::Ace::NG 1329 1330 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_FIELD_TEXT_FIELD_PATTERN_H 1331