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