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/plugin_modifier.h"
16
17 #include "core/components_ng/pattern/plugin/plugin_model_ng.h"
18
19 namespace OHOS::Ace::NG {
20 const DimensionUnit DEFAULT_UNIT = DimensionUnit::VP;
21 const double DEFAULT_VALUE = 0.0;
22
SetPluginWidth(ArkUINodeHandle node,ArkUI_Float32 value,ArkUI_Int32 widthUnit)23 void SetPluginWidth(ArkUINodeHandle node, ArkUI_Float32 value, ArkUI_Int32 widthUnit)
24 {
25 auto* frameNode = reinterpret_cast<FrameNode*>(node);
26 CHECK_NULL_VOID(frameNode);
27 Dimension width = Dimension(value, static_cast<DimensionUnit>(widthUnit));
28 PluginModelNG::SetWidth(frameNode, width);
29 }
30
SetPluginHeight(ArkUINodeHandle node,ArkUI_Float32 value,ArkUI_Int32 heightUnit)31 void SetPluginHeight(ArkUINodeHandle node, ArkUI_Float32 value, ArkUI_Int32 heightUnit)
32 {
33 auto* frameNode = reinterpret_cast<FrameNode*>(node);
34 CHECK_NULL_VOID(frameNode);
35 Dimension height = Dimension(value, static_cast<DimensionUnit>(heightUnit));
36 PluginModelNG::SetHeight(frameNode, height);
37 }
38
SetPluginSize(ArkUINodeHandle node,ArkUI_Float32 widthVal,ArkUI_Float32 heightVal,ArkUI_Int32 widthUnit,ArkUI_Int32 heightUnit)39 void SetPluginSize(ArkUINodeHandle node, ArkUI_Float32 widthVal, ArkUI_Float32 heightVal,
40 ArkUI_Int32 widthUnit, ArkUI_Int32 heightUnit)
41 {
42 auto* frameNode = reinterpret_cast<FrameNode*>(node);
43 CHECK_NULL_VOID(frameNode);
44 Dimension width = Dimension(widthVal, static_cast<DimensionUnit>(widthUnit));
45 Dimension height = Dimension(heightVal, static_cast<DimensionUnit>(heightUnit));
46 PluginModelNG::SetPluginSize(frameNode, width, height);
47 }
48
ResetPluginWidth(ArkUINodeHandle node)49 void ResetPluginWidth(ArkUINodeHandle node)
50 {
51 auto* frameNode = reinterpret_cast<FrameNode*>(node);
52 CHECK_NULL_VOID(frameNode);
53 Dimension width = Dimension(DEFAULT_VALUE, DEFAULT_UNIT);
54 PluginModelNG::SetWidth(frameNode, width);
55 }
56
ResetPluginHeight(ArkUINodeHandle node)57 void ResetPluginHeight(ArkUINodeHandle node)
58 {
59 auto* frameNode = reinterpret_cast<FrameNode*>(node);
60 CHECK_NULL_VOID(frameNode);
61 Dimension height = Dimension(DEFAULT_VALUE, DEFAULT_UNIT);
62 PluginModelNG::SetHeight(frameNode, height);
63 }
64
ResetPluginSize(ArkUINodeHandle node)65 void ResetPluginSize(ArkUINodeHandle node)
66 {
67 auto* frameNode = reinterpret_cast<FrameNode*>(node);
68 CHECK_NULL_VOID(frameNode);
69 Dimension width = Dimension(DEFAULT_VALUE, DEFAULT_UNIT);
70 Dimension height = Dimension(DEFAULT_VALUE, DEFAULT_UNIT);
71 PluginModelNG::SetPluginSize(frameNode, width, height);
72 }
73
74 namespace NodeModifier {
GetPluginModifier()75 const ArkUIPluginModifier* GetPluginModifier()
76 {
77 CHECK_INITIALIZED_FIELDS_BEGIN(); // don't move this line
78 static const ArkUIPluginModifier modifier = {
79 .setPluginWidth = SetPluginWidth,
80 .setPluginHeight = SetPluginHeight,
81 .setPluginSize = SetPluginSize,
82 .resetPluginWidth = ResetPluginWidth,
83 .resetPluginHeight = ResetPluginHeight,
84 .resetPluginSize = ResetPluginSize,
85 };
86 CHECK_INITIALIZED_FIELDS_END(modifier, 0, 0, 0); // don't move this line
87
88 return &modifier;
89 }
90
GetCJUIPluginModifier()91 const CJUIPluginModifier* GetCJUIPluginModifier()
92 {
93 CHECK_INITIALIZED_FIELDS_BEGIN(); // don't move this line
94 static const CJUIPluginModifier modifier = {
95 .setPluginWidth = SetPluginWidth,
96 .setPluginHeight = SetPluginHeight,
97 .setPluginSize = SetPluginSize,
98 .resetPluginWidth = ResetPluginWidth,
99 .resetPluginHeight = ResetPluginHeight,
100 .resetPluginSize = ResetPluginSize,
101 };
102 CHECK_INITIALIZED_FIELDS_END(modifier, 0, 0, 0); // don't move this line
103
104 return &modifier;
105 }
106 }
107 }
108