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