ginebra2/WebGestureHelper.cpp
changeset 5 0f2326c2a325
parent 0 1450b09d0cfd
child 16 3c88a81ff781
equal deleted inserted replaced
1:b0dd75e285d2 5:0f2326c2a325
     1 /*
     1 /*
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 *
     5 * under the terms of "Eclipse Public License v1.0"
     5 * This program is free software: you can redistribute it and/or modify
     6 * which accompanies this distribution, and is available
     6 * it under the terms of the GNU Lesser General Public License as published by
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * the Free Software Foundation, version 2.1 of the License.
     8 *
     8 *
     9 * Initial Contributors:
     9 * This program is distributed in the hope that it will be useful,
    10 * Nokia Corporation - initial contribution.
    10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11 *
    11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12 * Contributors:
    12 * GNU Lesser General Public License for more details.
    13 *
    13 *
    14 * Description: 
    14 * You should have received a copy of the GNU Lesser General Public License
       
    15 * along with this program.  If not,
       
    16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
       
    17 *
       
    18 * Description:
    15 *
    19 *
    16 */
    20 */
    17 
       
    18 #include <QDesktopWidget>
    21 #include <QDesktopWidget>
    19 #include <QGraphicsView>
    22 #include <QGraphicsView>
    20 #include <QGraphicsItem>
    23 #include <QGraphicsItem>
    21 
    24 
    22 #include "WebGestureHelper.h"
    25 #include "WebGestureHelper.h"
    30 #define ENABLE_GESTURE_LIB 1
    33 #define ENABLE_GESTURE_LIB 1
    31 
    34 
    32 
    35 
    33 WebGestureHelperEventFilter* WebGestureHelperEventFilter::m_instance = 0;
    36 WebGestureHelperEventFilter* WebGestureHelperEventFilter::m_instance = 0;
    34 
    37 
    35 WebGestureHelperEventFilter* WebGestureHelperEventFilter::instance() 
    38 WebGestureHelperEventFilter* WebGestureHelperEventFilter::instance()
    36 { 
    39 {
    37     if (!m_instance) {
    40     if (!m_instance) {
    38         m_instance = new WebGestureHelperEventFilter();
    41         m_instance = new WebGestureHelperEventFilter();
    39     }
    42     }
    40     return m_instance;
    43     return m_instance;
    41 }
    44 }
    42 
    45 
    43 bool WebGestureHelperEventFilter::eventFilter(QObject* receiver, QEvent* event)
    46 bool WebGestureHelperEventFilter::eventFilter(QObject* receiver, QEvent* event)
    44 {
    47 {
    45 	QStm_Gesture* g = getQStmGesture(event);
    48     QStm_Gesture* g = getQStmGesture(event);
    46     if (g) {
    49     if (g) {
    47     	g->sendMouseEvents(receiver);
    50         g->sendMouseEvents(receiver);
    48         return true;        	
    51         return true;
    49     }
    52     }
    50     return false;       
    53     return false;
    51 }
    54 }
    52 
    55 
    53 
    56 
    54 
    57 
    55 WebGestureHelper::WebGestureHelper(QWidget* ctrl) : 
    58 WebGestureHelper::WebGestureHelper(QWidget* ctrl) :
    56 		                     m_ctrl(ctrl)
    59                              m_ctrl(ctrl)
    57 {
    60 {
    58     m_gestureEngine = browserApp->gestureEngine();
    61     m_gestureEngine = browserApp->gestureEngine();
    59     setupGestureEngine(m_ctrl);
    62     setupGestureEngine(m_ctrl);
    60 }
    63 }
    61 
    64 
    72 
    75 
    73 
    76 
    74 void WebGestureHelper::setupGestureEngine(QWidget* ctrl)
    77 void WebGestureHelper::setupGestureEngine(QWidget* ctrl)
    75 {
    78 {
    76     m_gestures = m_gestureEngine->createContext(qptrdiff(ctrl));
    79     m_gestures = m_gestureEngine->createContext(qptrdiff(ctrl));
    77 #if defined(_DEBUG)    
    80 #if defined(_DEBUG)
    78     m_gestures->setLogging(0);
    81     m_gestures->setLogging(0);
    79 #endif    
    82 #endif
    80     QStm_GestureParameters& param = m_gestures->config();
    83     QStm_GestureParameters& param = m_gestures->config();
    81     param.setEnabled(qstmGesture::EGestureUidTap, true);
    84     param.setEnabled(qstmGesture::EGestureUidTap, true);
    82     param[qstmGesture::EDoubleTapTimeout] = 300;
    85     param[qstmGesture::EDoubleTapTimeout] = 300;
    83     
    86 
    84     param.setEnabled(qstmGesture::EGestureUidPan, true);
    87     param.setEnabled(qstmGesture::EGestureUidPan, true);
    85     param[qstmGesture::EPanSpeedLow] = 0;
    88     param[qstmGesture::EPanSpeedLow] = 0;
    86     param[qstmGesture::EPanSpeedHigh] = 100;
    89     param[qstmGesture::EPanSpeedHigh] = 100;
    87     param[qstmGesture::EPanDisabledWhileHovering] = false;
    90     param[qstmGesture::EPanDisabledWhileHovering] = false;
    88     param[qstmGesture::EMoveTolerance] = 2;
    91     param[qstmGesture::EMoveTolerance] = 2;
    89     
    92 
    90     param.setEnabled(qstmGesture::EGestureUidHover, false);
    93     param.setEnabled(qstmGesture::EGestureUidHover, false);
    91     param[qstmGesture::EHoverSpeed] = 0;
    94     param[qstmGesture::EHoverSpeed] = 0;
    92     param[qstmGesture::EHoverDisabledWhilePanning] = false;
    95     param[qstmGesture::EHoverDisabledWhilePanning] = false;
    93     
    96 
    94     param.setEnabled(qstmGesture::EGestureUidLeftRight,  false);
    97     param.setEnabled(qstmGesture::EGestureUidLeftRight,  false);
    95     param.setEnabled(qstmGesture::EGestureUidUpDown,     false);
    98     param.setEnabled(qstmGesture::EGestureUidUpDown,     false);
    96     
    99 
    97     param.setEnabled(qstmGesture::EGestureUidFlick,      true);
   100     param.setEnabled(qstmGesture::EGestureUidFlick,      true);
    98     param[qstmGesture::EFlickSpeed] = 25; /*param[stmGesture::EPanSpeedHigh];*/
   101     param[qstmGesture::EFlickSpeed] = 25; /*param[stmGesture::EPanSpeedHigh];*/
    99     
   102 
   100     param.setEnabled(qstmGesture::EGestureUidRelease,    true);
   103     param.setEnabled(qstmGesture::EGestureUidRelease,    true);
   101     param.setEnabled(qstmGesture::EGestureUidTouch,      true);
   104     param.setEnabled(qstmGesture::EGestureUidTouch,      true);
   102     
   105 
   103     param.setEnabled(qstmGesture::EGestureUidEdgeScroll, false);
   106     param.setEnabled(qstmGesture::EGestureUidEdgeScroll, false);
   104     param[qstmGesture::EEdgeScrollRange] = 20;
   107     param[qstmGesture::EEdgeScrollRange] = 20;
   105     
   108 
   106     param.setEnabled(qstmGesture::EGestureUidCornerZoom, false);
   109     param.setEnabled(qstmGesture::EGestureUidCornerZoom, false);
   107     param[qstmGesture::EZoomCornerSize] = 7;
   110     param[qstmGesture::EZoomCornerSize] = 7;
   108     
   111 
   109     param.setEnabled(qstmGesture::EGestureUidPinch, true);
   112     param.setEnabled(qstmGesture::EGestureUidPinch, true);
   110     param.setEnabled(qstmGesture::EGestureUidLongPress, true);
   113     param.setEnabled(qstmGesture::EGestureUidLongPress, true);
   111     
   114 
   112     param.setEnabled(qstmGesture::EGestureUidUnknown, true);
   115     param.setEnabled(qstmGesture::EGestureUidUnknown, true);
   113     
   116 
   114     QStm_GestureArea& touchArea = *param.area(qstmGesture::ETouchArea);
   117     QStm_GestureArea& touchArea = *param.area(qstmGesture::ETouchArea);
   115     QStm_GestureArea& tTimeArea = *param.area(qstmGesture::ETouchTimeArea);
   118     QStm_GestureArea& tTimeArea = *param.area(qstmGesture::ETouchTimeArea);
   116     QStm_GestureArea& holdArea  = *param.area(qstmGesture::EHoldArea);
   119     QStm_GestureArea& holdArea  = *param.area(qstmGesture::EHoldArea);
   117 
   120 
   118     touchArea.m_shape    = QStm_GestureArea::QStm_Shape(1);
   121     touchArea.m_shape    = QStm_GestureArea::QStm_Shape(1);
   124     tTimeArea.m_size     = QSize(7, 0);
   127     tTimeArea.m_size     = QSize(7, 0);
   125 
   128 
   126     holdArea.m_shape    = QStm_GestureArea::QStm_Shape(1);
   129     holdArea.m_shape    = QStm_GestureArea::QStm_Shape(1);
   127     holdArea.m_timeout  = 1500;
   130     holdArea.m_timeout  = 1500;
   128     holdArea.m_size     = QSize(7, 0);
   131     holdArea.m_size     = QSize(7, 0);
   129     
   132 
   130     param[ qstmGesture::ESuppressTimeout     ] = 0;
   133     param[ qstmGesture::ESuppressTimeout     ] = 0;
   131     param[ qstmGesture::EMoveSuppressTimeout ] = 0;
   134     param[ qstmGesture::EMoveSuppressTimeout ] = 0;
   132     param[ qstmGesture::ECapacitiveUpUsed    ] = false;
   135     param[ qstmGesture::ECapacitiveUpUsed    ] = false;
   133     param[ qstmGesture::EAdjustYPos          ] = false;
   136     param[ qstmGesture::EAdjustYPos          ] = false;
   134     param[ qstmGesture::EEnableFiltering     ] = 1;
   137     param[ qstmGesture::EEnableFiltering     ] = 1;
   135     param[ qstmGesture::EWServMessageInterception ] = false;
   138     param[ qstmGesture::EWServMessageInterception ] = false;
   136    
   139 
   137     m_gestures->activate(ctrl);
   140     m_gestures->activate(ctrl);
   138     
   141 
   139     /*
   142     /*
   140      * Only one instance of dummy recognizer is needed.
   143      * Only one instance of dummy recognizer is needed.
   141      * First context will have none-null pointer to it.
   144      * First context will have none-null pointer to it.
   142      */ 
   145      */
   143     if (QStm_Gesture::assignedType() == Qt::CustomGesture) {
   146     if (QStm_Gesture::assignedType() == Qt::CustomGesture) {
   144         m_dummyRecognizer = new QStm_QtDummyGestureRecognizer(m_gestures);
   147         m_dummyRecognizer = new QStm_QtDummyGestureRecognizer(m_gestures);
   145         m_gestures->addListener(m_dummyRecognizer);
   148         m_gestures->addListener(m_dummyRecognizer);
   146 	    m_qstmGestureType = QGestureRecognizer::registerRecognizer(m_dummyRecognizer);
   149         m_qstmGestureType = QGestureRecognizer::registerRecognizer(m_dummyRecognizer);
   147 	    QStm_Gesture::setAssignedGestureType(m_qstmGestureType);
   150         QStm_Gesture::setAssignedGestureType(m_qstmGestureType);
   148     }
   151     }
   149 }
   152 }
   150 
   153 
   151 
   154 
   152 bool  WebGestureHelper::symbianEventFilter(const QSymbianEvent *event)
   155 bool  WebGestureHelper::symbianEventFilter(const QSymbianEvent *event)
   153 {
   156 {
   154 	return m_gestures->handleSymbianPlatformEvent(event);
   157     return m_gestures->handleSymbianPlatformEvent(event);
   155 	
   158 
   156 }
   159 }
   157 
   160 
   158 
   161 
   159 bool WebGestureHelper::x11EventFilter (XEvent* event)
   162 bool WebGestureHelper::x11EventFilter (XEvent* event)
   160 {
   163 {
   161 	return m_gestures->handleX11PlatformEvent(event);
   164     return m_gestures->handleX11PlatformEvent(event);
   162 }
   165 }
   163 
   166 
   164 
   167 
   165 BrowserApp::BrowserApp(int argc, char** argv) : QApplication(argc, argv)
   168 BrowserApp::BrowserApp(int argc, char** argv) : QApplication(argc, argv)
   166 {
   169 {
   167     m_gestureEngine = new QStm_GestureEngineApi();
   170     m_gestureEngine = new QStm_GestureEngineApi();
   168 }
   171 }
   169 
   172 
   170 void BrowserApp::setGestureHelper(WebGestureHelper* gh) 
   173 void BrowserApp::setGestureHelper(WebGestureHelper* gh)
   171 { 
   174 {
   172 	m_gestureHelper = gh;     
   175     m_gestureHelper = gh;
   173 }
   176 }
   174 
   177 
   175 bool BrowserApp::symbianEventFilter(const QSymbianEvent *event)
   178 bool BrowserApp::symbianEventFilter(const QSymbianEvent *event)
   176 {
   179 {
   177 #if(ENABLE_GESTURE_LIB)
   180 #if(ENABLE_GESTURE_LIB)
   190     return false;
   193     return false;
   191 #endif
   194 #endif
   192 }
   195 }
   193 
   196 
   194 QStm_QtDummyGestureRecognizer::QStm_QtDummyGestureRecognizer(QStm_GestureContext* ctx) :
   197 QStm_QtDummyGestureRecognizer::QStm_QtDummyGestureRecognizer(QStm_GestureContext* ctx) :
   195 		                              QGestureRecognizer(), 
   198                                       QGestureRecognizer(),
   196 		                              m_context(ctx),
   199                                       m_context(ctx),
   197 		                              m_currentGesture(NULL)
   200                                       m_currentGesture(NULL)
   198 {
   201 {
   199 }
   202 }
   200 
   203 
   201 QStm_QtDummyGestureRecognizer::~QStm_QtDummyGestureRecognizer()
   204 QStm_QtDummyGestureRecognizer::~QStm_QtDummyGestureRecognizer()
   202 {
   205 {
   203 }
   206 }
   204 
   207 
   205 
   208 
   206 QGesture* QStm_QtDummyGestureRecognizer::create(QObject* /*target*/)
   209 QGesture* QStm_QtDummyGestureRecognizer::create(QObject* /*target*/)
   207 {
   210 {
   208 	return new QStm_Gesture();
   211     return new QStm_Gesture();
   209 }
   212 }
   210 
   213 
   211 QGestureRecognizer::Result QStm_QtDummyGestureRecognizer::recognize(QGesture *state, 
   214 QGestureRecognizer::Result QStm_QtDummyGestureRecognizer::recognize(QGesture *state,
   212 			                                                        QObject */*watched*/, 
   215                                                                     QObject */*watched*/,
   213 			                                                        QEvent *event)
   216                                                                     QEvent *event)
   214 {
   217 {
   215 	QGestureRecognizer::Result ret = QGestureRecognizer::Ignore;
   218     QGestureRecognizer::Result ret = QGestureRecognizer::Ignore;
   216 	if (event->type() == QStm_GestureEvent::stmGestureEventType()) {
   219     if (event->type() == QStm_GestureEvent::stmGestureEventType()) {
   217 		QStm_Gesture* gesture = static_cast<QStm_Gesture*>(state);
   220         QStm_Gesture* gesture = static_cast<QStm_Gesture*>(state);
   218 		*gesture = *m_currentGesture;
   221         *gesture = *m_currentGesture;
   219         ret = (m_currentGesture->gestureState() == Qt::GestureFinished) ? QGestureRecognizer::FinishGesture : 
   222         ret = (m_currentGesture->gestureState() == Qt::GestureFinished) ? QGestureRecognizer::FinishGesture :
   220 		                                                           QGestureRecognizer::TriggerGesture;	
   223                                                                    QGestureRecognizer::TriggerGesture;
   221 	}
   224     }
   222 	return ret;
   225     return ret;
   223 }
   226 }
   224 
   227 
   225 void QStm_QtDummyGestureRecognizer::reset(QGesture */*state*/)
   228 void QStm_QtDummyGestureRecognizer::reset(QGesture */*state*/)
   226 {
   229 {
   227 	
   230 
   228 }
   231 }
   229 
   232 
   230 
   233 
   231 
   234 
   232 QStm_GestureListenerApiIf::QStm_ProcessingResult QStm_QtDummyGestureRecognizer::handleGestureEvent(
   235 QStm_GestureListenerApiIf::QStm_ProcessingResult QStm_QtDummyGestureRecognizer::handleGestureEvent(
   234 {
   237 {
   235     if (!m_currentGesture) {
   238     if (!m_currentGesture) {
   236         Q_ASSERT(gesture);
   239         Q_ASSERT(gesture);
   237         m_currentGesture = new QStm_Gesture();
   240         m_currentGesture = new QStm_Gesture();
   238     }
   241     }
   239     
   242 
   240     int stmGestType = gesture ? gesture->getType() : -1;
   243     int stmGestType = gesture ? gesture->getType() : -1;
   241     
   244 
   242     switch(uid) {
   245     switch (uid) {
   243         case EGestureUidTap:
   246         case EGestureUidTap:
   244         {
   247         {
   245             QStm_TapType type = qstmGesture::QStm_TapType(stmGestType);
   248             QStm_TapType type = qstmGesture::QStm_TapType(stmGestType);
   246             if (type == qstmGesture::ETapTypeDouble) {
   249             if (type == qstmGesture::ETapTypeDouble) {
   247                 m_currentGesture->setGestureStmType(QStmDoubleTapGestureType);
   250                 m_currentGesture->setGestureStmType(QStmDoubleTapGestureType);
   248             }
   251             }
   249             else  {
   252             else  {
   250                 m_currentGesture->setGestureStmType(QStmTapGestureType);
   253                 m_currentGesture->setGestureStmType(QStmTapGestureType);
   251             }
   254             }
   252             break;    
   255             break;
   253         }
   256         }
   254         
   257 
   255         case EGestureUidTouch:
   258         case EGestureUidTouch:
   256         {
   259         {
   257             m_currentGesture->setGestureStmType(QStmTouchGestureType);
   260             m_currentGesture->setGestureStmType(QStmTouchGestureType);
   258             break;    
   261             break;
   259         }
   262         }
   260         
   263 
   261         case EGestureUidRelease:
   264         case EGestureUidRelease:
   262         {
   265         {
   263             m_currentGesture->setGestureStmType(QStmReleaseGestureType);
   266             m_currentGesture->setGestureStmType(QStmReleaseGestureType);
   264             break;
   267             break;
   265         }
   268         }
   266         
   269 
   267         case EGestureUidFlick:
   270         case EGestureUidFlick:
   268         {
   271         {
   269             m_currentGesture->setGestureStmType(QStmFlickGestureType);
   272             m_currentGesture->setGestureStmType(QStmFlickGestureType);
   270             break;    
   273             break;
   271         }
   274         }
   272         
   275 
   273         case EGestureUidLeftRight:
   276         case EGestureUidLeftRight:
   274         {
   277         {
   275             m_currentGesture->setGestureStmType(QStmLeftRightGestureType);
   278             m_currentGesture->setGestureStmType(QStmLeftRightGestureType);
   276             break;    
   279             break;
   277         }
   280         }
   278         
   281 
   279         case EGestureUidUpDown:
   282         case EGestureUidUpDown:
   280         {
   283         {
   281             m_currentGesture->setGestureStmType(QStmUpDownGestureType);
   284             m_currentGesture->setGestureStmType(QStmUpDownGestureType);
   282             break;
   285             break;
   283         }
   286         }
   284         
   287 
   285         case EGestureUidPan:
   288         case EGestureUidPan:
   286         {
   289         {
   287             m_currentGesture->setGestureStmType(QStmPanGestureType);
   290             m_currentGesture->setGestureStmType(QStmPanGestureType);
   288             break;
   291             break;
   289         }
   292         }
   290         
   293 
   291         case EGestureUidHover:
   294         case EGestureUidHover:
   292         {
   295         {
   293             m_currentGesture->setGestureStmType(QStmHoverGestureType);
   296             m_currentGesture->setGestureStmType(QStmHoverGestureType);
   294             break;
   297             break;
   295         }
   298         }
   297         case EGestureUidLongPress:
   300         case EGestureUidLongPress:
   298         {
   301         {
   299             m_currentGesture->setGestureStmType(QStmLongPressGestureType);
   302             m_currentGesture->setGestureStmType(QStmLongPressGestureType);
   300             break;
   303             break;
   301         }
   304         }
   302         
   305 
   303         case EGestureUidEdgeScroll:
   306         case EGestureUidEdgeScroll:
   304         {
   307         {
   305             m_currentGesture->setGestureStmType(QStmEdgeScrollGestureType);
   308             m_currentGesture->setGestureStmType(QStmEdgeScrollGestureType);
   306             break;
   309             break;
   307         }
   310         }
   308         
   311 
   309         case EGestureUidCornerZoom:
   312         case EGestureUidCornerZoom:
   310         {
   313         {
   311             m_currentGesture->setGestureStmType(QStmCornerZoomGestureType);
   314             m_currentGesture->setGestureStmType(QStmCornerZoomGestureType);
   312             break;
   315             break;
   313         }
   316         }
   314         
   317 
   315         case EGestureUidPinch:
   318         case EGestureUidPinch:
   316         {
   319         {
   317             m_currentGesture->setGestureStmType(QStmPinchGestureType);
   320             m_currentGesture->setGestureStmType(QStmPinchGestureType);
   318             break;
   321             break;
   319         }
   322         }
   321         {
   324         {
   322             m_currentGesture->setGestureStmType(QStmUknownGestureType);
   325             m_currentGesture->setGestureStmType(QStmUknownGestureType);
   323             break;
   326             break;
   324         }
   327         }
   325     }
   328     }
   326     
   329 
   327     if (gesture) { //gesture enter
   330     if (gesture) { //gesture enter
   328         m_currentGesture->setGestureSubType(gesture->getType());
   331         m_currentGesture->setGestureSubType(gesture->getType());
   329         m_currentGesture->setDirection(gesture->getDirection());
   332         m_currentGesture->setDirection(gesture->getDirection());
   330         QPoint vec = gesture->getLengthAndDirection();
   333         QPoint vec = gesture->getLengthAndDirection();
   331         m_currentGesture->setLengthAndDirection(vec);
   334         m_currentGesture->setLengthAndDirection(vec);
   339         m_currentGesture->setGestureState(Qt::NoGesture);
   342         m_currentGesture->setGestureState(Qt::NoGesture);
   340     }
   343     }
   341     else {
   344     else {
   342         m_currentGesture->setGestureState(Qt::GestureFinished);
   345         m_currentGesture->setGestureState(Qt::GestureFinished);
   343     }
   346     }
   344     
   347 
   345     QStm_GestureEvent dummy;
   348     QStm_GestureEvent dummy;
   346     m_currentGesture->sendEvent(&dummy);
   349     m_currentGesture->sendEvent(&dummy);
   347     
   350 
   348     return QStm_GestureListenerApiIf::EContinue;
   351     return QStm_GestureListenerApiIf::EContinue;
   349 }
   352 }
   350 
   353 
   351 
   354 
   352 
   355