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