ginebra2/ContentViews/GWebContentView.cpp
changeset 6 1c3b8676e58c
parent 5 0f2326c2a325
child 10 232fbd5a2dcb
equal deleted inserted replaced
5:0f2326c2a325 6:1c3b8676e58c
    20 */
    20 */
    21 
    21 
    22 #include "GWebContentView.h"
    22 #include "GWebContentView.h"
    23 #include "GWebContentViewWidget.h"
    23 #include "GWebContentViewWidget.h"
    24 #include "GWebContentViewJSObject.h"
    24 #include "GWebContentViewJSObject.h"
       
    25 #include "SuperPageView.h"
    25 #include "ChromeWidget.h"
    26 #include "ChromeWidget.h"
    26 #include "WebViewEventContext.h"
    27 #include "WebViewEventContext.h"
    27 #include "browserpagefactory.h"
    28 #include "browserpagefactory.h"
    28 #include "wrtbrowsercontainer.h"
    29 #include "wrtbrowsercontainer.h"
       
    30 
       
    31 #ifdef BEDROCK_TILED_BACKING_STORE
       
    32 #include "WebContentViewWidget.h"
       
    33 #endif
       
    34 
    29 #include "webpagecontroller.h"
    35 #include "webpagecontroller.h"
       
    36 #include "Utilities.h"
       
    37 #include "GSuperWebPage.h"
    30 #ifndef NO_QSTM_GESTURE
    38 #ifndef NO_QSTM_GESTURE
    31 #include "qstmgestureevent.h"
    39 #include "qstmgestureevent.h"
    32 #endif
    40 #endif
    33 
    41 
    34 #include <QGraphicsWebView>
    42 #include <QGraphicsWebView>
    36 #include <QWebPage>
    44 #include <QWebPage>
    37 #include <QWebFrame>
    45 #include <QWebFrame>
    38 #include <QTimeLine>
    46 #include <QTimeLine>
    39 #include <QDebug>
    47 #include <QDebug>
    40 #include <QtGui>
    48 #include <QtGui>
    41 
       
    42 
       
    43 #define safe_connect(src, srcSig, target, targetSlot) \
       
    44   { int res = connect(src, srcSig, target, targetSlot); assert(res); }
       
    45 
    49 
    46 namespace GVA {
    50 namespace GVA {
    47 
    51 
    48 
    52 
    49   // ----------------------------------------------------------
    53   // ----------------------------------------------------------
    64       m_currentPageIsSuperPage(false),
    68       m_currentPageIsSuperPage(false),
    65       m_timer(NULL),
    69       m_timer(NULL),
    66       m_enabled(true)
    70       m_enabled(true)
    67   {
    71   {
    68       setObjectName(objectName);
    72       setObjectName(objectName);
    69       qDebug() << "GWebContentView::GWebContentView: this=" << this;
       
    70       WRT::WrtBrowserContainer* page = BrowserPageFactory::openBrowserPage();
    73       WRT::WrtBrowserContainer* page = BrowserPageFactory::openBrowserPage();
    71 
    74 
    72       setActions();
    75       setActions();
       
    76 
       
    77 #ifdef BEDROCK_TILED_BACKING_STORE
       
    78       m_widget = new WebContentViewWidget(parent, page);
       
    79       connect(m_widget
       
    80               , SIGNAL(updateZoomActions(bool,bool))
       
    81               , this
       
    82               , SLOT(setZoomActions(bool, bool)));
       
    83 #else
    73       m_widget = new GWebContentViewWidget(parent, this, page);
    84       m_widget = new GWebContentViewWidget(parent, this, page);
       
    85 #endif
       
    86 
    74 #ifndef __gva_no_chrome__
    87 #ifndef __gva_no_chrome__
    75       setJSObject(objectName);
    88       setJSObject(objectName);
    76 #endif
    89 #endif
    77       m_networkMgr = webWidget()->page()->networkAccessManager();
    90       m_networkMgr = webWidget()->page()->networkAccessManager();
    78 
    91 
    79       webWidget()->page()->currentFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
    92       webWidget()->page()->currentFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
    80       webWidget()->page()->currentFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff);
    93       webWidget()->page()->currentFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff);
    81 
    94 
       
    95 #ifndef BEDROCK_TILED_BACKING_STORE
    82 #ifdef NO_QSTM_GESTURE
    96 #ifdef NO_QSTM_GESTURE
    83       m_touchNavigation = new GContentViewTouchNavigation(page, m_widget);
    97       m_touchNavigation = new GContentViewTouchNavigation(page, m_widget);
    84       m_touchNavigation->setChromeWidget(m_chrome);
    98       m_touchNavigation->setChromeWidget(m_chrome);
    85       connect(m_touchNavigation, SIGNAL(mouseEvent(QEvent::Type)) , this, SIGNAL(contentViewMouseEvent(QEvent::Type)));
    99       m_touchNavigation->setParent(m_jsObject);
       
   100       m_touchNavigation->setObjectName("touchNav");
       
   101       safe_connect(m_touchNavigation, SIGNAL(mouseEvent(QEvent::Type)) , this, SIGNAL(contentViewMouseEvent(QEvent::Type)));
       
   102       safe_connect(m_touchNavigation, SIGNAL(longPressEvent(QPoint)),
       
   103                    webWidget(), SLOT(onLongPressEvent(QPoint)));
       
   104 #endif
    86 #endif
   105 #endif
    87       WRT::WrtBrowserContainer * wrtPage = static_cast<WRT::WrtBrowserContainer *>(page);
   106       WRT::WrtBrowserContainer * wrtPage = static_cast<WRT::WrtBrowserContainer *>(page);
    88       if (wrtPage) {
   107       if (wrtPage) {
    89           wrtPage->setWebWidget(webWidget());
   108           wrtPage->setWebWidget(webWidget());
    90           pageCreated(wrtPage);
   109           pageCreated(wrtPage);
    94   }
   113   }
    95 
   114 
    96   GWebContentView::~GWebContentView() {
   115   GWebContentView::~GWebContentView() {
    97       disconnect(m_jsObject);
   116       disconnect(m_jsObject);
    98       disconnect(webWidget());
   117       disconnect(webWidget());
       
   118 #ifndef BEDROCK_TILED_BACKING_STORE
    99       delete m_touchNavigation;
   119       delete m_touchNavigation;
       
   120 #endif
   100       foreach(QAction * action, m_actions) {
   121       foreach(QAction * action, m_actions) {
   101           delete action;
   122           delete action;
   102       }
   123       }
   103 
   124 
   104       delete m_widget;
   125       delete m_widget;
   105       foreach(GWebPage *page, m_superPages) {
   126       foreach(GSuperWebPage *page, m_superPages) {
   106           delete page;
   127           delete page;
   107       }
   128       }
   108   }
   129   }
   109 
   130 
       
   131 #ifdef BEDROCK_TILED_BACKING_STORE
       
   132 void GWebContentView::zoomIn(qreal deltaPercent)
       
   133 {
       
   134     //FIX ME : Do we need deltaPercent?
       
   135     Q_UNUSED(deltaPercent);
       
   136     m_widget->setPageZoom(true);
       
   137 }
       
   138 
       
   139 void GWebContentView::zoomOut(qreal deltaPercent)
       
   140 {
       
   141     //FIX ME : Do we need deltaPercent?
       
   142     Q_UNUSED(deltaPercent);
       
   143     m_widget->setPageZoom(false);
       
   144 }
       
   145 #endif
       
   146 
       
   147 #ifndef BEDROCK_TILED_BACKING_STORE
   110 void GWebContentView::bitmapZoomStop()
   148 void GWebContentView::bitmapZoomStop()
   111 {
   149 {
   112     if (m_timer) {
   150     if (m_timer) {
   113         m_timer->stop();
   151         m_timer->stop();
   114         disconnect(m_timer,SIGNAL(timeout()));
   152         disconnect(m_timer,SIGNAL(timeout()));
   204             webWidget()->setZoomFactor(m_value * webWidget()->zoomFactor());
   242             webWidget()->setZoomFactor(m_value * webWidget()->zoomFactor());
   205         }
   243         }
   206     }
   244     }
   207 }
   245 }
   208 
   246 
       
   247 #endif
   209   void GWebContentView::connectAll() {
   248   void GWebContentView::connectAll() {
   210     //qDebug() << "GWebContentView::connectAll: " << widget();
   249     //qDebug() << "GWebContentView::connectAll: " << widget();
   211 
   250 
   212 #ifndef __gva_no_chrome__
   251 #ifndef __gva_no_chrome__
       
   252 #ifndef BEDROCK_TILED_BACKING_STORE
   213     safe_connect(widget(), SIGNAL(contextEvent(::WebViewEventContext *)),
   253     safe_connect(widget(), SIGNAL(contextEvent(::WebViewEventContext *)),
   214                  m_jsObject, SLOT(onContextEvent(::WebViewEventContext *)));
   254                  m_jsObject, SLOT(onContextEvent(::WebViewEventContext *)));
       
   255 #else
       
   256     safe_connect(this
       
   257                  , SIGNAL(contextEvent(::WebViewEventContext*))
       
   258                  ,  m_jsObject
       
   259                  , SLOT(onContextEvent(::WebViewEventContext*)));
       
   260 
       
   261     safe_connect(m_widget
       
   262                 , SIGNAL(contextEventObject(QWebHitTestResult*))
       
   263                 , this
       
   264                 , SLOT(handleContextEventObject(QWebHitTestResult*)));
       
   265 
       
   266     safe_connect(m_widget
       
   267                  , SIGNAL(viewScrolled(QPoint&, QPoint&))
       
   268                  , this
       
   269                  , SLOT(handleViewScrolled(QPoint&, QPoint&)));
       
   270 #endif
   215     QObject::connect(webWidget(), SIGNAL(titleChanged(const QString &)), m_jsObject, SIGNAL(titleChanged(const QString &)));
   271     QObject::connect(webWidget(), SIGNAL(titleChanged(const QString &)), m_jsObject, SIGNAL(titleChanged(const QString &)));
   216     QObject::connect(webWidget(), SIGNAL(loadStarted()), m_jsObject, SIGNAL(loadStarted()));
   272     QObject::connect(webWidget(), SIGNAL(loadStarted()), m_jsObject, SIGNAL(loadStarted()));
   217     QObject::connect(webWidget(), SIGNAL(loadProgress(int)), m_jsObject, SIGNAL(loadProgress(int)));
   273     QObject::connect(webWidget(), SIGNAL(loadProgress(int)), m_jsObject, SIGNAL(loadProgress(int)));
   218     QObject::connect(webWidget(), SIGNAL(loadProgress(int)), this, SIGNAL(loadProgress(int)));
   274     QObject::connect(webWidget(), SIGNAL(loadProgress(int)), this, SIGNAL(loadProgress(int)));
   219 #endif
   275 #endif
   224     QObject::connect(this, SIGNAL(urlChanged(const QString&)), m_jsObject, SIGNAL(urlChanged(const QString&)));
   280     QObject::connect(this, SIGNAL(urlChanged(const QString&)), m_jsObject, SIGNAL(urlChanged(const QString&)));
   225     QObject::connect(this, SIGNAL(backEnabled(bool)), m_jsObject, SIGNAL(backEnabled(bool)));
   281     QObject::connect(this, SIGNAL(backEnabled(bool)), m_jsObject, SIGNAL(backEnabled(bool)));
   226     QObject::connect(this, SIGNAL(forwardEnabled(bool)), m_jsObject, SIGNAL(forwardEnabled(bool)));
   282     QObject::connect(this, SIGNAL(forwardEnabled(bool)), m_jsObject, SIGNAL(forwardEnabled(bool)));
   227     QObject::connect(this, SIGNAL(loadFinished(bool)), m_jsObject, SIGNAL(loadFinished(bool)));
   283     QObject::connect(this, SIGNAL(loadFinished(bool)), m_jsObject, SIGNAL(loadFinished(bool)));
   228     QObject::connect(this, SIGNAL(secureConnection(bool)), m_jsObject, SIGNAL(secureConnection(bool)));
   284     QObject::connect(this, SIGNAL(secureConnection(bool)), m_jsObject, SIGNAL(secureConnection(bool)));
       
   285 #ifndef BEDROCK_TILED_BACKING_STORE
   229     connect(m_touchNavigation, SIGNAL(startingPanGesture(int)), m_jsObject, SIGNAL(startingPanGesture(int)));
   286     connect(m_touchNavigation, SIGNAL(startingPanGesture(int)), m_jsObject, SIGNAL(startingPanGesture(int)));
       
   287 #endif
       
   288 	QObject::connect(this, SIGNAL(superPageShown(const QString&)), m_jsObject, SIGNAL(superPageShown(const QString&)));    
       
   289      
   230 #endif
   290 #endif
   231     connect(WebPageController::getSingleton(), SIGNAL(pageCreated(WRT::WrtBrowserContainer*)),
   291     connect(WebPageController::getSingleton(), SIGNAL(pageCreated(WRT::WrtBrowserContainer*)),
   232             this, SLOT(pageCreated(WRT::WrtBrowserContainer*)));
   292             this, SLOT(pageCreated(WRT::WrtBrowserContainer*)));
   233     connect(WebPageController::getSingleton(), SIGNAL(pageChanged(WRT::WrtBrowserContainer*, WRT::WrtBrowserContainer*)),
   293     connect(WebPageController::getSingleton(), SIGNAL(pageChanged(WRT::WrtBrowserContainer*, WRT::WrtBrowserContainer*)),
   234             this, SLOT(pageChanged(WRT::WrtBrowserContainer*, WRT::WrtBrowserContainer*)));
   294             this, SLOT(pageChanged(WRT::WrtBrowserContainer*, WRT::WrtBrowserContainer*)));
   248 
   308 
   249   QGraphicsWidget* GWebContentView::widget() const {
   309   QGraphicsWidget* GWebContentView::widget() const {
   250     return static_cast<QGraphicsWidget*>(m_widget);
   310     return static_cast<QGraphicsWidget*>(m_widget);
   251   }
   311   }
   252 
   312 
       
   313 #ifdef BEDROCK_TILED_BACKING_STORE
       
   314   QGraphicsWebView* GWebContentView::webWidget() const {
       
   315     return m_widget->webView();
       
   316   }
       
   317 #else
   253   GWebContentViewWidget *GWebContentView::webWidget() const {
   318   GWebContentViewWidget *GWebContentView::webWidget() const {
   254     return m_widget;
   319     return m_widget;
   255   }
   320   }
       
   321 #endif
   256 
   322 
   257   QString GWebContentView::title() const {
   323   QString GWebContentView::title() const {
   258     return webWidget()->title();
   324     return webWidget()->title();
   259   }
   325   }
   260 
   326 
   261   QUrl GWebContentView::url() {
   327   QUrl GWebContentView::url() {
   262     return webWidget()->url();
   328     return webWidget()->url();
   263   }
   329   }
   264 
   330 
   265   QWebPage* GWebContentView::wrtPage() {
   331   QWebPage* GWebContentView::wrtPage() {
       
   332 #ifdef BEDROCK_TILED_BACKING_STORE
       
   333     return m_widget->page();
       
   334 #else
   266     return m_widget->wrtPage();
   335     return m_widget->wrtPage();
       
   336 #endif
   267   }
   337   }
   268 
   338 
   269   void GWebContentView::setActions(){
   339   void GWebContentView::setActions(){
   270 
   340 
   271       QAction* action;
   341       QAction* action;
   301 
   371 
   302   }
   372   }
   303 
   373 
   304   void GWebContentView::triggerAction(const QString & action)
   374   void GWebContentView::triggerAction(const QString & action)
   305   {
   375   {
   306     qDebug() << "GWebContentView::triggerAction: " << action;
       
   307     QWebPage::WebAction webAction;
   376     QWebPage::WebAction webAction;
   308     if (action=="Stop")
   377     if (action=="Stop")
   309       webAction = QWebPage::Stop;
   378       webAction = QWebPage::Stop;
   310     else if (action=="Back")
   379     else if (action=="Back")
   311       webAction = QWebPage::Back;
   380       webAction = QWebPage::Back;
   323     m_actions.value("zoomIn")->setEnabled(false);
   392     m_actions.value("zoomIn")->setEnabled(false);
   324     m_actions.value("zoomOut")->setEnabled(false);
   393     m_actions.value("zoomOut")->setEnabled(false);
   325   }
   394   }
   326 
   395 
   327   void GWebContentView::changeZoomAction(qreal zoom){
   396   void GWebContentView::changeZoomAction(qreal zoom){
       
   397   #ifndef BEDROCK_TILED_BACKING_STORE
   328     if (!webWidget()) return;
   398     if (!webWidget()) return;
   329     if (!(webWidget()->isUserScalable() ) ){
   399     if (!(webWidget()->isUserScalable() ) ){
   330         deactivateZoomActions();
   400         deactivateZoomActions();
   331     }
   401     }
   332     else {
   402     else {
   344       }
   414       }
   345       else {
   415       else {
   346          zoomInAction->setEnabled(true);
   416          zoomInAction->setEnabled(true);
   347       }
   417       }
   348     }
   418     }
       
   419 #endif
   349   }
   420   }
   350 
   421 
   351   void GWebContentView::setZoomFactor(qreal factor){
   422   void GWebContentView::setZoomFactor(qreal factor){
   352     if (webWidget())
   423     if (webWidget())
       
   424 #ifdef BEDROCK_TILED_BACKING_STORE
       
   425         webWidget()->setScale(factor);
       
   426 #else
   353         webWidget()->setZoomFactor(factor);
   427         webWidget()->setZoomFactor(factor);
   354   }
   428 #endif
   355 
   429   }
       
   430 
       
   431 #ifdef BEDROCK_TILED_BACKING_STORE
       
   432 QGraphicsWidget* GWebContentView::webWidgetConst()  {
       
   433     return m_widget;
       
   434 }
       
   435 
       
   436 void GWebContentView::setZoomActions(bool enableZoomIn, bool enableZoomOut)
       
   437 {
       
   438     m_actions.value("zoomIn")->setEnabled(enableZoomIn);
       
   439     m_actions.value("zoomOut")->setEnabled(enableZoomOut);
       
   440 }
       
   441   qreal GWebContentView::getZoomFactor(){
       
   442     return webWidgetConst() ? webWidgetConst()->scale() : 0.0;
       
   443   }
       
   444 
       
   445 #else
   356   qreal GWebContentView::getZoomFactor() const {
   446   qreal GWebContentView::getZoomFactor() const {
   357     return webWidgetConst() ? webWidgetConst()->zoomFactor() : 0.0;
   447     return webWidgetConst() ? webWidgetConst()->zoomFactor() : 0.0;
   358   }
   448   }
   359 
   449 #endif
   360   void GWebContentView::activate() {
   450   
   361       qDebug() << "GWebContentView::activate";
   451 void GWebContentView::activate() {
   362       ControllableViewBase::activate();
   452 #ifdef BEDROCK_TILED_BACKING_STORE
       
   453     WRT::WrtBrowserContainer* newPage = WebPageController::getSingleton()->currentPage();
       
   454     changeContentViewZoomInfo(newPage);
       
   455 #endif
       
   456     ControllableViewBase::activate();
   363   }
   457   }
   364 
   458 
   365   void GWebContentView::deactivate() {
   459   void GWebContentView::deactivate() {
   366       qDebug() << "GWebContentView::deactivate";
   460 #ifdef BEDROCK_TILED_BACKING_STORE
       
   461     if (!currentPageIsSuperPage()) {
       
   462         WRT::WrtBrowserContainer* currentPage = WebPageController::getSingleton()->currentPage();
       
   463         currentPage->setPageZoomMetaData(m_widget->currentPageInfo());
       
   464     }
       
   465 #endif
   367       ControllableViewBase::deactivate();
   466       ControllableViewBase::deactivate();
   368   }
   467   }
   369 
   468 
   370 //  static void appendAction(QWebPage* page, QList<QAction*> &list, enum QWebPage::WebAction webAction, const QString &name) {
   469 //  static void appendAction(QWebPage* page, QList<QAction*> &list, enum QWebPage::WebAction webAction, const QString &name) {
   371 //      QAction *action = page->action(webAction);
   470 //      QAction *action = page->action(webAction);
   477     webWidget()->stop();
   576     webWidget()->stop();
   478   }
   577   }
   479 
   578 
   480   void GWebContentView::back()
   579   void GWebContentView::back()
   481   {
   580   {
   482     qDebug() << "GWebContentView::back";
       
   483     webWidget()->back();
   581     webWidget()->back();
   484   }
   582   }
   485 
   583 
   486   void GWebContentView::forward()
   584   void GWebContentView::forward()
   487   {
   585   {
   524     m_timeLine->stop();
   622     m_timeLine->stop();
   525   }
   623   }
   526 
   624 
   527   void GWebContentView::updateZoom(qreal delta){
   625   void GWebContentView::updateZoom(qreal delta){
   528     Q_UNUSED(delta)
   626     Q_UNUSED(delta)
       
   627 #ifndef BEDROCK_TILED_BACKING_STORE
   529     if (m_zoomIn)
   628     if (m_zoomIn)
   530       zoomBy(0.1);
   629       zoomBy(0.1);
   531     else
   630     else
   532       zoomBy(-0.1);
   631       zoomBy(-0.1);
       
   632 #endif
   533   }
   633   }
   534 
   634 
   535   void GWebContentView::onUrlChanged(const QUrl& url)
   635   void GWebContentView::onUrlChanged(const QUrl& url)
   536   {
   636   {
   537     emit urlChanged(url.toString());
   637     emit urlChanged(url.toString());
   540       emit secureConnection(true);
   640       emit secureConnection(true);
   541     else
   641     else
   542       emit secureConnection(false);
   642       emit secureConnection(false);
   543   }
   643   }
   544 
   644 
   545   GWebPage *GWebContentView::createSuperPage(const QString &name, bool persist) {
   645   GSuperWebPage *GWebContentView::createSuperPage(const QString &name, bool persist) {
   546     qDebug() << "GWebContentView::createSuperPage: " << name;
   646     GSuperWebPage *page = 0;
   547     GWebPage *page = 0;
       
   548     PageMap::iterator it = m_superPages.find(name);
   647     PageMap::iterator it = m_superPages.find(name);
   549     // If page doesn't exist create a new one.
   648     // If page doesn't exist create a new one.
   550     if (it == m_superPages.end()) {
   649     if (it == m_superPages.end()) {
   551 
   650 
   552       if (persist || !m_sharedPage){
   651       if (persist || !m_sharedPage){
   563           page->page()->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
   662           page->page()->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
   564           page->page()->mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff);
   663           page->page()->mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff);
   565           //No history for super pages
   664           //No history for super pages
   566           page->page()->history()->setMaximumItemCount(0);
   665           page->page()->history()->setMaximumItemCount(0);
   567           //Limit page cache usage by super pages
   666           //Limit page cache usage by super pages
   568           //TODO: This needs to be further tested to weigh the costs and benefits.
   667 
   569           page->page()->settings()->setMaximumPagesInCache(2);
       
   570           //NB: needed?
   668           //NB: needed?
   571           QPalette viewPalette = widget()->palette();
   669           QPalette viewPalette = widget()->palette();
   572           viewPalette.setBrush(QPalette::Base, Qt::white);
   670           viewPalette.setBrush(QPalette::Base, Qt::white);
   573           page->page()->setPalette(viewPalette);
   671           page->page()->setPalette(viewPalette);
   574       } else {
   672       } else {
   586       }
   684       }
   587     }
   685     }
   588     else {
   686     else {
   589       qDebug() << "GWebContentView::createPage: page already exists: " << name;
   687       qDebug() << "GWebContentView::createPage: page already exists: " << name;
   590     }
   688     }
       
   689     //Create a controllable view onto the super page so that it can be controlled by the view controller.
       
   690     m_chrome->addView(new SuperPageView(this, page, name));
   591     return page;
   691     return page;
   592   }
   692   }
   593 
   693 
   594   void GWebContentView::destroySuperPage(const QString &name) {
   694   void GWebContentView::destroySuperPage(const QString &name) {
   595     qDebug() << "GWebContentView::destroySuperPage: " << name;
       
   596     if (!m_superPages.contains(name)) return;
   695     if (!m_superPages.contains(name)) return;
   597 
   696 
   598     GWebPage *page = m_superPages.take(name);
   697     GSuperWebPage *page = m_superPages.take(name);
   599     //This will destroy any QWebPage owned by the super page. The shared page is not
   698     //This will destroy any QWebPage owned by the super page. The shared page is not
   600     //owned by the super page and will be deleted when the GWebContentView is deleted.
   699     //owned by the super page and will be deleted when the GWebContentView is deleted.
   601     if (page){
   700     if (page){
   602         delete page;
   701         delete page;
   603     }
   702     }
   604   }
   703   }
   605 
   704 
   606   void GWebContentView::setCurrentSuperPage(const QString &name) {
   705   bool GWebContentView::setCurrentSuperPage(const QString &name) {
   607     PageMap::iterator it = m_superPages.find(name);
   706     PageMap::iterator it = m_superPages.find(name);
   608     if (it != m_superPages.end()) {
   707     if (it != m_superPages.end()) {
   609       m_currentSuperPage = it;
   708       m_currentSuperPage = it;
       
   709       return true;
   610     }
   710     }
   611     else {
   711     else {
   612       qDebug() << "GWebContentView::setCurrentSuperPage: not found: " << name;
   712       qDebug() << "GWebContentView::setCurrentSuperPage: not found: " << name;
       
   713       return false;
   613     }
   714     }
   614   }
   715   }
   615 
   716 
   616   bool GWebContentView::isSuperPage(const QString &name){
   717   bool GWebContentView::isSuperPage(const QString &name){
   617       PageMap::iterator it = m_superPages.find(name);
   718       PageMap::iterator it = m_superPages.find(name);
   618         if (it != m_superPages.end()) {
   719       if (it != m_superPages.end()) {
   619           return true;
   720         return true;
   620         }
   721       }
   621         qDebug() << "GWebContentView::superPage: not found: " << name;
   722       qDebug() << "GWebContentView::superPage: not found: " << name;
   622         return false;
   723       return false;
   623  }
   724  }
   624 
   725 
   625 
   726 
   626   GWebPage * GWebContentView::superPage(const QString &name) {
   727   GSuperWebPage * GWebContentView::superPage(const QString &name) {
   627     PageMap::iterator it = m_superPages.find(name);
   728       PageMap::iterator it = m_superPages.find(name);
   628     if (it != m_superPages.end()) {
   729       if (it != m_superPages.end()) {
   629       return it.value();
   730           return it.value();
   630     }
   731       }
   631     qDebug() << "GWebContentView::superPage: not found: " << name;
   732       qDebug() << "GWebContentView::superPage: not found: " << name;
   632     return 0;
   733       return 0;
   633   }
   734   }
   634 
   735 
   635   void GWebContentView::showSuperPage(const QString &name) {
   736   void GWebContentView::showSuperPage(const QString &name) {
   636     setCurrentSuperPage(name);
   737       if(isSuperPage(name)) {
   637     qDebug() << "GWebContentView::showSuperPage: " << currentSuperPage();
   738           if(currentPageIsSuperPage()) {
   638     m_currentPageIsSuperPage = true;
   739               currentSuperPage()->onHidden();
   639     webWidget()->setPage(currentSuperPage()->page());
   740           }
   640     m_touchNavigation->setPage(webWidget()->page());
   741 
   641     m_touchNavigation->setWantSlideViewCalls(false);
   742           setCurrentSuperPage(name);
   642     webWidget()->page()->setPreferredContentsSize(webWidget()->size().toSize());
   743           m_currentPageIsSuperPage = true;
       
   744 #ifndef BEDROCK_TILED_BACKING_STORE
       
   745           webWidget()->setPage(currentSuperPage()->page());
       
   746           m_touchNavigation->setPage(webWidget()->page());
       
   747           m_touchNavigation->setWantSlideViewCalls(false);
       
   748           webWidget()->page()->setPreferredContentsSize(webWidget()->size().toSize());
       
   749 #else
       
   750           WRT::WrtBrowserContainer *pg = WebPageController::getSingleton()->currentPage();
       
   751           pg->setPageZoomMetaData(m_widget->currentPageInfo());
       
   752           m_widget->setPage(currentSuperPage()->page());
       
   753           m_widget->showPage(true);
       
   754 #endif  
       
   755           emit superPageShown(name);
       
   756           currentSuperPage()->onShown();
       
   757       }
       
   758       else {
       
   759           qDebug() << "GWebContentView::showSuperPage: error, not found: " << name;
       
   760       }
   643   }
   761   }
   644 
   762 
   645   void GWebContentView::showNormalPage() {
   763   void GWebContentView::showNormalPage() {
   646     if (webWidget()) {
   764     if (webWidget()) {
       
   765 #ifndef BEDROCK_TILED_BACKING_STORE
   647       webWidget()->showNormalPage();
   766       webWidget()->showNormalPage();
   648       webWidget()->setViewportSize();
   767       webWidget()->setViewportSize();
   649       m_touchNavigation->setPage(currentPage());
   768       m_touchNavigation->setPage(currentPage());
   650       m_touchNavigation->setWantSlideViewCalls(true);
   769       m_touchNavigation->setWantSlideViewCalls(true);
       
   770 #else
       
   771         m_widget->showPage(false);
       
   772 #endif
   651       //TODO: Further testing is needed to show if the following is a net benefit.
   773       //TODO: Further testing is needed to show if the following is a net benefit.
   652       if (m_currentPageIsSuperPage && (currentSuperPage()->page() == m_sharedPage)){
   774       if (currentPageIsSuperPage()) {
   653           //Clear contents of shared page to free resources. This should save
   775           if(currentSuperPage()->page() == m_sharedPage){
   654           //memory for big pages, but at the performance cost of loading an empty page.
   776               //Clear contents of shared page to free resources. This should save
   655           //An alternative is to delete the shared page every time and reallocate it when
   777               //memory for big pages, but at the performance cost of loading an empty page.
   656           //a super page is loaded.
   778               //An alternative is to delete the shared page every time and reallocate it when
   657           currentSuperPage()->page()->mainFrame()->setHtml(QString());
   779               //a super page is loaded.
   658       }
   780               currentSuperPage()->page()->mainFrame()->setHtml(QString());
   659       m_currentPageIsSuperPage =false;
   781           }
       
   782 
       
   783           currentSuperPage()->onHidden();
       
   784           m_currentPageIsSuperPage =false;
       
   785       }
   660     }
   786     }
   661   }
   787   }
   662 
   788 
   663   QObjectList GWebContentView::getSuperPages() {
   789   QObjectList GWebContentView::getSuperPages() {
   664     QObjectList *result = new QObjectList;
   790     QObjectList *result = new QObjectList;
   665     foreach(GVA::GWebPage *page, m_superPages) {
   791     foreach(GVA::GSuperWebPage *page, m_superPages) {
   666       result->append(page);
   792       result->append(page);
   667     }
   793     }
   668     // TO DO: Need to add result to JS engine so it can be cleaned up.
   794     // TO DO: Need to add result to JS engine so it can be cleaned up.
   669     return *result;
   795     return *result;
   670   }
   796   }
   717     qDebug() << "-------------";
   843     qDebug() << "-------------";
   718     qDebug() << "GWebContentView::dump: " << this;
   844     qDebug() << "GWebContentView::dump: " << this;
   719     qDebug() << "\tcurrent page=: " << currentPage() << " title=" << currentPage()->mainFrame()->title();
   845     qDebug() << "\tcurrent page=: " << currentPage() << " title=" << currentPage()->mainFrame()->title();
   720     qDebug() << "\tcurrent superpage=: " << currentSuperPage();
   846     qDebug() << "\tcurrent superpage=: " << currentSuperPage();
   721     qDebug() << "\tsuperpage count=: " << m_superPages.count();
   847     qDebug() << "\tsuperpage count=: " << m_superPages.count();
   722     foreach(GVA::GWebPage *page, m_superPages) {
   848     foreach(GVA::GSuperWebPage *page, m_superPages) {
   723       page->dump();
   849       page->dump();
   724     }
   850     }
   725     qDebug() << "GWebContentView::dump: finished";
   851     qDebug() << "GWebContentView::dump: finished";
   726     qDebug() << "-------------";
   852     qDebug() << "-------------";
   727   }
   853   }
   733 //  }
   859 //  }
   734 
   860 
   735 
   861 
   736   void GWebContentView::pageCreated(WRT::WrtBrowserContainer* newPage) {
   862   void GWebContentView::pageCreated(WRT::WrtBrowserContainer* newPage) {
   737 
   863 
   738       qDebug() << "GWebContentView::pageCreated";
       
   739       /* save the page snapshot before changing the current page to the new page*/
   864       /* save the page snapshot before changing the current page to the new page*/
   740       WRT::WrtBrowserContainer * currPage = WebPageController::getSingleton()->currentPage();
   865       WRT::WrtBrowserContainer * currPage = WebPageController::getSingleton()->currentPage();
   741       if (currPage) {
   866       if (currPage) {
   742           QWebHistoryItem item = currPage->history()->currentItem();
   867           QWebHistoryItem item = currPage->history()->currentItem();
   743           currPage->savePageDataToHistoryItem(currPage->mainFrame(), &item);
   868           currPage->savePageDataToHistoryItem(currPage->mainFrame(), &item);
   745 
   870 
   746       // When new windows are created from window view, as the content is empty, we should disable
   871       // When new windows are created from window view, as the content is empty, we should disable
   747       // zoom actions. Set the user-scalable to false and also init the other zoom params
   872       // zoom actions. Set the user-scalable to false and also init the other zoom params
   748       // so that even if we change to windows view again without loading a page we are safe.
   873       // so that even if we change to windows view again without loading a page we are safe.
   749       // In the code-driven window usecase, this will be overwritten when the page is loaded and setViewportSize is invoked
   874       // In the code-driven window usecase, this will be overwritten when the page is loaded and setViewportSize is invoked
       
   875 #ifndef BEDROCK_TILED_BACKING_STORE
   750       newPage->setPageZoomMetaData(webWidget()->defaultZoomData());
   876       newPage->setPageZoomMetaData(webWidget()->defaultZoomData());
   751 
   877 #else
       
   878 	newPage->setPageZoomMetaData(m_widget->defaultZoomData());
       
   879 #endif
   752       /* Set the new page as the current page */
   880       /* Set the new page as the current page */
   753       WebPageController::getSingleton()->setCurrentPage(newPage);
   881       WebPageController::getSingleton()->setCurrentPage(newPage);
   754 
   882 
   755       /* Set the web widget- this one is responsible for webnavigation etc */
   883       /* Set the web widget- this one is responsible for webnavigation etc */
   756       newPage->setWebWidget(webWidget());
   884       newPage->setWebWidget(webWidget());
   757 
   885 
       
   886 #ifndef BEDROCK_TILED_BACKING_STORE
   758       //connect new page main frame's initialLayoutCompleted with WebContentWidget' setViewportSize SLOT
   887       //connect new page main frame's initialLayoutCompleted with WebContentWidget' setViewportSize SLOT
   759       connect(newPage->mainFrame(), SIGNAL(initialLayoutCompleted()), webWidget(), SLOT(setViewportSize()));
   888       connect(newPage->mainFrame(), SIGNAL(initialLayoutCompleted()), webWidget(), SLOT(setViewportSize()));
       
   889 #endif
   760   }
   890   }
   761 
   891 
   762   void GWebContentView::updateWebPage(WRT::WrtBrowserContainer* pg)
   892   void GWebContentView::updateWebPage(WRT::WrtBrowserContainer* pg)
   763   {
   893   {
       
   894 #ifdef BEDROCK_TILED_BACKING_STORE
       
   895       QGraphicsWebView* w = webWidget();
       
   896 #else
   764       GWebContentViewWidget* w = webWidget();
   897       GWebContentViewWidget* w = webWidget();
       
   898 #endif
       
   899 	  
       
   900 #ifndef BEDROCK_TILED_BACKING_STORE
   765       w->setPage(pg);
   901       w->setPage(pg);
       
   902 #else	  
       
   903 	  m_widget->setPage(pg);
       
   904 #endif
   766       if (pg)
   905       if (pg)
   767       {
   906       {
   768           pg->setWebWidget(w);
   907           pg->setWebWidget(w);
   769 
   908 
       
   909 #ifndef BEDROCK_TILED_BACKING_STORE
   770           // Change navigation also to the current page
   910           // Change navigation also to the current page
   771           m_touchNavigation->setPage(pg);
   911           m_touchNavigation->setPage(pg);
   772           m_touchNavigation->setWantSlideViewCalls(true);
   912           m_touchNavigation->setWantSlideViewCalls(true);
       
   913 #endif
   773 
   914 
   774       }
   915       }
   775   }
   916   }
   776 
   917 
   777   void GWebContentView::pageChanged(WRT::WrtBrowserContainer* oldPage, WRT::WrtBrowserContainer* newPage) {
   918   void GWebContentView::pageChanged(WRT::WrtBrowserContainer* oldPage, WRT::WrtBrowserContainer* newPage) {
   778     qDebug() << "GWebContentView::pageChanged";
       
   779       Q_UNUSED(oldPage)
   919       Q_UNUSED(oldPage)
   780       updateWebPage(newPage);
   920       updateWebPage(newPage);
   781 
   921 
       
   922 #ifndef BEDROCK_TILED_BACKING_STORE
   782       // Set new page zoom info
   923       // Set new page zoom info
   783       changeContentViewZoomInfo(newPage);
   924       changeContentViewZoomInfo(newPage);
   784   }
   925 #endif
   785 
   926   }
       
   927 
       
   928 #ifdef BEDROCK_TILED_BACKING_STORE
       
   929   void GWebContentView::handleContextEventObject(QWebHitTestResult* eventTarget)
       
   930   {
       
   931       WebViewEventContext context(type(), *eventTarget);
       
   932       if (currentPageIsSuperPage()) {
       
   933           // Let the superpage handle the event.
       
   934           currentSuperPage()->onContextEvent(&context);
       
   935       }
       
   936       else {
       
   937           // Send the event directly.
       
   938           emit contextEvent(&context);
       
   939       }
       
   940   }
       
   941 void GWebContentView::handleViewScrolled(QPoint& scrollPos, QPoint& delta)
       
   942 {
       
   943     if (delta.manhattanLength() && scrollPos.y() <= 5 && !currentPageIsSuperPage())
       
   944         m_chrome->layout()->slideView(-delta.y());
       
   945 }
       
   946 
       
   947 #endif
   786   void GWebContentView::changeContentViewZoomInfo(WRT::WrtBrowserContainer* newPage){
   948   void GWebContentView::changeContentViewZoomInfo(WRT::WrtBrowserContainer* newPage){
   787      // Copy the new page zoom info into cv
   949      // Copy the new page zoom info into cv
       
   950 #ifndef BEDROCK_TILED_BACKING_STORE
   788      webWidget()->setPageZoomMetaData(newPage->pageZoomMetaData());
   951      webWidget()->setPageZoomMetaData(newPage->pageZoomMetaData());
   789 
   952 
   790      if (webWidget()->isUserScalable()) {
   953      if (webWidget()->isUserScalable()) {
   791          webWidget()->setZoomFactor(newPage->mainFrame()->zoomFactor());
   954          webWidget()->setZoomFactor(newPage->mainFrame()->zoomFactor());
   792      }
   955      }
   795          // will not do anything if user-scalable is false. But we need to
   958          // will not do anything if user-scalable is false. But we need to
   796          // ensure that the correct zoom factor is applied as there is a possibility
   959          // ensure that the correct zoom factor is applied as there is a possibility
   797          // that we might have been on another page earlier
   960          // that we might have been on another page earlier
   798          webWidget()->setPageZoomFactor(newPage->mainFrame()->zoomFactor());
   961          webWidget()->setPageZoomFactor(newPage->mainFrame()->zoomFactor());
   799       }
   962       }
       
   963 #else
       
   964 	 m_widget->setCurrentPageInfo(newPage->pageZoomMetaData());
       
   965 #endif
   800   }
   966   }
   801 
   967 
   802   void GWebContentView::setJSObject(const QString &objectName) {
   968   void GWebContentView::setJSObject(const QString &objectName) {
   803       m_jsObject = new GWebContentViewJSObject(this, m_chrome->page()->mainFrame(), objectName);
   969       m_jsObject = new GWebContentViewJSObject(this, m_chrome->page()->mainFrame(), objectName);
   804   }
   970   }
   807   bool GWebContentView::enabled() const {
   973   bool GWebContentView::enabled() const {
   808       return m_enabled;
   974       return m_enabled;
   809   }
   975   }
   810 
   976 
   811   void GWebContentView::setEnabled(bool value) {
   977   void GWebContentView::setEnabled(bool value) {
   812       qDebug() << "GWebContentView::setEnabled: " << value;
       
   813       if(m_enabled == value)
   978       if(m_enabled == value)
   814           return;
   979           return;
   815 
   980 
   816       m_enabled = value;
   981       m_enabled = value;
   817       widget()->setEnabled(value);
   982       widget()->setEnabled(value);