• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_LOADING_PROGRESS_LOADING_PROGRESS_PATTERN_H
18 
19 #include "core/components_ng/pattern/loading_progress/loading_progress_layout_algorithm.h"
20 #include "core/components_ng/pattern/loading_progress/loading_progress_layout_property.h"
21 #include "core/components_ng/pattern/loading_progress/loading_progress_model_ng.h"
22 #include "core/components_ng/pattern/loading_progress/loading_progress_paint_method.h"
23 #include "core/components_ng/pattern/loading_progress/loading_progress_paint_property.h"
24 #include "core/components_ng/pattern/pattern.h"
25 #include "core/components_ng/property/property.h"
26 
27 namespace OHOS::Ace::NG {
28 // ProgressPattern is the base class for text render node to perform paint progress.
29 class LoadingProgressPattern : public Pattern {
30     DECLARE_ACE_TYPE(LoadingProgressPattern, Pattern);
31 
32 public:
33     LoadingProgressPattern() = default;
34     ~LoadingProgressPattern() override = default;
35 
36     bool OnThemeScopeUpdate(int32_t themeScopeId) override;
37 
CreateNodePaintMethod()38     RefPtr<NodePaintMethod> CreateNodePaintMethod() override
39     {
40         if (!loadingProgressModifier_) {
41             auto host = GetHost();
42             CHECK_NULL_RETURN(host, nullptr);
43             auto paintProperty = GetPaintProperty<LoadingProgressPaintProperty>();
44             CHECK_NULL_RETURN(paintProperty, nullptr);
45             auto loadingOwner =
46                 paintProperty->GetLoadingProgressOwner().value_or(LoadingProgressOwner::SELF);
47             loadingProgressModifier_ = AceType::MakeRefPtr<LoadingProgressModifier>(loadingOwner);
48             loadingProgressModifier_->SetUseContentModifier(UseContentModifier());
49             InitThemeValues();
50         }
51         return MakeRefPtr<LoadingProgressPaintMethod>(loadingProgressModifier_);
52     }
53 
CreateLayoutProperty()54     RefPtr<LayoutProperty> CreateLayoutProperty() override
55     {
56         return MakeRefPtr<LoadingProgressLayoutProperty>();
57     }
58 
CreateLayoutAlgorithm()59     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
60     {
61         return MakeRefPtr<LoadingProgressLayoutAlgorithm>();
62     }
63 
CreatePaintProperty()64     RefPtr<PaintProperty> CreatePaintProperty() override
65     {
66         return MakeRefPtr<LoadingProgressPaintProperty>();
67     }
68 
69     void OnVisibleChange(bool isVisible) override;
70 
GetFocusPattern()71     FocusPattern GetFocusPattern() const override
72     {
73         return { FocusType::NODE, true };
74     }
75 
SetBuilderFunc(LoadingProgressMakeCallback && makeFunc)76     void SetBuilderFunc(LoadingProgressMakeCallback&& makeFunc)
77     {
78         if (makeFunc == nullptr) {
79             makeFunc_ = std::nullopt;
80             contentModifierNode_ = nullptr;
81             OnModifyDone();
82             return;
83         }
84         makeFunc_ = std::move(makeFunc);
85     }
86 
GetContentModifierNode()87     const RefPtr<FrameNode>& GetContentModifierNode() const
88     {
89         return contentModifierNode_;
90     }
91 
UseContentModifier()92     bool UseContentModifier() const
93     {
94         return contentModifierNode_ != nullptr;
95     }
96 
SetForegroundColorParseFailed(bool isParseFailed)97     void SetForegroundColorParseFailed(bool isParseFailed)
98     {
99         CHECK_NULL_VOID(loadingProgressModifier_);
100         loadingProgressModifier_->SetForegroundColorParseFailed(isParseFailed);
101     }
102 
SetColorLock(bool colorLock)103     void SetColorLock(bool colorLock)
104     {
105         colorLock_ = colorLock;
106     }
107 
108 private:
109     void RegisterVisibleAreaChange();
110     bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, bool skipMeasure, bool skipLayout) override;
111     void OnAttachToFrameNode() override;
112     void OnDetachFromFrameNode(FrameNode* frameNode) override;
113     void OnModifyDone() override;
114     void OnWindowHide() override;
115     void OnWindowShow() override;
116     void DumpInfo() override;
117     void DumpInfo(std::unique_ptr<JsonValue>& json) override;
DumpSimplifyInfo(std::unique_ptr<JsonValue> & json)118     void DumpSimplifyInfo(std::unique_ptr<JsonValue>& json) override {}
119     void StartAnimation();
120     void StopAnimation();
121     void FireBuilder();
122     RefPtr<FrameNode> BuildContentModifierNode();
123     void InitThemeValues();
124     void InitFocusEvent();
125     void HandleFocusEvent();
126     void HandleBlurEvent();
127     void SetFocusStyle();
128     void ClearFocusStyle();
129     void AddIsFocusActiveUpdateEvent();
130     void RemoveIsFocusActiveUpdateEvent();
131 
132     Color defaultColor_;
133     Color focusedColor_;
134     bool isFocusColorSet_ = false;
135     std::function<void(bool)> isFocusActiveUpdateEvent_;
136 
137     std::optional<LoadingProgressMakeCallback> makeFunc_;
138     RefPtr<FrameNode> contentModifierNode_;
139 
140     bool hasVisibleChangeRegistered_ = false;
141     bool enableLoading_ = true;
142     bool isVisibleArea_ = false;
143     bool isVisible_ = true;
144     bool isShow_ = true;
145     bool colorLock_ = false;
146     RefPtr<LoadingProgressModifier> loadingProgressModifier_;
147     ACE_DISALLOW_COPY_AND_MOVE(LoadingProgressPattern);
148 };
149 } // namespace OHOS::Ace::NG
150 
151 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_LOADING_PROGRESS_LOADING_PROGRESS_PATTERN_H
152