uifw/EikStd/coctlsrc/aknedwinphysicshandler.cpp
branchRCL_3
changeset 20 d48ab3b357f1
parent 19 aecbbf00d063
child 21 978afdc0236f
equal deleted inserted replaced
19:aecbbf00d063 20:d48ab3b357f1
    50     self->ConstructL();
    50     self->ConstructL();
    51     return self;
    51     return self;
    52     }
    52     }
    53 
    53 
    54 // ---------------------------------------------------------------------------
    54 // ---------------------------------------------------------------------------
       
    55 // CAknEdwinPhysicsHandler::NewL
       
    56 // ---------------------------------------------------------------------------
       
    57 //
       
    58 CAknEdwinPhysicsHandler* CAknEdwinPhysicsHandler::NewL( CEikEdwin& aEdwin, CAknPhysics* aPhysics )
       
    59     {
       
    60     CAknEdwinPhysicsHandler* self = CAknEdwinPhysicsHandler::NewLC( aEdwin, aPhysics );
       
    61     CleanupStack::Pop( self );
       
    62     return self;
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // CAknEdwinPhysicsHandler::NewLC
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 CAknEdwinPhysicsHandler* CAknEdwinPhysicsHandler::NewLC( CEikEdwin& aEdwin, CAknPhysics* aPhysics )
       
    70     {
       
    71     CAknEdwinPhysicsHandler* self = new ( ELeave ) CAknEdwinPhysicsHandler(
       
    72             aEdwin, aPhysics );
       
    73     CleanupStack::PushL( self );
       
    74     self->ConstructL();
       
    75     return self;
       
    76     }
       
    77 
       
    78 // ---------------------------------------------------------------------------
    55 // CAknEdwinPhysicsHandler::~CAknEdwinPhysicsHandler
    79 // CAknEdwinPhysicsHandler::~CAknEdwinPhysicsHandler
    56 // ---------------------------------------------------------------------------
    80 // ---------------------------------------------------------------------------
    57 //
    81 //
    58 CAknEdwinPhysicsHandler::~CAknEdwinPhysicsHandler()
    82 CAknEdwinPhysicsHandler::~CAknEdwinPhysicsHandler()
    59     {
    83     {
    60     delete iPhysics;
    84     if (iOwnsPhysics)
       
    85         {
       
    86         delete iPhysics;
       
    87         }
    61     }
    88     }
    62 
    89 
    63 // ---------------------------------------------------------------------------
    90 // ---------------------------------------------------------------------------
    64 // CAknEdwinPhysicsHandler::HandlePointerEvent
    91 // CAknEdwinPhysicsHandler::HandlePointerEvent
    65 // ---------------------------------------------------------------------------
    92 // ---------------------------------------------------------------------------
    66 //
    93 //
    67 void CAknEdwinPhysicsHandler::HandlePointerEvent(
    94 void CAknEdwinPhysicsHandler::HandlePointerEvent(
    68     const TPointerEvent& aPointerEvent )
    95     const TPointerEvent& aPointerEvent )
    69     {   
    96     {   
    70     if ( aPointerEvent.iType == TPointerEvent::EButton1Down &&
    97     if (iOwnsPhysics)
    71         iViewRect.Contains( aPointerEvent.iPosition ) &&
    98         {
    72         iEventUnblockingAllowed )
    99         if ( aPointerEvent.iType == TPointerEvent::EButton1Down &&
    73         {
   100             iViewRect.Contains( aPointerEvent.iPosition ) &&
    74         BlockEvents( EFalse );
   101             iEventUnblockingAllowed )
    75         iPreviousYCoordinate = - KMaxWorldSize;
   102             {
    76         }
   103             BlockEvents( EFalse );
    77     if ( iEventsBlocked )
   104             iPreviousYCoordinate = - KMaxWorldSize;
    78         {
   105             }
    79 	    return;
   106         if ( iEventsBlocked )
    80         }
   107             {
    81 
   108             return;
    82     // Dragging/flicking logic    
   109             }
    83     
   110     
    84     if ( aPointerEvent.iType == TPointerEvent::EButton1Down &&
   111         // Dragging/flicking logic    
    85         iViewRect.Contains( aPointerEvent.iPosition ) )
   112         
    86         {
   113         if ( aPointerEvent.iType == TPointerEvent::EButton1Down &&
    87         // Pointer down inside view rect, set flag to allow dragging 
   114             iViewRect.Contains( aPointerEvent.iPosition ) )
    88         // and initialize values
   115             {
    89         iFlags.Set( EFlagDraggingAllowed );
   116             // Pointer down inside view rect, set flag to allow dragging 
    90         iPrevPosition = aPointerEvent.iPosition;
   117             // and initialize values
    91         iStartPosition = aPointerEvent.iPosition;
   118             iFlags.Set( EFlagDraggingAllowed );
    92         StopPhysics();
   119             iStartPosition = aPointerEvent.iPosition;
    93 
   120             StopPhysics();
    94         iStartTime.HomeTime();
   121     
    95         iDragThresholdExceeded = EFalse;
   122             iStartTime.HomeTime();
    96         iFlags.Clear( EFlagBouncingUp );
   123             iDragThresholdExceeded = EFalse;
    97         iFlags.Clear( EFlagBouncingDown );
   124             iFlags.Clear( EFlagBouncingUp );
    98         return;
   125             iFlags.Clear( EFlagBouncingDown );
    99         }
   126             return;
   100     if ( iFlags.IsClear( EFlagDraggingAllowed ) )
   127             }
   101         {
   128         if ( iFlags.IsClear( EFlagDraggingAllowed ) )
   102         return;
   129             {
   103         }
   130             return;
   104 
   131             }
   105     if ( aPointerEvent.iType == TPointerEvent::EDrag )
   132     
   106         {
   133         if ( aPointerEvent.iType == TPointerEvent::EDrag )
   107         if ( !iDragThresholdExceeded )
   134             {
   108             {
   135             if ( !iDragThresholdExceeded )
   109             TInt drag( iStartPosition.iY - aPointerEvent.iPosition.iY );
   136                 {
   110             if ( Abs( drag ) > DragThreshold() )
   137                 TInt drag( iStartPosition.iY - aPointerEvent.iPosition.iY );
   111                 {
   138                 if ( Abs( drag ) > DragThreshold() )
   112                 iDragThresholdExceeded = ETrue;
   139                     {
   113                 }
   140                     iDragThresholdExceeded = ETrue;
   114             }
   141                     }
   115 
   142                 }
   116         if ( iDragThresholdExceeded )
   143             else
   117             {
   144                 {
   118             TInt deltaY( iPrevPosition.iY - aPointerEvent.iPosition.iY );
   145                 if ( !iEdwin.ContentFitsToViewRect() )
       
   146                     {
       
   147                     TInt deltaY( iPrevPosition.iY - aPointerEvent.iPosition.iY );
       
   148                     TPoint deltaPoint( 0, deltaY );
       
   149                     iPhysics->RegisterPanningPosition( deltaPoint );
       
   150                     }
       
   151                 }
   119             iPrevPosition = aPointerEvent.iPosition;
   152             iPrevPosition = aPointerEvent.iPosition;
   120 
   153             }
   121             TPoint deltaPoint( 0, deltaY );
   154         else if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
   122             iPhysics->RegisterPanningPosition( deltaPoint );
   155             {
   123             }
   156             if ( iFlags.IsClear( EFlagDraggingAllowed ) )
   124         }
   157                 {
   125     else if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
   158                 return;
   126         {
   159                 }
   127         iFlags.Clear( EFlagDraggingAllowed );
   160             
   128         TPoint drag( 0, iStartPosition.iY - aPointerEvent.iPosition.iY );
   161             iFlags.Clear( EFlagDraggingAllowed );
   129         iPhysics->StartPhysics( drag, iStartTime );
   162 
       
   163             if ( !iEdwin.ContentFitsToViewRect() )
       
   164                 {
       
   165                 TPoint drag( 0, iStartPosition.iY - aPointerEvent.iPosition.iY );
       
   166                 iPhysics->StartPhysics( drag, iStartTime );
       
   167                 }
       
   168             }
   130         }
   169         }
   131     }
   170     }
   132 
   171 
   133 // ---------------------------------------------------------------------------
   172 // ---------------------------------------------------------------------------
   134 // CAknEdwinPhysicsHandler::SetViewRect
   173 // CAknEdwinPhysicsHandler::SetViewRect
   143 // CAknEdwinPhysicsHandler::InitPhysicsL
   182 // CAknEdwinPhysicsHandler::InitPhysicsL
   144 // ---------------------------------------------------------------------------
   183 // ---------------------------------------------------------------------------
   145 //   
   184 //   
   146 void CAknEdwinPhysicsHandler::InitPhysicsL()
   185 void CAknEdwinPhysicsHandler::InitPhysicsL()
   147     {
   186     {
   148     TSize totalSize( iViewRect.Width(), iViewRect.Height() + KMaxWorldSize );
   187     if (iOwnsPhysics)
   149     TSize viewSize( iViewRect.Width(), iViewRect.Height() );
   188         {
   150 
   189         TSize totalSize( iViewRect.Width(), iViewRect.Height()
   151     iPhysics->InitPhysicsL( totalSize, viewSize, EFalse );
   190                 + KMaxWorldSize );
   152     }
   191         TSize viewSize( iViewRect.Width(), iViewRect.Height() );
       
   192         
       
   193         CTextLayout* layout = iEdwin.TextLayout();
       
   194         
       
   195         if ( layout )
       
   196             {
       
   197             TInt pixelsAbove = layout->PixelsAboveBand();
       
   198             if ( pixelsAbove > 0 )
       
   199                 {
       
   200                 MoveScrollIndex( -pixelsAbove );
       
   201                 }
       
   202             } 
       
   203         
       
   204         iPhysics->InitPhysicsL( totalSize, viewSize, EFalse );
       
   205         }
       
   206 	}
   153 
   207 
   154 // ---------------------------------------------------------------------------
   208 // ---------------------------------------------------------------------------
   155 // CAknEdwinPhysicsHandler::MoveScrollIndex
   209 // CAknEdwinPhysicsHandler::MoveScrollIndex
   156 // ---------------------------------------------------------------------------
   210 // ---------------------------------------------------------------------------
   157 //     
   211 //     
   162     // Do nothing if handler itself is updating the view
   216     // Do nothing if handler itself is updating the view
   163     if ( iFlags.IsSet( EFlagUpdatingView ) )
   217     if ( iFlags.IsSet( EFlagUpdatingView ) )
   164         {
   218         {
   165         return;
   219         return;
   166         }
   220         }
   167 
   221     if ( !IsBouncing() )
       
   222         {
       
   223         iFlags.Clear( EFlagBouncingDown ); 
       
   224         iFlags.Clear( EFlagBouncingUp ); 
       
   225         }
   168     iWorldIndex += aPixelsToMove;
   226     iWorldIndex += aPixelsToMove;
   169     ScrollView( EFalse );
   227     ScrollView( EFalse );
   170     }
   228     }
   171 
   229 
   172 // ---------------------------------------------------------------------------
   230 // ---------------------------------------------------------------------------
   223     // If bounce is ongoing, block all pointer events.
   281     // If bounce is ongoing, block all pointer events.
   224     if ( IsBouncing() )
   282     if ( IsBouncing() )
   225         {
   283         {
   226         BlockEvents( ETrue );
   284         BlockEvents( ETrue );
   227         }
   285         }
   228     // Scroll view based on values from aknphysics
   286     
   229     ScrollView( ETrue );
   287     // Check also world indexes here because those might still equal although
       
   288     // y coordinates differ due to crossing world boundaries.
       
   289     if ( iPreviousWorldIndex != iWorldIndex )
       
   290         {
       
   291         // Disable background drawing while panning or flicking. Instead,
       
   292         // background is drawn in one frame.
       
   293         iEdwin.DrawViewBackground( ETrue );
       
   294         ScrollView( ETrue );
       
   295         iEdwin.DrawViewBackground( EFalse );
       
   296         }
   230     }
   297     }
   231 
   298 
   232 // ---------------------------------------------------------------------------
   299 // ---------------------------------------------------------------------------
   233 // CAknEdwinPhysicsHandler::PhysicEmulationEnded
   300 // CAknEdwinPhysicsHandler::PhysicEmulationEnded
   234 // ---------------------------------------------------------------------------
   301 // ---------------------------------------------------------------------------
   298 
   365 
   299 // ---------------------------------------------------------------------------
   366 // ---------------------------------------------------------------------------
   300 // CAknEdwinPhysicsHandler::CAknEdwinPhysicsHandler
   367 // CAknEdwinPhysicsHandler::CAknEdwinPhysicsHandler
   301 // ---------------------------------------------------------------------------
   368 // ---------------------------------------------------------------------------
   302 //
   369 //
   303 CAknEdwinPhysicsHandler::CAknEdwinPhysicsHandler( CEikEdwin& aEdwin ) :
   370 CAknEdwinPhysicsHandler::CAknEdwinPhysicsHandler( CEikEdwin& aEdwin,
       
   371     CAknPhysics* aPhysics ) :
   304     iWorldIndex( 0 ),
   372     iWorldIndex( 0 ),
   305     iPreviousWorldIndex( 0 ),
   373     iPreviousWorldIndex( 0 ),
   306     iPhysics( NULL ),
   374     iPhysics( aPhysics ),
   307     iEdwin( aEdwin )
   375     iEdwin( aEdwin ),
       
   376     iOwnsPhysics( aPhysics == NULL )
   308     {
   377     {
   309     }
   378     }
   310 
   379 
   311 // ---------------------------------------------------------------------------
   380 // ---------------------------------------------------------------------------
   312 // CAknEdwinPhysicsHandler::ConstructL
   381 // CAknEdwinPhysicsHandler::ConstructL
   313 // ---------------------------------------------------------------------------
   382 // ---------------------------------------------------------------------------
   314 //
   383 //
   315 void CAknEdwinPhysicsHandler::ConstructL()
   384 void CAknEdwinPhysicsHandler::ConstructL()
   316     {
   385     {
   317     iPhysics = CAknPhysics::NewL( *this, &iEdwin );    
   386     if (iOwnsPhysics)
       
   387         {
       
   388         iPhysics = CAknPhysics::NewL( *this, &iEdwin );    
       
   389         }
   318     }
   390     }
   319 
   391 
   320 // ---------------------------------------------------------------------------
   392 // ---------------------------------------------------------------------------
   321 // CAknEdwinPhysicsHandler::ScrollView
   393 // CAknEdwinPhysicsHandler::ScrollView
   322 // ---------------------------------------------------------------------------
   394 // ---------------------------------------------------------------------------
   347                 // (for example if length of content is short) to adjust
   419                 // (for example if length of content is short) to adjust
   348                 // position on aknphysics world correctly.
   420                 // position on aknphysics world correctly.
   349 
   421 
   350                 if ( restOfPixels != 0)
   422                 if ( restOfPixels != 0)
   351                     {
   423                     {
   352                     ScrollStep( pixelsToScroll, ETrue );
   424                     ScrollStep( restOfPixels, ETrue );
   353                     }
   425                     }
   354                 }
   426                 }
   355             else
   427             else
   356                 {
   428                 {
   357                 // Bounce not ongoing, use function that stops if we exceed the border
   429                 // Bounce not ongoing, use function that stops if we exceed the border
   388                 // aknphysics (in function ViewPosition) and restart physics with
   460                 // aknphysics (in function ViewPosition) and restart physics with
   389                 // current force and velocity.
   461                 // current force and velocity.
   390                 
   462                 
   391                 iPhysics->SuspendPhysics();
   463                 iPhysics->SuspendPhysics();
   392                 InitBounce( aPixelsToScroll > 0 );
   464                 InitBounce( aPixelsToScroll > 0 );
       
   465                 ScrollRestOfPixels( restOfPixels );
   393                 iPhysics->ResumePhysics();
   466                 iPhysics->ResumePhysics();
   394                 }
   467                 }
   395             else
   468             else
   396                 {
   469                 {
   397                 InitBounce( aPixelsToScroll > 0 );
   470                 InitBounce( aPixelsToScroll > 0 );
   645         {
   718         {
   646         return ETrue;
   719         return ETrue;
   647         }
   720         }
   648     return EFalse;
   721     return EFalse;
   649     }
   722     }
       
   723 
       
   724 // ---------------------------------------------------------------------------
       
   725 // CAknEdwinPhysicsHandler::DisableDragging
       
   726 // ---------------------------------------------------------------------------
       
   727 //
       
   728 void CAknEdwinPhysicsHandler::DisableDragging()
       
   729     {
       
   730     iFlags.Clear( EFlagDraggingAllowed );
       
   731     }
       
   732