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