uifw/EikStd/coctlsrc/aknedwinphysicshandler.cpp
branchRCL_3
changeset 56 d48ab3b357f1
parent 55 aecbbf00d063
child 59 978afdc0236f
--- a/uifw/EikStd/coctlsrc/aknedwinphysicshandler.cpp	Tue Aug 31 15:28:30 2010 +0300
+++ b/uifw/EikStd/coctlsrc/aknedwinphysicshandler.cpp	Wed Sep 01 12:16:19 2010 +0100
@@ -52,12 +52,39 @@
     }
 
 // ---------------------------------------------------------------------------
+// CAknEdwinPhysicsHandler::NewL
+// ---------------------------------------------------------------------------
+//
+CAknEdwinPhysicsHandler* CAknEdwinPhysicsHandler::NewL( CEikEdwin& aEdwin, CAknPhysics* aPhysics )
+    {
+    CAknEdwinPhysicsHandler* self = CAknEdwinPhysicsHandler::NewLC( aEdwin, aPhysics );
+    CleanupStack::Pop( self );
+    return self;
+    }
+
+// ---------------------------------------------------------------------------
+// CAknEdwinPhysicsHandler::NewLC
+// ---------------------------------------------------------------------------
+//
+CAknEdwinPhysicsHandler* CAknEdwinPhysicsHandler::NewLC( CEikEdwin& aEdwin, CAknPhysics* aPhysics )
+    {
+    CAknEdwinPhysicsHandler* self = new ( ELeave ) CAknEdwinPhysicsHandler(
+            aEdwin, aPhysics );
+    CleanupStack::PushL( self );
+    self->ConstructL();
+    return self;
+    }
+
+// ---------------------------------------------------------------------------
 // CAknEdwinPhysicsHandler::~CAknEdwinPhysicsHandler
 // ---------------------------------------------------------------------------
 //
 CAknEdwinPhysicsHandler::~CAknEdwinPhysicsHandler()
     {
-    delete iPhysics;
+    if (iOwnsPhysics)
+        {
+        delete iPhysics;
+        }
     }
 
 // ---------------------------------------------------------------------------
@@ -67,66 +94,78 @@
 void CAknEdwinPhysicsHandler::HandlePointerEvent(
     const TPointerEvent& aPointerEvent )
     {   
-    if ( aPointerEvent.iType == TPointerEvent::EButton1Down &&
-        iViewRect.Contains( aPointerEvent.iPosition ) &&
-        iEventUnblockingAllowed )
-        {
-        BlockEvents( EFalse );
-        iPreviousYCoordinate = - KMaxWorldSize;
-        }
-    if ( iEventsBlocked )
-        {
-	    return;
-        }
-
-    // Dragging/flicking logic    
-    
-    if ( aPointerEvent.iType == TPointerEvent::EButton1Down &&
-        iViewRect.Contains( aPointerEvent.iPosition ) )
+    if (iOwnsPhysics)
         {
-        // Pointer down inside view rect, set flag to allow dragging 
-        // and initialize values
-        iFlags.Set( EFlagDraggingAllowed );
-        iPrevPosition = aPointerEvent.iPosition;
-        iStartPosition = aPointerEvent.iPosition;
-        StopPhysics();
+        if ( aPointerEvent.iType == TPointerEvent::EButton1Down &&
+            iViewRect.Contains( aPointerEvent.iPosition ) &&
+            iEventUnblockingAllowed )
+            {
+            BlockEvents( EFalse );
+            iPreviousYCoordinate = - KMaxWorldSize;
+            }
+        if ( iEventsBlocked )
+            {
+            return;
+            }
+    
+        // Dragging/flicking logic    
+        
+        if ( aPointerEvent.iType == TPointerEvent::EButton1Down &&
+            iViewRect.Contains( aPointerEvent.iPosition ) )
+            {
+            // Pointer down inside view rect, set flag to allow dragging 
+            // and initialize values
+            iFlags.Set( EFlagDraggingAllowed );
+            iStartPosition = aPointerEvent.iPosition;
+            StopPhysics();
+    
+            iStartTime.HomeTime();
+            iDragThresholdExceeded = EFalse;
+            iFlags.Clear( EFlagBouncingUp );
+            iFlags.Clear( EFlagBouncingDown );
+            return;
+            }
+        if ( iFlags.IsClear( EFlagDraggingAllowed ) )
+            {
+            return;
+            }
+    
+        if ( aPointerEvent.iType == TPointerEvent::EDrag )
+            {
+            if ( !iDragThresholdExceeded )
+                {
+                TInt drag( iStartPosition.iY - aPointerEvent.iPosition.iY );
+                if ( Abs( drag ) > DragThreshold() )
+                    {
+                    iDragThresholdExceeded = ETrue;
+                    }
+                }
+            else
+                {
+                if ( !iEdwin.ContentFitsToViewRect() )
+                    {
+                    TInt deltaY( iPrevPosition.iY - aPointerEvent.iPosition.iY );
+                    TPoint deltaPoint( 0, deltaY );
+                    iPhysics->RegisterPanningPosition( deltaPoint );
+                    }
+                }
+            iPrevPosition = aPointerEvent.iPosition;
+            }
+        else if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
+            {
+            if ( iFlags.IsClear( EFlagDraggingAllowed ) )
+                {
+                return;
+                }
+            
+            iFlags.Clear( EFlagDraggingAllowed );
 
-        iStartTime.HomeTime();
-        iDragThresholdExceeded = EFalse;
-        iFlags.Clear( EFlagBouncingUp );
-        iFlags.Clear( EFlagBouncingDown );
-        return;
-        }
-    if ( iFlags.IsClear( EFlagDraggingAllowed ) )
-        {
-        return;
-        }
-
-    if ( aPointerEvent.iType == TPointerEvent::EDrag )
-        {
-        if ( !iDragThresholdExceeded )
-            {
-            TInt drag( iStartPosition.iY - aPointerEvent.iPosition.iY );
-            if ( Abs( drag ) > DragThreshold() )
+            if ( !iEdwin.ContentFitsToViewRect() )
                 {
-                iDragThresholdExceeded = ETrue;
+                TPoint drag( 0, iStartPosition.iY - aPointerEvent.iPosition.iY );
+                iPhysics->StartPhysics( drag, iStartTime );
                 }
             }
-
-        if ( iDragThresholdExceeded )
-            {
-            TInt deltaY( iPrevPosition.iY - aPointerEvent.iPosition.iY );
-            iPrevPosition = aPointerEvent.iPosition;
-
-            TPoint deltaPoint( 0, deltaY );
-            iPhysics->RegisterPanningPosition( deltaPoint );
-            }
-        }
-    else if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
-        {
-        iFlags.Clear( EFlagDraggingAllowed );
-        TPoint drag( 0, iStartPosition.iY - aPointerEvent.iPosition.iY );
-        iPhysics->StartPhysics( drag, iStartTime );
         }
     }
 
@@ -145,11 +184,26 @@
 //   
 void CAknEdwinPhysicsHandler::InitPhysicsL()
     {
-    TSize totalSize( iViewRect.Width(), iViewRect.Height() + KMaxWorldSize );
-    TSize viewSize( iViewRect.Width(), iViewRect.Height() );
-
-    iPhysics->InitPhysicsL( totalSize, viewSize, EFalse );
-    }
+    if (iOwnsPhysics)
+        {
+        TSize totalSize( iViewRect.Width(), iViewRect.Height()
+                + KMaxWorldSize );
+        TSize viewSize( iViewRect.Width(), iViewRect.Height() );
+        
+        CTextLayout* layout = iEdwin.TextLayout();
+        
+        if ( layout )
+            {
+            TInt pixelsAbove = layout->PixelsAboveBand();
+            if ( pixelsAbove > 0 )
+                {
+                MoveScrollIndex( -pixelsAbove );
+                }
+            } 
+        
+        iPhysics->InitPhysicsL( totalSize, viewSize, EFalse );
+        }
+	}
 
 // ---------------------------------------------------------------------------
 // CAknEdwinPhysicsHandler::MoveScrollIndex
