uifw/EikStd/coctlinc/aknedwinphysicshandler.h
changeset 0 2f259fa3e83a
child 9 aabf2c525e0f
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     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:  EikEdwin physics handler
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef C_AKNEDWINPHYSICSHANDLER_H
       
    19 #define C_AKNEDWINPHYSICSHANDLER_H
       
    20 
       
    21 
       
    22 #include <e32base.h>
       
    23 #include <aknphysicsobserveriface.h>
       
    24 
       
    25 class CAknPhysics;
       
    26 class CEikEdwin;
       
    27 
       
    28 /**
       
    29  *  EikEdwin physics handler.
       
    30  *
       
    31  *  @lib eikcoctl
       
    32  *  @since S60 v5.2
       
    33  */
       
    34 NONSHARABLE_CLASS( CAknEdwinPhysicsHandler ) : public CBase,
       
    35                                                public MAknPhysicsObserver
       
    36     {
       
    37 
       
    38 public:
       
    39 
       
    40     /**
       
    41      * Two-phased constructor.
       
    42      */
       
    43     static CAknEdwinPhysicsHandler* NewL( CEikEdwin& aEdwin );
       
    44 
       
    45     /**
       
    46      * Two-phased constructor.
       
    47      */
       
    48     static CAknEdwinPhysicsHandler* NewLC( CEikEdwin& aEdwin );
       
    49     /**
       
    50      * Destructor.
       
    51      */
       
    52     virtual ~CAknEdwinPhysicsHandler();
       
    53     
       
    54 public:
       
    55     
       
    56     /**
       
    57      * Sets view rect.
       
    58      *
       
    59      * @param aRect New view rect.
       
    60      */
       
    61     void SetViewRect( const TRect& aRect );
       
    62     
       
    63     /**
       
    64      * Initializes physics.
       
    65      */
       
    66     void InitPhysicsL();
       
    67   
       
    68     /**
       
    69      * Moves the scroll index.
       
    70      *
       
    71      * @param aPixelsToMove Number of pixels to move.
       
    72      */
       
    73     void MoveScrollIndex( TInt aPixelsToMove );
       
    74     
       
    75     /**
       
    76      * Returns ETrue if flicking or bouncing is ongoing.
       
    77      *
       
    78      * @return ETrue if flicking or bouncing is ongoing.
       
    79      */
       
    80     TBool EmulationOngoing();
       
    81     
       
    82     /**
       
    83      * Returns drag threshold.
       
    84      *
       
    85      * @return drag threshold.
       
    86      */
       
    87     TInt DragThreshold() const;
       
    88     
       
    89     /**
       
    90      * Initialises scrolling.
       
    91      *
       
    92      * @param aStartPosition Start position of dragging.
       
    93      */
       
    94     void InitKineticScrolling( const TPoint& aStartPosition );
       
    95     
       
    96     /**
       
    97      * Handles kinetic scrolling.
       
    98      *
       
    99      * @param aPointerEvent Pointer event to handle.
       
   100      * @param aShouldReturn Set to ETrue if we should return from
       
   101      *                      CEikEdwin's HandlePointerEventL after
       
   102      *                      call to this function. 
       
   103      */
       
   104     void HandleKineticScrolling( const TPointerEvent& aPointerEvent,
       
   105         TBool& aShouldReturn );
       
   106     
       
   107     /**
       
   108      * Returns ETrue if selection is started.
       
   109      *
       
   110      * @return ETrue if selection is started.
       
   111      */
       
   112     TBool SelectionStarted() const;
       
   113     
       
   114     /**
       
   115      * Returns ETrue if dragging is started.
       
   116      *
       
   117      * @return ETrue if dragging is started.
       
   118      */
       
   119     TBool DraggingStarted() const;
       
   120     
       
   121     /**
       
   122      * Returns ETrue if drag threshold is exceeded.
       
   123      *
       
   124      * @param aCurrentPosition Current position of dragging.
       
   125      * @return ETrue if drag threshold is exceeded.
       
   126      */
       
   127     TBool DragThresholdExceeded( const TPoint& aCurrentPosition ) const;
       
   128     
       
   129     
       
   130 public: // From base class MAknPhysicsObserver.
       
   131 
       
   132     /**
       
   133      * Called when view position changes.
       
   134      *
       
   135      * @param  aNewPosition  The new position of the view.
       
   136      * @param  aDrawNow      @c ETrue if the screen is to be redrawn,
       
   137      *                       otherwise @c EFalse.
       
   138      * @param  aFlags        Additional flags, not used currently.
       
   139      */
       
   140     virtual void ViewPositionChanged( const TPoint& aNewPosition,
       
   141                                       TBool aDrawNow = ETrue,
       
   142                                       TUint aFlags = 0 );
       
   143     
       
   144     /**
       
   145      * Called when emulation has ended.
       
   146      */
       
   147     virtual void PhysicEmulationEnded();
       
   148 
       
   149     /**
       
   150      * Returns the observer's view position.
       
   151      *
       
   152      * @return Physics observer's view position.
       
   153      */
       
   154     virtual TPoint ViewPosition() const;
       
   155     
       
   156 private:
       
   157 
       
   158     /**
       
   159      * C++ constructor.
       
   160      */
       
   161     CAknEdwinPhysicsHandler( CEikEdwin& aEdwin );
       
   162 
       
   163     /**
       
   164      * Symbian second-phase constructor.
       
   165      */
       
   166     void ConstructL();
       
   167 
       
   168     /**
       
   169      * Scrolls view to correct position.
       
   170      * 
       
   171      * @param  aAllowBounce If ETrue, it is possible to scroll
       
   172      *                      content out of borders.
       
   173      */
       
   174     void ScrollView( TBool aAllowBounce );
       
   175     
       
   176 	/**
       
   177      * Used to scroll view normally (without bounce).
       
   178      * Called from ScrollView.
       
   179      *
       
   180      * @param  aPixelsToScroll Number of pixels to scroll
       
   181      * @param  aAllowBounce    If this parameter is EFalse and end or
       
   182      *                         beginning of content is exceeded, this
       
   183      *                         function doesn't scroll over the border.
       
   184      *                         If this parameter is ETrue, it is possible
       
   185      *                         to scroll out of borders.  
       
   186      */
       
   187     void ScrollStep( TInt aPixelsToScroll, TBool aAllowBounce );
       
   188 	
       
   189 	/**
       
   190      * Used to scroll view with bounce (there can be empty
       
   191      * space above or below the content). 
       
   192      * Called from ScrollView.
       
   193      *
       
   194      * @param  aPixelsToScroll Number of pixels to scroll
       
   195      * @param  aRestOfPixels   Number of pixels not scrolled	 
       
   196      */
       
   197     void ScrollStepWithBounce( TInt aPixelsToScroll, TInt& aRestOfPixels );
       
   198     
       
   199 	/**
       
   200      * Moves world index.
       
   201      * 
       
   202      * @param  aDelta Number of pixels to move.
       
   203      */
       
   204     void MoveWorldIndex( TInt aDelta );
       
   205 	
       
   206 	/**
       
   207      * Scrolls rest of pixels. This function is used
       
   208      * to scroll rest of pixels when end or beginning
       
   209      * of content has exceeded and bounce starts. 
       
   210      *
       
   211      * @param  aRestOfPixels Number of pixels to scroll. 
       
   212      */
       
   213     void ScrollRestOfPixels( TInt aRestOfPixels ); 
       
   214 	
       
   215     /**
       
   216      * Stops physics.
       
   217      */
       
   218     void StopPhysics();
       
   219 	
       
   220 	/**
       
   221      * Blocks/unblocks pointer events.
       
   222      *
       
   223      * @param  aBlocked Tells if events should be blocked or not. 
       
   224      */
       
   225     void BlockEvents( TBool aBlocked );
       
   226     
       
   227     /**
       
   228      * Returns ETrue if flicking is ongoing. 
       
   229      */
       
   230     TBool IsFlicking() const;
       
   231     
       
   232     /**
       
   233      * Returns ETrue if bouncing is ongoing. 
       
   234      */
       
   235     TBool IsBouncing() const;
       
   236 
       
   237     /**
       
   238      * Initialises bounce.
       
   239      *
       
   240      * @param  aBounceDown ETrue if bouncing down. 
       
   241      */
       
   242     void InitBounce( TBool aBounceDown );
       
   243     
       
   244     /**
       
   245       * Handles the pointer event received by edwin.
       
   246       *
       
   247       * @param aPointerEvent Pointer event to handle.
       
   248       */
       
   249      void HandlePointerEvent( const TPointerEvent& aPointerEvent );
       
   250 
       
   251 
       
   252 private: // data
       
   253 
       
   254     /**
       
   255      * Physics handler flags
       
   256      */
       
   257     enum TAknEdwinPhysicsHandlerFlags
       
   258         {
       
   259         EFlagUpdatingView, // View updating ongoing
       
   260         EFlagBouncingUp,   // Content bouncing up, empty space below content   
       
   261         EFlagBouncingDown,  // Content bouncing down, empty space above content
       
   262         EFlagDraggingAllowed // Dragging allowed
       
   263         };
       
   264     
       
   265     /**
       
   266      * Scroll index.
       
   267      */
       
   268     TInt iWorldIndex;
       
   269     
       
   270     /**
       
   271      * Previous scroll index.
       
   272      */
       
   273     TInt iPreviousWorldIndex;
       
   274 
       
   275     /**
       
   276      * Previous pointer position.
       
   277      */   
       
   278     TPoint iPrevPosition;
       
   279     
       
   280     /**
       
   281      * View rect.
       
   282      */
       
   283     TRect iViewRect;
       
   284     
       
   285     /**
       
   286      * ETrue if pointer events are blocked.
       
   287      */
       
   288     TBool iEventsBlocked;
       
   289 
       
   290     /**
       
   291      * If set to ETrue, first pointer down event unblocks pointer events.
       
   292      */
       
   293     TBool iEventUnblockingAllowed;
       
   294     
       
   295     /**
       
   296      * ETrue if drag threshold exceeded.
       
   297      */
       
   298     TBool iDragThresholdExceeded;
       
   299     
       
   300     /**
       
   301      * Pointer down start time.
       
   302      */
       
   303     TTime iStartTime;
       
   304     
       
   305     /**
       
   306      * Physics. 
       
   307      * Own.
       
   308      */
       
   309     CAknPhysics *iPhysics;
       
   310 
       
   311     /**
       
   312      * Physics handler flags.
       
   313      */
       
   314     TBitFlags iFlags;
       
   315     
       
   316     /**
       
   317      * Pointer to edwin.
       
   318      * Not own.
       
   319      */
       
   320     CEikEdwin& iEdwin;
       
   321     
       
   322     /**
       
   323      * Position where bouncing down started.
       
   324      */
       
   325     TInt iBounceDownIndex;
       
   326     
       
   327     /**
       
   328      * Position where bouncing up started.
       
   329      */
       
   330     TInt iBounceUpIndex;
       
   331     
       
   332     /**
       
   333      * Previous Y-coordinate.
       
   334      */
       
   335     TInt iPreviousYCoordinate;
       
   336     
       
   337     /**
       
   338      * ETrue, if text selection has been started.
       
   339      */
       
   340     TBool iSelectionStarted;
       
   341             
       
   342     /**
       
   343      * ETrue, if dragging of content has been started.
       
   344      */
       
   345     TBool iDraggingStarted;
       
   346     
       
   347     /**
       
   348      * Start position of drag.
       
   349      */
       
   350     TPoint iStartPosition;
       
   351     };
       
   352 
       
   353 #endif // C_AKNEDWINPHYSICSHANDLER_H