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