ginebra2/GWebTouchNavigation.cpp
changeset 16 3c88a81ff781
parent 3 0954f5dd2cd0
equal deleted inserted replaced
14:6aeb7a756187 16:3c88a81ff781
    29 #include <QGraphicsSceneMouseEvent>
    29 #include <QGraphicsSceneMouseEvent>
    30 #include <QTimer>
    30 #include <QTimer>
    31 #include <qmath.h>
    31 #include <qmath.h>
    32 #include <QDebug>
    32 #include <QDebug>
    33 #include <QGraphicsView>
    33 #include <QGraphicsView>
    34 
    34 #include <QInputContext>
    35 
    35 
    36 namespace GVA {
    36 namespace GVA {
    37 
    37 
    38 const int KFlickSpeed = 400;
    38 const int KFlickSpeed = 400;
    39 const qreal PI = 3.1415926535897932;
    39 const qreal PI = 3.1415926535897932;
    55 const qreal KDeccelaration = 1000.00;
    55 const qreal KDeccelaration = 1000.00;
    56 
    56 
    57 static const int KStartPanDistance = 50;
    57 static const int KStartPanDistance = 50;
    58 static const int KWaitForClickTimeoutMS = 200;
    58 static const int KWaitForClickTimeoutMS = 200;
    59 static const int KLongPressDuration = 1000;
    59 static const int KLongPressDuration = 1000;
    60 static const int KLongPressThreshold = 30;
    60 static const int KLongPressThreshold = 18;
    61 //The amount of pixels to try to pan before pan mode unlocks
    61 //The amount of pixels to try to pan before pan mode unlocks
    62 static const int KPanModeChangeDelta = 100;
    62 static const int KPanModeChangeDelta = 100;
    63 
    63 
    64 /*!
    64 /*!
    65     \class WebTouchNavigation
    65     \class WebTouchNavigation
   187             mouseDoubleClickEvent(static_cast<QGraphicsSceneMouseEvent*>(event)->pos().toPoint());
   187             mouseDoubleClickEvent(static_cast<QGraphicsSceneMouseEvent*>(event)->pos().toPoint());
   188             emit mouseEvent(QEvent::GraphicsSceneMouseDoubleClick);
   188             emit mouseEvent(QEvent::GraphicsSceneMouseDoubleClick);
   189             return true;
   189             return true;
   190         case QEvent::GraphicsSceneContextMenu:
   190         case QEvent::GraphicsSceneContextMenu:
   191             contextMenuEvent();
   191             contextMenuEvent();
       
   192 // for orbit fw app, long press triggers context menu event which selects closest word
       
   193 #ifdef ORBIT_UI
       
   194             return true;
       
   195 #else
   192             break;
   196             break;
       
   197 #endif
   193         default:
   198         default:
   194             break;
   199             break;
   195     }
   200     }
   196     return false;
   201     return false;
   197 }
   202 }
   604     }
   609     }
   605 
   610 
   606     if (m_pressEvent){
   611     if (m_pressEvent){
   607         QPoint diff2 = m_pressEvent->pos() - pos;
   612         QPoint diff2 = m_pressEvent->pos() - pos;
   608         if (qAbs(diff2.x()) < KTouchThresholdX && qAbs(diff2.y()) < KTouchThresholdY) {
   613         if (qAbs(diff2.x()) < KTouchThresholdX && qAbs(diff2.y()) < KTouchThresholdY) {
   609             return;
   614             if (!m_frame)
       
   615                 return;
       
   616             QWebHitTestResult htr = m_frame->hitTestContent(m_touchPosition);
       
   617             if (!htr.isContentEditable())
       
   618                 return;
   610         }
   619         }
   611     }
   620     }
   612 
   621 
   613     if (m_doubleClickTimer && m_doubleClickTimer->isActive()) {
   622     if (m_doubleClickTimer && m_doubleClickTimer->isActive()) {
   614         //send mousePressEvent
   623         //send mousePressEvent
   631             if (hitTestResult.isContentEditable()) {
   640             if (hitTestResult.isContentEditable()) {
   632                 QMouseEvent moveEvt(QEvent::MouseMove, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
   641                 QMouseEvent moveEvt(QEvent::MouseMove, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
   633                 m_webPage->event(&moveEvt);
   642                 m_webPage->event(&moveEvt);
   634                 m_textSelected = true;
   643                 m_textSelected = true;
   635             }
   644             }
       
   645         } else { // FIXME add following lines to enable the auto-scroll while selecting text
       
   646             if (m_textSelected) {
       
   647                 QMouseEvent moveEvt(QEvent::MouseMove, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
       
   648                 m_webPage->event(&moveEvt);
       
   649             }
   636         }
   650         }
   637     }
   651     }
   638     if (!m_textSelected)
   652     if (!m_textSelected)
   639         scrollFrame(diff);
   653         scrollFrame(diff);
   640 
   654 
   726             startScrollTimer();
   740             startScrollTimer();
   727         }
   741         }
   728     } else {
   742     } else {
   729         // we don't want to automatically display the SIP (Software input panel) by qtwebkit
   743         // we don't want to automatically display the SIP (Software input panel) by qtwebkit
   730         bool sipEnabled = qApp->autoSipEnabled();
   744         bool sipEnabled = qApp->autoSipEnabled();
   731         qApp->setAutoSipEnabled(false);
   745         //qApp->setAutoSipEnabled(false);
   732         QMouseEvent iev = m_ishighlighted ?
   746         QMouseEvent iev = m_ishighlighted ?
   733         QMouseEvent(ev->type(), m_higlightedPos, ev->button(), ev->buttons(), getEventModifier(m_higlightedPos)) :
   747         QMouseEvent(ev->type(), m_higlightedPos, ev->button(), ev->buttons(), getEventModifier(m_higlightedPos)) :
   734         QMouseEvent(QEvent::MouseButtonRelease, m_touchPosition, ev->button(), ev->buttons(), getEventModifier(m_touchPosition));
   748         QMouseEvent(QEvent::MouseButtonRelease, m_touchPosition, ev->button(), ev->buttons(), getEventModifier(m_touchPosition));
   735         m_webPage->event(&iev);
   749         m_webPage->event(&iev);
   736         qApp->setAutoSipEnabled(sipEnabled);
   750         qApp->setAutoSipEnabled(sipEnabled);
   737 #if defined __SYMBIAN32__
   751 #if defined __SYMBIAN32__
   738 // FIXME Remove this, it will be fixed Qt 4.6.3 ?
   752 // FIXME Remove this, it will be fixed Qt 4.6.3 ?
   739         if (ev->button() == Qt::LeftButton) {
   753         if (ev->button() == Qt::LeftButton) {
   740             QWebHitTestResult htr = m_frame->hitTestContent(ev->pos());
   754             QWebHitTestResult htr = m_frame->hitTestContent(ev->pos());
   741             if (htr.isContentEditable()) {
   755             QEvent* vkbEvent; 
   742                 QEvent vkbEvent(QEvent::RequestSoftwareInputPanel);
   756             QInputContext *ic = qApp->inputContext();
   743                 QList<QGraphicsView*> views = m_view->scene()->views();
   757             if (htr.isContentEditable()) 
   744                 QWidget* view = qobject_cast<QWidget*>(views.value(0));
   758             	vkbEvent = new QEvent(QEvent::RequestSoftwareInputPanel);
   745                 if (view)
   759             else
   746                     QApplication::sendEvent(view, &vkbEvent);
   760             	vkbEvent = new QEvent(QEvent::CloseSoftwareInputPanel);
   747             }
   761             if (ic) 
       
   762             	ic->filterEvent(vkbEvent);
       
   763         delete vkbEvent;
   748         }
   764         }
   749 #endif
   765 #endif
   750     }
   766     }
   751 }
   767 }
   752 
   768 
   753 void GWebTouchNavigation::mouseDoubleClickEvent(const QPoint& pos)
   769 void GWebTouchNavigation::mouseDoubleClickEvent(const QPoint& pos)
   754 {
   770 {
   755 
       
   756     if (m_doubleClickTimer && !m_doubleClickTimer->isActive())
   771     if (m_doubleClickTimer && !m_doubleClickTimer->isActive())
   757         return;
   772         return;
   758     else if (m_doubleClickTimer)
   773     else if (m_doubleClickTimer)
   759         m_doubleClickTimer->stop();
   774         m_doubleClickTimer->stop();
   760 
   775 
  1372 void GWebTouchNavigation::onLoadFinished(bool ok)
  1387 void GWebTouchNavigation::onLoadFinished(bool ok)
  1373 {
  1388 {
  1374     Q_UNUSED(ok)
  1389     Q_UNUSED(ok)
  1375     m_isLoading = false;
  1390     m_isLoading = false;
  1376 }
  1391 }
  1377 void GWebTouchNavigation::setPage( QWebPage * page)
  1392 void GWebTouchNavigation::setPage( QWebPage * page, bool aWantSlideView)
  1378 {
  1393 {
  1379     if (m_webPage) {
  1394     // Need to listen to the load signals to determine whethter slideView should
       
  1395     // be called when scrolling. This is called only when m_wantSlideViewCalls is set and hence,
       
  1396     // there is no need to disconnect and connect to these signals if m_wantSlideViewCalls/ new value
       
  1397     // of m_wantSlideViewCalls is false
       
  1398     if (m_webPage && m_wantSlideViewCalls) {
  1380         disconnect(m_webPage, SIGNAL(loadStarted()), this, SLOT(onLoadStarted()));
  1399         disconnect(m_webPage, SIGNAL(loadStarted()), this, SLOT(onLoadStarted()));
  1381         disconnect(m_webPage, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool)));
  1400         disconnect(m_webPage, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool)));
  1382         //disconnect(m_webPage->mainFrame(), SIGNAL(contentsSizeChanged(const QSize &)), this, SLOT(onContentsSizeChanged(const QSize &)));
  1401         //disconnect(m_webPage->mainFrame(), SIGNAL(contentsSizeChanged(const QSize &)), this, SLOT(onContentsSizeChanged(const QSize &)));
  1383     }
  1402     }
  1384     m_webPage = page;
  1403     m_webPage = page;
  1385     if (m_webPage) {
  1404     m_wantSlideViewCalls = aWantSlideView;
       
  1405     if (m_webPage && m_wantSlideViewCalls) {
  1386         connect(m_webPage, SIGNAL(loadStarted()), this, SLOT(onLoadStarted()));
  1406         connect(m_webPage, SIGNAL(loadStarted()), this, SLOT(onLoadStarted()));
  1387         connect(m_webPage, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool)));
  1407         connect(m_webPage, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool)));
  1388         //connect(m_webPage->mainFrame(), SIGNAL(contentsSizeChanged(const QSize &)), this, SLOT(onContentsSizeChanged(const QSize &)));
  1408         //connect(m_webPage->mainFrame(), SIGNAL(contentsSizeChanged(const QSize &)), this, SLOT(onContentsSizeChanged(const QSize &)));
  1389     }
  1409     }
  1390 }
  1410 }
  1401 
  1421 
  1402 void GWebTouchNavigation::enableDClick(bool aValue)
  1422 void GWebTouchNavigation::enableDClick(bool aValue)
  1403 {
  1423 {
  1404     m_doubleClickEnabled = aValue;
  1424     m_doubleClickEnabled = aValue;
  1405 }
  1425 }
  1406 }
  1426 
       
  1427 }