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_grid_row.h"
17 
18 #include "core/components/common/layout/grid_system_manager.h"
19 #include "frameworks/bridge/common/dom/dom_grid_column.h"
20 #include "frameworks/bridge/common/dom/dom_reflect_map.h"
21 
22 namespace OHOS::Ace::Framework {
23 
DomGridRow(NodeId nodeId,const std::string & nodeName)24 DomGridRow::DomGridRow(NodeId nodeId, const std::string& nodeName) : DOMDiv(nodeId, nodeName) {}
25 
SetParentGridInfo(const RefPtr<GridContainerInfo> & parent)26 void DomGridRow::SetParentGridInfo(const RefPtr<GridContainerInfo>& parent)
27 {
28     if (columnType_ != GridColumnType::NONE) {
29         auto info = GridSystemManager::GetInstance().GetInfoByType(columnType_);
30         gridContainerInfo_ = info->GetParent();
31         boxComponent_->SetGridLayoutInfo(gridContainerInfo_);
32     } else {
33         gridContainerInfo_ = parent;
34     }
35 }
36 
OnChildNodeAdded(const RefPtr<DOMNode> & child,int32_t slot)37 void DomGridRow::OnChildNodeAdded(const RefPtr<DOMNode>& child, int32_t slot)
38 {
39     ACE_DCHECK(child);
40     DOMDiv::OnChildNodeAdded(child, slot);
41 
42     auto gridColumn = AceType::DynamicCast<DomGridColumn>(child);
43     if (gridColumn) {
44         gridColumn->SetParentGridInfo(gridContainerInfo_);
45     }
46 }
47 
OnChildNodeRemoved(const RefPtr<DOMNode> & child)48 void DomGridRow::OnChildNodeRemoved(const RefPtr<DOMNode>& child)
49 {
50     ACE_DCHECK(child);
51     DOMDiv::OnChildNodeRemoved(child);
52     auto gridColumn = AceType::DynamicCast<DomGridColumn>(child);
53     if (gridColumn) {
54         gridColumn->SetParentGridInfo(nullptr);
55     }
56 }
57 
SetSpecializedAttr(const std::pair<std::string,std::string> & attr)58 bool DomGridRow::SetSpecializedAttr(const std::pair<std::string, std::string>& attr)
59 {
60     if (attr.first == DOM_GRID_COLUMN_TYPE) {
61         auto iter = GridColumnTypeMap.find(attr.second);
62         if (iter != GridColumnTypeMap.end()) {
63             columnType_ = iter->second;
64         }
65         return true;
66     }
67     return false;
68 }
69 
SetSpecializedStyle(const std::pair<std::string,std::string> & style)70 bool DomGridRow::SetSpecializedStyle(const std::pair<std::string, std::string>& style)
71 {
72     static const std::list<const char*> notSupportStyles {
73         DOM_GRID_COLUMN_END,
74         DOM_GRID_COLUMN_START,
75         DOM_GRID_COLUMN_GAP,
76         DOM_GRID_ROW_END,
77         DOM_GRID_ROW_START,
78         DOM_GRID_ROW_GAP,
79         DOM_GRID_TEMPLATE_COLUMNS,
80         DOM_GRID_TEMPLATE_ROWS,
81     };
82 
83     if (std::find(notSupportStyles.begin(), notSupportStyles.end(), style.first.c_str()) != notSupportStyles.end()) {
84         // not support
85         return true;
86     }
87 
88     return DOMDiv::SetSpecializedStyle(style);
89 }
90 
91 } // namespace OHOS::Ace::Framework
92