• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 
16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SCROLL_SCROLL_MODEL_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SCROLL_SCROLL_MODEL_H
18 
19 #include <memory>
20 #include <mutex>
21 
22 #include "core/components/common/layout/constants.h"
23 #include "core/components/scroll_bar/scroll_proxy.h"
24 #include "core/components_ng/pattern/scroll/scroll_event_hub.h"
25 #include "core/common/resource/resource_object.h"
26 
27 namespace OHOS::Ace {
28 
29 class ScrollBarTheme;
30 class ScrollControllerBase;
31 
32 class ACE_FORCE_EXPORT ScrollModel {
33 public:
34     static ScrollModel* GetInstance();
35     virtual ~ScrollModel() = default;
36 
37     virtual void Create() = 0;
38     virtual RefPtr<ScrollControllerBase> GetOrCreateController() = 0;
39     virtual RefPtr<ScrollProxy> CreateScrollBarProxy() = 0;
40     virtual void SetAxis(Axis axis) = 0;
41     virtual void SetOnScrollBegin(OnScrollBeginEvent&& event) = 0;
42     virtual void SetOnScrollFrameBegin(OnScrollFrameBeginEvent&& event) = 0;
43     virtual void SetOnScroll(NG::ScrollEvent&& event) = 0;
SetOnWillScroll(NG::ScrollEventWithReturn && event)44     virtual void SetOnWillScroll(NG::ScrollEventWithReturn&& event) {};
SetOnDidScroll(NG::ScrollEventWithState && event)45     virtual void SetOnDidScroll(NG::ScrollEventWithState&& event) {};
46     virtual void SetOnScrollEdge(NG::ScrollEdgeEvent&& event) = 0;
47     virtual void SetOnScrollEnd(NG::ScrollEndEvent&& event) = 0;
48     virtual void SetOnScrollStart(OnScrollStartEvent&& event) = 0;
49     virtual void SetOnScrollStop(OnScrollStopEvent&& event) = 0;
50     virtual void SetOnReachStart(OnReachEvent&& onReachStart) = 0;
51     virtual void SetOnReachEnd(OnReachEvent&& onReachEnd) = 0;
52     virtual void SetScrollBarProxy(const RefPtr<ScrollProxy>& proxy) = 0;
53     virtual void InitScrollBar(const RefPtr<ScrollBarTheme>& theme, const std::pair<bool, Color>& color,
54         const std::pair<bool, Dimension>& width, EdgeEffect effect) = 0;
55     virtual void SetDisplayMode(int displayMode) = 0;
56     virtual void SetScrollBarWidth(const Dimension& dimension) = 0;
57     virtual void SetScrollBarColor(const Color& color) = 0;
58     virtual void SetEdgeEffect(EdgeEffect edgeEffect, bool alwaysEnabled, EffectEdge effectEdge = EffectEdge::ALL) = 0;
59     virtual void SetHasWidth(bool hasWidth) = 0;
60     virtual void SetHasHeight(bool hasHeight) = 0;
61     virtual void SetNestedScroll(const NestedScrollOptions& nestedOpt) = 0;
62     virtual void SetScrollEnabled(bool scrollEnabled) = 0;
63     virtual void SetFriction(double friction) = 0;
64     virtual void SetScrollSnap(ScrollSnapAlign scrollSnapAlign, const Dimension& intervalSize,
65         const std::vector<Dimension>& snapPaginations, const std::pair<bool, bool>& enableSnapToSide) = 0;
66     virtual void SetEnablePaging(bool enablePaging) = 0;
67     virtual void SetInitialOffset(const NG::OffsetT<CalcDimension>& offset) = 0;
CreateWithResourceObjFriction(const RefPtr<ResourceObject> & resObj)68     virtual void CreateWithResourceObjFriction(const RefPtr<ResourceObject>& resObj) {};
CreateWithResourceObjIntervalSize(const RefPtr<ResourceObject> & resObj)69     virtual void CreateWithResourceObjIntervalSize(const RefPtr<ResourceObject>& resObj) {};
CreateWithResourceObjSnapPaginations(const std::vector<Dimension> & snapPaginations,std::vector<RefPtr<ResourceObject>> & resObjs)70     virtual void CreateWithResourceObjSnapPaginations(
71         const std::vector<Dimension>& snapPaginations, std::vector<RefPtr<ResourceObject>>& resObjs) {};
CreateWithResourceObjScrollBarColor(const RefPtr<ResourceObject> & resObj)72     virtual void CreateWithResourceObjScrollBarColor(const RefPtr<ResourceObject>& resObj) {};
SetMaxZoomScale(float scale)73     virtual void SetMaxZoomScale(float scale) {};
SetMinZoomScale(float scale)74     virtual void SetMinZoomScale(float scale) {};
SetZoomScale(float scale)75     virtual void SetZoomScale(float scale) {};
ResetZoomScale()76     virtual void ResetZoomScale() {};
SetZoomScaleChangeEvent(std::function<void (float)> && event)77     virtual void SetZoomScaleChangeEvent(std::function<void(float)>&& event) {};
SetEnableBouncesZoom(bool enable)78     virtual void SetEnableBouncesZoom(bool enable) {};
SetOnDidZoom(std::function<void (float)> && event)79     virtual void SetOnDidZoom(std::function<void(float)>&& event) {};
SetOnZoomStart(std::function<void (void)> && event)80     virtual void SetOnZoomStart(std::function<void(void)>&& event) {};
SetOnZoomStop(std::function<void (void)> && event)81     virtual void SetOnZoomStop(std::function<void(void)>&& event) {};
82 
83 private:
84     static std::unique_ptr<ScrollModel> instance_;
85     static std::mutex mutex_;
86 };
87 
88 } // namespace OHOS::Ace
89 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SCROLL_SCROLL_MODEL_H
90