1 /*
2  * Copyright (c) 2023 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_PATTERNS_GESTURE_GESTURE_MODEL_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_GESTURE_GESTURE_MODEL_H
18 
19 #include <mutex>
20 #include <string>
21 
22 #include "core/gestures/gesture_info.h"
23 #include "core/gestures/gesture_processor.h"
24 #include "frameworks/base/memory/referenced.h"
25 
26 namespace OHOS::Ace {
27 enum class GestureEventAction { ACTION, START, UPDATE, END, CANCEL };
28 class GestureModel {
29 public:
30     static GestureModel* GetInstance();
31     virtual ~GestureModel() = default;
32 
33     virtual void Create(int32_t priorityNum, int32_t gestureMaskNum) = 0;
34     virtual void Finish() = 0;
35     virtual void Pop() = 0;
36     virtual void SetOnGestureEvent(const GestureEventNoParameter& gestureEventNoParameter) = 0;
37     virtual void SetOnActionFunc(const GestureEventFunc& gestureEventFunc, const Ace::GestureEventAction& action) = 0;
38     virtual void SetTag(const std::string& tag) = 0;
39     virtual void SetAllowedTypes(const std::set<SourceTool>& allowedTypes) = 0;
40 
41 private:
42     static std::unique_ptr<GestureModel> instance_;
43     static std::mutex mutex_;
44 };
45 
46 class TapGestureModel {
47 public:
48     static TapGestureModel* GetInstance();
49     virtual ~TapGestureModel() = default;
50 
51     virtual void Create(int32_t countNum, int32_t fingersNum, double distanceThreshold) = 0;
52 
53 private:
54     static std::unique_ptr<TapGestureModel> instance_;
55     static std::mutex mutex_;
56 };
57 
58 class LongPressGestureModel {
59 public:
60     static LongPressGestureModel* GetInstance();
61     virtual ~LongPressGestureModel() = default;
62 
63     virtual void Create(int32_t fingersNum, bool repeatResult, int32_t durationNum) = 0;
64 
65 private:
66     static std::unique_ptr<LongPressGestureModel> instance_;
67     static std::mutex mutex_;
68 };
69 
70 class PanGestureModel {
71 public:
72     static PanGestureModel* GetInstance();
73     virtual ~PanGestureModel() = default;
74 
75     virtual void Create(int32_t fingersNum, const PanDirection& panDirection, double distanceNum) = 0;
76     virtual void SetPanGestureOption(const RefPtr<PanGestureOption>& panGestureOption) = 0;
77 
78 private:
79     static std::unique_ptr<PanGestureModel> instance_;
80     static std::mutex mutex_;
81 };
82 
83 class SwipeGestureModel {
84 public:
85     static SwipeGestureModel* GetInstance();
86     virtual ~SwipeGestureModel() = default;
87 
88     virtual void Create(int32_t fingersNum, const SwipeDirection& slideDirection, double speedNum) = 0;
89 
90 private:
91     static std::unique_ptr<SwipeGestureModel> instance_;
92     static std::mutex mutex_;
93 };
94 
95 class PinchGestureModel {
96 public:
97     static PinchGestureModel* GetInstance();
98     virtual ~PinchGestureModel() = default;
99 
100     virtual void Create(int32_t fingersNum, double distanceNum) = 0;
101 
102 private:
103     static std::unique_ptr<PinchGestureModel> instance_;
104     static std::mutex mutex_;
105 };
106 
107 class RotationGestureModel {
108 public:
109     static RotationGestureModel* GetInstance();
110     virtual ~RotationGestureModel() = default;
111 
112     virtual void Create(int32_t fingersNum, double angleNum) = 0;
113 
114 private:
115     static std::unique_ptr<RotationGestureModel> instance_;
116     static std::mutex mutex_;
117 };
118 
119 class GestureGroupModel {
120 public:
121     static GestureGroupModel* GetInstance();
122     virtual ~GestureGroupModel() = default;
123 
124     virtual void Create(int32_t gestureMode) = 0;
125 
126 private:
127     static std::unique_ptr<GestureGroupModel> instance_;
128     static std::mutex mutex_;
129 };
130 
131 class TimeoutGestureModel {
132 public:
133     static TimeoutGestureModel* GetInstance();
134     virtual ~TimeoutGestureModel() = default;
135 
136     virtual RefPtr<GestureProcessor> GetGestureProcessor() = 0;
137 
138 private:
139     static std::unique_ptr<TimeoutGestureModel> instance_;
140     static std::mutex mutex_;
141 };
142 } // namespace OHOS::Ace
143 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_GESTURE_GESTURE_MODEL_H
144