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