uifw/EikStd/coctlsrc/aknedwinphysicshandler.cpp
changeset 0 2f259fa3e83a
child 4 8ca85d2f0db7
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 #include <aknphysics.h>
       
    19 #include <aknphysicsobserveriface.h>
       
    20 #include <babitflags.h>
       
    21 
       
    22 #include "eikedwin.h"
       
    23 #include "aknedwinphysicshandler.h"
       
    24 
       
    25 
       
    26 const TInt KMaxWorldSize( 100000000 );  // Maximum world size
       
    27 
       
    28 // ======== MEMBER FUNCTIONS ========
       
    29 
       
    30 // ---------------------------------------------------------------------------
       
    31 // CAknEdwinPhysicsHandler::NewL
       
    32 // ---------------------------------------------------------------------------
       
    33 //
       
    34 CAknEdwinPhysicsHandler* CAknEdwinPhysicsHandler::NewL( CEikEdwin& aEdwin )
       
    35     {
       
    36     CAknEdwinPhysicsHandler* self = CAknEdwinPhysicsHandler::NewLC( aEdwin );
       
    37     CleanupStack::Pop( self );
       
    38     return self;
       
    39     }
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // CAknEdwinPhysicsHandler::NewLC
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 CAknEdwinPhysicsHandler* CAknEdwinPhysicsHandler::NewLC( CEikEdwin& aEdwin )
       
    46     {
       
    47     CAknEdwinPhysicsHandler* self = new ( ELeave ) CAknEdwinPhysicsHandler(
       
    48             aEdwin );
       
    49     CleanupStack::PushL( self );
       
    50     self->ConstructL();
       
    51     return self;
       
    52     }
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // CAknEdwinPhysicsHandler::~CAknEdwinPhysicsHandler
       
    56 // ---------------------------------------------------------------------------
       
    57 //
       
    58 CAknEdwinPhysicsHandler::~CAknEdwinPhysicsHandler()
       
    59     {
       
    60     delete iPhysics;
       
    61     }
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // CAknEdwinPhysicsHandler::HandlePointerEvent
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 void CAknEdwinPhysicsHandler::HandlePointerEvent(
       
    68     const TPointerEvent& aPointerEvent )
       
    69     {   
       
    70     if ( aPointerEvent.iType == TPointerEvent::EButton1Down &&
       
    71         iViewRect.Contains( aPointerEvent.iPosition ) &&
       
    72         iEventUnblockingAllowed )
       
    73         {
       
    74         BlockEvents( EFalse );
       
    75         iPreviousYCoordinate = - KMaxWorldSize;
       
    76         }
       
    77     if ( iEventsBlocked )
       
    78         {
       
    79 	    return;
       
    80         }
       
    81 
       
    82     // Dragging/flicking logic    
       
    83     
       
    84     if ( aPointerEvent.iType == TPointerEvent::EButton1Down &&
       
    85         iViewRect.Contains( aPointerEvent.iPosition ) )
       
    86         {
       
    87         // Pointer down inside view rect, set flag to allow dragging 
       
    88         // and initialize values
       
    89         iFlags.Set( EFlagDraggingAllowed );
       
    90         iPrevPosition = aPointerEvent.iPosition;
       
    91         iStartPosition = aPointerEvent.iPosition;
       
    92         StopPhysics();
       
    93 
       
    94         iStartTime.HomeTime();
       
    95         iDragThresholdExceeded = EFalse;
       
    96         iFlags.Clear( EFlagBouncingUp );
       
    97         iFlags.Clear( EFlagBouncingDown );
       
    98         return;
       
    99         }
       
   100     if ( iFlags.IsClear( EFlagDraggingAllowed ) )
       
   101         {
       
   102         return;
       
   103         }
       
   104 
       
   105     if ( aPointerEvent.iType == TPointerEvent::EDrag )
       
   106         {
       
   107         if ( !iDragThresholdExceeded )
       
   108             {
       
   109             TInt drag( iStartPosition.iY - aPointerEvent.iPosition.iY );
       
   110             if ( Abs( drag ) > DragThreshold() )
       
   111                 {
       
   112                 iDragThresholdExceeded = ETrue;
       
   113                 }
       
   114             }
       
   115 
       
   116         if ( iDragThresholdExceeded )
       
   117             {
       
   118             TInt deltaY( iPrevPosition.iY - aPointerEvent.iPosition.iY );
       
   119             iPrevPosition = aPointerEvent.iPosition;
       
   120 
       
   121             TPoint deltaPoint( 0, deltaY );
       
   122             iPhysics->RegisterPanningPosition( deltaPoint );
       
   123             }
       
   124         }
       
   125     else if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
       
   126         {
       
   127         iFlags.Clear( EFlagDraggingAllowed );
       
   128         TPoint drag( 0, iStartPosition.iY - aPointerEvent.iPosition.iY );
       
   129         iPhysics->StartPhysics( drag, iStartTime );
       
   130         }
       
   131     }
       
   132 
       
   133 // ---------------------------------------------------------------------------
       
   134 // CAknEdwinPhysicsHandler::SetViewRect
       
   135 // ---------------------------------------------------------------------------
       
   136 //
       
   137 void CAknEdwinPhysicsHandler::SetViewRect( const TRect& aRect )
       
   138     {
       
   139     iViewRect = aRect;
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 // CAknEdwinPhysicsHandler::InitPhysicsL
       
   144 // ---------------------------------------------------------------------------
       
   145 //   
       
   146 void CAknEdwinPhysicsHandler::InitPhysicsL()
       
   147     {
       
   148     TSize totalSize( iViewRect.Width(), iViewRect.Height() + KMaxWorldSize );
       
   149     TSize viewSize( iViewRect.Width(), iViewRect.Height() );
       
   150 
       
   151     iPhysics->InitPhysicsL( totalSize, viewSize, EFalse );
       
   152     }
       
   153 
       
   154 // ---------------------------------------------------------------------------
       
   155 // CAknEdwinPhysicsHandler::MoveScrollIndex
       
   156 // ---------------------------------------------------------------------------
       
   157 //     
       
   158 void CAknEdwinPhysicsHandler::MoveScrollIndex( TInt aPixelsToMove )
       
   159     {
       
   160     // This is called when user moves content using scrollbar
       
   161     
       
   162     // Do nothing if handler itself is updating the view
       
   163     if ( iFlags.IsSet( EFlagUpdatingView ) )
       
   164         {
       
   165         return;
       
   166         }
       
   167 
       
   168     iWorldIndex += aPixelsToMove;
       
   169     ScrollView( EFalse );
       
   170     }
       
   171 
       
   172 // ---------------------------------------------------------------------------
       
   173 // CAknEdwinPhysicsHandler::EmulationOngoing
       
   174 // ---------------------------------------------------------------------------
       
   175 //     
       
   176 TBool CAknEdwinPhysicsHandler::EmulationOngoing()
       
   177     {
       
   178     return IsFlicking() || IsBouncing();
       
   179     }
       
   180 
       
   181 // ---------------------------------------------------------------------------
       
   182 // CAknEdwinPhysicsHandler::DragThreshold
       
   183 // ---------------------------------------------------------------------------
       
   184 //     
       
   185 TInt CAknEdwinPhysicsHandler::DragThreshold() const
       
   186     {
       
   187     return iPhysics->DragThreshold();
       
   188     }
       
   189 
       
   190 // ---------------------------------------------------------------------------
       
   191 // CAknEdwinPhysicsHandler::ViewPositionChanged
       
   192 // ---------------------------------------------------------------------------
       
   193 //
       
   194 void CAknEdwinPhysicsHandler::ViewPositionChanged( const TPoint& aNewPosition,
       
   195         TBool /*aDrawNow*/, TUint /*aFlags*/)
       
   196     {        
       
   197     // Skip equal sequential values.
       
   198     if ( aNewPosition.iY == iPreviousYCoordinate )
       
   199         {
       
   200         return;
       
   201         }
       
   202     iPreviousYCoordinate = aNewPosition.iY;
       
   203     
       
   204     TInt y( 0 );
       
   205     if ( iFlags.IsSet( EFlagBouncingDown ) )
       
   206         {
       
   207         // We are at the beginning of world
       
   208         y = aNewPosition.iY + iBounceDownIndex;
       
   209         }
       
   210     else if ( iFlags.IsSet( EFlagBouncingUp ) )
       
   211         {
       
   212         // We are at the end of world
       
   213         y = aNewPosition.iY + iBounceUpIndex - KMaxWorldSize;
       
   214         }
       
   215     else
       
   216         {
       
   217         // We are at the middle of world
       
   218         y = aNewPosition.iY - KMaxWorldSize / 2;
       
   219         }
       
   220 
       
   221     iWorldIndex = y - iViewRect.Height() / 2;
       
   222 
       
   223     // If bounce is ongoing, block all pointer events.
       
   224     if ( IsBouncing() )
       
   225         {
       
   226         BlockEvents( ETrue );
       
   227         }
       
   228     // Scroll view based on values from aknphysics
       
   229     ScrollView( ETrue );
       
   230     }
       
   231 
       
   232 // ---------------------------------------------------------------------------
       
   233 // CAknEdwinPhysicsHandler::PhysicEmulationEnded
       
   234 // ---------------------------------------------------------------------------
       
   235 //    
       
   236 void CAknEdwinPhysicsHandler::PhysicEmulationEnded()
       
   237     {
       
   238     TInt offset = iEdwin.PixelsOutOfBorder();
       
   239     if ( offset != 0 )
       
   240         {
       
   241         // If physics emulation ends and view position is not moved
       
   242         // back to original position (to position where bounce started)
       
   243         // we adjust it here. This is because aknphysics won't return
       
   244         // always to original position.
       
   245      
       
   246         TPoint newPosition( 0, iPreviousYCoordinate + offset );
       
   247         ViewPositionChanged( newPosition, ETrue, 0 );
       
   248         }
       
   249     
       
   250     // Enable pointer events when next pointer down received
       
   251     iEventUnblockingAllowed = ETrue;
       
   252     
       
   253     // Show cursor again if needed   
       
   254     iEdwin.RestoreCursorState();
       
   255     }
       
   256 
       
   257 // ---------------------------------------------------------------------------
       
   258 // CAknEdwinPhysicsHandler::ViewPosition
       
   259 // ---------------------------------------------------------------------------
       
   260 //    
       
   261 TPoint CAknEdwinPhysicsHandler::ViewPosition() const
       
   262     {
       
   263     // Aknphysics calls this function to get current view position.
       
   264     // We adjust the position based on information if we
       
   265     // are are bouncing up or down (in other words we
       
   266     // have exceeded end- or beginning of real editor content).
       
   267     // In these situations we adjust returned value so that
       
   268     // from aknphysic's point of view we seem to be at the beginning
       
   269     // or end of almost infinite large world. If we have not exceeded
       
   270     // borders of editor content, we are at the middle of this world.
       
   271     // So, when we are at the middle of this almost infinite large world,
       
   272     // we can in practice add and remove content to editor
       
   273     // and we must not tell correct position to aknphysics (we also can't because
       
   274     // it seems to be impossible to calculate excatly correct position and size
       
   275     // of world if we haven't formatted yet the whole editor content).  
       
   276 
       
   277     TInt y( 0 );
       
   278 
       
   279     if ( iFlags.IsClear( EFlagBouncingDown )
       
   280             && iFlags.IsClear( EFlagBouncingUp ) )
       
   281         {
       
   282         // We are at the middle of world
       
   283         y = iWorldIndex + KMaxWorldSize / 2;
       
   284         }
       
   285     else if ( iFlags.IsSet( EFlagBouncingDown ) )
       
   286         {
       
   287         // We are at the beginning of world
       
   288         y = iWorldIndex - iBounceDownIndex;
       
   289         }
       
   290     else if ( iFlags.IsSet( EFlagBouncingUp ) )
       
   291         {
       
   292         // We are at the end of world
       
   293         y = iWorldIndex - iBounceUpIndex +  KMaxWorldSize;
       
   294         }
       
   295 
       
   296     return TPoint( iViewRect.Width() / 2, y + iViewRect.Height() / 2 );
       
   297     }
       
   298 
       
   299 // ---------------------------------------------------------------------------
       
   300 // CAknEdwinPhysicsHandler::CAknEdwinPhysicsHandler
       
   301 // ---------------------------------------------------------------------------
       
   302 //
       
   303 CAknEdwinPhysicsHandler::CAknEdwinPhysicsHandler( CEikEdwin& aEdwin ) :
       
   304     iWorldIndex( 0 ),
       
   305     iPreviousWorldIndex( 0 ),
       
   306     iPhysics( NULL ),
       
   307     iEdwin( aEdwin )
       
   308     {
       
   309     }
       
   310 
       
   311 // ---------------------------------------------------------------------------
       
   312 // CAknEdwinPhysicsHandler::ConstructL
       
   313 // ---------------------------------------------------------------------------
       
   314 //
       
   315 void CAknEdwinPhysicsHandler::ConstructL()
       
   316     {
       
   317     iPhysics = CAknPhysics::NewL( *this, &iEdwin );    
       
   318     }
       
   319 
       
   320 // ---------------------------------------------------------------------------
       
   321 // CAknEdwinPhysicsHandler::ScrollView
       
   322 // ---------------------------------------------------------------------------
       
   323 //     
       
   324 void CAknEdwinPhysicsHandler::ScrollView( TBool aAllowBounce )
       
   325     {
       
   326     iFlags.Set( EFlagUpdatingView );
       
   327     if ( iPreviousWorldIndex != iWorldIndex )
       
   328         {
       
   329         // Calculate amount of pixels to scroll based on previous position
       
   330         TInt pixelsToScroll( iPreviousWorldIndex - iWorldIndex );
       
   331         if ( pixelsToScroll != 0 )
       
   332             {
       
   333             if ( iFlags.IsSet( EFlagBouncingDown ) ||
       
   334                     iFlags.IsSet( EFlagBouncingUp ) )
       
   335                 {
       
   336                 // Bounce ongoing, use function that supports scrolling
       
   337                 // over the content borders (there can be empty space above or
       
   338                 // below the editor content)
       
   339                 TInt restOfPixels( 0 );
       
   340                 ScrollStepWithBounce( pixelsToScroll, restOfPixels );
       
   341                 
       
   342                 // If restOfPixels is not zero, we were bouncing back
       
   343                 // and exceeded the border again. In this situation
       
   344                 // we must scroll rest of pixels using function
       
   345                 // that stops if we again exceed the border. This is needed
       
   346                 // because we need to know if we exceed the border again
       
   347                 // (for example if length of content is short) to adjust
       
   348                 // position on aknphysics world correctly.
       
   349 
       
   350                 if ( restOfPixels != 0)
       
   351                     {
       
   352                     ScrollStep( pixelsToScroll, ETrue );
       
   353                     }
       
   354                 }
       
   355             else
       
   356                 {
       
   357                 // Bounce not ongoing, use function that stops if we exceed the border
       
   358                 ScrollStep( pixelsToScroll, aAllowBounce );
       
   359                 }
       
   360             }
       
   361         }
       
   362     iFlags.Clear( EFlagUpdatingView );
       
   363     }
       
   364 
       
   365 // ---------------------------------------------------------------------------
       
   366 // CAknEdwinPhysicsHandler::ScrollStep
       
   367 // ---------------------------------------------------------------------------
       
   368 //   
       
   369 void CAknEdwinPhysicsHandler::ScrollStep( TInt aPixelsToScroll,
       
   370     TBool aAllowBounce )
       
   371     {
       
   372     TInt restOfPixels( 0 );
       
   373     TBool borderExceeded( EFalse );
       
   374 
       
   375     TInt scrolledPixels = iEdwin.ScrollView( aPixelsToScroll, borderExceeded,
       
   376         restOfPixels );
       
   377            
       
   378     if ( borderExceeded && aAllowBounce )
       
   379         {
       
   380         if ( aPixelsToScroll != 0 )
       
   381             {
       
   382             MoveWorldIndex( scrolledPixels );
       
   383             
       
   384             if ( IsFlicking() )
       
   385                 {
       
   386                 // Flicking is ongoing and end of content is arrived.
       
   387                 // In this situation we stop physics, adjust the view position in the
       
   388                 // aknphysics (in function ViewPosition) and restart physics with
       
   389                 // current force and velocity.
       
   390                 
       
   391                 iPhysics->SuspendPhysics();
       
   392                 InitBounce( aPixelsToScroll > 0 );
       
   393                 iPhysics->ResumePhysics();
       
   394                 }
       
   395             else
       
   396                 {
       
   397                 InitBounce( aPixelsToScroll > 0 );
       
   398                 ScrollRestOfPixels( restOfPixels );
       
   399                 }
       
   400             }
       
   401         return;
       
   402         }
       
   403 
       
   404     MoveWorldIndex( scrolledPixels );
       
   405     }
       
   406 
       
   407 // ---------------------------------------------------------------------------
       
   408 // CAknEdwinPhysicsHandler::ScrollStepWithBounce
       
   409 // ---------------------------------------------------------------------------
       
   410 // 
       
   411 void CAknEdwinPhysicsHandler::ScrollStepWithBounce( TInt aPixelsToScroll,
       
   412     TInt& aRestOfPixels )
       
   413     {
       
   414     TBool endOfBounce( EFalse );
       
   415     TInt scrolledPixels = iEdwin.ScrollViewWithBounce(
       
   416         aPixelsToScroll, endOfBounce, aRestOfPixels );
       
   417 
       
   418     MoveWorldIndex( scrolledPixels );
       
   419 
       
   420     if ( endOfBounce )
       
   421         {
       
   422         iFlags.Clear( EFlagBouncingDown );  
       
   423         iFlags.Clear( EFlagBouncingUp );
       
   424         }
       
   425     }
       
   426 
       
   427 // ---------------------------------------------------------------------------
       
   428 // CAknEdwinPhysicsHandler::MoveWorldIndex
       
   429 // ---------------------------------------------------------------------------
       
   430 //
       
   431 void CAknEdwinPhysicsHandler::MoveWorldIndex( TInt aDelta )
       
   432     {
       
   433     iWorldIndex = iPreviousWorldIndex - aDelta;
       
   434     iPreviousWorldIndex = iWorldIndex;
       
   435     }
       
   436 
       
   437 // ---------------------------------------------------------------------------
       
   438 // CAknEdwinPhysicsHandler::ScrollRestOfPixels
       
   439 // ---------------------------------------------------------------------------
       
   440 //
       
   441 void CAknEdwinPhysicsHandler::ScrollRestOfPixels( TInt aRestOfPixels )
       
   442     {
       
   443     // Scroll rest of pixels
       
   444     TBool endOfBounce;
       
   445     TInt restOfPixels( 0 );
       
   446     
       
   447     TInt scrolledPixels = iEdwin.ScrollViewWithBounce( aRestOfPixels,
       
   448             endOfBounce, restOfPixels );
       
   449     
       
   450     MoveWorldIndex( scrolledPixels );
       
   451     }
       
   452 
       
   453 // ---------------------------------------------------------------------------
       
   454 // CAknEdwinPhysicsHandler::StopPhysics
       
   455 // ---------------------------------------------------------------------------
       
   456 //
       
   457 void CAknEdwinPhysicsHandler::StopPhysics()
       
   458     {
       
   459     iPhysics->StopPhysics();
       
   460     iPhysics->ResetFriction();
       
   461     }
       
   462 
       
   463 // ---------------------------------------------------------------------------
       
   464 // CAknEdwinPhysicsHandler::BlockEvents
       
   465 // ---------------------------------------------------------------------------
       
   466 //
       
   467 void CAknEdwinPhysicsHandler::BlockEvents( TBool aBlocked )
       
   468     {
       
   469     iEventsBlocked = aBlocked;
       
   470     iEventUnblockingAllowed = EFalse;
       
   471     }
       
   472 
       
   473 // ---------------------------------------------------------------------------
       
   474 // CAknEdwinPhysicsHandler::IsFlicking
       
   475 // ---------------------------------------------------------------------------
       
   476 //
       
   477 TBool CAknEdwinPhysicsHandler::IsFlicking() const
       
   478     {
       
   479     return iPhysics->OngoingPhysicsAction()
       
   480             == CAknPhysics::EAknPhysicsActionFlicking;
       
   481     }
       
   482 
       
   483 // ---------------------------------------------------------------------------
       
   484 // CAknEdwinPhysicsHandler::IsBouncing
       
   485 // ---------------------------------------------------------------------------
       
   486 //
       
   487 TBool CAknEdwinPhysicsHandler::IsBouncing() const
       
   488     {
       
   489     return iPhysics->OngoingPhysicsAction()
       
   490             == CAknPhysics::EAknPhysicsActionBouncing;
       
   491     }
       
   492 
       
   493 // ---------------------------------------------------------------------------
       
   494 // CAknEdwinPhysicsHandler::InitBounce
       
   495 // ---------------------------------------------------------------------------
       
   496 //
       
   497 void CAknEdwinPhysicsHandler::InitBounce( TBool aBouncingDown )
       
   498     {
       
   499     if ( aBouncingDown )
       
   500         {
       
   501         iFlags.Clear( EFlagBouncingUp );
       
   502         iFlags.Set( EFlagBouncingDown );
       
   503         iBounceDownIndex = iWorldIndex;
       
   504         }
       
   505     else
       
   506         {
       
   507         iFlags.Set( EFlagBouncingUp );
       
   508         iFlags.Clear( EFlagBouncingDown );
       
   509         iBounceUpIndex = iWorldIndex;
       
   510         }   
       
   511     }
       
   512 
       
   513 // ---------------------------------------------------------------------------
       
   514 // CAknEdwinPhysicsHandler::InitKineticScrolling
       
   515 // ---------------------------------------------------------------------------
       
   516 //
       
   517 void CAknEdwinPhysicsHandler::InitKineticScrolling(
       
   518     const TPoint& aStartPosition )
       
   519     {
       
   520     iSelectionStarted = EFalse;
       
   521     iDraggingStarted = EFalse;
       
   522     iStartPosition = aStartPosition;
       
   523     }
       
   524 
       
   525 // ---------------------------------------------------------------------------
       
   526 // CAknEdwinPhysicsHandler::HandleKineticScrolling
       
   527 // ---------------------------------------------------------------------------
       
   528 //
       
   529 void CAknEdwinPhysicsHandler::HandleKineticScrolling(
       
   530     const TPointerEvent& aPointerEvent, TBool& aShouldReturn )
       
   531     {
       
   532     aShouldReturn = EFalse;
       
   533     
       
   534     // If editor content is empty, it is not possible to drag,
       
   535     // flick or select text and we return here. Other events
       
   536     // are passed because they are handled later.
       
   537     if ( aPointerEvent.iType == TPointerEvent::EDrag
       
   538         && iEdwin.TextLength() == 0 )
       
   539         {
       
   540         aShouldReturn = ETrue;
       
   541         return;
       
   542         }
       
   543     
       
   544     // If dragging or selection not started,
       
   545     // check if it should be started
       
   546     if ( aPointerEvent.iType == TPointerEvent::EDrag && !iSelectionStarted
       
   547         && !iDraggingStarted )
       
   548         {
       
   549         // Get delta values for pointer movement
       
   550         TInt deltaX( aPointerEvent.iPosition.iX - iStartPosition.iX );
       
   551         TInt deltaY( aPointerEvent.iPosition.iY - iStartPosition.iY );
       
   552             
       
   553         // If drag threshold not exceeded, return.
       
   554         if ( Abs( deltaX ) < DragThreshold()
       
   555             && Abs( deltaY ) < DragThreshold() )
       
   556             {
       
   557             HandlePointerEvent( aPointerEvent );
       
   558             aShouldReturn = ETrue;
       
   559             return;
       
   560             }
       
   561                   
       
   562         // If dragged horizontally more than vertically,
       
   563         // text selection started. Otherwise dragging started.
       
   564         if ( Abs( deltaX ) > Abs( deltaY ) )
       
   565             {
       
   566             iSelectionStarted = ETrue;
       
   567             }
       
   568         else
       
   569             {
       
   570             iDraggingStarted = ETrue;
       
   571                 
       
   572             // If cursor is visible, disable it and store
       
   573             // cursor visibility info when dragging starts.
       
   574             iEdwin.StoreCursorState();
       
   575             }
       
   576         }
       
   577 
       
   578     // Forward all events to physics handler, except:
       
   579     // If text selection started, don't forward drag and up events
       
   580     // because kinetic scrolling can't be used when selecting text.
       
   581     // However, fast scrolling can be used when we are selecting text.
       
   582 
       
   583     if ( !( iSelectionStarted &&
       
   584             ( aPointerEvent.iType == TPointerEvent::EDrag ||
       
   585                 aPointerEvent.iType == TPointerEvent::EButton1Up ) ) )
       
   586         {
       
   587         HandlePointerEvent( aPointerEvent );
       
   588         }
       
   589     
       
   590     if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
       
   591         {
       
   592         // If flick or bounce effect was started, check if there
       
   593         // is need to hide cursor.
       
   594         // If flick or bounce was not started, show cursor again if needed.
       
   595         if ( EmulationOngoing() )
       
   596             {
       
   597             iEdwin.StoreCursorState();
       
   598             }
       
   599         else
       
   600             {
       
   601             iEdwin.RestoreCursorState();
       
   602             }
       
   603         }
       
   604 
       
   605     // If selection not started, don't handle drag events but return
       
   606     // All other events must be handled anyway.
       
   607     if ( !iSelectionStarted && aPointerEvent.iType
       
   608             == TPointerEvent::EDrag )
       
   609         {
       
   610         aShouldReturn = ETrue;                     
       
   611         return;
       
   612         }
       
   613     }
       
   614 
       
   615 // ---------------------------------------------------------------------------
       
   616 // CAknEdwinPhysicsHandler::SelectionStarted
       
   617 // ---------------------------------------------------------------------------
       
   618 //
       
   619 TBool CAknEdwinPhysicsHandler::SelectionStarted() const
       
   620     {
       
   621     return iSelectionStarted;
       
   622     }
       
   623 
       
   624 // ---------------------------------------------------------------------------
       
   625 // CAknEdwinPhysicsHandler::DraggingStarted
       
   626 // ---------------------------------------------------------------------------
       
   627 //
       
   628 TBool CAknEdwinPhysicsHandler::DraggingStarted() const
       
   629     {
       
   630     return iDraggingStarted;
       
   631     }
       
   632 
       
   633 // ---------------------------------------------------------------------------
       
   634 // CAknEdwinPhysicsHandler::DragThresholdExceeded
       
   635 // ---------------------------------------------------------------------------
       
   636 //
       
   637 TBool CAknEdwinPhysicsHandler::DragThresholdExceeded(
       
   638     const TPoint& aCurrentPosition ) const
       
   639     {
       
   640     // Get delta values for pointer movement
       
   641     TInt deltaX( aCurrentPosition.iX - iStartPosition.iX );
       
   642     TInt deltaY( aCurrentPosition.iY - iStartPosition.iY );
       
   643 
       
   644     if ( Abs( deltaX ) >= DragThreshold() || Abs( deltaY ) >= DragThreshold() )
       
   645         {
       
   646         return ETrue;
       
   647         }
       
   648     return EFalse;
       
   649     }