• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 
16 #include "core/components_ng/pattern/scrollable/scrollable_pattern.h"
17 
18 #include "base/geometry/axis.h"
19 #include "base/geometry/point.h"
20 #include "base/log/dump_log.h"
21 #include "base/perfmonitor/perf_constants.h"
22 #include "base/perfmonitor/perf_monitor.h"
23 #include "base/ressched/ressched_report.h"
24 #include "base/utils/multi_thread.h"
25 #include "base/utils/utils.h"
26 #include "core/common/container.h"
27 #include "core/common/recorder/event_definition.h"
28 #include "core/components_ng/base/inspector_filter.h"
29 #include "core/components_ng/base/observer_handler.h"
30 #include "core/components_ng/manager/select_overlay/select_overlay_scroll_notifier.h"
31 #include "core/components_ng/pattern/scroll/effect/scroll_fade_effect.h"
32 #include "core/components_ng/pattern/scroll/scroll_event_hub.h"
33 #include "core/components_ng/pattern/scroll/scroll_spring_effect.h"
34 #include "core/components_ng/pattern/scrollable/scrollable.h"
35 #include "core/components_ng/pattern/scrollable/scrollable_event_hub.h"
36 #include "core/components_ng/pattern/scrollable/scrollable_properties.h"
37 #include "core/components_ng/pattern/swiper/swiper_pattern.h"
38 #include "core/components_ng/syntax/for_each_node.h"
39 #include "core/components_ng/syntax/lazy_for_each_node.h"
40 #include "core/components_ng/syntax/repeat_virtual_scroll_2_node.h"
41 #include "core/components_ng/syntax/repeat_virtual_scroll_node.h"
42 #include "core/pipeline_ng/pipeline_context.h"
43 
44 #ifdef ARKUI_CIRCLE_FEATURE
45 #include "core/components_ng/pattern/arc_scroll/inner/arc_scroll_bar.h"
46 #include "core/components_ng/pattern/arc_scroll/inner/arc_scroll_bar_overlay_modifier.h"
47 #endif // ARKUI_CIRCLE_FEATURE
48 
49 namespace OHOS::Ace::NG {
50 namespace {
51 
52 } // namespace
53 
OnDetachFromFrameNodeMultiThread(FrameNode * frameNode)54 void ScrollablePattern::OnDetachFromFrameNodeMultiThread(FrameNode* frameNode)
55 {
56     // do nothing unsafe thread
57 }
OnAttachToFrameNodeMultiThread()58 void ScrollablePattern::OnAttachToFrameNodeMultiThread()
59 {
60     auto host = GetHost();
61     CHECK_NULL_VOID(host);
62     host->GetRenderContext()->SetClipToBounds(true);
63 }
64 
OnDetachFromMainTreeMultiThread()65 void ScrollablePattern::OnDetachFromMainTreeMultiThread()
66 {
67     auto host = GetHost();
68     CHECK_NULL_VOID(host);
69     UnRegister2DragDropManager(AceType::RawPtr(host));
70     auto context = host->GetContextWithCheck();
71     CHECK_NULL_VOID(context);
72     context->RemoveWindowStateChangedCallback(host->GetId());
73 }
74 
OnAttachToMainTreeMultiThread()75 void ScrollablePattern::OnAttachToMainTreeMultiThread()
76 {
77     auto host = GetHost();
78     CHECK_NULL_VOID(host);
79     // moving from OnAttachToFrame to here
80     host->GetRenderContext()->UpdateClipEdge(true);
81     auto scrollBarProxy = scrollBarProxy_;
82     CHECK_NULL_VOID(scrollBarProxy);
83     auto enableNestScroll = scrollBarProxy->IsNestScroller();
84     if (enableNestScroll) {
85         SearchAndSetParentNestedScroll(host);
86     }
87 }
88 
ScrollPageMultiThread(bool reverse,bool smooth,AccessibilityScrollType scrollType)89 void ScrollablePattern::ScrollPageMultiThread(bool reverse, bool smooth, AccessibilityScrollType scrollType)
90 {
91     auto host = GetHost();
92     CHECK_NULL_VOID(host);
93     host->PostAfterAttachMainTreeTask([weak = WeakClaim(this), reverse, smooth, scrollType]() {
94         auto pattern = weak.Upgrade();
95         float distance = reverse ? pattern->GetMainContentSize() : -(pattern->GetMainContentSize());
96         if (scrollType == AccessibilityScrollType::SCROLL_HALF) {
97             distance = distance / 2.f;
98         }
99         if (smooth) {
100             float position = -(pattern->GetTotalOffset()) + distance;
101             pattern->AnimateTo(-position, -1, nullptr, true, false, false);
102         } else {
103             pattern->StopAnimate();
104             pattern->UpdateCurrentOffset(distance, SCROLL_FROM_JUMP);
105         }
106     });
107 }
108 } // namespace OHOS::Ace::NG
109