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 
16 #ifndef TOUCH_GESTURE_ADAPTER_H
17 #define TOUCH_GESTURE_ADAPTER_H
18 
19 #include <memory>
20 
21 #include "touch_gesture_detector.h"
22 
23 namespace OHOS {
24 namespace MMI {
25 class TouchGestureAdapter final :
26     public TouchGestureDetector::GestureListener,
27     public std::enable_shared_from_this<TouchGestureAdapter> {
28 public:
29     TouchGestureAdapter(TouchGestureType type, std::shared_ptr<TouchGestureAdapter> next);
30     static std::shared_ptr<TouchGestureAdapter> GetGestureFactory();
31     void process(std::shared_ptr<PointerEvent> event);
32     void SetGestureCondition(bool flag, TouchGestureType type, int32_t fingers);
33 
34 private:
35     enum class GestureState {
36         IDLE,
37         SWIPE,
38         PINCH,
39     };
ShouldDeliverToNext() const40     inline bool ShouldDeliverToNext() const
41     {
42         return shouldDeliverToNext_;
43     }
44     void Init();
45     void OnTouchEvent(std::shared_ptr<PointerEvent> event);
46     void OnSwipeGesture(std::shared_ptr<PointerEvent> event);
47     void OnPinchGesture(std::shared_ptr<PointerEvent> event);
48     void OnGestureSuccessful(std::shared_ptr<PointerEvent> event);
49     virtual bool OnGestureEvent(std::shared_ptr<PointerEvent> event, GestureMode mode) override;
50 
51 private:
52     bool hasCancel_ { false };
53     bool gestureStarted_ { false };
54     bool shouldDeliverToNext_ { true };
55     TouchGestureType gestureType_ { TOUCH_GESTURE_TYPE_NONE };
56     inline static GestureState state_ { GestureState::IDLE };
57     std::shared_ptr<TouchGestureDetector> gestureDetector_ { nullptr };
58     std::shared_ptr<TouchGestureAdapter> nextAdapter_ { nullptr };
59 };
60 } // namespace MMI
61 } // namespace OHOS
62 #endif // TOUCH_GESTURE_ADAPTER_H