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_DIVIDER_DIVIDER_LAYOUT_PROPERTY_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_DIVIDER_DIVIDER_LAYOUT_PROPERTY_H 18 19 #include "core/common/container.h" 20 #include "core/components_ng/base/inspector_filter.h" 21 #include "core/components_ng/layout/layout_property.h" 22 #include "core/pipeline/pipeline_base.h" 23 24 namespace OHOS::Ace::NG { 25 class ACE_EXPORT DividerLayoutProperty : public LayoutProperty { 26 DECLARE_ACE_TYPE(DividerLayoutProperty, LayoutProperty); 27 28 public: 29 DividerLayoutProperty() = default; 30 ~DividerLayoutProperty() override = default; Clone()31 RefPtr<LayoutProperty> Clone() const override 32 { 33 auto value = MakeRefPtr<DividerLayoutProperty>(); 34 value->LayoutProperty::UpdateLayoutProperty(DynamicCast<LayoutProperty>(this)); 35 value->propVertical_ = CloneVertical(); 36 value->propStrokeWidth_ = CloneStrokeWidth(); 37 value->propStrokeWidthLimitation_ = CloneStrokeWidthLimitation(); 38 return value; 39 } 40 Reset()41 void Reset() override 42 { 43 LayoutProperty::Reset(); 44 ResetVertical(); 45 ResetStrokeWidth(); 46 ResetStrokeWidthLimitation(); 47 } 48 ToJsonValue(std::unique_ptr<JsonValue> & json,const InspectorFilter & filter)49 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override 50 { 51 LayoutProperty::ToJsonValue(json, filter); 52 /* no fixed attr below, just return */ 53 if (filter.IsFastFilter()) { 54 return; 55 } 56 json->PutExtAttr("vertical", propVertical_.value_or(true) ? "true" : "false", filter); 57 json->PutExtAttr("strokeWidth", 58 propStrokeWidth_ 59 .value_or( 60 Dimension(1, Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TEN) ? DimensionUnit::PX 61 : DimensionUnit::VP)) 62 .ToString() 63 .c_str(), filter); 64 } 65 FromJson(const std::unique_ptr<JsonValue> & json)66 void FromJson(const std::unique_ptr<JsonValue>& json) override 67 { 68 UpdateVertical(json->GetString("vertical") == "true"); 69 UpdateStrokeWidth(Dimension::FromString(json->GetString("strokeWidth"))); 70 LayoutProperty::FromJson(json); 71 } 72 73 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Vertical, bool, PROPERTY_UPDATE_MEASURE); 74 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(StrokeWidth, Dimension, PROPERTY_UPDATE_MEASURE); 75 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(StrokeWidthLimitation, bool, PROPERTY_UPDATE_MEASURE); 76 77 private: 78 ACE_DISALLOW_COPY_AND_MOVE(DividerLayoutProperty); 79 }; 80 } // namespace OHOS::Ace::NG 81 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_DIVIDER_DIVIDER_LAYOUT_PROPERTY_H 82