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