webengine/webkitutils/rt_gesturehelper/src/gesturehelperimpl.h
changeset 42 d39add9822e2
parent 38 6297cdf66332
child 46 ea4b2e4f7cac
child 47 9377e2ba0634
child 65 5bfc169077b2
equal deleted inserted replaced
38:6297cdf66332 42:d39add9822e2
     1 /*
       
     2 * Copyright (c) 2007 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:  Gesture helper implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef _GESTUREHELPERIMPL_H_
       
    20 #define _GESTUREHELPERIMPL_H_
       
    21 
       
    22 #include <e32base.h>
       
    23 #include <coemain.h>
       
    24 #include <rt_gesturehelper.h>
       
    25 
       
    26 
       
    27 struct TPointerEvent;
       
    28 
       
    29 namespace RT_GestureHelper
       
    30 {
       
    31 
       
    32 class CCallbackTimer;
       
    33 class CGesture;
       
    34 class CPointerCapturer;
       
    35 class MGestureObserver;
       
    36 class CGestureEventFilter;
       
    37 class CGestureEventSender;
       
    38 
       
    39 /**
       
    40  * Implementation of CGestureHelper interface
       
    41  */
       
    42 NONSHARABLE_CLASS( CGestureHelperImpl ) : public CBase
       
    43     {
       
    44 public:
       
    45     /** 2-phase constructor */
       
    46     static CGestureHelperImpl* NewL( MGestureObserver& aObserver );
       
    47     
       
    48     /** Destructor */
       
    49     ~CGestureHelperImpl();    
       
    50     
       
    51     
       
    52     /** See @ref CGestureHelper::SetHoldingEnabled */
       
    53     void SetHoldingEnabled( TBool aEnabled );
       
    54     /** See @ref CGestureHelper::IsHoldingEnabled */
       
    55     TBool IsHoldingEnabled() const;
       
    56     /** See @ref CGestureHelper::SetDoubleTapEnabled */
       
    57     void SetDoubleTapEnabled( TBool aEnabled );
       
    58     /** See @ref CGestureHelper::IsDoubleTapEnabled */
       
    59     TBool IsDoubleTapEnabled() const;
       
    60     /** See @ref CGestureHelper::HandlePointerEventL */
       
    61     TBool HandlePointerEventL( const TPointerEvent& aEvent );
       
    62     
       
    63     /** Reset helper state */
       
    64     void Reset();
       
    65    
       
    66     void SetLastEventTime() {iLastEventTime.HomeTime(); } /*CCoeEnv::Static()->LastEvent().Time();*/ 
       
    67     
       
    68     
       
    69     TTime GetLastEventTime() const { return iLastEventTime; }
       
    70 private:
       
    71     /** Constructor */
       
    72     CGestureHelperImpl( MGestureObserver& aObserver );
       
    73 
       
    74     
       
    75     
       
    76     TBool noneAlf_HandlePointerEventL( const TPointerEvent& aEvent);
       
    77 
       
    78     /** @return ETrue if the helper has not started processing a gesture */
       
    79     inline TBool IsIdle() const;
       
    80     /** Add a point to the sequence of points that make up the gesture */
       
    81     inline void AddPointL( const TPointerEvent& aEvent );    
       
    82     /** Add a point to the sequence of points that make up the gesture */
       
    83     inline TInt AddPoint( const TPointerEvent& aEvent );    
       
    84     /** Activates holding and notifies observer that holding has been started */
       
    85     void StartHoldingL();
       
    86     /* Set previous tag gesture to null (and recycle the gesture object) */
       
    87     static void RecyclePreviousTapGesture( TAny* aSelf );
       
    88     /** Emits a tap event since second tap of a double tap was not received within timeout */
       
    89     void EmitFirstTapEvent();
       
    90     /** Emit the start gesture event that aGesture would have produced */
       
    91     void EmitStartEventL( const CGesture& aGesture );
       
    92     /** 
       
    93      * Send code event if not holding. Also sets the event to released and emits again.
       
    94      * Modifies aGesture! 
       
    95      */
       
    96     void CompleteAndEmit( CGesture& aGesture );
       
    97     /** 
       
    98      * Send cancel event about the latest gesture client was notified about 
       
    99      * Sets the latest gesture to Cancelled.
       
   100      */
       
   101     void EmitCancelEvent();
       
   102     
       
   103     /**
       
   104      * Send Released event
       
   105      */
       
   106     void EmitReleasedEvent();
       
   107     
       
   108     /** Notify observer of the gesture */
       
   109     void EmitEvent( const CGesture& aGesture );
       
   110     /** 
       
   111      * (re)start holding timer at the current point.
       
   112      * Does not restart holding if the point (in aEvent) is near enough to where holding 
       
   113      * was started earlier. (Allows small movement but still starting holding.
       
   114      */
       
   115     void StartHoldingTimer( const TPointerEvent& aNewEvent );
       
   116 
       
   117     /** 
       
   118      * @return a gesture object from the gesture pool 
       
   119      * Getting gestures from the gesture pool avoids the need to create gestures
       
   120      * after construction. There is max only one gesture object in the pool, 
       
   121      * but no more is needed 
       
   122      */
       
   123     CGesture* NewGesture();
       
   124     /** Move the gesture into the gesture pool, and set aGesturePointer to null */
       
   125     void RecycleGesture( CGesture*& aGesturePointer );
       
   126     
       
   127     
       
   128     void HandleTouchUp(const TPointerEvent& aEvent);
       
   129     void HandleTouchDownL(const TPointerEvent& aEvent);
       
   130     void HandleMoveL(const TPointerEvent& aEvent);
       
   131     void HandleLongTouch();
       
   132     void EmitDoubleTapEvent();
       
   133     TBool IsMovementGesture(TGestureCode aCode);
       
   134     
       
   135 private:
       
   136     /// Gesture is the logical representation of a sequence of points arriving
       
   137     /// at certain times
       
   138     /// This is the current gesture
       
   139     CGesture* iGesture;
       
   140     
       
   141     /// Tap gesture of the previous gesture. Used when double tap is enabled.
       
   142     /// The gesture is cached, since it cannot be emitted until gesture helper
       
   143     /// knows whether the next gesture forms a double tap
       
   144     /// @see CGestureHelperImpl::iDoubleTapTimer
       
   145     CGesture* iPreviousTapGesture;
       
   146 
       
   147     /// This is a recyclable object pool with just one object.
       
   148     /// This class needs one or two gesture objects at any one time. There is one
       
   149     /// less error condition to handle if gesture objects are not created after
       
   150     /// construction. Therefore, if only one gesture object is needed at a specific,
       
   151     /// point in time, the unused gesture object is stored here.
       
   152     CGesture* iUnusedGesture;
       
   153     
       
   154     /// When double tap is enabled, a tap
       
   155     /// event (and it's released event) is only emitted after the double tap timeout
       
   156     /// passes. If user taps again before the timeout (in the same position),
       
   157     /// this gesture is emitted as a double tap (followed by the released event, 
       
   158     /// and the second tap is not emitted at all.
       
   159     /// If user taps, and then swipes before the double tap timeout, this tap
       
   160     /// event (and it's released event) event is emitted, and only then the swipe's
       
   161     /// down and drag events are emitted. In other words, if user presses down
       
   162     /// during the timeout, the down event it not emitted until the gesture
       
   163     /// helper knows that the gesture is not another tap.
       
   164     /// Behavior while double tap enabled:
       
   165     /// Swipe: Down + drag + up => emits down + swipe/cancel + released
       
   166     /// Tap: Down + up => emits down ... timeout ... + tap + released
       
   167     /// Double tap: Down + up + down + up => emits down ... double tap + released
       
   168     /// Tap + quick swipe: Down + up + down + drag + ... => emits down ... tap + up (for tap) + down (for swipe ) + drag + ...
       
   169     /// Double tap timer is cancelled when the second pointer down event is received,
       
   170     /// i.e., it does not matter if user does this: 
       
   171     /// down + up + down ... long wait ... + up. It's still a double tap.
       
   172     CCallbackTimer* iDoubleTapTimer;
       
   173     
       
   174     /// holding is activated when user keeps pointer down in the same place for 
       
   175     /// a longer period. the holding timer activates off when enough time has passed.
       
   176     CCallbackTimer* iHoldingTimer;
       
   177     
       
   178     /// observer for gesture events
       
   179     MGestureObserver& iObserver;
       
   180     
       
   181     /// captures subsequent pointer events after pointer down received,
       
   182     /// until pointer up
       
   183     CPointerCapturer* iPointerCapturer;
       
   184 
       
   185     TTime  iLastEventTime;
       
   186     TTime  iLastTouchUpTime;
       
   187     TTime  iLastDoubleTapTime;
       
   188     
       
   189     CCallbackTimer*  iLongTouchTimer;
       
   190     CGestureEventFilter* iEventFilter;
       
   191     CGestureEventSender* iEventSender;
       
   192     };
       
   193     
       
   194 } // GestureHelper
       
   195 
       
   196 #endif // _GESTUREHELPERIMPL_H_