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 #include "frameworks/bridge/common/dom/dom_piece.h" 17 18 #include "core/components/declaration/piece/piece_declaration.h" 19 20 namespace OHOS::Ace::Framework { 21 DOMPiece(NodeId nodeId,const std::string & nodeName)22DOMPiece::DOMPiece(NodeId nodeId, const std::string& nodeName) : DOMNode(nodeId, nodeName) 23 { 24 pieceChild_ = AceType::MakeRefPtr<PieceComponent>(); 25 } 26 ResetInitializedStyle()27void DOMPiece::ResetInitializedStyle() 28 { 29 if (declaration_) { 30 declaration_->InitializeStyle(); 31 } 32 } 33 PrepareSpecializedComponent()34void DOMPiece::PrepareSpecializedComponent() 35 { 36 auto declaration = AceType::DynamicCast<PieceDeclaration>(declaration_); 37 if (!declaration) { 38 return; 39 } 40 41 pieceChild_->SetTextDirection(declaration->IsRightToLeft() ? TextDirection::RTL : TextDirection::LTR); 42 if (!declaration->HasBackGroundColor() && declaration->HasBackground()) { 43 declaration->GetBackDecoration()->SetBackgroundColor(Color::TRANSPARENT); 44 } 45 declaration->SetMargin(GetBoxComponent()->GetMargin()); 46 if (boxComponent_->GetBackDecoration()) { 47 declaration->SetBorder(boxComponent_->GetBackDecoration()->GetBorder()); 48 } 49 50 // If content is not exist, clear style. 51 if (!declaration->HasContent()) { 52 boxComponent_->SetWidth(0.0); 53 boxComponent_->SetHeight(0.0); 54 boxComponent_->SetPadding(Edge()); 55 boxComponent_->SetMargin(Edge()); 56 } 57 58 pieceChild_->SetDeclaration(AceType::DynamicCast<PieceDeclaration>(declaration_)); 59 } 60 GetSpecializedComponent()61RefPtr<Component> DOMPiece::GetSpecializedComponent() 62 { 63 return pieceChild_; 64 } 65 66 }; // namespace OHOS::Ace::Framework 67