|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Gesture recognition engine. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <akntouchgesturefwobserver.h> |
|
19 |
|
20 #include "akntouchgesturefwdefs.h" |
|
21 #include "akntouchgesturefwbaserecognizer.h" |
|
22 #include "akntouchgesturefwdragrecognizer.h" |
|
23 #include "akntouchgesturefwevent.h" |
|
24 #include "akntouchgesturefwflickrecognizer.h" |
|
25 #include "akntouchgesturefwpinchrecognizer.h" |
|
26 #include "akntouchgesturefwpointerstate.h" |
|
27 #include "akntouchgesturefwrecognitionengine.h" |
|
28 #include "akntouchgesturefwsettings.h" |
|
29 #include "akntouchgesturefwtaprecognizer.h" |
|
30 |
|
31 using namespace AknTouchGestureFw; |
|
32 |
|
33 // Array of gesture groups |
|
34 const TAknTouchGestureFwGroup KGestureGroup[] = |
|
35 { |
|
36 EAknTouchGestureFwGroupTap, |
|
37 EAknTouchGestureFwGroupDrag, |
|
38 EAknTouchGestureFwGroupFlick, |
|
39 EAknTouchGestureFwGroupPinch |
|
40 }; |
|
41 |
|
42 // ======== MEMBER FUNCTIONS ======== |
|
43 |
|
44 // --------------------------------------------------------------------------- |
|
45 // Two-phased constructor. |
|
46 // --------------------------------------------------------------------------- |
|
47 // |
|
48 CAknTouchGestureFwRecognitionEngine* CAknTouchGestureFwRecognitionEngine::NewL( |
|
49 MAknTouchGestureFwObserver& aObserver, CCoeControl* aControl ) |
|
50 { |
|
51 CAknTouchGestureFwRecognitionEngine* self = |
|
52 CAknTouchGestureFwRecognitionEngine::NewLC( aObserver, aControl ); |
|
53 CleanupStack::Pop( self ); |
|
54 return self; |
|
55 } |
|
56 |
|
57 |
|
58 // --------------------------------------------------------------------------- |
|
59 // Two-phased constructor. |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 CAknTouchGestureFwRecognitionEngine* |
|
63 CAknTouchGestureFwRecognitionEngine::NewLC( |
|
64 MAknTouchGestureFwObserver& aObserver, CCoeControl* aControl ) |
|
65 { |
|
66 CAknTouchGestureFwRecognitionEngine* self |
|
67 = new ( ELeave ) CAknTouchGestureFwRecognitionEngine( aObserver, |
|
68 aControl ); |
|
69 CleanupStack::PushL( self ); |
|
70 self->ConstructL(); |
|
71 return self; |
|
72 } |
|
73 |
|
74 |
|
75 // --------------------------------------------------------------------------- |
|
76 // Destructor |
|
77 // --------------------------------------------------------------------------- |
|
78 // |
|
79 CAknTouchGestureFwRecognitionEngine::~CAknTouchGestureFwRecognitionEngine() |
|
80 { |
|
81 delete iPointerState; |
|
82 delete iSettings; |
|
83 iRecognizers.ResetAndDestroy(); |
|
84 iRecognizers.Close(); |
|
85 } |
|
86 |
|
87 |
|
88 // --------------------------------------------------------------------------- |
|
89 // Notifies the observer about a gesture event. |
|
90 // --------------------------------------------------------------------------- |
|
91 // |
|
92 void CAknTouchGestureFwRecognitionEngine::NotifyObserverL( |
|
93 MAknTouchGestureFwEvent& aEvent ) |
|
94 { |
|
95 #ifdef GFW_DEBUG_TRACE_INPUTOUTPUT |
|
96 AknTouchGestureFwUtils::DumpGestureEvent( aEvent ); |
|
97 #endif // GFW_DEBUG_TRACE_INPUTOUTPUT |
|
98 |
|
99 iObserver.HandleTouchGestureL( aEvent ); |
|
100 } |
|
101 |
|
102 |
|
103 // --------------------------------------------------------------------------- |
|
104 // Sets the gesture interest. |
|
105 // --------------------------------------------------------------------------- |
|
106 // |
|
107 void CAknTouchGestureFwRecognitionEngine::SetGestureInterestL( |
|
108 TUint aGestureGroups ) |
|
109 { |
|
110 TUint newGestureInterest( aGestureGroups ); |
|
111 |
|
112 // Create recognizers on demand. |
|
113 if ( newGestureInterest & EAknTouchGestureFwGroupPinch ) |
|
114 { |
|
115 CreateRecognizerL( EAknTouchGestureFwGroupPinch ); |
|
116 } |
|
117 |
|
118 if ( newGestureInterest & EAknTouchGestureFwGroupDrag ) |
|
119 { |
|
120 CreateRecognizerL( EAknTouchGestureFwGroupDrag ); |
|
121 } |
|
122 |
|
123 if ( newGestureInterest & EAknTouchGestureFwGroupFlick ) |
|
124 { |
|
125 CreateRecognizerL( EAknTouchGestureFwGroupFlick ); |
|
126 } |
|
127 |
|
128 if ( newGestureInterest & EAknTouchGestureFwGroupTap ) |
|
129 { |
|
130 CreateRecognizerL( EAknTouchGestureFwGroupTap ); |
|
131 } |
|
132 |
|
133 iGestureInterest = newGestureInterest; |
|
134 |
|
135 // Enable/disable recognizers. |
|
136 UpdateRecognizersForInterest( newGestureInterest ); |
|
137 } |
|
138 |
|
139 |
|
140 // --------------------------------------------------------------------------- |
|
141 // Returns the current gesture interest. |
|
142 // --------------------------------------------------------------------------- |
|
143 // |
|
144 TUint CAknTouchGestureFwRecognitionEngine::GestureInterest() const |
|
145 { |
|
146 return iGestureInterest; |
|
147 } |
|
148 |
|
149 |
|
150 // --------------------------------------------------------------------------- |
|
151 // Cancels the gesture recognition. |
|
152 // --------------------------------------------------------------------------- |
|
153 // |
|
154 void CAknTouchGestureFwRecognitionEngine::CancelRecognizing() |
|
155 { |
|
156 if ( iSingleRecognizing || iMultiRecognizing ) |
|
157 { |
|
158 iSingleRecognizing = EFalse; |
|
159 iMultiRecognizing = EFalse; |
|
160 |
|
161 iPointerState->Reset(); |
|
162 |
|
163 for ( TInt i = 0; i < iRecognizers.Count(); i++ ) |
|
164 { |
|
165 iRecognizers[ i ]->CancelRecognizing(); |
|
166 } |
|
167 } |
|
168 } |
|
169 |
|
170 |
|
171 // --------------------------------------------------------------------------- |
|
172 // Handles pointer events. |
|
173 // --------------------------------------------------------------------------- |
|
174 // |
|
175 void CAknTouchGestureFwRecognitionEngine::HandlePointerEventL( |
|
176 const TPointerEventData& aPointerData ) |
|
177 { |
|
178 // Note: term pointer means physical pointer, e.g. finger |
|
179 // in the following comments. So first pointer down |
|
180 // means that single finger has been pressed down and |
|
181 // second pointer down means that also another finger has |
|
182 // been pressed down |
|
183 |
|
184 // Update pointer state |
|
185 if ( !iPointerState->Update( aPointerData ) ) |
|
186 { |
|
187 // Send unknown event if successive down events were received |
|
188 // to same pointer |
|
189 if ( iTestingEnabled && iPointerState->SuccessiveDownEventsReceived() ) |
|
190 { |
|
191 TAknTouchGestureFwUnknownEvent unknown; |
|
192 NotifyObserverL( unknown ); |
|
193 } |
|
194 return; |
|
195 } |
|
196 |
|
197 TBool multiTouchEvent( iMultiRecognizing ); |
|
198 |
|
199 if ( aPointerData.iPointerEvent.iType == TPointerEvent::EButton1Down ) |
|
200 { |
|
201 // Single recognizing with first button down |
|
202 if ( !iSingleRecognizing ) |
|
203 { |
|
204 iMultiRecognizing = EFalse; |
|
205 iSingleRecognizing = ETrue; |
|
206 multiTouchEvent = EFalse; |
|
207 } |
|
208 else |
|
209 { |
|
210 // Second pointer down starts multi recognizing |
|
211 iSingleRecognizing = EFalse; |
|
212 iMultiRecognizing = ETrue; |
|
213 multiTouchEvent = ETrue; |
|
214 } |
|
215 } |
|
216 else if ( aPointerData.iPointerEvent.iType == TPointerEvent::EButton1Up ) |
|
217 { |
|
218 if ( iMultiRecognizing && iPointerState->IsSingleTouch() ) |
|
219 { |
|
220 iSingleRecognizing = ETrue; |
|
221 iMultiRecognizing = EFalse; |
|
222 multiTouchEvent = ETrue; |
|
223 } |
|
224 else if ( iSingleRecognizing && iPointerState->IsNoTouch() ) |
|
225 { |
|
226 // Single recognizing ongoing, pointer goes up. |
|
227 iSingleRecognizing = EFalse; |
|
228 iMultiRecognizing = EFalse; |
|
229 multiTouchEvent = EFalse; |
|
230 } |
|
231 } |
|
232 |
|
233 SendPointerEventToRecognizersL( multiTouchEvent, aPointerData ); |
|
234 } |
|
235 |
|
236 |
|
237 // --------------------------------------------------------------------------- |
|
238 // Returns the framework settings provider. |
|
239 // --------------------------------------------------------------------------- |
|
240 // |
|
241 CAknTouchGestureFwSettings& CAknTouchGestureFwRecognitionEngine::Settings() const |
|
242 { |
|
243 return *iSettings; |
|
244 } |
|
245 |
|
246 |
|
247 // --------------------------------------------------------------------------- |
|
248 // EnableTestingFeatures |
|
249 // --------------------------------------------------------------------------- |
|
250 // |
|
251 void CAknTouchGestureFwRecognitionEngine::EnableTestingFeatures() |
|
252 { |
|
253 iTestingEnabled = ETrue; |
|
254 } |
|
255 |
|
256 |
|
257 // --------------------------------------------------------------------------- |
|
258 // C++ constructor. |
|
259 // --------------------------------------------------------------------------- |
|
260 // |
|
261 CAknTouchGestureFwRecognitionEngine::CAknTouchGestureFwRecognitionEngine( |
|
262 MAknTouchGestureFwObserver& aObserver, CCoeControl* aControl ) |
|
263 : |
|
264 iObserver( aObserver ), |
|
265 iPointerState( NULL ), |
|
266 iSettings( NULL ), |
|
267 iGestureInterest( EAknTouchGestureFwNoGroup ), |
|
268 iSingleRecognizing( EFalse ), |
|
269 iMultiRecognizing( EFalse ), |
|
270 iControl( aControl ), |
|
271 iFeedBack( MTouchFeedback::Instance() ) |
|
272 { |
|
273 } |
|
274 |
|
275 |
|
276 // --------------------------------------------------------------------------- |
|
277 // Second-phase constructor. |
|
278 // --------------------------------------------------------------------------- |
|
279 // |
|
280 void CAknTouchGestureFwRecognitionEngine::ConstructL() |
|
281 { |
|
282 iPointerState = CAknTouchGestureFwPointerState::NewL(); |
|
283 iSettings = CAknTouchGestureFwSettings::NewL(); |
|
284 } |
|
285 |
|
286 |
|
287 // --------------------------------------------------------------------------- |
|
288 // Enables/disables the necessary recognizers based on the gesture interest. |
|
289 // --------------------------------------------------------------------------- |
|
290 // |
|
291 void CAknTouchGestureFwRecognitionEngine::UpdateRecognizersForInterest( |
|
292 TUint aGestureInterest ) |
|
293 { |
|
294 for ( TInt i = 0; i < iRecognizers.Count(); i++ ) |
|
295 { |
|
296 if ( iRecognizers[i]->GestureGroup() & aGestureInterest ) |
|
297 { |
|
298 iRecognizers[i]->SetEnabled( ETrue ); |
|
299 } |
|
300 else |
|
301 { |
|
302 iRecognizers[i]->SetEnabled( EFalse ); |
|
303 } |
|
304 } |
|
305 } |
|
306 |
|
307 |
|
308 // --------------------------------------------------------------------------- |
|
309 // Creates the recognizer for the specified gesture group. |
|
310 // --------------------------------------------------------------------------- |
|
311 // |
|
312 CAknTouchGestureFwBaseRecognizer* |
|
313 CAknTouchGestureFwRecognitionEngine::CreateRecognizerL( |
|
314 TAknTouchGestureFwGroup aGroup ) |
|
315 { |
|
316 // Check first that the recognizer doesn't already exist. |
|
317 CAknTouchGestureFwBaseRecognizer* newRecognizer( Recognizer( aGroup ) ); |
|
318 if ( newRecognizer ) |
|
319 { |
|
320 return newRecognizer; |
|
321 } |
|
322 |
|
323 switch ( aGroup ) |
|
324 { |
|
325 case ( EAknTouchGestureFwGroupTap ): |
|
326 { |
|
327 newRecognizer = CAknTouchGestureFwTapRecognizer::NewLC( *this ); |
|
328 break; |
|
329 } |
|
330 case ( EAknTouchGestureFwGroupFlick ): |
|
331 { |
|
332 newRecognizer = CAknTouchGestureFwFlickRecognizer::NewLC( *this ); |
|
333 break; |
|
334 } |
|
335 case ( EAknTouchGestureFwGroupDrag ): |
|
336 { |
|
337 newRecognizer = CAknTouchGestureFwDragRecognizer::NewLC( *this ); |
|
338 break; |
|
339 } |
|
340 case ( EAknTouchGestureFwGroupPinch ): |
|
341 { |
|
342 newRecognizer = CAknTouchGestureFwPinchRecognizer::NewLC( *this ); |
|
343 break; |
|
344 } |
|
345 |
|
346 default: |
|
347 { |
|
348 break; |
|
349 } |
|
350 } |
|
351 |
|
352 if ( newRecognizer ) |
|
353 { |
|
354 iRecognizers.AppendL( newRecognizer ); |
|
355 CleanupStack::Pop( newRecognizer ); |
|
356 } |
|
357 |
|
358 return newRecognizer; |
|
359 } |
|
360 |
|
361 |
|
362 // --------------------------------------------------------------------------- |
|
363 // Gets recognizer for the specified gesture group. |
|
364 // --------------------------------------------------------------------------- |
|
365 // |
|
366 CAknTouchGestureFwBaseRecognizer* |
|
367 CAknTouchGestureFwRecognitionEngine::Recognizer( |
|
368 TAknTouchGestureFwGroup aGroup ) |
|
369 { |
|
370 for ( TInt i = 0; i < iRecognizers.Count(); i++ ) |
|
371 { |
|
372 if ( iRecognizers[i]->GestureGroup() == aGroup ) |
|
373 { |
|
374 return iRecognizers[i]; |
|
375 } |
|
376 } |
|
377 return NULL; |
|
378 } |
|
379 |
|
380 |
|
381 // --------------------------------------------------------------------------- |
|
382 // Sends a pointer event to all enabled recognizers. |
|
383 // --------------------------------------------------------------------------- |
|
384 // |
|
385 void CAknTouchGestureFwRecognitionEngine::SendPointerEventToRecognizersL( |
|
386 TBool aMultiPointer, |
|
387 const TPointerEventData& aPointerData ) |
|
388 { |
|
389 // Inform recognizers of pointer event |
|
390 for ( TInt i = 0; i < iRecognizers.Count(); i++ ) |
|
391 { |
|
392 if ( iRecognizers[ i ]->Enabled() ) |
|
393 { |
|
394 // Multi pointer event |
|
395 if ( aMultiPointer ) |
|
396 { |
|
397 // Both pointers in use |
|
398 if ( iPointerState->IsDoubleTouch() ) |
|
399 { |
|
400 iRecognizers[ i ]->HandleMultiPointerEventL( |
|
401 aPointerData, |
|
402 *iPointerState->FirstPointerPosition(), |
|
403 *iPointerState->SecondPointerPosition() ); |
|
404 } |
|
405 // One pointer up |
|
406 else |
|
407 { |
|
408 iRecognizers[ i ]->HandleMultiPointerEventL( |
|
409 aPointerData, |
|
410 *iPointerState->FirstPointerPosition(), |
|
411 TPoint() ); |
|
412 } |
|
413 } |
|
414 // Single pointer event |
|
415 else |
|
416 { |
|
417 iRecognizers[ i ]->HandleSinglePointerEventL( |
|
418 aPointerData ); |
|
419 } |
|
420 } |
|
421 } |
|
422 } |
|
423 |
|
424 |
|
425 // ----------------------------------------------------------------------------- |
|
426 // CAknTouchGestureFwRecognitionEngine::ImmediateFeedback |
|
427 // ----------------------------------------------------------------------------- |
|
428 // |
|
429 void CAknTouchGestureFwRecognitionEngine::ImmediateFeedback( |
|
430 TTouchLogicalFeedback aLogicalFeedback, |
|
431 TTouchFeedbackType aFeedbackType ) |
|
432 { |
|
433 if ( iFeedBack ) |
|
434 { |
|
435 // dummy pointer event is needed |
|
436 TPointerEvent pointerEvent; |
|
437 iFeedBack->InstantFeedback( iControl, aLogicalFeedback, aFeedbackType, |
|
438 pointerEvent ); |
|
439 } |
|
440 } |
|
441 |
|
442 |
|
443 // ----------------------------------------------------------------------------- |
|
444 // CAknTouchGestureFwRecognitionEngine::StartContinuousFeedback |
|
445 // ----------------------------------------------------------------------------- |
|
446 // |
|
447 void CAknTouchGestureFwRecognitionEngine::StartContinuousFeedback( |
|
448 TTouchContinuousFeedback aType, |
|
449 TInt aIntensity, |
|
450 TTimeIntervalMicroSeconds32 aTimeout ) |
|
451 { |
|
452 if ( iFeedBack ) |
|
453 { |
|
454 iFeedBack->StartFeedback( iControl, aType, NULL, |
|
455 aIntensity, aTimeout ); |
|
456 } |
|
457 } |
|
458 |
|
459 |
|
460 // ----------------------------------------------------------------------------- |
|
461 // CAknTouchGestureFwRecognitionEngine::ModifyContinuousFeedback |
|
462 // ----------------------------------------------------------------------------- |
|
463 // |
|
464 void CAknTouchGestureFwRecognitionEngine::ModifyContinuousFeedback( |
|
465 TInt aIntensity ) |
|
466 { |
|
467 iFeedBack->ModifyFeedback( iControl, aIntensity ); |
|
468 } |
|
469 |
|
470 |
|
471 // ----------------------------------------------------------------------------- |
|
472 // CAknTouchGestureFwRecognitionEngine::StopContinuousFeedback |
|
473 // ----------------------------------------------------------------------------- |
|
474 // |
|
475 void CAknTouchGestureFwRecognitionEngine::StopContinuousFeedback() |
|
476 { |
|
477 if ( iFeedBack ) |
|
478 { |
|
479 iFeedBack->StopFeedback( iControl ); |
|
480 } |
|
481 } |
|
482 |
|
483 |
|
484 // --------------------------------------------------------------------------- |
|
485 // Defines gesture groups, which trigger tactile feedback automatically. |
|
486 // --------------------------------------------------------------------------- |
|
487 // |
|
488 void CAknTouchGestureFwRecognitionEngine::SetFeedbackForGroupsL( TUint aGestureGroups ) |
|
489 { |
|
490 CAknTouchGestureFwBaseRecognizer* recognizer; |
|
491 |
|
492 TInt count = sizeof( KGestureGroup )/sizeof( TAknTouchGestureFwGroup ); |
|
493 for ( TInt i = 0; i < count; i++ ) |
|
494 { |
|
495 if ( aGestureGroups & KGestureGroup[ i ] ) |
|
496 { |
|
497 recognizer = Recognizer( KGestureGroup[ i ] ); |
|
498 if ( recognizer ) |
|
499 { |
|
500 recognizer->SetFeedbackForTypesL( |
|
501 KAknTouchGestureFwAllGestureTypes, |
|
502 KAknTouchGestureFwAllGestureTypes ); |
|
503 } |
|
504 } |
|
505 } |
|
506 } |
|
507 |
|
508 |
|
509 // --------------------------------------------------------------------------- |
|
510 // Defines gesture types, which trigger tactile feedback automatically. |
|
511 // --------------------------------------------------------------------------- |
|
512 // |
|
513 void CAknTouchGestureFwRecognitionEngine::SetFeedbackForTypesL( |
|
514 TAknTouchGestureFwGroup aGestureGroup, |
|
515 TUint aGestureTypesForTactile, |
|
516 TUint aGestureTypesForAudio ) |
|
517 { |
|
518 if ( aGestureGroup == EAknTouchGestureFwNoGroup ) |
|
519 { |
|
520 return; |
|
521 } |
|
522 if ( aGestureGroup == EAknTouchGestureFwAll ) |
|
523 { |
|
524 for ( TInt i = 0; i < iRecognizers.Count(); i++ ) |
|
525 { |
|
526 iRecognizers[ i ]->SetFeedbackForTypesL( aGestureTypesForTactile, |
|
527 aGestureTypesForAudio ); |
|
528 } |
|
529 return; |
|
530 } |
|
531 |
|
532 CAknTouchGestureFwBaseRecognizer* recognizer = |
|
533 Recognizer( aGestureGroup ); |
|
534 |
|
535 if ( recognizer ) |
|
536 { |
|
537 recognizer->SetFeedbackForTypesL( aGestureTypesForTactile, |
|
538 aGestureTypesForAudio ); |
|
539 } |
|
540 } |
|
541 |
|
542 // End of File |