• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
40 private:
41     static std::unique_ptr<GestureModel> instance_;
42     static std::mutex mutex_;
43 };
44 
45 class TapGestureModel {
46 public:
47     static TapGestureModel* GetInstance();
48     virtual ~TapGestureModel() = default;
49 
50     virtual void Create(int32_t countNum, int32_t fingersNum, double distanceThreshold) = 0;
51 
52 private:
53     static std::unique_ptr<TapGestureModel> instance_;
54     static std::mutex mutex_;
55 };
56 
57 class LongPressGestureModel {
58 public:
59     static LongPressGestureModel* GetInstance();
60     virtual ~LongPressGestureModel() = default;
61 
62     virtual void Create(int32_t fingersNum, bool repeatResult, int32_t durationNum) = 0;
63 
64 private:
65     static std::unique_ptr<LongPressGestureModel> instance_;
66     static std::mutex mutex_;
67 };
68 
69 class PanGestureModel {
70 public:
71     static PanGestureModel* GetInstance();
72     virtual ~PanGestureModel() = default;
73 
74     virtual void Create(int32_t fingersNum, const PanDirection& panDirection, double distanceNum) = 0;
75     virtual void SetPanGestureOption(const RefPtr<PanGestureOption>& panGestureOption) = 0;
76 
77 private:
78     static std::unique_ptr<PanGestureModel> instance_;
79     static std::mutex mutex_;
80 };
81 
82 class SwipeGestureModel {
83 public:
84     static SwipeGestureModel* GetInstance();
85     virtual ~SwipeGestureModel() = default;
86 
87     virtual void Create(int32_t fingersNum, const SwipeDirection& slideDirection, double speedNum) = 0;
88 
89 private:
90     static std::unique_ptr<SwipeGestureModel> instance_;
91     static std::mutex mutex_;
92 };
93 
94 class PinchGestureModel {
95 public:
96     static PinchGestureModel* GetInstance();
97     virtual ~PinchGestureModel() = default;
98 
99     virtual void Create(int32_t fingersNum, double distanceNum) = 0;
100 
101 private:
102     static std::unique_ptr<PinchGestureModel> instance_;
103     static std::mutex mutex_;
104 };
105 
106 class RotationGestureModel {
107 public:
108     static RotationGestureModel* GetInstance();
109     virtual ~RotationGestureModel() = default;
110 
111     virtual void Create(int32_t fingersNum, double angleNum) = 0;
112 
113 private:
114     static std::unique_ptr<RotationGestureModel> instance_;
115     static std::mutex mutex_;
116 };
117 
118 class GestureGroupModel {
119 public:
120     static GestureGroupModel* GetInstance();
121     virtual ~GestureGroupModel() = default;
122 
123     virtual void Create(int32_t gestureMode) = 0;
124 
125 private:
126     static std::unique_ptr<GestureGroupModel> instance_;
127     static std::mutex mutex_;
128 };
129 
130 class TimeoutGestureModel {
131 public:
132     static TimeoutGestureModel* GetInstance();
133     virtual ~TimeoutGestureModel() = default;
134 
135     virtual RefPtr<GestureProcessor> GetGestureProcessor() = 0;
136 
137 private:
138     static std::unique_ptr<TimeoutGestureModel> instance_;
139     static std::mutex mutex_;
140 };
141 } // namespace OHOS::Ace
142 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_GESTURE_GESTURE_MODEL_H
143