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, WeakClaim(this)); 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 void UpdateColor(const Color& color, bool isFristLoad = false); 97 SetForegroundColorParseFailed(bool isParseFailed)98 void SetForegroundColorParseFailed(bool isParseFailed) 99 { 100 CHECK_NULL_VOID(loadingProgressModifier_); 101 loadingProgressModifier_->SetForegroundColorParseFailed(isParseFailed); 102 } 103 SetColorLock(bool colorLock)104 void SetColorLock(bool colorLock) 105 { 106 colorLock_ = colorLock; 107 } 108 IsEnableMatchParent()109 bool IsEnableMatchParent() override 110 { 111 return true; 112 } 113 IsEnableFix()114 bool IsEnableFix() override 115 { 116 return true; 117 } 118 119 private: 120 void RegisterVisibleAreaChange(); 121 bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, bool skipMeasure, bool skipLayout) override; 122 void OnAttachToFrameNode() override; 123 void OnDetachFromFrameNode(FrameNode* frameNode) override; 124 void OnAttachToMainTree() override; 125 void OnDetachFromMainTree() override; 126 OnAttachToFrameNodeMultiThread()127 void OnAttachToFrameNodeMultiThread() {} OnDetachFromFrameNodeMultiThread(FrameNode * frameNode)128 void OnDetachFromFrameNodeMultiThread(FrameNode* frameNode) {} 129 void OnAttachToMainTreeMultiThread(); 130 void OnDetachFromMainTreeMultiThread(); 131 void OnModifyDone() override; 132 void OnWindowHide() override; 133 void OnWindowShow() override; 134 void DumpInfo() override; 135 void DumpInfo(std::unique_ptr<JsonValue>& json) override; DumpSimplifyInfo(std::shared_ptr<JsonValue> & json)136 void DumpSimplifyInfo(std::shared_ptr<JsonValue>& json) override {} 137 void StartAnimation(); 138 void StopAnimation(); 139 void FireBuilder(); 140 RefPtr<FrameNode> BuildContentModifierNode(); 141 void InitThemeValues(); 142 void InitFocusEvent(); 143 void HandleFocusEvent(); 144 void HandleBlurEvent(); 145 void SetFocusStyle(); 146 void ClearFocusStyle(); 147 void AddIsFocusActiveUpdateEvent(); 148 void RemoveIsFocusActiveUpdateEvent(); 149 void OnColorConfigurationUpdate() override; 150 151 Color defaultColor_; 152 Color focusedColor_; 153 bool isFocusColorSet_ = false; 154 std::function<void(bool)> isFocusActiveUpdateEvent_; 155 156 std::optional<LoadingProgressMakeCallback> makeFunc_; 157 RefPtr<FrameNode> contentModifierNode_; 158 159 bool hasVisibleChangeRegistered_ = false; 160 bool enableLoading_ = true; 161 bool isVisibleArea_ = false; 162 bool isVisible_ = true; 163 bool isShow_ = true; 164 bool colorLock_ = false; 165 RefPtr<LoadingProgressModifier> loadingProgressModifier_; 166 ACE_DISALLOW_COPY_AND_MOVE(LoadingProgressPattern); 167 }; 168 } // namespace OHOS::Ace::NG 169 170 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_LOADING_PROGRESS_LOADING_PROGRESS_PATTERN_H 171