webengine/osswebengine/WebKit/s60/webview/WebScrollingDeceleratorGH.cpp
changeset 65 5bfc169077b2
parent 42 d39add9822e2
equal deleted inserted replaced
42:d39add9822e2 65:5bfc169077b2
    26 #include "PlatformScrollbar.h"
    26 #include "PlatformScrollbar.h"
    27 #include "WebScrollbarDrawer.h"
    27 #include "WebScrollbarDrawer.h"
    28 
    28 
    29 #include "WebKitLogger.h"
    29 #include "WebKitLogger.h"
    30 
    30 
       
    31 using namespace RT_GestureHelper;
    31 // constants
    32 // constants
    32 const int KRecordSize = 4;
    33 const int KRecordSize = 4;
    33 
    34 
    34 // The following deceleration curve is generated by a script
    35 // The following deceleration curve is generated by a script
    35 // It lists the timeout dt values in microseconds.
    36 // It lists the timeout dt values in microseconds.
    36 const int KDecelCurveSize = 10;
    37 const int KDecelCurveSize = 10;
    37 
    38 
    38 const int KScrollIntervalTimeout = 60000; // scroll timer interval in microseconds
    39 const int KScrollIntervalTimeout = 60000; // scroll timer interval in microseconds
    39 
    40 
    40 const float KDeccelerationLow = -350.0;
    41 const float KDecceleration = -700.0;
    41 const float KDeccelerationHigh = -600.0;
       
    42 const float KSpeedHigh = 2000.0;
       
    43 
    42 
    44 int decelTimerCB(TAny* ptr);
    43 int decelTimerCB(TAny* ptr);
    45 
    44 
    46 
    45 
    47 // ============================ MEMBER FUNCTIONS ===============================
    46 // ============================ MEMBER FUNCTIONS ===============================
    77 // WebScrollingDeceleratorGH::ConstructL
    76 // WebScrollingDeceleratorGH::ConstructL
    78 // -----------------------------------------------------------------------------
    77 // -----------------------------------------------------------------------------
    79 void WebScrollingDeceleratorGH::ConstructL()
    78 void WebScrollingDeceleratorGH::ConstructL()
    80 {
    79 {
    81     m_decelTimer = CPeriodic::NewL(CActive::EPriorityStandard);
    80     m_decelTimer = CPeriodic::NewL(CActive::EPriorityStandard);
    82     m_deceleration = KDeccelerationHigh;
       
    83 }
    81 }
    84 
    82 
    85 // -----------------------------------------------------------------------------
    83 // -----------------------------------------------------------------------------
    86 // Destructor
    84 // Destructor
    87 // -----------------------------------------------------------------------------
    85 // -----------------------------------------------------------------------------
    91 }
    89 }
    92 
    90 
    93 
    91 
    94 int WebScrollingDeceleratorGH::getDecceleration()
    92 int WebScrollingDeceleratorGH::getDecceleration()
    95 {
    93 {
    96    return  m_deceleration;  
    94    return  KDecceleration;  
    97 }
    95 }
    98 
    96 
    99 
    97 
   100 int decelTimerCB(TAny* ptr)
    98 int decelTimerCB(TAny* ptr)
   101 {
    99 {
   114 
   112 
   115 void WebScrollingDeceleratorGH::startDecel(TRealPoint& speed, WebScrollbarDrawer* scrollbarDrawer)
   113 void WebScrollingDeceleratorGH::startDecel(TRealPoint& speed, WebScrollbarDrawer* scrollbarDrawer)
   116 {
   114 {
   117     m_decelelatorSwitch = true;
   115     m_decelelatorSwitch = true;
   118     m_scrollbarDrawer = scrollbarDrawer;
   116     m_scrollbarDrawer = scrollbarDrawer;
   119     float speedX = speed.iX;
   117     m_initSpeed.iX = (-1) * speed.iX;
   120     float speedY = speed.iY;
   118     m_initSpeed.iY = (-1) * speed.iY;
   121     float absSpeedX = abs(speedX);
       
   122     float absSpeedY = abs(speedY);
       
   123     
       
   124     if (absSpeedX > KSpeedHigh) {
       
   125         speedX = KSpeedHigh * speedX/absSpeedX ;
       
   126         m_deceleration = KDeccelerationLow;
       
   127     }
       
   128     if (absSpeedY > KSpeedHigh) {
       
   129         speedY = KSpeedHigh * speedY/absSpeedY;
       
   130         m_deceleration = KDeccelerationLow;
       
   131     }
       
   132     
       
   133     m_initSpeed.iX = (-1) * speedX;
       
   134     m_initSpeed.iY = (-1) * speedY;
       
   135     
   119     
   136     m_numscrollsteps = 0;
   120     m_numscrollsteps = 0;
   137     if (m_decelTimer->IsActive()) {
   121     if (m_decelTimer->IsActive()) {
   138         m_decelTimer->Cancel();
   122         m_decelTimer->Cancel();
   139     }
   123     }
   159     TReal32 vx = 0.0;
   143     TReal32 vx = 0.0;
   160     TReal32 vy = 0.0;
   144     TReal32 vy = 0.0;
   161     TReal32 accelX = 0.0;
   145     TReal32 accelX = 0.0;
   162     TReal32 accelY = 0.0;
   146     TReal32 accelY = 0.0;
   163     
   147     
   164     TReal32 deceleration = getDecceleration();
       
   165     
       
   166     if (m_initSpeed.iX) {
   148     if (m_initSpeed.iX) {
   167         accelX = (m_initSpeed.iX > 0) ?  deceleration : (-1) * deceleration;
   149         accelX = (m_initSpeed.iX > 0) ?  KDecceleration : (-1) * KDecceleration;
   168         vx = m_initSpeed.iX + accelX * t;
   150         vx = m_initSpeed.iX + accelX * t;
   169         dx = m_initSpeed.iX * t + 0.5 * accelX * (t * t);
   151         dx = m_initSpeed.iX * t + 0.5 * accelX * (t * t);
   170     }
   152     }
   171         
   153         
   172     if (m_initSpeed.iY) {
   154     if (m_initSpeed.iY) {
   173         accelY = (m_initSpeed.iY > 0) ?  deceleration : (-1) * deceleration;
   155         accelY = (m_initSpeed.iY > 0) ?  KDecceleration : (-1) * KDecceleration;
   174         vy = m_initSpeed.iY + accelY * t;
   156         vy = m_initSpeed.iY + accelY * t;
   175         dy = m_initSpeed.iY * t + 0.5 * accelY * (t * t);
   157         dy = m_initSpeed.iY * t + 0.5 * accelY * (t * t);
   176     }
   158     }
   177     
   159     
   178     dist.SetXY(static_cast<TInt>(dx), static_cast<TInt>(dy));
   160     dist.SetXY(static_cast<TInt>(dx), static_cast<TInt>(dy));