webengine/osswebengine/WebKit/s60/webview/WebScrollingDeceleratorGH.cpp
branchRCL_3
changeset 48 79859ed3eea9
parent 46 30342f40acbf
child 49 919f36ff910f
equal deleted inserted replaced
47:e1bea15f9a39 48:79859ed3eea9
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 // INCLUDE FILES
    19 // INCLUDE FILES
    20 #include <browser_platform_variant.hrh>
       
    21 #include <../bidi.h>
    20 #include <../bidi.h>
    22 #include "WebScrollingDeceleratorGH.h"
    21 #include "WebScrollingDeceleratorGH.h"
    23 #include "WebView.h"
    22 #include "WebView.h"
    24 #include "WebFrame.h"
    23 #include "WebFrame.h"
    25 #include "WebFrameView.h"
    24 #include "WebFrameView.h"
    27 #include "PlatformScrollbar.h"
    26 #include "PlatformScrollbar.h"
    28 #include "WebScrollbarDrawer.h"
    27 #include "WebScrollbarDrawer.h"
    29 
    28 
    30 #include "WebKitLogger.h"
    29 #include "WebKitLogger.h"
    31 
    30 
       
    31 using namespace RT_GestureHelper;
    32 // constants
    32 // constants
    33 const int KRecordSize = 4;
    33 const int KRecordSize = 4;
    34 
    34 
    35 // The following deceleration curve is generated by a script
    35 // The following deceleration curve is generated by a script
    36 // It lists the timeout dt values in microseconds.
    36 // It lists the timeout dt values in microseconds.
    37 const int KDecelCurveSize = 10;
    37 const int KDecelCurveSize = 10;
    38 
    38 
    39 #ifdef BRDO_PERF_IMPROVEMENTS_ENABLED_FF
       
    40 const int KScrollIntervalTimeout = 30000; // scroll timer interval in microseconds
       
    41 #else
       
    42 const int KScrollIntervalTimeout = 60000; // scroll timer interval in microseconds
    39 const int KScrollIntervalTimeout = 60000; // scroll timer interval in microseconds
    43 #endif
       
    44 
    40 
    45 #ifdef BRDO_MULTITOUCH_ENABLED_FF
    41 const float KDecceleration = -700.0;
    46 const float KDecceleration = -1300.0;
       
    47 #else 
       
    48 const float KDecceleration = -750.0;
       
    49 #endif 
       
    50 const float KSpeedHigh = 2000.0;
       
    51 
    42 
    52 int decelTimerCB(TAny* ptr);
    43 int decelTimerCB(TAny* ptr);
    53 
    44 
    54 
    45 
    55 // ============================ MEMBER FUNCTIONS ===============================
    46 // ============================ MEMBER FUNCTIONS ===============================
    85 // WebScrollingDeceleratorGH::ConstructL
    76 // WebScrollingDeceleratorGH::ConstructL
    86 // -----------------------------------------------------------------------------
    77 // -----------------------------------------------------------------------------
    87 void WebScrollingDeceleratorGH::ConstructL()
    78 void WebScrollingDeceleratorGH::ConstructL()
    88 {
    79 {
    89     m_decelTimer = CPeriodic::NewL(CActive::EPriorityStandard);
    80     m_decelTimer = CPeriodic::NewL(CActive::EPriorityStandard);
    90     m_deceleration = KDecceleration;
       
    91 }
    81 }
    92 
    82 
    93 // -----------------------------------------------------------------------------
    83 // -----------------------------------------------------------------------------
    94 // Destructor
    84 // Destructor
    95 // -----------------------------------------------------------------------------
    85 // -----------------------------------------------------------------------------
    99 }
    89 }
   100 
    90 
   101 
    91 
   102 int WebScrollingDeceleratorGH::getDecceleration()
    92 int WebScrollingDeceleratorGH::getDecceleration()
   103 {
    93 {
   104    return  m_deceleration;  
    94    return  KDecceleration;  
   105 }
    95 }
   106 
    96 
   107 
    97 
   108 int decelTimerCB(TAny* ptr)
    98 int decelTimerCB(TAny* ptr)
   109 {
    99 {
   114 
   104 
   115 void WebScrollingDeceleratorGH::cancelDecel() 
   105 void WebScrollingDeceleratorGH::cancelDecel() 
   116 { 
   106 { 
   117     m_decelelatorSwitch = false;
   107     m_decelelatorSwitch = false;
   118     if (m_decelTimer->IsActive()) {
   108     if (m_decelTimer->IsActive()) {
   119         m_webView.setViewIsScrolling(false);
       
   120 		m_webView.resumeJsTimers();		
       
   121         m_decelTimer->Cancel();
   109         m_decelTimer->Cancel();
   122     }
   110     }
   123 }
   111 }
   124 
   112 
   125 bool WebScrollingDeceleratorGH::startDecel(TRealPoint& speed, WebScrollbarDrawer* scrollbarDrawer)
   113 void WebScrollingDeceleratorGH::startDecel(TRealPoint& speed, WebScrollbarDrawer* scrollbarDrawer)
   126 {
   114 {
   127     bool started = false;
       
   128     m_decelelatorSwitch = true;
   115     m_decelelatorSwitch = true;
   129     m_scrollbarDrawer = scrollbarDrawer;
   116     m_scrollbarDrawer = scrollbarDrawer;
   130     float speedX = speed.iX;
   117     m_initSpeed.iX = (-1) * speed.iX;
   131     float speedY = speed.iY;
   118     m_initSpeed.iY = (-1) * speed.iY;
   132     float absSpeedX = abs(speedX);
       
   133     float absSpeedY = abs(speedY);
       
   134     
       
   135     if (absSpeedX > KSpeedHigh) {
       
   136         speedX = KSpeedHigh * speedX/absSpeedX ;
       
   137     }
       
   138     if (absSpeedY > KSpeedHigh) {
       
   139         speedY = KSpeedHigh * speedY/absSpeedY;
       
   140     }
       
   141     
       
   142     m_initSpeed.iX = (-1) * speedX;
       
   143     m_initSpeed.iY = (-1) * speedY;
       
   144     
   119     
   145     m_numscrollsteps = 0;
   120     m_numscrollsteps = 0;
   146     if (m_decelTimer->IsActive()) {
   121     if (m_decelTimer->IsActive()) {
   147         m_webView.setViewIsScrolling(false);
       
   148     	m_webView.resumeJsTimers();
       
   149         m_decelTimer->Cancel();
   122         m_decelTimer->Cancel();
   150     }
   123     }
   151     
   124     
   152     WebFrameView* scrollingView = m_webView.pageScrollHandler()->currentScrollingFrameView();
   125     WebFrameView* scrollingView = m_webView.pageScrollHandler()->currentScrollingFrameView();
   153     if (scrollingView) {
   126     if (scrollingView) {
   154         m_webView.pauseJsTimers(); // pause the JS timers
       
   155         m_webView.setViewIsScrolling(true);
       
   156         m_startPos = scrollingView->contentPos();
   127         m_startPos = scrollingView->contentPos();
   157         m_lastPos = m_startPos;
   128         m_lastPos = m_startPos;
   158         m_decelTimer->Start(0, KScrollIntervalTimeout, 
   129         m_decelTimer->Start(0, KScrollIntervalTimeout, 
   159                             TCallBack(&decelTimerCB, this));
   130                             TCallBack(&decelTimerCB, this));
   160         started = true;
       
   161     }
   131     }
   162     return started;
       
   163 }
   132 }
   164 
   133 
   165 void WebScrollingDeceleratorGH::scroll()
   134 void WebScrollingDeceleratorGH::scroll()
   166 {
   135 {
   167     if (!m_decelelatorSwitch) return;
   136     if (!m_decelelatorSwitch) return;
   174     TReal32 vx = 0.0;
   143     TReal32 vx = 0.0;
   175     TReal32 vy = 0.0;
   144     TReal32 vy = 0.0;
   176     TReal32 accelX = 0.0;
   145     TReal32 accelX = 0.0;
   177     TReal32 accelY = 0.0;
   146     TReal32 accelY = 0.0;
   178     
   147     
   179     TReal32 deceleration = getDecceleration();
       
   180     
       
   181     if (m_initSpeed.iX) {
   148     if (m_initSpeed.iX) {
   182         accelX = (m_initSpeed.iX > 0) ?  deceleration : (-1) * deceleration;
   149         accelX = (m_initSpeed.iX > 0) ?  KDecceleration : (-1) * KDecceleration;
   183         vx = m_initSpeed.iX + accelX * t;
   150         vx = m_initSpeed.iX + accelX * t;
   184         dx = m_initSpeed.iX * t + 0.5 * accelX * (t * t);
   151         dx = m_initSpeed.iX * t + 0.5 * accelX * (t * t);
   185     }
   152     }
   186         
   153         
   187     if (m_initSpeed.iY) {
   154     if (m_initSpeed.iY) {
   188         accelY = (m_initSpeed.iY > 0) ?  deceleration : (-1) * deceleration;
   155         accelY = (m_initSpeed.iY > 0) ?  KDecceleration : (-1) * KDecceleration;
   189         vy = m_initSpeed.iY + accelY * t;
   156         vy = m_initSpeed.iY + accelY * t;
   190         dy = m_initSpeed.iY * t + 0.5 * accelY * (t * t);
   157         dy = m_initSpeed.iY * t + 0.5 * accelY * (t * t);
   191     }
   158     }
   192     
   159     
   193     dist.SetXY(static_cast<TInt>(dx), static_cast<TInt>(dy));
   160     dist.SetXY(static_cast<TInt>(dx), static_cast<TInt>(dy));
   203         (m_numscrollsteps > 1 && !scrollingView->needScroll(pos) && 
   170         (m_numscrollsteps > 1 && !scrollingView->needScroll(pos) && 
   204         !handler->currentScrollingElement())) {
   171         !handler->currentScrollingElement())) {
   205         if (m_scrollbarDrawer) {
   172         if (m_scrollbarDrawer) {
   206             m_scrollbarDrawer->fadeScrollbar();
   173             m_scrollbarDrawer->fadeScrollbar();
   207         }
   174         }
   208 		
       
   209         m_webView.resumeJsTimers(); // resume the js timers
       
   210         m_webView.setViewIsScrolling(false);
       
   211         m_decelTimer->Cancel();
   175         m_decelTimer->Cancel();
   212         handler->clearScrollingElement();
   176         handler->clearScrollingElement();
   213         m_webView.setViewIsScrolling(false);
   177         m_webView.setViewIsScrolling(false);
   214         m_webView.toggleRepaintTimer(true);
   178         m_webView.toggleRepaintTimer(true);
   215     }
   179     }