• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_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_paint_method.h"
22 #include "core/components_ng/pattern/loading_progress/loading_progress_paint_property.h"
23 #include "core/components_ng/pattern/pattern.h"
24 #include "core/components_ng/property/property.h"
25 
26 namespace OHOS::Ace::NG {
27 // ProgressPattern is the base class for text render node to perform paint progress.
28 class LoadingProgressPattern : public Pattern {
29     DECLARE_ACE_TYPE(LoadingProgressPattern, Pattern);
30 
31 public:
32     LoadingProgressPattern() = default;
33     ~LoadingProgressPattern() override = default;
34 
CreateNodePaintMethod()35     RefPtr<NodePaintMethod> CreateNodePaintMethod() override
36     {
37         if (!loadingProgressModifier_) {
38             auto host = GetHost();
39             CHECK_NULL_RETURN(host, nullptr);
40             auto paintProperty = GetPaintProperty<LoadingProgressPaintProperty>();
41             CHECK_NULL_RETURN(paintProperty, nullptr);
42             auto loadingOwner =
43                 paintProperty->GetLoadingProgressOwner().value_or(LoadingProgressOwner::SELF);
44             loadingProgressModifier_ = AceType::MakeRefPtr<LoadingProgressModifier>(loadingOwner);
45         }
46         return MakeRefPtr<LoadingProgressPaintMethod>(loadingProgressModifier_);
47     }
48 
CreateLayoutProperty()49     RefPtr<LayoutProperty> CreateLayoutProperty() override
50     {
51         return MakeRefPtr<LoadingProgressLayoutProperty>();
52     }
53 
CreateLayoutAlgorithm()54     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
55     {
56         return MakeRefPtr<LoadingProgressLayoutAlgorithm>();
57     }
58 
CreatePaintProperty()59     RefPtr<PaintProperty> CreatePaintProperty() override
60     {
61         return MakeRefPtr<LoadingProgressPaintProperty>();
62     }
63 
64     void OnVisibleChange(bool isVisible) override;
65 
GetFocusPattern()66     FocusPattern GetFocusPattern() const override
67     {
68         return { FocusType::NODE, true };
69     }
70 private:
71     void RegisterVisibleAreaChange();
72     bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, bool skipMeasure, bool skipLayout) override;
73     void OnAttachToFrameNode() override;
74     void OnDetachFromFrameNode(FrameNode* frameNode) override;
75     void OnModifyDone() override;
76     void OnWindowHide() override;
77     void OnWindowShow() override;
78     void StartAnimation();
79     void StopAnimation();
80 
81     bool hasVisibleChangeRegistered_ = false;
82     bool enableLoading_ = true;
83     bool isVisibleArea_ = false;
84     bool isVisible_ = true;
85     bool isShow_ = true;
86     RefPtr<LoadingProgressModifier> loadingProgressModifier_;
87     ACE_DISALLOW_COPY_AND_MOVE(LoadingProgressPattern);
88 };
89 } // namespace OHOS::Ace::NG
90 
91 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_LOADING_PROGRESS_LOADING_PROGRESS_PATTERN_H
92