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_NG_PATTERN_GRID_CONTAINER_LAYOUT_PROPERTY_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_GRID_CONTAINER_LAYOUT_PROPERTY_H 18 19 #include <memory> 20 #include <vector> 21 22 #include "../linear_layout/linear_layout_property.h" 23 24 #include "core/components_ng/base/frame_node.h" 25 #include "core/components_ng/property/property.h" 26 #include "frameworks/core/components/common/layout/grid_container_info.h" 27 28 namespace OHOS::Ace::NG { 29 30 class ACE_EXPORT GridContainerLayoutProperty : public LinearLayoutProperty { 31 DECLARE_ACE_TYPE(GridContainerLayoutProperty, LinearLayoutProperty); 32 33 public: GridContainerLayoutProperty()34 GridContainerLayoutProperty() : LinearLayoutProperty(true) 35 { 36 reserveProperty_ = WeakClaim(this); 37 } 38 39 ~GridContainerLayoutProperty() override = default; 40 41 bool operator==(const GridContainerLayoutProperty& other) const 42 { 43 return (propContainerInfo_ == other.propContainerInfo_); 44 } 45 Clone()46 RefPtr<LayoutProperty> Clone() const override 47 { 48 auto value = MakeRefPtr<GridContainerLayoutProperty>(); 49 LinearLayoutProperty::Clone(value); 50 value->propContainerInfo_ = propContainerInfo_; 51 value->childrenFramenode_ = childrenFramenode_; 52 return value; 53 } 54 Reset()55 void Reset() override 56 { 57 childrenFramenode_.clear(); 58 ResetContainerInfo(); 59 LinearLayoutProperty::Reset(); 60 } 61 62 void ToJsonValue(std::unique_ptr<JsonValue>& json) const override; 63 64 void UpdateChild(RefPtr<GridProperty>& child, const GridContainerInfo& info); 65 void RegistGridChild(const RefPtr<FrameNode>& child); 66 void BuildWidth(float width); SetReserveObj(const RefPtr<GridContainerLayoutProperty> & obj)67 void SetReserveObj(const RefPtr<GridContainerLayoutProperty>& obj) 68 { 69 reserveProperty_ = obj; 70 } GetReserveObj()71 RefPtr<GridContainerLayoutProperty> GetReserveObj() 72 { 73 auto obj = reserveProperty_.Upgrade(); 74 return obj ? obj : Claim(this); 75 } SetGlobalOffset(const OffsetF & offset)76 void SetGlobalOffset(const OffsetF& offset) 77 { 78 globalOffset_ = offset; 79 } GetGlobalOffset()80 const OffsetF& GetGlobalOffset() 81 { 82 return globalOffset_; 83 } 84 85 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP_AND_USING_CALLBACK( 86 ContainerInfo, GridContainerInfo, PROPERTY_UPDATE_MEASURE_SELF); 87 88 private: 89 void OnContainerInfoUpdate(const GridContainerInfo& info); 90 std::vector<WeakPtr<FrameNode>> childrenFramenode_; 91 WeakPtr<GridContainerLayoutProperty> reserveProperty_; // the layout property that will be active on next vsync 92 OffsetF globalOffset_; 93 ACE_DISALLOW_COPY_AND_MOVE(GridContainerLayoutProperty); 94 }; 95 } // namespace OHOS::Ace::NG 96 #endif