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