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