ginebra2/ContentViews/GWebContentView.cpp
changeset 0 1450b09d0cfd
child 3 0954f5dd2cd0
child 5 0f2326c2a325
equal deleted inserted replaced
-1:000000000000 0:1450b09d0cfd
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "GWebContentView.h"
       
    20 #include "GWebContentViewWidget.h"
       
    21 #include "GWebContentViewJSObject.h"
       
    22 #include "ChromeWidget.h"
       
    23 #include "WebViewEventContext.h"
       
    24 #include "browserpagefactory.h"
       
    25 #include "wrtbrowsercontainer.h"
       
    26 #include "webpagecontroller.h"
       
    27 #ifndef NO_QSTM_GESTURE
       
    28 #include "qstmgestureevent.h"
       
    29 #endif
       
    30 
       
    31 #include <QGraphicsWebView>
       
    32 #include <QWebHistory>
       
    33 #include <QWebPage>
       
    34 #include <QWebFrame>
       
    35 #include <QTimeLine>
       
    36 #include <QDebug>
       
    37 
       
    38 
       
    39 #define safe_connect(src, srcSig, target, targetSlot) \
       
    40   { int res = connect(src, srcSig, target, targetSlot); assert(res); }
       
    41 
       
    42 namespace GVA {
       
    43 
       
    44 
       
    45   // ----------------------------------------------------------
       
    46 
       
    47   const qreal KZoomInStep = 1.05;
       
    48   const qreal KZoomOutStep = 0.95238;
       
    49   
       
    50   GWebContentView::GWebContentView(ChromeWidget *chrome, QObject * parent, const QString &objectName)
       
    51     : ControllableViewBase(parent),
       
    52       m_networkMgr(0),
       
    53       m_chrome(chrome),
       
    54       m_timeLine(0),
       
    55       m_zoomIn(false),
       
    56       m_backEnabled(false),
       
    57       m_forwardEnabled(false),
       
    58       m_currentSuperPage(m_superPages.begin()),
       
    59       m_currentPageIsSuperPage(false),
       
    60       m_timer(NULL)
       
    61   {
       
    62       setObjectName(objectName);
       
    63       qDebug() << "GWebContentView::GWebContentView: this=" << this;
       
    64       QWebPage* page = BrowserPageFactory::openBrowserPage();
       
    65 
       
    66       setZoomActions();
       
    67       m_widget = new GWebContentViewWidget(parent, this, page);
       
    68 #ifndef __gva_no_chrome__
       
    69       m_jsObject = new GWebContentViewJSObject(this, m_chrome->page()->mainFrame(), objectName);
       
    70 #endif
       
    71       m_networkMgr = webWidget()->page()->networkAccessManager();
       
    72 
       
    73       webWidget()->page()->currentFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
       
    74       webWidget()->page()->currentFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff);
       
    75 
       
    76 #ifdef NO_QSTM_GESTURE
       
    77       m_touchNavigation = new GWebTouchNavigation(page, m_widget);
       
    78       m_touchNavigation->setChromeWidget(m_chrome);
       
    79       connect(m_touchNavigation, SIGNAL(mouseEvent(QEvent::Type)) , this, SIGNAL(contentViewMouseEvent(QEvent::Type)));
       
    80 #endif
       
    81       WRT::WrtBrowserContainer * wrtPage = static_cast<WRT::WrtBrowserContainer *>(page);
       
    82       if(wrtPage) {
       
    83           wrtPage->setWebWidget(webWidget());
       
    84           pageCreated(wrtPage);
       
    85       }
       
    86 
       
    87       connectAll();
       
    88   }
       
    89 
       
    90   GWebContentView::~GWebContentView() {
       
    91       disconnect(m_jsObject);
       
    92       disconnect(webWidget());
       
    93       delete m_touchNavigation;
       
    94       delete m_actionZoomIn;
       
    95       delete m_actionZoomOut;
       
    96       delete m_widget;
       
    97       foreach(GWebPage *page, m_superPages) {
       
    98           delete page;
       
    99       }
       
   100   }
       
   101 
       
   102 void GWebContentView::bitmapZoomStop()
       
   103 {
       
   104     if (m_timer) {
       
   105         m_timer->stop();
       
   106         disconnect(m_timer,SIGNAL(timeout()));
       
   107         delete m_timer;
       
   108         m_timer = NULL;	
       
   109     }
       
   110     qreal zoomFactor = m_value * webWidget()->zoomFactor();
       
   111     ((zoomFactor+0.001) >= webWidget()->maximumScale() )? webWidget()->setZoomFactor(webWidget()->maximumScale()):webWidget()->setZoomFactor(zoomFactor);
       
   112     webWidget()->bitmapZoomCleanup();
       
   113 }
       
   114 
       
   115 void GWebContentView::zoomP()
       
   116 {
       
   117     if ((m_value * webWidget()->zoomFactor()) >  webWidget()->maximumScale()) {
       
   118         if (m_timer && m_timer->isActive())
       
   119             bitmapZoomStop();
       
   120     }else {
       
   121         if (m_timer->isSingleShot()) {
       
   122             m_timer->setSingleShot(false);
       
   123             m_timer->start(1);
       
   124         }
       
   125         webWidget()->setBitmapZoom(m_value * webWidget()->zoomFactor());
       
   126         m_value *= KZoomInStep;
       
   127     }
       
   128 }
       
   129 
       
   130 void GWebContentView::zoomN()
       
   131 {
       
   132     if ((m_value * webWidget()->zoomFactor()) <  webWidget()->minimumScale()){
       
   133         if (m_timer && m_timer->isActive())
       
   134             bitmapZoomStop();	
       
   135     }else {
       
   136         if (m_timer->isSingleShot()) {
       
   137             m_timer->setSingleShot(false);
       
   138             m_timer->start(1);
       
   139         }
       
   140         webWidget()->setBitmapZoom(m_value * webWidget()->zoomFactor());
       
   141         m_value *= KZoomOutStep;
       
   142     }
       
   143 }
       
   144 
       
   145 void GWebContentView::zoomIn(qreal deltaPercent)	
       
   146 {
       
   147     Q_UNUSED(deltaPercent)
       
   148     if (webWidget() && webWidget()->isUserScalable()) {
       
   149         if (m_timer && m_timer->isActive()) {
       
   150             if (!m_timer->isSingleShot())
       
   151                 m_value /= KZoomInStep;
       
   152             bitmapZoomStop();
       
   153 	        return;
       
   154         }else if (!m_timer)
       
   155             m_timer = new QTimer(this);
       
   156   
       
   157         m_value = KZoomInStep;
       
   158 	
       
   159         if ((m_value * webWidget()->zoomFactor()) <  webWidget()->maximumScale()) {
       
   160             webWidget()->createPageSnapShot();
       
   161             connect(m_timer,SIGNAL(timeout()),this,SLOT(zoomP()));
       
   162             zoomP();
       
   163             m_timer->setSingleShot(true);
       
   164             m_timer->start(500);
       
   165         }else {
       
   166             delete m_timer;
       
   167             m_timer = NULL;
       
   168             webWidget()->setZoomFactor(m_value * webWidget()->zoomFactor());
       
   169         }
       
   170     }   
       
   171 }
       
   172 
       
   173 void GWebContentView::zoomOut(qreal deltaPercent)	
       
   174 {
       
   175     Q_UNUSED(deltaPercent)
       
   176     if (webWidget() && webWidget()->isUserScalable()) {
       
   177         if (m_timer && m_timer->isActive()) {
       
   178             if (!m_timer->isSingleShot())
       
   179                 m_value /= KZoomOutStep;
       
   180             bitmapZoomStop();
       
   181             return;
       
   182         }else if (!m_timer)
       
   183             m_timer = new QTimer(this);
       
   184  
       
   185         m_value = KZoomOutStep;
       
   186 
       
   187         if ((m_value * webWidget()->zoomFactor()) >  webWidget()->minimumScale()) {
       
   188             webWidget()->createPageSnapShot();
       
   189             connect(m_timer,SIGNAL(timeout()),this,SLOT(zoomN()));
       
   190             zoomN();
       
   191             m_timer->setSingleShot(true);
       
   192             m_timer->start(500);
       
   193         }else {
       
   194             delete m_timer;
       
   195             m_timer = NULL;
       
   196             webWidget()->setZoomFactor(m_value * webWidget()->zoomFactor());
       
   197         }
       
   198     }
       
   199 }
       
   200 
       
   201   void GWebContentView::connectAll() {
       
   202     //qDebug() << "GWebContentView::connectAll: " << widget();
       
   203 
       
   204 #ifndef __gva_no_chrome__
       
   205     safe_connect(widget(), SIGNAL(contextEvent(::WebViewEventContext *)),
       
   206                  m_jsObject, SLOT(onContextEvent(::WebViewEventContext *)));
       
   207     QObject::connect(webWidget(), SIGNAL(titleChanged(const QString &)), m_jsObject, SIGNAL(titleChanged(const QString &)));
       
   208     QObject::connect(webWidget(), SIGNAL(loadStarted()), m_jsObject, SIGNAL(loadStarted()));
       
   209     QObject::connect(webWidget(), SIGNAL(loadProgress(int)), m_jsObject, SIGNAL(loadProgress(int)));
       
   210 #endif
       
   211     QObject::connect(webWidget(), SIGNAL(loadStarted()), this, SLOT(onLoadStarted()));
       
   212     QObject::connect(webWidget(), SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool)));
       
   213     QObject::connect(webWidget(), SIGNAL(urlChanged(const QUrl&)), this, SLOT(onUrlChanged(const QUrl&)));
       
   214 #ifndef __gva_no_chrome__
       
   215     QObject::connect(this, SIGNAL(urlChanged(const QString&)), m_jsObject, SIGNAL(urlChanged(const QString&)));
       
   216     QObject::connect(this, SIGNAL(backEnabled(bool)), m_jsObject, SIGNAL(backEnabled(bool)));
       
   217     QObject::connect(this, SIGNAL(forwardEnabled(bool)), m_jsObject, SIGNAL(forwardEnabled(bool)));
       
   218     QObject::connect(this, SIGNAL(loadFinished(bool)), m_jsObject, SIGNAL(loadFinished(bool)));
       
   219     QObject::connect(this, SIGNAL(secureConnection(bool)), m_jsObject, SIGNAL(secureConnection(bool)));
       
   220     connect(m_touchNavigation, SIGNAL(startingPanGesture(int)), m_jsObject, SIGNAL(startingPanGesture(int)));
       
   221 #endif
       
   222     connect(WebPageController::getSingleton(), SIGNAL(pageCreated(WRT::WrtBrowserContainer*)),
       
   223             this, SLOT(pageCreated(WRT::WrtBrowserContainer*)));
       
   224     connect(WebPageController::getSingleton(), SIGNAL(pageChanged(WRT::WrtBrowserContainer*, WRT::WrtBrowserContainer*)),
       
   225             this, SLOT(pageChanged(WRT::WrtBrowserContainer*, WRT::WrtBrowserContainer*)));    
       
   226   }
       
   227 
       
   228   QVariant GWebContentView::getContentWindowObject() {
       
   229     try {
       
   230         return webWidget()->page()->mainFrame()->evaluateJavaScript("window");
       
   231     }
       
   232     catch(...) {
       
   233         qDebug() << "GWebContentView::getContentWindowObject: caught expection";
       
   234         return QVariant();
       
   235     }
       
   236   }
       
   237 
       
   238   QGraphicsWidget* GWebContentView::widget() const {
       
   239     return static_cast<QGraphicsWidget*>(m_widget);
       
   240   }
       
   241 
       
   242   GWebContentViewWidget *GWebContentView::webWidget() const {
       
   243     return m_widget;
       
   244   }
       
   245 
       
   246   QString GWebContentView::title() const {
       
   247     return webWidget()->title();
       
   248   }
       
   249 
       
   250   QUrl GWebContentView::url() {
       
   251     return webWidget()->url();
       
   252   }
       
   253 
       
   254   QWebPage* GWebContentView::wrtPage() {
       
   255     return m_widget->wrtPage();
       
   256   }
       
   257 
       
   258   void GWebContentView::setZoomActions(){
       
   259 
       
   260       // Create zoomIn and zoomOut actions */
       
   261       m_actionZoomIn = new QAction("zoomIn", this);
       
   262       m_actionZoomIn->setObjectName("zoomIn");
       
   263 
       
   264       m_actionZoomOut = new QAction("zoomOut", this);
       
   265       m_actionZoomOut->setObjectName("zoomOut");
       
   266       /* Disable zoomOut action initially as we are the the minimum scale */
       
   267       /* Revisit this to determine whether we can use the change signal to
       
   268        * set the zoomOut button image initially as well
       
   269        */
       
   270       m_actionZoomOut->setEnabled(false);
       
   271 
       
   272       connect(m_actionZoomIn, SIGNAL(triggered()), this, SLOT(zoomIn()));
       
   273       connect(m_actionZoomOut, SIGNAL(triggered()), this, SLOT(zoomOut()));
       
   274   }
       
   275 
       
   276   void GWebContentView::triggerAction(const QString & action)
       
   277   {
       
   278     qDebug() << "GWebContentView::triggerAction: " << action;
       
   279     QWebPage::WebAction webAction;
       
   280     if(action=="Stop")
       
   281       webAction = QWebPage::Stop;
       
   282     else if (action=="Back")
       
   283       webAction = QWebPage::Back;
       
   284     else if(action=="Reload")
       
   285       webAction = QWebPage::Reload;
       
   286     else if (action=="Forward")
       
   287       webAction = QWebPage::Forward;
       
   288     else
       
   289       return;
       
   290     webWidget()->triggerPageAction(webAction);
       
   291   }
       
   292 
       
   293   void GWebContentView::deactivateZoomActions()
       
   294   {
       
   295     m_actionZoomOut->setEnabled(false);
       
   296     m_actionZoomIn->setEnabled(false);
       
   297   }
       
   298  
       
   299   void GWebContentView::changeZoomAction(qreal zoom){
       
   300     if(!webWidget()) return;
       
   301     if(!(webWidget()->isUserScalable() ) ){
       
   302         deactivateZoomActions();
       
   303     }
       
   304     else {
       
   305       if (zoom <= webWidget()->minimumScale() ) {
       
   306          m_actionZoomOut->setEnabled(false);
       
   307       }
       
   308       else {
       
   309          m_actionZoomOut->setEnabled(true);
       
   310       }
       
   311 
       
   312       if (zoom >= webWidget()->maximumScale()  ){
       
   313          m_actionZoomIn->setEnabled(false);
       
   314       }
       
   315       else {
       
   316          m_actionZoomIn->setEnabled(true);
       
   317       }
       
   318     }
       
   319   }
       
   320 
       
   321   void GWebContentView::setZoomFactor(qreal factor){
       
   322     if(webWidget())
       
   323         webWidget()->setZoomFactor(factor);
       
   324   }
       
   325 
       
   326   qreal GWebContentView::getZoomFactor() const {
       
   327     return webWidgetConst() ? webWidgetConst()->zoomFactor() : 0.0;
       
   328   }
       
   329 
       
   330   void GWebContentView::activate() {
       
   331       qDebug() << "GWebContentView::activate";
       
   332       ControllableViewBase::activate();
       
   333   }
       
   334 
       
   335   void GWebContentView::deactivate() {
       
   336       qDebug() << "GWebContentView::deactivate";
       
   337       ControllableViewBase::deactivate();
       
   338   }
       
   339 
       
   340 //  static void appendAction(QWebPage* page, QList<QAction*> &list, enum QWebPage::WebAction webAction, const QString &name) {
       
   341 //      QAction *action = page->action(webAction);
       
   342 //      if(action) {
       
   343 //          action->setObjectName(name);
       
   344 //          list.append(action);
       
   345 //      }
       
   346 //  }
       
   347 
       
   348   /*!
       
   349     Return the list of public QActions most relevant to the view's current context.
       
   350     @return  List of public actions
       
   351   */
       
   352   QList<QAction *> GWebContentView::getContext()
       
   353   {
       
   354       // Get some of the actions from the page (there are many more available) and build a list
       
   355       // list of them.
       
   356 
       
   357       QList<QAction*> actions;
       
   358 
       
   359       /* Add zoomIn and zoomOut actions created earlier*/
       
   360       if(m_actionZoomIn) actions.append(m_actionZoomIn);
       
   361       if(m_actionZoomOut) actions.append(m_actionZoomOut);
       
   362 
       
   363       return actions;
       
   364   }
       
   365 
       
   366 
       
   367   QAction * GWebContentView::getAction(const QString & action)
       
   368   {
       
   369     if(action == "zoomIn")
       
   370       return m_actionZoomIn;
       
   371     if(action == "zoomOut")
       
   372       return m_actionZoomOut;
       
   373     QWebPage::WebAction webAction;
       
   374     if(action == "Back")
       
   375       webAction = QWebPage::Back;
       
   376     else if(action == "Forward")
       
   377       webAction = QWebPage::Forward;
       
   378     else if(action == "Stop")
       
   379       webAction = QWebPage::Stop;
       
   380     else if(action == "Reload")
       
   381       webAction = QWebPage::Reload;
       
   382     else return 0;
       
   383     return webWidget()->pageAction(webAction);
       
   384   }
       
   385 
       
   386   void GWebContentView::scrollViewBy(int dx, int dy)
       
   387   {
       
   388       wrtPage()->mainFrame()->scroll(dx, dy);
       
   389   }
       
   390 
       
   391   void GWebContentView::scrollViewTo(int x, int y)
       
   392   {
       
   393       wrtPage()->mainFrame()->setScrollPosition(QPoint(x, y));
       
   394   }
       
   395 
       
   396 
       
   397   void GWebContentView::showMessageBox(WRT::MessageBoxProxy* proxy)
       
   398   {
       
   399   /*
       
   400       QMessageBox msgBox(this);
       
   401       msgBox.setText(proxy->m_text);
       
   402       msgBox.setInformativeText(proxy->m_informativeText);
       
   403       msgBox.setDetailedText(proxy->m_detailedText);
       
   404       msgBox.setStandardButtons(proxy->m_buttons);
       
   405       msgBox.setDefaultButton(proxy->m_defaultButton);
       
   406       msgBox.setIcon(proxy->m_icon);
       
   407       int ret = msgBox.exec();
       
   408       */
       
   409       QString displayText = proxy->m_text + QLatin1String("\n") + QLatin1String("\n")+ proxy->m_detailedText + QLatin1String("\n") + QLatin1String("\n") + proxy->m_informativeText;
       
   410       int ret = QMessageBox::warning(0/* TODO: find appropriate widget if required or just remove this widget()*/,
       
   411                                      proxy->m_text, displayText, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
       
   412       proxy->onMessageBoxResponse(ret);
       
   413   }
       
   414 
       
   415   void GWebContentView::loadUrlToCurrentPage(const QString & url)
       
   416   {
       
   417       WRT::WrtBrowserContainer * activePage = WebPageController::getSingleton()->currentPage();
       
   418 
       
   419       if(activePage) {
       
   420         activePage->mainFrame()->load(url);
       
   421       }
       
   422   }
       
   423 
       
   424   QWebPage *GWebContentView::currentPage() {
       
   425       WRT::WrtBrowserContainer * activePage = WebPageController::getSingleton()->currentPage();
       
   426       return activePage;
       
   427   }
       
   428 
       
   429   int GWebContentView::contentWidth()
       
   430   {
       
   431     return currentPage()->mainFrame()->contentsSize().width();
       
   432   }
       
   433 
       
   434   int GWebContentView::contentHeight()
       
   435   {
       
   436     return currentPage()->mainFrame()->contentsSize().height();
       
   437   }
       
   438 
       
   439   void GWebContentView::stop()
       
   440   {
       
   441     webWidget()->stop();
       
   442   }
       
   443 
       
   444   void GWebContentView::back()
       
   445   {
       
   446     qDebug() << "GWebContentView::back";
       
   447     webWidget()->back();
       
   448   }
       
   449 
       
   450   void GWebContentView::forward()
       
   451   {
       
   452     webWidget()->forward();
       
   453   }
       
   454 
       
   455   void GWebContentView::reload()
       
   456   {
       
   457     webWidget()->reload();
       
   458   }
       
   459 
       
   460   int GWebContentView::scrollX()
       
   461   {
       
   462     return currentPage()->mainFrame()->scrollPosition().x();
       
   463   }
       
   464 
       
   465   int GWebContentView::scrollY()
       
   466   {
       
   467     return currentPage()->mainFrame()->scrollPosition().y();
       
   468   }
       
   469 
       
   470   void GWebContentView::zoom(bool in)
       
   471   {
       
   472     m_zoomIn = in;
       
   473     if(!m_timeLine) {
       
   474       m_timeLine = new QTimeLine();
       
   475       connect(m_timeLine, SIGNAL(valueChanged(qreal)),
       
   476         this, SLOT(updateZoom(qreal)));
       
   477     }
       
   478     else {
       
   479       m_timeLine->stop();
       
   480     }
       
   481     m_timeLine->start();
       
   482   }
       
   483 
       
   484   void GWebContentView::toggleZoom(){
       
   485     zoom(!m_zoomIn);
       
   486   }
       
   487   void GWebContentView::stopZoom() {
       
   488     m_timeLine->stop();
       
   489   }
       
   490 
       
   491   void GWebContentView::updateZoom(qreal delta){
       
   492     Q_UNUSED(delta)
       
   493     if(m_zoomIn)
       
   494       zoomBy(0.1);
       
   495     else
       
   496       zoomBy(-0.1);
       
   497   }
       
   498 
       
   499   void GWebContentView::onUrlChanged(const QUrl& url)
       
   500   {
       
   501     emit urlChanged(url.toString());
       
   502     //NB: Brief hack
       
   503     if(url.scheme()=="https")
       
   504       emit secureConnection(true);
       
   505     else
       
   506       emit secureConnection(false);
       
   507   }
       
   508 
       
   509   GWebPage *GWebContentView::createSuperPage(const QString &name) {
       
   510     qDebug() << "GWebContentView::createSuperPage: " << name;
       
   511     GWebPage *page = 0;
       
   512     PageMap::iterator it = m_superPages.find(name);
       
   513     if(it == m_superPages.end()) {
       
   514       // Doesn't exist.  Create a new one.
       
   515       page = new GSuperWebPage(0, chrome());
       
   516       page->setParent(jsObject());
       
   517       page->setObjectName(name);
       
   518 
       
   519       // Add it to the superpage list.
       
   520       m_superPages[name] = page;
       
   521       if(m_superPages.count() == 1) {
       
   522         // This is the only superpage, make it current.
       
   523         m_currentSuperPage = m_superPages.find(name);
       
   524       }
       
   525 
       
   526       //NB: Here's how to set default webview backgound color
       
   527       page->page()->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
       
   528       page->page()->mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff);
       
   529       QPalette viewPalette = widget()->palette();
       
   530       viewPalette.setBrush(QPalette::Base, Qt::white);
       
   531       //viewPalette.setColor(QPalette::Window, Qt::transparent);
       
   532       page->page()->setPalette(viewPalette);
       
   533       //m_view->setPalette(viewPalette);
       
   534     }
       
   535     else {
       
   536       qDebug() << "GWebContentView::createPage: page already exists: " << name;
       
   537     }
       
   538     return page;
       
   539   }
       
   540   
       
   541   void GWebContentView::destroySuperPage(const QString &name) {
       
   542     qDebug() << "GWebContentView::destroySuperPage: " << name;
       
   543     if(!m_superPages.contains(name)) return;
       
   544 
       
   545     GWebPage *page = m_superPages.take(name);
       
   546     if(page) {
       
   547       delete page;
       
   548     }
       
   549   }
       
   550 
       
   551   void GWebContentView::setCurrentSuperPage(const QString &name) {
       
   552     PageMap::iterator it = m_superPages.find(name);
       
   553     if(it != m_superPages.end()) {
       
   554       m_currentSuperPage = it;
       
   555     }
       
   556     else {
       
   557       qDebug() << "GWebContentView::setCurrentSuperPage: not found: " << name;
       
   558     }
       
   559   }
       
   560   
       
   561   bool GWebContentView::isSuperPage(const QString &name){
       
   562       PageMap::iterator it = m_superPages.find(name);
       
   563         if(it != m_superPages.end()) {
       
   564           return true;
       
   565         }
       
   566         qDebug() << "GWebContentView::superPage: not found: " << name;
       
   567         return false;
       
   568  }
       
   569       
       
   570   
       
   571   GWebPage * GWebContentView::superPage(const QString &name) {
       
   572     PageMap::iterator it = m_superPages.find(name);
       
   573     if(it != m_superPages.end()) {
       
   574       return it.value();
       
   575     }
       
   576     qDebug() << "GWebContentView::superPage: not found: " << name;
       
   577     return 0;
       
   578   }
       
   579   
       
   580   void GWebContentView::showSuperPage(const QString &name) {
       
   581     setCurrentSuperPage(name);
       
   582     qDebug() << "GWebContentView::showSuperPage: " << currentSuperPage();
       
   583     m_currentPageIsSuperPage = true;
       
   584     webWidget()->setPage(currentSuperPage()->page());
       
   585     m_touchNavigation->setPage(webWidget()->page());
       
   586     webWidget()->page()->setPreferredContentsSize(webWidget()->size().toSize());
       
   587   }
       
   588 
       
   589   void GWebContentView::showNormalPage() {
       
   590     if(webWidget()) {
       
   591       webWidget()->showNormalPage();
       
   592       webWidget()->setViewportSize();
       
   593       m_touchNavigation->setPage(currentPage());
       
   594       m_currentPageIsSuperPage =false;
       
   595     }
       
   596   }
       
   597   
       
   598   QObjectList GWebContentView::getSuperPages() {
       
   599     QObjectList *result = new QObjectList;
       
   600     foreach(GVA::GWebPage *page, m_superPages) {
       
   601       result->append(page);
       
   602     }
       
   603     // TO DO: Need to add result to JS engine so it can be cleaned up.
       
   604     return *result;
       
   605   }
       
   606 
       
   607   bool GWebContentView::currentPageIsSuperPage() const {
       
   608     //qDebug() << "GWebContentView::currentPageIsSuperPage: " << webWidget()->page();
       
   609     return m_currentPageIsSuperPage;
       
   610   }
       
   611 
       
   612   void GWebContentView::onLoadStarted()
       
   613   {
       
   614     //qDebug() << "GWebContentView::onLoadStarted: " << QTime::currentTime();
       
   615 #if defined(__gva_no_chrome__) || defined(NO_RESIZE_ON_LOAD)      
       
   616       m_widget->onLoadStarted();
       
   617 #endif
       
   618     emit loadStarted();
       
   619   }
       
   620 
       
   621   void GWebContentView::onLoadFinished(bool ok)
       
   622   {
       
   623     //qDebug() << "GWebContentView::onLoadFinished: " << QTime::currentTime();
       
   624     emit loadFinished(ok);
       
   625     //NB: page manager functions really
       
   626     if(!m_backEnabled && currentPage()->history()->canGoBack()){
       
   627       m_backEnabled = true;
       
   628       emit backEnabled(true);
       
   629     }
       
   630     else if (m_backEnabled && !currentPage()->history()->canGoBack()){
       
   631       m_backEnabled = false;
       
   632       emit backEnabled(false);
       
   633     }
       
   634     if(!m_forwardEnabled && currentPage()->history()->canGoForward()){
       
   635       m_forwardEnabled = true;
       
   636       emit forwardEnabled(true);
       
   637     }
       
   638     else if (m_forwardEnabled && !currentPage()->history()->canGoForward()){
       
   639       m_forwardEnabled = false;
       
   640       emit forwardEnabled(false);
       
   641     }
       
   642     
       
   643     // Set focus to the Web View so that text boxes have the focus (BR-994)
       
   644     m_widget->setFocus();
       
   645 
       
   646 #if defined(__gva_no_chrome__) || defined(NO_RESIZE_ON_LOAD)
       
   647     m_widget->onLoadFinished();
       
   648 #endif
       
   649   }
       
   650 
       
   651   void GWebContentView::dump() {
       
   652     qDebug() << "-------------";
       
   653     qDebug() << "GWebContentView::dump: " << this;
       
   654     qDebug() << "\tcurrent page=: " << currentPage() << " title=" << currentPage()->mainFrame()->title();
       
   655     qDebug() << "\tcurrent superpage=: " << currentSuperPage();
       
   656     qDebug() << "\tsuperpage count=: " << m_superPages.count();
       
   657     foreach(GVA::GWebPage *page, m_superPages) {
       
   658       page->dump();
       
   659     }
       
   660     qDebug() << "GWebContentView::dump: finished";
       
   661     qDebug() << "-------------";
       
   662   }
       
   663 
       
   664 //  ControllableView* GWebContentView::createNew(QWidget *parent)
       
   665 //  {
       
   666 //      QWebPage* page = BrowserPageFactory::openBrowserPage();
       
   667 //      return new GWebContentView(page, parent);
       
   668 //  }
       
   669 
       
   670 
       
   671   void GWebContentView::pageCreated(WRT::WrtBrowserContainer* newPage) {
       
   672 
       
   673       qDebug() << "GWebContentView::pageCreated";
       
   674       /* save the page snapshot before changing the current page to the new page*/
       
   675       WRT::WrtBrowserContainer * currPage = WebPageController::getSingleton()->currentPage();
       
   676       if(currPage) {
       
   677           QWebHistoryItem item = currPage->history()->currentItem();
       
   678           currPage->savePageDataToHistoryItem(currPage->mainFrame(), &item);
       
   679       }
       
   680 
       
   681       // When new windows are created from window view, as the content is empty, we should disable
       
   682       // zoom actions. Set the user-scalable to false and also init the other zoom params
       
   683       // so that even if we change to windows view again without loading a page we are safe.
       
   684       // In the code-driven window usecase, this will be overwritten when the page is loaded and setViewportSize is invoked
       
   685       newPage->setPageZoomMetaData(webWidget()->defaultZoomData());
       
   686 
       
   687       /* Set the new page as the current page */
       
   688       WebPageController::getSingleton()->setCurrentPage(newPage);
       
   689 
       
   690       /* Set the web widget- this one is responsible for webnavigation etc */
       
   691       newPage->setWebWidget(webWidget());
       
   692 
       
   693       //connect new page main frame's initialLayoutCompleted with WebContentWidget' setViewportSize SLOT
       
   694       connect(newPage->mainFrame(), SIGNAL(initialLayoutCompleted()), webWidget(), SLOT(setViewportSize()));
       
   695   }
       
   696 
       
   697   void GWebContentView::updateWebPage(WRT::WrtBrowserContainer* pg)
       
   698   {
       
   699       GWebContentViewWidget* w = webWidget();
       
   700       w->setPage(pg);
       
   701       if(pg)
       
   702       {
       
   703           pg->setWebWidget(w);
       
   704 
       
   705           // Change navigation also to the current page
       
   706           m_touchNavigation->setPage(pg);
       
   707 
       
   708       }
       
   709   }
       
   710 
       
   711   void GWebContentView::pageChanged(WRT::WrtBrowserContainer* oldPage, WRT::WrtBrowserContainer* newPage) {
       
   712     qDebug() << "GWebContentView::pageChanged";
       
   713       Q_UNUSED(oldPage)
       
   714       updateWebPage(newPage);
       
   715 
       
   716       // Set new page zoom info
       
   717       changeContentViewZoomInfo(newPage);
       
   718   }
       
   719 
       
   720   void GWebContentView::changeContentViewZoomInfo(WRT::WrtBrowserContainer* newPage){
       
   721      // Copy the new page zoom info into cv
       
   722      webWidget()->setPageZoomMetaData(newPage->pageZoomMetaData());
       
   723 
       
   724      if (webWidget()->isUserScalable()) {
       
   725          webWidget()->setZoomFactor(newPage->mainFrame()->zoomFactor());
       
   726      }
       
   727      else {
       
   728          // Need to call setPageZoomFactor instead of setZoomFactor because setZoomFactor
       
   729          // will not do anything if user-scalable is false. But we need to
       
   730          // ensure that the correct zoom factor is applied as there is a possibility
       
   731          // that we might have been on another page earlier
       
   732          webWidget()->setPageZoomFactor(newPage->mainFrame()->zoomFactor());
       
   733       }
       
   734   }
       
   735   
       
   736 
       
   737 
       
   738 } // end of namespace GVA
       
   739 
       
   740