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