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_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 CreateNodePaintMethod()36 RefPtr<NodePaintMethod> CreateNodePaintMethod() override 37 { 38 if (!loadingProgressModifier_) { 39 auto host = GetHost(); 40 CHECK_NULL_RETURN(host, nullptr); 41 auto paintProperty = GetPaintProperty<LoadingProgressPaintProperty>(); 42 CHECK_NULL_RETURN(paintProperty, nullptr); 43 auto loadingOwner = 44 paintProperty->GetLoadingProgressOwner().value_or(LoadingProgressOwner::SELF); 45 loadingProgressModifier_ = AceType::MakeRefPtr<LoadingProgressModifier>(loadingOwner); 46 loadingProgressModifier_->SetUseContentModifier(UseContentModifier()); 47 } 48 return MakeRefPtr<LoadingProgressPaintMethod>(loadingProgressModifier_); 49 } 50 CreateLayoutProperty()51 RefPtr<LayoutProperty> CreateLayoutProperty() override 52 { 53 return MakeRefPtr<LoadingProgressLayoutProperty>(); 54 } 55 CreateLayoutAlgorithm()56 RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override 57 { 58 return MakeRefPtr<LoadingProgressLayoutAlgorithm>(); 59 } 60 CreatePaintProperty()61 RefPtr<PaintProperty> CreatePaintProperty() override 62 { 63 return MakeRefPtr<LoadingProgressPaintProperty>(); 64 } 65 66 void OnVisibleChange(bool isVisible) override; 67 GetFocusPattern()68 FocusPattern GetFocusPattern() const override 69 { 70 return { FocusType::NODE, true }; 71 } 72 SetBuilderFunc(LoadingProgressMakeCallback && makeFunc)73 void SetBuilderFunc(LoadingProgressMakeCallback&& makeFunc) 74 { 75 if (makeFunc == nullptr) { 76 makeFunc_ = std::nullopt; 77 contentModifierNode_ = nullptr; 78 OnModifyDone(); 79 return; 80 } 81 makeFunc_ = std::move(makeFunc); 82 } 83 GetContentModifierNode()84 const RefPtr<FrameNode>& GetContentModifierNode() const 85 { 86 return contentModifierNode_; 87 } 88 UseContentModifier()89 bool UseContentModifier() const 90 { 91 return contentModifierNode_ != nullptr; 92 } 93 94 private: 95 void RegisterVisibleAreaChange(); 96 bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, bool skipMeasure, bool skipLayout) override; 97 void OnAttachToFrameNode() override; 98 void OnDetachFromFrameNode(FrameNode* frameNode) override; 99 void OnModifyDone() override; 100 void OnWindowHide() override; 101 void OnWindowShow() override; 102 void DumpInfo() override; 103 void StartAnimation(); 104 void StopAnimation(); 105 void FireBuilder(); 106 RefPtr<FrameNode> BuildContentModifierNode(); 107 108 std::optional<LoadingProgressMakeCallback> makeFunc_; 109 RefPtr<FrameNode> contentModifierNode_; 110 111 bool hasVisibleChangeRegistered_ = false; 112 bool enableLoading_ = true; 113 bool isVisibleArea_ = false; 114 bool isVisible_ = true; 115 bool isShow_ = true; 116 RefPtr<LoadingProgressModifier> loadingProgressModifier_; 117 ACE_DISALLOW_COPY_AND_MOVE(LoadingProgressPattern); 118 }; 119 } // namespace OHOS::Ace::NG 120 121 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_LOADING_PROGRESS_LOADING_PROGRESS_PATTERN_H 122