1 /* 2 * Copyright (c) 2022 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_CORE_COMPONENTS_RELATIVE_CONTAINER_RENDER_RELATIVE_CONTAINER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_RELATIVE_CONTAINER_RENDER_RELATIVE_CONTAINER_H 18 19 #include <typeinfo> 20 21 #include "core/components/common/layout/constants.h" 22 #include "core/components/common/properties/alignment.h" 23 #include "core/components/flex/flex_item_component.h" 24 #include "core/pipeline/base/render_node.h" 25 26 namespace OHOS::Ace { 27 using AlignRules = std::map<AlignDirection, AlignRule>; 28 using AlignRulesMap = std::map<std::string, AlignRules>; 29 class ACE_EXPORT RenderRelativeContainer : public RenderNode { 30 DECLARE_ACE_TYPE(RenderRelativeContainer, RenderNode); 31 32 public: 33 static RefPtr<RenderNode> Create(); 34 35 void Update(const RefPtr<Component>& component) override; 36 37 void PerformLayout() override; 38 GetAlignRulesMap()39 AlignRulesMap GetAlignRulesMap() const 40 { 41 return alignRulesMap_; 42 } 43 44 private: 45 void CollectNodesById(); 46 void GetDependencyRelationship(); 47 bool PreTopologicalLoopDetection(); 48 void TopologicalSort(std::list<std::string>& renderList); 49 50 void CalcHorizontalLayoutParam(AlignDirection alignDirection, const AlignRule& alignRule, 51 const std::string& nodeName); 52 void CalcVerticalLayoutParam(AlignDirection alignDirection, const AlignRule& alignRule, 53 const std::string& nodeName); 54 void CalcLayoutParam(const std::map<AlignDirection, AlignRule> alignRules, LayoutParam& itemLayout, 55 const std::string& nodeName); 56 57 double CalcHorizontalOffset(AlignDirection alignDirection, const AlignRule& alignRule, 58 double containerWidth, const std::string& nodeName); 59 double CalcVerticalOffset(AlignDirection alignDirection, const AlignRule& alignRule, 60 double containerHeight, const std::string& nodeName); 61 62 std::list<std::string> renderList_; 63 std::map<std::string, RefPtr<RenderFlexItem>> idNodeMap_; 64 std::map<std::string, uint32_t> incomingDegreeMap_; 65 // list of nodes that relied on the key node represented by string 66 std::map<std::string, std::set<std::string>> reliedOnMap_; 67 std::list<std::string> orderedRenderList_; 68 69 AlignRulesMap alignRulesMap_; 70 }; 71 72 } // namespace OHOS::Ace 73 74 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_RELATIVE_CONTAINER_RENDER_RELATIVE_CONTAINER_H 75