ginebra2/ContentViews/GWebContentViewWidget.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 #include "GWebContentViewWidget.h"
    21 #include "GWebContentViewWidget.h"
    19 #include "GWebContentView.h"
    22 #include "GWebContentView.h"
    20 #include "browserpagefactory.h"
    23 #include "browserpagefactory.h"
    21 #include "webpagecontroller.h"
    24 #include "webpagecontroller.h"
       
    25 #include "Utilities.h"
       
    26 #include "ChromeEffect.h"
    22 
    27 
    23 #include <QGraphicsSceneResizeEvent>
    28 #include <QGraphicsSceneResizeEvent>
    24 #include <QGraphicsSceneContextMenuEvent>
    29 #include <QGraphicsSceneContextMenuEvent>
    25 #include <QWebFrame>
    30 #include <QWebFrame>
    26 #include <QWebHitTestResult>
    31 #include <QWebHitTestResult>
    28 #include <QStyleOptionGraphicsItem>
    33 #include <QStyleOptionGraphicsItem>
    29 #include <QDebug>
    34 #include <QDebug>
    30 #include <QGraphicsView>
    35 #include <QGraphicsView>
    31 
    36 
    32 #ifdef ENABLE_PERF_TRACE
    37 #ifdef ENABLE_PERF_TRACE
    33     #include "wrtperftracer.h"
    38 #include "wrtperftracer.h"
    34     // Global reference to WrtPerfTracer
       
    35     extern WrtPerfTracer* g_wrtPerfTracing;
       
    36 #endif
    39 #endif
    37 
    40 
    38 namespace GVA {
    41 namespace GVA {
    39 
    42 
    40 const QString KViewPortWidthTag("width");
    43 const QString KViewPortWidthTag("width");
    63 
    66 
    64 GWebContentViewWidget::GWebContentViewWidget(QObject* parent, GWebContentView* view,QWebPage* pg) : QGraphicsWebView(0)
    67 GWebContentViewWidget::GWebContentViewWidget(QObject* parent, GWebContentView* view,QWebPage* pg) : QGraphicsWebView(0)
    65 , m_webContentView(view)
    68 , m_webContentView(view)
    66 , m_dirtyZoomFactor(1)
    69 , m_dirtyZoomFactor(1)
    67 , m_frozenPixmap(0)
    70 , m_frozenPixmap(0)
    68 , m_freezeCount(0)
    71 , m_frozenCount(0)
    69 , m_wrtPage(0)
    72 , m_wrtPage(0)
    70 , m_bitmapZoom(false)
    73 , m_bitmapZoom(false)
    71 , m_pagePixmap(0)
       
    72 , m_isResize(false)
    74 , m_isResize(false)
    73 , m_currentinitialScale(0)
    75 , m_currentinitialScale(0)
    74 , m_previousViewPortwidth(size().toSize().width())
    76 , m_previousViewPortwidth(size().toSize().width())
    75 , m_bitmapImage(NULL)
    77 , m_bitmapImage(NULL)
    76 , m_checkeredBoxPixmap(NULL)
    78 , m_checkeredBoxPixmap(NULL)
    77 {
    79 {
    78   qDebug() << "GWebContentViewWidget::GWebContentViewWidget: page=" << pg;
    80   qDebug() << "GWebContentViewWidget::GWebContentViewWidget: page=" << pg;
    79   setParent(parent);
    81   setParent(parent);
    80   if( pg ) {
    82   if ( pg ) {
    81     setPage(pg);
    83     setPage(pg);
    82   }
    84   }
    83 #ifdef ENABLE_PERF_TRACE  
    85 #ifdef ENABLE_PERF_TRACE
    84   g_wrtPerfTracing->initPage(pg);
    86   WrtPerfTracer::tracer()->initPage(pg);
    85 #endif //ENABLE_PERF_TRACE
    87 #endif //ENABLE_PERF_TRACE
    86   
    88 
    87   m_currentinitialScale = zoomFactor();
    89   m_currentinitialScale = zoomFactor();
    88   //connect(this->page()->mainFrame(), SIGNAL(initialLayoutCompleted()), this, SLOT(onInitLayout()));
    90   //connect(this->page()->mainFrame(), SIGNAL(initialLayoutCompleted()), this, SLOT(onInitLayout()));
    89 #ifndef NO_QSTM_GESTURE      
    91 #ifndef NO_QSTM_GESTURE
    90   m_touchNavigation = new WebTouchNavigation(this);
    92   m_touchNavigation = new WebTouchNavigation(this);
    91 #endif
    93 #endif
       
    94   // Fixes missing radio button problem with certain themes
       
    95   QPalette pal = palette();
       
    96   pal.setColor(QPalette::ButtonText,Qt::black);
       
    97   setPalette(pal);
    92 }
    98 }
    93 
    99 
    94 GWebContentViewWidget::~GWebContentViewWidget()
   100 GWebContentViewWidget::~GWebContentViewWidget()
    95 {
   101 {
    96     if (m_bitmapImage)
   102     delete m_bitmapImage;
    97         delete m_bitmapImage;
   103     delete m_checkeredBoxPixmap;
    98     if (m_checkeredBoxPixmap)
   104     delete m_frozenPixmap;
    99         delete m_checkeredBoxPixmap;
       
   100 }
   105 }
   101 
   106 
   102 void GWebContentViewWidget::updateViewport()
   107 void GWebContentViewWidget::updateViewport()
   103 {
   108 {
   104     if (page() && size() != page()->viewportSize()) {
   109     if (page() && size() != page()->viewportSize()) {
   105         page()->setViewportSize(size().toSize());
   110         page()->setViewportSize(size().toSize());
   106     }
   111     }
   107     setViewportSize();
   112     setViewportSize();
   108 }
   113 }
   109 
   114 
   110 void GWebContentViewWidget::setBlockElement(QWebElement pt)
   115 void GWebContentViewWidget::setBlockElement(const QWebElement &pt)
   111 {
   116 {
   112   m_BlockElement = pt;
   117   m_BlockElement = pt;
   113 }
   118 }
   114 
   119 
   115 void GWebContentViewWidget::setCheckeredPixmap()
   120 void GWebContentViewWidget::setCheckeredPixmap()
   116 {
   121 {
   117     delete m_checkeredBoxPixmap;
   122     delete m_checkeredBoxPixmap;
   118     m_checkeredBoxPixmap = NULL;
   123     m_checkeredBoxPixmap = NULL;
   119     int checkerPixmapSizeX = size().toSize().width();
   124     int checkerPixmapSizeX = size().toSize().width();
   120     int checkerPixmapSizeY = size().toSize().height() + 50;
   125     int checkerPixmapSizeY = size().toSize().height() + 50;
   121     m_checkeredBoxPixmap = new QPixmap(size().width(), size().height() + 50);
   126     m_checkeredBoxPixmap = new QPixmap(checkerSize, checkerSize);
   122     QPainter painter(m_checkeredBoxPixmap);
   127     QPainter painter(m_checkeredBoxPixmap);
   123    
   128     painter.fillRect(0, 0, checkerSize, checkerSize, QColor(checkerColor1));
   124     for (int y = 0; y < checkerPixmapSizeY; y += checkerSize / 2) {
   129     painter.fillRect(0, checkerSize/2, checkerSize/2, checkerSize/2, QColor(checkerColor2));
   125         bool alternate = y % checkerSize;
   130     painter.fillRect(checkerSize/2, 0, checkerSize/2, checkerSize/2, QColor(checkerColor2));
   126         for (int x = 0; x < checkerPixmapSizeX; x += checkerSize / 2) {
       
   127             QColor color(alternate ? checkerColor1 : checkerColor2);
       
   128             painter.fillRect(x, y, checkerSize / 2, checkerSize / 2, color);
       
   129             alternate = !alternate;
       
   130         }
       
   131     }
       
   132 }
   131 }
   133 
   132 
   134 void GWebContentViewWidget::createPageSnapShot()
   133 void GWebContentViewWidget::createPageSnapShot()
   135 {
   134 {
   136     bitmapZoomCleanup();
   135     bitmapZoomCleanup();
   145 
   144 
   146 void GWebContentViewWidget::bitmapZoomCleanup()
   145 void GWebContentViewWidget::bitmapZoomCleanup()
   147 {
   146 {
   148     m_bitmapZoom = false;
   147     m_bitmapZoom = false;
   149     if (m_bitmapImage) {
   148     if (m_bitmapImage) {
   150 	    delete m_bitmapImage;
   149         delete m_bitmapImage;
   151 		m_bitmapImage = NULL;
   150         m_bitmapImage = NULL;
   152 	}
   151     }
       
   152 }
       
   153 
       
   154 void GWebContentViewWidget::updateFrozenImage() {
       
   155     // Take a snapshot for to be displayed while in frozen state.
       
   156     QStyleOptionGraphicsItem opt;
       
   157     opt.levelOfDetail = 1.0;
       
   158     opt.exposedRect = QRectF(QPointF(0,0), size());
       
   159 
       
   160     m_frozenPixmap = new QPixmap(opt.exposedRect.size().toSize());
       
   161     QPainter painter(m_frozenPixmap);
       
   162     paint(&painter, &opt);
       
   163 
       
   164     if(!isEnabled()) {
       
   165         // Disabled, apply whitewash.
       
   166 
       
   167         painter.setOpacity(ChromeEffect::disabledOpacity);
       
   168         painter.fillRect(opt.exposedRect, ChromeEffect::disabledColor);
       
   169     }
       
   170     painter.end();
   153 }
   171 }
   154 
   172 
   155 QImage GWebContentViewWidget::getPageSnapshot()
   173 QImage GWebContentViewWidget::getPageSnapshot()
   156 {
   174 {
   157   QImage img(size().toSize(), QImage::Format_RGB32);
   175   QImage img(size().toSize(), QImage::Format_RGB32);
   158 
   176 
   159   if(!page()) return QImage();
   177   if (!page()) return QImage();
   160 
   178 
   161   QPainter painter(&img);
   179   QPainter painter(&img);
   162   QWebFrame *frame = page()->mainFrame();
   180   QWebFrame *frame = page()->mainFrame();
   163 
   181 
   164   painter.fillRect(QRectF(0, 0, size().width(), size().height()), QColor(255, 255, 255));
   182   painter.fillRect(QRectF(0, 0, size().width(), size().height()), QColor(255, 255, 255));
   190 
   208 
   191 bool GWebContentViewWidget::event(QEvent * e) {
   209 bool GWebContentViewWidget::event(QEvent * e) {
   192 
   210 
   193     if (e->type() == QEvent::Gesture) {
   211     if (e->type() == QEvent::Gesture) {
   194 #ifndef NO_QSTM_GESTURE
   212 #ifndef NO_QSTM_GESTURE
   195 		  QStm_Gesture* gesture = getQStmGesture(e, WebGestureHelper::getAssignedGestureType());
   213           QStm_Gesture* gesture = getQStmGesture(e, WebGestureHelper::getAssignedGestureType());
   196 		  if (gesture) {
   214           if (gesture) {
   197 			  m_touchNavigation->handleQStmGesture(gesture);
   215               m_touchNavigation->handleQStmGesture(gesture);
   198 			  return true;
   216               return true;
   199 		  }
   217           }
   200 #endif
   218 #endif
   201     }
   219     }
   202 	
   220 
   203     else if(e->type() == WebPageControllerUpdateViewPortEvent::staticType()) {
   221     else if (e->type() == WebPageControllerUpdateViewPortEvent::staticType()) {
   204         updateViewport();
   222         updateViewport();
   205     }
   223     }
   206     return QGraphicsWebView::event(e);
   224     return QGraphicsWebView::event(e);
   207 }
   225 }
   208 
   226 
   209 void GWebContentViewWidget::resizeEvent(QGraphicsSceneResizeEvent* e)
   227 void GWebContentViewWidget::resizeEvent(QGraphicsSceneResizeEvent* e)
   210 {
   228 {
       
   229    
   211   // set the fixed text layout size for text wrapping
   230   // set the fixed text layout size for text wrapping
   212 #if defined CWRTINTERNALWEBKIT
   231 #if defined CWRTINTERNALWEBKIT
   213   if (page()) {
   232   if (page()) {
   214     p->m_webPage->settings()->setMaximumTextColumnWidth(e->newSize().width() - 6);
   233     p->m_webPage->settings()->setMaximumTextColumnWidth(e->newSize().width() - 6);
   215   }
   234   }
   217 
   236 
   218   m_previousViewPortwidth = page()->viewportSize().width();
   237   m_previousViewPortwidth = page()->viewportSize().width();
   219 
   238 
   220   const QSize &s = e->newSize().toSize();
   239   const QSize &s = e->newSize().toSize();
   221   if (page() && s != page()->viewportSize()) {
   240   if (page() && s != page()->viewportSize()) {
   222     if(m_BlockElement.isNull()) {
   241     if (m_BlockElement.isNull()) {
   223       QPoint pos = QPoint(0,0);
   242       QPoint pos = QPoint(0,0);
   224       QWebFrame* frame = page()->frameAt(pos);
   243       QWebFrame* frame = page()->frameAt(pos);
   225       frame = (frame) ? frame : page()->currentFrame();
   244       frame = (frame) ? frame : page()->currentFrame();
   226       QWebHitTestResult htr = frame->hitTestContent(pos);
   245       QWebHitTestResult htr = frame->hitTestContent(pos);
   227       m_BlockInFocus = htr.element();
   246       m_BlockInFocus = htr.element();
   228 
   247 
   229       if(m_BlockInFocus.tagName() != "IMG")
   248       if (m_BlockInFocus.tagName() != "IMG")
   230         m_BlockInFocus = htr.enclosingBlockElement();
   249         m_BlockInFocus = htr.enclosingBlockElement();
   231 
   250 
   232       QPoint position = m_BlockInFocus.geometry().topLeft() - page()->currentFrame()->scrollPosition();
   251       QPoint position = m_BlockInFocus.geometry().topLeft() - page()->currentFrame()->scrollPosition();
   233       m_Ratiox = (qreal) position.x() / m_BlockInFocus.geometry().width();
   252       m_Ratiox = (qreal) position.x() / m_BlockInFocus.geometry().width();
   234       m_Ratioy = (qreal) position.y() / m_BlockInFocus.geometry().height();
   253       m_Ratioy = (qreal) position.y() / m_BlockInFocus.geometry().height();
   235     }
   254     }
   236     page()->setViewportSize(s);
   255     page()->setViewportSize(s);
   237   }
   256   }
   238 
   257 
   239   updateViewportSize(e);
   258   updateViewportSize(e);
       
   259 
       
   260   if(frozen())
       
   261     updateFrozenImage();
   240 }
   262 }
   241 
   263 
   242 void GWebContentViewWidget::contextMenuEvent(::QGraphicsSceneContextMenuEvent *event) {
   264 void GWebContentViewWidget::contextMenuEvent(::QGraphicsSceneContextMenuEvent *event) {
   243     qDebug() << "GWebContentViewWidget::contextMenuEvent: " << event;
   265     QWebHitTestResult hitTest = page()->currentFrame()->hitTestContent(event->pos().toPoint());
   244     QPoint p = mapFromGlobal(event->scenePos()).toPoint();
   266     qDebug() << "GWebContentViewWidget::contextMenuEvent:"
   245     QWebHitTestResult hitTest = page()->currentFrame()->hitTestContent(p);
   267             << "\n\t pos=" << hitTest.pos()
       
   268             << "\n\t linkUrl=" << hitTest.linkUrl()
       
   269             << "\n\t imageUrl=" << hitTest.imageUrl();
   246 
   270 
   247     WebViewEventContext *context =
   271     WebViewEventContext *context =
   248         new WebViewEventContext(view()->type(), hitTest);
   272         new WebViewEventContext(view()->type(), hitTest);
   249 
   273 
   250     emit contextEvent(context);
   274     if (m_webContentView && m_webContentView->currentPageIsSuperPage()) {
       
   275         // Let the superpage handle the event.
       
   276         m_webContentView->currentSuperPage()->onContextEvent(context);
       
   277     }
       
   278     else {
       
   279         // Send the event directly.
       
   280         emit contextEvent(context);
       
   281     }
   251     event->accept();
   282     event->accept();
   252 }
   283 }
   253 
   284 
   254 void GWebContentViewWidget::setZoomFactor(qreal zoom)
   285 void GWebContentViewWidget::setZoomFactor(qreal zoom)
   255 {
   286 {
   259 
   290 
   260     setPageZoomFactor(zoom);
   291     setPageZoomFactor(zoom);
   261 }
   292 }
   262 
   293 
   263 void GWebContentViewWidget::setPageZoomFactor(qreal zoom)
   294 void GWebContentViewWidget::setPageZoomFactor(qreal zoom)
   264 {
   295 {  
   265   if(!page()) return;
   296 //not zooming if it's bookmark or historyview or not a page
       
   297   if (!page() ||
       
   298 	  	(m_webContentView->type() == "webView" && 
       
   299           m_webContentView->currentPageIsSuperPage()) )
       
   300       {
       
   301       return;      
       
   302       }
   266 
   303 
   267   //qDebug() << __func__ << "Zoom " << zoom << "Max : " << m_maximumScale << "Min: " << m_minimumScale;
   304   //qDebug() << __func__ << "Zoom " << zoom << "Max : " << m_maximumScale << "Min: " << m_minimumScale;
   268 
   305 
   269   if (zoom < m_minimumScale)
   306   if (zoom < m_minimumScale)
   270       zoom = m_minimumScale;
   307       zoom = m_minimumScale;
   271   else if (zoom > m_maximumScale)
   308   else if (zoom > m_maximumScale)
   272       zoom = m_maximumScale;
   309       zoom = m_maximumScale;
   273 
   310 
   274   QPoint pos = QPoint(0,0);
   311   QPoint pos = QPoint(0,0);
   275 
   312 
   276   if(!m_isResize) {
   313   if (!m_isResize) {
   277     QWebFrame* frame = page()->frameAt(pos);
   314     QWebFrame* frame = page()->frameAt(pos);
   278     frame = (frame) ? frame : page()->currentFrame();
   315     frame = (frame) ? frame : page()->currentFrame();
   279     QWebHitTestResult htr = frame->hitTestContent(pos);
   316     QWebHitTestResult htr = frame->hitTestContent(pos);
   280     m_BlockInFocus = htr.element();
   317     m_BlockInFocus = htr.element();
   281 
   318 
   282     if(m_BlockInFocus.tagName() != "IMG")
   319     if (m_BlockInFocus.tagName() != "IMG")
   283       m_BlockInFocus = htr.enclosingBlockElement();
   320       m_BlockInFocus = htr.enclosingBlockElement();
   284 
   321 
   285     QPoint position = m_BlockInFocus.geometry().topLeft() - page()->currentFrame()->scrollPosition();
   322     QPoint position = m_BlockInFocus.geometry().topLeft() - page()->currentFrame()->scrollPosition();
   286     m_Ratiox = (qreal) position.x() / m_BlockInFocus.geometry().width();
   323     m_Ratiox = (qreal) position.x() / m_BlockInFocus.geometry().width();
   287     m_Ratioy = (qreal) position.y() / m_BlockInFocus.geometry().height();
   324     m_Ratioy = (qreal) position.y() / m_BlockInFocus.geometry().height();
   288   }
   325   }
   289 
   326 
   290   if( m_dirtyZoomFactor != zoom ) {
   327   if ( m_dirtyZoomFactor != zoom ) {
   291       m_dirtyZoomFactor = zoom;
   328       m_dirtyZoomFactor = zoom;
   292   }
   329   }
   293 
   330 
   294   QGraphicsWebView::setZoomFactor( zoom );
   331   QGraphicsWebView::setZoomFactor( zoom );
   295 
   332 
   296   if(!m_BlockElement.isNull() && m_isResize) {
   333   if (!m_BlockElement.isNull() && m_isResize) {
   297     QPoint imageFocusPoint;
   334     QPoint imageFocusPoint;
   298     QPoint m_focusedBlockPt = QPoint(m_BlockElement.geometry().topLeft()) - page()->mainFrame()->scrollPosition();
   335     QPoint m_focusedBlockPt = QPoint(m_BlockElement.geometry().topLeft()) - page()->mainFrame()->scrollPosition();
   299     if(m_BlockElement.tagName() != "IMG" && (m_BlockElement.styleProperty(QString("background-image"),QWebElement::InlineStyle) == ""))
   336     if (m_BlockElement.tagName() != "IMG" && (m_BlockElement.styleProperty(QString("background-image"),QWebElement::InlineStyle) == ""))
   300       page()->mainFrame()->scroll(m_focusedBlockPt.x() - KFocussPoint.x() , m_focusedBlockPt.y() - KFocussPoint.y());
   337       page()->mainFrame()->scroll(m_focusedBlockPt.x() - KFocussPoint.x() , m_focusedBlockPt.y() - KFocussPoint.y());
   301     else {
   338     else {
   302       if((page()->viewportSize().width() - m_BlockElement.geometry().width()) > 0)
   339       if ((page()->viewportSize().width() - m_BlockElement.geometry().width()) > 0)
   303         imageFocusPoint.setX((page()->viewportSize().width() - m_BlockElement.geometry().width())/2);
   340         imageFocusPoint.setX((page()->viewportSize().width() - m_BlockElement.geometry().width())/2);
   304       else
   341       else
   305         imageFocusPoint.setX(0);
   342         imageFocusPoint.setX(0);
   306 
   343 
   307       if((page()->viewportSize().height() - m_BlockElement.geometry().height()) > 0)
   344       if ((page()->viewportSize().height() - m_BlockElement.geometry().height()) > 0)
   308         imageFocusPoint.setY((page()->viewportSize().height() - m_BlockElement.geometry().height())/2);
   345         imageFocusPoint.setY((page()->viewportSize().height() - m_BlockElement.geometry().height())/2);
   309       else
   346       else
   310         imageFocusPoint.setY(0);
   347         imageFocusPoint.setY(0);
   311 
   348 
   312       page()->mainFrame()->scroll(m_focusedBlockPt.x() - imageFocusPoint.x() ,
   349       page()->mainFrame()->scroll(m_focusedBlockPt.x() - imageFocusPoint.x() ,
   325 
   362 
   326 }
   363 }
   327 
   364 
   328 void GWebContentViewWidget::setDirtyZoomFactor(qreal zoom)
   365 void GWebContentViewWidget::setDirtyZoomFactor(qreal zoom)
   329 {
   366 {
   330     if( m_dirtyZoomFactor == zoom )
   367     if ( m_dirtyZoomFactor == zoom )
   331         return;
   368         return;
   332 
   369 
   333     m_dirtyZoomFactor = zoom;
   370     m_dirtyZoomFactor = zoom;
   334 
   371 
   335     update();
   372     update();
   342     m_loadingTime.start();
   379     m_loadingTime.start();
   343 }
   380 }
   344 
   381 
   345 void GWebContentViewWidget::onLoadFinished()
   382 void GWebContentViewWidget::onLoadFinished()
   346 {
   383 {
       
   384 #ifdef NO_RESIZE_ON_LOAD
   347     m_inLoading = false;
   385     m_inLoading = false;
   348     update();
   386     update();
       
   387 #endif
   349 }
   388 }
   350 
   389 
   351 #ifdef NO_RESIZE_ON_LOAD
   390 #ifdef NO_RESIZE_ON_LOAD
   352 void GWebContentViewWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* options, QWidget* widget)
   391 void GWebContentViewWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* options, QWidget* widget)
   353 {
   392 {
       
   393 
   354     QRect clipRect;
   394     QRect clipRect;
   355     if(options && !options->exposedRect.isEmpty())
   395     if (options && !options->exposedRect.isEmpty())
   356         clipRect = options->exposedRect.toRect();
   396         clipRect = options->exposedRect.toRect();
   357     else
   397     else
   358         {
   398         {
   359             clipRect = geometry().toRect();
   399             clipRect = geometry().toRect();
   360             clipRect.moveTo(0,0);
   400             clipRect.moveTo(0,0);
   361 
   401 
   362         }
   402         }
   363 
   403 #ifdef ENABLE_PERF_TRACE
   364     painter->fillRect(clipRect, QColor(255, 255, 255));
   404     PERF_DEBUG() << "GWebContentViewWidget::paint: " << clipRect << "\n";
       
   405     unsigned int st = WrtPerfTracer::tracer()->startTimer();
       
   406 #endif
       
   407 
       
   408     //painter->fillRect(clipRect, QColor(255, 255, 255));
   365     if (!m_inLoading || !(m_loadingTime.elapsed() < 750)) {
   409     if (!m_inLoading || !(m_loadingTime.elapsed() < 750)) {
   366         QGraphicsWebView::paint(painter, options, widget);
   410         QGraphicsWebView::paint(painter, options, widget);
   367     }
   411     }
       
   412 #ifdef ENABLE_PERF_TRACE
       
   413     PERF_DEBUG() << "GWebContentViewWidget::paint__end: " <<
       
   414         WrtPerfTracer::tracer()->elapsedTime(st) << "\n";
       
   415 #endif
       
   416 
       
   417 
   368 }
   418 }
   369 
   419 
   370 #else //NO_RESIZE_ON_LOAD
   420 #else //NO_RESIZE_ON_LOAD
   371 void GWebContentViewWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
   421 void GWebContentViewWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
   372 {
   422 {
   373 
   423 //    if (!m_active) return;
   374 //    if(!m_active) return;
   424 
   375 
   425 #ifdef ENABLE_PERF_TRACE
   376     if(m_freezeCount > 0) {
   426     PERF_DEBUG() << "GWebContentViewWidget::paint: " << option->exposedRect << "\n";
       
   427     unsigned int st = WrtPerfTracer::tracer()->startTimer();
       
   428 #endif
       
   429     //qDebug() << "GWebContentViewWidget::paint";
       
   430     if (frozen() && m_frozenPixmap) {
   377         // Frozen, paint the snapshot.
   431         // Frozen, paint the snapshot.
   378         painter->drawPixmap(0, 0, *m_frozenPixmap);
   432         painter->drawPixmap(option->exposedRect.topLeft(), *m_frozenPixmap, option->exposedRect);
   379     }
   433     }
   380     else {
   434     else {
   381         if (m_bitmapZoom) {
   435         if (m_bitmapZoom) {
       
   436             // Frozen ----
       
   437 
   382             qreal czf = 1;
   438             qreal czf = 1;
   383             qreal zoomF = zoomFactor();
   439             qreal zoomF = zoomFactor();
   384 
   440 
   385             if ( m_bitmapZoomFactor != zoomF )
   441             if ( m_bitmapZoomFactor != zoomF )
   386                 czf = m_bitmapZoomFactor/zoomF;
   442                 czf = m_bitmapZoomFactor/zoomF;
   387 
   443 
   388             painter->save();
   444             painter->save();
   389 
   445 
   390             if (czf < 1) 
   446             if (czf < 1) {
   391                 painter->drawPixmap(QPoint(0,0), *m_checkeredBoxPixmap);
   447                 if (!m_checkeredBoxPixmap) {
   392 
   448                     setCheckeredPixmap();
       
   449                 }
       
   450                 QBrush brush(*m_checkeredBoxPixmap);
       
   451                 painter->fillRect(0, 0, size().width(), size().height(), brush);
       
   452             }
   393             painter->drawImage(QRectF(0,0,size().width() * czf,size().height() * czf), *m_bitmapImage);
   453             painter->drawImage(QRectF(0,0,size().width() * czf,size().height() * czf), *m_bitmapImage);
   394             painter->restore();
   454             painter->restore();
   395         }
   455         }
   396 
   456         else if ( qAbs(zoomFactor() - m_dirtyZoomFactor) < 0.0001 )
   397         // Not frozen, do normal paint.
       
   398         else if( zoomFactor() == m_dirtyZoomFactor )
       
   399         {
   457         {
       
   458             // Do normal paint. ----
       
   459 
   400             // Cannot use normal QGraphicsWebView paint because have to fill background with white for the phone build
   460             // Cannot use normal QGraphicsWebView paint because have to fill background with white for the phone build
   401             // QGraphicsWebView::paintEvent( event);
   461             // QGraphicsWebView::paintEvent( event);
   402 
   462 
   403             // Commented the following line out to try to improve scrolling performance.  hab - 3/25/10
   463             // Commented the following line out to try to improve scrolling performance.  hab - 3/25/10
   404             //painter->fillRect(0, 0, size().width(), size().height(), QColor(255, 255, 255));
   464             //painter->fillRect(0, 0, size().width(), size().height(), QColor(255, 255, 255));
   405 
   465 
   406             //painter->fillRect(clipRect, QColor(255, 255, 255));       
   466             //painter->fillRect(clipRect, QColor(255, 255, 255));
       
   467 
       
   468 
   407             QGraphicsWebView::paint(painter, option, widget);
   469             QGraphicsWebView::paint(painter, option, widget);
   408         } else {
   470         } else {
       
   471             // Do zooming paint. ----
       
   472 
   409             qreal czf = m_dirtyZoomFactor / zoomFactor();
   473             qreal czf = m_dirtyZoomFactor / zoomFactor();
   410 
   474 
   411             QWebFrame* frame = page()->mainFrame();
   475             QWebFrame* frame = page()->mainFrame();
   412 
   476 
   413             painter->save();
   477             painter->save();
   414 
   478 
   415             // Commented the following line out to try to improve scrolling performance.  hab - 3/25/10
   479             // Commented the following line out to try to improve scrolling performance.  hab - 3/25/10
   416 			//painter->fillRect(0, 0, size().width(), size().height(), QColor(255, 255, 255));
   480             //painter->fillRect(0, 0, size().width(), size().height(), QColor(255, 255, 255));
   417 
   481 
   418             QTransform transform;
   482             QTransform transform;
   419             transform.scale(czf, czf);
   483             transform.scale(czf, czf);
   420 //            painter.translate(-transform.map(frame->scrollPosition()));
   484 //            painter.translate(-transform.map(frame->scrollPosition()));
   421 
   485 
   422             QRegion clipRegion = QRect(QPoint(0,0), size().toSize());
   486             QRegion clipRegion = QRect(QPoint(0,0), size().toSize());
   423             if(option && !option->exposedRect.isEmpty())
   487             if (option && !option->exposedRect.isEmpty())
   424             {
   488             {
   425                 clipRegion.intersect( option->exposedRect.toRect());
   489                 clipRegion.intersect( option->exposedRect.toRect());
   426             }
   490             }
   427             QTransform invert = transform.inverted();
   491             QTransform invert = transform.inverted();
   428             clipRegion = invert.map(clipRegion);
   492             clipRegion = invert.map(clipRegion);
   433             frame->render(painter, clipRegion);
   497             frame->render(painter, clipRegion);
   434             painter->restore();
   498             painter->restore();
   435         }
   499         }
   436 
   500 
   437     }
   501     }
       
   502 
       
   503 #ifdef ENABLE_PERF_TRACE
       
   504     PERF_DEBUG() << "GWebContentViewWidget::paint__end: " <<
       
   505         WrtPerfTracer::tracer()->elapsedTime(st) << "\n";
       
   506 #endif
   438 }
   507 }
   439 #endif //NO_RESIZE_ON_LOAD
   508 #endif //NO_RESIZE_ON_LOAD
   440 
   509 
       
   510 void GWebContentViewWidget::freeze() {
       
   511     if(m_frozenCount == 0) {
       
   512         updateFrozenImage();
       
   513         update();
       
   514     }
       
   515     m_frozenCount++;
       
   516 }
       
   517 
       
   518 void GWebContentViewWidget::unfreeze() {
       
   519     if(m_frozenCount > 0) {
       
   520         m_frozenCount--;
       
   521 
       
   522         if(m_frozenCount == 0){
       
   523             delete m_frozenPixmap;
       
   524             m_frozenPixmap = 0;
       
   525             update();
       
   526         }
       
   527     }
       
   528 }
       
   529 
   441 void GWebContentViewWidget::setPage(QWebPage* pg)
   530 void GWebContentViewWidget::setPage(QWebPage* pg)
   442 {
   531 {
   443   if(m_wrtPage == pg) return;
   532   if (m_wrtPage == pg) return;
   444 
   533 
   445   qDebug() << "GWebContentViewWidget::setPage: " << pg;
   534   qDebug() << "GWebContentViewWidget::setPage: " << pg;
   446   if(m_wrtPage) {
   535   if (m_wrtPage) {
   447     disconnect(page()->mainFrame(), 0, this, 0);
   536     disconnect(page()->mainFrame(), 0, this, 0);
   448     m_wrtPage->setView(0);
   537     m_wrtPage->setView(0);
   449   }
   538   }
   450   /* Reset the webview page as well - for its internal clean up */
   539   /* Reset the webview page as well - for its internal clean up */
   451   QGraphicsWebView::setPage(pg);
   540   QGraphicsWebView::setPage(pg);
   452 
   541 
   453   m_wrtPage = pg;
   542   m_wrtPage = pg;
   454   if(page()) {
   543 
   455 #ifndef NO_RESIZE_ON_LOAD  
   544   // Call setViewportSize when the initial layout finishes unless pg is a super page.
       
   545   // Otherwise the superpage's zoom factor get set to its initialScale (0.6667).
       
   546   // This should be updated/removed when we start saving zoom factors on each page.
       
   547   if (page() && !m_webContentView->currentPageIsSuperPage()) {
       
   548 #ifndef NO_RESIZE_ON_LOAD
   456     connect(page()->mainFrame(), SIGNAL(initialLayoutCompleted()), this, SLOT(setViewportSize()));
   549     connect(page()->mainFrame(), SIGNAL(initialLayoutCompleted()), this, SLOT(setViewportSize()));
   457 #endif
   550 #endif
   458     
   551 //    setCacheMode(QGraphicsItem::DeviceCoordinateCache);
   459   }
   552   }
   460 
   553 
   461   // setPage() above doesn't seem to trigger an update, do it explicitly.
   554   // setPage() above doesn't seem to trigger an update, do it explicitly.
   462   update();
   555   update();
   463 
   556 
   467 
   560 
   468 void GWebContentViewWidget::showNormalPage()
   561 void GWebContentViewWidget::showNormalPage()
   469 {
   562 {
   470     WRT::WrtBrowserContainer *wbc = WebPageController::getSingleton()->currentPage();
   563     WRT::WrtBrowserContainer *wbc = WebPageController::getSingleton()->currentPage();
   471     setPage((QWebPage *)wbc);  // static_cast here gives compiler error
   564     setPage((QWebPage *)wbc);  // static_cast here gives compiler error
   472 }
       
   473 
       
   474 void GWebContentViewWidget::createPagePixmap()
       
   475 {
       
   476     if (m_pagePixmap)
       
   477        delete m_pagePixmap;
       
   478 
       
   479     m_pagePixmap = new QPixmap(size().toSize());
       
   480     QStyleOptionGraphicsItem op;
       
   481     QPainter p(m_pagePixmap);
       
   482     paint(&p,&op,0);
       
   483     p.end();
       
   484 }
   565 }
   485 
   566 
   486 void GWebContentViewWidget::setBitmapZoom(qreal zoom)
   567 void GWebContentViewWidget::setBitmapZoom(qreal zoom)
   487 {
   568 {
   488     if (!m_userScalable || zoom == zoomFactor())
   569     if (!m_userScalable || zoom == zoomFactor())
   494         zoom = m_maximumScale;
   575         zoom = m_maximumScale;
   495 
   576 
   496     m_bitmapZoom = true;
   577     m_bitmapZoom = true;
   497     m_bitmapZoomFactor = zoom;
   578     m_bitmapZoomFactor = zoom;
   498     update();
   579     update();
   499 }
       
   500 
       
   501 void GWebContentViewWidget::deletePagePixmap()
       
   502 {
       
   503     if (m_pagePixmap) {
       
   504         delete m_pagePixmap;
       
   505         m_pagePixmap = 0;
       
   506     }
       
   507     m_bitmapZoom = false;
       
   508 }
   580 }
   509 
   581 
   510 void GWebContentViewWidget::setPageCenterZoomFactor(qreal zoom)
   582 void GWebContentViewWidget::setPageCenterZoomFactor(qreal zoom)
   511 {
   583 {
   512     //calculating the center of the widget
   584     //calculating the center of the widget
   534     m_userScalable = true;
   606     m_userScalable = true;
   535     m_inferWidthHeight = true;
   607     m_inferWidthHeight = true;
   536 
   608 
   537     m_aspectRation = size().width() / size().height();
   609     m_aspectRation = size().width() / size().height();
   538 
   610 
   539 #ifdef NO_RESIZE_ON_LOAD    
   611 #ifdef NO_RESIZE_ON_LOAD
   540     QSize sz = size().toSize(); 
   612     QSize sz = size().toSize();
   541     m_viewportWidth = sz.width();
   613     m_viewportWidth = sz.width();
   542     m_viewportHeight = sz.height();
   614     m_viewportHeight = sz.height();
   543     m_initialScale = 1.0;
   615     m_initialScale = 1.0;
   544 #else
   616 #else
   545     m_viewportWidth = KDefaultViewportWidth;
   617     m_viewportWidth = KDefaultViewportWidth;
   546     m_viewportHeight = (int)size().height();
   618     m_viewportHeight = (int)size().height();
   547 
   619 
   548     if( size().width() < size().height())       //if Portrait
   620     if ( size().width() < size().height())       //if Portrait
   549       m_initialScale = size().width() / KDefaultPortraitScaleWidth;
   621       m_initialScale = size().width() / KDefaultPortraitScaleWidth;
   550     else
   622     else
   551       m_initialScale = size().width() / KDefaultViewportWidth;
   623       m_initialScale = size().width() / KDefaultViewportWidth;
   552 #endif //NO_RESIZE_ON_LOAD 
   624 #endif //NO_RESIZE_ON_LOAD
   553     
   625 
   554     m_minimumScale = m_initialScale;
   626     m_minimumScale = m_initialScale;
   555 }
   627 }
   556 
   628 
   557 /*!
   629 /*!
   558  * Provides the default values - used when opening a new blank window
   630  * Provides the default values - used when opening a new blank window
   571 /*!
   643 /*!
   572  * Set the viewport Size
   644  * Set the viewport Size
   573  */
   645  */
   574 void GWebContentViewWidget::setViewportSize()
   646 void GWebContentViewWidget::setViewportSize()
   575 {
   647 {
   576     if(!page()) return;
   648 
       
   649     if (!page()) return;
   577 
   650 
   578     QWebFrame* frame = page()->mainFrame();
   651     QWebFrame* frame = page()->mainFrame();
   579 
   652 
   580     initializeViewportParams();
   653     initializeViewportParams();
   581 
   654 
   612     page()->setFixedContentsSize(QSize(m_viewportWidth, m_viewportHeight));
   685     page()->setFixedContentsSize(QSize(m_viewportWidth, m_viewportHeight));
   613 #else
   686 #else
   614     page()->setPreferredContentsSize(QSize((int)m_viewportWidth, (int)m_viewportHeight));
   687     page()->setPreferredContentsSize(QSize((int)m_viewportWidth, (int)m_viewportHeight));
   615 #endif
   688 #endif
   616 
   689 
   617 #ifndef NO_RESIZE_ON_LOAD      
   690 #ifndef NO_RESIZE_ON_LOAD
   618   qreal zoomF = 0.0;
   691   qreal zoomF = 0.0;
   619   QString str;
   692   QString str;
   620   if(m_isResize &&  (m_currentinitialScale != zoomFactor())) {
   693   if (m_isResize &&  (m_currentinitialScale != zoomFactor())) {
   621     zoomF = ((qreal)(page()->viewportSize().width()-10) * zoomFactor())/(m_previousViewPortwidth-10);
   694     zoomF = ((qreal)(page()->viewportSize().width()-10) * zoomFactor())/(m_previousViewPortwidth-10);
   622     str.setNum(zoomF,'f',2);
   695     str.setNum(zoomF,'f',2);
   623     zoomF = str.toDouble();
   696     zoomF = str.toDouble();
   624     setPageZoomFactor(zoomF);
   697     setPageZoomFactor(zoomF);
   625   }
   698   }
   627     setPageZoomFactor(m_initialScale);
   700     setPageZoomFactor(m_initialScale);
   628   }
   701   }
   629   m_BlockInFocus = QWebElement();
   702   m_BlockInFocus = QWebElement();
   630   m_currentinitialScale = m_initialScale;
   703   m_currentinitialScale = m_initialScale;
   631 #endif //NO_RESIZE_ON_LOAD
   704 #endif //NO_RESIZE_ON_LOAD
   632   
   705 
   633   setCheckeredPixmap();
       
   634   // Let the page save the data. Even though it is part of the frame, it is easier to
   706   // Let the page save the data. Even though it is part of the frame, it is easier to
   635   // save the info in the page to avoid parsing the meta data again.
   707   // save the info in the page to avoid parsing the meta data again.
   636   emit pageZoomMetaDataChange(frame, pageZoomMetaData());
   708   WrtBrowserContainer* pg = static_cast<WrtBrowserContainer*>(page());
       
   709   pg->setPageZoomMetaData(pageZoomMetaData());
       
   710   
       
   711 
   637 }
   712 }
   638 
   713 
   639 qreal GWebContentViewWidget::initialScale()
   714 qreal GWebContentViewWidget::initialScale()
   640 {
   715 {
   641   return  m_initialScale;
   716   return  m_initialScale;
   646     if (propertyName == KViewPortWidthTag) {
   721     if (propertyName == KViewPortWidthTag) {
   647       if (propertyValue == KViewPortDeviceWidthTag) {
   722       if (propertyValue == KViewPortDeviceWidthTag) {
   648             m_viewportWidth = size().width();
   723             m_viewportWidth = size().width();
   649         m_viewportHeight = m_viewportWidth * m_aspectRation;
   724         m_viewportHeight = m_viewportWidth * m_aspectRation;
   650       }
   725       }
   651         else if(propertyValue == KViewPortDeviceHeightTag) {
   726         else if (propertyValue == KViewPortDeviceHeightTag) {
   652             m_viewportWidth = size().height();
   727             m_viewportWidth = size().height();
   653         m_viewportHeight = m_viewportWidth * m_aspectRation;
   728         m_viewportHeight = m_viewportWidth * m_aspectRation;
   654         }
   729         }
   655         else {
   730         else {
   656         m_viewportWidth = propertyValue.toInt();
   731         m_viewportWidth = propertyValue.toInt();
   771 
   846 
   772 QPointF GWebContentViewWidget::mapToGlobal(const QPointF& p)
   847 QPointF GWebContentViewWidget::mapToGlobal(const QPointF& p)
   773 {
   848 {
   774     QList<QGraphicsView*> gvList = scene()->views();
   849     QList<QGraphicsView*> gvList = scene()->views();
   775     QList<QGraphicsView*>::iterator it;
   850     QList<QGraphicsView*>::iterator it;
   776     for(it = gvList.begin(); it != gvList.end(); it++)
   851     for (it = gvList.begin(); it != gvList.end(); it++)
   777         {
   852         {
   778             if (static_cast<QGraphicsView*>(*it)->hasFocus())
   853             if (static_cast<QGraphicsView*>(*it)->hasFocus())
   779                 {
   854                 {
   780                     QWidget* viewport = static_cast<QGraphicsView*>(*it)->viewport();
   855                     QWidget* viewport = static_cast<QGraphicsView*>(*it)->viewport();
   781                     return viewport->mapToGlobal(mapToScene(p).toPoint());
   856                     return viewport->mapToGlobal(mapToScene(p).toPoint());
   787 
   862 
   788 QPointF GWebContentViewWidget::mapFromGlobal(const QPointF& p)
   863 QPointF GWebContentViewWidget::mapFromGlobal(const QPointF& p)
   789 {
   864 {
   790     QList<QGraphicsView*> gvList = scene()->views();
   865     QList<QGraphicsView*> gvList = scene()->views();
   791     QList<QGraphicsView*>::iterator it;
   866     QList<QGraphicsView*>::iterator it;
   792     for(it = gvList.begin(); it != gvList.end(); it++)
   867     for (it = gvList.begin(); it != gvList.end(); it++)
   793         {
   868         {
   794             if (static_cast<QGraphicsView*>(*it)->hasFocus())
   869             if (static_cast<QGraphicsView*>(*it)->hasFocus())
   795                 {
   870                 {
   796                     QWidget* viewport = static_cast<QGraphicsView*>(*it)->viewport();
   871                     QWidget* viewport = static_cast<QGraphicsView*>(*it)->viewport();
   797                     return mapFromScene(viewport->mapFromGlobal(p.toPoint()));
   872                     return mapFromScene(viewport->mapFromGlobal(p.toPoint()));