• 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SCROLL_ZOOM_CONTROLLER_H
16 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SCROLL_ZOOM_CONTROLLER_H
17 
18 #include "core/components_ng/base/modifier.h"
19 #include "core/components_ng/gestures/recognizers/pinch_recognizer.h"
20 
21 namespace OHOS::Ace::NG {
22 class ScrollPattern;
23 
24 /**
25  * @brief Controller for free scrolling behavior. It manages related gestures and animations.
26  *
27  */
28 class ZoomController final : public AceType {
29     DECLARE_ACE_TYPE(ZoomController, AceType);
30     ACE_DISALLOW_COPY_AND_MOVE(ZoomController);
31 
32 public:
33     explicit ZoomController(ScrollPattern& pattern);
34     ~ZoomController() final;
35 
GetPinchGesture()36     RefPtr<PinchRecognizer> GetPinchGesture() const
37     {
38         return pinchGesture_;
39     }
40 
41 private:
42     void InitializePinchGesture();
43     void DeinitializePinchGesture();
44     void HandleZoomStart(GestureEvent& info);
45     void HandleZoomUpdate(GestureEvent& info);
46     void HandleZoomEnd(GestureEvent& info);
47     OffsetF GetCenterPoint(GestureEvent& info);
48     void UpdateOffset(float scale, float prevScale, OffsetF centerOffset);
49 
50     ScrollPattern& pattern_;
51     RefPtr<PinchRecognizer> pinchGesture_;
52     float zoomScaleStart_ = 1.0f;
53 };
54 
55 } // namespace OHOS::Ace::NG
56 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SCROLL_ZOOM_CONTROLLER_H
57