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/common/layout/constants.h"
18 #include "core/components_ng/base/frame_node.h"
19 #include "core/components_ng/base/view_abstract.h"
20 #include "core/components_ng/pattern/plugin/plugin_model_ng.h"
21 #include "core/pipeline/base/element_register.h"
22
23 namespace OHOS::Ace::NG {
24 const DimensionUnit DEFAULT_UNIT = DimensionUnit::VP;
25 const double DEFAULT_VALUE = 0.0;
26
SetPluginWidth(ArkUINodeHandle node,ArkUI_Float32 value,ArkUI_Int32 widthUnit)27 void SetPluginWidth(ArkUINodeHandle node, ArkUI_Float32 value, ArkUI_Int32 widthUnit)
28 {
29 auto* frameNode = reinterpret_cast<FrameNode*>(node);
30 CHECK_NULL_VOID(frameNode);
31 Dimension width = Dimension(value, static_cast<DimensionUnit>(widthUnit));
32 PluginModelNG::SetWidth(frameNode, width);
33 }
34
SetPluginHeight(ArkUINodeHandle node,ArkUI_Float32 value,ArkUI_Int32 heightUnit)35 void SetPluginHeight(ArkUINodeHandle node, ArkUI_Float32 value, ArkUI_Int32 heightUnit)
36 {
37 auto* frameNode = reinterpret_cast<FrameNode*>(node);
38 CHECK_NULL_VOID(frameNode);
39 Dimension height = Dimension(value, static_cast<DimensionUnit>(heightUnit));
40 PluginModelNG::SetHeight(frameNode, height);
41 }
42
SetPluginSize(ArkUINodeHandle node,ArkUI_Float32 widthVal,ArkUI_Float32 heightVal,ArkUI_Int32 widthUnit,ArkUI_Int32 heightUnit)43 void SetPluginSize(ArkUINodeHandle node, ArkUI_Float32 widthVal, ArkUI_Float32 heightVal,
44 ArkUI_Int32 widthUnit, ArkUI_Int32 heightUnit)
45 {
46 auto* frameNode = reinterpret_cast<FrameNode*>(node);
47 CHECK_NULL_VOID(frameNode);
48 Dimension width = Dimension(widthVal, static_cast<DimensionUnit>(widthUnit));
49 Dimension height = Dimension(heightVal, static_cast<DimensionUnit>(heightUnit));
50 PluginModelNG::SetPluginSize(frameNode, width, height);
51 }
52
ResetPluginWidth(ArkUINodeHandle node)53 void ResetPluginWidth(ArkUINodeHandle node)
54 {
55 auto* frameNode = reinterpret_cast<FrameNode*>(node);
56 CHECK_NULL_VOID(frameNode);
57 Dimension width = Dimension(DEFAULT_VALUE, DEFAULT_UNIT);
58 PluginModelNG::SetWidth(frameNode, width);
59 }
60
ResetPluginHeight(ArkUINodeHandle node)61 void ResetPluginHeight(ArkUINodeHandle node)
62 {
63 auto* frameNode = reinterpret_cast<FrameNode*>(node);
64 CHECK_NULL_VOID(frameNode);
65 Dimension height = Dimension(DEFAULT_VALUE, DEFAULT_UNIT);
66 PluginModelNG::SetHeight(frameNode, height);
67 }
68
ResetPluginSize(ArkUINodeHandle node)69 void ResetPluginSize(ArkUINodeHandle node)
70 {
71 auto* frameNode = reinterpret_cast<FrameNode*>(node);
72 CHECK_NULL_VOID(frameNode);
73 Dimension width = Dimension(DEFAULT_VALUE, DEFAULT_UNIT);
74 Dimension height = Dimension(DEFAULT_VALUE, DEFAULT_UNIT);
75 PluginModelNG::SetPluginSize(frameNode, width, height);
76 }
77
78 namespace NodeModifier {
GetPluginModifier()79 const ArkUIPluginModifier* GetPluginModifier()
80 {
81 static const ArkUIPluginModifier modifier = {SetPluginWidth, SetPluginHeight, SetPluginSize,
82 ResetPluginWidth, ResetPluginHeight, ResetPluginSize };
83
84 return &modifier;
85 }
86
GetCJUIPluginModifier()87 const CJUIPluginModifier* GetCJUIPluginModifier()
88 {
89 static const CJUIPluginModifier modifier = {SetPluginWidth, SetPluginHeight, SetPluginSize,
90 ResetPluginWidth, ResetPluginHeight, ResetPluginSize };
91
92 return &modifier;
93 }
94 }
95 }