• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
22 namespace {
23 constexpr bool DEFAULT_BACKTOTOP = false;
24 
SetContentClip(ArkUINodeHandle node,ArkUI_Int32 mode)25 void SetContentClip(ArkUINodeHandle node, ArkUI_Int32 mode)
26 {
27     auto* frameNode = reinterpret_cast<FrameNode*>(node);
28     auto val = static_cast<ContentClipMode>(mode);
29     if (val < ContentClipMode::CONTENT_ONLY || val > ContentClipMode::SAFE_AREA) {
30         val = ContentClipMode::DEFAULT;
31     }
32     ScrollableModelNG::SetContentClip(frameNode, static_cast<ContentClipMode>(mode), nullptr);
33 }
34 
ResetContentClip(ArkUINodeHandle node)35 void ResetContentClip(ArkUINodeHandle node)
36 {
37     auto* frameNode = reinterpret_cast<FrameNode*>(node);
38     ScrollableModelNG::SetContentClip(frameNode, ContentClipMode::DEFAULT, nullptr);
39 }
40 
SetOnReachStartCallBack(ArkUINodeHandle node,void * extraParam)41 void SetOnReachStartCallBack(ArkUINodeHandle node, void* extraParam)
42 {
43     auto* frameNode = reinterpret_cast<FrameNode*>(node);
44     CHECK_NULL_VOID(frameNode);
45     if (extraParam) {
46         auto onReachStart = reinterpret_cast<OnReachEvent*>(extraParam);
47         ScrollableModelNG::SetOnReachStart(frameNode, std::move(*onReachStart));
48     } else {
49         ScrollableModelNG::SetOnReachStart(frameNode, nullptr);
50     }
51 }
52 
ResetOnReachStartCallBack(ArkUINodeHandle node)53 void ResetOnReachStartCallBack(ArkUINodeHandle node)
54 {
55     auto* frameNode = reinterpret_cast<FrameNode*>(node);
56     CHECK_NULL_VOID(frameNode);
57     ScrollableModelNG::SetOnReachStart(frameNode, nullptr);
58 }
59 
SetOnReachEndCallBack(ArkUINodeHandle node,void * extraParam)60 void SetOnReachEndCallBack(ArkUINodeHandle node, void* extraParam)
61 {
62     auto* frameNode = reinterpret_cast<FrameNode*>(node);
63     CHECK_NULL_VOID(frameNode);
64     if (extraParam) {
65         auto onReachEnd = reinterpret_cast<OnReachEvent*>(extraParam);
66         ScrollableModelNG::SetOnReachEnd(frameNode, std::move(*onReachEnd));
67     } else {
68         ScrollableModelNG::SetOnReachEnd(frameNode, nullptr);
69     }
70 }
71 
ResetOnReachEndCallBack(ArkUINodeHandle node)72 void ResetOnReachEndCallBack(ArkUINodeHandle node)
73 {
74     auto* frameNode = reinterpret_cast<FrameNode*>(node);
75     CHECK_NULL_VOID(frameNode);
76     ScrollableModelNG::SetOnReachEnd(frameNode, nullptr);
77 }
78 
SetBackToTop(ArkUINodeHandle node,ArkUI_Bool value)79 void SetBackToTop(ArkUINodeHandle node, ArkUI_Bool value)
80 {
81     auto* frameNode = reinterpret_cast<FrameNode*>(node);
82     CHECK_NULL_VOID(frameNode);
83     ScrollableModelNG::SetBackToTop(frameNode, value);
84 }
85 
ResetBackToTop(ArkUINodeHandle node)86 void ResetBackToTop(ArkUINodeHandle node)
87 {
88     auto* frameNode = reinterpret_cast<FrameNode*>(node);
89     CHECK_NULL_VOID(frameNode);
90     ScrollableModelNG::SetBackToTop(frameNode, false);
91 }
92 
GetBackToTop(ArkUINodeHandle node)93 int32_t GetBackToTop(ArkUINodeHandle node)
94 {
95     auto* frameNode = reinterpret_cast<FrameNode*>(node);
96     CHECK_NULL_RETURN(frameNode, DEFAULT_BACKTOTOP);
97     return ScrollableModelNG::GetBackToTop(frameNode);
98 }
99 } // namespace
100 
101 namespace NodeModifier {
GetScrollableModifier()102 const ArkUIScrollableModifier* GetScrollableModifier()
103 {
104     static const ArkUIScrollableModifier modifier = {
105         SetContentClip,
106         ResetContentClip,
107         SetOnReachStartCallBack,
108         ResetOnReachStartCallBack,
109         SetOnReachEndCallBack,
110         ResetOnReachEndCallBack,
111         SetBackToTop,
112         ResetBackToTop,
113         GetBackToTop,
114     };
115     return &modifier;
116 }
117 } // namespace NodeModifier
118 } // namespace OHOS::Ace::NG
119