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_PATTERN_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_LOADING_PROGRESS_LOADING_PROGRESS_PATTERN_H 18 19 #include "base/log/log_wrapper.h" 20 #include "core/components_ng/pattern/loading_progress/loading_progress_layout_algorithm.h" 21 #include "core/components_ng/pattern/loading_progress/loading_progress_layout_property.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 } 47 return MakeRefPtr<LoadingProgressPaintMethod>(loadingProgressModifier_); 48 } 49 CreateLayoutProperty()50 RefPtr<LayoutProperty> CreateLayoutProperty() override 51 { 52 return MakeRefPtr<LoadingProgressLayoutProperty>(); 53 } 54 CreateLayoutAlgorithm()55 RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override 56 { 57 return MakeRefPtr<LoadingProgressLayoutAlgorithm>(); 58 } 59 CreatePaintProperty()60 RefPtr<PaintProperty> CreatePaintProperty() override 61 { 62 return MakeRefPtr<LoadingProgressPaintProperty>(); 63 } 64 65 private: 66 bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, bool skipMeasure, bool skipLayout) override; 67 void OnAttachToFrameNode() override; 68 69 RefPtr<LoadingProgressModifier> loadingProgressModifier_; 70 ACE_DISALLOW_COPY_AND_MOVE(LoadingProgressPattern); 71 }; 72 } // namespace OHOS::Ace::NG 73 74 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_LOADING_PROGRESS_LOADING_PROGRESS_PATTERN_H 75