1 /* 2 * Copyright (c) 2022-2023 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_LOADING_PROGRESS_LOADING_PROGRESS_PAINT_PROPERTY_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_LOADING_PROGRESS_LOADING_PROGRESS_PAINT_PROPERTY_H 18 19 #include "base/geometry/dimension.h" 20 #include "core/components/progress/progress_theme.h" 21 #include "core/components_ng/base/inspector_filter.h" 22 #include "core/components_ng/pattern/loading_progress/loading_progress_owner.h" 23 #include "core/components_ng/pattern/loading_progress/loading_progress_style.h" 24 #include "core/components_ng/pattern/refresh/refresh_animation_state.h" 25 #include "core/components_ng/property/property.h" 26 #include "core/components_ng/render/paint_property.h" 27 #include "core/pipeline_ng/pipeline_context.h" 28 29 namespace OHOS::Ace::NG { 30 31 class ACE_EXPORT LoadingProgressPaintProperty : public PaintProperty { 32 DECLARE_ACE_TYPE(LoadingProgressPaintProperty, PaintProperty); 33 34 public: 35 LoadingProgressPaintProperty() = default; 36 37 ~LoadingProgressPaintProperty() override = default; 38 Clone()39 RefPtr<PaintProperty> Clone() const override 40 { 41 auto paintProperty = MakeRefPtr<LoadingProgressPaintProperty>(); 42 paintProperty->propColor_ = CloneColor(); 43 paintProperty->propEnableLoading_ = CloneEnableLoading(); 44 paintProperty->propLoadingProgressOwner_ = CloneLoadingProgressOwner(); 45 paintProperty->propRefreshAnimationState_ = CloneRefreshAnimationState(); 46 paintProperty->propRefreshSizeScaleRatio_ = CloneRefreshSizeScaleRatio(); 47 return paintProperty; 48 } 49 Reset()50 void Reset() override 51 { 52 PaintProperty::Reset(); 53 ResetColor(); 54 ResetEnableLoading(); 55 ResetLoadingProgressOwner(); 56 ResetRefreshAnimationState(); 57 ResetRefreshSizeScaleRatio(); 58 } 59 ToJsonValue(std::unique_ptr<JsonValue> & json,const InspectorFilter & filter)60 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override 61 { 62 PaintProperty::ToJsonValue(json, filter); 63 /* no fixed attr below, just return */ 64 if (filter.IsFastFilter()) { 65 return; 66 } 67 auto pipeline = PipelineBase::GetCurrentContext(); 68 CHECK_NULL_VOID(pipeline); 69 auto progressTheme = pipeline->GetTheme<ProgressTheme>(); 70 CHECK_NULL_VOID(progressTheme); 71 72 json->PutExtAttr("color", 73 propColor_.value_or(progressTheme->GetLoadingColor()).ColorToString().c_str(), filter); 74 json->PutExtAttr("enableLoading", GetEnableLoading().value_or(true) ? "true" : "false", filter); 75 } 76 77 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Color, Color, PROPERTY_UPDATE_RENDER); 78 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(EnableLoading, bool, PROPERTY_UPDATE_RENDER); 79 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(LoadingProgressOwner, LoadingProgressOwner, PROPERTY_UPDATE_RENDER); 80 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(RefreshAnimationState, RefreshAnimationState, PROPERTY_UPDATE_RENDER); 81 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(RefreshSizeScaleRatio, float, PROPERTY_UPDATE_RENDER); 82 }; 83 } // namespace OHOS::Ace::NG 84 85 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_LOADING_PROGRESS_LOADING_PROGRESS_PAINT_PROPERTY_H 86