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 "core/interfaces/native/node/scrollable_modifier.h"
16
17 #include "core/components_ng/pattern/scrollable/scrollable_model_ng.h"
18 #include "core/components_ng/pattern/scrollable/scrollable_paint_property.h"
19
20 namespace OHOS::Ace::NG {
21
SetContentClip(ArkUINodeHandle node,ArkUI_Int32 mode)22 void SetContentClip(ArkUINodeHandle node, ArkUI_Int32 mode)
23 {
24 auto* frameNode = reinterpret_cast<FrameNode*>(node);
25 auto val = static_cast<ContentClipMode>(mode);
26 if (val < ContentClipMode::CONTENT_ONLY || val > ContentClipMode::SAFE_AREA) {
27 val = ContentClipMode::DEFAULT;
28 }
29 ScrollableModelNG::SetContentClip(frameNode, static_cast<ContentClipMode>(mode), nullptr);
30 }
31
ResetContentClip(ArkUINodeHandle node)32 void ResetContentClip(ArkUINodeHandle node)
33 {
34 auto* frameNode = reinterpret_cast<FrameNode*>(node);
35 ScrollableModelNG::SetContentClip(frameNode, ContentClipMode::DEFAULT, nullptr);
36 }
37
SetOnReachStartCallBack(ArkUINodeHandle node,void * extraParam)38 void SetOnReachStartCallBack(ArkUINodeHandle node, void* extraParam)
39 {
40 auto* frameNode = reinterpret_cast<FrameNode*>(node);
41 CHECK_NULL_VOID(frameNode);
42 if (extraParam) {
43 auto onReachStart = reinterpret_cast<OnReachEvent*>(extraParam);
44 ScrollableModelNG::SetOnReachStart(frameNode, std::move(*onReachStart));
45 } else {
46 ScrollableModelNG::SetOnReachStart(frameNode, nullptr);
47 }
48 }
49
ResetOnReachStartCallBack(ArkUINodeHandle node)50 void ResetOnReachStartCallBack(ArkUINodeHandle node)
51 {
52 auto* frameNode = reinterpret_cast<FrameNode*>(node);
53 CHECK_NULL_VOID(frameNode);
54 ScrollableModelNG::SetOnReachStart(frameNode, nullptr);
55 }
56
SetOnReachEndCallBack(ArkUINodeHandle node,void * extraParam)57 void SetOnReachEndCallBack(ArkUINodeHandle node, void* extraParam)
58 {
59 auto* frameNode = reinterpret_cast<FrameNode*>(node);
60 CHECK_NULL_VOID(frameNode);
61 if (extraParam) {
62 auto onReachEnd = reinterpret_cast<OnReachEvent*>(extraParam);
63 ScrollableModelNG::SetOnReachEnd(frameNode, std::move(*onReachEnd));
64 } else {
65 ScrollableModelNG::SetOnReachEnd(frameNode, nullptr);
66 }
67 }
68
ResetOnReachEndCallBack(ArkUINodeHandle node)69 void ResetOnReachEndCallBack(ArkUINodeHandle node)
70 {
71 auto* frameNode = reinterpret_cast<FrameNode*>(node);
72 CHECK_NULL_VOID(frameNode);
73 ScrollableModelNG::SetOnReachEnd(frameNode, nullptr);
74 }
75
76 namespace NodeModifier {
GetScrollableModifier()77 const ArkUIScrollableModifier* GetScrollableModifier()
78 {
79 static const ArkUIScrollableModifier modifier = {
80 SetContentClip,
81 ResetContentClip,
82 SetOnReachStartCallBack,
83 ResetOnReachStartCallBack,
84 SetOnReachEndCallBack,
85 ResetOnReachEndCallBack,
86 };
87 return &modifier;
88 }
89 } // namespace NodeModifier
90 } // namespace OHOS::Ace::NG
91