ginebra2/ContentViews/GWebContentViewWidget.cpp
changeset 16 3c88a81ff781
parent 12 afcd8e6d025b
equal deleted inserted replaced
14:6aeb7a756187 16:3c88a81ff781
    23 #include "browserpagefactory.h"
    23 #include "browserpagefactory.h"
    24 #include "webpagecontroller.h"
    24 #include "webpagecontroller.h"
    25 #include "Utilities.h"
    25 #include "Utilities.h"
    26 #include "ChromeEffect.h"
    26 #include "ChromeEffect.h"
    27 
    27 
       
    28 #ifdef Q_WS_MAEMO_5
       
    29 #include "ContentViewContextMenu.h"
       
    30 #endif
       
    31 
    28 #include <QGraphicsSceneResizeEvent>
    32 #include <QGraphicsSceneResizeEvent>
    29 #include <QGraphicsSceneContextMenuEvent>
    33 #include <QGraphicsSceneContextMenuEvent>
    30 #include <QWebFrame>
    34 #include <QWebFrame>
    31 #include <QWebHitTestResult>
    35 #include <QWebHitTestResult>
    32 #include <QPoint>
    36 #include <QPoint>
    86   WrtPerfTracer::tracer()->initPage(pg);
    90   WrtPerfTracer::tracer()->initPage(pg);
    87 #endif //ENABLE_PERF_TRACE
    91 #endif //ENABLE_PERF_TRACE
    88 
    92 
    89   m_currentinitialScale = zoomFactor();
    93   m_currentinitialScale = zoomFactor();
    90 
    94 
    91 #ifndef NO_QSTM_GESTURE
       
    92   m_touchNavigation = new WebTouchNavigation(this);
       
    93 #endif
       
    94   // Fixes missing radio button problem with certain themes
    95   // Fixes missing radio button problem with certain themes
    95   QPalette pal = palette();
    96   QPalette pal = palette();
    96   pal.setColor(QPalette::ButtonText,Qt::black);
    97   pal.setColor(QPalette::ButtonText,Qt::black);
    97   setPalette(pal);
    98   setPalette(pal);
    98 }
    99 }
   211     m_isResize = false;
   212     m_isResize = false;
   212 }
   213 }
   213 
   214 
   214 bool GWebContentViewWidget::event(QEvent * e) {
   215 bool GWebContentViewWidget::event(QEvent * e) {
   215 
   216 
   216     if (e->type() == QEvent::Gesture) {
   217     if (e->type() == WebPageControllerUpdateViewPortEvent::staticType()) {
   217 #ifndef NO_QSTM_GESTURE
       
   218           QStm_Gesture* gesture = getQStmGesture(e, WebGestureHelper::getAssignedGestureType());
       
   219           if (gesture) {
       
   220               m_touchNavigation->handleQStmGesture(gesture);
       
   221               return true;
       
   222           }
       
   223 #endif
       
   224     }
       
   225 
       
   226     else if (e->type() == WebPageControllerUpdateViewPortEvent::staticType()) {
       
   227         updateViewport();
   218         updateViewport();
   228     }
   219     }
   229     return QGraphicsWebView::event(e);
   220     return QGraphicsWebView::event(e);
   230 }
   221 }
   231 
   222 
   269   }
   260   }
   270 }
   261 }
   271 
   262 
   272 void GWebContentViewWidget::onLongPressEvent(QPoint pos) {
   263 void GWebContentViewWidget::onLongPressEvent(QPoint pos) {
   273     QWebHitTestResult hitTest = page()->currentFrame()->hitTestContent(pos);
   264     QWebHitTestResult hitTest = page()->currentFrame()->hitTestContent(pos);
   274     //qDebug() << "GWebContentViewWidget::contextMenuEvent:"
   265     qDebug() << "GWebContentViewWidget::onLongPressEvent:";
   275     //        << "\n\t pos=" << hitTest.pos()
   266     //        << "\n\t pos=" << hitTest.pos()
   276     //        << "\n\t linkUrl=" << hitTest.linkUrl()
   267     //        << "\n\t linkUrl=" << hitTest.linkUrl()
   277     //        << "\n\t imageUrl=" << hitTest.imageUrl();
   268     //        << "\n\t imageUrl=" << hitTest.imageUrl();
   278 
   269 
   279     ::WebViewEventContext *context =
   270     ::WebViewEventContext *context =
   283         // Let the superpage handle the event.
   274         // Let the superpage handle the event.
   284         m_webContentView->currentSuperPage()->onContextEvent(context);
   275         m_webContentView->currentSuperPage()->onContextEvent(context);
   285     }
   276     }
   286     else {
   277     else {
   287         // Send the event directly.
   278         // Send the event directly.
       
   279        #ifndef Q_WS_MAEMO_5
   288         emit contextEvent(context);
   280         emit contextEvent(context);
       
   281        #endif
   289     }
   282     }
   290 }
   283 }
   291 
   284 
   292 void GWebContentViewWidget::contextMenuEvent(::QGraphicsSceneContextMenuEvent *event) {
   285 void GWebContentViewWidget::contextMenuEvent(::QGraphicsSceneContextMenuEvent *event) {
       
   286 	  #ifndef Q_WS_MAEMO_5
   293     // Ignore.  The touch navigation code handles long presses.
   287     // Ignore.  The touch navigation code handles long presses.
   294     event->accept();
   288     	event->accept();
       
   289     #else	
       
   290     	QWebHitTestResult hitTest = page()->currentFrame()->hitTestContent(this->mapFromScene(event->scenePos()).toPoint());
       
   291     	if (m_webContentView && m_webContentView->currentPageIsSuperPage()) {
       
   292         // Let the superpage handle the event.
       
   293         ::WebViewEventContext *context =
       
   294                 new ::WebViewEventContext(view()->type(), hitTest);
       
   295         m_webContentView->currentSuperPage()->onContextEvent(context);
       
   296     }
       
   297     else {
       
   298         ContentViewContextMenu menu(&hitTest, 0);
       
   299         menu.exec(event->scenePos().toPoint());
       
   300     }
       
   301     #endif
   295 }
   302 }
   296 
   303 
   297 void GWebContentViewWidget::setZoomFactor(qreal zoom)
   304 void GWebContentViewWidget::setZoomFactor(qreal zoom)
   298 {
   305 {
   299     this->setFocus();
   306     this->setFocus();
   339   if ( m_dirtyZoomFactor != zoom ) {
   346   if ( m_dirtyZoomFactor != zoom ) {
   340       m_dirtyZoomFactor = zoom;
   347       m_dirtyZoomFactor = zoom;
   341       #if QT_VERSION < 0x040600
   348       #if QT_VERSION < 0x040600
   342 		  page()->setFixedContentsSize(QSize(m_viewportWidth, m_viewportHeight/zoom));
   349 		  page()->setFixedContentsSize(QSize(m_viewportWidth, m_viewportHeight/zoom));
   343 	  #else
   350 	  #else
   344           if(!m_webContentView->currentPageIsSuperPage()) 
       
   345             page()->setPreferredContentsSize(QSize((int)m_viewportWidth, (int)m_viewportHeight/zoom));
   351             page()->setPreferredContentsSize(QSize((int)m_viewportWidth, (int)m_viewportHeight/zoom));
   346 	  #endif
   352 	  #endif
   347   }
   353   }
   348 
   354 
   349   QGraphicsWebView::setZoomFactor( zoom );
   355   QGraphicsWebView::setZoomFactor( zoom );
   647 }
   653 }
   648 
   654 
   649 /*!
   655 /*!
   650  * Provides the default values - used when opening a new blank window
   656  * Provides the default values - used when opening a new blank window
   651  */
   657  */
   652 ZoomMetaData GWebContentViewWidget::defaultZoomData()
   658 const WebPageData& GWebContentViewWidget::defaultZoomData()
   653 {
   659 {
   654     ZoomMetaData data;
   660     static const WebPageData data(KDefaultMaxScale,KDefaultMinScale,false, KInitialZoomFactorValue);
   655 
       
   656     data.maxScale = KDefaultMaxScale;
       
   657     data.minScale =  KDefaultMinScale;
       
   658     data.userScalable = false;
       
   659     data.zoomValue = KInitialZoomFactorValue;
       
   660 
   661 
   661     return data;
   662     return data;
   662 }
   663 }
   663 
   664 
   664 /*!
   665 /*!
   706 		page()->setFixedContentsSize(QSize(m_viewportWidth, m_viewportHeight));
   707 		page()->setFixedContentsSize(QSize(m_viewportWidth, m_viewportHeight));
   707 	#else
   708 	#else
   708 		page()->setPreferredContentsSize(QSize((int)m_viewportWidth, (int)m_viewportHeight));
   709 		page()->setPreferredContentsSize(QSize((int)m_viewportWidth, (int)m_viewportHeight));
   709 	#endif
   710 	#endif
   710 #endif //NO_RESIZE_ON_LOAD
   711 #endif //NO_RESIZE_ON_LOAD
   711    if((m_webContentView->currentPageIsSuperPage())){
       
   712         page()->setPreferredContentsSize(QSize((int)m_viewportWidth, (int)m_viewportHeight));
       
   713    }
       
   714 #ifndef NO_RESIZE_ON_LOAD
   712 #ifndef NO_RESIZE_ON_LOAD
   715   qreal zoomF = 0.0;
   713   qreal zoomF = 0.0;
   716   QString str;
   714   QString str;
   717   if (m_isResize &&  (m_currentinitialScale != zoomFactor())) {
   715   if (m_isResize &&  (m_currentinitialScale != zoomFactor())) {
   718     zoomF = ((qreal)(page()->viewportSize().width()-10) * zoomFactor())/(m_previousViewPortwidth-10);
   716     zoomF = ((qreal)(page()->viewportSize().width()-10) * zoomFactor())/(m_previousViewPortwidth-10);
   728 #endif //NO_RESIZE_ON_LOAD
   726 #endif //NO_RESIZE_ON_LOAD
   729 
   727 
   730   // Let the page save the data. Even though it is part of the frame, it is easier to
   728   // Let the page save the data. Even though it is part of the frame, it is easier to
   731   // save the info in the page to avoid parsing the meta data again.
   729   // save the info in the page to avoid parsing the meta data again.
   732   WrtBrowserContainer* pg = static_cast<WrtBrowserContainer*>(page());
   730   WrtBrowserContainer* pg = static_cast<WrtBrowserContainer*>(page());
   733   pg->setPageZoomMetaData(pageZoomMetaData());
   731   //WTF pg->setPageZoomMetaData(pageZoomMetaData());
   734   
   732   
   735 
   733 
   736 }
   734 }
   737 
   735 
   738 qreal GWebContentViewWidget::initialScale()
   736 qreal GWebContentViewWidget::initialScale()
   839 qreal GWebContentViewWidget::maximumScale()
   837 qreal GWebContentViewWidget::maximumScale()
   840 {
   838 {
   841     return m_maximumScale;
   839     return m_maximumScale;
   842 }
   840 }
   843 
   841 
   844 ZoomMetaData GWebContentViewWidget::pageZoomMetaData() {
   842 /* WTF ZoomMetaData GWebContentViewWidget::pageZoomMetaData() {
   845 
   843 
   846     ZoomMetaData data;
   844     ZoomMetaData data;
   847 
   845 
   848     data.minScale = m_minimumScale;
   846     data.minScale = m_minimumScale;
   849     data.maxScale = m_maximumScale;
   847     data.maxScale = m_maximumScale;
   858     m_minimumScale = data.minScale ;
   856     m_minimumScale = data.minScale ;
   859     m_maximumScale = data.maxScale ;
   857     m_maximumScale = data.maxScale ;
   860     m_userScalable = data.userScalable;
   858     m_userScalable = data.userScalable;
   861     view()->setSavedZoomValueInView(data.zoomValue);
   859     view()->setSavedZoomValueInView(data.zoomValue);
   862 }
   860 }
       
   861 */
   863 
   862 
   864 QWebPage* GWebContentViewWidget::page() const
   863 QWebPage* GWebContentViewWidget::page() const
   865 {
   864 {
   866     if (!m_wrtPage) {
   865     if (!m_wrtPage) {
   867         GWebContentViewWidget* that = const_cast<GWebContentViewWidget*>(this);
   866         GWebContentViewWidget* that = const_cast<GWebContentViewWidget*>(this);