• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_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/property/property.h"
24 #include "core/components_ng/render/paint_property.h"
25 #include "core/pipeline_ng/pipeline_context.h"
26 
27 namespace OHOS::Ace::NG {
28 
29 class ACE_EXPORT LoadingProgressPaintProperty : public PaintProperty {
30     DECLARE_ACE_TYPE(LoadingProgressPaintProperty, PaintProperty);
31 
32 public:
33     LoadingProgressPaintProperty() = default;
34 
35     ~LoadingProgressPaintProperty() override = default;
36 
Clone()37     RefPtr<PaintProperty> Clone() const override
38     {
39         auto paintProperty = MakeRefPtr<LoadingProgressPaintProperty>();
40         paintProperty->propColor_ = CloneColor();
41         paintProperty->propLoadingProgressOwner_ = CloneLoadingProgressOwner();
42         paintProperty->propRefreshAnimationState_ = CloneRefreshAnimationState();
43         paintProperty->propRefreshFollowRatio_ = CloneRefreshFollowRatio();
44         paintProperty->propRefreshTransitionRatio_ = CloneRefreshTransitionRatio();
45         paintProperty->propRefreshFadeAwayRatio_ = CloneRefreshFadeAwayRatio();
46         return paintProperty;
47     }
48 
Reset()49     void Reset() override
50     {
51         PaintProperty::Reset();
52         ResetColor();
53         ResetLoadingProgressOwner();
54         ResetRefreshAnimationState();
55         ResetRefreshFollowRatio();
56         ResetRefreshTransitionRatio();
57         ResetRefreshFadeAwayRatio();
58     }
59 
ToJsonValue(std::unique_ptr<JsonValue> & json)60     void ToJsonValue(std::unique_ptr<JsonValue>& json) const override
61     {
62         PaintProperty::ToJsonValue(json);
63 
64         auto pipeline = PipelineBase::GetCurrentContext();
65         CHECK_NULL_VOID(pipeline);
66         auto progressTheme = pipeline->GetTheme<ProgressTheme>();
67         CHECK_NULL_VOID(progressTheme);
68 
69         json->Put("color", propColor_.value_or(progressTheme->GetLoadingColor()).ColorToString().c_str());
70     }
71 
72     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Color, Color, PROPERTY_UPDATE_MEASURE);
73     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(LoadingProgressOwner, LoadingProgressOwner, PROPERTY_UPDATE_RENDER);
74     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(RefreshAnimationState, int32_t, PROPERTY_UPDATE_RENDER);
75     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(RefreshFollowRatio, float, PROPERTY_UPDATE_RENDER);
76     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(RefreshTransitionRatio, float, PROPERTY_UPDATE_RENDER);
77     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(RefreshFadeAwayRatio, float, PROPERTY_UPDATE_RENDER);
78 };
79 } // namespace OHOS::Ace::NG
80 
81 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_LOADING_PROGRESS_LOADING_PROGRESS_PAINT_PROPERTY_H
82