webengine/osswebengine/WebKit/s60/webview/WebPointerEventHandler.cpp
changeset 11 c8a366e56285
parent 5 10e98eab6f85
child 15 60c5402cb945
equal deleted inserted replaced
10:a359256acfc6 11:c8a366e56285
    64 
    64 
    65 static const int KMinScrollAndTapInterval = 200000;				// 200 ms
    65 static const int KMinScrollAndTapInterval = 200000;				// 200 ms
    66 static const int KDoubleTapMinActivationInterval = 100000;     // 100 ms
    66 static const int KDoubleTapMinActivationInterval = 100000;     // 100 ms
    67 static const int KDoubleTapMaxActivationInterval = 500000;     // 500 ms
    67 static const int KDoubleTapMaxActivationInterval = 500000;     // 500 ms
    68 static const int KDoubleTapIdleInterval = 700000;			// 700 ms, to prevent triple-tap effects
    68 static const int KDoubleTapIdleInterval = 700000;			// 700 ms, to prevent triple-tap effects
       
    69 #define IS_NAVIGATION_NONE      (m_webview->brCtl()->settings()->getNavigationType() == SettingsContainer::NavigationTypeNone)
       
    70 #define IS_TABBED_NAVIGATION    (m_webview->brCtl()->settings()->getNavigationType() == SettingsContainer::NavigationTypeTabbed)
    69 
    71 
    70 //-----------------------------------------------------------------------------
    72 //-----------------------------------------------------------------------------
    71 // WebPointerEventHandler::NewL
    73 // WebPointerEventHandler::NewL
    72 //-----------------------------------------------------------------------------
    74 //-----------------------------------------------------------------------------
    73 WebPointerEventHandler* WebPointerEventHandler::NewL(WebView* view)
    75 WebPointerEventHandler* WebPointerEventHandler::NewL(WebView* view)
   190       case EGestureSwipeRight:
   192       case EGestureSwipeRight:
   191       case EGestureSwipeUp:
   193       case EGestureSwipeUp:
   192       case EGestureSwipeDown:
   194       case EGestureSwipeDown:
   193       {
   195       {
   194           m_ignoreTap = false;
   196           m_ignoreTap = false;
       
   197           if (!IS_NAVIGATION_NONE) {
   195           handleTouchUp(aEvent);      
   198           handleTouchUp(aEvent);      
       
   199           }
       
   200           else {
       
   201               Frame* frm = m_webview->page()->focusController()->focusedOrMainFrame();
       
   202               m_webview->sendMouseEventToEngine(TPointerEvent::EButton1Up, m_highlightPos, frm);
       
   203           }
   196           break;    
   204           break;    
   197       }
   205       }
   198       // sent on move
   206       // sent on move
   199       case EGestureDrag:
   207       case EGestureDrag:
   200       {
   208       {
   250     PluginHandler* pluginHandler = WebCore::StaticObjectsContainer::instance()->pluginHandler();
   258     PluginHandler* pluginHandler = WebCore::StaticObjectsContainer::instance()->pluginHandler();
   251     PluginSkin* pluginToActivate = pluginHandler->pluginToActivate();
   259     PluginSkin* pluginToActivate = pluginHandler->pluginToActivate();
   252     m_buttonDownEvent = m_currentEvent;
   260     m_buttonDownEvent = m_currentEvent;
   253     m_highlightPos = aEvent.CurrentPos();
   261     m_highlightPos = aEvent.CurrentPos();
   254     
   262     
   255     if ( !m_buttonDownTimer.isActive() && !m_webview->inPageViewMode() && 
   263     if ( !m_buttonDownTimer.isActive() && !m_webview->inPageViewMode()){
   256          !pluginToActivate ){
       
   257         m_buttonDownTimer.startOneShot(0.1f);        
   264         m_buttonDownTimer.startOneShot(0.1f);        
   258     }
   265     }
   259 
   266 
       
   267     if (!IS_NAVIGATION_NONE) {
   260     m_webview->pageScrollHandler()->handleTouchDownGH(aEvent);
   268     m_webview->pageScrollHandler()->handleTouchDownGH(aEvent);
       
   269     }
   261 
   270 
   262     if ( TBrCtlDefs::EElementActivatedObjectBox == elType) {
   271     if ( TBrCtlDefs::EElementActivatedObjectBox == elType) {
   263         PluginSkin* plugin = m_webview->mainFrame()->focusedPlugin();
   272         PluginSkin* plugin = m_webview->mainFrame()->focusedPlugin();
   264         if (plugin && plugin->pluginWin()) {
   273         if (plugin && plugin->pluginWin()) {
   265             if (!plugin->getClipRect().Contains(m_buttonDownEvent.iPosition)) {
   274             if (!plugin->getClipRect().Contains(m_buttonDownEvent.iPosition)) {
   268             else {
   277             else {
   269                 plugin->pluginWin()->HandlePointerEventL(m_buttonDownEvent);
   278                 plugin->pluginWin()->HandlePointerEventL(m_buttonDownEvent);
   270             }
   279             }
   271         }
   280         }
   272     }
   281     }
   273     if (pluginToActivate) {
   282     
   274         Frame* coreFrame = core(m_webview->mainFrame());
       
   275         coreFrame->eventHandler()->handleMousePressEvent(PlatformMouseEvent(m_buttonDownEvent));
       
   276     }    
       
   277     /*
   283     /*
   278      * After introducing "link selection" pointer down action is done in 
   284      * After introducing "link selection" pointer down action is done in 
   279      * buttondown timer callback. When "down" gesture event is arrived we start 
   285      * buttondown timer callback. When "down" gesture event is arrived we start 
   280      * timer end exit, so gesture helper is ready to deliver next gesture event. 
   286      * timer end exit, so gesture helper is ready to deliver next gesture event. 
   281      * Meanwhile the processing of the first gesture event hasn't been finished yet. 
   287      * Meanwhile the processing of the first gesture event hasn't been finished yet. 
   296 {
   302 {
   297     m_highlightPos = TPoint(-1,-1);
   303     m_highlightPos = TPoint(-1,-1);
   298     m_highlightedNode = NULL;
   304     m_highlightedNode = NULL;
   299     PluginHandler* pluginHandler = WebCore::StaticObjectsContainer::instance()->pluginHandler();
   305     PluginHandler* pluginHandler = WebCore::StaticObjectsContainer::instance()->pluginHandler();
   300     pluginHandler->setPluginToActivate(NULL);
   306     pluginHandler->setPluginToActivate(NULL);
       
   307     if (!IS_NAVIGATION_NONE) {
   301     m_webview->pageScrollHandler()->handleTouchUpGH(aEvent);
   308     m_webview->pageScrollHandler()->handleTouchUpGH(aEvent);
       
   309     }
   302 }
   310 }
   303 
   311 
   304 // ======================================================================
   312 // ======================================================================
   305 // WebPointerEventHandler::handleMoveL
   313 // WebPointerEventHandler::handleMoveL
   306 // ======================================================================
   314 // ======================================================================
   309     TBrCtlDefs::TBrCtlElementType elType = m_webview->focusedElementType();
   317     TBrCtlDefs::TBrCtlElementType elType = m_webview->focusedElementType();
   310     TPoint curPos = aEvent.CurrentPos();
   318     TPoint curPos = aEvent.CurrentPos();
   311     PluginHandler* pluginHandler = WebCore::StaticObjectsContainer::instance()->pluginHandler();
   319     PluginHandler* pluginHandler = WebCore::StaticObjectsContainer::instance()->pluginHandler();
   312     pluginHandler->setPluginToActivate(NULL);
   320     pluginHandler->setPluginToActivate(NULL);
   313     m_buttonDownTimer.stop();
   321     m_buttonDownTimer.stop();
       
   322     if (IS_NAVIGATION_NONE) {
       
   323         Frame* frm = m_webview->page()->focusController()->focusedOrMainFrame();
       
   324         m_webview->sendMouseEventToEngine(TPointerEvent::EMove, curPos, frm);
       
   325     }
       
   326     else {
   314     HandleHighlightChange(curPos);
   327     HandleHighlightChange(curPos);
   315     
   328     
   316     m_webview->pageScrollHandler()->handleScrollingGH(aEvent);
   329     m_webview->pageScrollHandler()->handleScrollingGH(aEvent);
       
   330     }
   317 }
   331 }
   318 
   332 
   319 
   333 
   320 // ======================================================================
   334 // ======================================================================
   321 // WebPointerEventHandler::HandlePointerEventL
   335 // WebPointerEventHandler::HandlePointerEventL
   344             m_webview->GetContainerWindow().EnablePointerMoveBuffer();
   358             m_webview->GetContainerWindow().EnablePointerMoveBuffer();
   345         }
   359         }
   346         else if (aPointerEvent.iType == TPointerEvent::EButton1Up) {
   360         else if (aPointerEvent.iType == TPointerEvent::EButton1Up) {
   347             m_webview->GetContainerWindow().DisablePointerMoveBuffer();
   361             m_webview->GetContainerWindow().DisablePointerMoveBuffer();
   348         }
   362         }
   349         if (m_webview->brCtl()->settings()->getNavigationType() == SettingsContainer::NavigationTypeNone) {
   363 
   350             TPointerEvent event;
   364         }
   351             event.iPosition = aPointerEvent.iPosition;
   365 
   352             event.iModifiers = 0;
       
   353             event.iType = aPointerEvent.iType;
       
   354 
       
   355             if (event.iType == TPointerEvent::EDrag) event.iType = TPointerEvent::EMove;
       
   356             m_webview->sendMouseEventToEngine(event.iType, event.iPosition, core(m_webview->mainFrame()));
       
   357             return;
       
   358         }
       
   359     }
       
   360 
   366 
   361     if (m_webview->brCtl()->settings()->getNavigationType() == SettingsContainer::NavigationTypeTabbed) {
   367     if (m_webview->brCtl()->settings()->getNavigationType() == SettingsContainer::NavigationTypeTabbed) {
   362         m_webview->tabbedNavigation()->updateCursorPosition(aPointerEvent.iPosition);
   368         m_webview->tabbedNavigation()->updateCursorPosition(aPointerEvent.iPosition);
   363     }
   369     }
   364 
   370 
   405     TRect elRect;
   411     TRect elRect;
   406     TBrCtlDefs::TBrCtlElementType elType = TBrCtlDefs::EElementNone;
   412     TBrCtlDefs::TBrCtlElementType elType = TBrCtlDefs::EElementNone;
   407     Frame* coreFrame = core(m_webview->mainFrame());
   413     Frame* coreFrame = core(m_webview->mainFrame());
   408     WebCursor* cursor = StaticObjectsContainer::instance()->webCursor();
   414     WebCursor* cursor = StaticObjectsContainer::instance()->webCursor();
   409     m_webview->page()->chrome()->client()->setElementVisibilityChanged(false);
   415     m_webview->page()->chrome()->client()->setElementVisibilityChanged(false);
   410     HitTestResult htresult(cursor->position());
       
   411     TPointerEvent event;
   416     TPointerEvent event;
   412     TPoint pos = cursor->position();
   417     TPoint pos = cursor->position();
   413     event.iPosition = pos;
   418     IntPoint point(pos.iX, pos.iY);   
   414     event.iModifiers = 0;
   419     HitTestResult htresult = coreFrame->eventHandler()->hitTestResultAtPoint(point, true);
   415     event.iType = TPointerEvent::EMove;
   420     Node* eventNode = htresult.innerNode();
   416     coreFrame->eventHandler()->handleMouseMoveEvent(PlatformMouseEvent(event),&htresult);
   421     Frame* frm = eventNode->document()->frame();
   417     WebFrame* frm = cursor->getFrameUnderCursor();
   422     WebFrame* wfrm = kit(frm);
   418     TPoint pt(frm->frameView()->viewCoordsInFrameCoords(pos));
   423     TPoint pt(wfrm->frameView()->viewCoordsInFrameCoords(pos));
   419     TPoint nodePoint;
   424     TPoint nodePoint;
   420     
   425     
   421     m_highlightedNode = NULL;
   426     m_highlightedNode = NULL;
   422 
   427 
   423     cursor->navigableNodeUnderCursor(*(frm), pt, elType, elRect);
   428     frm->bridge()->getTypeFromElement(eventNode, elType, elRect);
   424     if (elType == TBrCtlDefs::EElementNone) {
   429     if (elType == TBrCtlDefs::EElementNone) {
   425         
   430         
   426         Node* n = frm->getClosestAnchorElement(cursor->position(), pos);
   431         Node* n = wfrm->getClosestAnchorElement(cursor->position(), pos);
   427         if (n) {
   432         if (n) {
   428             htresult = HitTestResult(pos);
   433             point.setX(pos.iX);
   429             event.iPosition = pos;
   434             point.setY(pos.iY);
   430             coreFrame->eventHandler()->handleMouseMoveEvent(PlatformMouseEvent(event),&htresult);
   435             htresult = coreFrame->eventHandler()->hitTestResultAtPoint(point, true);
   431             coreFrame->bridge()->getTypeFromElement(htresult.innerNode(), elType, elRect);
   436             eventNode = htresult.innerNode();
       
   437             frm = eventNode->document()->frame();
       
   438             frm->bridge()->getTypeFromElement(eventNode, elType, elRect);
   432             TPoint nodePoint = n->getRect().Rect().Center();
   439             TPoint nodePoint = n->getRect().Rect().Center();
   433             m_offset = (pt.iX- nodePoint.iX)*(pt.iX- nodePoint.iX) +
   440             m_offset = (pt.iX- nodePoint.iX)*(pt.iX- nodePoint.iX) +
   434                        (pt.iY- nodePoint.iY)*(pt.iY- nodePoint.iY);
   441                        (pt.iY- nodePoint.iY)*(pt.iY- nodePoint.iY);
   435             
   442             
   436             
   443             
   437         }
   444         }
   438     }
   445     }
   439     m_highlightedNode = htresult.innerNode();
   446     m_highlightedNode = eventNode;
   440     if (m_highlightedNode) {
   447     if (m_highlightedNode) {
   441         m_highlightPos = pos;
   448         m_highlightPos = pos;
   442         m_buttonDownEvent.iPosition = m_highlightPos;
   449         m_buttonDownEvent.iPosition = m_highlightPos;
   443     }
   450     }
   444     m_webview->setFocusedElementType(elType);
   451     m_webview->setFocusedElementType(elType);
   489 
   496 
   490      // We assume that if element visibility has been changed  
   497      // We assume that if element visibility has been changed  
   491      // between "up" and "down" that means that some node event 
   498      // between "up" and "down" that means that some node event 
   492      // listener (onMouseOver etc) handling happened and we don't 
   499      // listener (onMouseOver etc) handling happened and we don't 
   493      // want to send a click (mouse press + mouse release) event.
   500      // want to send a click (mouse press + mouse release) event.
   494      if (m_webview->page()->chrome()->client()->elementVisibilityChanged()) {
   501      if (!IS_NAVIGATION_NONE && 
       
   502          m_webview->page()->chrome()->client()->elementVisibilityChanged()) {
   495          return;
   503          return;
   496      }
   504      }
   497 
   505 
   498      m_lastTapEvent.iPosition = m_buttonDownEvent.iPosition;
   506      m_lastTapEvent.iPosition = m_buttonDownEvent.iPosition;
   499      m_lastTapEvent.iType = TPointerEvent::EButton1Up;
   507      m_lastTapEvent.iType = TPointerEvent::EButton1Up;
   500      m_lastTapEvent.iModifiers = 0;
   508      m_lastTapEvent.iModifiers = 0;
   501 
   509 
   502     // don't pass the event if the text input is not in valid format
   510     // don't pass the event if the text input is not in valid format
   503     if (isHighlitableElement(elType) || m_webview->fepTextEditor()->validateTextFormat()) {
   511     if (isHighlitableElement(elType) || m_webview->fepTextEditor()->validateTextFormat()) {
   504         // because of scrolling we delay sending EButton1Down till we get EButton1Up event and if the content is not scrolling
   512         // because of scrolling we delay sending EButton1Down till we get EButton1Up event and if the content is not scrolling
   505         coreFrame->eventHandler()->handleMousePressEvent(PlatformMouseEvent(m_buttonDownEvent));
       
   506         coreFrame->eventHandler()->handleMouseReleaseEvent(PlatformMouseEvent(m_lastTapEvent));
   513         coreFrame->eventHandler()->handleMouseReleaseEvent(PlatformMouseEvent(m_lastTapEvent));
   507     }
   514     }
   508 
   515 
   509     // special handling for broken image (why is this here??)
   516     // special handling for broken image (why is this here??)
   510     if (m_webview->focusedElementType() == TBrCtlDefs::EElementBrokenImage) {
   517     if (m_webview->focusedElementType() == TBrCtlDefs::EElementBrokenImage) {
   529 {
   536 {
   530     // send dehighlight event to engine by passing -1, -1
   537     // send dehighlight event to engine by passing -1, -1
   531     // sending any other pointer value may result in highligh of other links
   538     // sending any other pointer value may result in highligh of other links
   532     m_highlightPos = TPoint(-1, -1);
   539     m_highlightPos = TPoint(-1, -1);
   533     m_isHighlighted = EFalse;
   540     m_isHighlighted = EFalse;
   534     TPointerEvent event;
   541 
   535     event.iType = TPointerEvent::EMove;
       
   536     event.iPosition = m_highlightPos;
       
   537     event.iModifiers = 0;
       
   538 
       
   539     Frame* coreFrame = core(m_webview->mainFrame());
       
   540     Frame* frm = m_webview->page()->focusController()->focusedOrMainFrame();
   542     Frame* frm = m_webview->page()->focusController()->focusedOrMainFrame();
   541     frm->eventHandler()->handleMouseMoveEvent(PlatformMouseEvent(event));
   543     m_webview->sendMouseEventToEngine(TPointerEvent::EMove, m_highlightPos, frm);
   542 
   544 
   543     
   545     
   544     m_highlightedNode = NULL;
   546     m_highlightedNode = NULL;
   545        
   547        
   546     m_webview->syncRepaint();   
   548     m_webview->syncRepaint();   
   586 //-----------------------------------------------------------------------------
   588 //-----------------------------------------------------------------------------
   587 void WebPointerEventHandler::buttonDownTimerCB(Timer<WebPointerEventHandler>* t)
   589 void WebPointerEventHandler::buttonDownTimerCB(Timer<WebPointerEventHandler>* t)
   588 {
   590 {
   589     m_buttonDownTimer.stop();
   591     m_buttonDownTimer.stop();
   590 
   592 
   591     WebCursor*  cursor = StaticObjectsContainer::instance()->webCursor();
       
   592     
   593     
   593     Frame* coreFrame = core(m_webview->mainFrame());
   594     Frame* coreFrame = core(m_webview->mainFrame());
   594     TPointerEvent event;
   595     TPointerEvent event;
   595     
   596     
   596     TBrCtlDefs::TBrCtlElementType elType = highlitableElement();
   597     TBrCtlDefs::TBrCtlElementType elType = highlitableElement();
   598     if (!isHighlitableElement(elType)) {
   599     if (!isHighlitableElement(elType)) {
   599         elType = TBrCtlDefs::EElementNone;
   600         elType = TBrCtlDefs::EElementNone;
   600     }
   601     }
   601     m_isHighlighted = (m_highlightedNode != NULL) && (elType != TBrCtlDefs::EElementNone) ;
   602     m_isHighlighted = (m_highlightedNode != NULL) && (elType != TBrCtlDefs::EElementNone) ;
   602     
   603     
   603     event.iPosition = m_highlightPos;
   604     m_webview->sendMouseEventToEngine(TPointerEvent::EButton1Down, m_highlightPos, coreFrame);
   604     event.iModifiers = 0;
   605 
   605     event.iType = TPointerEvent::EMove;
   606     m_webview->sendMouseEventToEngine(TPointerEvent::EMove, m_highlightPos, coreFrame);
   606 
       
   607     coreFrame->eventHandler()->handleMouseMoveEvent(PlatformMouseEvent(event));
       
   608     m_waiter->AsyncStop();
   607     m_waiter->AsyncStop();
   609 }
   608 }
   610 
   609 
   611 
   610 
   612 //-----------------------------------------------------------------------------
   611 //-----------------------------------------------------------------------------