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