1 /* 2 * Copyright (c) 2022-2025 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->UpdatePaintPropertyHost(this); 43 paintProperty->propColor_ = CloneColor(); 44 paintProperty->propEnableLoading_ = CloneEnableLoading(); 45 paintProperty->propLoadingProgressOwner_ = CloneLoadingProgressOwner(); 46 paintProperty->propRefreshAnimationState_ = CloneRefreshAnimationState(); 47 paintProperty->propRefreshSizeScaleRatio_ = CloneRefreshSizeScaleRatio(); 48 paintProperty->SetHost(GetHost()); 49 return paintProperty; 50 } 51 Reset()52 void Reset() override 53 { 54 PaintProperty::Reset(); 55 ResetColor(); 56 ResetEnableLoading(); 57 ResetLoadingProgressOwner(); 58 ResetRefreshAnimationState(); 59 ResetRefreshSizeScaleRatio(); 60 } 61 ToJsonValue(std::unique_ptr<JsonValue> & json,const InspectorFilter & filter)62 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override 63 { 64 PaintProperty::ToJsonValue(json, filter); 65 /* no fixed attr below, just return */ 66 if (filter.IsFastFilter()) { 67 return; 68 } 69 auto host = GetHost(); 70 auto themeScopeId = host ? host->GetThemeScopeId() : 0; 71 auto pipeline = PipelineBase::GetCurrentContext(); 72 CHECK_NULL_VOID(pipeline); 73 auto progressTheme = pipeline->GetTheme<ProgressTheme>(themeScopeId); 74 CHECK_NULL_VOID(progressTheme); 75 76 json->PutExtAttr("color", 77 propColor_.value_or(progressTheme->GetLoadingColor()).ColorToString().c_str(), filter); 78 json->PutExtAttr("foregroundColor", 79 propColor_.value_or(progressTheme->GetLoadingColor()).ColorToString().c_str(), filter); 80 json->PutExtAttr("enableLoading", GetEnableLoading().value_or(true) ? "true" : "false", filter); 81 } 82 83 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Color, Color, PROPERTY_UPDATE_RENDER); 84 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(EnableLoading, bool, PROPERTY_UPDATE_RENDER); 85 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(LoadingProgressOwner, LoadingProgressOwner, PROPERTY_UPDATE_RENDER); 86 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(RefreshAnimationState, RefreshAnimationState, PROPERTY_UPDATE_RENDER); 87 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(RefreshSizeScaleRatio, float, PROPERTY_UPDATE_RENDER); 88 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(ColorSetByUser, bool, PROPERTY_UPDATE_RENDER); 89 }; 90 } // namespace OHOS::Ace::NG 91 92 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_LOADING_PROGRESS_LOADING_PROGRESS_PAINT_PROPERTY_H 93