1 /* 2 * Copyright (c) 2021 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_BRIDGE_COMMON_DOM_DOM_SPAN_H 17 #define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_SPAN_H 18 19 #include "core/components/declaration/span/span_declaration.h" 20 #include "core/components/text_span/text_span_component.h" 21 #include "frameworks/bridge/common/dom/dom_node.h" 22 #include "frameworks/bridge/common/dom/dom_type.h" 23 24 namespace OHOS::Ace::Framework { 25 26 class DOMSpan final : public DOMNode { 27 DECLARE_ACE_TYPE(DOMSpan, DOMNode); 28 29 public: 30 DOMSpan(NodeId nodeId, const std::string& nodeName); 31 ~DOMSpan() override = default; 32 HasSetFontStyle()33 bool HasSetFontStyle() const 34 { 35 auto declaration = AceType::DynamicCast<SpanDeclaration>(declaration_); 36 return declaration ? declaration->HasSetFontStyle() : false; 37 } 38 HasSetFontColor()39 bool HasSetFontColor() const 40 { 41 auto declaration = AceType::DynamicCast<SpanDeclaration>(declaration_); 42 return declaration ? declaration->HasSetFontColor() : false; 43 } 44 HasSetFontWeight()45 bool HasSetFontWeight() const 46 { 47 auto declaration = AceType::DynamicCast<SpanDeclaration>(declaration_); 48 return declaration ? declaration->HasSetFontWeight() : false; 49 } 50 HasSetFontSize()51 bool HasSetFontSize() const 52 { 53 auto declaration = AceType::DynamicCast<SpanDeclaration>(declaration_); 54 return declaration ? declaration->HasSetFontSize() : false; 55 } 56 HasSetFontFamily()57 bool HasSetFontFamily() const 58 { 59 auto declaration = AceType::DynamicCast<SpanDeclaration>(declaration_); 60 return declaration ? declaration->HasSetFontFamily() : false; 61 } 62 HasSetTextDecoration()63 bool HasSetTextDecoration() const 64 { 65 auto declaration = AceType::DynamicCast<SpanDeclaration>(declaration_); 66 return declaration ? declaration->HasSetTextDecoration() : false; 67 } 68 HasSetAllowScale()69 bool HasSetAllowScale() const 70 { 71 auto declaration = AceType::DynamicCast<SpanDeclaration>(declaration_); 72 return declaration ? declaration->HasSetAllowScale() : false; 73 } 74 HasSetFontFeatures()75 bool HasSetFontFeatures() const 76 { 77 auto declaration = AceType::DynamicCast<SpanDeclaration>(declaration_); 78 return declaration ? declaration->HasSetFontFeatures() : false; 79 } 80 SetTextStyle(const TextStyle & spanStyle)81 void SetTextStyle(const TextStyle& spanStyle) 82 { 83 if (declaration_) { 84 auto& specializedStyle = declaration_->MaybeResetStyle<SpanStyle>(StyleTag::SPECIALIZED_STYLE); 85 if (specializedStyle.IsValid()) { 86 specializedStyle.spanStyle = spanStyle; 87 } 88 } 89 } 90 GetSpecializedComponent()91 RefPtr<Component> GetSpecializedComponent() override 92 { 93 return textSpanChild_; 94 } 95 96 protected: 97 void PrepareSpecializedComponent() override; 98 void OnChildNodeAdded(const RefPtr<DOMNode>& child, int32_t slot) override; 99 void OnChildNodeRemoved(const RefPtr<DOMNode>& child) override; 100 void ResetInitializedStyle() override; 101 102 private: 103 void CheckAndSetCurrentSpanStyle( 104 const RefPtr<DOMSpan>& domSpan, TextStyle& currentStyle, const TextStyle& parentStyle); 105 106 std::list<RefPtr<DOMNode>> children_; 107 RefPtr<TextSpanComponent> textSpanChild_; 108 }; 109 110 } // namespace OHOS::Ace::Framework 111 112 #endif // FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_SPAN_H 113