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