1 /* 2 * Copyright (c) 2022-2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_FIELD_TEXT_FIELD_PATTERN_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_FIELD_TEXT_FIELD_PATTERN_H 18 19 #include <cstdint> 20 #include <optional> 21 #include <queue> 22 #include <string> 23 #include <utility> 24 #include <vector> 25 26 #include "base/geometry/ng/offset_t.h" 27 #include "base/geometry/ng/rect_t.h" 28 #include "base/geometry/rect.h" 29 #include "base/memory/referenced.h" 30 #include "base/mousestyle/mouse_style.h" 31 #include "base/utils/utf_helper.h" 32 #include "base/view_data/view_data_wrap.h" 33 #include "core/common/ai/ai_write_adapter.h" 34 #include "base/view_data/hint_to_type_wrap.h" 35 #include "core/common/clipboard/clipboard.h" 36 #include "core/common/ime/text_edit_controller.h" 37 #include "core/common/ime/text_input_action.h" 38 #include "core/common/ime/text_input_client.h" 39 #include "core/common/ime/text_input_configuration.h" 40 #include "core/common/ime/text_input_connection.h" 41 #include "core/common/ime/text_input_formatter.h" 42 #include "core/common/ime/text_input_proxy.h" 43 #include "core/common/ime/text_input_type.h" 44 #include "core/common/ime/text_selection.h" 45 #include "core/components/text_field/textfield_theme.h" 46 #include "core/components_ng/image_provider/image_loading_context.h" 47 #include "core/components_ng/pattern/overlay/keyboard_base_pattern.h" 48 #include "core/components_ng/pattern/scrollable/scrollable_pattern.h" 49 #include "core/components_ng/pattern/text/layout_info_interface.h" 50 #include "core/components_ng/pattern/select_overlay/magnifier.h" 51 #include "core/components_ng/pattern/text/multiple_click_recognizer.h" 52 #include "core/components_ng/pattern/text/text_base.h" 53 #include "core/components_ng/pattern/text/text_menu_extension.h" 54 #include "core/components_ng/pattern/text_area/text_area_layout_algorithm.h" 55 #include "core/components_ng/pattern/text_drag/text_drag_base.h" 56 #include "core/components_ng/pattern/text_field/content_controller.h" 57 #include "core/components_ng/pattern/text_field/text_component_decorator.h" 58 #include "core/components_ng/pattern/text_field/text_editing_value_ng.h" 59 #include "core/components_ng/pattern/text_field/text_content_type.h" 60 #include "core/components_ng/pattern/text_field/text_field_accessibility_property.h" 61 #include "core/components_ng/pattern/text_field/text_field_controller.h" 62 #include "core/components_ng/pattern/text_field/text_field_event_hub.h" 63 #include "core/components_ng/pattern/text_field/text_field_layout_property.h" 64 #include "core/components_ng/pattern/text_field/text_field_manager.h" 65 #include "core/components_ng/pattern/text_field/text_field_paint_method.h" 66 #include "core/components_ng/pattern/text_field/text_field_paint_property.h" 67 #include "core/components_ng/pattern/text_field/text_field_select_overlay.h" 68 #include "core/components_ng/pattern/text_field/text_input_response_area.h" 69 #include "core/components_ng/pattern/text_field/text_select_controller.h" 70 #include "core/components_ng/pattern/text_field/text_selector.h" 71 #include "core/components_ng/pattern/text_input/text_input_layout_algorithm.h" 72 73 #ifndef ACE_UNITTEST 74 #ifdef ENABLE_STANDARD_INPUT 75 #include "refbase.h" 76 77 namespace OHOS::MiscServices { 78 class InspectorFilter; 79 class OnTextChangedListener; 80 81 struct TextConfig; 82 } // namespace OHOS::MiscServices 83 #endif 84 #endif 85 86 namespace OHOS::Ace::NG { 87 88 enum class FocuseIndex { TEXT = 0, CANCEL, UNIT }; 89 90 enum class SelectionMode { SELECT, SELECT_ALL, NONE }; 91 92 enum class DragStatus { DRAGGING, ON_DROP, NONE }; 93 94 enum class CaretStatus { SHOW, HIDE, NONE }; 95 96 enum class InputOperation { 97 INSERT, 98 DELETE_BACKWARD, 99 DELETE_FORWARD, 100 CURSOR_UP, 101 CURSOR_DOWN, 102 CURSOR_LEFT, 103 CURSOR_RIGHT, 104 SET_PREVIEW_TEXT, 105 SET_PREVIEW_FINISH, 106 INPUT, 107 }; 108 109 struct PasswordModeStyle { 110 Color bgColor; 111 Color textColor; 112 BorderWidthProperty borderwidth; 113 BorderColorProperty borderColor; 114 BorderRadiusProperty radius; 115 PaddingProperty padding; 116 MarginProperty margin; 117 }; 118 119 struct PreState { 120 Color textColor; 121 Color bgColor; 122 BorderRadiusProperty radius; 123 BorderWidthProperty borderWidth; 124 BorderColorProperty borderColor; 125 PaddingProperty padding; 126 MarginProperty margin; 127 RectF frameRect; 128 bool setHeight = false; 129 bool saveState = false; 130 bool hasBorderColor = false; 131 }; 132 133 enum class RequestKeyboardReason { 134 UNKNOWN = 0, 135 ON_KEY_EVENT, 136 SINGLE_CLICK, 137 DOUBLE_CLICK, 138 LONG_PRESS, 139 RESET_KEYBOARD, 140 MOUSE_RELEASE, 141 SET_SELECTION, 142 SEARCH_REQUEST, 143 AUTO_FILL_REQUEST_FAIL, 144 SHOW_KEYBOARD_ON_FOCUS, 145 STYLUS_DETECTOR, 146 CUSTOM_KEYBOARD 147 }; 148 149 enum class RequestFocusReason { 150 UNKNOWN = 0, 151 DRAG_END, 152 DRAG_MOVE, 153 CLICK, 154 LONG_PRESS, 155 AUTO_FILL, 156 CLEAN_NODE, 157 MOUSE, 158 SYSTEM, 159 DRAG_ENTER, 160 DRAG_SELECT 161 }; 162 163 164 // reason for needToRequestKeyboardInner_ change 165 enum class RequestKeyboardInnerChangeReason { 166 UNKNOWN = 0, 167 BLUR, 168 FOCUS, 169 AUTOFILL_PROCESS, 170 REQUEST_KEYBOARD_SUCCESS, 171 SEARCH_FOCUS 172 }; 173 174 enum class InputReason { 175 NONE = 0, 176 IME, 177 PASTE, 178 CUT, 179 DRAG, 180 AUTO_FILL, 181 AI_WRITE, 182 CANCEL_BUTTON 183 }; 184 185 struct PreviewTextInfo { 186 std::u16string text; 187 PreviewRange range; 188 bool isIme; 189 }; 190 191 struct InsertCommandInfo { 192 std::u16string insertValue; 193 InputReason reason; 194 }; 195 196 struct InputCommandInfo { 197 PreviewRange deleteRange; 198 int32_t insertOffset; 199 std::u16string insertValue; 200 InputReason reason; 201 }; 202 203 struct TouchAndMoveCaretState { 204 bool isTouchCaret = false; 205 bool isMoveCaret = false; 206 Offset touchDownOffset; 207 Dimension minDinstance = 5.0_vp; 208 int32_t touchFingerId = -1; 209 }; 210 211 struct FloatingCaretState { 212 bool FloatingCursorVisible = false; 213 bool ShowOriginCursor = false; 214 Color OriginCursorColor = Color(0x4D000000); 215 std::optional<float> lastFloatingCursorY = std::nullopt; 216 ResetFloatingCaretState217 void Reset() 218 { 219 FloatingCursorVisible = false; 220 ShowOriginCursor = false; 221 lastFloatingCursorY = std::nullopt; 222 } 223 }; 224 225 struct ContentScroller { 226 CancelableCallback<void()> autoScrollTask; 227 std::function<void(const Offset&)> scrollingCallback; 228 std::function<void(const Offset&)> beforeScrollingCallback; 229 bool isScrolling = false; 230 float scrollInterval = 15; 231 float stepOffset = 0.0f; 232 Offset localOffset; 233 std::optional<Offset> hotAreaOffset; 234 float updateMagniferEpsilon = 0.5f; 235 OnBeforeScrollingCallbackContentScroller236 void OnBeforeScrollingCallback(const Offset& localOffset) 237 { 238 if (beforeScrollingCallback && !isScrolling) { 239 beforeScrollingCallback(localOffset); 240 } 241 } 242 }; 243 244 class TextFieldPattern : public ScrollablePattern, 245 public TextDragBase, 246 public ValueChangeObserver, 247 public TextInputClient, 248 public TextBase, 249 public Magnifier, 250 public TextGestureSelector, 251 public LayoutInfoInterface { 252 DECLARE_ACE_TYPE(TextFieldPattern, ScrollablePattern, TextDragBase, ValueChangeObserver, TextInputClient, TextBase, 253 Magnifier, TextGestureSelector); 254 255 public: 256 TextFieldPattern(); 257 ~TextFieldPattern() override; 258 GetInstanceId()259 int32_t GetInstanceId() const override 260 { 261 return GetHostInstanceId(); 262 } 263 264 // TextField needs softkeyboard, override function. NeedSoftKeyboard()265 bool NeedSoftKeyboard() const override 266 { 267 return true; 268 } 269 SetBlurOnSubmit(bool blurOnSubmit)270 void SetBlurOnSubmit(bool blurOnSubmit) 271 { 272 textInputBlurOnSubmit_ = blurOnSubmit; 273 textAreaBlurOnSubmit_ = blurOnSubmit; 274 } 275 GetBlurOnSubmit()276 bool GetBlurOnSubmit() 277 { 278 return IsTextArea() ? textAreaBlurOnSubmit_ : textInputBlurOnSubmit_; 279 } 280 SetKeyboardAppearance(KeyboardAppearance value)281 void SetKeyboardAppearance(KeyboardAppearance value) 282 { 283 keyboardAppearance_ = value; 284 } 285 GetKeyboardAppearance()286 KeyboardAppearance GetKeyboardAppearance() const 287 { 288 return keyboardAppearance_; 289 } 290 NeedToRequestKeyboardOnFocus()291 bool NeedToRequestKeyboardOnFocus() const override 292 { 293 return needToRequestKeyboardOnFocus_; 294 } 295 296 bool CheckBlurReason(); 297 298 RefPtr<NodePaintMethod> CreateNodePaintMethod() override; 299 CreateLayoutProperty()300 RefPtr<LayoutProperty> CreateLayoutProperty() override 301 { 302 return MakeRefPtr<TextFieldLayoutProperty>(); 303 } 304 CreateEventHub()305 RefPtr<EventHub> CreateEventHub() override 306 { 307 return MakeRefPtr<TextFieldEventHub>(); 308 } 309 CreatePaintProperty()310 RefPtr<PaintProperty> CreatePaintProperty() override 311 { 312 return MakeRefPtr<TextFieldPaintProperty>(); 313 } 314 CreateAccessibilityProperty()315 RefPtr<AccessibilityProperty> CreateAccessibilityProperty() override 316 { 317 return MakeRefPtr<TextFieldAccessibilityProperty>(); 318 } 319 CreateLayoutAlgorithm()320 RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override 321 { 322 if (IsTextArea()) { 323 return MakeRefPtr<TextAreaLayoutAlgorithm>(); 324 } 325 return MakeRefPtr<TextInputLayoutAlgorithm>(); 326 } 327 328 void OnModifyDone() override; 329 void ProcessUnderlineColorOnModifierDone(); 330 void UpdateSelectionOffset(); 331 void CalcCaretMetricsByPosition( 332 int32_t extent, CaretMetricsF& caretCaretMetric, TextAffinity textAffinity = TextAffinity::DOWNSTREAM); 333 int32_t ConvertTouchOffsetToCaretPosition(const Offset& localOffset); 334 int32_t ConvertTouchOffsetToCaretPositionNG(const Offset& localOffset); 335 336 // Obtain the systemWindowsId when switching between windows 337 uint32_t GetSCBSystemWindowId(); 338 339 void InsertValue(const std::u16string& insertValue, bool isIME = false) override; 340 void InsertValue(const std::string& insertValue, bool isIME = false) override; 341 void NotifyImfFinishTextPreview(); 342 int32_t InsertValueByController(const std::u16string& insertValue, int32_t offset); 343 void ExecuteInsertValueCommand(const InsertCommandInfo& info); 344 void CalcCounterAfterFilterInsertValue(int32_t curLength, const std::u16string insertValue, int32_t maxLength); 345 void UpdateObscure(const std::u16string& insertValue, bool hasInsertValue); 346 void CleanCounterNode(); 347 void CleanErrorNode(); 348 float CalcDecoratorWidth(const RefPtr<FrameNode>& decoratorNode); 349 float CalcDecoratorHeight(const RefPtr<FrameNode>& decoratorNode); 350 void UltralimitShake(); 351 void UpdateAreaBorderStyle(BorderWidthProperty& currentBorderWidth, BorderWidthProperty& overCountBorderWidth, 352 BorderColorProperty& overCountBorderColor, BorderColorProperty& currentBorderColor); 353 void DeleteBackward(int32_t length) override; 354 void DeleteBackwardOperation(int32_t length); 355 void DeleteForward(int32_t length) override; 356 void DeleteForwardOperation(int32_t length); 357 void HandleOnDelete(bool backward) override; 358 bool HandleOnDeleteComb(bool backward) override; 359 void DeleteBackwardWord(); 360 void DeleteForwardWord(); 361 void HandleOnPageUp() override; 362 void HandleOnPageDown() override; 363 void CreateHandles() override; 364 void GetEmojiSubStringRange(int32_t& start, int32_t& end); 365 366 int32_t SetPreviewText(const std::u16string& previewValue, const PreviewRange range) override; 367 int32_t SetPreviewText(const std::string& previewValue, const PreviewRange range) override; 368 void FinishTextPreview() override; 369 void SetPreviewTextOperation(PreviewTextInfo info); 370 void FinishTextPreviewOperation(); 371 TextDragInfo CreateTextDragInfo() const; 372 GetCounterDecorator()373 RefPtr<TextComponentDecorator> GetCounterDecorator() const 374 { 375 return counterDecorator_; 376 } 377 GetErrorDecorator()378 RefPtr<TextComponentDecorator> GetErrorDecorator() const 379 { 380 return errorDecorator_; 381 } 382 GetShowCounterStyleValue()383 bool GetShowCounterStyleValue() const 384 { 385 return showCountBorderStyle_; 386 } 387 SetCounterState(bool counterChange)388 void SetCounterState(bool counterChange) 389 { 390 counterChange_ = counterChange; 391 } 392 393 float GetTextOrPlaceHolderFontSize(); 394 SetTextFieldController(const RefPtr<TextFieldController> & controller)395 void SetTextFieldController(const RefPtr<TextFieldController>& controller) 396 { 397 textFieldController_ = controller; 398 } 399 GetTextFieldController()400 const RefPtr<TextFieldController>& GetTextFieldController() 401 { 402 return textFieldController_; 403 } 404 SetJSTextEditableController(const RefPtr<Referenced> & jsController)405 void SetJSTextEditableController(const RefPtr<Referenced>& jsController) 406 { 407 jsTextEditableController_ = jsController; 408 } 409 GetJSTextEditableController()410 RefPtr<Referenced> GetJSTextEditableController() 411 { 412 return jsTextEditableController_.Upgrade(); 413 } 414 SetTextEditController(const RefPtr<TextEditController> & textEditController)415 void SetTextEditController(const RefPtr<TextEditController>& textEditController) 416 { 417 textEditingController_ = textEditController; 418 } 419 GetTextValue()420 std::string GetTextValue() const 421 { 422 return contentController_->GetTextValue(); 423 } 424 GetTextUtf16Value()425 const std::u16string& GetTextUtf16Value() const 426 { 427 return contentController_->GetTextUtf16Value(); 428 } 429 430 #if defined(IOS_PLATFORM) GetInputEditingValue()431 const TextEditingValue& GetInputEditingValue() const override 432 { 433 static TextEditingValue value; 434 value.text = contentController_->GetTextValue(); 435 value.hint = UtfUtils::Str16DebugToStr8(GetPlaceHolder()); 436 value.selection.Update(selectController_->GetStartIndex(), selectController_->GetEndIndex()); 437 return value; 438 }; 439 Offset GetGlobalOffset() const; 440 double GetEditingBoxY() const override; 441 double GetEditingBoxTopY() const override; 442 bool GetEditingBoxModel() const override; 443 #endif 444 ShouldDelayChildPressedState()445 bool ShouldDelayChildPressedState() const override 446 { 447 return false; 448 } 449 UpdateEditingValue(const std::string & value,int32_t caretPosition)450 void UpdateEditingValue(const std::string& value, int32_t caretPosition) 451 { 452 contentController_->SetTextValue(UtfUtils::Str8DebugToStr16(value)); 453 selectController_->UpdateCaretIndex(caretPosition); 454 } 455 void UpdateCaretPositionByTouch(const Offset& offset); 456 bool IsReachedBoundary(float offset); 457 458 virtual int32_t GetRequestKeyboardId(); 459 460 virtual TextInputAction GetDefaultTextInputAction() const; 461 bool RequestKeyboardCrossPlatForm(bool isFocusViewChanged); 462 bool RequestKeyboard(bool isFocusViewChanged, bool needStartTwinkling, bool needShowSoftKeyboard, 463 SourceType sourceType = SourceType::NONE); 464 bool CloseKeyboard(bool forceClose) override; 465 bool CloseKeyboard(bool forceClose, bool isStopTwinkling); 466 467 FocusPattern GetFocusPattern() const override; 468 void PerformAction(TextInputAction action, bool forceCloseKeyboard = false) override; 469 void UpdateEditingValue(const std::shared_ptr<TextEditingValue>& value, bool needFireChangeEvent = true) override; 470 void UpdateInputFilterErrorText(const std::u16string& errorText) override; 471 void UpdateInputFilterErrorText(const std::string& errorText) override; 472 473 void OnValueChanged(bool needFireChangeEvent = true, bool needFireSelectChangeEvent = true) override; 474 475 void OnHandleAreaChanged() override; 476 void OnVisibleChange(bool isVisible) override; 477 void HandleCounterBorder(); 478 GetCaretIndex()479 int32_t GetCaretIndex() const override 480 { 481 return selectController_->GetCaretIndex(); 482 } 483 GetFirstHandleOffset()484 OffsetF GetFirstHandleOffset() const override 485 { 486 return selectController_->GetFirstHandleOffset(); 487 } 488 GetSecondHandleOffset()489 OffsetF GetSecondHandleOffset() const override 490 { 491 return selectController_->GetSecondHandleOffset(); 492 } 493 ACE_DEFINE_PROPERTY_ITEM_FUNC_WITHOUT_GROUP(TextInputAction,TextInputAction)494 ACE_DEFINE_PROPERTY_ITEM_FUNC_WITHOUT_GROUP(TextInputAction, TextInputAction) 495 496 const RefPtr<Paragraph>& GetParagraph() const 497 { 498 return paragraph_; 499 } 500 GetCursorVisible()501 bool GetCursorVisible() const 502 { 503 return cursorVisible_; 504 } 505 GetFloatingCursorVisible()506 bool GetFloatingCursorVisible() const 507 { 508 return floatCaretState_.FloatingCursorVisible; 509 } 510 SetFloatingCursorVisible(bool floatingCursorVisible)511 void SetFloatingCursorVisible(bool floatingCursorVisible) 512 { 513 floatCaretState_.FloatingCursorVisible = floatingCursorVisible; 514 } 515 ResetFloatingCursorState()516 void ResetFloatingCursorState() 517 { 518 floatCaretState_.Reset(); 519 } 520 521 void SetMagnifierLocalOffsetToFloatingCaretPos(); 522 GetShowOriginCursor()523 bool GetShowOriginCursor() const 524 { 525 return floatCaretState_.ShowOriginCursor; 526 } 527 SetShowOriginCursor(bool showOriginCursor)528 void SetShowOriginCursor(bool showOriginCursor) 529 { 530 floatCaretState_.ShowOriginCursor = showOriginCursor; 531 } 532 GetOriginCursorColor()533 Color GetOriginCursorColor() const 534 { 535 return floatCaretState_.OriginCursorColor; 536 } 537 SetOriginCursorColor(Color originCursorColor)538 void SetOriginCursorColor(Color originCursorColor) 539 { 540 floatCaretState_.OriginCursorColor = originCursorColor; 541 } 542 543 virtual void AdjustFloatingCaretInfo(const Offset& localOffset, 544 const HandleInfoNG& caretInfo, HandleInfoNG& floatingCaretInfo); 545 546 void FloatingCaretLand(); 547 548 #if defined(OHOS_STANDARD_SYSTEM) && !defined(PREVIEW) GetImeAttached()549 bool GetImeAttached() const 550 { 551 return imeAttached_; 552 } 553 #endif 554 GetLastTouchOffset()555 const OffsetF& GetLastTouchOffset() 556 { 557 return lastTouchOffset_; 558 } 559 GetCaretOffset()560 OffsetF GetCaretOffset() const override 561 { 562 return movingCaretOffset_; 563 } 564 SetMovingCaretOffset(const OffsetF & offset)565 void SetMovingCaretOffset(const OffsetF& offset) 566 { 567 movingCaretOffset_ = offset; 568 } 569 GetCaretUpdateType()570 CaretUpdateType GetCaretUpdateType() const 571 { 572 return caretUpdateType_; 573 } 574 SetCaretUpdateType(CaretUpdateType type)575 void SetCaretUpdateType(CaretUpdateType type) 576 { 577 caretUpdateType_ = type; 578 } 579 580 float GetPaddingTop() const; 581 float GetPaddingBottom() const; 582 float GetPaddingLeft() const; 583 float GetPaddingRight() const; 584 585 float GetHorizontalPaddingAndBorderSum() const; 586 587 float GetVerticalPaddingAndBorderSum() const; 588 589 double GetPercentReferenceWidth() const; 590 591 BorderWidthProperty GetBorderWidthProperty() const; 592 float GetBorderLeft(BorderWidthProperty border) const; 593 float GetBorderTop(BorderWidthProperty border) const; 594 float GetBorderBottom(BorderWidthProperty border) const; 595 float GetBorderRight(BorderWidthProperty border) const; 596 GetTextRect()597 const RectF& GetTextRect() override 598 { 599 return textRect_; 600 } 601 SetTextRect(const RectF & textRect)602 void SetTextRect(const RectF& textRect) 603 { 604 textRect_ = textRect; 605 } 606 GetTextParagraphIndent()607 float GetTextParagraphIndent() const 608 { 609 return textParagraphIndent_; 610 } 611 GetFrameRect()612 const RectF& GetFrameRect() const 613 { 614 return frameRect_; 615 } 616 GetCountHeight()617 float GetCountHeight() const 618 { 619 return countHeight_; 620 } 621 GetTextSelectController()622 const RefPtr<TextSelectController>& GetTextSelectController() 623 { 624 return selectController_; 625 } 626 GetTextContentController()627 const RefPtr<ContentController>& GetTextContentController() 628 { 629 return contentController_; 630 } 631 SetInSelectMode(SelectionMode selectionMode)632 void SetInSelectMode(SelectionMode selectionMode) 633 { 634 selectionMode_ = selectionMode; 635 } 636 GetSelectMode()637 SelectionMode GetSelectMode() const 638 { 639 return selectionMode_; 640 } 641 IsSelected()642 bool IsSelected() const override 643 { 644 return selectController_->IsSelected(); 645 } 646 IsUsingMouse()647 bool IsUsingMouse() const 648 { 649 return selectOverlay_->IsUsingMouse(); 650 } 651 int32_t GetWordLength(int32_t originCaretPosition, int32_t directionalMove, bool skipNewLineChar = true); 652 int32_t GetLineBeginPosition(int32_t originCaretPosition, bool needToCheckLineChanged = true); 653 int32_t GetLineEndPosition(int32_t originCaretPosition, bool needToCheckLineChanged = true); HasText()654 bool HasText() const 655 { 656 return !contentController_->IsEmpty(); 657 } 658 659 void CursorMove(CaretMoveIntent direction) override; 660 bool CursorMoveLeft(); 661 bool CursorMoveLeftOperation(); 662 bool CursorMoveLeftWord(); 663 bool CursorMoveLineBegin(); 664 bool CursorMoveToParagraphBegin(); 665 bool CursorMoveHome(); 666 bool CursorMoveRight(); 667 bool CursorMoveRightOperation(); 668 bool CursorMoveRightWord(); 669 bool CursorMoveLineEnd(); 670 bool CursorMoveToParagraphEnd(); 671 bool CursorMoveEnd(); 672 bool CursorMoveUp(); 673 bool CursorMoveDown(); 674 bool CursorMoveUpOperation(); 675 bool CursorMoveDownOperation(); 676 void SetCaretPosition(int32_t position, bool moveContent = true); 677 void HandleSetSelection(int32_t start, int32_t end, bool showHandle = true) override; 678 void HandleExtendAction(int32_t action) override; 679 void HandleSelect(CaretMoveIntent direction) override; 680 OffsetF GetDragUpperLeftCoordinates() override; 681 GetTextBoxes()682 std::vector<RectF> GetTextBoxes() override 683 { 684 return selectController_->GetSelectedRects(); 685 } 686 std::vector<RectF> GetTextBoxesForSelect(); 687 void AdjustSelectedBlankLineWidth(RectF& rect); 688 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override; 689 void ToTreeJson(std::unique_ptr<JsonValue>& json, const InspectorConfig& config) const override; 690 void ToJsonValueForOption(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const; 691 void ToJsonValueSelectOverlay(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const; 692 void FromJson(const std::unique_ptr<JsonValue>& json) override; 693 void InitEditingValueText(std::u16string content); 694 bool InitValueText(std::u16string content); 695 void HandleButtonMouseEvent(const RefPtr<TextInputResponseArea>& responseArea, bool isHover); 696 697 void CloseSelectOverlay() override; 698 void CloseSelectOverlay(bool animation); SetInputMethodStatus(bool keyboardShown)699 void SetInputMethodStatus(bool keyboardShown) override 700 { 701 #if defined(OHOS_STANDARD_SYSTEM) && !defined(PREVIEW) 702 imeShown_ = keyboardShown; 703 #endif 704 } 705 void NotifyKeyboardClosedByUser() override; 706 707 void NotifyKeyboardClosed() override; 708 709 std::u16string GetLeftTextOfCursor(int32_t number) override; 710 std::u16string GetRightTextOfCursor(int32_t number) override; 711 int32_t GetTextIndexAtCursor() override; 712 HasConnection()713 bool HasConnection() const 714 { 715 #if defined(OHOS_STANDARD_SYSTEM) && !defined(PREVIEW) 716 return imeShown_; 717 #else 718 return connection_; 719 #endif 720 } 721 float PreferredLineHeight(bool isAlgorithmMeasure = false); 722 723 void SearchRequestKeyboard(); 724 725 bool RequestKeyboardNotByFocusSwitch( 726 RequestKeyboardReason reason = RequestKeyboardReason::UNKNOWN, SourceType sourceType = SourceType::NONE); 727 728 bool TextFieldRequestFocus(RequestFocusReason reason = RequestFocusReason::UNKNOWN); 729 730 static std::string RequestFocusReasonToString(RequestFocusReason reason); 731 732 static std::string RequestKeyboardReasonToString(RequestKeyboardReason reason); 733 GetTextObscured()734 bool GetTextObscured() const 735 { 736 return textObscured_; 737 } 738 739 static std::u16string CreateObscuredText(int32_t len); 740 static std::u16string CreateDisplayText( 741 const std::u16string& content, int32_t nakedCharPosition, bool needObscureText, bool showPasswordDirectly); 742 bool IsTextArea() const override; 743 GetTouchListener()744 const RefPtr<TouchEventImpl>& GetTouchListener() 745 { 746 return touchListener_; 747 } 748 NeedShowPasswordIcon()749 bool NeedShowPasswordIcon() 750 { 751 auto layoutProperty = GetLayoutProperty<TextFieldLayoutProperty>(); 752 CHECK_NULL_RETURN(layoutProperty, false); 753 return IsInPasswordMode() && layoutProperty->GetShowPasswordIconValue(true); 754 } 755 SetEnableTouchAndHoverEffect(bool enable)756 void SetEnableTouchAndHoverEffect(bool enable) 757 { 758 enableTouchAndHoverEffect_ = enable; 759 } 760 GetCaretRect()761 RectF GetCaretRect() const override 762 { 763 return selectController_->GetCaretRect(); 764 } 765 GetFloatingCaretRect()766 RectF GetFloatingCaretRect() const 767 { 768 return selectController_->GetFloatingCaretRect(); 769 } 770 771 void HandleSurfaceChanged(int32_t newWidth, int32_t newHeight, int32_t prevWidth, int32_t prevHeight); 772 void HandleSurfacePositionChanged(int32_t posX, int32_t posY); 773 774 void InitSurfaceChangedCallback(); 775 void InitSurfacePositionChangedCallback(); 776 HasSurfaceChangedCallback()777 bool HasSurfaceChangedCallback() 778 { 779 return surfaceChangedCallbackId_.has_value(); 780 } UpdateSurfaceChangedCallbackId(int32_t id)781 void UpdateSurfaceChangedCallbackId(int32_t id) 782 { 783 surfaceChangedCallbackId_ = id; 784 } 785 HasSurfacePositionChangedCallback()786 bool HasSurfacePositionChangedCallback() 787 { 788 return surfacePositionChangedCallbackId_.has_value(); 789 } UpdateSurfacePositionChangedCallbackId(int32_t id)790 void UpdateSurfacePositionChangedCallbackId(int32_t id) 791 { 792 surfacePositionChangedCallbackId_ = id; 793 } 794 795 void ProcessInnerPadding(); 796 void ProcessNumberOfLines(); 797 void OnCursorMoveDone( 798 TextAffinity textAffinity = TextAffinity::UPSTREAM, std::optional<Offset> offset = std::nullopt); 799 bool IsDisabled(); 800 bool AllowCopy(); 801 GetIsMousePressed()802 bool GetIsMousePressed() const 803 { 804 return isMousePressed_; 805 } 806 GetMouseStatus()807 MouseStatus GetMouseStatus() const 808 { 809 return mouseStatus_; 810 } 811 812 void UpdateEditingValueToRecord(int32_t beforeCaretPosition = -1); 813 814 void UpdateScrollBarOffset() override; 815 UpdateCurrentOffset(float offset,int32_t source)816 bool UpdateCurrentOffset(float offset, int32_t source) override 817 { 818 OnScrollCallback(offset, source); 819 return true; 820 } 821 822 void PlayScrollBarAppearAnimation(); 823 824 void ScheduleDisappearDelayTask(); 825 IsAtTop()826 bool IsAtTop() const override 827 { 828 return contentRect_.GetY() == textRect_.GetY(); 829 } 830 IsAtBottom()831 bool IsAtBottom() const override 832 { 833 return contentRect_.GetY() + contentRect_.Height() == textRect_.GetY() + textRect_.Height(); 834 } 835 IsScrollable()836 bool IsScrollable() const override 837 { 838 return scrollable_; 839 } 840 IsAtomicNode()841 bool IsAtomicNode() const override 842 { 843 return true; 844 } 845 GetCurrentOffset()846 float GetCurrentOffset() const 847 { 848 return currentOffset_; 849 } 850 GetContentModifier()851 RefPtr<TextFieldContentModifier> GetContentModifier() 852 { 853 return textFieldContentModifier_; 854 } 855 856 double GetScrollBarWidth(); 857 GetLineHeight()858 float GetLineHeight() const override 859 { 860 return selectController_->GetCaretRect().Height(); 861 } 862 GetParentGlobalOffset()863 OffsetF GetParentGlobalOffset() const override 864 { 865 return parentGlobalOffset_; 866 } 867 868 RectF GetTextContentRect(bool isActualText = false) const override 869 { 870 return contentRect_; 871 } 872 GetKeyboardOverLay()873 const RefPtr<OverlayManager>& GetKeyboardOverLay() 874 { 875 return keyboardOverlay_; 876 } 877 GetIsCustomKeyboardAttached()878 bool GetIsCustomKeyboardAttached() 879 { 880 return isCustomKeyboardAttached_; 881 } 882 GetDragParagraph()883 const RefPtr<Paragraph>& GetDragParagraph() const override 884 { 885 return paragraph_; 886 } 887 MoveDragNode()888 const RefPtr<FrameNode>& MoveDragNode() override 889 { 890 return dragNode_; 891 } 892 GetDragContents()893 const std::vector<std::u16string>& GetDragContents() const 894 { 895 return dragContents_; 896 } 897 898 void AddDragFrameNodeToManager(const RefPtr<FrameNode>& frameNode); 899 900 void RemoveDragFrameNodeFromManager(const RefPtr<FrameNode>& frameNode); 901 IsDragging()902 bool IsDragging() const 903 { 904 return dragStatus_ == DragStatus::DRAGGING; 905 } 906 907 bool BetweenSelectedPosition(GestureEvent& info); 908 909 bool BetweenSelectedPosition(const Offset& globalOffset) override; 910 911 bool RequestCustomKeyboard(); 912 bool CloseCustomKeyboard(); 913 914 // xts 915 std::string TextInputTypeToString() const; 916 std::string TextInputActionToString() const; 917 std::string TextContentTypeToString() const; 918 virtual std::string GetPlaceholderFont() const; 919 RefPtr<TextFieldTheme> GetTheme() const; 920 void InitTheme(); 921 std::string GetTextColor() const; 922 std::string GetCaretColor() const; 923 std::string GetPlaceholderColor() const; 924 std::string GetFontSize() const; 925 std::string GetMinFontSize() const; 926 std::string GetMaxFontSize() const; 927 std::string GetMinFontScale() const; 928 std::string GetMaxFontScale() const; 929 std::string GetEllipsisMode() const; 930 std::string GetTextIndent() const; 931 Ace::FontStyle GetItalicFontStyle() const; 932 FontWeight GetFontWeight() const; 933 std::string GetFontFamily() const; 934 TextAlign GetTextAlign() const; 935 std::u16string GetPlaceHolder() const; 936 uint32_t GetMaxLength() const; 937 uint32_t GetMaxLines() const; 938 std::string GetInputFilter() const; 939 std::string GetCopyOptionString() const; 940 std::string GetInputStyleString() const; 941 std::u16string GetErrorTextString() const; 942 std::string GetBarStateString() const; 943 bool GetErrorTextState() const; 944 std::string GetShowPasswordIconString() const; 945 int32_t GetNakedCharPosition() const; 946 void SetSelectionFlag(int32_t selectionStart, int32_t selectionEnd, 947 const std::optional<SelectionOptions>& options = std::nullopt, bool isForward = false); 948 void SetSelection(int32_t start, int32_t end, 949 const std::optional<SelectionOptions>& options = std::nullopt, bool isForward = false) override; 950 void HandleBlurEvent(); 951 void HandleFocusEvent(); 952 void SetFocusStyle(); 953 void ClearFocusStyle(); 954 void ProcessFocusStyle(); 955 bool OnBackPressed() override; 956 bool IsStopBackPress() const override; 957 void CheckScrollable(); 958 void HandleClickEvent(GestureEvent& info); 959 bool CheckMousePressedOverScrollBar(GestureEvent& info); 960 int32_t CheckClickLocation(GestureEvent& info); 961 void HandleDoubleClickEvent(GestureEvent& info); 962 void HandleTripleClickEvent(GestureEvent& info); 963 void HandleSingleClickEvent(GestureEvent& info, bool firstGetFocus = false); 964 bool HandleBetweenSelectedPosition(const GestureEvent& info); 965 966 void HandleSelectionUp(); 967 void HandleSelectionDown(); 968 void HandleSelectionLeft(); 969 void HandleSelectionLeftWord(); 970 void HandleSelectionLineBegin(); 971 void HandleSelectionHome(); 972 void HandleSelectionRight(); 973 void HandleSelectionRightWord(); 974 void HandleSelectionLineEnd(); 975 void HandleSelectionEnd(); 976 bool HandleOnEscape() override; 977 bool HandleOnTab(bool backward) override; HandleOnEnter()978 void HandleOnEnter() override 979 { 980 PerformAction(GetTextInputActionValue(GetDefaultTextInputAction()), false); 981 } 982 void HandleOnUndoAction() override; 983 void HandleOnRedoAction() override; 984 bool CanUndo(); 985 bool HasOperationRecords(); 986 bool CanRedo(); 987 void HandleOnSelectAll(bool isKeyEvent, bool inlineStyle = false, bool showMenu = false); HandleOnSelectAll()988 void HandleOnSelectAll() override 989 { 990 HandleOnSelectAll(true); 991 } 992 void HandleOnCopy(bool isUsingExternalKeyboard = false) override; 993 void HandleOnPaste() override; 994 void HandleOnCut() override; 995 bool IsShowTranslate(); 996 bool IsShowSearch(); 997 void HandleOnCameraInput(); 998 void HandleOnAIWrite(); 999 void GetAIWriteInfo(AIWriteInfo& info); 1000 bool IsShowAIWrite(); 1001 void HandleAIWriteResult(int32_t start, int32_t end, std::vector<uint8_t>& buffer); 1002 void UpdateShowCountBorderStyle(); 1003 void StripNextLine(std::wstring& data); 1004 bool IsShowHandle(); 1005 std::string GetCancelButton(); 1006 std::string GetCancelImageText(); 1007 std::string GetPasswordIconPromptInformation(bool show); 1008 bool OnKeyEvent(const KeyEvent& event); 1009 size_t GetLineCount() const override; GetKeyboard()1010 TextInputType GetKeyboard() 1011 { 1012 return keyboard_; 1013 } GetAction()1014 TextInputAction GetAction() 1015 { 1016 return action_; 1017 } 1018 SetNeedToRequestKeyboardOnFocus(bool needToRequest)1019 void SetNeedToRequestKeyboardOnFocus(bool needToRequest) 1020 { 1021 needToRequestKeyboardOnFocus_ = needToRequest; 1022 } 1023 void SetUnitNode(const RefPtr<NG::UINode>& unitNode); 1024 void AddCounterNode(); 1025 void SetShowError(); 1026 GetUnderlineWidth()1027 float GetUnderlineWidth() const 1028 { 1029 return static_cast<float>(underlineWidth_.Value()); 1030 } 1031 GetUnderlineColor()1032 const Color& GetUnderlineColor() const 1033 { 1034 return underlineColor_; 1035 } 1036 1037 float GetMarginBottom() const; 1038 SetUnderlineColor(Color underlineColor)1039 void SetUnderlineColor(Color underlineColor) 1040 { 1041 underlineColor_ = underlineColor; 1042 } 1043 SetNormalUnderlineColor(const Color & normalColor)1044 void SetNormalUnderlineColor(const Color& normalColor) 1045 { 1046 userUnderlineColor_.normal = normalColor; 1047 } 1048 SetUserUnderlineColor(UserUnderlineColor userUnderlineColor)1049 void SetUserUnderlineColor(UserUnderlineColor userUnderlineColor) 1050 { 1051 userUnderlineColor_ = userUnderlineColor; 1052 } 1053 GetUserUnderlineColor()1054 UserUnderlineColor GetUserUnderlineColor() 1055 { 1056 return userUnderlineColor_; 1057 } 1058 SetUnderlineWidth(Dimension underlineWidth)1059 void SetUnderlineWidth(Dimension underlineWidth) 1060 { 1061 underlineWidth_ = underlineWidth; 1062 } 1063 IsSelectAll()1064 bool IsSelectAll() 1065 { 1066 return abs(selectController_->GetStartIndex() - selectController_->GetEndIndex()) >= 1067 static_cast<int32_t>(contentController_->GetTextUtf16Value().length()); 1068 } 1069 1070 void StopEditing(); 1071 MarkContentChange()1072 void MarkContentChange() 1073 { 1074 contChange_ = true; 1075 } 1076 ResetContChange()1077 void ResetContChange() 1078 { 1079 contChange_ = false; 1080 } 1081 GetContChange()1082 bool GetContChange() const 1083 { 1084 return contChange_; 1085 } 1086 std::string GetShowResultImageSrc() const; 1087 std::string GetHideResultImageSrc() const; 1088 std::string GetNormalUnderlineColorStr() const; 1089 std::string GetTypingUnderlineColorStr() const; 1090 std::string GetDisableUnderlineColorStr() const; 1091 std::string GetErrorUnderlineColorStr() const; 1092 void OnAttachToFrameNode() override; 1093 GetTextInputFlag()1094 bool GetTextInputFlag() const 1095 { 1096 return isTextInput_; 1097 } 1098 SetTextInputFlag(bool isTextInput)1099 void SetTextInputFlag(bool isTextInput) 1100 { 1101 isTextInput_ = isTextInput; 1102 SetTextFadeoutCapacity(isTextInput_); 1103 } 1104 SetSingleLineHeight(float height)1105 void SetSingleLineHeight(float height) 1106 { 1107 inlineSingleLineHeight_ = height; 1108 } 1109 GetSingleLineHeight()1110 float GetSingleLineHeight() const 1111 { 1112 return inlineSingleLineHeight_; 1113 } 1114 GetInlinePadding()1115 float GetInlinePadding() const 1116 { 1117 return inlinePadding_; 1118 } 1119 GetScrollBarVisible()1120 bool GetScrollBarVisible() const 1121 { 1122 return scrollBarVisible_; 1123 } 1124 SetFillRequestFinish(bool success)1125 void SetFillRequestFinish(bool success) 1126 { 1127 isFillRequestFinish_ = success; 1128 } 1129 IsFillRequestFinish()1130 bool IsFillRequestFinish() 1131 { 1132 return isFillRequestFinish_; 1133 } 1134 1135 bool IsNormalInlineState() const; 1136 bool IsUnspecifiedOrTextType() const; 1137 void TextIsEmptyRect(RectF& rect); 1138 void TextAreaInputRectUpdate(RectF& rect); 1139 void UpdateRectByTextAlign(RectF& rect); 1140 1141 void EditingValueFilterChange(); 1142 1143 void SetCustomKeyboard(const std::function<void()>&& keyboardBuilder); 1144 1145 void SetCustomKeyboardWithNode(const RefPtr<UINode>& keyboardBuilder); 1146 HasCustomKeyboard()1147 bool HasCustomKeyboard() const 1148 { 1149 return customKeyboard_ != nullptr || customKeyboardBuilder_ != nullptr; 1150 } 1151 1152 void DumpInfo() override; DumpSimplifyInfo(std::unique_ptr<JsonValue> & json)1153 void DumpSimplifyInfo(std::unique_ptr<JsonValue>& json) override {} 1154 void DumpAdvanceInfo() override; 1155 void DumpPlaceHolderInfo(); 1156 void DumpTextEngineInfo(); 1157 void DumpScaleInfo(); 1158 std::string GetDumpTextValue() const; 1159 void DumpViewDataPageNode(RefPtr<ViewDataWrap> viewDataWrap, bool needsRecordData = false) override; 1160 void NotifyFillRequestSuccess(RefPtr<ViewDataWrap> viewDataWrap, 1161 RefPtr<PageNodeInfoWrap> nodeWrap, AceAutoFillType autoFillType) override; 1162 void NotifyFillRequestFailed(int32_t errCode, const std::string& fillContent = "", bool isPopup = false) override; 1163 bool CheckAutoSave() override; 1164 void OnColorConfigurationUpdate() override; 1165 bool NeedPaintSelect(); 1166 void SetCustomKeyboardOption(bool supportAvoidance); 1167 SetIsCustomFont(bool isCustomFont)1168 void SetIsCustomFont(bool isCustomFont) 1169 { 1170 isCustomFont_ = isCustomFont; 1171 } 1172 GetIsCustomFont()1173 bool GetIsCustomFont() const 1174 { 1175 return isCustomFont_; 1176 } 1177 SetIsCounterIdealHeight(bool isIdealHeight)1178 void SetIsCounterIdealHeight(bool isIdealHeight) 1179 { 1180 isCounterIdealheight_ = isIdealHeight; 1181 } 1182 GetIsCounterIdealHeight()1183 bool GetIsCounterIdealHeight() const 1184 { 1185 return isCounterIdealheight_; 1186 } 1187 1188 virtual RefPtr<FocusHub> GetFocusHub() const; 1189 void UpdateCaretInfoToController(bool forceUpdate = false); 1190 void OnObscuredChanged(bool isObscured); GetResponseArea()1191 const RefPtr<TextInputResponseArea>& GetResponseArea() 1192 { 1193 return responseArea_; 1194 } 1195 GetCleanNodeResponseArea()1196 const RefPtr<TextInputResponseArea>& GetCleanNodeResponseArea() 1197 { 1198 return cleanNodeResponseArea_; 1199 } 1200 1201 bool IsShowUnit() const; 1202 bool IsShowPasswordIcon() const; 1203 std::optional<bool> IsShowPasswordText() const; 1204 bool IsInPasswordMode() const; 1205 bool IsShowCancelButtonMode() const; 1206 void CheckPasswordAreaState(); 1207 GetShowSelect()1208 bool GetShowSelect() const 1209 { 1210 return showSelect_; 1211 } 1212 ShowSelect()1213 void ShowSelect() 1214 { 1215 showSelect_ = true; 1216 } 1217 1218 void FocusForwardStopTwinkling(); 1219 bool UpdateFocusForward(); 1220 1221 bool UpdateFocusBackward(); 1222 1223 bool HandleSpaceEvent(); 1224 1225 virtual void ApplyNormalTheme(); 1226 void ApplyUnderlineTheme(); 1227 void ApplyInlineTheme(); 1228 GetContentWideTextLength()1229 int32_t GetContentWideTextLength() override 1230 { 1231 return static_cast<int32_t>(contentController_->GetTextUtf16Value().length()); 1232 } 1233 HandleOnShowMenu()1234 void HandleOnShowMenu() override 1235 { 1236 selectOverlay_->HandleOnShowMenu(); 1237 } 1238 bool HasFocus() const; 1239 void StopTwinkling(); 1240 void StartTwinkling(); 1241 IsModifyDone()1242 bool IsModifyDone() 1243 { 1244 return isModifyDone_; 1245 } SetModifyDoneStatus(bool value)1246 void SetModifyDoneStatus(bool value) 1247 { 1248 isModifyDone_ = value; 1249 } 1250 GetLastClickTime()1251 const TimeStamp& GetLastClickTime() 1252 { 1253 return lastClickTimeStamp_; 1254 } 1255 1256 void CheckTextAlignByDirection(TextAlign& textAlign, TextDirection direction); 1257 1258 void HandleOnDragStatusCallback( 1259 const DragEventType& dragEventType, const RefPtr<NotifyDragEvent>& notifyDragEvent) override; 1260 1261 void GetCaretMetrics(CaretMetricsF& caretCaretMetric) override; 1262 1263 OffsetF GetTextPaintOffset() const override; 1264 1265 OffsetF GetPaintRectGlobalOffset() const; 1266 NeedRequestKeyboard()1267 void NeedRequestKeyboard() 1268 { 1269 SetNeedToRequestKeyboardInner(true, RequestKeyboardInnerChangeReason::SEARCH_FOCUS); 1270 } 1271 1272 void SetNeedToRequestKeyboardInner(bool needToRequestKeyboardInner, 1273 RequestKeyboardInnerChangeReason reason = RequestKeyboardInnerChangeReason::UNKNOWN); 1274 1275 void CleanNodeResponseKeyEvent(); 1276 1277 void ScrollPage(bool reverse, bool smooth = false, 1278 AccessibilityScrollType scrollType = AccessibilityScrollType::SCROLL_FULL) override; InitScrollBarClickEvent()1279 void InitScrollBarClickEvent() override {} 1280 void ClearTextContent(); 1281 bool IsUnderlineMode() const; 1282 bool IsInlineMode() const; 1283 bool IsShowError(); 1284 bool IsShowCount(); 1285 void ResetContextAttr(); 1286 void RestoreDefaultMouseState(); 1287 1288 void RegisterWindowSizeCallback(); 1289 void OnWindowSizeChanged(int32_t width, int32_t height, WindowSizeChangeReason type) override; 1290 IsTransparent()1291 bool IsTransparent() 1292 { 1293 return isTransparent_; 1294 } 1295 GetClipboard()1296 RefPtr<Clipboard> GetClipboard() override 1297 { 1298 return clipboard_; 1299 } 1300 1301 const Dimension& GetAvoidSoftKeyboardOffset() const override; 1302 GetPaintContentRect()1303 RectF GetPaintContentRect() override 1304 { 1305 auto transformContentRect = contentRect_; 1306 selectOverlay_->GetLocalRectWithTransform(transformContentRect); 1307 return transformContentRect; 1308 } 1309 1310 bool ProcessAutoFill(bool& isPopup, bool isFromKeyBoard = false, bool isNewPassWord = false); SetAutoFillUserName(const std::string & userName)1311 void SetAutoFillUserName(const std::string& userName) 1312 { 1313 autoFillUserName_ = userName; 1314 } 1315 GetAutoFillUserName()1316 std::string GetAutoFillUserName() 1317 { 1318 return autoFillUserName_; 1319 } 1320 GetAutoFillNewPassword()1321 std::string GetAutoFillNewPassword() 1322 { 1323 return autoFillNewPassword_; 1324 } 1325 SetAutoFillNewPassword(const std::string & newPassword)1326 void SetAutoFillNewPassword(const std::string& newPassword) 1327 { 1328 autoFillNewPassword_ = newPassword; 1329 } SetAutoFillOtherAccount(bool otherAccount)1330 void SetAutoFillOtherAccount(bool otherAccount) 1331 { 1332 autoFillOtherAccount_ = otherAccount; 1333 } 1334 1335 std::vector<RectF> GetPreviewTextRects() const; 1336 GetIsPreviewText()1337 bool GetIsPreviewText() const 1338 { 1339 return hasPreviewText_; 1340 } 1341 GetPreviewDecorationColor()1342 const Color& GetPreviewDecorationColor() const 1343 { 1344 auto theme = GetTheme(); 1345 CHECK_NULL_RETURN(theme, Color::TRANSPARENT); 1346 return theme->GetPreviewUnderlineColor(); 1347 } 1348 1349 bool NeedDrawPreviewText(); 1350 GetPreviewUnderlineWidth()1351 float GetPreviewUnderlineWidth() const 1352 { 1353 return static_cast<float>(previewUnderlineWidth_.ConvertToPx()); 1354 } 1355 1356 void ReceivePreviewTextStyle(const std::string& style) override; 1357 1358 PreviewTextStyle GetPreviewTextStyle() const; 1359 GetCustomKeyboard()1360 RefPtr<UINode> GetCustomKeyboard() 1361 { 1362 return customKeyboard_; 1363 } 1364 GetCustomKeyboardOption()1365 bool GetCustomKeyboardOption() 1366 { 1367 return keyboardAvoidance_; 1368 } 1369 1370 void SetShowKeyBoardOnFocus(bool value); GetShowKeyBoardOnFocus()1371 bool GetShowKeyBoardOnFocus() 1372 { 1373 return showKeyBoardOnFocus_; 1374 } 1375 1376 void OnSelectionMenuOptionsUpdate( 1377 const NG::OnCreateMenuCallback&& onCreateMenuCallback, const NG::OnMenuItemClickCallback&& onMenuItemClick); 1378 OnCreateMenuCallbackUpdate(const NG::OnCreateMenuCallback && onCreateMenuCallback)1379 void OnCreateMenuCallbackUpdate(const NG::OnCreateMenuCallback&& onCreateMenuCallback) 1380 { 1381 selectOverlay_->OnCreateMenuCallbackUpdate(std::move(onCreateMenuCallback)); 1382 } 1383 OnMenuItemClickCallbackUpdate(const NG::OnMenuItemClickCallback && onMenuItemClick)1384 void OnMenuItemClickCallbackUpdate(const NG::OnMenuItemClickCallback&& onMenuItemClick) 1385 { 1386 selectOverlay_->OnMenuItemClickCallbackUpdate(std::move(onMenuItemClick)); 1387 } 1388 SetSupportPreviewText(bool isSupported)1389 void SetSupportPreviewText(bool isSupported) 1390 { 1391 hasSupportedPreviewText_ = isSupported; 1392 } 1393 GetSupportPreviewText()1394 bool GetSupportPreviewText() const 1395 { 1396 return hasSupportedPreviewText_; 1397 } 1398 GetPreviewTextStart()1399 int32_t GetPreviewTextStart() const 1400 { 1401 return hasPreviewText_ ? previewTextStart_ : selectController_->GetCaretIndex(); 1402 } 1403 GetPreviewTextEnd()1404 int32_t GetPreviewTextEnd() const 1405 { 1406 return hasPreviewText_ ? previewTextEnd_ : selectController_->GetCaretIndex(); 1407 } 1408 GetPreviewTextValue()1409 std::u16string GetPreviewTextValue() const 1410 { 1411 return contentController_->GetSelectedValue(GetPreviewTextStart(), GetPreviewTextEnd()); 1412 } 1413 GetBodyTextValue()1414 std::u16string GetBodyTextValue() const 1415 { 1416 return hasPreviewText_ ? bodyTextInPreivewing_ : GetTextUtf16Value(); 1417 } 1418 IsPressSelectedBox()1419 bool IsPressSelectedBox() 1420 { 1421 return isPressSelectedBox_; 1422 } 1423 1424 int32_t CheckPreviewTextValidate(const std::string& previewValue, const PreviewRange range) override; 1425 int32_t CheckPreviewTextValidate(const std::u16string& previewValue, const PreviewRange range) override; 1426 void HiddenMenu(); 1427 OnFrameNodeChanged(FrameNodeChangeInfoFlag flag)1428 void OnFrameNodeChanged(FrameNodeChangeInfoFlag flag) override 1429 { 1430 selectOverlay_->OnAncestorNodeChanged(flag); 1431 } 1432 GetSelectIndex(int32_t & start,int32_t & end)1433 void GetSelectIndex(int32_t& start, int32_t& end) const override 1434 { 1435 start = selectController_->GetStartIndex(); 1436 end = selectController_->GetEndIndex(); 1437 } 1438 SetTextChangedAtCreation(bool changed)1439 void SetTextChangedAtCreation(bool changed) 1440 { 1441 isTextChangedAtCreation_ = changed; 1442 } 1443 SetIsPasswordSymbol(bool isPasswordSymbol)1444 void SetIsPasswordSymbol(bool isPasswordSymbol) 1445 { 1446 isPasswordSymbol_ = isPasswordSymbol; 1447 } 1448 IsShowPasswordSymbol()1449 bool IsShowPasswordSymbol() const 1450 { 1451 return isPasswordSymbol_ && Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_THIRTEEN); 1452 } 1453 1454 bool IsResponseRegionExpandingNeededForStylus(const TouchEvent& touchEvent) const override; 1455 1456 RectF ExpandDefaultResponseRegion(RectF& rect) override; 1457 UpdateParentGlobalOffset()1458 void UpdateParentGlobalOffset() 1459 { 1460 parentGlobalOffset_ = GetPaintRectGlobalOffset(); 1461 } 1462 1463 PositionWithAffinity GetGlyphPositionAtCoordinate(int32_t x, int32_t y) override; 1464 1465 bool InsertOrDeleteSpace(int32_t index) override; 1466 1467 void DeleteRange(int32_t start, int32_t end, bool isIME = true) override; 1468 1469 void DeleteTextRange(int32_t start, int32_t end, TextDeleteDirection direction); 1470 1471 bool SetCaretOffset(int32_t caretPostion) override; 1472 GetMultipleClickRecognizer()1473 const RefPtr<MultipleClickRecognizer>& GetMultipleClickRecognizer() const 1474 { 1475 return multipleClickRecognizer_; 1476 } 1477 SetAdaptFontSize(const std::optional<Dimension> & adaptFontSize)1478 void SetAdaptFontSize(const std::optional<Dimension>& adaptFontSize) 1479 { 1480 adaptFontSize_ = adaptFontSize; 1481 } 1482 1483 void ShowCaretAndStopTwinkling(); 1484 1485 void TriggerAvoidOnCaretChange(); 1486 1487 void TriggerAvoidWhenCaretGoesDown(); 1488 1489 bool IsTextEditableForStylus() const override; 1490 bool IsHandleDragging(); IsLTRLayout()1491 bool IsLTRLayout() 1492 { 1493 auto host = GetHost(); 1494 CHECK_NULL_RETURN(host, true); 1495 return host->GetLayoutProperty()->GetNonAutoLayoutDirection() == TextDirection::LTR; 1496 } 1497 GetLastCaretPos()1498 std::optional<float> GetLastCaretPos() const 1499 { 1500 return lastCaretPos_; 1501 } 1502 SetLastCaretPos(float lastCaretPos)1503 void SetLastCaretPos(float lastCaretPos) 1504 { 1505 lastCaretPos_ = lastCaretPos; 1506 } 1507 SetEnableHapticFeedback(bool isEnabled)1508 void SetEnableHapticFeedback(bool isEnabled) 1509 { 1510 isEnableHapticFeedback_ = isEnabled; 1511 } 1512 GetEnableHapticFeedback()1513 bool GetEnableHapticFeedback() const 1514 { 1515 return isEnableHapticFeedback_; 1516 } 1517 SetIsFocusedBeforeClick(bool isFocusedBeforeClick)1518 void SetIsFocusedBeforeClick(bool isFocusedBeforeClick) 1519 { 1520 isFocusedBeforeClick_ = isFocusedBeforeClick; 1521 } 1522 1523 void StartVibratorByIndexChange(int32_t currentIndex, int32_t preIndex); 1524 virtual void ProcessSelection(); 1525 void AfterLayoutProcessCleanResponse( 1526 const RefPtr<CleanNodeResponseArea>& cleanNodeResponseArea); 1527 void StopContentScroll(); 1528 void UpdateContentScroller(const Offset& localOffset); SetIsInitTextRect(bool isInitTextRect)1529 void SetIsInitTextRect(bool isInitTextRect) 1530 { 1531 initTextRect_ = isInitTextRect; 1532 } 1533 1534 virtual float FontSizeConvertToPx(const Dimension& fontSize); 1535 1536 SelectionInfo GetSelection(); 1537 GetContentScrollerIsScrolling()1538 bool GetContentScrollerIsScrolling() const 1539 { 1540 return contentScroller_.isScrolling; 1541 } 1542 SetTextFadeoutCapacity(bool enabled)1543 void SetTextFadeoutCapacity(bool enabled) 1544 { 1545 haveTextFadeoutCapacity_ = enabled; 1546 } GetTextFadeoutCapacity()1547 bool GetTextFadeoutCapacity() 1548 { 1549 return haveTextFadeoutCapacity_; 1550 } 1551 SetHoverPressBgColorEnabled(bool enabled)1552 void SetHoverPressBgColorEnabled(bool enabled) 1553 { 1554 hoverAndPressBgColorEnabled_ = enabled; 1555 } 1556 1557 bool GetOriginCaretPosition(OffsetF& offset) const; 1558 void ResetOriginCaretPosition() override; 1559 bool RecordOriginCaretPosition() override; 1560 void AddInsertCommand(const std::u16string& insertValue, InputReason reason); 1561 void AddInputCommand(const InputCommandInfo& inputCommandInfo); 1562 void ExecuteInputCommand(const InputCommandInfo& inputCommandInfo); SetIsFilterChanged(bool isFilterChanged)1563 void SetIsFilterChanged(bool isFilterChanged) 1564 { 1565 isFilterChanged_ = isFilterChanged; 1566 } GetCancelButtonTouchInfo()1567 bool GetCancelButtonTouchInfo() 1568 { 1569 return cancelButtonTouched_; 1570 } 1571 protected: 1572 virtual void InitDragEvent(); 1573 void OnAttachToMainTree() override; 1574 1575 void OnDetachFromMainTree() override; 1576 IsReverse()1577 bool IsReverse() const override 1578 { 1579 return false; 1580 } 1581 SelectOverlayIsOn()1582 bool SelectOverlayIsOn() 1583 { 1584 return selectOverlay_->SelectOverlayIsOn(); 1585 } 1586 SetIsSingleHandle(bool isSingleHandle)1587 void SetIsSingleHandle(bool isSingleHandle) 1588 { 1589 selectOverlay_->SetIsSingleHandle(isSingleHandle); 1590 } 1591 1592 int32_t GetTouchIndex(const OffsetF& offset) override; 1593 void OnTextGestureSelectionUpdate(int32_t start, int32_t end, const TouchEventInfo& info) override; 1594 void OnTextGenstureSelectionEnd(const TouchLocationInfo& locationInfo) override; 1595 void DoTextSelectionTouchCancel() override; 1596 void StartGestureSelection(int32_t start, int32_t end, const Offset& startOffset) override; 1597 void UpdateSelection(int32_t both); 1598 void UpdateSelection(int32_t start, int32_t end); 1599 virtual bool IsNeedProcessAutoFill(); 1600 void UpdatePasswordIconColor(const Color& color); 1601 bool OnThemeScopeUpdate(int32_t themeScopeId) override; 1602 1603 RefPtr<ContentController> contentController_; 1604 RefPtr<TextSelectController> selectController_; 1605 bool needToRefreshSelectOverlay_ = false; 1606 bool isTextChangedAtCreation_ = false; 1607 1608 void HandleCloseKeyboard(bool forceClose); 1609 1610 // 是否独立控制键盘 1611 bool independentControlKeyboard_ = false; 1612 1613 private: 1614 Offset ConvertTouchOffsetToTextOffset(const Offset& touchOffset); 1615 void GetTextSelectRectsInRangeAndWillChange(); 1616 bool BeforeIMEInsertValue(const std::u16string& insertValue, int32_t offset); 1617 void AfterIMEInsertValue(const std::u16string& insertValue); 1618 bool BeforeIMEDeleteValue(const std::u16string& deleteValue, TextDeleteDirection direction, int32_t offset); 1619 void AfterIMEDeleteValue(const std::u16string& deleteValue, TextDeleteDirection direction); 1620 1621 bool FireOnWillChange(const ChangeValueInfo& changeValueInfo); 1622 bool OnWillChangePreSetValue(const std::u16string& newValue); 1623 bool OnWillChangePreDelete(const std::u16string& oldContent, uint32_t start, uint32_t end); 1624 bool OnWillChangePreInsert(const std::u16string& insertValue, const std::u16string& oldContent, 1625 uint32_t start, uint32_t end); 1626 void RecoverTextValueAndCaret(const std::u16string& oldValue, TextRange caretIndex); 1627 void OnAfterModifyDone() override; 1628 void HandleTouchEvent(const TouchEventInfo& info); 1629 void HandleTouchDown(const Offset& offset); 1630 void HandleTouchUp(); 1631 void HandleCancelButtonTouchDown(const RefPtr<TextInputResponseArea>& responseArea); 1632 void HandleCancelButtonTouchUp(); 1633 void HandleTouchMove(const TouchLocationInfo& info); 1634 void UpdateCaretByTouchMove(const TouchLocationInfo& info); 1635 void InitDisableColor(); 1636 void InitFocusEvent(); 1637 void InitTouchEvent(); 1638 void InitLongPressEvent(); 1639 void InitClickEvent(); 1640 void InitDragDropEvent(); 1641 bool ProcessFocusIndexAction(); 1642 std::function<DragDropInfo(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)> OnDragStart(); 1643 std::function<void(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)> OnDragDrop(); 1644 std::string GetDragStyledText(); 1645 void ShowSelectAfterDragEvent(); 1646 void ClearDragDropEvent(); 1647 std::function<void(Offset)> GetThumbnailCallback(); 1648 bool HasStateStyle(UIState state) const; 1649 1650 void OnTextInputScroll(float offset); 1651 void OnTextAreaScroll(float offset); 1652 bool OnScrollCallback(float offset, int32_t source) override; 1653 void OnScrollEndCallback() override; 1654 bool CheckSelectAreaVisible(); 1655 void InitMouseEvent(); 1656 void InitCancelButtonMouseEvent(); 1657 void InitPasswordButtonMouseEvent(); 1658 void HandleHoverEffect(MouseInfo& info, bool isHover); 1659 void OnHover(bool isHover); 1660 void UpdateHoverStyle(bool isHover); 1661 void UpdatePressStyle(bool isPressed); 1662 void PlayAnimationHoverAndPress(const Color& color); 1663 void UpdateTextFieldBgColor(const Color& color); 1664 void ChangeMouseState( 1665 const Offset location, int32_t frameId, bool isByPass = false); 1666 void FreeMouseStyleHoldNode(const Offset location); 1667 void HandleMouseEvent(MouseInfo& info); 1668 void FocusAndUpdateCaretByMouse(MouseInfo& info); 1669 void UpdateShiftFlag(const KeyEvent& keyEvent) override; 1670 void UpdateCaretByClick(const Offset& localOffset); 1671 void HandleRightMouseEvent(MouseInfo& info); 1672 void HandleRightMousePressEvent(MouseInfo& info); 1673 void HandleRightMouseReleaseEvent(MouseInfo& info); 1674 void HandleLeftMouseEvent(MouseInfo& info); 1675 void HandleLeftMousePressEvent(MouseInfo& info); 1676 void HandleLeftMouseMoveEvent(MouseInfo& info); 1677 void HandleLeftMouseReleaseEvent(MouseInfo& info); 1678 void StartVibratorByLongPress(); 1679 void HandleLongPress(GestureEvent& info); 1680 bool CanChangeSelectState(); 1681 void UpdateCaretPositionWithClamp(const int32_t& pos); 1682 void CursorMoveOnClick(const Offset& offset); 1683 1684 void DelayProcessOverlay(const OverlayRequest& request = OverlayRequest()); 1685 void CancelDelayProcessOverlay(); 1686 void ProcessOverlayAfterLayout(const OffsetF& prevOffset); 1687 void ProcessOverlay(const OverlayRequest& request = OverlayRequest()); 1688 1689 // when moving one handle causes shift of textRect, update x position of the other handle 1690 void SetHandlerOnMoveDone(); 1691 void OnDetachFromFrameNode(FrameNode* node) override; 1692 void OnAttachContext(PipelineContext* context) override; 1693 void OnDetachContext(PipelineContext* context) override; 1694 void UpdateSelectionByMouseDoubleClick(); 1695 1696 void AfterSelection(); 1697 1698 void AutoFillValueChanged(); 1699 void FireEventHubOnChange(const std::u16string& text); 1700 // The return value represents whether the editor content has change. 1701 bool FireOnTextChangeEvent(); 1702 void AddTextFireOnChange(); 1703 void RecordTextInputEvent(); 1704 1705 void FilterInitializeText(); 1706 1707 void UpdateCaretPositionByLastTouchOffset(); 1708 bool UpdateCaretPosition(); 1709 void UpdateCaretRect(bool isEditorValueChanged); 1710 void AdjustTextInReasonableArea(); 1711 bool CharLineChanged(int32_t caretPosition); 1712 1713 void ScheduleCursorTwinkling(); 1714 void OnCursorTwinkling(); 1715 void CheckIfNeedToResetKeyboard(); 1716 1717 float PreferredTextHeight(bool isPlaceholder, bool isAlgorithmMeasure = false); 1718 1719 void SetCaretOffsetForEmptyTextOrPositionZero(); 1720 void UpdateTextFieldManager(const Offset& offset, float height); 1721 void OnTextInputActionUpdate(TextInputAction value); 1722 1723 void Delete(int32_t start, int32_t end); 1724 void CheckAndUpdateRecordBeforeOperation(); 1725 void BeforeCreateLayoutWrapper() override; 1726 bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override; 1727 bool CursorInContentRegion(); 1728 bool OffsetInContentRegion(const Offset& offset); 1729 void SetDisabledStyle(); 1730 1731 void CalculateDefaultCursor(); 1732 void RequestKeyboardByFocusSwitch(); 1733 void TextFieldLostFocusToViewRoot(); 1734 bool IsModalCovered(); 1735 void SetNeedToRequestKeyboardOnFocus(); 1736 void SetAccessibilityAction() override; 1737 void SetAccessibilityActionGetAndSetCaretPosition(); 1738 void SetAccessibilityActionOverlayAndSelection(); 1739 void SetAccessibilityMoveTextAction(); 1740 void SetAccessibilityErrotText(); 1741 void SetAccessibilityClearAction(); 1742 void SetAccessibilityPasswordIconAction(); 1743 void SetAccessibilityUnitAction(); 1744 1745 void UpdateCopyAllStatus(); 1746 void RestorePreInlineStates(); 1747 void ProcessRectPadding(); 1748 void CalcScrollRect(Rect& inlineScrollRect); 1749 1750 bool ResetObscureTickCountDown(); 1751 bool IsAccessibilityClick(); 1752 bool IsOnUnitByPosition(const Offset& globalOffset); 1753 bool IsOnPasswordByPosition(const Offset& globalOffset); 1754 bool IsOnCleanNodeByPosition(const Offset& globalOffset); 1755 bool IsTouchAtLeftOffset(float currentOffsetX); 1756 void FilterExistText(); 1757 void UpdateErrorTextMargin(); 1758 void UpdateSelectController(); 1759 void UpdateHandlesOffsetOnScroll(float offset); 1760 void CloseHandleAndSelect() override; 1761 bool RepeatClickCaret(const Offset& offset, int32_t lastCaretIndex); 1762 bool RepeatClickCaret(const Offset& offset, const RectF& lastCaretRect); 1763 void PaintTextRect(); 1764 void GetIconPaintRect(const RefPtr<TextInputResponseArea>& responseArea, RoundRect& paintRect); 1765 void GetInnerFocusPaintRect(RoundRect& paintRect); 1766 void GetTextInputFocusPaintRect(RoundRect& paintRect); 1767 void PaintResponseAreaRect(); 1768 void PaintCancelRect(); 1769 void PaintUnitRect(); 1770 void PaintPasswordRect(); CancelNodeIsShow()1771 bool CancelNodeIsShow() 1772 { 1773 auto cleanNodeArea = AceType::DynamicCast<CleanNodeResponseArea>(cleanNodeResponseArea_); 1774 CHECK_NULL_RETURN(cleanNodeArea, false); 1775 return cleanNodeArea->IsShow(); 1776 } 1777 1778 void InitPanEvent(); 1779 1780 void PasswordResponseKeyEvent(); 1781 void UnitResponseKeyEvent(); 1782 void ProcBorderAndUnderlineInBlurEvent(); 1783 void ProcNormalInlineStateInBlurEvent(); 1784 bool IsMouseOverScrollBar(const BaseEventInfo* info); 1785 1786 #if defined(ENABLE_STANDARD_INPUT) 1787 std::optional<MiscServices::TextConfig> GetMiscTextConfig() const; 1788 void GetInlinePositionYAndHeight(double& positionY, double& height) const; 1789 #endif 1790 void NotifyOnEditChanged(bool isChanged); 1791 void ProcessResponseArea(); 1792 void ProcessCancelButton(); 1793 bool HasInputOperation(); 1794 AceAutoFillType ConvertToAceAutoFillType(TextInputType type); 1795 bool CheckAutoFill(bool isFromKeyBoard = false); 1796 void ScrollToSafeArea() const override; 1797 void RecordSubmitEvent() const; 1798 void UpdateCancelNode(); 1799 void AdjustTextRectByCleanNode(RectF& textRect); 1800 void RequestKeyboardAfterLongPress(); 1801 void UpdatePasswordModeState(); 1802 void InitDragDropCallBack(); 1803 void InitDragDropEventWithOutDragStart(); 1804 void UpdateBlurReason(); 1805 AceAutoFillType TextContentTypeToAceAutoFillType(const TextContentType& type); 1806 bool CheckAutoFillType(const AceAutoFillType& aceAutoFillAllType, bool isFromKeyBoard = false); 1807 bool GetAutoFillTriggeredStateByType(const AceAutoFillType& autoFillType); 1808 void SetAutoFillTriggeredStateByType(const AceAutoFillType& autoFillType); 1809 AceAutoFillType GetAutoFillType(bool isNeedToHitType = true); 1810 bool IsAutoFillPasswordType(const AceAutoFillType& autoFillType); 1811 void DoProcessAutoFill(SourceType sourceType = SourceType::NONE); 1812 void KeyboardContentTypeToInputType(); 1813 void ProcessScroll(); 1814 void ProcessCounter(); 1815 void HandleParentGlobalOffsetChange(); 1816 HintToTypeWrap GetHintType(); 1817 HintToTypeWrap GetAutoFillTypeAndMetaData(bool isNeedToHitType = true); 1818 PaddingProperty GetPaddingByUserValue(); 1819 void SetThemeAttr(); 1820 void SetThemeBorderAttr(); 1821 void ProcessInlinePaddingAndMargin(); 1822 Offset ConvertGlobalToLocalOffset(const Offset& globalOffset); 1823 void HandleCountStyle(); 1824 void HandleDeleteOnCounterScene(); 1825 bool ParseFillContentJsonValue(const std::unique_ptr<JsonValue>& jsonObject, 1826 std::unordered_map<std::string, std::variant<std::string, bool, int32_t>>& map); 1827 void HandleContentSizeChange(const RectF& textRect); UpdatePreviewIndex(int32_t start,int32_t end)1828 void UpdatePreviewIndex(int32_t start, int32_t end) 1829 { 1830 previewTextStart_ = start; 1831 previewTextEnd_ = end; 1832 } 1833 1834 void CalculatePreviewingTextMovingLimit(const Offset& touchOffset, double& limitL, double& limitR); 1835 void UpdateParam(GestureEvent& info, bool shouldProcessOverlayAfterLayout); 1836 void OnCaretMoveDone(const TouchEventInfo& info); 1837 void HandleCrossPlatformInBlurEvent(); 1838 void ModifyInnerStateInBlurEvent(); 1839 1840 void TwinklingByFocus(); 1841 1842 bool FinishTextPreviewByPreview(const std::u16string& insertValue); 1843 bool GetIndependentControlKeyboard(); 1844 bool IsMoveFocusOutFromLeft(const KeyEvent& event); 1845 bool IsMoveFocusOutFromRight(const KeyEvent& event); 1846 1847 bool GetTouchInnerPreviewText(const Offset& offset) const; 1848 bool IsShowMenu(const std::optional<SelectionOptions>& options, bool defaultValue); 1849 bool IsContentRectNonPositive(); 1850 void ReportEvent(); 1851 void ResetPreviewTextState(); 1852 void CalculateBoundsRect(); 1853 TextFieldInfo GenerateTextFieldInfo(); 1854 void AddTextFieldInfo(); 1855 void RemoveTextFieldInfo(); 1856 void UpdateTextFieldInfo(); 1857 bool IsAutoFillUserName(const AceAutoFillType& autoFillType); 1858 bool HasAutoFillPasswordNode(); 1859 bool IsTriggerAutoFillPassword(); 1860 1861 void PauseContentScroll(); 1862 void ScheduleContentScroll(float delay); 1863 void UpdateSelectionByLongPress(int32_t start, int32_t end, const Offset& localOffset); 1864 std::optional<float> CalcAutoScrollStepOffset(const Offset& localOffset); 1865 void SetDragMovingScrollback(); 1866 float CalcScrollSpeed(float hotAreaStart, float hotAreaEnd, float point); 1867 std::optional<TouchLocationInfo> GetAcceptedTouchLocationInfo(const TouchEventInfo& info); 1868 void ResetTouchAndMoveCaretState(); 1869 void UpdateSelectionAndHandleVisibility(); 1870 void ResetFirstClickAfterGetFocus(); 1871 void ProcessAutoFillOnFocus(); 1872 bool IsStopEditWhenCloseKeyboard(); 1873 void SetIsEnableSubWindowMenu(); 1874 1875 RectF frameRect_; 1876 RectF textRect_; 1877 float textParagraphIndent_ = 0.0; 1878 RefPtr<Paragraph> paragraph_; 1879 InlineMeasureItem inlineMeasureItem_; 1880 TextStyle nextLineUtilTextStyle_; 1881 1882 RefPtr<ClickEvent> clickListener_; 1883 RefPtr<TouchEventImpl> touchListener_; 1884 RefPtr<TouchEventImpl> imageTouchEvent_; 1885 RefPtr<ScrollableEvent> scrollableEvent_; 1886 RefPtr<InputEvent> mouseEvent_; 1887 RefPtr<InputEvent> hoverEvent_; 1888 RefPtr<InputEvent> imageHoverEvent_; 1889 RefPtr<LongPressEvent> longPressEvent_; 1890 CursorPositionType cursorPositionType_ = CursorPositionType::NORMAL; 1891 1892 // What the keyboard should appears. 1893 TextInputType keyboard_ = TextInputType::UNSPECIFIED; 1894 // Action when "enter" pressed. 1895 TextInputAction action_ = TextInputAction::UNSPECIFIED; 1896 TextDirection textDirection_ = TextDirection::LTR; 1897 // Used to record original caret position for "shift + up/down" 1898 // Less than 0 is invalid, initialized as invalid in constructor 1899 OffsetF originCaretPosition_; 1900 1901 OffsetF parentGlobalOffset_; 1902 OffsetF lastTouchOffset_; 1903 std::optional<PaddingPropertyF> utilPadding_; 1904 1905 bool setBorderFlag_ = true; 1906 BorderWidthProperty lastDiffBorderWidth_; 1907 BorderColorProperty lastDiffBorderColor_; 1908 1909 HandleMoveStatus handleMoveStatus_; 1910 bool cursorVisible_ = false; 1911 bool focusEventInitialized_ = false; 1912 bool isMousePressed_ = false; 1913 bool textObscured_ = true; 1914 bool enableTouchAndHoverEffect_ = true; 1915 bool isOnHover_ = false; 1916 bool needToRequestKeyboardInner_ = false; 1917 bool needToRequestKeyboardOnFocus_ = false; 1918 bool isTransparent_ = false; 1919 bool contChange_ = false; 1920 bool counterChange_ = false; 1921 std::optional<int32_t> surfaceChangedCallbackId_; 1922 std::optional<int32_t> surfacePositionChangedCallbackId_; 1923 RefPtr<TextComponentDecorator> counterDecorator_; 1924 RefPtr<TextComponentDecorator> errorDecorator_; 1925 1926 SelectionMode selectionMode_ = SelectionMode::NONE; 1927 CaretUpdateType caretUpdateType_ = CaretUpdateType::NONE; 1928 bool scrollable_ = true; 1929 bool blockPress_ = false; 1930 bool isPressSelectedBox_ = false; 1931 float previewWidth_ = 0.0f; 1932 float lastTextRectY_ = 0.0f; 1933 std::optional<DisplayMode> barState_; 1934 1935 uint32_t twinklingInterval_ = 0; 1936 int32_t obscureTickCountDown_ = 0; 1937 int32_t nakedCharPosition_ = -1; 1938 bool obscuredChange_ = false; 1939 float currentOffset_ = 0.0f; 1940 float countHeight_ = 0.0f; 1941 Dimension underlineWidth_ = 1.0_px; 1942 Color underlineColor_; 1943 UserUnderlineColor userUnderlineColor_ = UserUnderlineColor(); 1944 bool scrollBarVisible_ = false; 1945 bool isCounterIdealheight_ = false; 1946 float maxFrameOffsetY_ = 0.0f; 1947 float maxFrameHeight_ = 0.0f; 1948 1949 CancelableCallback<void()> cursorTwinklingTask_; 1950 1951 std::list<std::unique_ptr<TextInputFormatter>> textInputFormatters_; 1952 1953 RefPtr<TextFieldController> textFieldController_; 1954 WeakPtr<Referenced> jsTextEditableController_; 1955 RefPtr<TextEditController> textEditingController_; 1956 TextEditingValueNG textEditingValue_; 1957 // controls redraw of overlay modifier, update when need to redraw 1958 bool changeSelectedRects_ = false; 1959 RefPtr<TextFieldOverlayModifier> textFieldOverlayModifier_; 1960 RefPtr<TextFieldContentModifier> textFieldContentModifier_; 1961 RefPtr<TextFieldForegroundModifier> textFieldForegroundModifier_; 1962 WeakPtr<TextFieldTheme> textFieldTheme_; 1963 ACE_DISALLOW_COPY_AND_MOVE(TextFieldPattern); 1964 1965 int32_t dragTextStart_ = 0; 1966 int32_t dragTextEnd_ = 0; 1967 std::u16string dragValue_; 1968 RefPtr<FrameNode> dragNode_; 1969 DragStatus dragStatus_ = DragStatus::NONE; // The status of the dragged initiator 1970 DragStatus dragRecipientStatus_ = DragStatus::NONE; // Drag the recipient's state 1971 RefPtr<Clipboard> clipboard_; 1972 std::vector<TextEditingValueNG> operationRecords_; 1973 std::vector<TextEditingValueNG> redoOperationRecords_; 1974 std::vector<NG::MenuOptionsParam> menuOptionItems_; 1975 BorderRadiusProperty borderRadius_; 1976 PasswordModeStyle passwordModeStyle_; 1977 SelectMenuInfo selectMenuInfo_; 1978 1979 RefPtr<PanEvent> boxSelectPanEvent_; 1980 1981 // inline 1982 bool isTextInput_ = false; 1983 bool inlineSelectAllFlag_ = false; 1984 bool inlineFocusState_ = false; 1985 float inlineSingleLineHeight_ = 0.0f; 1986 float inlinePadding_ = 0.0f; 1987 1988 bool isOritationListenerRegisted_ = false; 1989 1990 #if defined(ENABLE_STANDARD_INPUT) 1991 sptr<OHOS::MiscServices::OnTextChangedListener> textChangeListener_; 1992 #else 1993 RefPtr<TextInputConnection> connection_; 1994 #endif 1995 #if defined(OHOS_STANDARD_SYSTEM) && !defined(PREVIEW) 1996 bool imeAttached_ = false; 1997 bool imeShown_ = false; 1998 #endif 1999 bool isFocusedBeforeClick_ = false; 2000 bool isCustomKeyboardAttached_ = false; 2001 bool isCustomFont_ = false; 2002 BlurReason blurReason_ = BlurReason::FOCUS_SWITCH; 2003 std::function<void()> customKeyboardBuilder_; 2004 RefPtr<UINode> customKeyboard_; 2005 RefPtr<OverlayManager> keyboardOverlay_; 2006 TimeStamp lastClickTimeStamp_; 2007 float paragraphWidth_ = 0.0f; 2008 2009 std::queue<int32_t> deleteBackwardOperations_; 2010 std::queue<int32_t> deleteForwardOperations_; 2011 std::queue<InsertCommandInfo> insertCommands_; 2012 std::queue<InputCommandInfo> inputCommands_; 2013 std::queue<InputOperation> inputOperations_; 2014 bool leftMouseCanMove_ = false; 2015 bool isLongPress_ = false; 2016 bool isEdit_ = false; 2017 bool isSupportCameraInput_ = false; 2018 RefPtr<NG::UINode> unitNode_; 2019 RefPtr<TextInputResponseArea> responseArea_; 2020 RefPtr<TextInputResponseArea> cleanNodeResponseArea_; 2021 std::string lastAutoFillTextValue_; 2022 std::function<void()> processOverlayDelayTask_; 2023 FocuseIndex focusIndex_ = FocuseIndex::TEXT; 2024 TouchAndMoveCaretState moveCaretState_; 2025 FloatingCaretState floatCaretState_; 2026 bool needSelectAll_ = false; 2027 bool isModifyDone_ = false; 2028 bool initTextRect_ = false; 2029 bool isKeyboardClosedByUser_ = false; 2030 bool isFillRequestFinish_ = true; 2031 bool keyboardAvoidance_ = false; 2032 bool hasMousePressed_ = false; 2033 bool showCountBorderStyle_ = false; 2034 RefPtr<TextFieldSelectOverlay> selectOverlay_; 2035 OffsetF movingCaretOffset_; 2036 std::string autoFillUserName_; 2037 std::string autoFillNewPassword_; 2038 uint32_t autoFillSessionId_ = 0; 2039 std::unordered_map<std::string, std::variant<std::string, bool, int32_t>> fillContentMap_; 2040 bool autoFillOtherAccount_ = false; 2041 2042 bool textInputBlurOnSubmit_ = true; 2043 bool textAreaBlurOnSubmit_ = false; 2044 bool isDetachFromMainTree_ = false; 2045 2046 // 节点是否需要渐隐能力 2047 bool haveTextFadeoutCapacity_ = false; 2048 bool isFocusTextColorSet_ = false; 2049 bool isFocusBGColorSet_ = false; 2050 bool isFocusPlaceholderColorSet_ = false; 2051 bool hoverAndPressBgColorEnabled_ = false; 2052 std::function<void(bool)> isFocusActiveUpdateEvent_; 2053 2054 Dimension previewUnderlineWidth_ = 2.0_vp; 2055 bool hasSupportedPreviewText_ = true; 2056 bool hasPreviewText_ = false; 2057 std::queue<PreviewTextInfo> previewTextOperation_; 2058 int32_t previewTextStart_ = -1; 2059 int32_t previewTextEnd_ = -1; 2060 std::u16string bodyTextInPreivewing_; 2061 PreviewRange lastCursorRange_ = {}; 2062 std::u16string lastTextValue_ = u""; 2063 float lastCursorTop_ = 0.0f; 2064 bool showKeyBoardOnFocus_ = true; 2065 bool isTextSelectionMenuShow_ = true; 2066 bool isMoveCaretAnywhere_ = false; 2067 bool isTouchPreviewText_ = false; 2068 bool isPreviewTextOverCount_ = false; 2069 bool isCaretTwinkling_ = false; 2070 bool isPasswordSymbol_ = true; 2071 bool isEnableHapticFeedback_ = true; 2072 RefPtr<MultipleClickRecognizer> multipleClickRecognizer_ = MakeRefPtr<MultipleClickRecognizer>(); 2073 RefPtr<AIWriteAdapter> aiWriteAdapter_ = MakeRefPtr<AIWriteAdapter>(); 2074 std::optional<Dimension> adaptFontSize_; 2075 uint32_t longPressFingerNum_ = 0; 2076 ContentScroller contentScroller_; 2077 WeakPtr<FrameNode> firstAutoFillContainerNode_; 2078 std::optional<float> lastCaretPos_ = std::nullopt; 2079 bool firstClickAfterLosingFocus_ = true; 2080 CancelableCallback<void()> firstClickResetTask_; 2081 RequestFocusReason requestFocusReason_ = RequestFocusReason::UNKNOWN; 2082 bool directionKeysMoveFocusOut_ = false; 2083 KeyboardAppearance keyboardAppearance_ = KeyboardAppearance::NONE_IMMERSIVE; 2084 TextRange callbackRangeBefore_; 2085 TextRange callbackRangeAfter_; 2086 std::u16string callbackOldContent_; 2087 PreviewText callbackOldPreviewText_; 2088 bool isFilterChanged_ = false; 2089 std::optional<bool> showPasswordState_; 2090 bool cancelButtonTouched_ = false; 2091 }; 2092 } // namespace OHOS::Ace::NG 2093 2094 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_FIELD_TEXT_FIELD_PATTERN_H 2095