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