• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/// <reference path='./import.ts' />
17enum CommonGestureType {
18    TAP_GESTURE = 0,
19    LONG_PRESS_GESTURE,
20    PAN_GESTURE,
21    SWIPE_GESTURE,
22    PINCH_GESTURE,
23    ROTATION_GESTURE,
24    GESTURE_GROUP,
25}
26
27class GestureHandler {
28    gestureType: CommonGestureType;
29
30    constructor(gestureType: CommonGestureType) {
31        this.gestureType = gestureType;
32    }
33}
34
35class TapGestureHandler extends GestureHandler {
36    fingers?: number;
37    count?: number;
38    gestureTag?: string;
39    allowedTypes?: Array<SourceTool>;
40    onActionCallback?: Callback<GestureEvent>;
41
42    constructor(options?: TapGestureHandlerOptions) {
43        super(CommonGestureType.TAP_GESTURE);
44        if (options !== undefined) {
45            this.fingers = options.fingers;
46            this.count = options.count;
47        }
48    }
49    onAction(event: Callback<GestureEvent>) {
50        this.onActionCallback = event;
51        return this;
52    }
53    tag(tag: string) {
54        this.gestureTag = tag;
55        return this;
56    }
57    allowedTypes(types: Array<SourceTool>) {
58        this.allowedTypes = types;
59        return this;
60    }
61}
62
63class LongPressGestureHandler extends GestureHandler {
64    fingers?: number;
65    repeat?: boolean;
66    duration?: number;
67    gestureTag?: string;
68    allowedTypes?: Array<SourceTool>;
69    onActionCallback?: Callback<GestureEvent>;
70    onActionEndCallback?: Callback<GestureEvent>;
71    onActionCancelCallback?: Callback<void>;
72    constructor(options?: LongPressGestureHandlerOptions) {
73        super(CommonGestureType.LONG_PRESS_GESTURE);
74        if (options !== undefined) {
75            this.fingers = options.fingers;
76            this.repeat = options.repeat;
77            this.duration = options.duration;
78        }
79    }
80
81    onAction(event: Callback<GestureEvent>) {
82        this.onActionCallback = event;
83        return this;
84    }
85
86    onActionEnd(event: Callback<GestureEvent>) {
87        this.onActionEndCallback = event;
88        return this;
89    }
90
91    onActionCancel(event: Callback<void>) {
92        this.onActionCancelCallback = event;
93        return this;
94    }
95
96    tag(tag: string) {
97        this.gestureTag = tag;
98        return this;
99    }
100
101    allowedTypes(types: Array<SourceTool>) {
102        this.allowedTypes = types;
103        return this;
104    }
105}
106
107class PanGestureHandler extends GestureHandler {
108    fingers?: number;
109    direction?: PanDirection;
110    distance?: number;
111    gestureTag?: string;
112    allowedTypes?: Array<SourceTool>;
113    onActionStartCallback?: Callback<GestureEvent>;
114    onActionUpdateCallback?: Callback<GestureEvent>;
115    onActionEndCallback?: Callback<GestureEvent>;
116    onActionCancelCallback?: Callback<void>;
117    constructor(options?: PanGestureHandlerOptions) {
118        super(CommonGestureType.PAN_GESTURE);
119        if (options !== undefined) {
120            this.fingers = options.fingers;
121            this.direction = options.direction;
122            this.distance = options.distance;
123        }
124    }
125
126    onActionStart(event: Callback<GestureEvent>) {
127        this.onActionStartCallback = event;
128        return this;
129    }
130
131    onActionUpdate(event: Callback<GestureEvent>) {
132        this.onActionUpdateCallback = event;
133        return this;
134    }
135
136    onActionEnd(event: Callback<GestureEvent>) {
137        this.onActionEndCallback = event;
138        return this;
139    }
140
141    onActionCancel(event: Callback<void>) {
142        this.onActionCancelCallback = event;
143        return this;
144    }
145
146    tag(tag: string) {
147        this.gestureTag = tag;
148        return this;
149    }
150
151    allowedTypes(types: Array<SourceTool>) {
152        this.allowedTypes = types;
153        return this;
154    }
155}
156
157class SwipeGestureHandler extends GestureHandler {
158    fingers?: number;
159    direction?: SwipeDirection;
160    speed?: number;
161    gestureTag?: string;
162    allowedTypes?: Array<SourceTool>;
163    onActionCallback?: Callback<GestureEvent>;
164    constructor(options?: SwipeGestureHandlerOptions) {
165        super(CommonGestureType.PAN_GESTURE);
166        if (options !== undefined) {
167            this.fingers = options.fingers;
168            this.direction = options.direction;
169            this.speed = options.speed;
170        }
171    }
172
173    onAction(event: Callback<GestureEvent>) {
174        this.onActionCallback = event;
175        return this;
176    }
177
178    tag(tag: string) {
179        this.gestureTag = tag;
180        return this;
181    }
182
183    allowedTypes(types: Array<SourceTool>) {
184        this.allowedTypes = types;
185        return this;
186    }
187}
188
189class PinchGestureHandler extends GestureHandler {
190    fingers?: number;
191    distance?: number;
192    gestureTag?: string;
193    allowedTypes?: Array<SourceTool>;
194    onActionStartCallback?: Callback<GestureEvent>;
195    onActionUpdateCallback?: Callback<GestureEvent>;
196    onActionEndCallback?: Callback<GestureEvent>;
197    onActionCancelCallback?: Callback<void>;
198    constructor(options?: PinchGestureHandlerOptions) {
199        super(CommonGestureType.PINCH_GESTURE);
200        if (options !== undefined) {
201            this.fingers = options.fingers;
202            this.distance = options.distance;
203        }
204    }
205
206    onActionStart(event: Callback<GestureEvent>) {
207        this.onActionStartCallback = event;
208        return this;
209    }
210
211    onActionUpdate(event: Callback<GestureEvent>) {
212        this.onActionUpdateCallback = event;
213        return this;
214    }
215
216    onActionEnd(event: Callback<GestureEvent>) {
217        this.onActionEndCallback = event;
218        return this;
219    }
220
221    onActionCancel(event: Callback<void>) {
222        this.onActionCancelCallback = event;
223        return this;
224    }
225
226    tag(tag: string) {
227        this.gestureTag = tag;
228        return this;
229    }
230
231    allowedTypes(types: Array<SourceTool>) {
232        this.allowedTypes = types;
233        return this;
234    }
235}
236
237class RotationGestureHandler extends GestureHandler {
238    fingers?: number;
239    angle?: number;
240    gestureTag?: string;
241    allowedTypes?: Array<SourceTool>;
242    onActionStartCallback?: Callback<GestureEvent>;
243    onActionUpdateCallback?: Callback<GestureEvent>;
244    onActionEndCallback?: Callback<GestureEvent>;
245    onActionCancelCallback?: Callback<void>;
246    constructor(options?: RotationGestureHandlerOptions) {
247        super(CommonGestureType.ROTATION_GESTURE);
248        if (options !== undefined) {
249            this.fingers = options.fingers;
250            this.angle = options.angle;
251        }
252    }
253
254    onActionStart(event: Callback<GestureEvent>) {
255        this.onActionStartCallback = event;
256        return this;
257    }
258
259    onActionUpdate(event: Callback<GestureEvent>) {
260        this.onActionUpdateCallback = event;
261        return this;
262    }
263
264    onActionEnd(event: Callback<GestureEvent>) {
265        this.onActionEndCallback = event;
266        return this;
267    }
268
269    onActionCancel(event: Callback<void>) {
270        this.onActionCancelCallback = event;
271        return this;
272    }
273
274    tag(tag: string) {
275        this.gestureTag = tag;
276        return this;
277    }
278
279    allowedTypes(types: Array<SourceTool>) {
280        this.allowedTypes = types;
281        return this;
282    }
283}
284
285class GestureGroupHandler extends GestureHandler {
286    mode?: GestureMode;
287    gestures?: GestureHandler[];
288    gestureTag?: string;
289    onCancelCallback?: Callback<void>;
290    constructor(options?: GestureGroupGestureHandlerOptions) {
291        super(CommonGestureType.GESTURE_GROUP);
292        if (options !== undefined) {
293            this.mode = options.mode;
294            this.gestures = options.gestures;
295        }
296    }
297
298    onCancel(event: Callback<void>) {
299        this.onCancelCallback = event;
300        return this;
301    }
302
303    tag(tag: string) {
304        this.gestureTag = tag;
305        return this;
306    }
307}