webengine/osswebengine/WebKit/s60/webview/WebPointerEventHandler.cpp
branchRCL_3
changeset 48 79859ed3eea9
parent 47 e1bea15f9a39
child 49 919f36ff910f
equal deleted inserted replaced
47:e1bea15f9a39 48:79859ed3eea9
     9 * Initial Contributors:
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:
    14 * Description:   
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include <browser_platform_variant.hrh>
    18 #include <Browser_platform_variant.hrh>
    19 #include "config.h"
    19 #include "config.h"
    20 #include "../../bidi.h"
    20 #include "../../bidi.h"
    21 #include <AknUtils.h>
    21 #include <AknUtils.h>
    22 #ifdef BRDO_TOUCH_ENABLED_FF
    22 #ifdef BRDO_TOUCH_ENABLED_FF
    23 #include <touchfeedback.h>
    23 #include <touchfeedback.h>
    24 #endif // BRDO_TOUCH_ENABLED_FF
    24 #endif // BRDO_TOUCH_ENABLED_FF
    25 #include "brctl.h"
    25 #include "BrCtl.h"
    26 #include <brctldefs.h>
    26 #include "BrCtlDefs.h"
    27 #include "WebPointerEventHandler.h"
    27 #include "WebPointerEventHandler.h"
    28 #include "WebView.h"
    28 #include "WebView.h"
    29 #include "WebFrame.h"
    29 #include "WebFrame.h"
    30 #include "WebFrameView.h"
    30 #include "WebFrameView.h"
    31 #include "WebCursor.h"
    31 #include "WebCursor.h"
    32 #include "WebPopupDrawer.h"
    32 #include "WebPopupDrawer.h"
    33 #include "WebFormFillPopup.h"
    33 #include "WebFormFillPopup.h"
    34 #include "WebPageScrollHandler.h"
    34 #include "WebPageScrollHandler.h"
    35 #include "WebFepTextEditor.h"
    35 #include "WebFepTextEditor.h"
       
    36 #include "WebCoreFrameBridge.h"
       
    37 #include "StaticObjectsContainer.h"
    36 #include "PluginSkin.h"
    38 #include "PluginSkin.h"
    37 #include "WebUtil.h"
    39 #include "WebUtil.h"
       
    40 #include "Element.h"
       
    41 #include "Document.h"
       
    42 #include "Frame.h"
       
    43 #include "FrameView.h"
       
    44 #include "EventHandler.h"
       
    45 #include "EventNames.h"
       
    46 #include "HitTestResult.h"
       
    47 #include "MouseEvent.h"
    38 #include "WebPageFullScreenHandler.h"
    48 #include "WebPageFullScreenHandler.h"
       
    49 #include "PluginSkin.h"
    39 #include "PluginWin.h"
    50 #include "PluginWin.h"
    40 #include "WebFrameBridge.h"
    51 #include "WebFrameBridge.h"
    41 #include "Page.h"
    52 #include "Page.h"
    42 #include "Chrome.h"
    53 #include "Chrome.h"
    43 #include "ChromeClient.h"
    54 #include "ChromeClient.h"
    44 #include "FocusController.h"
    55 #include "FocusController.h"
    45 #include "WebTabbedNavigation.h"
    56 #include "WebTabbedNavigation.h"
    46 #include "SettingsContainer.h"
    57 #include "SettingsContainer.h"
    47 #include "PluginHandler.h"
    58 #include "PluginHandler.h"
    48 #include "WebGestureInterface.h"
       
    49 #include "WebPagePinchZoomHandler.h"
       
    50 #include "WebScrollingDeceleratorGH.h"
       
    51 
    59 
    52 #include "WebKitLogger.h"
    60 #include "WebKitLogger.h"
    53 
    61 using namespace WebCore;
       
    62 using namespace EventNames;
       
    63 using namespace RT_GestureHelper;
       
    64 
       
    65 static const int KMinScrollAndTapInterval = 200000;				// 200 ms
       
    66 static const int KDoubleTapMinActivationInterval = 100000;     // 100 ms
       
    67 static const int KDoubleTapMaxActivationInterval = 500000;     // 500 ms
       
    68 static const int KDoubleTapIdleInterval = 700000;			// 700 ms, to prevent triple-tap effects
    54 #define IS_NAVIGATION_NONE      (m_webview->brCtl()->settings()->getNavigationType() == SettingsContainer::NavigationTypeNone)
    69 #define IS_NAVIGATION_NONE      (m_webview->brCtl()->settings()->getNavigationType() == SettingsContainer::NavigationTypeNone)
    55 #define IS_TABBED_NAVIGATION    (m_webview->brCtl()->settings()->getNavigationType() == SettingsContainer::NavigationTypeTabbed)
    70 #define IS_TABBED_NAVIGATION    (m_webview->brCtl()->settings()->getNavigationType() == SettingsContainer::NavigationTypeTabbed)
    56 
    71 
    57 //-----------------------------------------------------------------------------
    72 //-----------------------------------------------------------------------------
    58 // WebPointerEventHandler::NewL
    73 // WebPointerEventHandler::NewL
    71 //-----------------------------------------------------------------------------
    86 //-----------------------------------------------------------------------------
    72 WebPointerEventHandler::WebPointerEventHandler(WebView* view)
    87 WebPointerEventHandler::WebPointerEventHandler(WebView* view)
    73     : m_webview(view),
    88     : m_webview(view),
    74       m_isHighlighted(false),
    89       m_isHighlighted(false),
    75       m_highlightedNode(NULL),
    90       m_highlightedNode(NULL),
    76       m_ignoreTap(false),
    91       m_buttonDownTimer( this, &WebPointerEventHandler::buttonDownTimerCB ),
    77       m_gestureInterface(NULL)
    92       m_ignoreTap(false)
    78 {
    93 {
    79 }
    94 }
    80 
    95 
    81 //-----------------------------------------------------------------------------
    96 //-----------------------------------------------------------------------------
    82 // WebPointerEventHandler::~WebPointerEventHandler
    97 // WebPointerEventHandler::~WebPointerEventHandler
    83 //-----------------------------------------------------------------------------
    98 //-----------------------------------------------------------------------------
    84 WebPointerEventHandler::~WebPointerEventHandler()
    99 WebPointerEventHandler::~WebPointerEventHandler()
    85 {
   100 {
    86    delete m_gestureInterface;
   101     delete m_gestureHelper;
       
   102     delete m_waiter;
    87 }
   103 }
    88 
   104 
    89 //-----------------------------------------------------------------------------
   105 //-----------------------------------------------------------------------------
    90 // WebPointerEventHandler::ConstructL
   106 // WebPointerEventHandler::ConstructL
    91 //-----------------------------------------------------------------------------
   107 //-----------------------------------------------------------------------------
    92 void WebPointerEventHandler::ConstructL()
   108 void WebPointerEventHandler::ConstructL()
    93 {
   109 {
    94 #ifdef BRDO_USE_GESTURE_HELPER
   110 #ifdef BRDO_USE_GESTURE_HELPER  
    95   m_gestureInterface = WebGestureInterface::NewL(m_webview);
   111   m_gestureHelper = CGestureHelper::NewL( *this );
       
   112   m_gestureHelper->SetDoubleTapEnabled(true);
       
   113   m_gestureHelper->SetHoldingEnabled(false);
    96 #else
   114 #else
    97   m_gestureInterface = NULL;
   115   m_gestureHelper = NULL;
    98 #endif
   116 #endif  
    99 }
   117   m_waiter = new(ELeave) CActiveSchedulerWait();
   100 
   118 }
   101 
   119 /**
   102 // ======================================================================
   120  * EGestureStart is sent on touch down
   103 // WebPointerEventHandler::HandleGestureEventL
   121  * EGestureReleased is sent on touch up
   104 // ======================================================================
   122  * EGestureTap = touch down + touch up - events sent: EGestureStart, EGestureTap
   105 void  WebPointerEventHandler::HandleGestureEventL(const TStmGestureEvent& aGesture)
   123  *                EGestureReleased
   106 {
   124  * EGestureDrag = touch down + "move" - events sent: EGestureStart, EGestureDrag
   107     TStmGestureUid uid = aGesture.Code();
   125  * EGestureDoubleTap = 2 * (touch down + touch up) - events sent EGestureStart, 
   108     if (m_webview->pinchZoomHandler()->isPinchActive() && uid != stmGesture::EGestureUidPinch)
   126  *                     EGestureDoubleTap, EGestureReleased
   109         return;
   127  * EGestureLongTap = touch down + "long touch" - events sent: EGestureStart, 
       
   128  *                   EGestureLongTap
       
   129  * EGestureSwipe<Up/Down/Left/Right> - drag + touch up, where movements is
       
   130  *                   close to particular direction - event sent: EGestureSwipe, 
       
   131  *                   EGestureReleased
       
   132  * EGestureFlick - "fast" drag + touch up - events sent: EGestureFlick, 
       
   133  *                  EGestureReleased
       
   134  * EGestureDrop -  drag + touch up, !(EGestureSwipe || EGestureFlick) - events
       
   135  *                 sent: EGestureDrop, EGestureReleased
       
   136  */
       
   137 void WebPointerEventHandler::HandleGestureL( const TGestureEvent& aEvent )
       
   138 {
       
   139     TGestureCode gtype = aEvent.Code(EAxisBoth);
       
   140     TPoint gpos = aEvent.CurrentPos();
   110     
   141     
   111     TBrCtlDefs::TBrCtlElementType elType = m_webview->focusedElementType();
   142     TBrCtlDefs::TBrCtlElementType elType = m_webview->focusedElementType();
   112     
   143     
   113     bool pluginConsumable = isPluginConsumable(uid);
   144     PluginSkin* plugin = m_webview->mainFrame()->focusedPlugin();
   114     PluginHandler* pluginHandler = StaticObjectsContainer::instance()->pluginHandler();
   145     if (plugin && plugin->pluginWin()) {
   115     
   146       if (plugin->pluginWin()->HandleGesture(aEvent)) {
   116     if (pluginConsumable && pluginHandler->getVisiblePlugins().Count() > 0) {
   147           return;
   117         for ( int i=0; i < pluginHandler->getVisiblePlugins().Count(); i++) {
   148       }
   118              PluginSkin* plugin = pluginHandler->getVisiblePlugins()[i];
   149     }
   119              if (plugin && plugin->pluginWin() && plugin->pluginWin()->containsPoint(*m_webview,aGesture.CurrentPos())) {
   150     updateCursor(aEvent.CurrentPos());
   120                  if (plugin->pluginWin()->HandleGesture(aGesture)) {
       
   121                      // Above call can end up in the deletion of the plugin, so check if the plugin is still alive
       
   122                      if (pluginHandler->getVisiblePlugins().Find(plugin) != KErrNotFound) {
       
   123                          if(!plugin->isActive()) {
       
   124                              plugin->activate();
       
   125                          }
       
   126                          else {
       
   127                              m_webview->mainFrame()->frameView()->topView()->setFocusedElementType(TBrCtlDefs::EElementActivatedObjectBox);
       
   128                              m_webview->page()->focusController()->setFocusedNode(plugin->getElement(), m_webview->page()->focusController()->focusedOrMainFrame());                        
       
   129                              m_webview->brCtl()->updateDefaultSoftkeys();
       
   130                          }
       
   131                      }
       
   132                      return;
       
   133                  }
       
   134                  break;
       
   135              }
       
   136         }
       
   137     }
       
   138 
       
   139     updateCursor(aGesture.CurrentPos());
       
   140     if (IS_TABBED_NAVIGATION) {
   151     if (IS_TABBED_NAVIGATION) {
   141         m_webview->tabbedNavigation()->updateCursorPosition(aGesture.CurrentPos());
   152         m_webview->tabbedNavigation()->updateCursorPosition(m_highlightPos);
   142     }
   153     }
   143 
   154     switch (gtype) {
   144     switch(uid) {
   155       // sent on touch down
   145         case stmGesture::EGestureUidTouch:
   156       case EGestureStart:  
   146         {
   157       {
   147             if (m_webview->viewIsScrolling()) {
   158           if (m_webview->viewIsScrolling()) {
   148                 m_ignoreTap = true;
   159               m_ignoreTap = true;
   149                 m_webview->pageScrollHandler()->handleTouchDownGH(aGesture);
   160               m_webview->pageScrollHandler()->handleTouchDownGH(aEvent);
   150             }
   161           }
   151             else {
   162           else {
   152                 handleTouchDownL(aGesture);
   163               handleTouchDownL(aEvent);   
   153             }
   164           }
   154             break;
   165           break;
   155         }
   166       }
   156 
   167       
   157 
   168       // sent on tap
   158         case stmGesture::EGestureUidTap:
   169       case EGestureTap:
   159         {
   170       {
   160             if (aGesture.Type() == stmGesture::ETapTypeSingle) {
   171           if (!m_ignoreTap) {
   161                 if (!m_ignoreTap) {
   172               handleTapL(aEvent);
   162                     handleTapL(aGesture);
   173           }
   163                 }
   174           break;    
   164             }
   175       }
   165             else {
   176       
   166                 handleDoubleTap(aGesture);
   177       // sent on double tap
   167             }
   178       case EGestureDoubleTap:
   168 
   179       {
   169                 break;
   180           handleDoubleTap(aEvent);
   170         }
   181           break;    
   171 
   182       }
   172         case stmGesture::EGestureUidRelease:
   183       
   173         {
   184       // sent on long tap
   174             m_ignoreTap = false;
   185       case EGestureLongTap:
   175             handleTouchUp(aGesture);
   186       {
   176 			m_webview->resumeJsTimers(); // resume js timers
   187           break;    
   177 			m_webview->setViewIsScrolling(false); 
   188       }
   178             break;
   189 
   179         }
   190       // sent on touch up after drag
   180 
   191       case EGestureDrop:
   181         case stmGesture::EGestureUidPan:
   192       case EGestureFlick:
   182         {
   193       case EGestureSwipeLeft:
   183             // pause js timers (if not already done)
   194       case EGestureSwipeRight:
   184             if(!m_webview->jsTimersPaused()) 
   195       case EGestureSwipeUp:
   185                 m_webview->pauseJsTimers();
   196       case EGestureSwipeDown:
   186 
   197       {
   187             handleMove(aGesture);
   198           m_ignoreTap = false;
   188             break;
   199           if (!IS_NAVIGATION_NONE) {
   189         }
   200               handleTouchUp(aEvent);
   190         case stmGesture::EGestureUidFlick:
   201           }
   191         {
   202           else {
   192             m_ignoreTap = false;
   203               Frame* frm = m_webview->page()->focusController()->focusedOrMainFrame();
   193             if (!IS_NAVIGATION_NONE) {
   204               m_webview->sendMouseEventToEngine(TPointerEvent::EButton1Up, m_highlightPos, frm);
   194                 handleTouchUp(aGesture);
   205           }
   195             }
   206           break;    
   196             else {
   207       }
   197                 Frame* frm = m_webview->page()->focusController()->focusedOrMainFrame();
   208       // sent on move
   198                 m_webview->sendMouseEventToEngine(TPointerEvent::EButton1Up, m_highlightPos, frm);
   209       case EGestureDrag:
   199             }
   210       {
   200             break;
   211           handleMove(aEvent);
   201         }
   212           break;    
   202 
   213       }
   203         case stmGesture::EGestureUidPinch:
   214       
   204         {
   215       // sent on touch up after tap double tap and long tap
   205         if (m_webview->viewIsScrolling()) {
   216       case EGestureReleased:
   206             m_webview->pageScrollHandler()->stopScrolling();
   217       {
   207         }
   218           m_ignoreTap = false;
   208         if(!m_webview->inPageViewMode())
   219           handleTouchUp(aEvent);      
   209             {
   220           break;    
   210             handlePinchZoomL(aGesture);
   221       }
   211             if(aGesture.GestureState() != EGestureEnter) {
   222     }
   212                 m_webview->resumeJsTimers(); // resume js timers
       
   213                 }
       
   214             }
       
   215             break;
       
   216         }
       
   217         default:
       
   218             break;
       
   219 
       
   220     }
       
   221     return;
       
   222 }
   223 }
   223 
   224 
   224 
   225 
   225 // ======================================================================
   226 // ======================================================================
   226 // WebPointerEventHandler::handleTap
   227 // WebPointerEventHandler::handleTap
   227 // ======================================================================
   228 // ======================================================================
   228 void WebPointerEventHandler::handleTapL(const TStmGestureEvent& aGesture)
   229 void WebPointerEventHandler::handleTapL(const TGestureEvent& aEvent)
   229 {
   230 {
   230     m_lastTapEvent = m_currentEvent;
   231     m_buttonDownTimer.stop();
       
   232     m_lastTapEvent = m_currentEvent; 
   231     if(!m_webview->inPageViewMode()){
   233     if(!m_webview->inPageViewMode()){
   232     	doTapL();
   234     	doTapL();
   233     }
   235     }
   234 }
   236 }
   235 // ======================================================================
   237 // ======================================================================
   236 //  WebPointerEventHandler::handleDoubleTap
   238 //  WebPointerEventHandler::handleDoubleTap
   237 //======================================================================
   239 //======================================================================
   238 void WebPointerEventHandler::handleDoubleTap(const TStmGestureEvent& aGesture)
   240 void WebPointerEventHandler::handleDoubleTap(const TGestureEvent& aEvent)
   239 {
   241 {
   240     if ( !m_webview->viewIsScrolling() &&
   242     if ( !m_webview->viewIsScrolling() &&
   241          (m_webview->brCtl()->capabilities() & TBrCtlDefs::ECapabilityFitToScreen)) {
   243          (m_webview->brCtl()->capabilities() & TBrCtlDefs::ECapabilityFitToScreen)) {
   242         if (m_isHighlighted){
   244         if (m_isHighlighted){
   243             dehighlight();
   245             dehighlight();                
   244         }
   246         }
   245         m_webview->setZoomLevelAdaptively();
   247         m_webview->setZoomLevelAdaptively();
   246     }
   248     }
   247     else {
   249     else {
   248         m_webview->resetLastZoomLevelIfNeeded();
   250         m_webview->resetLastZoomLevelIfNeeded();
   250 }
   252 }
   251 
   253 
   252 // ======================================================================
   254 // ======================================================================
   253 // WebPointerEventHandler::handleTouchDownL
   255 // WebPointerEventHandler::handleTouchDownL
   254 //======================================================================
   256 //======================================================================
   255 void WebPointerEventHandler::handleTouchDownL(const TStmGestureEvent& aGesture)
   257 void WebPointerEventHandler::handleTouchDownL(const TGestureEvent& aEvent)
   256 {
   258 {
   257     TBrCtlDefs::TBrCtlElementType elType = m_webview->focusedElementType();
   259     TBrCtlDefs::TBrCtlElementType elType = m_webview->focusedElementType();
   258     PluginHandler* pluginHandler = WebCore::StaticObjectsContainer::instance()->pluginHandler();
   260     PluginHandler* pluginHandler = WebCore::StaticObjectsContainer::instance()->pluginHandler();
   259     PluginSkin* pluginToActivate = pluginHandler->pluginToActivate();
   261     PluginSkin* pluginToActivate = pluginHandler->pluginToActivate();
   260     m_buttonDownEvent = m_currentEvent;
   262     m_buttonDownEvent = m_currentEvent;
   261     m_highlightPos = aGesture.CurrentPos();
   263     m_highlightPos = aEvent.CurrentPos();
   262 
   264     
       
   265     if ( !m_buttonDownTimer.isActive() && !m_webview->inPageViewMode()){
       
   266         m_buttonDownTimer.startOneShot(0.1f);        
       
   267     }
   263 
   268 
   264     if (!IS_NAVIGATION_NONE) {
   269     if (!IS_NAVIGATION_NONE) {
   265         m_webview->pageScrollHandler()->handleTouchDownGH(aGesture);
   270         m_webview->pageScrollHandler()->handleTouchDownGH(aEvent);
   266     }
   271     }
   267 
   272 
   268     if ( TBrCtlDefs::EElementActivatedObjectBox == elType) {
   273     if ( TBrCtlDefs::EElementActivatedObjectBox == elType) {
   269         PluginSkin* plugin = m_webview->mainFrame()->focusedPlugin();
   274         PluginSkin* plugin = m_webview->mainFrame()->focusedPlugin();
   270         if (plugin && plugin->pluginWin()) {
   275         if (plugin && plugin->pluginWin()) {
   275                 plugin->pluginWin()->HandlePointerEventL(m_buttonDownEvent);
   280                 plugin->pluginWin()->HandlePointerEventL(m_buttonDownEvent);
   276             }
   281             }
   277         }
   282         }
   278     }
   283     }
   279     
   284     
   280     doTouchDownL();
   285     /*
   281 }
   286      * After introducing "link selection" pointer down action is done in 
   282 
   287      * buttondown timer callback. When "down" gesture event is arrived we start 
   283 // ======================================================================
   288      * timer end exit, so gesture helper is ready to deliver next gesture event. 
   284 // WebPointerEventHandler::handleTouchUp
   289      * Meanwhile the processing of the first gesture event hasn't been finished yet. 
   285 // ======================================================================
   290      * The gesture helper doesn't "know" about our plans to handle the event inside 
   286 void WebPointerEventHandler::handleTouchUp(const TStmGestureEvent& aGesture)
   291      * timer callback and only way for us to "tell" about this is to stop RunL() 
       
   292      * of CGestureEventSender (HandleGestureL() is inside it) and finish buttondown 
       
   293      * timer callback first.  
       
   294      */    
       
   295     if ( m_buttonDownTimer.isActive()){
       
   296     	m_waiter->Start();	
       
   297     }
       
   298 }
       
   299 
       
   300 // ======================================================================
       
   301 // WebPointerEventHandler::handleTouchUp 
       
   302 // ======================================================================
       
   303 void WebPointerEventHandler::handleTouchUp(const TGestureEvent& aEvent)
   287 {
   304 {
   288     m_highlightPos = TPoint(-1,-1);
   305     m_highlightPos = TPoint(-1,-1);
   289     m_highlightedNode = NULL;
   306     m_highlightedNode = NULL;
   290     PluginHandler* pluginHandler = WebCore::StaticObjectsContainer::instance()->pluginHandler();
   307     PluginHandler* pluginHandler = WebCore::StaticObjectsContainer::instance()->pluginHandler();
   291     pluginHandler->setPluginToActivate(NULL);
   308     pluginHandler->setPluginToActivate(NULL);
   292     if (!IS_NAVIGATION_NONE) {
   309     if (!IS_NAVIGATION_NONE) {
   293         m_webview->pageScrollHandler()->handleTouchUpGH(aGesture);
   310         m_webview->pageScrollHandler()->handleTouchUpGH(aEvent);
   294     }
   311     }
   295 }
   312 }
   296 
   313 
   297 // ======================================================================
   314 // ======================================================================
   298 // WebPointerEventHandler::handleMoveL
   315 // WebPointerEventHandler::handleMoveL
   299 // ======================================================================
   316 // ======================================================================
   300 void WebPointerEventHandler::handleMove(const TStmGestureEvent& aGesture)
   317 void WebPointerEventHandler::handleMove(const TGestureEvent& aEvent)
   301 {
   318 {
   302     TBrCtlDefs::TBrCtlElementType elType = m_webview->focusedElementType();
   319     TBrCtlDefs::TBrCtlElementType elType = m_webview->focusedElementType();
   303     TPoint curPos =  aGesture.CurrentPos();
   320     TPoint curPos = aEvent.CurrentPos();
   304     PluginHandler* pluginHandler = WebCore::StaticObjectsContainer::instance()->pluginHandler();
   321     PluginHandler* pluginHandler = WebCore::StaticObjectsContainer::instance()->pluginHandler();
   305     pluginHandler->setPluginToActivate(NULL);
   322     pluginHandler->setPluginToActivate(NULL);
   306 
   323     m_buttonDownTimer.stop();
   307     if (IS_NAVIGATION_NONE) {
   324     if (IS_NAVIGATION_NONE) {
   308         Frame* frm = m_webview->page()->focusController()->focusedOrMainFrame();
   325         Frame* frm = m_webview->page()->focusController()->focusedOrMainFrame();
   309         m_webview->sendMouseEventToEngine(TPointerEvent::EMove, curPos, frm);
   326         m_webview->sendMouseEventToEngine(TPointerEvent::EMove, curPos, frm);
   310     }
   327     }
   311     else {
   328     else {
   312     HandleHighlightChange(curPos);
   329     HandleHighlightChange(curPos);
   313 
   330     
   314     m_webview->pageScrollHandler()->handleScrollingGH(aGesture);
   331     m_webview->pageScrollHandler()->handleScrollingGH(aEvent);
   315     }
   332     }
   316 }
   333 }
   317 
   334 
   318 
   335 
   319 // ======================================================================
   336 // ======================================================================
   320 // WebPointerEventHandler::HandlePointerEventL
   337 // WebPointerEventHandler::HandlePointerEventL
   321 // ======================================================================
   338 // ======================================================================
   322 void WebPointerEventHandler::HandlePointerEventL(const TPointerEvent& aPointerEvent)
   339 void WebPointerEventHandler::HandlePointerEventL(const TPointerEvent& aPointerEvent)
   323 {
   340 {
   324     m_currentEvent = aPointerEvent;
   341     m_currentEvent = aPointerEvent;
   325 
   342     
   326     if (m_webview->isSynchRequestPending()) {
   343     if (m_webview->isSynchRequestPending()) { 
   327        return;
   344        return;
   328     }
   345     }
   329 
   346     
   330     // Handle graphical history - should never happen, as HistoryView handles this event by itself
   347     // Handle graphical history - should never happen, as HistoryView handles this event by itself
   331     if ( m_webview->brCtl()->historyHandler()->historyController()->historyView()) {
   348     if ( m_webview->brCtl()->historyHandler()->historyController()->historyView()) {
   332         return;
   349         return;
   333     }
   350     }
   334 
   351 
   336     if (m_webview->formFillPopup() && m_webview->formFillPopup()->IsVisible()) {
   353     if (m_webview->formFillPopup() && m_webview->formFillPopup()->IsVisible()) {
   337         m_webview->formFillPopup()->HandlePointerEventL(aPointerEvent);
   354         m_webview->formFillPopup()->HandlePointerEventL(aPointerEvent);
   338         return;
   355         return;
   339     }
   356     }
   340     
   357     
   341     //if scrolling is going on, it need to be stopped immediately when user touches down    
   358     if (!m_webview->inPageViewMode()) {
   342     if (aPointerEvent.iType == TPointerEvent::EButton1Down && m_webview->viewIsScrolling()) {
   359         if (aPointerEvent.iType == TPointerEvent::EButton1Down) {
   343         WebScrollingDeceleratorGH* scrollDecelGH = m_webview->pageScrollHandler()->ScrollingDeceleratorGH();
   360             m_webview->GetContainerWindow().EnablePointerMoveBuffer();
   344         if(scrollDecelGH) {
   361         }
   345             scrollDecelGH->cancelDecel();            
   362         else if (aPointerEvent.iType == TPointerEvent::EButton1Up) {
   346         }
   363             m_webview->GetContainerWindow().DisablePointerMoveBuffer();
   347     }
   364         }
   348     
   365     }
   349     // pause JS timers for better ui response    
   366 
   350     if (aPointerEvent.iType == TPointerEvent::EButton1Down) {
       
   351         m_webview->pauseJsTimers();    
       
   352     }
       
   353 #ifdef BRDO_USE_GESTURE_HELPER
   367 #ifdef BRDO_USE_GESTURE_HELPER
   354       m_gestureInterface->HandlePointerEventL(aPointerEvent);
   368     m_gestureHelper->HandlePointerEventL(aPointerEvent);
   355 #endif
   369 #endif    
   356 }
   370 }
   357 
   371 
   358 //-----------------------------------------------------------------------------
   372 //-----------------------------------------------------------------------------
   359 // WebPointerEventHandler::HandleHighlightChange
   373 // WebPointerEventHandler::HandleHighlightChange
   360 //-----------------------------------------------------------------------------
   374 //-----------------------------------------------------------------------------
   364 
   378 
   365     if (!canDehighlight(aPoint)) return;
   379     if (!canDehighlight(aPoint)) return;
   366 
   380 
   367     dehighlight();
   381     dehighlight();
   368 }
   382 }
       
   383 
       
   384 //-----------------------------------------------------------------------------
       
   385 // WebPointerEventHandler::checkForEventListener
       
   386 //-----------------------------------------------------------------------------
       
   387 bool WebPointerEventHandler::checkForEventListener(WebCore::Node* node)
       
   388 {
       
   389     EventTargetNode* etnfound = NULL;
       
   390     for (Node* np = node; np; np = np->parentNode()) {
       
   391         //check for a mouseover event listener
       
   392         if (np->isEventTargetNode()) {
       
   393             if (m_webview->page()->chrome()->client()->elementVisibilityChanged()) {
       
   394                 return true;
       
   395             }
       
   396         }
       
   397     }
       
   398     return false;
       
   399 }
       
   400 
   369 
   401 
   370 //-----------------------------------------------------------------------------
   402 //-----------------------------------------------------------------------------
   371 // WebPointerEventHandler::highlitableElement
   403 // WebPointerEventHandler::highlitableElement
   372 //-----------------------------------------------------------------------------
   404 //-----------------------------------------------------------------------------
   373 TBrCtlDefs::TBrCtlElementType WebPointerEventHandler::highlitableElement()
   405 TBrCtlDefs::TBrCtlElementType WebPointerEventHandler::highlitableElement()
   374 {
   406 {
   375     TRect elRect;
   407     TRect elRect;
   376     TBrCtlDefs::TBrCtlElementType elType = TBrCtlDefs::EElementNone;
   408     TBrCtlDefs::TBrCtlElementType elType = TBrCtlDefs::EElementNone;
   377     Frame* coreFrame = core(m_webview->mainFrame());
   409     Frame* coreFrame = core(m_webview->mainFrame());
   378     WebCursor* cursor = StaticObjectsContainer::instance()->webCursor();
   410     WebCursor* cursor = StaticObjectsContainer::instance()->webCursor();
   379 
   411     
   380     TPointerEvent event;
   412     TPointerEvent event;
   381     TPoint pos = cursor->position();
   413     TPoint pos = cursor->position();
   382     WebFrame* wfrm = cursor->getFrameAtPoint(pos);
   414     WebFrame* wfrm = cursor->getFrameAtPoint(pos);
   383     Frame* frm = core(wfrm);
   415     Frame* frm = core(wfrm);
   384     TPoint pt(wfrm->frameView()->viewCoordsInFrameCoords(pos));
   416     TPoint pt(wfrm->frameView()->viewCoordsInFrameCoords(pos));
   385     TPoint nodePoint;
   417     TPoint nodePoint;
   386 
   418     
   387     Element* eventNode = frm->document()->elementFromPoint(pt.iX, pt.iY);
   419     Element* eventNode = frm->document()->elementFromPoint(pos.iX, pos.iY);
   388 
   420     
   389     m_highlightedNode = NULL;
   421     m_highlightedNode = NULL;
   390 
   422 
   391     Node* retNode = 0;
   423     Node* retNode = 0;
   392     frm->bridge()->getTypeFromElement(eventNode, elType, elRect, retNode);
   424     frm->bridge()->getTypeFromElement(eventNode, elType, elRect, retNode);
   393 
   425 
   394     if (elType == TBrCtlDefs::EElementNone) {
   426     if (elType == TBrCtlDefs::EElementNone) {
   395         Node* n = wfrm->getClosestAnchorElement(cursor->position(), pos);
   427         Node* n = wfrm->getClosestAnchorElement(cursor->position(), pos);
   396         if (n) {
   428         if (n) {          
   397             wfrm = cursor->getFrameAtPoint(pos);
   429             wfrm = cursor->getFrameAtPoint(pos);
   398             frm = core(wfrm);
   430             frm = core(wfrm);
   399             //eventNode = frm->document()->elementFromPoint(pos.iX, pos.iY);
   431             eventNode = frm->document()->elementFromPoint(pos.iX, pos.iY);
   400             TPoint newPos(wfrm->frameView()->viewCoordsInFrameCoords(pos));
       
   401             eventNode = frm->document()->elementFromPoint(newPos.iX, newPos.iY);
       
   402             frm->bridge()->getTypeFromElement(eventNode, elType, elRect, retNode);
   432             frm->bridge()->getTypeFromElement(eventNode, elType, elRect, retNode);
   403             TPoint nodePoint = n->getRect().Rect().Center();
   433             TPoint nodePoint = n->getRect().Rect().Center();
   404             m_offset = (pt.iX- nodePoint.iX)*(pt.iX- nodePoint.iX) +
   434             m_offset = (pt.iX- nodePoint.iX)*(pt.iX- nodePoint.iX) +
   405                        (pt.iY- nodePoint.iY)*(pt.iY- nodePoint.iY);
   435                        (pt.iY- nodePoint.iY)*(pt.iY- nodePoint.iY);
   406         }
   436         }
   441 //-----------------------------------------------------------------------------
   471 //-----------------------------------------------------------------------------
   442 void WebPointerEventHandler::doTapL()
   472 void WebPointerEventHandler::doTapL()
   443 {
   473 {
   444     TBrCtlDefs::TBrCtlElementType elType = m_webview->focusedElementType();
   474     TBrCtlDefs::TBrCtlElementType elType = m_webview->focusedElementType();
   445     Frame* coreFrame = core(m_webview->mainFrame());
   475     Frame* coreFrame = core(m_webview->mainFrame());
   446 
   476     
   447 #ifdef BRDO_TOUCH_ENABLED_FF
   477 #ifdef BRDO_TOUCH_ENABLED_FF
   448     if (m_isHighlighted)
   478     if (m_isHighlighted)
   449     {
   479     {
   450         MTouchFeedback* feedback = MTouchFeedback::Instance();
   480         MTouchFeedback* feedback = MTouchFeedback::Instance();
   451         if (feedback)
   481         if (feedback)
   454            }
   484            }
   455     }
   485     }
   456 #endif // BRDO_TOUCH_ENABLED_FF
   486 #endif // BRDO_TOUCH_ENABLED_FF
   457     
   487     
   458      /*
   488      /*
   459       * We assume that if element visibility has been changed
   489       * We assume that if element visibility has been changed  
   460       * between "up" and "down" that means that some node event
   490       * between "up" and "down" that means that some node event 
   461       * listener (onMouseOver etc) handling happened and we don't
   491       * listener (onMouseOver etc) handling happened and we don't 
   462       * want to send a click (mouse press + mouse release) event.
   492       * want to send a click (mouse press = mouse release) event.
   463       * The exception is editable element, since we want VKB anyway
   493       * The exception is editable element, since we want VKB anyway
   464       */
   494       */
   465      if (!IS_NAVIGATION_NONE &&
   495      if (!IS_NAVIGATION_NONE &&
   466          elType != TBrCtlDefs::EElementActivatedInputBox &&
   496          elType != TBrCtlDefs::EElementActivatedInputBox && 
   467          elType != TBrCtlDefs::EElementTextAreaBox &&
   497          elType != TBrCtlDefs::EElementTextAreaBox &&     
   468          m_webview->page()->chrome()->client()->elementVisibilityChangedByMouse()) {
   498          m_webview->page()->chrome()->client()->elementVisibilityChangedByMouse()) {
   469          return;
   499          return;
   470      }
   500      }
   471 
   501 
   472      m_lastTapEvent.iPosition = m_buttonDownEvent.iPosition;
   502      m_lastTapEvent.iPosition = m_buttonDownEvent.iPosition;
   473      m_lastTapEvent.iType = TPointerEvent::EButton1Up;
   503      m_lastTapEvent.iType = TPointerEvent::EButton1Up;
   474      m_lastTapEvent.iModifiers = 0;
   504      m_lastTapEvent.iModifiers = 0;
   475 
   505 
   476      m_webview->fepTextEditor()->validateTextFormat();
   506     // don't pass the event if the text input is not in valid format
   477      
   507     if (isHighlitableElement(elType) || m_webview->fepTextEditor()->validateTextFormat()) {
   478      if (!IS_NAVIGATION_NONE) {
   508         m_webview->sendMouseEventToEngine(TPointerEvent::EButton1Up,  m_lastTapEvent.iPosition, coreFrame);
   479          // in case of navigation none button down was sent in buttonDownTimerCB()
   509     }
   480          m_webview->sendMouseEventToEngine(TPointerEvent::EButton1Down, m_highlightPos, coreFrame);
       
   481      }
       
   482      m_webview->sendMouseEventToEngine(TPointerEvent::EButton1Up,  m_highlightPos, coreFrame);
       
   483 
   510 
   484     // special handling for broken image (why is this here??)
   511     // special handling for broken image (why is this here??)
   485     if (elType == TBrCtlDefs::EElementBrokenImage) {
   512     if (elType == TBrCtlDefs::EElementBrokenImage) {
   486         loadFocusedImage(m_webview);
   513         loadFocusedImage(m_webview);
   487     }
   514     }
   508     m_isHighlighted = EFalse;
   535     m_isHighlighted = EFalse;
   509 
   536 
   510     Frame* frm = m_webview->page()->focusController()->focusedOrMainFrame();
   537     Frame* frm = m_webview->page()->focusController()->focusedOrMainFrame();
   511     m_webview->sendMouseEventToEngine(TPointerEvent::EMove, m_highlightPos, frm);
   538     m_webview->sendMouseEventToEngine(TPointerEvent::EMove, m_highlightPos, frm);
   512 
   539 
       
   540     
   513     m_highlightedNode = NULL;
   541     m_highlightedNode = NULL;
   514 
   542        
   515     m_webview->syncRepaint();
   543     m_webview->syncRepaint();   
   516 }
   544 }
   517 
   545 
   518 
   546 
   519 //-----------------------------------------------------------------------------
   547 //-----------------------------------------------------------------------------
   520 // WebPointerEventHandler::canDehighlight
   548 // WebPointerEventHandler::canDehighlight
   551 
   579 
   552 
   580 
   553 //-----------------------------------------------------------------------------
   581 //-----------------------------------------------------------------------------
   554 // WebPointerEventHandler::buttonDownTimerCallback
   582 // WebPointerEventHandler::buttonDownTimerCallback
   555 //-----------------------------------------------------------------------------
   583 //-----------------------------------------------------------------------------
   556 void WebPointerEventHandler::doTouchDownL()
   584 void WebPointerEventHandler::buttonDownTimerCB(Timer<WebPointerEventHandler>* t)
   557 {
   585 {
       
   586     m_buttonDownTimer.stop();
       
   587 
       
   588     
   558     Frame* coreFrame = core(m_webview->mainFrame());
   589     Frame* coreFrame = core(m_webview->mainFrame());
   559     TPointerEvent event;
   590     TPointerEvent event;
   560     
   591     
   561     TBrCtlDefs::TBrCtlElementType elType = highlitableElement();
   592     TBrCtlDefs::TBrCtlElementType elType = highlitableElement();
   562 
   593     
   563     if (!isHighlitableElement(elType)) {
   594     if (!isHighlitableElement(elType)) {
   564         elType = TBrCtlDefs::EElementNone;
   595         elType = TBrCtlDefs::EElementNone;
   565     }
   596     }
   566     m_isHighlighted = (m_highlightedNode != NULL) && (elType != TBrCtlDefs::EElementNone) ;
   597     m_isHighlighted = (m_highlightedNode != NULL) && (elType != TBrCtlDefs::EElementNone) ;
       
   598     
   567     m_webview->page()->chrome()->client()->setElementVisibilityChanged(false);
   599     m_webview->page()->chrome()->client()->setElementVisibilityChanged(false);
   568     
   600     
   569     /*
   601     /*
   570      * Tabbed navigation might already set the focused node.
   602      * Tabbed navigation might already set the focused node.
   571      * If it's the same as m_highlightedNode FocuseController::setFocusedNode()
   603      * If it's the same as m_highlightedNode FocuseController::setFocusedNode()
   572      * wouldn't do anything and setEditable won't be called.
   604      * wouldn't do anything and setEditable won't be called.
   573      * So we are setting focused node to NULL here and let mouse event handler
   605      * So we are setting focused node to NULL here and let mouse event handler
   574      * set it through FocuseController::setFocusedNode()
   606      * set it through ocuseController::setFocusedNode()
   575      */
   607      */
   576     if (IS_TABBED_NAVIGATION &&
   608     if (IS_TABBED_NAVIGATION &&
   577        (elType == TBrCtlDefs::EElementInputBox || elType == TBrCtlDefs::EElementTextAreaBox)) {
   609         elType == TBrCtlDefs::EElementInputBox || 
   578            coreFrame->document()->setFocusedNode(NULL);
   610         elType == TBrCtlDefs::EElementTextAreaBox) {
   579     }
   611         coreFrame->document()->setFocusedNode(NULL);
   580 
   612     }
   581     if (!IS_NAVIGATION_NONE) {
   613          
   582 		m_webview->sendMouseEventToEngine(TPointerEvent::EMove, m_highlightPos, coreFrame);
   614     m_webview->sendMouseEventToEngine(TPointerEvent::EButton1Down, m_highlightPos, coreFrame);
   583     } 
   615 
   584     else {
   616     m_webview->sendMouseEventToEngine(TPointerEvent::EMove, m_highlightPos, coreFrame);
   585         m_webview->sendMouseEventToEngine(TPointerEvent::EButton1Down, m_highlightPos, coreFrame);
   617     m_waiter->AsyncStop();
   586     }
       
   587 
       
   588 }
   618 }
   589 
   619 
   590 
   620 
   591 //-----------------------------------------------------------------------------
   621 //-----------------------------------------------------------------------------
   592 // WebPointerEventHandler::updateCursor
   622 // WebPointerEventHandler::updateCursor
   599             cursor->setPosition(pos);
   629             cursor->setPosition(pos);
   600         }
   630         }
   601         if (m_webview->showCursor()) {
   631         if (m_webview->showCursor()) {
   602             cursor->resetTransparency();
   632             cursor->resetTransparency();
   603             m_webview->setShowCursor(false);
   633             m_webview->setShowCursor(false);
   604             cursor->cursorUpdate(false);
   634             cursor->cursorUpdate(false); 
   605         }
   635         }
   606     }
   636     }
   607 }
   637 }
   608 
       
   609 
       
   610 //-----------------------------------------------------------------------------
       
   611 // WebPointerEventHandler::handlePinchZoom
       
   612 //----------------------------------------------------------------------------
       
   613 void  WebPointerEventHandler::handlePinchZoomL(const TStmGestureEvent& aGesture)
       
   614 {
       
   615  //dehighlight anything which is highlighted already
       
   616     if (m_isHighlighted){
       
   617         dehighlight();
       
   618     }
       
   619     m_webview->pinchZoomHandler()->handlePinchGestureEventL(aGesture);
       
   620 }
       
   621 
       
   622 
       
   623 //-----------------------------------------------------------------------------
       
   624 // WebPointerEventHandler::isPluginConsumable
       
   625 //-----------------------------------------------------------------------------
       
   626 bool WebPointerEventHandler::isPluginConsumable(const TStmGestureUid uid)
       
   627 {
       
   628     //  Gestures which a Plugin can consume
       
   629     return ( uid == stmGesture::EGestureUidRelease ||
       
   630              uid == stmGesture::EGestureUidTap ||
       
   631              uid == stmGesture::EGestureUidTouch ||
       
   632              uid == stmGesture::EGestureUidLongPress ||
       
   633              (uid == stmGesture::EGestureUidPan && m_webview->widgetExtension()) ||     // Currently Pan is consumed in Widget mode
       
   634              (uid == stmGesture::EGestureUidFlick && m_webview->widgetExtension())
       
   635            ); 
       
   636 }