1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_RICH_EDITOR_RICH_EDITOR_PATTERN_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_RICH_EDITOR_RICH_EDITOR_PATTERN_H 18 19 #include <cstdint> 20 #include <map> 21 #include <optional> 22 #include <string> 23 24 #include "core/common/ai/ai_write_adapter.h" 25 #include "core/common/ime/text_edit_controller.h" 26 #include "core/common/ime/text_input_action.h" 27 #include "core/common/ime/text_input_client.h" 28 #include "core/common/ime/text_input_configuration.h" 29 #include "core/common/ime/text_input_connection.h" 30 #include "core/common/ime/text_input_formatter.h" 31 #include "core/common/ime/text_input_proxy.h" 32 #include "core/common/ime/text_input_type.h" 33 #include "core/common/ime/text_selection.h" 34 #include "core/components/common/properties/text_layout_info.h" 35 #include "core/components_ng/pattern/rich_editor/paragraph_manager.h" 36 #include "core/components_ng/pattern/rich_editor/rich_editor_accessibility_property.h" 37 #include "core/components_ng/pattern/rich_editor/rich_editor_content_modifier.h" 38 #include "core/components_ng/pattern/rich_editor/rich_editor_controller.h" 39 #include "core/components_ng/pattern/rich_editor/rich_editor_event_hub.h" 40 #include "core/components_ng/pattern/rich_editor/rich_editor_layout_algorithm.h" 41 #include "core/components_ng/pattern/rich_editor/rich_editor_layout_property.h" 42 #include "core/components_ng/pattern/rich_editor/rich_editor_overlay_modifier.h" 43 #include "core/components_ng/pattern/rich_editor/rich_editor_paint_method.h" 44 #include "core/components_ng/pattern/rich_editor/rich_editor_select_overlay.h" 45 #include "core/components_ng/pattern/rich_editor/rich_editor_styled_string_controller.h" 46 #include "core/components_ng/pattern/rich_editor/selection_info.h" 47 #include "core/components_ng/pattern/scrollable/scrollable_pattern.h" 48 #include "core/components_ng/pattern/select_overlay/magnifier.h" 49 #include "core/components_ng/pattern/select_overlay/magnifier_controller.h" 50 #include "core/components_ng/pattern/text/layout_info_interface.h" 51 #include "core/components_ng/pattern/text/span_node.h" 52 #include "core/components_ng/pattern/text/text_base.h" 53 #include "core/components_ng/pattern/text/text_pattern.h" 54 #include "core/components_ng/pattern/text_field/text_field_model.h" 55 #include "core/text/text_emoji_processor.h" 56 57 #ifndef ACE_UNITTEST 58 #ifdef ENABLE_STANDARD_INPUT 59 #include "commonlibrary/c_utils/base/include/refbase.h" 60 61 namespace OHOS::MiscServices { 62 class OnTextChangedListener; 63 struct TextConfig; 64 } // namespace OHOS::MiscServices 65 #endif 66 #endif 67 68 #define COPY_SPAN_STYLE_IF_PRESENT(sourceNode, targetNode, styleType, propertyInfo) \ 69 do { \ 70 if ((sourceNode)->Has##styleType()) { \ 71 (targetNode)->Update##styleType(*((sourceNode)->Get##styleType())); \ 72 (targetNode)->AddPropertyInfo(propertyInfo); \ 73 } \ 74 } while (false) 75 #define CONTENT_MODIFY_LOCK(patternPtr) ContentModifyLock contentModifyLock(patternPtr) 76 77 #define IF_TRUE(cond, func) \ 78 do { \ 79 if (cond) { \ 80 func; \ 81 } \ 82 } while (false) 83 84 #define IF_PRESENT(opt, func) \ 85 do { \ 86 if (opt) { \ 87 (opt)->func; \ 88 } \ 89 } while (false) 90 91 namespace OHOS::Ace::NG { 92 class InspectorFilter; 93 class OneStepDragController; 94 95 // TextPattern is the base class for text render node to perform paint text. 96 enum class MoveDirection { FORWARD, BACKWARD }; 97 98 enum class AutoScrollEvent { HANDLE, DRAG, MOUSE, NONE }; 99 enum class EdgeDetectionStrategy { OUT_BOUNDARY, IN_BOUNDARY, DISABLE }; 100 struct AutoScrollParam { 101 AutoScrollEvent autoScrollEvent = AutoScrollEvent::NONE; 102 RectF handleRect; 103 bool isFirstHandle = false; 104 float offset = 0.0f; 105 bool showScrollbar = false; 106 Offset eventOffset; 107 bool isFirstRun_ = true; 108 }; 109 enum class RecordType { DEL_FORWARD = 0, DEL_BACKWARD = 1, INSERT = 2, UNDO = 3, REDO = 4, DRAG = 5 }; 110 enum class SelectorAdjustPolicy { INCLUDE = 0, EXCLUDE }; 111 enum class HandleType { FIRST = 0, SECOND }; 112 enum class SelectType { SELECT_FORWARD = 0, SELECT_BACKWARD, SELECT_NOTHING }; 113 enum class CaretAffinityPolicy { DEFAULT = 0, UPSTREAM_FIRST, DOWNSTREAM_FIRST }; 114 enum class OperationType { DEFAULT = 0, DRAG, IME }; 115 const std::map<std::pair<HandleType, SelectorAdjustPolicy>, MoveDirection> SELECTOR_ADJUST_DIR_MAP = { 116 {{ HandleType::FIRST, SelectorAdjustPolicy::INCLUDE }, MoveDirection::BACKWARD }, 117 {{ HandleType::FIRST, SelectorAdjustPolicy::EXCLUDE }, MoveDirection::FORWARD }, 118 {{ HandleType::SECOND, SelectorAdjustPolicy::INCLUDE }, MoveDirection::FORWARD }, 119 {{ HandleType::SECOND, SelectorAdjustPolicy::EXCLUDE }, MoveDirection::BACKWARD } 120 }; 121 struct CaretOffsetInfo { 122 // caret front offset info 123 OffsetF caretOffsetUp; 124 // caret end offset info 125 OffsetF caretOffsetDown; 126 // caret position offset info 127 OffsetF caretOffsetLine; 128 float caretHeightUp = 0.0f; 129 float caretHeightDown = 0.0f; 130 float caretHeightLine = 0.0f; 131 }; 132 enum class PositionType { DEFAULT, PARAGRAPH_START, PARAGRAPH_END, LINE_START, LINE_END }; 133 134 135 class RichEditorPattern 136 : public TextPattern, public ScrollablePattern, public TextInputClient, public SpanWatcher { 137 DECLARE_ACE_TYPE(RichEditorPattern, TextPattern, ScrollablePattern, TextInputClient, SpanWatcher); 138 139 public: 140 RichEditorPattern(); 141 ~RichEditorPattern() override; 142 143 struct OperationRecord { OperationRecordOperationRecord144 OperationRecord() : beforeCaretPosition(-1), afterCaretPosition(-1), deleteCaretPostion(-1) {} 145 std::optional<std::string> addText; 146 std::optional<std::string> deleteText; 147 int32_t beforeCaretPosition; 148 int32_t afterCaretPosition; 149 int32_t deleteCaretPostion; 150 }; 151 152 struct PreviewTextRecord { 153 int32_t startOffset = INVALID_VALUE; 154 int32_t endOffset = INVALID_VALUE; 155 bool isPreviewTextInputting = false; 156 std::string previewContent; 157 std::string newPreviewContent; 158 bool hasDiff = false; 159 PreviewRange replacedRange; 160 ToStringPreviewTextRecord161 std::string ToString() const 162 { 163 auto jsonValue = JsonUtil::Create(true); 164 JSON_STRING_PUT_STRING(jsonValue, previewContent); 165 JSON_STRING_PUT_BOOL(jsonValue, isPreviewTextInputting); 166 JSON_STRING_PUT_INT(jsonValue, startOffset); 167 JSON_STRING_PUT_INT(jsonValue, endOffset); 168 169 return jsonValue->ToString(); 170 } 171 ResetPreviewTextRecord172 void Reset() 173 { 174 startOffset = INVALID_VALUE; 175 endOffset = INVALID_VALUE; 176 previewContent.clear(); 177 isPreviewTextInputting = false; 178 hasDiff = false; 179 replacedRange.Set(INVALID_VALUE, INVALID_VALUE); 180 } 181 IsValidPreviewTextRecord182 bool IsValid() const 183 { 184 return !previewContent.empty() && isPreviewTextInputting && startOffset >= 0 && endOffset >= startOffset; 185 } 186 }; 187 188 struct TouchAndMoveCaretState { 189 bool isTouchCaret = false; 190 bool isMoveCaret = false; 191 Offset touchDownOffset; 192 const Dimension minDistance = 5.0_vp; 193 ResetTouchAndMoveCaretState194 void Reset() 195 { 196 isTouchCaret = false; 197 isMoveCaret = false; 198 touchDownOffset.Reset(); 199 } 200 }; 201 202 class ContentModifyLock { 203 public: 204 ContentModifyLock(); ContentModifyLock(RichEditorPattern * pattern)205 ContentModifyLock(RichEditorPattern* pattern) 206 { 207 pattern->isModifyingContent_ = true; 208 pattern_ = WeakClaim(pattern); 209 } ~ContentModifyLock()210 ~ContentModifyLock() 211 { 212 auto pattern = pattern_.Upgrade(); 213 if (!pattern) { 214 TAG_LOGE(AceLogTag::ACE_RICH_TEXT, "pattern is null, unlock failed"); 215 return; 216 } 217 pattern->isModifyingContent_ = false; 218 auto host = pattern->GetHost(); 219 CHECK_NULL_VOID(host); 220 host->MarkDirtyNode(PROPERTY_UPDATE_MEASURE); 221 } 222 private: 223 WeakPtr<RichEditorPattern> pattern_; 224 }; 225 226 int32_t SetPreviewText(const std::string& previewTextValue, const PreviewRange range) override; 227 228 bool InitPreviewText(const std::string& previewTextValue, const PreviewRange range); 229 230 bool ReplacePreviewText(const std::string& previewTextValue, const PreviewRange& range); 231 232 bool UpdatePreviewText(const std::string& previewTextValue, const PreviewRange range); 233 234 const PreviewTextInfo GetPreviewTextInfo() const; 235 236 void FinishTextPreview() override; 237 ReceivePreviewTextStyle(const std::string & style)238 void ReceivePreviewTextStyle(const std::string& style) override 239 { 240 ACE_UPDATE_LAYOUT_PROPERTY(RichEditorLayoutProperty, PreviewTextStyle, style); 241 } 242 243 const Color& GetPreviewTextDecorationColor() const; 244 IsPreviewTextInputting()245 bool IsPreviewTextInputting() 246 { 247 return previewTextRecord_.IsValid(); 248 } 249 250 std::vector<RectF> GetPreviewTextRects(); 251 252 float GetPreviewTextUnderlineWidth() const; 253 254 PreviewTextStyle GetPreviewTextStyle() const; 255 SetSupportPreviewText(bool isTextPreviewSupported)256 void SetSupportPreviewText(bool isTextPreviewSupported) 257 { 258 isTextPreviewSupported_ = isTextPreviewSupported; 259 } 260 261 ACE_DEFINE_PROPERTY_ITEM_FUNC_WITHOUT_GROUP(TextInputAction, TextInputAction) 262 TextInputAction GetDefaultTextInputAction() const; 263 CreateEventHub()264 RefPtr<EventHub> CreateEventHub() override 265 { 266 return MakeRefPtr<RichEditorEventHub>(); 267 } 268 CreateLayoutProperty()269 RefPtr<LayoutProperty> CreateLayoutProperty() override 270 { 271 return MakeRefPtr<RichEditorLayoutProperty>(); 272 } 273 CreateLayoutAlgorithm()274 RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override 275 { 276 return MakeRefPtr<RichEditorLayoutAlgorithm>(spans_, ¶graphs_, typingTextStyle_); 277 } 278 GetFocusPattern()279 FocusPattern GetFocusPattern() const override 280 { 281 FocusPattern focusPattern = { FocusType::NODE, true, FocusStyleType::INNER_BORDER }; 282 focusPattern.SetIsFocusActiveWhenFocused(true); 283 return focusPattern; 284 } 285 286 RefPtr<NodePaintMethod> CreateNodePaintMethod() override; 287 GetRichEditorController()288 const RefPtr<RichEditorController>& GetRichEditorController() 289 { 290 return richEditorController_; 291 } 292 SetRichEditorController(const RefPtr<RichEditorController> & controller)293 void SetRichEditorController(const RefPtr<RichEditorController>& controller) 294 { 295 richEditorController_ = controller; 296 } 297 GetRichEditorStyledStringController()298 const RefPtr<RichEditorStyledStringController>& GetRichEditorStyledStringController() 299 { 300 return richEditorStyledStringController_; 301 } 302 SetRichEditorStyledStringController(const RefPtr<RichEditorStyledStringController> & controller)303 void SetRichEditorStyledStringController(const RefPtr<RichEditorStyledStringController>& controller) 304 { 305 richEditorStyledStringController_ = controller; 306 } 307 GetTimestamp()308 long long GetTimestamp() const 309 { 310 return timestamp_; 311 } 312 313 // RichEditor needs softkeyboard, override function. NeedSoftKeyboard()314 bool NeedSoftKeyboard() const override 315 { 316 return true; 317 } 318 UpdateSpanPosition()319 void UpdateSpanPosition() 320 { 321 uint32_t spanTextLength = 0; 322 for (auto& span : spans_) { 323 span->rangeStart = static_cast<int32_t>(spanTextLength); 324 spanTextLength += StringUtils::ToWstring(span->content).length(); 325 span->position = static_cast<int32_t>(spanTextLength); 326 } 327 } 328 329 BlurReason GetBlurReason(); 330 331 uint32_t GetSCBSystemWindowId(); 332 OnAttachToMainTree()333 void OnAttachToMainTree() override 334 { 335 TextPattern::OnAttachToMainTree(); 336 } 337 void RegisiterCaretChangeListener(std::function<void(int32_t)>&& listener); 338 void SetStyledString(const RefPtr<SpanString>& value); 339 GetStyledString()340 RefPtr<MutableSpanString> GetStyledString() const 341 { 342 return styledString_; 343 } 344 345 void UpdateSpanItems(const std::list<RefPtr<NG::SpanItem>>& spanItems) override; 346 void ProcessStyledString(); 347 void MountImageNode(const RefPtr<ImageSpanItem>& imageItem); 348 void SetImageLayoutProperty(RefPtr<ImageSpanNode> imageNode, const ImageSpanOptions& options); 349 void InsertValueInStyledString(const std::string& insertValue); 350 RefPtr<SpanString> CreateStyledStringByTextStyle( 351 const std::string& insertValue, const struct UpdateSpanStyle& updateSpanStyle, const TextStyle& textStyle); 352 RefPtr<FontSpan> CreateFontSpanByTextStyle( 353 const struct UpdateSpanStyle& updateSpanStyle, const TextStyle& textStyle, int32_t length); 354 RefPtr<DecorationSpan> CreateDecorationSpanByTextStyle( 355 const struct UpdateSpanStyle& updateSpanStyle, const TextStyle& textStyle, int32_t length); 356 void DeleteBackwardInStyledString(int32_t length); 357 void DeleteForwardInStyledString(int32_t length, bool isIME = true); 358 void DeleteValueInStyledString(int32_t start, int32_t length, bool isIME = true, bool isUpdateCaret = true); 359 360 bool BeforeStyledStringChange(int32_t start, int32_t length, const std::string& string); 361 bool BeforeStyledStringChange(int32_t start, int32_t length, const RefPtr<SpanString>& styledString); 362 void AfterStyledStringChange(int32_t start, int32_t length, const std::string& string); 363 void ResetBeforePaste(); 364 void ResetAfterPaste(); 365 366 void OnVisibleChange(bool isVisible) override; 367 void OnModifyDone() override; 368 void BeforeCreateLayoutWrapper() override; 369 bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override; 370 void HandleSelectOverlayOnLayoutSwap(); 371 void FireOnReady(); 372 void SupplementIdealSizeWidth(const RefPtr<FrameNode>& frameNode); 373 void MoveCaretOnLayoutSwap(); 374 375 void UpdateEditingValue(const std::shared_ptr<TextEditingValue>& value, bool needFireChangeEvent = true) override; 376 void PerformAction(TextInputAction action, bool forceCloseKeyboard = true) override; 377 bool IsIMEOperation(OperationType operationType); 378 void InsertValue(const std::string& insertValue, bool isIME = false) override; 379 void InsertValueByOperationType(const std::string& insertValue, 380 OperationType operationType = OperationType::DEFAULT); 381 void InsertValueOperation(const std::string& insertValue, OperationRecord* const record = nullptr, 382 OperationType operationType = OperationType::IME); 383 void DeleteSelectOperation(OperationRecord* const record); 384 void DeleteByRange(OperationRecord* const record, int32_t start, int32_t end); 385 void InsertDiffStyleValueInSpan( 386 RefPtr<SpanNode>& spanNode, const TextInsertValueInfo& info, const std::string& insertValue, bool isIME = true); 387 void InsertValueByPaste(const std::string& insertValue); 388 bool IsLineSeparatorInLast(RefPtr<SpanNode>& spanNode); 389 void InsertValueToSpanNode( 390 RefPtr<SpanNode>& spanNode, const std::string& insertValue, const TextInsertValueInfo& info); 391 void SpanNodeFission(RefPtr<SpanNode>& spanNode); 392 void CreateTextSpanNode( 393 RefPtr<SpanNode>& spanNode, const TextInsertValueInfo& info, const std::string& insertValue, bool isIME = true); 394 void SetDefaultColor(RefPtr<SpanNode>& spanNode); 395 void HandleOnDelete(bool backward) override; 396 std::pair<bool, bool> IsEmojiOnCaretPosition(int32_t& emojiLength, bool isBackward, int32_t length); 397 int32_t CalculateDeleteLength(int32_t length, bool isBackward); 398 void DeleteBackward(int32_t length = 1) override; 399 std::wstring DeleteBackwardOperation(int32_t length); 400 void DeleteForward(int32_t length = 1) override; 401 int32_t HandleOnDragDeleteForward(); 402 std::wstring DeleteForwardOperation(int32_t length); 403 void SetInputMethodStatus(bool keyboardShown) override; 404 bool ClickAISpan(const PointF& textOffset, const AISpan& aiSpan) override; 405 WindowMode GetWindowMode(); NotifyKeyboardClosedByUser()406 void NotifyKeyboardClosedByUser() override 407 { 408 TAG_LOGI(AceLogTag::ACE_RICH_TEXT, "KeyboardClosedByUser"); 409 FocusHub::LostFocusToViewRoot(); 410 } NotifyKeyboardClosed()411 void NotifyKeyboardClosed() override 412 { 413 TAG_LOGI(AceLogTag::ACE_RICH_TEXT, "KeyboardClosed"); 414 CHECK_NULL_VOID(HasFocus()); 415 416 // lost focus in floating window mode 417 auto windowMode = GetWindowMode(); 418 TAG_LOGD(AceLogTag::ACE_RICH_TEXT, "KeyboardClosed windowMode = %{public}d", windowMode); 419 if (windowMode == WindowMode::WINDOW_MODE_FLOATING || windowMode == WindowMode::WINDOW_MODE_SPLIT_PRIMARY || 420 windowMode == WindowMode::WINDOW_MODE_SPLIT_SECONDARY) { 421 FocusHub::LostFocusToViewRoot(); 422 } 423 } 424 void ClearOperationRecords(); 425 void ClearRedoOperationRecords(); 426 void AddOperationRecord(const OperationRecord& record); 427 void UpdateShiftFlag(const KeyEvent& keyEvent) override; 428 bool HandleOnEscape() override; 429 void HandleOnUndoAction() override; 430 void HandleOnRedoAction() override; 431 void CursorMove(CaretMoveIntent direction) override; 432 bool BeforeStatusCursorMove(bool isLeft); 433 bool CursorMoveLeft(); 434 bool CursorMoveRight(); 435 bool CursorMoveUp(); 436 bool CursorMoveDown(); 437 void CursorMoveToNextWord(CaretMoveIntent direction); 438 int32_t GetLeftWordIndex(); 439 int32_t GetRightWordIndex(); 440 bool CursorMoveToParagraphBegin(); 441 bool CursorMoveToParagraphEnd(); 442 bool CursorMoveHome(); 443 bool CursorMoveEnd(); 444 void CalcLineSidesIndexByPosition(int32_t& startIndex, int32_t& endIndex); 445 RectF CalcLineInfoByPosition(); 446 CaretOffsetInfo GetCaretOffsetInfoByPosition(int32_t position = -1); 447 int32_t CalcMoveUpPos(float& leadingMarginOffset); 448 int32_t CalcMoveDownPos(float& leadingMarginOffset); 449 int32_t CalcLineBeginPosition(); 450 float GetTextThemeFontSize(); 451 int32_t CalcLineEndPosition(int32_t index = -1); 452 bool CursorMoveLineBegin(); 453 bool CursorMoveLineEnd(); 454 void HandleSelectFontStyle(KeyCode code) override; 455 void HandleSelectFontStyleWrapper(KeyCode code, TextStyle& spanStyle); 456 void HandleOnShowMenu() override; 457 int32_t HandleSelectPosition(bool isForward); 458 int32_t HandleSelectParagraghPos(bool direction); 459 PositionType GetPositionTypeFromLine(); 460 int32_t HandleSelectWrapper(CaretMoveIntent direction, int32_t fixedPos); 461 void AIDeleteComb(int32_t start, int32_t end, int32_t& aiPosition, bool direction); 462 bool HandleOnDeleteComb(bool backward) override; 463 void DeleteBackwardWord(); 464 void DeleteForwardWord(); 465 int32_t GetLeftWordPosition(int32_t caretPosition); 466 int32_t GetRightWordPosition(int32_t caretPosition); 467 int32_t GetParagraphBeginPosition(int32_t caretPosition); 468 int32_t GetParagraphEndPosition(int32_t caretPosition); 469 int32_t CaretPositionSelectEmoji(CaretMoveIntent direction); 470 void HandleSelect(CaretMoveIntent direction) override; 471 void SetCaretPositionWithAffinity(PositionWithAffinity positionWithAffinity); 472 bool SetCaretPosition(int32_t pos, bool needNotifyImf = true); 473 int32_t GetCaretPosition(); 474 int32_t GetTextContentLength() override; 475 bool GetCaretVisible() const; 476 OffsetF CalcCursorOffsetByPosition( 477 int32_t position, float& selectLineHeight, bool downStreamFirst = false, bool needLineHighest = true); 478 bool IsCustomSpanInCaretPos(int32_t position, bool downStreamFirst); 479 void CopyTextSpanStyle(RefPtr<SpanNode>& source, RefPtr<SpanNode>& target, bool needLeadingMargin = false); 480 void CopyTextSpanFontStyle(RefPtr<SpanNode>& source, RefPtr<SpanNode>& target); 481 void CopyTextSpanLineStyle(RefPtr<SpanNode>& source, RefPtr<SpanNode>& target, bool needLeadingMargin = false); 482 void CopyGestureOption(const RefPtr<SpanNode>& source, RefPtr<SpanNode>& target); 483 int32_t TextSpanSplit(int32_t position, bool needLeadingMargin = false); 484 SpanPositionInfo GetSpanPositionInfo(int32_t position); 485 std::function<ImageSourceInfo()> CreateImageSourceInfo(const ImageSpanOptions& options); 486 void DeleteSpans(const RangeOptions& options); 487 void DeleteSpansOperation(int32_t start, int32_t end); 488 void DeleteSpanByRange(int32_t start, int32_t end, SpanPositionInfo info); 489 void DeleteSpansByRange(int32_t start, int32_t end, SpanPositionInfo startInfo, SpanPositionInfo endInfo); 490 void ClearContent(const RefPtr<UINode>& child); 491 void CloseSelectionMenu(); 492 bool SetCaretOffset(int32_t caretPosition) override; 493 void ResetFirstNodeStyle(); 494 bool DoDeleteActions(int32_t currentPosition, int32_t length, RichEditorDeleteValue& info); 495 496 void UpdateSpanStyle(int32_t start, int32_t end, const TextStyle& textStyle, const ImageSpanAttribute& imageStyle); 497 std::string GetContentBySpans(); 498 ResultObject TextEmojiSplit(int32_t& start, int32_t end, std::string& content); 499 SelectionInfo GetEmojisBySelect(int32_t start, int32_t end); 500 void MixTextEmojiUpdateStyle(int32_t start, int32_t end, TextStyle textStyle, ImageSpanAttribute imageStyle); 501 void SetSelectSpanStyle(int32_t start, int32_t end, KeyCode code, bool isStart); 502 void GetSelectSpansPositionInfo( 503 int32_t& start, int32_t& end, SpanPositionInfo& startPositionSpanInfo, SpanPositionInfo& endPositionSpanInfo); 504 std::list<RefPtr<UINode>>::const_iterator GetSpanNodeIter(int32_t index); 505 std::list<SpanPosition> GetSelectSpanSplit( 506 SpanPositionInfo& startPositionSpanInfo, SpanPositionInfo& endPositionSpanInfo); 507 std::list<SpanPosition> GetSelectSpanInfo(int32_t start, int32_t end); 508 bool IsTextSpanFromResult(int32_t& start, int32_t& end, KeyCode code); 509 void UpdateSelectSpanStyle(int32_t start, int32_t end, KeyCode code); 510 bool SymbolSpanUpdateStyle(RefPtr<SpanNode>& spanNode, struct UpdateSpanStyle updateSpanStyle, TextStyle textStyle); 511 void SetUpdateSpanStyle(struct UpdateSpanStyle updateSpanStyle); 512 struct UpdateSpanStyle GetUpdateSpanStyle(); 513 void UpdateParagraphStyle(int32_t start, int32_t end, const struct UpdateParagraphStyle& style); 514 void UpdateParagraphStyle(RefPtr<SpanNode> spanNode, const struct UpdateParagraphStyle& style); 515 std::vector<ParagraphInfo> GetParagraphInfo(int32_t start, int32_t end); 516 void SetTypingStyle(std::optional<struct UpdateSpanStyle> typingStyle, std::optional<TextStyle> textStyle); 517 std::optional<struct UpdateSpanStyle> GetTypingStyle(); 518 int32_t AddImageSpan(const ImageSpanOptions& options, bool isPaste = false, int32_t index = -1, 519 bool updateCaret = true); 520 int32_t AddTextSpan(TextSpanOptions options, bool isPaste = false, int32_t index = -1); 521 int32_t AddTextSpanOperation(const TextSpanOptions& options, bool isPaste = false, int32_t index = -1, 522 bool needLeadingMargin = false, bool updateCaretPosition = true); 523 int32_t AddSymbolSpan(const SymbolSpanOptions& options, bool isPaste = false, int32_t index = -1); 524 int32_t AddSymbolSpanOperation(const SymbolSpanOptions& options, bool isPaste = false, int32_t index = -1); 525 void AddSpanItem(const RefPtr<SpanItem>& item, int32_t offset); 526 int32_t AddPlaceholderSpan(const RefPtr<UINode>& customNode, const SpanOptionBase& options); 527 void HandleSelectOverlayWithOptions(const SelectionOptions& options); 528 void SetSelection(int32_t start, int32_t end, const std::optional<SelectionOptions>& options = std::nullopt, 529 bool isForward = false) override; 530 bool ResetOnInvalidSelection(int32_t start, int32_t end); 531 void RefreshSelectOverlay(bool isMousePressed, bool selectedTypeChange); 532 bool IsShowHandle(); 533 void UpdateSelectionInfo(int32_t start, int32_t end); 534 bool IsEditing(); 535 std::u16string GetLeftTextOfCursor(int32_t number) override; 536 std::u16string GetRightTextOfCursor(int32_t number) override; 537 int32_t GetTextIndexAtCursor() override; 538 void ShowSelectOverlay(const RectF& firstHandle, const RectF& secondHandle, bool isCopyAll = false, 539 TextResponseType responseType = TextResponseType::LONG_PRESS, bool handlReverse = false); 540 void CheckEditorTypeChange(); 541 int32_t GetHandleIndex(const Offset& offset) const override; 542 void OnAreaChangedInner() override; 543 void CreateHandles() override; 544 void ShowHandles(const bool isNeedShowHandles) override; 545 void ShowHandles() override; 546 void HandleMenuCallbackOnSelectAll(); 547 void HandleOnSelectAll() override; 548 void OnCopyOperation(bool isUsingExternalKeyboard = false); 549 void HandleOnCopy(bool isUsingExternalKeyboard = false) override; 550 void HandleDraggableFlag(bool isTouchSelectArea); 551 void SetIsTextDraggable(bool isTextDraggable = true) override; 552 bool JudgeContentDraggable(); 553 std::pair<OffsetF, float> CalculateCaretOffsetAndHeight(); 554 std::pair<OffsetF, float> CalculateEmptyValueCaretRect(); 555 void UpdateModifierCaretOffsetAndHeight(); 556 void NotifyCaretChange(); 557 TextAlign GetTextAlignByDirection(); 558 void RemoveEmptySpan(std::set<int32_t, std::greater<int32_t>>& deleteSpanIndexs); 559 void RemoveEmptySpanItems(); 560 void RemoveEmptySpanNodes(); 561 void RemoveEmptySpans(); 562 RefPtr<GestureEventHub> GetGestureEventHub(); 563 float GetSelectedMaxWidth(); 564 void OnWindowHide() override; 565 bool BeforeAddImage(RichEditorChangeValue& changeValue, const ImageSpanOptions& options, int32_t insertIndex); 566 RefPtr<SpanString> ToStyledString(int32_t start, int32_t end); 567 SelectionInfo FromStyledString(const RefPtr<SpanString>& spanString); 568 bool BeforeAddSymbol(RichEditorChangeValue& changeValue, const SymbolSpanOptions& options); 569 void AfterContentChange(RichEditorChangeValue& changeValue); 570 IsUsingMouse()571 bool IsUsingMouse() const 572 { 573 return isMousePressed_; 574 } 575 ResetIsMousePressed()576 void ResetIsMousePressed() 577 { 578 isMousePressed_ = false; 579 } 580 GetSelectionMenuOffset()581 OffsetF GetSelectionMenuOffset() const 582 { 583 return selectionMenuOffsetByMouse_; 584 } 585 SetLastClickOffset(const OffsetF & lastClickOffset)586 void SetLastClickOffset(const OffsetF& lastClickOffset) 587 { 588 lastClickOffset_ = lastClickOffset; 589 } 590 ResetLastClickOffset()591 void ResetLastClickOffset() 592 { 593 lastClickOffset_.SetX(-1); 594 lastClickOffset_.SetY(-1); 595 } 596 GetCaretSpanIndex()597 int32_t GetCaretSpanIndex() 598 { 599 return caretSpanIndex_; 600 } 601 GetParagraphs()602 std::list<ParagraphManager::ParagraphInfo> GetParagraphs() const override 603 { 604 return paragraphs_.GetParagraphs(); 605 } 606 GetFirstHandleInfo()607 std::optional<SelectHandleInfo> GetFirstHandleInfo() const 608 { 609 return selectOverlay_->GetFirstHandleInfo(); 610 } 611 GetSecondHandleInfo()612 std::optional<SelectHandleInfo> GetSecondHandleInfo() const 613 { 614 return selectOverlay_->GetSecondHandleInfo(); 615 } 616 617 RectF GetCaretRect() const override; 618 void CloseSelectOverlay() override; 619 void CloseHandleAndSelect() override; 620 void CalculateHandleOffsetAndShowOverlay(bool isUsingMouse = false); 621 void CalculateDefaultHandleHeight(float& height) override; 622 bool IsSingleHandle(); 623 bool IsHandlesShow() override; 624 void CopySelectionMenuParams(SelectOverlayInfo& selectInfo, TextResponseType responseType); 625 std::function<void(Offset)> GetThumbnailCallback() override; 626 void HandleOnDragStatusCallback( 627 const DragEventType& dragEventType, const RefPtr<NotifyDragEvent>& notifyDragEvent) override; 628 void ResetSelection(); 629 bool BetweenSelection(const Offset& globalOffset); 630 bool BetweenSelectedPosition(const Offset& globalOffset) override; 631 void HandleSurfaceChanged(int32_t newWidth, int32_t newHeight, int32_t prevWidth, int32_t prevHeight) override; 632 void HandleSurfacePositionChanged(int32_t posX, int32_t posY) override; 633 bool RequestCustomKeyboard(); 634 bool CloseCustomKeyboard(); GetPasteStr()635 const std::string& GetPasteStr() const 636 { 637 return pasteStr_; 638 } AddPasteStr(const std::string & addedStr)639 void AddPasteStr(const std::string& addedStr) 640 { 641 pasteStr_.append(addedStr); 642 } ClearPasteStr()643 void ClearPasteStr() 644 { 645 pasteStr_.clear(); 646 } SetCustomKeyboard(const std::function<void ()> && keyboardBuilder)647 void SetCustomKeyboard(const std::function<void()>&& keyboardBuilder) 648 { 649 if (customKeyboardBuilder_ && isCustomKeyboardAttached_ && !keyboardBuilder) { 650 // close customKeyboard and request system keyboard 651 CloseCustomKeyboard(); 652 customKeyboardBuilder_ = keyboardBuilder; // refresh current keyboard 653 RequestKeyboard(false, true, true); 654 return; 655 } 656 if (!customKeyboardBuilder_ && keyboardBuilder) { 657 // close system keyboard and request custom keyboard 658 #if defined(OHOS_STANDARD_SYSTEM) && !defined(PREVIEW) 659 if (imeShown_) { 660 CloseKeyboard(true); 661 customKeyboardBuilder_ = keyboardBuilder; // refresh current keyboard 662 RequestKeyboard(false, true, true); 663 return; 664 } 665 #endif 666 } 667 customKeyboardBuilder_ = keyboardBuilder; 668 } 669 void BindSelectionMenu(TextResponseType type, TextSpanType richEditorType, std::function<void()>& menuBuilder, 670 const SelectMenuParam& menuParam); ClearSelectionMenu()671 void ClearSelectionMenu() 672 { 673 selectionMenuMap_.clear(); 674 } 675 void DumpInfo() override; 676 void MouseDoubleClickParagraphEnd(int32_t& index); 677 void AdjustSelectionExcludeSymbol(int32_t& start, int32_t& end); 678 void InitSelection(const Offset& pos); 679 bool HasFocus() const; 680 void OnColorConfigurationUpdate() override; 681 bool IsDisabled() const; 682 float GetLineHeight() const override; 683 size_t GetLineCount() const override; 684 std::vector<ParagraphManager::TextBox> GetRectsForRange(int32_t start, int32_t end, 685 RectHeightStyle heightStyle, RectWidthStyle widthStyle) override; 686 TextLineMetrics GetLineMetrics(int32_t lineNumber) override; 687 float GetLetterSpacing() const; 688 std::vector<RectF> GetTextBoxes() override; 689 bool OnBackPressed() override; 690 bool IsShowSelectMenuUsingMouse(); 691 692 // Add for Scroll 693 694 void OnAttachToFrameNode() override; 695 696 void OnDetachFromFrameNode(FrameNode* node) override; 697 IsAtBottom()698 bool IsAtBottom() const override 699 { 700 return true; 701 } 702 IsAtTop()703 bool IsAtTop() const override 704 { 705 return true; 706 } 707 UpdateCurrentOffset(float offset,int32_t source)708 bool UpdateCurrentOffset(float offset, int32_t source) override 709 { 710 return true; 711 } 712 GetTextRect()713 const RectF& GetTextRect() override 714 { 715 return richTextRect_; 716 } 717 GetScrollOffset()718 float GetScrollOffset() const 719 { 720 return scrollOffset_; 721 } 722 GetScrollControllerBar()723 RefPtr<ScrollBar> GetScrollControllerBar() 724 { 725 return GetScrollBar(); 726 } 727 728 bool OnScrollCallback(float offset, int32_t source) override; 729 void OnScrollEndCallback() override; IsScrollable()730 bool IsScrollable() const override 731 { 732 return scrollable_; 733 } 734 IsAtomicNode()735 bool IsAtomicNode() const override 736 { 737 return true; 738 } 739 GetClientHost()740 RefPtr<FrameNode> GetClientHost() const override 741 { 742 return GetHost(); 743 } 744 745 bool IsSelectAreaVisible(); 746 747 void ResetDragOption() override; 748 bool NeedShowAIDetect() override; 749 GetEditorType()750 TextSpanType GetEditorType() const 751 { 752 return selectedType_.value_or(TextSpanType::NONE); 753 } 754 755 std::string GetPlaceHolder() const; 756 757 void HandleOnCameraInput() override; 758 void HandleOnAIWrite(); 759 void GetAIWriteInfo(AIWriteInfo& info); 760 void HandleAIWriteResult(int32_t start, int32_t end, std::vector<uint8_t>& buffer); 761 void InsertSpanByBackData(RefPtr<SpanString>& spanString); 762 void AddSpansAndReplacePlaceholder(RefPtr<SpanString>& spanString); 763 void ReplacePlaceholderWithRawSpans(const RefPtr<SpanItem>& spanItem, size_t& index, size_t& textIndex); 764 void SetSubSpansWithAIWrite(RefPtr<SpanString>& spanString, int32_t start, int32_t end); 765 SymbolSpanOptions GetSymbolSpanOptions(const RefPtr<SpanItem>& spanItem); 766 bool IsShowTranslate(); 767 bool IsShowAIWrite(); 768 RefPtr<FocusHub> GetFocusHub() const; 769 SetShowSelect(bool isShowSelect)770 void SetShowSelect(bool isShowSelect) 771 { 772 showSelect_ = isShowSelect; 773 } 774 void GetCaretMetrics(CaretMetricsF& caretCaretMetric) override; 775 776 const std::list<RefPtr<UINode>>& GetAllChildren() const override; 777 778 void OnVirtualKeyboardAreaChanged() override; 779 IsShowPlaceholder()780 bool IsShowPlaceholder() const 781 { 782 return isShowPlaceholder_; 783 } 784 785 bool SetPlaceholder(std::vector<std::list<RefPtr<SpanItem>>>& spanItemList); 786 SetCaretColor(const Color & caretColor)787 void SetCaretColor(const Color& caretColor) 788 { 789 caretColor_ = caretColor; 790 IF_TRUE(SelectOverlayIsOn(), selectOverlay_->UpdateHandleColor()); 791 } 792 793 Color GetCaretColor(); 794 SetSelectedBackgroundColor(const Color & selectedBackgroundColor)795 void SetSelectedBackgroundColor(const Color& selectedBackgroundColor) 796 { 797 selectedBackgroundColor_ = selectedBackgroundColor; 798 } 799 800 Color GetSelectedBackgroundColor(); 801 802 void SetCustomKeyboardOption(bool supportAvoidance); 803 804 void StopEditing(); 805 void ResetKeyboardIfNeed(); 806 HandleOnEnter()807 void HandleOnEnter() override 808 { 809 PerformAction(GetTextInputActionValue(GetDefaultTextInputAction()), false); 810 } 811 GetCaretIndex()812 int32_t GetCaretIndex() const override 813 { 814 return caretPosition_; 815 } 816 GetContentWideTextLength()817 int32_t GetContentWideTextLength() override 818 { 819 return GetTextContentLength(); 820 } 821 GetCaretOffset()822 OffsetF GetCaretOffset() const override 823 { 824 // only used in magnifier, return position of the handle that is currently moving 825 return movingHandleOffset_; 826 } 827 SetMovingHandleOffset(const OffsetF & handleOffset)828 void SetMovingHandleOffset(const OffsetF& handleOffset) 829 { 830 movingHandleOffset_ = handleOffset; 831 } 832 GetParentGlobalOffset()833 OffsetF GetParentGlobalOffset() const override 834 { 835 return parentGlobalOffset_; 836 } 837 GetFirstHandleOffset()838 OffsetF GetFirstHandleOffset() const override 839 { 840 return textSelector_.firstHandle.GetOffset(); 841 } 842 GetSecondHandleOffset()843 OffsetF GetSecondHandleOffset() const override 844 { 845 return textSelector_.secondHandle.GetOffset(); 846 } 847 848 OffsetF GetTextPaintOffset() const override; 849 OffsetF GetPaintRectGlobalOffset() const; 850 // original local point to transformed global point. 851 void HandlePointWithTransform(OffsetF& point); 852 853 float GetCrossOverHeight() const; 854 CreateAccessibilityProperty()855 RefPtr<AccessibilityProperty> CreateAccessibilityProperty() override 856 { 857 return MakeRefPtr<RichEditorAccessibilityProperty>(); 858 } 859 860 void AdjustSelector(int32_t& index, HandleType handleType, 861 SelectorAdjustPolicy policy = SelectorAdjustPolicy::INCLUDE); 862 void AdjustSelector(int32_t& start, int32_t& end, SelectorAdjustPolicy policy = SelectorAdjustPolicy::INCLUDE); 863 bool AdjustSelectorForSymbol(int32_t& index, HandleType handleType, SelectorAdjustPolicy policy); 864 bool AdjustSelectorForEmoji(int32_t& index, HandleType handleType, SelectorAdjustPolicy policy); 865 EmojiRelation GetEmojiRelation(int index); 866 void UpdateSelector(int32_t start, int32_t end); 867 void UpdateSelectionType(const SelectionInfo& textSelectInfo); 868 std::list<RefPtr<SpanItem>>::iterator GetSpanIter(int32_t index); 869 SpanItemType GetSpanType(int32_t index); 870 DumpAdvanceInfo()871 void DumpAdvanceInfo() override {} 872 SetContentChange(bool onChange)873 void SetContentChange(bool onChange) 874 { 875 contentChange_ = onChange; 876 } 877 GetClipboard()878 RefPtr<Clipboard> GetClipboard() override 879 { 880 return clipboard_; 881 } 882 883 PositionWithAffinity GetGlyphPositionAtCoordinate(int32_t x, int32_t y) override; 884 void OnSelectionMenuOptionsUpdate( 885 const NG::OnCreateMenuCallback&& onCreateMenuCallback, const NG::OnMenuItemClickCallback&& onMenuItemClick); 886 RectF GetTextContentRect(bool isActualText = false) const override 887 { 888 return contentRect_; 889 } 890 891 void PreferredParagraph(); 892 GetPresetParagraph()893 const RefPtr<Paragraph>& GetPresetParagraph() 894 { 895 return presetParagraph_; 896 } 897 IsMoveCaretAnywhere()898 bool IsMoveCaretAnywhere() const 899 { 900 return isMoveCaretAnywhere_; 901 } 902 OnFrameNodeChanged(FrameNodeChangeInfoFlag flag)903 void OnFrameNodeChanged(FrameNodeChangeInfoFlag flag) override 904 { 905 selectOverlay_->OnAncestorNodeChanged(flag); 906 } 907 908 bool IsResponseRegionExpandingNeededForStylus(const TouchEvent& touchEvent) const override; 909 910 RectF ExpandDefaultResponseRegion(RectF& rect) override; ConsumeChildrenAdjustment(const OffsetF &)911 bool ConsumeChildrenAdjustment(const OffsetF& /* offset */) override 912 { 913 return true; 914 } 915 916 TextStyle GetDefaultTextStyle(); SetEnableHapticFeedback(bool isEnabled)917 void SetEnableHapticFeedback(bool isEnabled) 918 { 919 isEnableHapticFeedback_ = isEnabled; 920 } 921 922 bool InsertOrDeleteSpace(int32_t index) override; 923 924 void DeleteRange(int32_t start, int32_t end, bool isIME = true) override; 925 926 void HandleOnPageUp() override; 927 void HandleOnPageDown() override; 928 void HandlePageScroll(bool isPageUp); 929 SetRequestKeyboardOnFocus(bool needToRequest)930 void SetRequestKeyboardOnFocus(bool needToRequest) 931 { 932 needToRequestKeyboardOnFocus_ = needToRequest; 933 } 934 935 bool IsTextEditableForStylus() const override; 936 937 NG::DragDropInfo HandleDragStart(const RefPtr<Ace::DragEvent>& event, const std::string& extraParams); 938 RequestFocusWhenSelected()939 void RequestFocusWhenSelected() 940 { 941 CHECK_NULL_VOID(!HasFocus()); 942 CHECK_NULL_VOID(IsSelected()); 943 auto focusHub = GetFocusHub(); 944 CHECK_NULL_VOID(focusHub); 945 focusHub->RequestFocusImmediately(); 946 isOnlyRequestFocus_ = true; 947 } 948 GetBarDisplayMode()949 DisplayMode GetBarDisplayMode() 950 { 951 return barDisplayMode_.value_or(DisplayMode::AUTO); 952 } 953 954 Color GetUrlSpanColor() override; 955 956 void SetPreviewMenuParam(TextSpanType spanType, std::function<void()>& builder, const SelectMenuParam& menuParam); 957 958 void TriggerAvoidOnCaretChange(); 959 960 void ForceTriggerAvoidOnCaretChange(bool isMoveContent = false) 961 { 962 auto pipeline = GetContext(); 963 CHECK_NULL_VOID(pipeline && pipeline->UsingCaretAvoidMode()); 964 IF_TRUE(isMoveContent, MoveCaretToContentRect()); 965 isTriggerAvoidOnCaretAvoidMode_ = true; 966 } 967 TriggerAvoidOnCaretChangeNextFrame()968 void TriggerAvoidOnCaretChangeNextFrame() 969 { 970 ForceTriggerAvoidOnCaretChange(true); 971 isTriggerAvoidOnCaretAvoidMode_ = false; 972 UpdateModifierCaretOffsetAndHeight(); 973 TriggerAvoidOnCaretChange(); 974 } 975 ResetTriggerAvoidFlagOnCaretChange()976 void ResetTriggerAvoidFlagOnCaretChange() 977 { 978 isTriggerAvoidOnCaretAvoidMode_ = false; 979 } 980 981 void OnWindowSizeChanged(int32_t width, int32_t height, WindowSizeChangeReason type) override; 982 IsTriggerAvoidOnCaretAvoidMode()983 bool IsTriggerAvoidOnCaretAvoidMode() 984 { 985 return isTriggerAvoidOnCaretAvoidMode_; 986 } 987 SetAvoidFlagOnCaretAvoidMode(bool isTriggerAvoidOnCaretAvoidMode)988 void SetAvoidFlagOnCaretAvoidMode(bool isTriggerAvoidOnCaretAvoidMode) 989 { 990 auto pipeline = GetContext(); 991 CHECK_NULL_VOID(pipeline && pipeline->UsingCaretAvoidMode()); 992 isTriggerAvoidOnCaretAvoidMode_ = isTriggerAvoidOnCaretAvoidMode; 993 } 994 ChangeLastRichTextRect()995 void ChangeLastRichTextRect() 996 { 997 lastRichTextRect_ = richTextRect_; 998 } 999 GetLastTextRect()1000 const RectF& GetLastTextRect() 1001 { 1002 return lastRichTextRect_; 1003 } 1004 SetKeyboardAppearance(KeyboardAppearance value)1005 void SetKeyboardAppearance(KeyboardAppearance value) 1006 { 1007 TAG_LOGI(AceLogTag::ACE_RICH_TEXT, "SetKeyboardAppearance=%{public}d", value); 1008 keyboardAppearance_ = value; 1009 } 1010 GetKeyboardAppearance()1011 KeyboardAppearance GetKeyboardAppearance() const 1012 { 1013 return keyboardAppearance_; 1014 } 1015 1016 protected: 1017 bool CanStartAITask() override; 1018 1019 template<typename T> GetTheme()1020 RefPtr<T> GetTheme() 1021 { 1022 auto pipelineContext = GetContext(); 1023 CHECK_NULL_RETURN(pipelineContext, {}); 1024 return pipelineContext->GetTheme<T>(); 1025 } 1026 1027 std::vector<RectF> GetSelectedRects(int32_t start, int32_t end) override; 1028 PointF GetTextOffset(const Offset& localLocation, const RectF& contentRect) override; 1029 1030 private: 1031 friend class RichEditorSelectOverlay; 1032 friend class OneStepDragController; 1033 bool HandleUrlSpanClickEvent(const GestureEvent& info); 1034 void HandleUrlSpanForegroundClear(); 1035 bool HandleUrlSpanShowShadow(const Offset& localLocation, const Offset& globalOffset, const Color& color); 1036 Color GetUrlHoverColor(); 1037 Color GetUrlPressColor(); 1038 RefPtr<RichEditorSelectOverlay> selectOverlay_; 1039 Offset ConvertGlobalToLocalOffset(const Offset& globalOffset); 1040 void UpdateSelectMenuInfo(SelectMenuInfo& selectInfo); 1041 void HandleOnPaste() override; 1042 void HandleOnCut() override; 1043 void InitClickEvent(const RefPtr<GestureEventHub>& gestureHub) override; 1044 void InitFocusEvent(const RefPtr<FocusHub>& focusHub); 1045 void HandleBlurEvent(); 1046 void HandleFocusEvent(); 1047 void HandleClickEvent(GestureEvent& info); 1048 void HandleSingleClickEvent(GestureEvent& info); 1049 bool HandleClickSelection(const OHOS::Ace::GestureEvent& info); 1050 bool IsClickEventOnlyForMenuToggle(const OHOS::Ace::GestureEvent& info); 1051 Offset ConvertTouchOffsetToTextOffset(const Offset& touchOffset); 1052 bool IsShowSingleHandleByClick(const OHOS::Ace::GestureEvent& info, int32_t lastCaretPosition, 1053 const RectF& lastCaretRect, bool isCaretTwinkling); 1054 bool RepeatClickCaret(const Offset& offset, int32_t lastCaretPosition, const RectF& lastCaretRect); 1055 bool RepeatClickCaret(const Offset& offset, const RectF& lastCaretRect); 1056 void CreateAndShowSingleHandle(); 1057 void MoveCaretAndStartFocus(const Offset& offset); 1058 void HandleDoubleClickEvent(GestureEvent& info); 1059 bool HandleUserClickEvent(GestureEvent& info); 1060 bool HandleUserLongPressEvent(GestureEvent& info); 1061 bool HandleUserDoubleClickEvent(GestureEvent& info); 1062 bool HandleUserGestureEvent( 1063 GestureEvent& info, std::function<bool(RefPtr<SpanItem> item, GestureEvent& info)>&& gestureFunc); 1064 void HandleOnlyImageSelected(const Offset& globalOffset, const SourceTool sourceTool); 1065 void CalcCaretInfoByClick(const Offset& touchOffset); 1066 std::pair<OffsetF, float> CalcAndRecordLastClickCaretInfo(const Offset& textOffset); 1067 void HandleEnabled(); 1068 void InitMouseEvent(); 1069 void ScheduleCaretTwinkling(); 1070 void OnCaretTwinkling(); 1071 void StartTwinkling(); 1072 void ShowCaretWithoutTwinkling(); 1073 void StopTwinkling(); 1074 void UpdateFontFeatureTextStyle( 1075 RefPtr<SpanNode>& spanNode, struct UpdateSpanStyle& updateSpanStyle, TextStyle& textStyle); 1076 void UpdateDecoration(RefPtr<SpanNode>& spanNode, struct UpdateSpanStyle& updateSpanStyle, TextStyle& textStyle); 1077 void UpdateTextStyle(RefPtr<SpanNode>& spanNode, struct UpdateSpanStyle updateSpanStyle, TextStyle textStyle); 1078 void UpdateSymbolStyle(RefPtr<SpanNode>& spanNode, struct UpdateSpanStyle updateSpanStyle, TextStyle textStyle); 1079 void UpdateImageStyle(RefPtr<FrameNode>& imageNode, const ImageSpanAttribute& imageStyle); 1080 void UpdateImageAttribute(RefPtr<FrameNode>& imageNode, const ImageSpanAttribute& imageStyle); 1081 void InitTouchEvent(); 1082 void InitPanEvent(); 1083 bool SelectOverlayIsOn(); 1084 void HandleLongPress(GestureEvent& info); 1085 void HandleDoubleClickOrLongPress(GestureEvent& info); 1086 void HandleDoubleClickOrLongPress(GestureEvent& info, RefPtr<FrameNode> host); 1087 void StartVibratorByLongPress(); 1088 std::string GetPositionSpansText(int32_t position, int32_t& startSpan); 1089 void FireOnSelect(int32_t selectStart, int32_t selectEnd); 1090 void FireOnSelectionChange(const int32_t caretPosition); 1091 void FireOnSelectionChange(const TextSelector& selector); 1092 void FireOnSelectionChange(int32_t selectStart, int32_t selectEnd, bool isForced = false); 1093 void MouseRightFocus(const MouseInfo& info); 1094 bool IsScrollBarPressed(const MouseInfo& info); 1095 void HandleMouseLeftButtonMove(const MouseInfo& info); 1096 void HandleMouseLeftButtonPress(const MouseInfo& info); 1097 void HandleShiftSelect(int32_t position); 1098 void HandleMouseLeftButtonRelease(const MouseInfo& info); 1099 void HandleMouseLeftButton(const MouseInfo& info); 1100 void HandleMouseRightButton(const MouseInfo& info); 1101 void HandleMouseEvent(const MouseInfo& info); 1102 void HandleTouchEvent(const TouchEventInfo& info); 1103 void HandleTouchDown(const TouchEventInfo& info); 1104 void HandleTouchUp(); 1105 void HandleTouchUpAfterLongPress(); 1106 void HandleTouchMove(const Offset& offset); 1107 void UpdateCaretByTouchMove(const Offset& offset); 1108 Offset AdjustLocalOffsetOnMoveEvent(const Offset& originalOffset); 1109 void StartVibratorByIndexChange(int32_t currentIndex, int32_t preIndex); 1110 void InitLongPressEvent(const RefPtr<GestureEventHub>& gestureHub); 1111 void UseHostToUpdateTextFieldManager(); 1112 void UpdateTextFieldManager(const Offset& offset, float height); 1113 void ScrollToSafeArea() const override; 1114 void InitDragDropEvent(); 1115 void OnDragStartAndEnd(); 1116 void onDragDropAndLeave(); 1117 void ClearDragDropEvent(); 1118 void OnDragMove(const RefPtr<OHOS::Ace::DragEvent>& event); 1119 void OnDragEnd(const RefPtr<Ace::DragEvent>& event); 1120 void ResetDragSpanItems(); 1121 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override; 1122 std::string GetPlaceHolderInJson() const; 1123 std::string GetTextColorInJson(const std::optional<Color>& value) const; 1124 void FillPreviewMenuInJson(const std::unique_ptr<JsonValue>& jsonValue) const override; 1125 void ResetSelectionAfterAddSpan(bool isPaste); 1126 void SetResultObjectText(ResultObject& resultObject, const RefPtr<SpanItem>& spanItem) override; 1127 SelectionInfo GetAdjustedSelectionInfo(const SelectionInfo& textSelectInfo); ResetAfterTextChange()1128 void ResetAfterTextChange() override {}; 1129 void AddOprationWhenAddImage(int32_t beforeCaretPos); 1130 void UpdateSpanNode(RefPtr<SpanNode> spanNode, const TextSpanOptions& options); 1131 void InitPlaceholderSpansMap( 1132 RefPtr<SpanItem>& newSpanItem, const RefPtr<SpanItem>& spanItem, size_t& index, size_t& placeholderGains); 1133 void ReplacePlaceholderWithCustomSpan(const RefPtr<SpanItem>& spanItem, size_t& index, size_t& textIndex); 1134 void ReplacePlaceholderWithSymbolSpan(const RefPtr<SpanItem>& spanItem, size_t& index, size_t& textIndex); 1135 void ReplacePlaceholderWithImageSpan(const RefPtr<SpanItem>& spanItem, size_t& index, size_t& textIndex); AddDragFrameNodeToManager(const RefPtr<FrameNode> & frameNode)1136 void AddDragFrameNodeToManager(const RefPtr<FrameNode>& frameNode) 1137 { 1138 auto host = GetHost(); 1139 CHECK_NULL_VOID(host); 1140 auto context = host->GetContext(); 1141 CHECK_NULL_VOID(context); 1142 auto dragDropManager = context->GetDragDropManager(); 1143 CHECK_NULL_VOID(dragDropManager); 1144 dragDropManager->AddDragFrameNode(frameNode->GetId(), AceType::WeakClaim(AceType::RawPtr(frameNode))); 1145 } 1146 RemoveDragFrameNodeFromManager(const RefPtr<FrameNode> & frameNode)1147 void RemoveDragFrameNodeFromManager(const RefPtr<FrameNode>& frameNode) 1148 { 1149 auto host = GetHost(); 1150 CHECK_NULL_VOID(host); 1151 auto context = host->GetContext(); 1152 CHECK_NULL_VOID(context); 1153 auto dragDropManager = context->GetDragDropManager(); 1154 CHECK_NULL_VOID(dragDropManager); 1155 dragDropManager->RemoveDragFrameNode(frameNode->GetId()); 1156 } 1157 1158 void HandleCursorOnDragMoved(const RefPtr<NotifyDragEvent>& notifyDragEvent); 1159 void HandleCursorOnDragLeaved(const RefPtr<NotifyDragEvent>& notifyDragEvent); 1160 void HandleCursorOnDragEnded(const RefPtr<NotifyDragEvent>& notifyDragEvent); 1161 1162 int32_t GetParagraphLength(const std::list<RefPtr<UINode>>& spans) const; 1163 // REQUIRES: 0 <= start < end 1164 std::vector<RefPtr<SpanNode>> GetParagraphNodes(int32_t start, int32_t end) const; 1165 void OnHover(bool isHover); 1166 bool RequestKeyboard(bool isFocusViewChanged, bool needStartTwinkling, bool needShowSoftKeyboard); 1167 void UpdateCaretInfoToController(); 1168 #if defined(ENABLE_STANDARD_INPUT) 1169 bool EnableStandardInput(bool needShowSoftKeyboard); 1170 std::optional<MiscServices::TextConfig> GetMiscTextConfig(); 1171 #else 1172 bool UnableStandardInput(bool isFocusViewChanged); 1173 #endif 1174 1175 bool HasConnection() const; 1176 bool CloseKeyboard(bool forceClose) override; 1177 void CalcInsertValueObj(TextInsertValueInfo& info); 1178 void CalcDeleteValueObj(int32_t currentPosition, int32_t length, RichEditorDeleteValue& info); 1179 RefPtr<SpanNode> GetSpanNodeBySpanItem(const RefPtr<SpanItem> spanItem); 1180 int32_t DeleteValueSetBuilderSpan(const RefPtr<SpanItem>& spanItem, RichEditorAbstractSpanResult& spanResult); 1181 int32_t DeleteValueSetImageSpan(const RefPtr<SpanItem>& spanItem, RichEditorAbstractSpanResult& spanResult); 1182 int32_t DeleteValueSetSymbolSpan(const RefPtr<SpanItem>& spanItem, RichEditorAbstractSpanResult& spanResult); 1183 int32_t DeleteValueSetTextSpan(const RefPtr<SpanItem>& spanItem, int32_t currentPosition, int32_t length, 1184 RichEditorAbstractSpanResult& spanResult); 1185 void DeleteByDeleteValueInfo(const RichEditorDeleteValue& info); 1186 int32_t ProcessDeleteNodes(std::list<RichEditorAbstractSpanResult>& deleteSpans); 1187 bool OnKeyEvent(const KeyEvent& keyEvent); 1188 void MoveCaretAfterTextChange(); 1189 bool BeforeIMEInsertValue(const std::string& insertValue); 1190 void AfterInsertValue( 1191 const RefPtr<SpanNode>& spanNode, int32_t insertValueLength, bool isCreate, bool isIme = true); 1192 bool AfterIMEInsertValue(const RefPtr<SpanNode>& spanNode, int32_t moveLength, bool isCreate); 1193 RefPtr<SpanNode> InsertValueToBeforeSpan(RefPtr<SpanNode>& spanNodeBefore, const std::string& insertValue); 1194 void SetCaretSpanIndex(int32_t index); 1195 bool HasSameTypingStyle(const RefPtr<SpanNode>& spanNode); 1196 void GetChangeSpanStyle(RichEditorChangeValue& changeValue, std::optional<TextStyle>& spanTextStyle, 1197 std::optional<struct UpdateParagraphStyle>& spanParaStyle, const RefPtr<SpanNode>& spanNode, int32_t spanIndex); 1198 void GetReplacedSpan(RichEditorChangeValue& changeValue, int32_t& innerPosition, const std::string& insertValue, 1199 int32_t textIndex, std::optional<TextStyle> textStyle, std::optional<struct UpdateParagraphStyle> paraStyle, 1200 bool isCreate = false, bool fixDel = true); 1201 void GetReplacedSpanFission(RichEditorChangeValue& changeValue, int32_t& innerPosition, std::string& content, 1202 int32_t startSpanIndex, int32_t offsetInSpan, std::optional<TextStyle> textStyle, 1203 std::optional<struct UpdateParagraphStyle> paraStyle); 1204 void CreateSpanResult(RichEditorChangeValue& changeValue, int32_t& innerPosition, int32_t spanIndex, 1205 int32_t offsetInSpan, int32_t endInSpan, std::string content, std::optional<TextStyle> textStyle, 1206 std::optional<struct UpdateParagraphStyle> paraStyle); 1207 void SetTextStyleToRet(RichEditorAbstractSpanResult& retInfo, const TextStyle& textStyle); 1208 void CalcInsertValueObj(TextInsertValueInfo& info, int textIndex, bool isCreate = false); 1209 void GetDeletedSpan(RichEditorChangeValue& changeValue, int32_t& innerPosition, int32_t length, 1210 RichEditorDeleteDirection direction = RichEditorDeleteDirection::FORWARD, bool isResetSelection = true); 1211 RefPtr<SpanItem> GetDelPartiallySpanItem( 1212 RichEditorChangeValue& changeValue, std::string& originalStr, int32_t& originalPos); 1213 void FixMoveDownChange(RichEditorChangeValue& changeValue, int32_t delLength); 1214 bool BeforeChangeText( 1215 RichEditorChangeValue& changeValue, const OperationRecord& record, RecordType type, int32_t delLength = 0); 1216 void BeforeUndo(RichEditorChangeValue& changeValue, int32_t& innerPosition, const OperationRecord& record); 1217 void BeforeRedo(RichEditorChangeValue& changeValue, int32_t& innerPosition, const OperationRecord& record); 1218 void BeforeDrag(RichEditorChangeValue& changeValue, int32_t& innerPosition, const OperationRecord& record); 1219 bool BeforeChangeText(RichEditorChangeValue& changeValue, const TextSpanOptions& options); 1220 1221 // add for scroll. 1222 void UpdateChildrenOffset(); 1223 void MoveFirstHandle(float offset); 1224 void MoveSecondHandle(float offset); 1225 void InitScrollablePattern(); 1226 bool IsReachedBoundary(float offset); 1227 void UpdateScrollBarOffset() override; 1228 void CheckScrollable(); 1229 void UpdateMagnifierStateAfterLayout(bool frameSizeChange); 1230 void UpdateScrollStateAfterLayout(bool shouldDisappear); 1231 void ScheduleAutoScroll(AutoScrollParam param); 1232 void OnAutoScroll(AutoScrollParam param); 1233 void StopAutoScroll(bool hideBarImmediately = true); 1234 void AutoScrollByEdgeDetection(AutoScrollParam param, OffsetF offset, EdgeDetectionStrategy strategy); 1235 float CalcDragSpeed(float hotAreaStart, float hotAreaEnd, float point); 1236 float MoveTextRect(float offset); 1237 void SetNeedMoveCaretToContentRect(); 1238 void MoveCaretToContentRect(); 1239 void MoveCaretToContentRect(const OffsetF& caretOffset, float caretHeight); 1240 void MoveCaretToContentRect(float offset, int32_t source); 1241 bool IsCaretInContentArea(); IsTextArea()1242 bool IsTextArea() const override 1243 { 1244 return true; 1245 } 1246 void ProcessInnerPadding(); 1247 1248 // ai analysis fun 1249 bool NeedAiAnalysis( 1250 const CaretUpdateType targeType, const int32_t pos, const int32_t& spanStart, const std::string& content); 1251 bool IsIndexAfterOrInSymbolOrEmoji(int32_t index); 1252 void AdjustCursorPosition(int32_t& pos); 1253 void AdjustPlaceholderSelection(int32_t& start, int32_t& end, const Offset& pos); 1254 bool AdjustWordSelection(int32_t& start, int32_t& end); 1255 bool IsTouchAtLineEnd(int32_t caretPos, const Offset& textOffset); 1256 bool IsTouchBeforeCaret(int32_t caretPos, const Offset& textOffset); 1257 bool IsClickBoundary(const int32_t position); 1258 IsReachTop()1259 bool IsReachTop() 1260 { 1261 return NearEqual(richTextRect_.GetY(), contentRect_.GetY()); 1262 } 1263 IsReachBottom()1264 bool IsReachBottom() 1265 { 1266 return NearEqual(richTextRect_.Bottom(), contentRect_.Bottom()); 1267 } 1268 1269 void SetSelfAndChildDraggableFalse(const RefPtr<UINode>& customNode); 1270 RefPtr<SpanItem> GetSameSpanItem(const RefPtr<SpanItem>& spanItem); 1271 RefPtr<ImageSpanNode> GetImageSpanNodeBySpanItem(const RefPtr<ImageSpanItem>& spanItem); 1272 1273 void AdjustSelectRects(SelectRectsType pos, std::vector<RectF>& selectRects); 1274 RectF GetSelectArea(SelectRectsType pos); 1275 bool IsTouchInFrameArea(const PointF& touchPoint); 1276 void HandleOnDragDrop(const RefPtr<OHOS::Ace::DragEvent>& event); 1277 void DeleteForward(int32_t currentPosition, int32_t length); 1278 void HandleOnDragDropTextOperation(const std::string& insertValue, bool isDeleteSelect); 1279 void UndoDrag(const OperationRecord& record); 1280 void RedoDrag(const OperationRecord& record); 1281 void HandleOnDragInsertValueOperation(const std::string& insertValue); 1282 void HandleOnDragInsertValue(const std::string& str); 1283 void HandleOnEditChanged(bool isEditing); 1284 void OnTextInputActionUpdate(TextInputAction value); 1285 void CloseSystemMenu(); 1286 void SetAccessibilityAction() override; 1287 void SetAccessibilityEditAction(); 1288 void HandleTripleClickEvent(OHOS::Ace::GestureEvent& info); 1289 bool CheckTripClickEvent(GestureEvent& info); 1290 void HandleSelect(GestureEvent& info, int32_t selectStart, int32_t selectEnd); 1291 TextStyleResult GetTextStyleBySpanItem(const RefPtr<SpanItem>& spanItem); 1292 ImageStyleResult GetImageStyleBySpanItem(const RefPtr<SpanItem>& spanItem); 1293 void SetSubSpans(RefPtr<SpanString>& spanString, int32_t start, int32_t end); 1294 void SetSubMap(RefPtr<SpanString>& spanString); 1295 void OnCopyOperationExt(RefPtr<PasteDataMix>& pasteData); 1296 void AddSpanByPasteData(const RefPtr<SpanString>& spanString); 1297 void CompleteStyledString(RefPtr<SpanString>& spanString); 1298 void InsertStyledStringByPaste(const RefPtr<SpanString>& spanString); 1299 void HandleOnDragInsertStyledString(const RefPtr<SpanString>& spanString); 1300 void AddSpansByPaste(const std::list<RefPtr<NG::SpanItem>>& spans); 1301 TextSpanOptions GetTextSpanOptions(const RefPtr<SpanItem>& spanItem); 1302 void HandleOnCopyStyledString(); 1303 void HandleOnDragDropStyledString(const RefPtr<OHOS::Ace::DragEvent>& event); 1304 void NotifyExitTextPreview(); 1305 void ProcessInsertValue(const std::string& insertValue, OperationType operationType = OperationType::DEFAULT, 1306 bool calledbyImf = false); 1307 void FinishTextPreviewInner(); 1308 void UpdateSelectionByTouchMove(const Offset& offset); 1309 void MoveCaretAnywhere(const Offset& touchOffset); 1310 void ShowCaretNoTwinkling(const Offset& textOffset); 1311 void TripleClickSection(GestureEvent& info, int32_t start, int32_t end, int32_t pos); 1312 void ProcessOverlayOnSetSelection(const std::optional<SelectionOptions>& options); 1313 std::pair<int32_t, SelectType> JudgeSelectType(const Offset& pos); 1314 bool IsSelectEmpty(int32_t start, int32_t end); 1315 void ProcessResultObject(RefPtr<PasteDataMix> pasteData, const ResultObject& result); 1316 void EncodeTlvDataByResultObject(const ResultObject& result, std::vector<uint8_t>& tlvData); 1317 bool AdjustIndexSkipLineSeparator(int32_t& currentPosition); 1318 bool AdjustIndexSkipSpace(int32_t& currentPosition, const MoveDirection direction); 1319 void RequestKeyboardToEdit(); HandleTasksOnLayoutSwap()1320 void HandleTasksOnLayoutSwap() 1321 { 1322 while (!tasks_.empty()) { 1323 const auto& task = tasks_.front(); 1324 if (task) { 1325 task(); 1326 } 1327 tasks_.pop(); 1328 } 1329 } PostTaskToLayutSwap(std::function<void ()> && task)1330 void PostTaskToLayutSwap(std::function<void()>&& task) 1331 { 1332 tasks_.emplace(std::forward<std::function<void()>>(task)); 1333 } 1334 1335 OffsetF GetGlobalOffset() const; 1336 void HandleImageDrag(const RefPtr<ImageSpanNode>& imageNode); 1337 void DisableDrag(const RefPtr<ImageSpanNode>& imageNode); 1338 void SetGestureOptions(UserGestureOptions userGestureOptions, RefPtr<SpanItem> spanItem); 1339 void AddSpanHoverEvent( 1340 RefPtr<SpanItem> spanItem, const RefPtr<FrameNode>& frameNode, const SpanOptionBase& options); 1341 void ClearOnFocusTextField(); 1342 1343 #if defined(ENABLE_STANDARD_INPUT) 1344 sptr<OHOS::MiscServices::OnTextChangedListener> richEditTextChangeListener_; 1345 #else 1346 RefPtr<TextInputConnection> connection_ = nullptr; 1347 #endif 1348 const bool isAPI14Plus; 1349 bool shiftFlag_ = false; 1350 bool isMouseSelect_ = false; 1351 bool isMousePressed_ = false; 1352 bool isFirstMouseSelect_ = true; 1353 bool leftMousePress_ = false; 1354 bool isLongPress_ = false; 1355 #if defined(OHOS_STANDARD_SYSTEM) && !defined(PREVIEW) 1356 bool imeAttached_ = false; 1357 bool imeShown_ = false; 1358 #endif 1359 1360 bool isTextChange_ = false; 1361 bool caretVisible_ = false; 1362 bool caretTwinkling_ = false; 1363 bool isRichEditorInit_ = false; 1364 bool clickEventInitialized_ = false; 1365 bool focusEventInitialized_ = false; 1366 bool blockPress_ = false; 1367 bool isCustomKeyboardAttached_ = false; 1368 bool usingMouseRightButton_ = false; 1369 bool isCursorAlwaysDisplayed_ = false; 1370 bool isClickOnAISpan_ = false; 1371 bool isOnlyRequestFocus_ = false; 1372 1373 int32_t moveLength_ = 0; 1374 int32_t caretPosition_ = 0; 1375 int32_t caretSpanIndex_ = -1; 1376 long long timestamp_ = 0; 1377 CaretAffinityPolicy caretAffinityPolicy_ = CaretAffinityPolicy::DEFAULT; 1378 OffsetF selectionMenuOffsetByMouse_; 1379 OffsetF selectionMenuOffsetClick_; 1380 OffsetF lastClickOffset_; 1381 std::string pasteStr_; 1382 1383 // still in progress 1384 ParagraphManager paragraphs_; 1385 RefPtr<Paragraph> presetParagraph_; 1386 std::vector<OperationRecord> operationRecords_; 1387 std::vector<OperationRecord> redoOperationRecords_; 1388 1389 RefPtr<TouchEventImpl> touchListener_; 1390 RefPtr<PanEvent> panEvent_; 1391 struct UpdateSpanStyle updateSpanStyle_; 1392 CancelableCallback<void()> caretTwinklingTask_; 1393 RefPtr<RichEditorController> richEditorController_; 1394 RefPtr<RichEditorStyledStringController> richEditorStyledStringController_; 1395 MoveDirection moveDirection_ = MoveDirection::FORWARD; 1396 RectF frameRect_; 1397 std::optional<struct UpdateSpanStyle> typingStyle_; 1398 std::optional<TextStyle> typingTextStyle_; 1399 std::list<ResultObject> dragResultObjects_; 1400 std::optional<Color> caretColor_; 1401 std::optional<Color> selectedBackgroundColor_; 1402 std::function<void()> customKeyboardBuilder_; 1403 std::function<void(int32_t)> caretChangeListener_; 1404 RefPtr<OverlayManager> keyboardOverlay_; 1405 RefPtr<AIWriteAdapter> aiWriteAdapter_ = MakeRefPtr<AIWriteAdapter>(); 1406 Offset selectionMenuOffset_; 1407 // add for scroll 1408 RectF richTextRect_; 1409 float scrollOffset_ = 0.0f; 1410 bool isFirstCallOnReady_ = false; 1411 bool scrollable_ = true; 1412 CancelableCallback<void()> autoScrollTask_; 1413 OffsetF prevAutoScrollOffset_; 1414 // add for ai input analysis 1415 bool hasClicked_ = false; 1416 CaretUpdateType caretUpdateType_ = CaretUpdateType::NONE; 1417 TimeStamp lastClickTimeStamp_; 1418 TimeStamp lastAiPosTimeStamp_; 1419 bool adjusted_ = false; 1420 AutoScrollParam currentScrollParam_; 1421 bool isAutoScrollRunning_ = false; 1422 bool isShowMenu_ = true; 1423 bool isOnlyImageDrag_ = false; 1424 bool isShowPlaceholder_ = false; 1425 TouchAndMoveCaretState moveCaretState_; 1426 // Recorded when touch down or mouse left button press. 1427 OffsetF globalOffsetOnMoveStart_; 1428 SelectionRangeInfo lastSelectionRange_{-1, -1}; 1429 bool isDragSponsor_ = false; 1430 std::pair<int32_t, int32_t> dragRange_ { 0, 0 }; 1431 bool isEditing_ = false; 1432 int32_t dragPosition_ = 0; 1433 // Action when "enter" pressed. 1434 TextInputAction action_ = TextInputAction::NEW_LINE; 1435 // What the keyboard appears. 1436 TextInputType keyboard_ = TextInputType::UNSPECIFIED; 1437 ACE_DISALLOW_COPY_AND_MOVE(RichEditorPattern); 1438 1439 int32_t richEditorInstanceId_ = -1; 1440 int32_t frameId_ = -1; 1441 bool keyboardAvoidance_ = false; 1442 bool contentChange_ = false; 1443 PreviewTextRecord previewTextRecord_; 1444 bool isTextPreviewSupported_ = true; 1445 bool isTouchCaret_ = false; 1446 OffsetF movingHandleOffset_; 1447 float lastFontScale_ = -1; 1448 bool isCaretInContentArea_ = false; 1449 std::vector<TimeStamp> clickInfo_; 1450 std::pair<int32_t, int32_t> initSelector_ = { 0, 0 }; 1451 bool isMoveCaretAnywhere_ = false; 1452 bool previewLongPress_ = false; 1453 bool editingLongPress_ = false; 1454 bool needMoveCaretToContentRect_ = false; 1455 std::queue<std::function<void()>> tasks_; 1456 bool isModifyingContent_ = false; 1457 bool needToRequestKeyboardOnFocus_ = true; 1458 bool isEnableHapticFeedback_ = true; 1459 std::optional<DisplayMode> barDisplayMode_ = std::nullopt; 1460 std::unordered_map<std::string, RefPtr<SpanItem>> placeholderSpansMap_; 1461 std::unique_ptr<OneStepDragController> oneStepDragController_; 1462 std::list<WeakPtr<ImageSpanNode>> imageNodes; 1463 std::list<WeakPtr<PlaceholderSpanNode>> builderNodes; 1464 bool isTriggerAvoidOnCaretAvoidMode_ = false; 1465 RectF lastRichTextRect_; 1466 KeyboardAppearance keyboardAppearance_ = KeyboardAppearance::NONE_IMMERSIVE; 1467 }; 1468 } // namespace OHOS::Ace::NG 1469 1470 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_RICH_EDITOR_RICH_EDITOR_PATTERN_H 1471