ginebra2/ContentViews/GWebContentView.cpp
changeset 5 0f2326c2a325
parent 0 1450b09d0cfd
child 6 1c3b8676e58c
equal deleted inserted replaced
1:b0dd75e285d2 5:0f2326c2a325
     1 /*
     1 /*
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
       
     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 *
     4 *
     9 * Initial Contributors:
     5 * This program is free software: you can redistribute it and/or modify
    10 * Nokia Corporation - initial contribution.
     6 * it under the terms of the GNU Lesser General Public License as published by
       
     7 * the Free Software Foundation, version 2.1 of the License.
    11 *
     8 *
    12 * Contributors:
     9 * This program is distributed in the hope that it will be useful,
       
    10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12 * GNU Lesser General Public License for more details.
    13 *
    13 *
    14 * Description: 
    14 * You should have received a copy of the GNU Lesser General Public License
       
    15 * along with this program.  If not,
       
    16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
       
    17 *
       
    18 * Description:
    15 *
    19 *
    16 */
    20 */
    17 
       
    18 
    21 
    19 #include "GWebContentView.h"
    22 #include "GWebContentView.h"
    20 #include "GWebContentViewWidget.h"
    23 #include "GWebContentViewWidget.h"
    21 #include "GWebContentViewJSObject.h"
    24 #include "GWebContentViewJSObject.h"
    22 #include "ChromeWidget.h"
    25 #include "ChromeWidget.h"
    32 #include <QWebHistory>
    35 #include <QWebHistory>
    33 #include <QWebPage>
    36 #include <QWebPage>
    34 #include <QWebFrame>
    37 #include <QWebFrame>
    35 #include <QTimeLine>
    38 #include <QTimeLine>
    36 #include <QDebug>
    39 #include <QDebug>
       
    40 #include <QtGui>
    37 
    41 
    38 
    42 
    39 #define safe_connect(src, srcSig, target, targetSlot) \
    43 #define safe_connect(src, srcSig, target, targetSlot) \
    40   { int res = connect(src, srcSig, target, targetSlot); assert(res); }
    44   { int res = connect(src, srcSig, target, targetSlot); assert(res); }
    41 
    45 
    44 
    48 
    45   // ----------------------------------------------------------
    49   // ----------------------------------------------------------
    46 
    50 
    47   const qreal KZoomInStep = 1.05;
    51   const qreal KZoomInStep = 1.05;
    48   const qreal KZoomOutStep = 0.95238;
    52   const qreal KZoomOutStep = 0.95238;
    49   
    53 
    50   GWebContentView::GWebContentView(ChromeWidget *chrome, QObject * parent, const QString &objectName)
    54   GWebContentView::GWebContentView(ChromeWidget *chrome, QObject * parent, const QString &objectName)
    51     : ControllableViewBase(parent),
    55     : ControllableViewBase(parent),
    52       m_networkMgr(0),
    56       m_networkMgr(0),
    53       m_chrome(chrome),
    57       m_chrome(chrome),
    54       m_timeLine(0),
    58       m_timeLine(0),
    55       m_zoomIn(false),
    59       m_zoomIn(false),
    56       m_backEnabled(false),
    60       m_backEnabled(false),
    57       m_forwardEnabled(false),
    61       m_forwardEnabled(false),
       
    62       m_sharedPage(0),
    58       m_currentSuperPage(m_superPages.begin()),
    63       m_currentSuperPage(m_superPages.begin()),
    59       m_currentPageIsSuperPage(false),
    64       m_currentPageIsSuperPage(false),
    60       m_timer(NULL)
    65       m_timer(NULL),
       
    66       m_enabled(true)
    61   {
    67   {
    62       setObjectName(objectName);
    68       setObjectName(objectName);
    63       qDebug() << "GWebContentView::GWebContentView: this=" << this;
    69       qDebug() << "GWebContentView::GWebContentView: this=" << this;
    64       QWebPage* page = BrowserPageFactory::openBrowserPage();
    70       WRT::WrtBrowserContainer* page = BrowserPageFactory::openBrowserPage();
    65 
    71 
    66       setZoomActions();
    72       setActions();
    67       m_widget = new GWebContentViewWidget(parent, this, page);
    73       m_widget = new GWebContentViewWidget(parent, this, page);
    68 #ifndef __gva_no_chrome__
    74 #ifndef __gva_no_chrome__
    69       m_jsObject = new GWebContentViewJSObject(this, m_chrome->page()->mainFrame(), objectName);
    75       setJSObject(objectName);
    70 #endif
    76 #endif
    71       m_networkMgr = webWidget()->page()->networkAccessManager();
    77       m_networkMgr = webWidget()->page()->networkAccessManager();
    72 
    78 
    73       webWidget()->page()->currentFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
    79       webWidget()->page()->currentFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
    74       webWidget()->page()->currentFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff);
    80       webWidget()->page()->currentFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff);
    75 
    81 
    76 #ifdef NO_QSTM_GESTURE
    82 #ifdef NO_QSTM_GESTURE
    77       m_touchNavigation = new GWebTouchNavigation(page, m_widget);
    83       m_touchNavigation = new GContentViewTouchNavigation(page, m_widget);
    78       m_touchNavigation->setChromeWidget(m_chrome);
    84       m_touchNavigation->setChromeWidget(m_chrome);
    79       connect(m_touchNavigation, SIGNAL(mouseEvent(QEvent::Type)) , this, SIGNAL(contentViewMouseEvent(QEvent::Type)));
    85       connect(m_touchNavigation, SIGNAL(mouseEvent(QEvent::Type)) , this, SIGNAL(contentViewMouseEvent(QEvent::Type)));
    80 #endif
    86 #endif
    81       WRT::WrtBrowserContainer * wrtPage = static_cast<WRT::WrtBrowserContainer *>(page);
    87       WRT::WrtBrowserContainer * wrtPage = static_cast<WRT::WrtBrowserContainer *>(page);
    82       if(wrtPage) {
    88       if (wrtPage) {
    83           wrtPage->setWebWidget(webWidget());
    89           wrtPage->setWebWidget(webWidget());
    84           pageCreated(wrtPage);
    90           pageCreated(wrtPage);
    85       }
    91       }
    86 
    92 
    87       connectAll();
    93       connectAll();
    89 
    95 
    90   GWebContentView::~GWebContentView() {
    96   GWebContentView::~GWebContentView() {
    91       disconnect(m_jsObject);
    97       disconnect(m_jsObject);
    92       disconnect(webWidget());
    98       disconnect(webWidget());
    93       delete m_touchNavigation;
    99       delete m_touchNavigation;
    94       delete m_actionZoomIn;
   100       foreach(QAction * action, m_actions) {
    95       delete m_actionZoomOut;
   101           delete action;
       
   102       }
       
   103 
    96       delete m_widget;
   104       delete m_widget;
    97       foreach(GWebPage *page, m_superPages) {
   105       foreach(GWebPage *page, m_superPages) {
    98           delete page;
   106           delete page;
    99       }
   107       }
   100   }
   108   }
   103 {
   111 {
   104     if (m_timer) {
   112     if (m_timer) {
   105         m_timer->stop();
   113         m_timer->stop();
   106         disconnect(m_timer,SIGNAL(timeout()));
   114         disconnect(m_timer,SIGNAL(timeout()));
   107         delete m_timer;
   115         delete m_timer;
   108         m_timer = NULL;	
   116         m_timer = NULL;
   109     }
   117     }
   110     qreal zoomFactor = m_value * webWidget()->zoomFactor();
   118     qreal zoomFactor = m_value * webWidget()->zoomFactor();
   111     ((zoomFactor+0.001) >= webWidget()->maximumScale() )? webWidget()->setZoomFactor(webWidget()->maximumScale()):webWidget()->setZoomFactor(zoomFactor);
   119     ((zoomFactor+0.001) >= webWidget()->maximumScale() )? webWidget()->setZoomFactor(webWidget()->maximumScale()):webWidget()->setZoomFactor(zoomFactor);
   112     webWidget()->bitmapZoomCleanup();
   120     webWidget()->bitmapZoomCleanup();
   113 }
   121 }
   129 
   137 
   130 void GWebContentView::zoomN()
   138 void GWebContentView::zoomN()
   131 {
   139 {
   132     if ((m_value * webWidget()->zoomFactor()) <  webWidget()->minimumScale()){
   140     if ((m_value * webWidget()->zoomFactor()) <  webWidget()->minimumScale()){
   133         if (m_timer && m_timer->isActive())
   141         if (m_timer && m_timer->isActive())
   134             bitmapZoomStop();	
   142             bitmapZoomStop();
   135     }else {
   143     }else {
   136         if (m_timer->isSingleShot()) {
   144         if (m_timer->isSingleShot()) {
   137             m_timer->setSingleShot(false);
   145             m_timer->setSingleShot(false);
   138             m_timer->start(1);
   146             m_timer->start(1);
   139         }
   147         }
   140         webWidget()->setBitmapZoom(m_value * webWidget()->zoomFactor());
   148         webWidget()->setBitmapZoom(m_value * webWidget()->zoomFactor());
   141         m_value *= KZoomOutStep;
   149         m_value *= KZoomOutStep;
   142     }
   150     }
   143 }
   151 }
   144 
   152 
   145 void GWebContentView::zoomIn(qreal deltaPercent)	
   153 void GWebContentView::zoomIn(qreal deltaPercent)
   146 {
   154 {
   147     Q_UNUSED(deltaPercent)
   155     Q_UNUSED(deltaPercent)
   148     if (webWidget() && webWidget()->isUserScalable()) {
   156     if (webWidget() && webWidget()->isUserScalable()) {
   149         if (m_timer && m_timer->isActive()) {
   157         if (m_timer && m_timer->isActive()) {
   150             if (!m_timer->isSingleShot())
   158             if (!m_timer->isSingleShot())
   151                 m_value /= KZoomInStep;
   159                 m_value /= KZoomInStep;
   152             bitmapZoomStop();
   160             bitmapZoomStop();
   153 	        return;
   161             return;
   154         }else if (!m_timer)
   162         }else if (!m_timer)
   155             m_timer = new QTimer(this);
   163             m_timer = new QTimer(this);
   156   
   164 
   157         m_value = KZoomInStep;
   165         m_value = KZoomInStep;
   158 	
   166 
   159         if ((m_value * webWidget()->zoomFactor()) <  webWidget()->maximumScale()) {
   167         if ((m_value * webWidget()->zoomFactor()) <  webWidget()->maximumScale()) {
   160             webWidget()->createPageSnapShot();
   168             webWidget()->createPageSnapShot();
   161             connect(m_timer,SIGNAL(timeout()),this,SLOT(zoomP()));
   169             connect(m_timer,SIGNAL(timeout()),this,SLOT(zoomP()));
   162             zoomP();
   170             zoomP();
   163             m_timer->setSingleShot(true);
   171             m_timer->setSingleShot(true);
   165         }else {
   173         }else {
   166             delete m_timer;
   174             delete m_timer;
   167             m_timer = NULL;
   175             m_timer = NULL;
   168             webWidget()->setZoomFactor(m_value * webWidget()->zoomFactor());
   176             webWidget()->setZoomFactor(m_value * webWidget()->zoomFactor());
   169         }
   177         }
   170     }   
   178     }
   171 }
   179 }
   172 
   180 
   173 void GWebContentView::zoomOut(qreal deltaPercent)	
   181 void GWebContentView::zoomOut(qreal deltaPercent)
   174 {
   182 {
   175     Q_UNUSED(deltaPercent)
   183     Q_UNUSED(deltaPercent)
   176     if (webWidget() && webWidget()->isUserScalable()) {
   184     if (webWidget() && webWidget()->isUserScalable()) {
   177         if (m_timer && m_timer->isActive()) {
   185         if (m_timer && m_timer->isActive()) {
   178             if (!m_timer->isSingleShot())
   186             if (!m_timer->isSingleShot())
   179                 m_value /= KZoomOutStep;
   187                 m_value /= KZoomOutStep;
   180             bitmapZoomStop();
   188             bitmapZoomStop();
   181             return;
   189             return;
   182         }else if (!m_timer)
   190         }else if (!m_timer)
   183             m_timer = new QTimer(this);
   191             m_timer = new QTimer(this);
   184  
   192 
   185         m_value = KZoomOutStep;
   193         m_value = KZoomOutStep;
   186 
   194 
   187         if ((m_value * webWidget()->zoomFactor()) >  webWidget()->minimumScale()) {
   195         if ((m_value * webWidget()->zoomFactor()) >  webWidget()->minimumScale()) {
   188             webWidget()->createPageSnapShot();
   196             webWidget()->createPageSnapShot();
   189             connect(m_timer,SIGNAL(timeout()),this,SLOT(zoomN()));
   197             connect(m_timer,SIGNAL(timeout()),this,SLOT(zoomN()));
   205     safe_connect(widget(), SIGNAL(contextEvent(::WebViewEventContext *)),
   213     safe_connect(widget(), SIGNAL(contextEvent(::WebViewEventContext *)),
   206                  m_jsObject, SLOT(onContextEvent(::WebViewEventContext *)));
   214                  m_jsObject, SLOT(onContextEvent(::WebViewEventContext *)));
   207     QObject::connect(webWidget(), SIGNAL(titleChanged(const QString &)), m_jsObject, SIGNAL(titleChanged(const QString &)));
   215     QObject::connect(webWidget(), SIGNAL(titleChanged(const QString &)), m_jsObject, SIGNAL(titleChanged(const QString &)));
   208     QObject::connect(webWidget(), SIGNAL(loadStarted()), m_jsObject, SIGNAL(loadStarted()));
   216     QObject::connect(webWidget(), SIGNAL(loadStarted()), m_jsObject, SIGNAL(loadStarted()));
   209     QObject::connect(webWidget(), SIGNAL(loadProgress(int)), m_jsObject, SIGNAL(loadProgress(int)));
   217     QObject::connect(webWidget(), SIGNAL(loadProgress(int)), m_jsObject, SIGNAL(loadProgress(int)));
       
   218     QObject::connect(webWidget(), SIGNAL(loadProgress(int)), this, SIGNAL(loadProgress(int)));
   210 #endif
   219 #endif
   211     QObject::connect(webWidget(), SIGNAL(loadStarted()), this, SLOT(onLoadStarted()));
   220     QObject::connect(webWidget(), SIGNAL(loadStarted()), this, SLOT(onLoadStarted()));
   212     QObject::connect(webWidget(), SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool)));
   221     QObject::connect(webWidget(), SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool)));
   213     QObject::connect(webWidget(), SIGNAL(urlChanged(const QUrl&)), this, SLOT(onUrlChanged(const QUrl&)));
   222     QObject::connect(webWidget(), SIGNAL(urlChanged(const QUrl&)), this, SLOT(onUrlChanged(const QUrl&)));
   214 #ifndef __gva_no_chrome__
   223 #ifndef __gva_no_chrome__
   220     connect(m_touchNavigation, SIGNAL(startingPanGesture(int)), m_jsObject, SIGNAL(startingPanGesture(int)));
   229     connect(m_touchNavigation, SIGNAL(startingPanGesture(int)), m_jsObject, SIGNAL(startingPanGesture(int)));
   221 #endif
   230 #endif
   222     connect(WebPageController::getSingleton(), SIGNAL(pageCreated(WRT::WrtBrowserContainer*)),
   231     connect(WebPageController::getSingleton(), SIGNAL(pageCreated(WRT::WrtBrowserContainer*)),
   223             this, SLOT(pageCreated(WRT::WrtBrowserContainer*)));
   232             this, SLOT(pageCreated(WRT::WrtBrowserContainer*)));
   224     connect(WebPageController::getSingleton(), SIGNAL(pageChanged(WRT::WrtBrowserContainer*, WRT::WrtBrowserContainer*)),
   233     connect(WebPageController::getSingleton(), SIGNAL(pageChanged(WRT::WrtBrowserContainer*, WRT::WrtBrowserContainer*)),
   225             this, SLOT(pageChanged(WRT::WrtBrowserContainer*, WRT::WrtBrowserContainer*)));    
   234             this, SLOT(pageChanged(WRT::WrtBrowserContainer*, WRT::WrtBrowserContainer*)));
       
   235     connect(WebPageController::getSingleton(), SIGNAL(showMessageBox(WRT::MessageBoxProxy*)),
       
   236             this, SLOT(showMessageBox(WRT::MessageBoxProxy*)));
   226   }
   237   }
   227 
   238 
   228   QVariant GWebContentView::getContentWindowObject() {
   239   QVariant GWebContentView::getContentWindowObject() {
   229     try {
   240     try {
   230         return webWidget()->page()->mainFrame()->evaluateJavaScript("window");
   241         return webWidget()->page()->mainFrame()->evaluateJavaScript("window");
   253 
   264 
   254   QWebPage* GWebContentView::wrtPage() {
   265   QWebPage* GWebContentView::wrtPage() {
   255     return m_widget->wrtPage();
   266     return m_widget->wrtPage();
   256   }
   267   }
   257 
   268 
   258   void GWebContentView::setZoomActions(){
   269   void GWebContentView::setActions(){
   259 
   270 
   260       // Create zoomIn and zoomOut actions */
   271       QAction* action;
   261       m_actionZoomIn = new QAction("zoomIn", this);
   272       action = m_actions["zoomIn"] =  new QAction("zoomIn", this);
   262       m_actionZoomIn->setObjectName("zoomIn");
   273       action->setObjectName("zoomIn");
   263 
   274       connect(action, SIGNAL(triggered()), this, SLOT(zoomIn()));
   264       m_actionZoomOut = new QAction("zoomOut", this);
   275 
   265       m_actionZoomOut->setObjectName("zoomOut");
   276       action = m_actions["zoomOut"] = new QAction("zoomOut", this);
       
   277       action->setObjectName("zoomOut");
   266       /* Disable zoomOut action initially as we are the the minimum scale */
   278       /* Disable zoomOut action initially as we are the the minimum scale */
   267       /* Revisit this to determine whether we can use the change signal to
   279       /* Revisit this to determine whether we can use the change signal to
   268        * set the zoomOut button image initially as well
   280        * set the zoomOut button image initially as well
   269        */
   281        */
   270       m_actionZoomOut->setEnabled(false);
   282       action->setEnabled(false);
   271 
   283       connect(action, SIGNAL(triggered()), this, SLOT(zoomOut()));
   272       connect(m_actionZoomIn, SIGNAL(triggered()), this, SLOT(zoomIn()));
   284 
   273       connect(m_actionZoomOut, SIGNAL(triggered()), this, SLOT(zoomOut()));
   285       action = m_actions["zoom"] = new QAction("zoom", this);
       
   286       action->setObjectName("zoom");
       
   287 
       
   288 
       
   289       action =  m_actions["winview"]=  new QAction("winview", this);
       
   290       action->setObjectName("winview");
       
   291 
       
   292 
       
   293       action = m_actions["menu"] =  new QAction("menu", this);
       
   294       action->setObjectName("menu");
       
   295 
       
   296       action = m_actions["mostvisited"] =  new QAction("mostvisited", this);
       
   297       action->setObjectName("mostvisited");
       
   298 
       
   299       action = m_actions["toggletb"] = new QAction("toggletb", this);
       
   300       action->setObjectName("toggletb");
       
   301 
   274   }
   302   }
   275 
   303 
   276   void GWebContentView::triggerAction(const QString & action)
   304   void GWebContentView::triggerAction(const QString & action)
   277   {
   305   {
   278     qDebug() << "GWebContentView::triggerAction: " << action;
   306     qDebug() << "GWebContentView::triggerAction: " << action;
   279     QWebPage::WebAction webAction;
   307     QWebPage::WebAction webAction;
   280     if(action=="Stop")
   308     if (action=="Stop")
   281       webAction = QWebPage::Stop;
   309       webAction = QWebPage::Stop;
   282     else if (action=="Back")
   310     else if (action=="Back")
   283       webAction = QWebPage::Back;
   311       webAction = QWebPage::Back;
   284     else if(action=="Reload")
   312     else if (action=="Reload")
   285       webAction = QWebPage::Reload;
   313       webAction = QWebPage::Reload;
   286     else if (action=="Forward")
   314     else if (action=="Forward")
   287       webAction = QWebPage::Forward;
   315       webAction = QWebPage::Forward;
   288     else
   316     else
   289       return;
   317       return;
   290     webWidget()->triggerPageAction(webAction);
   318     webWidget()->triggerPageAction(webAction);
   291   }
   319   }
   292 
   320 
   293   void GWebContentView::deactivateZoomActions()
   321   void GWebContentView::deactivateZoomActions()
   294   {
   322   {
   295     m_actionZoomOut->setEnabled(false);
   323     m_actions.value("zoomIn")->setEnabled(false);
   296     m_actionZoomIn->setEnabled(false);
   324     m_actions.value("zoomOut")->setEnabled(false);
   297   }
   325   }
   298  
   326 
   299   void GWebContentView::changeZoomAction(qreal zoom){
   327   void GWebContentView::changeZoomAction(qreal zoom){
   300     if(!webWidget()) return;
   328     if (!webWidget()) return;
   301     if(!(webWidget()->isUserScalable() ) ){
   329     if (!(webWidget()->isUserScalable() ) ){
   302         deactivateZoomActions();
   330         deactivateZoomActions();
   303     }
   331     }
   304     else {
   332     else {
       
   333       QAction * zoomOutAction = m_actions.value("zoomOut");
       
   334       QAction * zoomInAction = m_actions.value("zoomIn");
   305       if (zoom <= webWidget()->minimumScale() ) {
   335       if (zoom <= webWidget()->minimumScale() ) {
   306          m_actionZoomOut->setEnabled(false);
   336          zoomOutAction->setEnabled(false);
   307       }
   337       }
   308       else {
   338       else {
   309          m_actionZoomOut->setEnabled(true);
   339          zoomOutAction->setEnabled(true);
   310       }
   340       }
   311 
   341 
   312       if (zoom >= webWidget()->maximumScale()  ){
   342       if (zoom >= webWidget()->maximumScale()  ){
   313          m_actionZoomIn->setEnabled(false);
   343          zoomInAction->setEnabled(false);
   314       }
   344       }
   315       else {
   345       else {
   316          m_actionZoomIn->setEnabled(true);
   346          zoomInAction->setEnabled(true);
   317       }
   347       }
   318     }
   348     }
   319   }
   349   }
   320 
   350 
   321   void GWebContentView::setZoomFactor(qreal factor){
   351   void GWebContentView::setZoomFactor(qreal factor){
   322     if(webWidget())
   352     if (webWidget())
   323         webWidget()->setZoomFactor(factor);
   353         webWidget()->setZoomFactor(factor);
   324   }
   354   }
   325 
   355 
   326   qreal GWebContentView::getZoomFactor() const {
   356   qreal GWebContentView::getZoomFactor() const {
   327     return webWidgetConst() ? webWidgetConst()->zoomFactor() : 0.0;
   357     return webWidgetConst() ? webWidgetConst()->zoomFactor() : 0.0;
   337       ControllableViewBase::deactivate();
   367       ControllableViewBase::deactivate();
   338   }
   368   }
   339 
   369 
   340 //  static void appendAction(QWebPage* page, QList<QAction*> &list, enum QWebPage::WebAction webAction, const QString &name) {
   370 //  static void appendAction(QWebPage* page, QList<QAction*> &list, enum QWebPage::WebAction webAction, const QString &name) {
   341 //      QAction *action = page->action(webAction);
   371 //      QAction *action = page->action(webAction);
   342 //      if(action) {
   372 //      if (action) {
   343 //          action->setObjectName(name);
   373 //          action->setObjectName(name);
   344 //          list.append(action);
   374 //          list.append(action);
   345 //      }
   375 //      }
   346 //  }
   376 //  }
   347 
   377 
   353   {
   383   {
   354       // Get some of the actions from the page (there are many more available) and build a list
   384       // Get some of the actions from the page (there are many more available) and build a list
   355       // list of them.
   385       // list of them.
   356 
   386 
   357       QList<QAction*> actions;
   387       QList<QAction*> actions;
       
   388       QAction * action = m_actions.value("zoomIn");
       
   389 
   358 
   390 
   359       /* Add zoomIn and zoomOut actions created earlier*/
   391       /* Add zoomIn and zoomOut actions created earlier*/
   360       if(m_actionZoomIn) actions.append(m_actionZoomIn);
   392       if (action) actions.append(action);
   361       if(m_actionZoomOut) actions.append(m_actionZoomOut);
   393 
       
   394       action = m_actions.value("zoomOut");
       
   395       if (action) actions.append(action);
   362 
   396 
   363       return actions;
   397       return actions;
   364   }
   398   }
   365 
   399 
   366 
   400 
   367   QAction * GWebContentView::getAction(const QString & action)
   401   QAction * GWebContentView::getAction(const QString & action)
   368   {
   402   {
   369     if(action == "zoomIn")
   403     QAction * act = NULL;
   370       return m_actionZoomIn;
   404     if (m_actions.contains(action) )
   371     if(action == "zoomOut")
   405         act = m_actions.value(action);
   372       return m_actionZoomOut;
   406 
   373     QWebPage::WebAction webAction;
   407     if (!act ) {
   374     if(action == "Back")
   408         WebPageController * pageController =  WebPageController::getSingleton();
   375       webAction = QWebPage::Back;
   409         if (action == "Back")
   376     else if(action == "Forward")
   410           act = pageController->getActionBack();
   377       webAction = QWebPage::Forward;
   411         else if (action == "Forward")
   378     else if(action == "Stop")
   412           act = pageController->getActionForward();
   379       webAction = QWebPage::Stop;
   413         else if (action == "Stop")
   380     else if(action == "Reload")
   414           act = pageController->getActionStop();
   381       webAction = QWebPage::Reload;
   415         else if (action == "Reload")
   382     else return 0;
   416           act = pageController->getActionReload();
   383     return webWidget()->pageAction(webAction);
   417 
       
   418     }
       
   419     return act;
   384   }
   420   }
   385 
   421 
   386   void GWebContentView::scrollViewBy(int dx, int dy)
   422   void GWebContentView::scrollViewBy(int dx, int dy)
   387   {
   423   {
   388       wrtPage()->mainFrame()->scroll(dx, dy);
   424       wrtPage()->mainFrame()->scroll(dx, dy);
   414 
   450 
   415   void GWebContentView::loadUrlToCurrentPage(const QString & url)
   451   void GWebContentView::loadUrlToCurrentPage(const QString & url)
   416   {
   452   {
   417       WRT::WrtBrowserContainer * activePage = WebPageController::getSingleton()->currentPage();
   453       WRT::WrtBrowserContainer * activePage = WebPageController::getSingleton()->currentPage();
   418 
   454 
   419       if(activePage) {
   455       if (activePage) {
   420         activePage->mainFrame()->load(url);
   456         activePage->mainFrame()->load(url);
   421       }
   457       }
   422   }
   458   }
   423 
   459 
   424   QWebPage *GWebContentView::currentPage() {
   460   QWebPage *GWebContentView::currentPage() {
   468   }
   504   }
   469 
   505 
   470   void GWebContentView::zoom(bool in)
   506   void GWebContentView::zoom(bool in)
   471   {
   507   {
   472     m_zoomIn = in;
   508     m_zoomIn = in;
   473     if(!m_timeLine) {
   509     if (!m_timeLine) {
   474       m_timeLine = new QTimeLine();
   510       m_timeLine = new QTimeLine();
   475       connect(m_timeLine, SIGNAL(valueChanged(qreal)),
   511       connect(m_timeLine, SIGNAL(valueChanged(qreal)),
   476         this, SLOT(updateZoom(qreal)));
   512         this, SLOT(updateZoom(qreal)));
   477     }
   513     }
   478     else {
   514     else {
   488     m_timeLine->stop();
   524     m_timeLine->stop();
   489   }
   525   }
   490 
   526 
   491   void GWebContentView::updateZoom(qreal delta){
   527   void GWebContentView::updateZoom(qreal delta){
   492     Q_UNUSED(delta)
   528     Q_UNUSED(delta)
   493     if(m_zoomIn)
   529     if (m_zoomIn)
   494       zoomBy(0.1);
   530       zoomBy(0.1);
   495     else
   531     else
   496       zoomBy(-0.1);
   532       zoomBy(-0.1);
   497   }
   533   }
   498 
   534 
   499   void GWebContentView::onUrlChanged(const QUrl& url)
   535   void GWebContentView::onUrlChanged(const QUrl& url)
   500   {
   536   {
   501     emit urlChanged(url.toString());
   537     emit urlChanged(url.toString());
   502     //NB: Brief hack
   538     //NB: Brief hack
   503     if(url.scheme()=="https")
   539     if (url.scheme()=="https")
   504       emit secureConnection(true);
   540       emit secureConnection(true);
   505     else
   541     else
   506       emit secureConnection(false);
   542       emit secureConnection(false);
   507   }
   543   }
   508 
   544 
   509   GWebPage *GWebContentView::createSuperPage(const QString &name) {
   545   GWebPage *GWebContentView::createSuperPage(const QString &name, bool persist) {
   510     qDebug() << "GWebContentView::createSuperPage: " << name;
   546     qDebug() << "GWebContentView::createSuperPage: " << name;
   511     GWebPage *page = 0;
   547     GWebPage *page = 0;
   512     PageMap::iterator it = m_superPages.find(name);
   548     PageMap::iterator it = m_superPages.find(name);
   513     if(it == m_superPages.end()) {
   549     // If page doesn't exist create a new one.
   514       // Doesn't exist.  Create a new one.
   550     if (it == m_superPages.end()) {
   515       page = new GSuperWebPage(0, chrome());
   551 
       
   552       if (persist || !m_sharedPage){
       
   553           if (persist)
       
   554               //Implicitly creates a new QWebPage that is owned by the superpage object
       
   555               page = new GSuperWebPage(0, chrome());
       
   556 
       
   557           else {
       
   558               //Create a shared QWebPage that is owned by this view
       
   559               m_sharedPage = new WebPageWrapper(this, "Superpage javascript error");
       
   560               page = new GSuperWebPage(m_sharedPage, chrome());
       
   561           }
       
   562           //No scroll bars
       
   563           page->page()->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
       
   564           page->page()->mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff);
       
   565           //No history for super pages
       
   566           page->page()->history()->setMaximumItemCount(0);
       
   567           //Limit page cache usage by super pages
       
   568           //TODO: This needs to be further tested to weigh the costs and benefits.
       
   569           page->page()->settings()->setMaximumPagesInCache(2);
       
   570           //NB: needed?
       
   571           QPalette viewPalette = widget()->palette();
       
   572           viewPalette.setBrush(QPalette::Base, Qt::white);
       
   573           page->page()->setPalette(viewPalette);
       
   574       } else {
       
   575           //Reuse the shared QWebPage
       
   576           page = new GSuperWebPage(m_sharedPage, chrome());
       
   577       }
       
   578       //Export the superpage to JS
   516       page->setParent(jsObject());
   579       page->setParent(jsObject());
   517       page->setObjectName(name);
   580       page->setObjectName(name);
   518 
       
   519       // Add it to the superpage list.
   581       // Add it to the superpage list.
   520       m_superPages[name] = page;
   582       m_superPages[name] = page;
   521       if(m_superPages.count() == 1) {
   583       if (m_superPages.count() == 1) {
   522         // This is the only superpage, make it current.
   584         // This is the only superpage, make it current.
   523         m_currentSuperPage = m_superPages.find(name);
   585         m_currentSuperPage = m_superPages.find(name);
   524       }
   586       }
   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     }
   587     }
   535     else {
   588     else {
   536       qDebug() << "GWebContentView::createPage: page already exists: " << name;
   589       qDebug() << "GWebContentView::createPage: page already exists: " << name;
   537     }
   590     }
   538     return page;
   591     return page;
   539   }
   592   }
   540   
   593 
   541   void GWebContentView::destroySuperPage(const QString &name) {
   594   void GWebContentView::destroySuperPage(const QString &name) {
   542     qDebug() << "GWebContentView::destroySuperPage: " << name;
   595     qDebug() << "GWebContentView::destroySuperPage: " << name;
   543     if(!m_superPages.contains(name)) return;
   596     if (!m_superPages.contains(name)) return;
   544 
   597 
   545     GWebPage *page = m_superPages.take(name);
   598     GWebPage *page = m_superPages.take(name);
   546     if(page) {
   599     //This will destroy any QWebPage owned by the super page. The shared page is not
   547       delete page;
   600     //owned by the super page and will be deleted when the GWebContentView is deleted.
       
   601     if (page){
       
   602         delete page;
   548     }
   603     }
   549   }
   604   }
   550 
   605 
   551   void GWebContentView::setCurrentSuperPage(const QString &name) {
   606   void GWebContentView::setCurrentSuperPage(const QString &name) {
   552     PageMap::iterator it = m_superPages.find(name);
   607     PageMap::iterator it = m_superPages.find(name);
   553     if(it != m_superPages.end()) {
   608     if (it != m_superPages.end()) {
   554       m_currentSuperPage = it;
   609       m_currentSuperPage = it;
   555     }
   610     }
   556     else {
   611     else {
   557       qDebug() << "GWebContentView::setCurrentSuperPage: not found: " << name;
   612       qDebug() << "GWebContentView::setCurrentSuperPage: not found: " << name;
   558     }
   613     }
   559   }
   614   }
   560   
   615 
   561   bool GWebContentView::isSuperPage(const QString &name){
   616   bool GWebContentView::isSuperPage(const QString &name){
   562       PageMap::iterator it = m_superPages.find(name);
   617       PageMap::iterator it = m_superPages.find(name);
   563         if(it != m_superPages.end()) {
   618         if (it != m_superPages.end()) {
   564           return true;
   619           return true;
   565         }
   620         }
   566         qDebug() << "GWebContentView::superPage: not found: " << name;
   621         qDebug() << "GWebContentView::superPage: not found: " << name;
   567         return false;
   622         return false;
   568  }
   623  }
   569       
   624 
   570   
   625 
   571   GWebPage * GWebContentView::superPage(const QString &name) {
   626   GWebPage * GWebContentView::superPage(const QString &name) {
   572     PageMap::iterator it = m_superPages.find(name);
   627     PageMap::iterator it = m_superPages.find(name);
   573     if(it != m_superPages.end()) {
   628     if (it != m_superPages.end()) {
   574       return it.value();
   629       return it.value();
   575     }
   630     }
   576     qDebug() << "GWebContentView::superPage: not found: " << name;
   631     qDebug() << "GWebContentView::superPage: not found: " << name;
   577     return 0;
   632     return 0;
   578   }
   633   }
   579   
   634 
   580   void GWebContentView::showSuperPage(const QString &name) {
   635   void GWebContentView::showSuperPage(const QString &name) {
   581     setCurrentSuperPage(name);
   636     setCurrentSuperPage(name);
   582     qDebug() << "GWebContentView::showSuperPage: " << currentSuperPage();
   637     qDebug() << "GWebContentView::showSuperPage: " << currentSuperPage();
   583     m_currentPageIsSuperPage = true;
   638     m_currentPageIsSuperPage = true;
   584     webWidget()->setPage(currentSuperPage()->page());
   639     webWidget()->setPage(currentSuperPage()->page());
   585     m_touchNavigation->setPage(webWidget()->page());
   640     m_touchNavigation->setPage(webWidget()->page());
       
   641     m_touchNavigation->setWantSlideViewCalls(false);
   586     webWidget()->page()->setPreferredContentsSize(webWidget()->size().toSize());
   642     webWidget()->page()->setPreferredContentsSize(webWidget()->size().toSize());
   587   }
   643   }
   588 
   644 
   589   void GWebContentView::showNormalPage() {
   645   void GWebContentView::showNormalPage() {
   590     if(webWidget()) {
   646     if (webWidget()) {
   591       webWidget()->showNormalPage();
   647       webWidget()->showNormalPage();
   592       webWidget()->setViewportSize();
   648       webWidget()->setViewportSize();
   593       m_touchNavigation->setPage(currentPage());
   649       m_touchNavigation->setPage(currentPage());
       
   650       m_touchNavigation->setWantSlideViewCalls(true);
       
   651       //TODO: Further testing is needed to show if the following is a net benefit.
       
   652       if (m_currentPageIsSuperPage && (currentSuperPage()->page() == m_sharedPage)){
       
   653           //Clear contents of shared page to free resources. This should save
       
   654           //memory for big pages, but at the performance cost of loading an empty page.
       
   655           //An alternative is to delete the shared page every time and reallocate it when
       
   656           //a super page is loaded.
       
   657           currentSuperPage()->page()->mainFrame()->setHtml(QString());
       
   658       }
   594       m_currentPageIsSuperPage =false;
   659       m_currentPageIsSuperPage =false;
   595     }
   660     }
   596   }
   661   }
   597   
   662 
   598   QObjectList GWebContentView::getSuperPages() {
   663   QObjectList GWebContentView::getSuperPages() {
   599     QObjectList *result = new QObjectList;
   664     QObjectList *result = new QObjectList;
   600     foreach(GVA::GWebPage *page, m_superPages) {
   665     foreach(GVA::GWebPage *page, m_superPages) {
   601       result->append(page);
   666       result->append(page);
   602     }
   667     }
   610   }
   675   }
   611 
   676 
   612   void GWebContentView::onLoadStarted()
   677   void GWebContentView::onLoadStarted()
   613   {
   678   {
   614     //qDebug() << "GWebContentView::onLoadStarted: " << QTime::currentTime();
   679     //qDebug() << "GWebContentView::onLoadStarted: " << QTime::currentTime();
   615 #if defined(__gva_no_chrome__) || defined(NO_RESIZE_ON_LOAD)      
   680 #if defined(__gva_no_chrome__) || defined(NO_RESIZE_ON_LOAD)
   616       m_widget->onLoadStarted();
   681       m_widget->onLoadStarted();
   617 #endif
   682 #endif
   618     emit loadStarted();
   683     emit loadStarted();
   619   }
   684   }
   620 
   685 
   621   void GWebContentView::onLoadFinished(bool ok)
   686   void GWebContentView::onLoadFinished(bool ok)
   622   {
   687   {
   623     //qDebug() << "GWebContentView::onLoadFinished: " << QTime::currentTime();
   688     //qDebug() << "GWebContentView::onLoadFinished: " << QTime::currentTime();
   624     emit loadFinished(ok);
   689     emit loadFinished(ok);
   625     //NB: page manager functions really
   690     //NB: page manager functions really
   626     if(!m_backEnabled && currentPage()->history()->canGoBack()){
   691     if (!m_backEnabled && currentPage()->history()->canGoBack()){
   627       m_backEnabled = true;
   692       m_backEnabled = true;
   628       emit backEnabled(true);
   693       emit backEnabled(true);
   629     }
   694     }
   630     else if (m_backEnabled && !currentPage()->history()->canGoBack()){
   695     else if (m_backEnabled && !currentPage()->history()->canGoBack()){
   631       m_backEnabled = false;
   696       m_backEnabled = false;
   632       emit backEnabled(false);
   697       emit backEnabled(false);
   633     }
   698     }
   634     if(!m_forwardEnabled && currentPage()->history()->canGoForward()){
   699     if (!m_forwardEnabled && currentPage()->history()->canGoForward()){
   635       m_forwardEnabled = true;
   700       m_forwardEnabled = true;
   636       emit forwardEnabled(true);
   701       emit forwardEnabled(true);
   637     }
   702     }
   638     else if (m_forwardEnabled && !currentPage()->history()->canGoForward()){
   703     else if (m_forwardEnabled && !currentPage()->history()->canGoForward()){
   639       m_forwardEnabled = false;
   704       m_forwardEnabled = false;
   640       emit forwardEnabled(false);
   705       emit forwardEnabled(false);
   641     }
   706     }
   642     
   707 
   643     // Set focus to the Web View so that text boxes have the focus (BR-994)
   708     // Set focus to the Web View so that text boxes have the focus (BR-994)
   644     m_widget->setFocus();
   709     m_widget->setFocus();
   645 
   710 
   646 #if defined(__gva_no_chrome__) || defined(NO_RESIZE_ON_LOAD)
   711 #if defined(__gva_no_chrome__) || defined(NO_RESIZE_ON_LOAD)
   647     m_widget->onLoadFinished();
   712     m_widget->onLoadFinished();
   671   void GWebContentView::pageCreated(WRT::WrtBrowserContainer* newPage) {
   736   void GWebContentView::pageCreated(WRT::WrtBrowserContainer* newPage) {
   672 
   737 
   673       qDebug() << "GWebContentView::pageCreated";
   738       qDebug() << "GWebContentView::pageCreated";
   674       /* save the page snapshot before changing the current page to the new page*/
   739       /* save the page snapshot before changing the current page to the new page*/
   675       WRT::WrtBrowserContainer * currPage = WebPageController::getSingleton()->currentPage();
   740       WRT::WrtBrowserContainer * currPage = WebPageController::getSingleton()->currentPage();
   676       if(currPage) {
   741       if (currPage) {
   677           QWebHistoryItem item = currPage->history()->currentItem();
   742           QWebHistoryItem item = currPage->history()->currentItem();
   678           currPage->savePageDataToHistoryItem(currPage->mainFrame(), &item);
   743           currPage->savePageDataToHistoryItem(currPage->mainFrame(), &item);
   679       }
   744       }
   680 
   745 
   681       // When new windows are created from window view, as the content is empty, we should disable
   746       // When new windows are created from window view, as the content is empty, we should disable
   696 
   761 
   697   void GWebContentView::updateWebPage(WRT::WrtBrowserContainer* pg)
   762   void GWebContentView::updateWebPage(WRT::WrtBrowserContainer* pg)
   698   {
   763   {
   699       GWebContentViewWidget* w = webWidget();
   764       GWebContentViewWidget* w = webWidget();
   700       w->setPage(pg);
   765       w->setPage(pg);
   701       if(pg)
   766       if (pg)
   702       {
   767       {
   703           pg->setWebWidget(w);
   768           pg->setWebWidget(w);
   704 
   769 
   705           // Change navigation also to the current page
   770           // Change navigation also to the current page
   706           m_touchNavigation->setPage(pg);
   771           m_touchNavigation->setPage(pg);
       
   772           m_touchNavigation->setWantSlideViewCalls(true);
   707 
   773 
   708       }
   774       }
   709   }
   775   }
   710 
   776 
   711   void GWebContentView::pageChanged(WRT::WrtBrowserContainer* oldPage, WRT::WrtBrowserContainer* newPage) {
   777   void GWebContentView::pageChanged(WRT::WrtBrowserContainer* oldPage, WRT::WrtBrowserContainer* newPage) {
   730          // ensure that the correct zoom factor is applied as there is a possibility
   796          // ensure that the correct zoom factor is applied as there is a possibility
   731          // that we might have been on another page earlier
   797          // that we might have been on another page earlier
   732          webWidget()->setPageZoomFactor(newPage->mainFrame()->zoomFactor());
   798          webWidget()->setPageZoomFactor(newPage->mainFrame()->zoomFactor());
   733       }
   799       }
   734   }
   800   }
   735   
   801 
   736 
   802   void GWebContentView::setJSObject(const QString &objectName) {
   737 
   803       m_jsObject = new GWebContentViewJSObject(this, m_chrome->page()->mainFrame(), objectName);
       
   804   }
       
   805 
       
   806 
       
   807   bool GWebContentView::enabled() const {
       
   808       return m_enabled;
       
   809   }
       
   810 
       
   811   void GWebContentView::setEnabled(bool value) {
       
   812       qDebug() << "GWebContentView::setEnabled: " << value;
       
   813       if(m_enabled == value)
       
   814           return;
       
   815 
       
   816       m_enabled = value;
       
   817       widget()->setEnabled(value);
       
   818       widget()->update();
       
   819   }
   738 } // end of namespace GVA
   820 } // end of namespace GVA
   739 
   821 
   740 
   822