@@ -164,7 +218,11 @@
         {
         return;
         }
-
+    if ( !IsBouncing() )
+        {
+        iFlags.Clear( EFlagBouncingDown ); 
+        iFlags.Clear( EFlagBouncingUp ); 
+        }
     iWorldIndex += aPixelsToMove;
     ScrollView( EFalse );
     }
@@ -225,8 +283,17 @@
         {
         BlockEvents( ETrue );
         }
-    // Scroll view based on values from aknphysics
-    ScrollView( ETrue );
+    
+    // Check also world indexes here because those might still equal although
+    // y coordinates differ due to crossing world boundaries.
+    if ( iPreviousWorldIndex != iWorldIndex )
+        {
+        // Disable background drawing while panning or flicking. Instead,
+        // background is drawn in one frame.
+        iEdwin.DrawViewBackground( ETrue );
+        ScrollView( ETrue );
+        iEdwin.DrawViewBackground( EFalse );
+        }
     }
 
 // ---------------------------------------------------------------------------
@@ -300,11 +367,13 @@
 // CAknEdwinPhysicsHandler::CAknEdwinPhysicsHandler
 // ---------------------------------------------------------------------------
 //
-CAknEdwinPhysicsHandler::CAknEdwinPhysicsHandler( CEikEdwin& aEdwin ) :
+CAknEdwinPhysicsHandler::CAknEdwinPhysicsHandler( CEikEdwin& aEdwin,
+    CAknPhysics* aPhysics ) :
     iWorldIndex( 0 ),
     iPreviousWorldIndex( 0 ),
-    iPhysics( NULL ),
-    iEdwin( aEdwin )
+    iPhysics( aPhysics ),
+    iEdwin( aEdwin ),
+    iOwnsPhysics( aPhysics == NULL )
     {
     }
 
@@ -314,7 +383,10 @@
 //
 void CAknEdwinPhysicsHandler::ConstructL()
     {
-    iPhysics = CAknPhysics::NewL( *this, &iEdwin );    
+    if (iOwnsPhysics)
+        {
+        iPhysics = CAknPhysics::NewL( *this, &iEdwin );    
+        }
     }
 
 // ---------------------------------------------------------------------------
@@ -349,7 +421,7 @@
 
                 if ( restOfPixels != 0)
                     {
-                    ScrollStep( pixelsToScroll, ETrue );
+                    ScrollStep( restOfPixels, ETrue );
                     }
                 }
             else
@@ -390,6 +462,7 @@
                 
                 iPhysics->SuspendPhysics();
                 InitBounce( aPixelsToScroll > 0 );
+                ScrollRestOfPixels( restOfPixels );
                 iPhysics->ResumePhysics();
                 }
             else
@@ -647,3 +720,13 @@
         }
     return EFalse;
     }
+
+// ---------------------------------------------------------------------------
+// CAknEdwinPhysicsHandler::DisableDragging
+// ---------------------------------------------------------------------------
+//
+void CAknEdwinPhysicsHandler::DisableDragging()
+    {
+    iFlags.Clear( EFlagDraggingAllowed );
+    }
+