• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "core/components_ng/pattern/rich_editor/rich_editor_event_hub.h"
16 #include "base/utils/utf_helper.h"
17 #include "interfaces/inner_api/ui_session/ui_session_manager.h"
18 
19 #include "core/components_ng/pattern/rich_editor/rich_editor_pattern.h"
20 
21 namespace OHOS::Ace::NG {
SetInsertOffset(int32_t insertOffset)22 void RichEditorInsertValue::SetInsertOffset(int32_t insertOffset)
23 {
24     insertOffset_ = insertOffset;
25 }
26 
GetInsertOffset() const27 int32_t RichEditorInsertValue::GetInsertOffset() const
28 {
29     return insertOffset_;
30 }
31 
SetInsertValue(const std::u16string & insertValue)32 void RichEditorInsertValue::SetInsertValue(const std::u16string& insertValue)
33 {
34     insertValue_ = insertValue;
35 }
36 
SetPreviewText(const std::u16string & previewText)37 void RichEditorInsertValue::SetPreviewText(const std::u16string& previewText)
38 {
39     previewText_ = previewText;
40 }
41 
GetInsertValue() const42 const std::u16string& RichEditorInsertValue::GetInsertValue() const
43 {
44     return insertValue_;
45 }
46 
GetPreviewText() const47 const std::u16string& RichEditorInsertValue::GetPreviewText() const
48 {
49     return previewText_;
50 }
51 
SetSpanIndex(int32_t spanIndex)52 void RichEditorAbstractSpanResult::SetSpanIndex(int32_t spanIndex)
53 {
54     spanIndex_ = spanIndex;
55 }
56 
GetSpanIndex() const57 int32_t RichEditorAbstractSpanResult::GetSpanIndex() const
58 {
59     return spanIndex_;
60 }
61 
SetSpanRangeStart(int32_t spanRangeStart)62 void RichEditorAbstractSpanResult::SetSpanRangeStart(int32_t spanRangeStart)
63 {
64     spanRangeStart_ = spanRangeStart;
65 }
66 
GetSpanRangeStart() const67 int32_t RichEditorAbstractSpanResult::GetSpanRangeStart() const
68 {
69     return spanRangeStart_;
70 }
71 
SetSpanRangeEnd(int32_t spanRangeEnd)72 void RichEditorAbstractSpanResult::SetSpanRangeEnd(int32_t spanRangeEnd)
73 {
74     spanRangeEnd_ = spanRangeEnd;
75 }
76 
GetSpanRangeEnd() const77 int32_t RichEditorAbstractSpanResult::GetSpanRangeEnd() const
78 {
79     return spanRangeEnd_;
80 }
81 
SetSpanType(SpanResultType spanType)82 void RichEditorAbstractSpanResult::SetSpanType(SpanResultType spanType)
83 {
84     spanType_ = spanType;
85 }
86 
GetType() const87 SpanResultType RichEditorAbstractSpanResult::GetType() const
88 {
89     return spanType_;
90 }
91 
SetOffsetInSpan(int32_t offsetInSpan)92 void RichEditorAbstractSpanResult::SetOffsetInSpan(int32_t offsetInSpan)
93 {
94     offsetInSpan_ = offsetInSpan;
95 }
96 
OffsetInSpan() const97 int32_t RichEditorAbstractSpanResult::OffsetInSpan() const
98 {
99     return offsetInSpan_;
100 }
101 
SetEraseLength(int32_t eraseLength)102 void RichEditorAbstractSpanResult::SetEraseLength(int32_t eraseLength)
103 {
104     eraseLength_ = eraseLength;
105 }
106 
GetEraseLength() const107 int32_t RichEditorAbstractSpanResult::GetEraseLength() const
108 {
109     return eraseLength_;
110 }
111 
SetValue(const std::u16string & value)112 void RichEditorAbstractSpanResult::SetValue(const std::u16string& value)
113 {
114     value_ = value;
115 }
116 
GetValue() const117 const std::u16string& RichEditorAbstractSpanResult::GetValue() const
118 {
119     return value_;
120 }
121 
SetPreviewText(const std::u16string & previewText)122 void RichEditorAbstractSpanResult::SetPreviewText(const std::u16string& previewText)
123 {
124     previewText_ = previewText;
125 }
126 
GetPreviewText() const127 const std::u16string& RichEditorAbstractSpanResult::GetPreviewText() const
128 {
129     return previewText_;
130 }
131 
SetFontColor(const std::string & fontColor)132 void RichEditorAbstractSpanResult::SetFontColor(const std::string& fontColor)
133 {
134     fontColor_ = fontColor;
135 }
136 
SetFontFeature(const FONT_FEATURES_LIST & fontFeature)137 void RichEditorAbstractSpanResult::SetFontFeature(const FONT_FEATURES_LIST& fontFeature)
138 {
139     fontFeature_ = fontFeature;
140 }
141 
GetFontFeatures() const142 const FONT_FEATURES_LIST& RichEditorAbstractSpanResult::GetFontFeatures() const
143 {
144     return fontFeature_;
145 }
146 
SetTextStyle(TextStyleResult textStyle)147 void RichEditorAbstractSpanResult::SetTextStyle(TextStyleResult textStyle)
148 {
149     textStyle_ = textStyle;
150 }
151 
GetTextStyle() const152 TextStyleResult RichEditorAbstractSpanResult::GetTextStyle() const
153 {
154     return textStyle_;
155 }
156 
SetLineHeight(double lineHeight)157 void RichEditorAbstractSpanResult::SetLineHeight(double lineHeight)
158 {
159     lineHeight_ = lineHeight;
160 }
161 
GetLineHeight() const162 double RichEditorAbstractSpanResult::GetLineHeight() const
163 {
164     return lineHeight_;
165 }
166 
SetHalfLeading(bool halfLeading)167 void RichEditorAbstractSpanResult::SetHalfLeading(bool halfLeading)
168 {
169     halfLeading_ = halfLeading;
170 }
171 
GetHalfLeading() const172 bool RichEditorAbstractSpanResult::GetHalfLeading() const
173 {
174     return halfLeading_;
175 }
176 
SetLetterspacing(double letterSpacing)177 void RichEditorAbstractSpanResult::SetLetterspacing(double letterSpacing)
178 {
179     letterSpacing_ = letterSpacing;
180 }
181 
GetLetterspacing() const182 double RichEditorAbstractSpanResult::GetLetterspacing() const
183 {
184     return letterSpacing_;
185 }
186 
GetFontColor() const187 const std::string& RichEditorAbstractSpanResult::GetFontColor() const
188 {
189     return fontColor_;
190 }
191 
SetFontSize(double fontSize)192 void RichEditorAbstractSpanResult::SetFontSize(double fontSize)
193 {
194     fontSize_ = fontSize;
195 }
196 
GetFontSize() const197 double RichEditorAbstractSpanResult::GetFontSize() const
198 {
199     return fontSize_;
200 }
201 
SetValueResource(const RefPtr<ResourceObject> & valueResource)202 void RichEditorAbstractSpanResult::SetValueResource(const RefPtr<ResourceObject>& valueResource)
203 {
204     valueResource_ = valueResource;
205 }
206 
GetValueResource() const207 const RefPtr<ResourceObject> RichEditorAbstractSpanResult::GetValueResource() const
208 {
209     return valueResource_;
210 }
211 
SetValueString(const std::string & valueString)212 void RichEditorAbstractSpanResult::SetValueString(const std::string& valueString)
213 {
214     valueString_ = valueString;
215 }
216 
GetValueString() const217 const std::string RichEditorAbstractSpanResult::GetValueString() const
218 {
219     return valueString_;
220 }
221 
SetSymbolSpanStyle(const SymbolSpanStyle & symbolSpanStyle)222 void RichEditorAbstractSpanResult::SetSymbolSpanStyle(const SymbolSpanStyle& symbolSpanStyle)
223 {
224     symbolSpanStyle_ = symbolSpanStyle;
225 }
226 
GetSymbolSpanStyle() const227 const SymbolSpanStyle RichEditorAbstractSpanResult::GetSymbolSpanStyle() const
228 {
229     return symbolSpanStyle_;
230 }
231 
SetFontWeight(int32_t fontWeigth)232 void RichEditorAbstractSpanResult::SetFontWeight(int32_t fontWeigth)
233 {
234     fontWeigth_ = fontWeigth;
235 }
236 
GetFontWeight() const237 int32_t RichEditorAbstractSpanResult::GetFontWeight() const
238 {
239     return fontWeigth_;
240 }
241 
SetFontFamily(const std::string & fontFamily)242 void RichEditorAbstractSpanResult::SetFontFamily(const std::string& fontFamily)
243 {
244     fontFamily_ = fontFamily;
245 }
246 
GetFontFamily() const247 const std::string& RichEditorAbstractSpanResult::GetFontFamily() const
248 {
249     return fontFamily_;
250 }
251 
SetTextDecoration(TextDecoration textDecoration)252 void RichEditorAbstractSpanResult::SetTextDecoration(TextDecoration textDecoration)
253 {
254     textDecoration_ = textDecoration;
255 }
256 
GetTextDecoration() const257 TextDecoration RichEditorAbstractSpanResult::GetTextDecoration() const
258 {
259     return textDecoration_;
260 }
261 
SetColor(const std::string & color)262 void RichEditorAbstractSpanResult::SetColor(const std::string& color)
263 {
264     color_ = color;
265 }
266 
GetColor() const267 const std::string& RichEditorAbstractSpanResult::GetColor() const
268 {
269     return color_;
270 }
271 
SetTextDecorationStyle(TextDecorationStyle textDecorationStyle)272 void RichEditorAbstractSpanResult::SetTextDecorationStyle(TextDecorationStyle textDecorationStyle)
273 {
274     textDecorationStyle_ = textDecorationStyle;
275 }
276 
GetTextDecorationStyle() const277 TextDecorationStyle RichEditorAbstractSpanResult::GetTextDecorationStyle() const
278 {
279     return textDecorationStyle_;
280 }
281 
SetValuePixelMap(const RefPtr<PixelMap> & valuePixelMap)282 void RichEditorAbstractSpanResult::SetValuePixelMap(const RefPtr<PixelMap>& valuePixelMap)
283 {
284     valuePixelMap_ = valuePixelMap;
285 }
286 
GetValuePixelMap() const287 const RefPtr<PixelMap>& RichEditorAbstractSpanResult::GetValuePixelMap() const
288 {
289     return valuePixelMap_;
290 }
291 
SetValueResourceStr(const std::string valueResourceStr)292 void RichEditorAbstractSpanResult::SetValueResourceStr(const std::string valueResourceStr)
293 {
294     valueResourceStr_ = valueResourceStr;
295 }
296 
GetValueResourceStr() const297 const std::string& RichEditorAbstractSpanResult::GetValueResourceStr() const
298 {
299     return valueResourceStr_;
300 }
301 
SetSizeWidth(int32_t width)302 void RichEditorAbstractSpanResult::SetSizeWidth(int32_t width)
303 {
304     width_ = width;
305 }
306 
GetSizeWidth() const307 int32_t RichEditorAbstractSpanResult::GetSizeWidth() const
308 {
309     return width_;
310 }
311 
SetSizeHeight(int32_t height)312 void RichEditorAbstractSpanResult::SetSizeHeight(int32_t height)
313 {
314     height_ = height;
315 }
316 
GetSizeHeight() const317 int32_t RichEditorAbstractSpanResult::GetSizeHeight() const
318 {
319     return height_;
320 }
321 
SetVerticalAlign(VerticalAlign verticalAlign)322 void RichEditorAbstractSpanResult::SetVerticalAlign(VerticalAlign verticalAlign)
323 {
324     verticalAlign_ = verticalAlign;
325 }
326 
GetVerticalAlign() const327 VerticalAlign RichEditorAbstractSpanResult::GetVerticalAlign() const
328 {
329     return verticalAlign_;
330 }
331 
SetImageFit(ImageFit objectFit)332 void RichEditorAbstractSpanResult::SetImageFit(ImageFit objectFit)
333 {
334     objectFit_ = objectFit;
335 }
336 
GetObjectFit() const337 ImageFit RichEditorAbstractSpanResult::GetObjectFit() const
338 {
339     return objectFit_;
340 }
341 
SetUrlAddress(const std::u16string & urlAddress)342 void RichEditorAbstractSpanResult::SetUrlAddress(const std::u16string& urlAddress)
343 {
344     urlAddress_ = urlAddress;
345 }
346 
GetUrlAddress() const347 const std::u16string& RichEditorAbstractSpanResult::GetUrlAddress() const
348 {
349     return urlAddress_;
350 }
351 
SetOffset(int32_t offset)352 void RichEditorDeleteValue::SetOffset(int32_t offset)
353 {
354     offset_ = offset;
355 }
356 
GetOffset() const357 int32_t RichEditorDeleteValue::GetOffset() const
358 {
359     return offset_;
360 }
361 
SetRichEditorDeleteDirection(RichEditorDeleteDirection direction)362 void RichEditorDeleteValue::SetRichEditorDeleteDirection(RichEditorDeleteDirection direction)
363 {
364     direction_ = direction;
365 }
366 
GetRichEditorDeleteDirection() const367 RichEditorDeleteDirection RichEditorDeleteValue::GetRichEditorDeleteDirection() const
368 {
369     return direction_;
370 }
371 
SetLength(int32_t length)372 void RichEditorDeleteValue::SetLength(int32_t length)
373 {
374     length_ = length;
375 }
376 
GetLength() const377 int32_t RichEditorDeleteValue::GetLength() const
378 {
379     return length_;
380 }
381 
SetRichEditorDeleteSpans(const RichEditorAbstractSpanResult & deleteSpan)382 void RichEditorDeleteValue::SetRichEditorDeleteSpans(const RichEditorAbstractSpanResult& deleteSpan)
383 {
384     richEditorDeleteSpans_.emplace_back(deleteSpan);
385 }
386 
ResetRichEditorDeleteSpans()387 void RichEditorDeleteValue::ResetRichEditorDeleteSpans()
388 {
389     richEditorDeleteSpans_.clear();
390 }
391 
GetRichEditorDeleteSpans() const392 const std::list<RichEditorAbstractSpanResult>& RichEditorDeleteValue::GetRichEditorDeleteSpans() const
393 {
394     return richEditorDeleteSpans_;
395 }
396 
SetRichEditorOriginalSpans(const RichEditorAbstractSpanResult & span)397 void RichEditorChangeValue::SetRichEditorOriginalSpans(const RichEditorAbstractSpanResult& span)
398 {
399     originalSpans_.emplace_back(span);
400 }
401 
GetRichEditorOriginalSpans() const402 const std::vector<RichEditorAbstractSpanResult>& RichEditorChangeValue::GetRichEditorOriginalSpans() const
403 {
404     return originalSpans_;
405 }
406 
SetRichEditorReplacedSpans(const RichEditorAbstractSpanResult & span)407 void RichEditorChangeValue::SetRichEditorReplacedSpans(const RichEditorAbstractSpanResult& span)
408 {
409     replacedSpans_.emplace_back(span);
410 }
411 
GetRichEditorReplacedSpans() const412 const std::vector<RichEditorAbstractSpanResult>& RichEditorChangeValue::GetRichEditorReplacedSpans() const
413 {
414     return replacedSpans_;
415 }
416 
SetRichEditorReplacedImageSpans(const RichEditorAbstractSpanResult & span)417 void RichEditorChangeValue::SetRichEditorReplacedImageSpans(const RichEditorAbstractSpanResult& span)
418 {
419     replacedImageSpans_.emplace_back(span);
420 }
421 
GetRichEditorReplacedImageSpans() const422 const std::vector<RichEditorAbstractSpanResult>& RichEditorChangeValue::GetRichEditorReplacedImageSpans() const
423 {
424     return replacedImageSpans_;
425 }
426 
SetRichEditorReplacedSymbolSpans(const RichEditorAbstractSpanResult & span)427 void RichEditorChangeValue::SetRichEditorReplacedSymbolSpans(const RichEditorAbstractSpanResult& span)
428 {
429     replacedSymbolSpans_.emplace_back(span);
430 }
431 
GetRichEditorReplacedSymbolSpans() const432 const std::vector<RichEditorAbstractSpanResult>& RichEditorChangeValue::GetRichEditorReplacedSymbolSpans() const
433 {
434     return replacedSymbolSpans_;
435 }
436 
SetRangeBefore(const TextRange & rangeBefore)437 void RichEditorChangeValue::SetRangeBefore(const TextRange& rangeBefore)
438 {
439     rangeBefore_ = rangeBefore;
440 }
441 
GetRangeBefore() const442 TextRange RichEditorChangeValue::GetRangeBefore() const
443 {
444     return rangeBefore_;
445 }
446 
SetRangeAfter(const TextRange & rangeAfter)447 void RichEditorChangeValue::SetRangeAfter(const TextRange& rangeAfter)
448 {
449     rangeAfter_ = rangeAfter;
450 }
451 
GetRangeAfter() const452 TextRange RichEditorChangeValue::GetRangeAfter() const
453 {
454     return rangeAfter_;
455 }
456 
SetRangeBefore(const TextRange & range)457 void StyledStringChangeValue::SetRangeBefore(const TextRange& range)
458 {
459     rangeBefore_ = range;
460 }
461 
GetRangeBefore() const462 TextRange StyledStringChangeValue::GetRangeBefore() const
463 {
464     return rangeBefore_;
465 }
466 
SetRangeAfter(const TextRange & range)467 void StyledStringChangeValue::SetRangeAfter(const TextRange& range)
468 {
469     rangeAfter_ = range;
470 }
471 
GetRangeAfter() const472 TextRange StyledStringChangeValue::GetRangeAfter() const
473 {
474     return rangeAfter_;
475 }
476 
SetReplacementString(const RefPtr<SpanStringBase> & styledString)477 void StyledStringChangeValue::SetReplacementString(const RefPtr<SpanStringBase>& styledString)
478 {
479     replacementString_ = styledString;
480 }
481 
GetReplacementString() const482 const RefPtr<SpanStringBase> StyledStringChangeValue::GetReplacementString() const
483 {
484     return replacementString_;
485 }
486 
SetPreviewText(const RefPtr<SpanStringBase> & previewText)487 void StyledStringChangeValue::SetPreviewText(const RefPtr<SpanStringBase>& previewText)
488 {
489     previewText_ = previewText;
490 }
491 
GetPreviewText() const492 const RefPtr<SpanStringBase> StyledStringChangeValue::GetPreviewText() const
493 {
494     return previewText_;
495 }
496 
SetOnReady(std::function<void ()> && func)497 void RichEditorEventHub::SetOnReady(std::function<void()>&& func)
498 {
499     onReady_ = std::move(func);
500 }
501 
FireOnReady()502 void RichEditorEventHub::FireOnReady()
503 {
504     if (onReady_) {
505         onReady_();
506         auto host = GetFrameNode();
507         CHECK_NULL_VOID(host);
508         auto* context = host->GetContext();
509         CHECK_NULL_VOID(context);
510         context->AddAfterRenderTask([host]() { host->MarkDirtyNode(PROPERTY_UPDATE_MEASURE); });
511     }
512 }
513 
SetAboutToIMEInput(std::function<bool (const RichEditorInsertValue &)> && func)514 void RichEditorEventHub::SetAboutToIMEInput(std::function<bool(const RichEditorInsertValue&)>&& func)
515 {
516     aboutToIMEInput_ = std::move(func);
517 }
518 
FireAboutToIMEInput(const RichEditorInsertValue & info)519 bool RichEditorEventHub::FireAboutToIMEInput(const RichEditorInsertValue& info)
520 {
521     return aboutToIMEInput_ ? aboutToIMEInput_(info) : true;
522 }
523 
SetOnIMEInputComplete(std::function<void (const RichEditorAbstractSpanResult &)> && func)524 void RichEditorEventHub::SetOnIMEInputComplete(std::function<void(const RichEditorAbstractSpanResult&)>&& func)
525 {
526     onIMEInputComplete_ = std::move(func);
527 }
528 
FireOnIMEInputComplete(const RichEditorAbstractSpanResult & info)529 void RichEditorEventHub::FireOnIMEInputComplete(const RichEditorAbstractSpanResult& info)
530 {
531     if (onIMEInputComplete_)
532         onIMEInputComplete_(info);
533 }
534 
SetOnDidIMEInput(std::function<void (const TextRange &)> && func)535 void RichEditorEventHub::SetOnDidIMEInput(std::function<void(const TextRange&)>&& func)
536 {
537     onDidIMEInput_ = std::move(func);
538 }
539 
FireOnDidIMEInput(const TextRange & range)540 void RichEditorEventHub::FireOnDidIMEInput(const TextRange& range)
541 {
542     if (onDidIMEInput_)
543         onDidIMEInput_(range);
544 }
545 
SetAboutToDelete(std::function<bool (const RichEditorDeleteValue &)> && func)546 void RichEditorEventHub::SetAboutToDelete(std::function<bool(const RichEditorDeleteValue&)>&& func)
547 {
548     aboutToDelete_ = std::move(func);
549 }
550 
FireAboutToDelete(const RichEditorDeleteValue & info)551 bool RichEditorEventHub::FireAboutToDelete(const RichEditorDeleteValue& info)
552 {
553     return aboutToDelete_ ? aboutToDelete_(info) : true;
554 }
555 
SetOnDeleteComplete(std::function<void ()> && func)556 void RichEditorEventHub::SetOnDeleteComplete(std::function<void()>&& func)
557 {
558     onDeleteComplete_ = std::move(func);
559 }
FireOnDeleteComplete()560 void RichEditorEventHub::FireOnDeleteComplete()
561 {
562     if (onDeleteComplete_) {
563         onDeleteComplete_();
564         UiSessionManager::GetInstance()->ReportComponentChangeEvent("event", "Radio.onChange");
565     }
566 }
567 
GetDragExtraParams(const std::string & extraInfo,const Point & point,DragEventType type)568 std::string RichEditorEventHub::GetDragExtraParams(const std::string& extraInfo, const Point& point, DragEventType type)
569 {
570     auto host = GetFrameNode();
571     CHECK_NULL_RETURN(host, extraInfo);
572     auto pattern = host->GetPattern<RichEditorPattern>();
573     CHECK_NULL_RETURN(host, extraInfo);
574 
575     auto json = JsonUtil::Create(true);
576     if (type == DragEventType::DROP && timestamp_ != 0 && pattern->GetTimestamp() == timestamp_) {
577         json->Put("isInComponent", true);
578         timestamp_ = 0;
579     }
580     if (!extraInfo.empty()) {
581         json->Put("extraInfo", extraInfo.c_str());
582     }
583     return json->ToString();
584 }
585 
SetOnEditingChange(std::function<void (const bool &)> && func)586 void RichEditorEventHub::SetOnEditingChange(std::function<void(const bool&)>&& func)
587 {
588     onEditingChange_ = std::move(func);
589 }
590 
FireOnEditingChange(bool isEditing)591 void RichEditorEventHub::FireOnEditingChange(bool isEditing)
592 {
593     if (onEditingChange_) {
594         onEditingChange_(isEditing);
595     }
596 }
597 
SetOnWillChange(std::function<bool (const RichEditorChangeValue &)> && func)598 void RichEditorEventHub::SetOnWillChange(std::function<bool(const RichEditorChangeValue&)>&& func)
599 {
600     onWillChange_ = std::move(func);
601 }
602 
FireOnWillChange(const RichEditorChangeValue & info)603 bool RichEditorEventHub::FireOnWillChange(const RichEditorChangeValue& info)
604 {
605     return onWillChange_ ? onWillChange_(info) : true;
606 }
607 
HasOnWillChange() const608 bool RichEditorEventHub::HasOnWillChange() const
609 {
610     return static_cast<bool>(onWillChange_);
611 }
612 
SetOnDidChange(std::function<void (const RichEditorChangeValue &)> && func)613 void RichEditorEventHub::SetOnDidChange(std::function<void(const RichEditorChangeValue&)>&& func)
614 {
615     onDidChange_ = std::move(func);
616 }
617 
FireOnDidChange(const RichEditorChangeValue & changeValue)618 void RichEditorEventHub::FireOnDidChange(const RichEditorChangeValue& changeValue)
619 {
620     if (onDidChange_) {
621         onDidChange_(changeValue);
622     }
623 }
624 
HasOnDidChange() const625 bool RichEditorEventHub::HasOnDidChange() const
626 {
627     auto host = GetFrameNode();
628     CHECK_NULL_RETURN(host, false);
629     auto pattern = host->GetPattern<RichEditorPattern>();
630     CHECK_NULL_RETURN(pattern, false);
631     pattern->SetContentChange(true);
632     return static_cast<bool>(onDidChange_);
633 }
634 
SetOnCut(std::function<void (NG::TextCommonEvent &)> && func)635 void RichEditorEventHub::SetOnCut(std::function<void(NG::TextCommonEvent&)>&& func)
636 {
637     onCut_ = std::move(func);
638 }
639 
FireOnCut(NG::TextCommonEvent & value)640 void RichEditorEventHub::FireOnCut(NG::TextCommonEvent& value)
641 {
642     if (onCut_) {
643         onCut_(value);
644     }
645 }
646 
SetOnCopy(std::function<void (NG::TextCommonEvent &)> && func)647 void RichEditorEventHub::SetOnCopy(std::function<void(NG::TextCommonEvent&)>&& func)
648 {
649     onCopy_ = std::move(func);
650 }
651 
FireOnCopy(NG::TextCommonEvent & value)652 void RichEditorEventHub::FireOnCopy(NG::TextCommonEvent& value)
653 {
654     if (onCopy_) {
655         onCopy_(value);
656     }
657 }
658 
SetOnShare(std::function<void (NG::TextCommonEvent &)> && func)659 void RichEditorEventHub::SetOnShare(std::function<void(NG::TextCommonEvent&)>&& func)
660 {
661     onShare_ = std::move(func);
662 }
663 
FireOnShare(NG::TextCommonEvent & value)664 void RichEditorEventHub::FireOnShare(NG::TextCommonEvent& value)
665 {
666     if (onShare_) {
667         onShare_(value);
668     }
669 }
670 
SetOnStyledStringWillChange(std::function<bool (const StyledStringChangeValue &)> && func)671 void RichEditorEventHub::SetOnStyledStringWillChange(std::function<bool(const StyledStringChangeValue&)> && func)
672 {
673     onStyledStringWillChange_ = std::move(func);
674 }
675 
FireOnStyledStringWillChange(const StyledStringChangeValue & info)676 bool RichEditorEventHub::FireOnStyledStringWillChange(const StyledStringChangeValue& info)
677 {
678     return onStyledStringWillChange_ ? onStyledStringWillChange_(info) : true;
679 }
680 
HasOnStyledStringWillChange() const681 bool RichEditorEventHub::HasOnStyledStringWillChange() const
682 {
683     return static_cast<bool>(onStyledStringWillChange_);
684 }
685 
SetOnStyledStringDidChange(std::function<void (const StyledStringChangeValue &)> && func)686 void RichEditorEventHub::SetOnStyledStringDidChange(std::function<void(const StyledStringChangeValue&)> && func)
687 {
688     onStyledStringDidChange_ = std::move(func);
689 }
690 
FireOnStyledStringDidChange(const StyledStringChangeValue & info)691 void RichEditorEventHub::FireOnStyledStringDidChange(const StyledStringChangeValue& info)
692 {
693     onStyledStringDidChange_(info);
694 }
695 
HasOnStyledStringDidChange() const696 bool RichEditorEventHub::HasOnStyledStringDidChange() const
697 {
698     return static_cast<bool>(onStyledStringDidChange_);
699 }
700 } // namespace OHOS::Ace::NG
701