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_PATTERNS_PROGRESS_PROGRESS_LAYOUT_PROPERTY_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_PROGRESS_PROGRESS_LAYOUT_PROPERTY_H 18 19 #include "base/geometry/dimension.h" 20 #include "core/common/container.h" 21 #include "core/components/progress/progress_theme.h" 22 #include "core/components_ng/base/inspector_filter.h" 23 #include "core/components_ng/layout/layout_property.h" 24 #include "core/components_ng/pattern/progress/progress_date.h" 25 #include "core/pipeline/pipeline_base.h" 26 27 namespace OHOS::Ace::NG { 28 class ACE_EXPORT ProgressLayoutProperty : public LayoutProperty { 29 DECLARE_ACE_TYPE(ProgressLayoutProperty, LayoutProperty); 30 31 public: 32 ProgressLayoutProperty() = default; 33 34 ~ProgressLayoutProperty() override = default; 35 Clone()36 RefPtr<LayoutProperty> Clone() const override 37 { 38 auto value = MakeRefPtr<ProgressLayoutProperty>(); 39 value->LayoutProperty::UpdateLayoutProperty(DynamicCast<LayoutProperty>(this)); 40 value->propType_ = CloneType(); 41 value->propStrokeWidth_ = CloneStrokeWidth(); 42 return value; 43 } 44 Reset()45 void Reset() override 46 { 47 LayoutProperty::Reset(); 48 ResetType(); 49 ResetStrokeWidth(); 50 } 51 ToJsonValue(std::unique_ptr<JsonValue> & json,const InspectorFilter & filter)52 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override 53 { 54 LayoutProperty::ToJsonValue(json, filter); 55 /* no fixed attr below, just return */ 56 if (filter.IsFastFilter()) { 57 return; 58 } 59 auto pipeline = PipelineBase::GetCurrentContext(); 60 CHECK_NULL_VOID(pipeline); 61 auto progressTheme = pipeline->GetTheme<ProgressTheme>(); 62 CHECK_NULL_VOID(progressTheme); 63 64 json->PutExtAttr("type", 65 (ProgressTypeUtils::ConvertProgressTypeToString(propType_.value_or(ProgressType::LINEAR))).c_str(), filter); 66 json->PutExtAttr("strokeWidth", 67 propStrokeWidth_.value_or(progressTheme->GetTrackThickness()).ToString().c_str(), filter); 68 } 69 70 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Type, ProgressType, PROPERTY_UPDATE_MEASURE); 71 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(StrokeWidth, Dimension, PROPERTY_UPDATE_MEASURE); 72 73 private: 74 ACE_DISALLOW_COPY_AND_MOVE(ProgressLayoutProperty); 75 }; 76 } // namespace OHOS::Ace::NG 77 78 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_PROGRESS_PROGRESS_LAYOUT_PROPERTY_H 79