1 /* 2 * Copyright (c) 2022-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_PATTERN_TEXT_SPAN_NODE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_SPAN_NODE_H 18 19 #include <list> 20 #include <memory> 21 #include <optional> 22 #include <string> 23 24 #include "base/memory/referenced.h" 25 #include "core/common/ai/data_detector_adapter.h" 26 #include "core/common/resource/resource_object.h" 27 #include "core/components/common/layout/constants.h" 28 #include "core/components/common/properties/color.h" 29 #include "core/components/common/properties/text_style.h" 30 #include "core/components_ng/base/ui_node.h" 31 #include "core/components_ng/pattern/image/image_pattern.h" 32 #include "core/components_ng/pattern/text/text_styles.h" 33 #include "core/components_ng/render/paragraph.h" 34 #include "core/components_v2/inspector/inspector_constants.h" 35 #include "core/components_v2/inspector/utils.h" 36 37 #define DEFINE_SPAN_FONT_STYLE_ITEM(name, type) \ 38 public: \ 39 std::optional<type> Get##name() const \ 40 { \ 41 if (spanItem_->fontStyle) { \ 42 return spanItem_->fontStyle->Get##name(); \ 43 } \ 44 return std::nullopt; \ 45 } \ 46 bool Has##name() const \ 47 { \ 48 if (spanItem_->fontStyle) { \ 49 return spanItem_->fontStyle->Has##name(); \ 50 } \ 51 return false; \ 52 } \ 53 type Get##name##Value(const type& defaultValue) const \ 54 { \ 55 if (spanItem_->fontStyle) { \ 56 return spanItem_->fontStyle->Get##name().value_or(defaultValue); \ 57 } \ 58 return defaultValue; \ 59 } \ 60 void Update##name(const type& value) \ 61 { \ 62 if (!spanItem_->fontStyle) { \ 63 spanItem_->fontStyle = std::make_unique<FontStyle>(); \ 64 } \ 65 if (spanItem_->fontStyle->Check##name(value)) { \ 66 return; \ 67 } \ 68 spanItem_->fontStyle->Update##name(value); \ 69 RequestTextFlushDirty(); \ 70 } \ 71 void Reset##name() \ 72 { \ 73 if (spanItem_->fontStyle) { \ 74 return spanItem_->fontStyle->Reset##name(); \ 75 } \ 76 } \ 77 void Update##name##WithoutFlushDirty(const type& value) \ 78 { \ 79 if (!spanItem_->fontStyle) { \ 80 spanItem_->fontStyle = std::make_unique<FontStyle>(); \ 81 } \ 82 if (spanItem_->fontStyle->Check##name(value)) { \ 83 return; \ 84 } \ 85 spanItem_->fontStyle->Update##name(value); \ 86 } 87 88 #define DEFINE_SPAN_TEXT_LINE_STYLE_ITEM(name, type) \ 89 public: \ 90 std::optional<type> Get##name() const \ 91 { \ 92 if (spanItem_->textLineStyle) { \ 93 return spanItem_->textLineStyle->Get##name(); \ 94 } \ 95 return std::nullopt; \ 96 } \ 97 bool Has##name() const \ 98 { \ 99 if (spanItem_->textLineStyle) { \ 100 return spanItem_->textLineStyle->Has##name(); \ 101 } \ 102 return false; \ 103 } \ 104 type Get##name##Value(const type& defaultValue) const \ 105 { \ 106 if (spanItem_->textLineStyle) { \ 107 return spanItem_->textLineStyle->Get##name().value_or(defaultValue); \ 108 } \ 109 return defaultValue; \ 110 } \ 111 void Update##name(const type& value) \ 112 { \ 113 if (!spanItem_->textLineStyle) { \ 114 spanItem_->textLineStyle = std::make_unique<TextLineStyle>(); \ 115 } \ 116 if (spanItem_->textLineStyle->Check##name(value)) { \ 117 return; \ 118 } \ 119 spanItem_->textLineStyle->Update##name(value); \ 120 RequestTextFlushDirty(); \ 121 } \ 122 void Reset##name() \ 123 { \ 124 if (spanItem_->textLineStyle) { \ 125 return spanItem_->textLineStyle->Reset##name(); \ 126 } \ 127 } \ 128 void Update##name##WithoutFlushDirty(const type& value) \ 129 { \ 130 if (!spanItem_->textLineStyle) { \ 131 spanItem_->textLineStyle = std::make_unique<TextLineStyle>(); \ 132 } \ 133 if (spanItem_->textLineStyle->Check##name(value)) { \ 134 return; \ 135 } \ 136 spanItem_->textLineStyle->Update##name(value); \ 137 } 138 139 namespace OHOS::Ace::NG { 140 141 class Paragraph; 142 143 struct SpanItem : public AceType { 144 DECLARE_ACE_TYPE(SpanItem, AceType); 145 146 public: 147 SpanItem() = default; ~SpanItemSpanItem148 virtual ~SpanItem() 149 { 150 children.clear(); 151 } 152 // position of last char + 1 153 int32_t position = -1; 154 int32_t imageNodeId = -1; 155 std::string inspectId; 156 std::string description; 157 std::string content; 158 uint32_t unicode = 0; 159 std::unique_ptr<FontStyle> fontStyle = std::make_unique<FontStyle>(); 160 std::unique_ptr<TextLineStyle> textLineStyle = std::make_unique<TextLineStyle>(); 161 // for text background style 162 std::optional<TextBackgroundStyle> backgroundStyle; 163 GestureEventFunc onClick; 164 GestureEventFunc onLongPress; 165 [[deprecated]] std::list<RefPtr<SpanItem>> children; 166 std::map<int32_t, AISpan> aiSpanMap; 167 int32_t placeholderIndex = -1; 168 // when paragraph ends with a \n, it causes the paragraph height to gain an extra line 169 // to have normal spacing between paragraphs, remove \n from every paragraph except the last one. 170 bool needRemoveNewLine = false; 171 bool hasResourceFontColor = false; 172 bool hasResourceDecorationColor = false; 173 std::optional<LeadingMargin> leadingMargin; 174 int32_t selectedStart = -1; 175 int32_t selectedEnd = -1; 176 void UpdateSymbolSpanParagraph(const RefPtr<FrameNode>& frameNode, const RefPtr<Paragraph>& builder); 177 virtual int32_t UpdateParagraph(const RefPtr<FrameNode>& frameNode, const RefPtr<Paragraph>& builder, 178 double width = 0.0f, double height = 0.0f, VerticalAlign verticalAlign = VerticalAlign::BASELINE); 179 virtual void UpdateSymbolSpanColor(const RefPtr<FrameNode>& frameNode, TextStyle& symbolSpanStyle); 180 virtual void UpdateTextStyleForAISpan( 181 const std::string& content, const RefPtr<Paragraph>& builder, const std::optional<TextStyle>& textStyle); 182 virtual void UpdateTextStyle( 183 const std::string& content, const RefPtr<Paragraph>& builder, const std::optional<TextStyle>& textStyle); 184 virtual void SetAiSpanTextStyle(std::optional<TextStyle>& textStyle); 185 virtual void GetIndex(int32_t& start, int32_t& end) const; 186 virtual void FontRegisterCallback(const RefPtr<FrameNode>& frameNode, const TextStyle& textStyle); 187 virtual void ToJsonValue(std::unique_ptr<JsonValue>& json) const; 188 std::string GetFont() const; 189 virtual void StartDrag(int32_t start, int32_t end); 190 virtual void EndDrag(); 191 virtual bool IsDragging(); GetTextStyleSpanItem192 std::optional<TextStyle> GetTextStyle() const 193 { 194 return textStyle_; 195 } SetTextStyleSpanItem196 void SetTextStyle(const std::optional<TextStyle>& textStyle) 197 { 198 textStyle_ = textStyle; 199 } GetResourceObjectSpanItem200 RefPtr<ResourceObject> GetResourceObject() 201 { 202 return resourceObject_; 203 } SetResourceObjectSpanItem204 void SetResourceObject(RefPtr<ResourceObject> resourceObject) 205 { 206 resourceObject_ = resourceObject; 207 } MarkNeedRemoveNewLineSpanItem208 void MarkNeedRemoveNewLine(bool value) 209 { 210 needRemoveNewLine = value; 211 } SetOnClickEventSpanItem212 void SetOnClickEvent(GestureEventFunc&& onClick_) 213 { 214 onClick = std::move(onClick_); 215 } SetLongPressEventSpanItem216 void SetLongPressEvent(GestureEventFunc&& onLongPress_) 217 { 218 onLongPress = std::move(onLongPress_); 219 } SetIsParentTextSpanItem220 void SetIsParentText(bool isText) 221 { 222 isParentText = isText; 223 } GetIsParentTextSpanItem224 bool GetIsParentText() 225 { 226 return isParentText; 227 } 228 std::string GetSpanContent(const std::string& rawContent); 229 std::string GetSpanContent(); 230 uint32_t GetSymbolUnicode(); 231 232 private: 233 std::optional<TextStyle> textStyle_; 234 bool isParentText = false; 235 RefPtr<ResourceObject> resourceObject_; 236 }; 237 238 239 enum class PropertyInfo { 240 FONTSIZE = 0, 241 FONTCOLOR, 242 FONTSTYLE, 243 FONTWEIGHT, 244 FONTFAMILY, 245 TEXTDECORATION, 246 TEXTCASE, 247 LETTERSPACE, 248 LINEHEIGHT, 249 TEXT_ALIGN, 250 LEADING_MARGIN, 251 NONE, 252 TEXTSHADOW, 253 SYMBOL_COLOR, 254 SYMBOL_RENDERING_STRATEGY, 255 SYMBOL_EFFECT_STRATEGY, 256 }; 257 258 class ACE_EXPORT BaseSpan : public virtual AceType { 259 DECLARE_ACE_TYPE(BaseSpan, AceType); 260 261 public: BaseSpan(int32_t id)262 explicit BaseSpan(int32_t id) : groupId_(id) {} 263 virtual void MarkTextDirty() = 0; 264 virtual void SetTextBackgroundStyle(const TextBackgroundStyle& style); UpdateTextBackgroundFromParent(const std::optional<TextBackgroundStyle> & style)265 virtual void UpdateTextBackgroundFromParent(const std::optional<TextBackgroundStyle>& style) 266 { 267 textBackgroundStyle_ = style; 268 } 269 GetTextBackgroundStyle()270 const std::optional<TextBackgroundStyle> GetTextBackgroundStyle() const 271 { 272 return textBackgroundStyle_; 273 } 274 SetHasTextBackgroundStyle(bool hasStyle)275 void SetHasTextBackgroundStyle(bool hasStyle) 276 { 277 hasTextBackgroundStyle_ = hasStyle; 278 } 279 HasTextBackgroundStyle()280 bool HasTextBackgroundStyle() 281 { 282 return hasTextBackgroundStyle_; 283 } 284 285 private: 286 std::optional<TextBackgroundStyle> textBackgroundStyle_; 287 int32_t groupId_ = 0; 288 bool hasTextBackgroundStyle_ = false; 289 }; 290 291 class ACE_EXPORT SpanNode : public UINode, public BaseSpan { 292 DECLARE_ACE_TYPE(SpanNode, UINode, BaseSpan); 293 294 public: 295 static RefPtr<SpanNode> GetOrCreateSpanNode(int32_t nodeId); 296 static RefPtr<SpanNode> GetOrCreateSpanNode(const std::string& tag, int32_t nodeId); 297 static RefPtr<SpanNode> CreateSpanNode(int32_t nodeId); 298 SpanNode(int32_t nodeId)299 explicit SpanNode(int32_t nodeId) : UINode(V2::SPAN_ETS_TAG, nodeId), BaseSpan(nodeId) {} SpanNode(const std::string & tag,int32_t nodeId)300 explicit SpanNode(const std::string& tag, int32_t nodeId) : UINode(tag, nodeId), BaseSpan(nodeId) {} 301 ~SpanNode() override = default; 302 303 void SetTextBackgroundStyle(const TextBackgroundStyle& style) override; 304 void UpdateTextBackgroundFromParent(const std::optional<TextBackgroundStyle>& style) override; 305 IsAtomicNode()306 bool IsAtomicNode() const override 307 { 308 return true; 309 } 310 GetSpanItem()311 const RefPtr<SpanItem>& GetSpanItem() const 312 { 313 return spanItem_; 314 } 315 UpdateContent(const uint32_t & unicode)316 void UpdateContent(const uint32_t& unicode) 317 { 318 if (spanItem_->unicode == unicode) { 319 return; 320 } 321 spanItem_->unicode = unicode; 322 RequestTextFlushDirty(); 323 } 324 UpdateContent(const std::string & content)325 void UpdateContent(const std::string& content) 326 { 327 if (spanItem_->content == content) { 328 return; 329 } 330 spanItem_->content = content; 331 RequestTextFlushDirty(); 332 } 333 UpdateOnClickEvent(GestureEventFunc && onClick)334 void UpdateOnClickEvent(GestureEventFunc&& onClick) 335 { 336 spanItem_->onClick = std::move(onClick); 337 } 338 OnInspectorIdUpdate(const std::string & inspectorId)339 void OnInspectorIdUpdate(const std::string& inspectorId) override 340 { 341 spanItem_->inspectId = inspectorId; 342 } 343 OnAutoEventParamUpdate(const std::string & desc)344 void OnAutoEventParamUpdate(const std::string& desc) override 345 { 346 spanItem_->description = desc; 347 } 348 349 DEFINE_SPAN_FONT_STYLE_ITEM(FontSize, Dimension); 350 DEFINE_SPAN_FONT_STYLE_ITEM(TextColor, Color); 351 DEFINE_SPAN_FONT_STYLE_ITEM(ItalicFontStyle, Ace::FontStyle); 352 DEFINE_SPAN_FONT_STYLE_ITEM(FontWeight, FontWeight); 353 DEFINE_SPAN_FONT_STYLE_ITEM(FontFamily, std::vector<std::string>); 354 DEFINE_SPAN_FONT_STYLE_ITEM(TextDecoration, TextDecoration); 355 DEFINE_SPAN_FONT_STYLE_ITEM(TextDecorationStyle, TextDecorationStyle); 356 DEFINE_SPAN_FONT_STYLE_ITEM(TextDecorationColor, Color); 357 DEFINE_SPAN_FONT_STYLE_ITEM(TextCase, TextCase); 358 DEFINE_SPAN_FONT_STYLE_ITEM(TextShadow, std::vector<Shadow>); 359 DEFINE_SPAN_FONT_STYLE_ITEM(LetterSpacing, Dimension); 360 DEFINE_SPAN_FONT_STYLE_ITEM(SymbolColorList, std::vector<Color>); 361 DEFINE_SPAN_FONT_STYLE_ITEM(SymbolRenderingStrategy, uint32_t); 362 DEFINE_SPAN_FONT_STYLE_ITEM(SymbolEffectStrategy, uint32_t); 363 DEFINE_SPAN_TEXT_LINE_STYLE_ITEM(LineHeight, Dimension); 364 DEFINE_SPAN_TEXT_LINE_STYLE_ITEM(TextAlign, TextAlign); 365 DEFINE_SPAN_TEXT_LINE_STYLE_ITEM(LeadingMargin, LeadingMargin); 366 367 // Mount to the previous Span node or Text node. 368 void MountToParagraph(); 369 AddChildSpanItem(const RefPtr<SpanNode> & child)370 void AddChildSpanItem(const RefPtr<SpanNode>& child) 371 { 372 spanItem_->children.emplace_back(child->GetSpanItem()); 373 } 374 CleanSpanItemChildren()375 void CleanSpanItemChildren() 376 { 377 spanItem_->children.clear(); 378 } 379 ToJsonValue(std::unique_ptr<JsonValue> & json)380 void ToJsonValue(std::unique_ptr<JsonValue>& json) const override 381 { 382 spanItem_->ToJsonValue(json); 383 } 384 385 void RequestTextFlushDirty(); 386 static void RequestTextFlushDirty(const RefPtr<UINode>& node); 387 // The function is only used for fast preview. FastPreviewUpdateChildDone()388 void FastPreviewUpdateChildDone() override 389 { 390 RequestTextFlushDirty(); 391 } 392 AddPropertyInfo(PropertyInfo value)393 void AddPropertyInfo(PropertyInfo value) 394 { 395 propertyInfo_.insert(value); 396 } 397 CleanPropertyInfo()398 void CleanPropertyInfo() 399 { 400 propertyInfo_.clear(); 401 } 402 MarkTextDirty()403 void MarkTextDirty() override 404 { 405 RequestTextFlushDirty(); 406 } 407 CalculateInheritPropertyInfo()408 std::set<PropertyInfo> CalculateInheritPropertyInfo() 409 { 410 std::set<PropertyInfo> inheritPropertyInfo; 411 const std::set<PropertyInfo> propertyInfoContainer = { PropertyInfo::FONTSIZE, PropertyInfo::FONTCOLOR, 412 PropertyInfo::FONTSTYLE, PropertyInfo::FONTWEIGHT, PropertyInfo::FONTFAMILY, PropertyInfo::TEXTDECORATION, 413 PropertyInfo::TEXTCASE, PropertyInfo::LETTERSPACE, PropertyInfo::LINEHEIGHT, PropertyInfo::TEXT_ALIGN, 414 PropertyInfo::LEADING_MARGIN, PropertyInfo::TEXTSHADOW, PropertyInfo::SYMBOL_COLOR, 415 PropertyInfo::SYMBOL_RENDERING_STRATEGY, PropertyInfo::SYMBOL_EFFECT_STRATEGY }; 416 set_difference(propertyInfoContainer.begin(), propertyInfoContainer.end(), propertyInfo_.begin(), 417 propertyInfo_.end(), inserter(inheritPropertyInfo, inheritPropertyInfo.begin())); 418 return inheritPropertyInfo; 419 } 420 421 private: 422 std::list<RefPtr<SpanNode>> spanChildren_; 423 std::set<PropertyInfo> propertyInfo_; 424 425 RefPtr<SpanItem> spanItem_ = MakeRefPtr<SpanItem>(); 426 427 ACE_DISALLOW_COPY_AND_MOVE(SpanNode); 428 }; 429 430 struct PlaceholderSpanItem : public SpanItem { 431 DECLARE_ACE_TYPE(PlaceholderSpanItem, SpanItem); 432 433 public: 434 int32_t placeholderSpanNodeId = -1; 435 TextStyle textStyle; 436 PlaceholderSpanItem() = default; 437 ~PlaceholderSpanItem() override = default; ToJsonValuePlaceholderSpanItem438 void ToJsonValue(std::unique_ptr<JsonValue>& json) const override {}; 439 int32_t UpdateParagraph(const RefPtr<FrameNode>& frameNode, const RefPtr<Paragraph>& builder, double width, 440 double height, VerticalAlign verticalAlign) override; 441 ACE_DISALLOW_COPY_AND_MOVE(PlaceholderSpanItem); 442 }; 443 444 class PlaceholderSpanPattern : public Pattern { 445 DECLARE_ACE_TYPE(PlaceholderSpanPattern, Pattern); 446 447 public: 448 PlaceholderSpanPattern() = default; 449 ~PlaceholderSpanPattern() override = default; 450 IsAtomicNode()451 bool IsAtomicNode() const override 452 { 453 return false; 454 } 455 }; 456 457 class ACE_EXPORT PlaceholderSpanNode : public FrameNode { 458 DECLARE_ACE_TYPE(PlaceholderSpanNode, FrameNode); 459 460 public: GetOrCreateSpanNode(const std::string & tag,int32_t nodeId,const std::function<RefPtr<Pattern> (void)> & patternCreator)461 static RefPtr<PlaceholderSpanNode> GetOrCreateSpanNode( 462 const std::string& tag, int32_t nodeId, const std::function<RefPtr<Pattern>(void)>& patternCreator) 463 { 464 auto frameNode = GetFrameNode(tag, nodeId); 465 CHECK_NULL_RETURN(!frameNode, AceType::DynamicCast<PlaceholderSpanNode>(frameNode)); 466 auto pattern = patternCreator ? patternCreator() : MakeRefPtr<Pattern>(); 467 auto placeholderSpanNode = AceType::MakeRefPtr<PlaceholderSpanNode>(tag, nodeId, pattern); 468 placeholderSpanNode->InitializePatternAndContext(); 469 ElementRegister::GetInstance()->AddUINode(placeholderSpanNode); 470 return placeholderSpanNode; 471 } 472 PlaceholderSpanNode(const std::string & tag,int32_t nodeId)473 PlaceholderSpanNode(const std::string& tag, int32_t nodeId) : FrameNode(tag, nodeId, AceType::MakeRefPtr<Pattern>()) 474 {} PlaceholderSpanNode(const std::string & tag,int32_t nodeId,const RefPtr<Pattern> & pattern)475 PlaceholderSpanNode(const std::string& tag, int32_t nodeId, const RefPtr<Pattern>& pattern) 476 : FrameNode(tag, nodeId, pattern) 477 {} 478 ~PlaceholderSpanNode() override = default; 479 GetSpanItem()480 const RefPtr<PlaceholderSpanItem>& GetSpanItem() const 481 { 482 return placeholderSpanItem_; 483 } 484 IsAtomicNode()485 bool IsAtomicNode() const override 486 { 487 return false; 488 } 489 490 private: 491 RefPtr<PlaceholderSpanItem> placeholderSpanItem_ = MakeRefPtr<PlaceholderSpanItem>(); 492 493 ACE_DISALLOW_COPY_AND_MOVE(PlaceholderSpanNode); 494 }; 495 496 struct ImageSpanItem : public PlaceholderSpanItem { 497 DECLARE_ACE_TYPE(ImageSpanItem, PlaceholderSpanItem); 498 499 public: 500 ImageSpanItem() = default; 501 ~ImageSpanItem() override = default; 502 int32_t UpdateParagraph(const RefPtr<FrameNode>& frameNode, const RefPtr<Paragraph>& builder, double width, 503 double height, VerticalAlign verticalAlign) override; ToJsonValueImageSpanItem504 void ToJsonValue(std::unique_ptr<JsonValue>& json) const override {}; 505 void UpdatePlaceholderBackgroundStyle(const RefPtr<FrameNode>& imageNode); 506 ACE_DISALLOW_COPY_AND_MOVE(ImageSpanItem); 507 }; 508 509 class ACE_EXPORT ImageSpanNode : public FrameNode { 510 DECLARE_ACE_TYPE(ImageSpanNode, FrameNode); 511 512 public: GetOrCreateSpanNode(const std::string & tag,int32_t nodeId,const std::function<RefPtr<Pattern> (void)> & patternCreator)513 static RefPtr<ImageSpanNode> GetOrCreateSpanNode( 514 const std::string& tag, int32_t nodeId, const std::function<RefPtr<Pattern>(void)>& patternCreator) 515 { 516 auto frameNode = GetFrameNode(tag, nodeId); 517 CHECK_NULL_RETURN(!frameNode, AceType::DynamicCast<ImageSpanNode>(frameNode)); 518 auto pattern = patternCreator ? patternCreator() : MakeRefPtr<Pattern>(); 519 auto imageSpanNode = AceType::MakeRefPtr<ImageSpanNode>(tag, nodeId, pattern); 520 imageSpanNode->InitializePatternAndContext(); 521 ElementRegister::GetInstance()->AddUINode(imageSpanNode); 522 return imageSpanNode; 523 } 524 ImageSpanNode(const std::string & tag,int32_t nodeId)525 ImageSpanNode(const std::string& tag, int32_t nodeId) : FrameNode(tag, nodeId, AceType::MakeRefPtr<ImagePattern>()) 526 {} ImageSpanNode(const std::string & tag,int32_t nodeId,const RefPtr<Pattern> & pattern)527 ImageSpanNode(const std::string& tag, int32_t nodeId, const RefPtr<Pattern>& pattern) 528 : FrameNode(tag, nodeId, pattern) 529 {} 530 ~ImageSpanNode() override = default; 531 GetSpanItem()532 const RefPtr<ImageSpanItem>& GetSpanItem() const 533 { 534 return imageSpanItem_; 535 } 536 537 private: 538 RefPtr<ImageSpanItem> imageSpanItem_ = MakeRefPtr<ImageSpanItem>(); 539 540 ACE_DISALLOW_COPY_AND_MOVE(ImageSpanNode); 541 }; 542 543 class ACE_EXPORT ContainerSpanNode : public UINode, public BaseSpan { 544 DECLARE_ACE_TYPE(ContainerSpanNode, UINode, BaseSpan); 545 546 public: GetOrCreateSpanNode(int32_t nodeId)547 static RefPtr<ContainerSpanNode> GetOrCreateSpanNode(int32_t nodeId) 548 { 549 auto spanNode = ElementRegister::GetInstance()->GetSpecificItemById<ContainerSpanNode>(nodeId); 550 if (spanNode) { 551 spanNode->SetHasTextBackgroundStyle(false); 552 return spanNode; 553 } 554 spanNode = MakeRefPtr<ContainerSpanNode>(nodeId); 555 ElementRegister::GetInstance()->AddUINode(spanNode); 556 return spanNode; 557 } 558 ContainerSpanNode(int32_t nodeId)559 explicit ContainerSpanNode(int32_t nodeId) : UINode(V2::CONTAINER_SPAN_ETS_TAG, nodeId), BaseSpan(nodeId) {} 560 ~ContainerSpanNode() override = default; 561 562 void ToJsonValue(std::unique_ptr<JsonValue>& json) const override; 563 IsAtomicNode()564 bool IsAtomicNode() const override 565 { 566 return false; 567 } 568 MarkTextDirty()569 void MarkTextDirty() override 570 { 571 SpanNode::RequestTextFlushDirty(Claim(this)); 572 } 573 574 private: 575 ACE_DISALLOW_COPY_AND_MOVE(ContainerSpanNode); 576 }; 577 } // namespace OHOS::Ace::NG 578 579 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_SYNTAX_FOR_EACH_NODE_H 580