webengine/webkitutils/stmgesturefw/inc/tapgesturerecogniser.h
changeset 65 5bfc169077b2
parent 42 d39add9822e2
child 66 cacf6ee57968
equal deleted inserted replaced
42:d39add9822e2 65:5bfc169077b2
     1 /*
       
     2 * Copyright (c) 2008 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 the License "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: Tap Gesture Recognizer
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef TAPGESTURERECOGNISER_H_
       
    19 #define TAPGESTURERECOGNISER_H_
       
    20 
       
    21 #include "rt_gestureengineif.h"
       
    22 #include <rt_gestureif.h>
       
    23 #include <rt_gesturelistener.h>
       
    24 
       
    25 class CCoeControl ;
       
    26 
       
    27 namespace stmGesture
       
    28 {
       
    29 
       
    30 /*!
       
    31  * CTapGestureRecogniser handles both tap and double tap recognition.
       
    32  * Doubletap needs to work even if it crosses window boundaries, so
       
    33  * CTapGestureRecogniser is a "global" recogniser.  The application
       
    34  * creates only one instance of it (TODO later: how to use Singleton
       
    35  * pattern in Symbian, seems to be tricky since we would need to have
       
    36  * writable static variable to hold the one instance, so currently
       
    37  * we need well-behaving app to handle this: the application must known
       
    38  * the nature of this gesture recogniser).
       
    39  * The different windows can add their callbacks, and when recognising tap
       
    40  * the target window is stored so that proper callback can be called.
       
    41  * Doubletap is reported either to the target of second tap, or if that windows parent
       
    42  * has a doubletap listener, to that.
       
    43  * Use separate listeners for tap and doubletap.
       
    44  */
       
    45 NONSHARABLE_CLASS( CTapGestureRecogniser ): public CTimer, public MGestureRecogniserIf
       
    46 {
       
    47 public:
       
    48     static const TGestureUid KUid = EGestureUidTap;
       
    49 
       
    50     /** Two-phase constructor */
       
    51     static CTapGestureRecogniser* NewL(MGestureListener* aListener) ;
       
    52 
       
    53     virtual ~CTapGestureRecogniser();
       
    54 
       
    55     /*!
       
    56      * MGestureRecogniserIf methods
       
    57      */
       
    58     virtual TGestureRecognitionState recognise(int numOfActiveStreams, MGestureEngineIf* ge) ;
       
    59     virtual void release(MGestureEngineIf* ge) ;
       
    60     virtual void enable(bool enabled) ;
       
    61     virtual bool isEnabled() ;
       
    62     virtual void setOwner(CCoeControl* owner) ;
       
    63 
       
    64     virtual TGestureUid gestureUid() const
       
    65         {
       
    66         return KUid;
       
    67         }
       
    68 
       
    69     /*!
       
    70      * Additional methods to set up tap gesture recogniser:
       
    71      * define the double tap timeout in microseconds.
       
    72      * \param timeoutInMicroseconds
       
    73      */
       
    74     void setDoubleTapTimeout(int timeoutInMicroseconds) ;
       
    75 
       
    76     /*!
       
    77      * Additional methods to set up tap gesture recogniser:
       
    78      * define how close the two taps need to be to be recognised
       
    79      * as a double tap.
       
    80      * \param rangeInMillimetres
       
    81      */
       
    82     void setDoubleTapRange(int rangeInMillimetres) ;
       
    83     /*!
       
    84      * Additional methods to set up tap gesture recogniser:
       
    85      * Produce two separate taps or just ignore the first one
       
    86      * if the second tap is outside range.
       
    87      */
       
    88     void ignoreFirstTap(bool ignore) ;
       
    89 
       
    90     /*!
       
    91      * Method to add a listener to tap gestures
       
    92      */
       
    93     void addTapListener(MGestureListener* aListener, CCoeControl* listenerOwner) ;
       
    94     /*!
       
    95      * Method to remove a listener from tap gestures
       
    96      */
       
    97     void removeTapListener(MGestureListener* aListener, CCoeControl* listenerOwner) ;
       
    98     /*!
       
    99      * Method to add a listener to doubletap gestures
       
   100      */
       
   101     void addDoubleTapListener(MGestureListener* aListener, CCoeControl* listenerOwner) ;
       
   102     /*!
       
   103      * Method to remove a listener from doubletap gestures
       
   104      */
       
   105     void removeDoubleTapListener(MGestureListener* aListener, CCoeControl* listenerOwner) ;
       
   106 
       
   107     /*!
       
   108      * for testing purposes we need to log the stuff somewhere...
       
   109      */
       
   110 public:
       
   111     virtual void enableLogging(bool loggingOn) ;
       
   112 
       
   113     /*!
       
   114      * The timer function to handle timeout for tap
       
   115      */
       
   116     virtual void RunL() ;
       
   117 
       
   118 
       
   119 private:
       
   120     CTapGestureRecogniser(MGestureListener* aListener) ;
       
   121     bool m_loggingenabled ;
       
   122     bool isSecondTapClose(const TPoint& secondPoint, const TPoint& firstPoint) ;
       
   123 private:
       
   124     CCoeControl* m_powner ; // The owning control for this gesture
       
   125     bool m_waitingforsecondtap ;
       
   126     TPoint m_firstTapXY ;
       
   127     CCoeControl* m_firstTapTarget ;
       
   128     float m_firstTapSpeedX ;
       
   129     float m_firstTapSpeedY ;
       
   130     int m_doubleTapTimeout ;
       
   131     bool m_gestureEnabled ;
       
   132     bool m_ignorefirst ;
       
   133     int  m_rangesizeInPixels ;
       
   134     // use simple arrays to store the listeners and corresponding windows
       
   135     RPointerArray<MGestureListener> m_tapListeners ;
       
   136     RPointerArray<CCoeControl> m_tapListenerWindows ;
       
   137     RPointerArray<MGestureListener> m_doubleTapListeners ;
       
   138     RPointerArray<CCoeControl> m_doubleTapListenerWindows ;
       
   139 
       
   140 
       
   141 };
       
   142 
       
   143 } // namespace
       
   144 
       
   145 #endif /* TAPGESTURERECOGNISER_H_ */