1 /*
2  * Copyright (c) 2024 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 #include "node_loading_progress_modifier.h"
16 
17 #include "base/error/error_code.h"
18 #include "core/components/common/layout/constants.h"
19 #include "core/components/progress/progress_theme.h"
20 #include "core/components_ng/base/frame_node.h"
21 #include "core/components_ng/pattern/loading_progress/loading_progress_model_ng.h"
22 #include "core/pipeline/base/element_register.h"
23 
24 namespace OHOS::Ace::NG {
25 namespace {
GetLoadingProgressColor(ArkUINodeHandle node)26 ArkUI_Uint32 GetLoadingProgressColor(ArkUINodeHandle node)
27 {
28     auto* frameNode = reinterpret_cast<FrameNode*>(node);
29     CHECK_NULL_RETURN(frameNode, 0x0);
30     return LoadingProgressModelNG::GetColor(frameNode);
31 }
32 
SetLoadingProgressColor(ArkUINodeHandle node,uint32_t colorValue)33 void SetLoadingProgressColor(ArkUINodeHandle node, uint32_t colorValue)
34 {
35     auto* frameNode = reinterpret_cast<FrameNode*>(node);
36     CHECK_NULL_VOID(frameNode);
37     LoadingProgressModelNG::SetColor(frameNode, Color(colorValue));
38 }
39 
ResetLoadingProgressColor(ArkUINodeHandle node)40 void ResetLoadingProgressColor(ArkUINodeHandle node)
41 {
42     auto* frameNode = reinterpret_cast<FrameNode*>(node);
43     CHECK_NULL_VOID(frameNode);
44     if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TEN)) {
45         auto pipelineContext = frameNode->GetContext();
46         CHECK_NULL_VOID(pipelineContext);
47         auto theme = pipelineContext->GetTheme<ProgressTheme>();
48         CHECK_NULL_VOID(theme);
49         LoadingProgressModelNG::SetColor(frameNode, theme->GetLoadingColor());
50     }
51 }
52 
GetEnableLoading(ArkUINodeHandle node)53 ArkUI_Bool GetEnableLoading(ArkUINodeHandle node)
54 {
55     auto* frameNode = reinterpret_cast<FrameNode*>(node);
56     CHECK_NULL_RETURN(frameNode, ERROR_CODE_PARAM_INVALID);
57     return LoadingProgressModelNG::GetEnableLoading(frameNode);
58 }
59 
SetEnableLoading(ArkUINodeHandle node,ArkUI_Bool enableLoadingValue)60 void SetEnableLoading(ArkUINodeHandle node, ArkUI_Bool enableLoadingValue)
61 {
62     auto* frameNode = reinterpret_cast<FrameNode*>(node);
63     CHECK_NULL_VOID(frameNode);
64     LoadingProgressModelNG::SetEnableLoading(frameNode, enableLoadingValue);
65 }
66 
ResetEnableLoading(ArkUINodeHandle node)67 void ResetEnableLoading(ArkUINodeHandle node)
68 {
69     auto* frameNode = reinterpret_cast<FrameNode*>(node);
70     CHECK_NULL_VOID(frameNode);
71     LoadingProgressModelNG::SetEnableLoading(frameNode, true);
72 }
73 
SetLoadingProgressForegroundColor(ArkUINodeHandle node,ArkUI_Uint32 colorValue)74 void SetLoadingProgressForegroundColor(ArkUINodeHandle node, ArkUI_Uint32 colorValue)
75 {
76     auto* frameNode = reinterpret_cast<FrameNode*>(node);
77     CHECK_NULL_VOID(frameNode);
78     LoadingProgressModelNG::SetForegroundColor(frameNode, Color(colorValue));
79 }
80 
ResetLoadingProgressForegroundColor(ArkUINodeHandle node)81 void ResetLoadingProgressForegroundColor(ArkUINodeHandle node)
82 {
83     auto* frameNode = reinterpret_cast<FrameNode*>(node);
84     CHECK_NULL_VOID(frameNode);
85 }
86 } // namespace
87 
88 namespace NodeModifier {
GetLoadingProgressModifier()89 const ArkUILoadingProgressModifier* GetLoadingProgressModifier()
90 {
91     static const ArkUILoadingProgressModifier modifier = {
92         GetLoadingProgressColor, SetLoadingProgressColor, ResetLoadingProgressColor,
93         GetEnableLoading, SetEnableLoading, ResetEnableLoading,
94         SetLoadingProgressForegroundColor, ResetLoadingProgressForegroundColor };
95 
96     return &modifier;
97 }
98 
GetCJUILoadingProgressModifier()99 const CJUILoadingProgressModifier* GetCJUILoadingProgressModifier()
100 {
101     static const CJUILoadingProgressModifier modifier = {
102         GetLoadingProgressColor, SetLoadingProgressColor, ResetLoadingProgressColor,
103         GetEnableLoading, SetEnableLoading, ResetEnableLoading,
104         SetLoadingProgressForegroundColor, ResetLoadingProgressForegroundColor };
105 
106     return &modifier;
107 }
108 } // namespace NodeModifier
109 } // namespace OHOS::Ace::NG
110