1 /*
2 * Copyright (c) 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 #include "core/interfaces/native/node/blank_modifier.h"
16
17 #include "core/pipeline/base/element_register.h"
18 #include "core/components_ng/base/frame_node.h"
19 #include "core/components_ng/pattern/blank/blank_model_ng.h"
20 #include "core/components/common/layout/constants.h"
21 #include "core/components/common/properties/color.h"
22 #include "core/components_ng/base/view_abstract.h"
23
24 namespace OHOS::Ace::NG {
SetColor(ArkUINodeHandle node,ArkUI_Uint32 value)25 void SetColor(ArkUINodeHandle node, ArkUI_Uint32 value)
26 {
27 auto *frameNode = reinterpret_cast<FrameNode *>(node);
28 CHECK_NULL_VOID(frameNode);
29 BlankModelNG::SetColor(frameNode, Color(value));
30 }
31
ResetColor(ArkUINodeHandle node)32 void ResetColor(ArkUINodeHandle node)
33 {
34 auto *frameNode = reinterpret_cast<FrameNode *>(node);
35 CHECK_NULL_VOID(frameNode);
36 BlankModelNG::SetColor(frameNode, Color::TRANSPARENT);
37 }
38
SetBlankHeight(ArkUINodeHandle node,ArkUI_Float32 heightValue,ArkUI_Int32 heightUnit)39 void SetBlankHeight(ArkUINodeHandle node, ArkUI_Float32 heightValue, ArkUI_Int32 heightUnit)
40 {
41 auto* frameNode = reinterpret_cast<FrameNode*>(node);
42 CHECK_NULL_VOID(frameNode);
43 BlankModelNG::SetHeight(frameNode, CalcDimension(heightValue, (DimensionUnit)heightUnit));
44 }
45
ResetBlankHeight(ArkUINodeHandle node)46 void ResetBlankHeight(ArkUINodeHandle node)
47 {
48 auto* frameNode = reinterpret_cast<FrameNode*>(node);
49 CHECK_NULL_VOID(frameNode);
50 ViewAbstract::ClearWidthOrHeight(frameNode, false);
51 }
52
SetBlankMin(ArkUINodeHandle node,ArkUI_Float32 minValue,ArkUI_Int32 minUnit)53 void SetBlankMin(ArkUINodeHandle node, ArkUI_Float32 minValue, ArkUI_Int32 minUnit)
54 {
55 auto* frameNode = reinterpret_cast<FrameNode*>(node);
56 CHECK_NULL_VOID(frameNode);
57 BlankModelNG::SetBlankMin(frameNode, CalcDimension(minValue, (DimensionUnit)minUnit));
58 }
59
ResetBlankMin(ArkUINodeHandle node)60 void ResetBlankMin(ArkUINodeHandle node)
61 {
62 auto* frameNode = reinterpret_cast<FrameNode*>(node);
63 CHECK_NULL_VOID(frameNode);
64 BlankModelNG::SetBlankMin(frameNode, CalcDimension(0.0, DimensionUnit::VP));
65 }
66
67 namespace NodeModifier {
GetBlankModifier()68 const ArkUIBlankModifier* GetBlankModifier()
69 {
70 static const ArkUIBlankModifier modifier = { SetColor, ResetColor, SetBlankHeight, ResetBlankHeight,
71 SetBlankMin, ResetBlankMin };
72 return &modifier;
73 }
74
GetCJUIBlankModifier()75 const CJUIBlankModifier* GetCJUIBlankModifier()
76 {
77 static const CJUIBlankModifier modifier = { SetColor, ResetColor, SetBlankHeight, ResetBlankHeight,
78 SetBlankMin, ResetBlankMin };
79 return &modifier;
80 }
81 }
82 }