webengine/webkitutils/rt_gesturehelper/src/gesture.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) 2008-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 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 class
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef _GESTURE_H_
       
    19 #define _GESTURE_H_
       
    20 
       
    21 #include <e32base.h>
       
    22 
       
    23 #include <rt_gestureobserver.h>
       
    24 #include "gesturerecogniser.h"
       
    25 #include "pointarray.h"
       
    26 
       
    27 namespace RT_GestureHelper
       
    28 {
       
    29 
       
    30 enum TEventState
       
    31     {     
       
    32     ENoEvent = 0,
       
    33     ETouchDown,            
       
    34     ETouchUp,      
       
    35     EMove,
       
    36     ELongTouchDown
       
    37     };
       
    38 
       
    39 /**  
       
    40  * TGesture represents the gesture that the user has made.
       
    41  * Implements MGestureEvent interface to allow clients to 
       
    42  * inspect the gesture
       
    43  */
       
    44 NONSHARABLE_CLASS( CGesture ) : public CBase
       
    45     {
       
    46 public:  
       
    47     /** destructor */
       
    48     ~CGesture();
       
    49     
       
    50     /** 
       
    51      * @return a new gesture that will have only the first point
       
    52      * of this gesture. Can be used to create gesture's a "start" event
       
    53      * after some other points have been received. 
       
    54      */ 
       
    55     CGesture* AsStartEventLC() const;
       
    56     
       
    57     /** 
       
    58      * Sets the gesture as empty. resets timers to receive points
       
    59      * immediately
       
    60      */
       
    61     void Reset();
       
    62     
       
    63     /** @return ETrue if the gesture has no points */
       
    64     TBool IsEmpty() const;
       
    65     
       
    66     /**
       
    67      * Add a point to the sequence of points that forms the gesture
       
    68      * Call Reset() just before adding the first point
       
    69      * @param aPoint the point to add
       
    70      * @return error code
       
    71      */
       
    72     TInt AddPoint( const TPoint& aPoint, const TTime& eventtime);
       
    73     
       
    74     /** Set the visual of this gesture. Should be called when gesture starts */
       
    75     
       
    76     /** @return ETrue if the point is very near the holding point */
       
    77     TBool IsNearHoldingPoint( const TPoint& aPoint ) const;
       
    78     /** Set the latest point as the holding point */
       
    79     void SetHoldingPoint();
       
    80     /** @return ETrue if aPoint is the same as point added last */
       
    81     TBool IsLatestPoint( const TPoint& aPoint ) const;
       
    82     
       
    83     /** 
       
    84      * After call, Code(...) will return appropriate holding gesture code.
       
    85      */
       
    86     void StartHolding();
       
    87     /** 
       
    88      * After call, Code(...) will return a "hold released" gesture code when
       
    89      * the gesture is completed. Meanwhile, code will be drag.
       
    90      */
       
    91     void ContinueHolding();
       
    92     /** Set as stylus released */
       
    93     void SetReleased();
       
    94     /** Set the gesture as complete. Gesture is completed at pointer up */
       
    95     void SetComplete();
       
    96     /** After call, Code(...) will return a "cancelled" gesture code */
       
    97     void SetCancelled();
       
    98     
       
    99     /** force returning a code as double tap when gesture is complete */
       
   100     void SetDoubleTap();
       
   101     
       
   102     /** 
       
   103      * @return Whether the current gesture is a tap (and hence not a swipe)
       
   104      *         Does not consider holding or other state information (such as
       
   105      *         whether the gesture was just started or is dragging).  
       
   106      *         Results are based purely on the current stream of points.
       
   107      */ 
       
   108     TBool IsTap() const;
       
   109     
       
   110     void SetLongTap(TBool aLongTap);
       
   111     
       
   112 // From MGestureEvent
       
   113     TTime TimeOfLastEntry() const;
       
   114     inline TGestureCode PreviousGestureCode() { return iPrevGestureCode; };
       
   115     TGestureCode Code( TAxis aRelevantAxis );
       
   116     TBool IsHolding() const;
       
   117     TPoint StartPos() const;
       
   118     TPoint CurrentPos() const; 
       
   119     TRealPoint Speed() const;
       
   120     TRealPoint SpeedPercent( const TRect& aEdges ) const;
       
   121     TPoint Distance() const; 
       
   122     
       
   123     
       
   124     
       
   125     
       
   126 private:
       
   127     /** @return elapsed time between the latest and previous points */
       
   128     inline TTimeIntervalMicroSeconds32 TimeFromPreviousPoint() const; 
       
   129     
       
   130     /** @return elapsed time between the latest and first points */
       
   131     inline TTimeIntervalMicroSeconds32 TimeFromStart() const; 
       
   132     
       
   133     /** @return ETrue if user has stopped moving the stylus before lifting it */
       
   134     inline TBool IsMovementStopped() const;
       
   135     
       
   136     /** @return aOffset'th last entry in the list of points */
       
   137     inline const TPointEntry& NthLastEntry( TInt aOffset ) const;
       
   138     
       
   139     /** @return previous point (may not be exactly the point before last) */
       
   140     inline const TPointEntry& PreviousEntry() const;
       
   141     
       
   142     /** @return position of point received just before the latest point */
       
   143     inline TPoint PreviousPos() const;
       
   144     
       
   145     
       
   146     
       
   147     TBool IsFlick() const;
       
   148 private:
       
   149     /// sequence of points that make up the gesture. own.
       
   150     RArray< TPointEntry > iPoints;
       
   151     /// index in iPoints of the point in which user started holding
       
   152     TInt iHoldingPointIndex;
       
   153 
       
   154     /// the different states that indicate whether user has made a holding gesture 
       
   155     enum THoldingState
       
   156         {
       
   157         ENotHolding = 0, // before holding activated (i.e., holding not activated)
       
   158         EHoldStarting,   // holding activated just now (lasts just one callback round)
       
   159         EHolding         // holding activated earlier 
       
   160         };
       
   161   
       
   162     /// state that indicates is user has held the pointer down in one position 
       
   163     /// for long time to indicate a holding gesture    
       
   164     THoldingState iHoldingState;
       
   165     
       
   166     /// Whether the gesture completion code will be forcefully overridden to be double tap,
       
   167     /// regardless of what the points are
       
   168     TBool iIsDoubleTap;
       
   169     
       
   170     enum TCompletionState 
       
   171         {
       
   172         // Note: implementation assumes this order of enums
       
   173         ENotComplete = 0,
       
   174         ECancelled,
       
   175         EComplete,
       
   176         EReleased
       
   177         };
       
   178     /// gesture only becomes complete when user lifts the pointer
       
   179     TCompletionState iState;
       
   180 
       
   181     /// time when the stylus was lifted.
       
   182     TTime iCompletionTime;
       
   183     
       
   184     /// visual relevant to this gesture. null if not known.
       
   185     
       
   186     TGestureCode iPrevGestureCode;
       
   187     
       
   188     TBool iIsLongTap;
       
   189     TBool iIsStopFlick;
       
   190     };
       
   191 
       
   192 } // namespace GestureHelper
       
   193 
       
   194 #endif // _GESTURE_H_