webengine/osswebengine/WebKit/s60/webview/WebPageScrollHandler.cpp
changeset 13 10e98eab6f85
parent 8 7c90e6132015
child 36 0ed94ceaa377
equal deleted inserted replaced
8:7c90e6132015 13:10e98eab6f85
   249         }
   249         }
   250         case TPointerEvent::EButton1Up:
   250         case TPointerEvent::EButton1Up:
   251         {
   251         {
   252             m_scrollTimer->Cancel();
   252             m_scrollTimer->Cancel();
   253             if (m_scrollableView.m_scrollingElement) {
   253             if (m_scrollableView.m_scrollingElement) {
   254                 if (m_scrollableView.m_scrollingElement) {
   254                 clearScrollingElement();
   255                     m_scrollableView.m_scrollingElement->deref();
       
   256                     m_scrollableView.m_scrollingElement = NULL;
       
   257                 }
       
   258             }
   255             }
   259             else {
   256             else {
   260                 if (m_lastMoveEventTime != 0)
   257                 if (m_lastMoveEventTime != 0)
   261                 {           
   258                 {           
   262                     // Start deceleration only if the delta since last drag event is less than threshold
   259                     // Start deceleration only if the delta since last drag event is less than threshold
   279         }
   276         }
   280     }
   277     }
   281 }
   278 }
   282 
   279 
   283 void WebPageScrollHandler::setupScrolling(const TPoint& aNewPosition)
   280 void WebPageScrollHandler::setupScrolling(const TPoint& aNewPosition)
   284 {   
   281 {
   285     if (m_lastPosition == TPoint(0, 0)) {
   282     if (m_lastPosition == TPoint(0, 0)) {
   286         m_lastPosition = aNewPosition;
   283         m_lastPosition = aNewPosition;
   287     }
   284     }
       
   285    
   288     if(m_lastPosition == aNewPosition)
   286     if(m_lastPosition == aNewPosition)
   289         return; // no displacement -- means no need for scrolling    
   287         return; // no displacement -- means no need for scrolling    
   290 
   288 
   291     //Ignore move events until they jump the threshold (avoids jittery finger effect) 
   289     //Ignore move events until they jump the threshold (avoids jittery finger effect) 
   292     TInt absX = Abs( aNewPosition.iX - m_lastPosition.iX);
   290     TInt absX = Abs( aNewPosition.iX - m_lastPosition.iX);
   303         m_scrollTimer->Cancel();                   
   301         m_scrollTimer->Cancel();                   
   304         m_scrollTimer->Start( 0, KScrollIntervalTimeout, TCallBack(&handleScrollTimerEventCallback,this));
   302         m_scrollTimer->Start( 0, KScrollIntervalTimeout, TCallBack(&handleScrollTimerEventCallback,this));
   305         m_webView->setViewIsScrolling(true);
   303         m_webView->setViewIsScrolling(true);
   306         m_webView->toggleRepaintTimer(false);
   304         m_webView->toggleRepaintTimer(false);
   307     }
   305     }
   308 
   306 }
   309 
   307 
   310 }    
   308 
       
   309 void WebPageScrollHandler::clearScrollingElement()
       
   310 {
       
   311     if (m_scrollableView.m_scrollingElement) {
       
   312         m_scrollableView.m_scrollingElement->deref();
       
   313         m_scrollableView.m_scrollingElement = NULL;
       
   314     }
       
   315 }
   311 
   316 
   312 void WebPageScrollHandler::scrollContent()
   317 void WebPageScrollHandler::scrollContent()
   313 {
   318 {
   314     TPoint scrollDelta = m_lastPosition - m_currentPosition;
   319     TPoint scrollDelta = m_lastPosition - m_currentPosition;
   315  
   320     scrollContent(scrollDelta);
       
   321 }
       
   322 
       
   323 void WebPageScrollHandler::scrollContent(TPoint& aScrollDelta)
       
   324 {
   316     if(!m_scrollableView.activeFrameView())
   325     if(!m_scrollableView.activeFrameView())
   317             return;
   326             return;
   318         
   327         
   319     int absX = Abs(scrollDelta.iX);
   328     
   320     int absY = Abs(scrollDelta.iY);
   329     int absX = Abs(aScrollDelta.iX);
       
   330     int absY = Abs(aScrollDelta.iY);
   321                                        
   331                                        
   322     if(absX || absY) //move only if necessary
   332     if(absX || absY) //move only if necessary
   323     {      
   333     {      
   324         // calculate which direction we are trying to scroll
   334         // calculate which direction we are trying to scroll
   325         if(m_scrollDirectionState == ScrollDirectionUnassigned) {
   335         if(m_scrollDirectionState == ScrollDirectionUnassigned) {
   329         
   339         
   330         switch (m_scrollDirectionState)
   340         switch (m_scrollDirectionState)
   331         {           
   341         {           
   332             case ScrollDirectionX: //scroll in X dir
   342             case ScrollDirectionX: //scroll in X dir
   333             {
   343             {
   334                 scrollDelta.iY = 0;
   344                 aScrollDelta.iY = 0;
   335                 scrollDelta.iX *= 100;
   345                 aScrollDelta.iX *= 100;
   336                 //Fallback to XY state if the current position is out of bounds                
   346                 //Fallback to XY state if the current position is out of bounds                
   337                 TPoint boundaryCheckpoint = m_focalPoint - m_currentPosition;                                
   347                 TPoint boundaryCheckpoint = m_focalPoint - m_currentPosition;                                
   338                 if(Abs(boundaryCheckpoint.iY) > KScrollDirectionBoundary)
   348                 if(Abs(boundaryCheckpoint.iY) > KScrollDirectionBoundary)
   339                     m_scrollDirectionState = ScrollDirectionXY;
   349                     m_scrollDirectionState = ScrollDirectionXY;
   340                 break;
   350                 break;
   341             }
   351             }
   342             case ScrollDirectionY: //scroll in Y dir
   352             case ScrollDirectionY: //scroll in Y dir
   343             {                
   353             {                
   344                 scrollDelta.iX = 0;
   354                 aScrollDelta.iX = 0;
   345                 scrollDelta.iY *= 100;
   355                 aScrollDelta.iY *= 100;
   346                 //Fallback to XY state if the current position is out of bounds                
   356                 //Fallback to XY state if the current position is out of bounds                
   347                 TPoint boundaryCheckpoint = m_focalPoint - m_currentPosition;                                
   357                 TPoint boundaryCheckpoint = m_focalPoint - m_currentPosition;                                
   348                 if(Abs(boundaryCheckpoint.iX) > KScrollDirectionBoundary)
   358                 if(Abs(boundaryCheckpoint.iX) > KScrollDirectionBoundary)
   349                     m_scrollDirectionState = ScrollDirectionXY;
   359                     m_scrollDirectionState = ScrollDirectionXY;
   350                 break;
   360                 break;
   351             }
   361             }
   352             case ScrollDirectionXY: //scroll in XY
   362             case ScrollDirectionXY: //scroll in XY
   353             {
   363             {
   354                 scrollDelta.iX *= 100;
   364                 aScrollDelta.iX *= 100;
   355                 scrollDelta.iY *= 100;
   365                 aScrollDelta.iY *= 100;
   356                 m_scrollDirectionState = ScrollDirectionUnassigned;
   366                 m_scrollDirectionState = ScrollDirectionUnassigned;
   357                 break;
   367                 break;
   358             }
   368             }
   359         }        
   369         }        
   360         if (m_scrollableView.m_scrollingElement) {
   370         if (m_scrollableView.m_scrollingElement) {
   361             bool shouldScrollVertically = false;
   371             bool shouldScrollVertically = false;
   362             bool shouldScrollHorizontally = false;
   372             bool shouldScrollHorizontally = false;
   363             //WebFrameView* mfv = m_webView->mainFrame()->frameView();
       
   364             WebFrame* frame = kit(m_scrollableView.m_scrollingElement->document()->frame());
   373             WebFrame* frame = kit(m_scrollableView.m_scrollingElement->document()->frame());
   365             IntPoint currPoint = frame->frameView()->viewCoordsInFrameCoords(m_currentPosition);
       
   366             RenderObject* render = m_scrollableView.m_scrollingElement->renderer();
   374             RenderObject* render = m_scrollableView.m_scrollingElement->renderer();
   367             __ASSERT_DEBUG(render->isScrollable(), User::Panic(_L(""), KErrGeneral));
   375             __ASSERT_DEBUG(render->isScrollable(), User::Panic(_L(""), KErrGeneral));
   368             if (scrollDelta.iY)
   376             if (aScrollDelta.iY)
   369                 shouldScrollVertically = !render->scroll(ScrollDown, ScrollByPixel, frame->frameView()->toDocCoords(scrollDelta).iY / 100);
   377                 shouldScrollVertically = !render->scroll(ScrollDown, ScrollByPixel, frame->frameView()->toDocCoords(aScrollDelta).iY / 100);
   370             if (scrollDelta.iX)
   378             if (aScrollDelta.iX)
   371                 shouldScrollHorizontally = !render->scroll(ScrollRight, ScrollByPixel, frame->frameView()->toDocCoords(scrollDelta).iX / 100);
   379                 shouldScrollHorizontally = !render->scroll(ScrollRight, ScrollByPixel, frame->frameView()->toDocCoords(aScrollDelta).iX / 100);
       
   380 
   372             TPoint scrollPos = frame->frameView()->contentPos();
   381             TPoint scrollPos = frame->frameView()->contentPos();
   373             TPoint newscrollDelta = frame->frameView()->toDocCoords(scrollDelta);
   382             TPoint newscrollDelta = frame->frameView()->toDocCoords(aScrollDelta);
   374             m_currentNormalizedPosition +=  newscrollDelta;     
   383             m_currentNormalizedPosition +=  newscrollDelta;     
   375 
   384 
   376             if (shouldScrollHorizontally) {
   385             if (shouldScrollHorizontally) {
   377                 scrollPos.iX = m_currentNormalizedPosition.iX/100;
   386                 scrollPos.iX = m_currentNormalizedPosition.iX/100;
   378             }
   387             }
   379             if (shouldScrollVertically) {
   388             if (shouldScrollVertically) {
   380                 scrollPos.iY = m_currentNormalizedPosition.iY/100;
   389                 scrollPos.iY = m_currentNormalizedPosition.iY/100;
   381             }
   390             }
   382             frame->frameView()->scrollTo(scrollPos);
   391             
       
   392             
       
   393             if (shouldScrollVertically || shouldScrollHorizontally){
       
   394                 if (m_scrollableView.m_frameView->needScroll(scrollPos)) {
       
   395                     frame->frameView()->scrollTo(scrollPos);
       
   396                     updateScrollbars(scrollPos, newscrollDelta);
       
   397                     core(frame)->sendScrollEvent();
       
   398                 }
       
   399             }
       
   400             else {
       
   401                 m_webView->syncRepaint();
       
   402             }
   383             m_lastPosition = m_currentPosition;
   403             m_lastPosition = m_currentPosition;
   384             m_currentNormalizedPosition.iX = frame->frameView()->contentPos().iX * 100;
   404             m_currentNormalizedPosition.iX = frame->frameView()->contentPos().iX * 100;
   385             m_currentNormalizedPosition.iY = frame->frameView()->contentPos().iY * 100;
   405             m_currentNormalizedPosition.iY = frame->frameView()->contentPos().iY * 100;
   386             if (shouldScrollVertically || shouldScrollHorizontally)
       
   387                 updateScrollbars(scrollPos, newscrollDelta);
       
   388             currPoint = frame->frameView()->viewCoordsInFrameCoords(m_currentPosition);
       
   389             if (shouldScrollHorizontally || shouldScrollVertically) {
       
   390                 core(frame)->sendScrollEvent();
       
   391                 m_webView->DrawNow();
       
   392             }
       
   393         }
   406         }
   394         else {
   407         else {
   395             TPoint scrollPos;
   408             TPoint scrollPos;
   396             TPoint newscrollDelta = m_scrollableView.m_frameView->toDocCoords(scrollDelta);
   409             TPoint newscrollDelta = m_scrollableView.m_frameView->toDocCoords(aScrollDelta);
   397             m_currentNormalizedPosition +=  newscrollDelta;  
   410             m_currentNormalizedPosition +=  newscrollDelta;  
   398             scrollPos.iX = m_currentNormalizedPosition.iX/100;
   411             scrollPos.iX = m_currentNormalizedPosition.iX/100;
   399             scrollPos.iY = m_currentNormalizedPosition.iY/100;
   412             scrollPos.iY = m_currentNormalizedPosition.iY/100;
   400             TPoint cpos = m_scrollableView.m_frameView->contentPos();
   413             TPoint cpos = m_scrollableView.m_frameView->contentPos();
   401            
   414            
   404                 m_lastPosition = m_currentPosition;
   417                 m_lastPosition = m_currentPosition;
   405                 m_currentNormalizedPosition.iX = m_scrollableView.contentPos().iX * 100;
   418                 m_currentNormalizedPosition.iX = m_scrollableView.contentPos().iX * 100;
   406                 m_currentNormalizedPosition.iY = m_scrollableView.contentPos().iY * 100;
   419                 m_currentNormalizedPosition.iY = m_scrollableView.contentPos().iY * 100;
   407             }
   420             }
   408             else {
   421             else {
       
   422           
   409                 m_scrollableView.m_frameView->scrollTo(scrollPos);
   423                 m_scrollableView.m_frameView->scrollTo(scrollPos);
   410                 m_lastPosition = m_currentPosition;
   424                 m_lastPosition = m_currentPosition;
   411 #ifndef BRDO_USE_GESTURE_HELPER                
   425 #ifndef BRDO_USE_GESTURE_HELPER                
   412                 m_decel->updatePos();
   426                 m_decel->updatePos();
   413 #endif                
   427 #endif                
   418     }
   432     }
   419 } 
   433 } 
   420 
   434 
   421 bool WebPageScrollHandler::calculateScrollableFrameView(const TPoint& aNewPosition)
   435 bool WebPageScrollHandler::calculateScrollableFrameView(const TPoint& aNewPosition)
   422 {
   436 {
   423     if (calculateScrollableElement(aNewPosition)) return true;
   437     calculateScrollableElement(aNewPosition);
   424     
   438     
   425     //First figure out the direction we are scrolling    
   439     //First figure out the direction we are scrolling    
   426     bool x_r = false;
   440     bool x_r = false;
   427     bool x_l = false;
   441     bool x_l = false;
   428     bool y_t = false;
   442     bool y_t = false;
   632         m_webView->toggleRepaintTimer(true);
   646         m_webView->toggleRepaintTimer(true);
   633     }
   647     }
   634     else {
   648     else {
   635         m_scrollTimer->Cancel();
   649         m_scrollTimer->Cancel();
   636         m_lastPosition = TPoint(0, 0);
   650         m_lastPosition = TPoint(0, 0);
   637         if (m_scrollableView.m_scrollingElement) {
   651         decelDoesScrollbars = startDeceleration(aEvent);
   638             if (m_scrollableView.m_scrollingElement) {
       
   639                 m_scrollableView.m_scrollingElement->deref();
       
   640                 m_scrollableView.m_scrollingElement = NULL;
       
   641             }
       
   642         }
       
   643         else {
       
   644             decelDoesScrollbars = startDeceleration(aEvent);
       
   645                     
   652                     
   646             if (m_webView->viewIsScrolling()) {
   653         if (m_webView->viewIsScrolling()) {
   647                 Frame* frame = m_webView->page()->focusController()->focusedOrMainFrame();
   654             Frame* frame = m_webView->page()->focusController()->focusedOrMainFrame();
   648                 frame->bridge()->sendScrollEvent();                            
   655             frame->bridge()->sendScrollEvent();                            
   649             }
       
   650         }
   656         }
   651     
   657     
   652         if (!decelDoesScrollbars) {
   658         if (!decelDoesScrollbars) {
   653             m_scrollbarDrawer->fadeScrollbar();
   659             m_scrollbarDrawer->fadeScrollbar();
   654             m_webView->setViewIsScrolling(false);
   660             m_webView->setViewIsScrolling(false);