browsercore/appfw/ThumbnailEngine/TnEngineHandler.cpp
branchGCC_SURGE
changeset 8 2e16851ffecd
parent 2 bf4420e9fa4d
parent 6 1c3b8676e58c
equal deleted inserted replaced
2:bf4420e9fa4d 8:2e16851ffecd
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <QPen>
       
    20 #include <QBrush>
       
    21 #include <QPainter>
       
    22 #include "webcontentview.h"
       
    23 #include "TnEngineHandler.h"
       
    24 #include "TnEngineView.h"
       
    25 #include "TnEngineGenerator.h"
       
    26 #include "WrtPageManager.h"
       
    27 #include "wrtbrowsercontainer.h"
       
    28 #include "qwebframe.h"
       
    29 #include <QDebug>
       
    30 
       
    31 namespace WRT {
       
    32 
       
    33 const int KDefaultZoomOutPercent = 250; // 2.5x TnEngine zoom out by default
       
    34 
       
    35 // defines a box relative to TnEngine edges. if view center goes outside this box
       
    36 // the view is recentered (50%==always center)
       
    37 const int KHScrollAreaPercent = 33; // horizontal distance in percent
       
    38 const int KVScrollAreaPercent = 50; // verical distance in percent
       
    39 const int KHScrollAreaPercentWithTouch1 = 20; // horizontal distance in percent when to scroll
       
    40 const int KVScrollAreaPercentWithTouch1 = 20; // verical distance in percent when to scroll
       
    41 const int KHScrollAreaPercentWithTouch2 = 25; // horizontal distance in percent amount to scroll (scroll to the right only)
       
    42 const int KVScrollAreaPercentWithTouch2 = 25; // verical distance in percent amount to scroll (scroll up only)
       
    43 const int KUpdateDelayComplete = 45000; // 45s
       
    44 const int KUpdateDelayLoading = 7000; // 7s
       
    45 const int KUpdateDelayFullScreen = 4000; // 4s
       
    46 const int KUpdateCbDelayComplete = 100; // 0.1s
       
    47 const int KUpdateCbDelayLoading = 1000; // 1s
       
    48 
       
    49 TnEngineHandler::TnEngineHandler(WrtPageManager * mgr, QWidget * parent)
       
    50     : m_pageMgr(mgr),
       
    51       m_zoomOutLevel(KDefaultZoomOutPercent),
       
    52       m_needsUpdate(false),
       
    53       m_documentComplete(false),
       
    54       m_fullScreenMode(false),
       
    55       m_pageScalerUpdating(false),
       
    56       m_activePage(NULL),
       
    57       m_parentWidget(parent)
       
    58 {
       
    59     m_TnEngineView = NULL;
       
    60     m_generator = NULL;
       
    61     m_updateCbTimer = NULL;
       
    62     m_updateTimer = NULL;
       
    63 
       
    64     activate();
       
    65 }
       
    66 
       
    67 TnEngineHandler::~TnEngineHandler()
       
    68 {
       
    69     deactivate();
       
    70 }
       
    71 
       
    72 QRect TnEngineHandler::containerRect() const
       
    73 {
       
    74     return m_containerRect;
       
    75 }
       
    76 
       
    77 QRect TnEngineHandler::TnEngineRect() const
       
    78 {
       
    79     QSize s(calcSize());
       
    80     //center
       
    81     QPoint p((m_containerRect.width()-s.width())/2,(m_containerRect.height()-s.height())/2);
       
    82     return QRect(p,s);
       
    83 }
       
    84 
       
    85 QRect TnEngineHandler::indicatorRect() const
       
    86 {
       
    87     QRect vp(documentViewport());
       
    88     QRect TnEngineVp(viewportOnDocument());
       
    89     vp.moveTo(vp.topLeft()-TnEngineVp.topLeft()); //make vp relative to TnEngineVp
       
    90     QRect res = fromDocCoords(vp); //translate vp to mmap coords
       
    91     // borders
       
    92     res.moveTo(res.topLeft()+TnEngineRect().topLeft());
       
    93     // so that view area is within the indicator
       
    94     res.adjust(1,1,-1,-1);
       
    95     // ensure it is within the bounds
       
    96     QRect mr = TnEngineRect();
       
    97     if (res.left() < mr.left()) {
       
    98         res.setLeft(mr.left());
       
    99     }
       
   100     if (res.top() < mr.top()) {
       
   101         res.setTop(mr.top());
       
   102     }
       
   103     if (res.right() > mr.right()) {
       
   104         res.setRight(mr.right());
       
   105     }
       
   106     if (res.bottom() > mr.bottom()) {
       
   107         res.setBottom(mr.bottom());
       
   108     }
       
   109     return res;
       
   110 }
       
   111 
       
   112 void TnEngineHandler::documentStarted()
       
   113 {
       
   114     scaledPageChanged(theRect(), true, false);
       
   115     m_documentComplete = false;
       
   116     m_viewportOnDocument = QRect();
       
   117     m_updateTimer->stop();
       
   118     m_updateCbTimer->stop();
       
   119     m_generator->clear();
       
   120     m_needsUpdate = false;
       
   121     // keep bitmaps during loading to avoid constant realloc
       
   122     m_generator->setKeepsBitmaps(true);
       
   123 }
       
   124 
       
   125 void TnEngineHandler::documentChanged()
       
   126 {
       
   127     long delay(m_documentComplete?KUpdateCbDelayComplete:KUpdateCbDelayLoading);
       
   128     m_updateCbTimer->start( delay );
       
   129 }
       
   130 
       
   131 void TnEngineHandler::documentChangedCb()
       
   132 {
       
   133     m_generator->invalidate();
       
   134     if (m_updateTimer->isActive()) {
       
   135         // timer running, update when it completes
       
   136         m_needsUpdate = true;
       
   137     }
       
   138     else {
       
   139         if (documentSize().height()>5) {
       
   140             m_viewportOnDocument = calcViewportOnDocument();
       
   141             m_generator->update();
       
   142             m_needsUpdate = false;
       
   143             // don't do another update for..
       
   144             long delay(m_fullScreenMode?KUpdateDelayFullScreen:m_documentComplete?KUpdateDelayComplete:KUpdateDelayLoading);
       
   145             m_updateTimer->start(delay);
       
   146         }
       
   147     }
       
   148 }
       
   149 
       
   150 void TnEngineHandler::documentViewportMoved()
       
   151 {
       
   152     m_viewportOnDocument = calcViewportOnDocument();
       
   153     m_generator->scroll();
       
   154     if (m_visible) {
       
   155         m_generator->update(true);
       
   156     }
       
   157     else {
       
   158         m_needsUpdate = true;
       
   159         if (!m_updateTimer->isActive()) {
       
   160             long delay(m_documentComplete?KUpdateDelayComplete:KUpdateDelayLoading);
       
   161             m_updateTimer->start(delay);
       
   162         }
       
   163     }
       
   164 }
       
   165 
       
   166 void TnEngineHandler::documentCompleted(bool)
       
   167 {
       
   168     if( m_pageScalerUpdating ) return;
       
   169     
       
   170     // wait for a while so to make sure all images are decoded etc.
       
   171     m_needsUpdate = true;
       
   172     m_documentComplete = true;
       
   173     m_updateTimer->start(0);
       
   174     // we can delete the buffers now
       
   175     m_generator->setKeepsBitmaps(false);
       
   176     documentChanged();
       
   177 }
       
   178 
       
   179 QRect TnEngineHandler::viewportOnTnEngine() const
       
   180 {
       
   181     return fromDocCoords(m_viewportOnDocument);
       
   182 }
       
   183 
       
   184 
       
   185 QRect TnEngineHandler::viewportOnDocument() const
       
   186 {
       
   187     return m_viewportOnDocument;
       
   188 }
       
   189 
       
   190 QSize TnEngineHandler::calcSize() const
       
   191 {
       
   192     QSize res, max;
       
   193     QSize mms = fromDocCoords(documentSize());
       
   194     max = m_containerRect.size();
       
   195     res.setWidth(qMin(mms.width(),max.width()));
       
   196     res.setHeight(qMin(mms.height(),max.height()));
       
   197     return res;
       
   198 }
       
   199 
       
   200 QRect TnEngineHandler::calcViewportOnDocument() const
       
   201 {
       
   202     QPoint mvp(m_viewportOnDocument.topLeft());
       
   203     
       
   204     QRect docvp(documentViewport());
       
   205     QSize docs(documentSize());
       
   206     QSize ms(toDocCoords(TnEngineRect().size()));
       
   207     QPoint docc(docvp.center());
       
   208     
       
   209     if (!m_dragging) {
       
   210         // scroll if not within 1/3 center area
       
   211         // check x-direction
       
   212         if (docc.x()<mvp.x()+ms.width()*KHScrollAreaPercent/100 ||
       
   213             docc.x()>mvp.x()+ms.width()*(100-KHScrollAreaPercent)/100) {
       
   214             // far enough from the center, re-center the view
       
   215             mvp.setX(docc.x()-ms.width()/2);
       
   216             if (mvp.x()+ms.width()>docs.width()) {
       
   217                 mvp.setX(docs.width()-ms.width());
       
   218             }
       
   219             if (mvp.x()<0) {
       
   220                 mvp.setX(0);
       
   221             }
       
   222         }
       
   223         // y-direction
       
   224         if (docc.y()<mvp.y()+ms.height()*KVScrollAreaPercent/100 ||
       
   225             docc.y()>mvp.y()+ms.height()*(100-KVScrollAreaPercent)/100) {
       
   226             // far enough from the center, re-center the view
       
   227             mvp.setY(docc.y()-ms.height()/2);
       
   228             if (mvp.y()+ms.height()>docs.height()) {
       
   229                 mvp.setY(docs.height()-ms.height());
       
   230             }
       
   231             if (mvp.y()<0) {
       
   232                 mvp.setY(0);
       
   233             }
       
   234         }
       
   235         
       
   236     }
       
   237     else {
       
   238         // check x-direction
       
   239         bool moved = false;
       
   240         if (docc.x()<mvp.x()+ms.width()*KHScrollAreaPercentWithTouch1/100) {
       
   241             mvp.setX(docc.x()-ms.width()*KHScrollAreaPercentWithTouch2/100);
       
   242             moved = true;
       
   243         }
       
   244         else if (docc.x()>mvp.x()+ms.width()*(100-KHScrollAreaPercentWithTouch1)/100) {
       
   245             mvp.setX(docc.x()-ms.width()*(100-KHScrollAreaPercentWithTouch1)/100);
       
   246             moved = true;
       
   247         }
       
   248         if (moved) {
       
   249             if (mvp.x()+ms.width()>docs.width()) {
       
   250                 mvp.setX(docs.width()-ms.width());
       
   251             }
       
   252             if (mvp.x()<0) {
       
   253                 mvp.setX(0);
       
   254             }
       
   255         }
       
   256         // y-direction
       
   257         moved = false;
       
   258         if (docc.y()<mvp.y()+ms.height()*KVScrollAreaPercentWithTouch1/100) {
       
   259             mvp.setY(docc.y()-ms.height()*KVScrollAreaPercentWithTouch2/80);
       
   260             moved = true;
       
   261         }
       
   262         else if (docc.y()>mvp.y()+ms.height()*(100-KVScrollAreaPercentWithTouch1)/100) {
       
   263       mvp.setY(docc.y()-ms.height()*(100-KVScrollAreaPercentWithTouch1)/100);
       
   264             moved = true;
       
   265         }
       
   266         
       
   267         if (moved) {
       
   268             if (mvp.y()+ms.height()>docs.height()) {
       
   269                 mvp.setY(docs.height()-ms.height());
       
   270             }
       
   271             if (mvp.y()<0) {
       
   272                 mvp.setY(0);
       
   273             }
       
   274         }
       
   275     }
       
   276     return QRect(mvp,ms);
       
   277 }
       
   278 
       
   279 void TnEngineHandler::draw(QPainter& gc, const QRect& rect) const
       
   280 {
       
   281     if (m_fullScreenMode) {
       
   282         QPen pen(Qt::SolidLine);
       
   283         pen.setColor(QColor(220,220,255));
       
   284         QBrush brush(Qt::SolidPattern);
       
   285         brush.setColor(QColor(220,220,255));
       
   286         gc.setPen(pen);
       
   287         gc.setBrush(brush);
       
   288         gc.drawRect(m_containerRect);
       
   289         m_generator->draw(gc, TnEngineRect());
       
   290         pen.setWidth(1);
       
   291         pen.setColor(QColor(255, 0, 0));
       
   292         gc.setPen(pen);
       
   293         gc.setBrush(Qt::NoBrush);
       
   294         gc.drawRect(indicatorRect());
       
   295     }
       
   296 }
       
   297 
       
   298 QRect TnEngineHandler::fromDocCoords(const QRect& from) const
       
   299 {
       
   300     return QRect(fromDocCoords(from.topLeft()),fromDocCoords(from.size()));
       
   301 }
       
   302 
       
   303 QPoint TnEngineHandler::fromDocCoords(const QPoint& from) const
       
   304 {
       
   305     QPoint res;
       
   306     res.setX(from.x()*100/m_zoomOutLevel);
       
   307     res.setY(from.y()*100/m_zoomOutLevel);
       
   308     return res;
       
   309 }
       
   310 
       
   311 QSize TnEngineHandler::fromDocCoords(const QSize& from) const
       
   312 {
       
   313     QSize res;
       
   314     res.setWidth(from.width()*100/m_zoomOutLevel);
       
   315     res.setHeight(from.height()*100/m_zoomOutLevel);
       
   316     return res;
       
   317 }
       
   318 
       
   319 QPoint TnEngineHandler::toDocCoords(const QPoint& from) const
       
   320 {
       
   321     QPoint res;
       
   322     res.setX(from.x()*m_zoomOutLevel/100);
       
   323     res.setY(from.y()*m_zoomOutLevel/100);
       
   324     return res;
       
   325 }
       
   326 
       
   327 QSize TnEngineHandler::toDocCoords(const QSize& from) const
       
   328 {
       
   329     QSize res;
       
   330     res.setWidth(from.width()*m_zoomOutLevel/100);
       
   331     res.setHeight(from.height()*m_zoomOutLevel/100);
       
   332     return res;
       
   333 }
       
   334 
       
   335 QRect TnEngineHandler::toDocCoords(const QRect& from) const
       
   336 {
       
   337   return QRect(toDocCoords(from.topLeft()),toDocCoords(from.size()));
       
   338 }
       
   339 
       
   340 bool TnEngineHandler::checkAndCreateBitmap(QSize sz, QPixmap*& image)
       
   341 {
       
   342     if ( sz.width()<=0 || sz.height()<=0 ) {
       
   343         // delete bitmap if there was one
       
   344         delete image;
       
   345         image = 0;
       
   346         return false;
       
   347     }
       
   348     else {
       
   349         if ( image && sz != image->size() ) {
       
   350             // resize if different size
       
   351             QPixmap* bm = new QPixmap(image->copy(0, 0, sz.width(), sz.height()));
       
   352             delete image;
       
   353             image = bm;
       
   354         }
       
   355         else if ( !image ) {
       
   356             // create new
       
   357       QPixmap* bm = new QPixmap(sz);
       
   358           image = bm;
       
   359         }
       
   360     }
       
   361     return true;
       
   362 }
       
   363 
       
   364 void TnEngineHandler::updateCbTimerCb()
       
   365 {
       
   366     m_updateCbTimer->stop();
       
   367     m_pageScalerUpdating = true;
       
   368     documentChangedCb();
       
   369     m_pageScalerUpdating = false;
       
   370 }
       
   371 
       
   372 void TnEngineHandler::updateTimerCb()
       
   373 {
       
   374     m_updateTimer->stop();
       
   375     m_pageScalerUpdating = true;
       
   376     if (m_needsUpdate) {
       
   377         m_viewportOnDocument = calcViewportOnDocument();
       
   378         m_generator->update();
       
   379     }
       
   380     m_needsUpdate = false;
       
   381     m_pageScalerUpdating = false;
       
   382     m_updateTimer->stop();
       
   383 }
       
   384 
       
   385 QRect TnEngineHandler::theRect() const
       
   386 {
       
   387     return m_containerRect;
       
   388 }
       
   389 
       
   390 void TnEngineHandler::setContainerRect(const QRect& rect)
       
   391 {
       
   392     m_containerRect = rect;
       
   393     m_viewportOnDocument = calcViewportOnDocument();
       
   394 }
       
   395 
       
   396 bool TnEngineHandler::isFullScreenMode() const
       
   397 {
       
   398     return m_fullScreenMode;
       
   399 }
       
   400 
       
   401 void TnEngineHandler::setFullScreenMode(bool fullScreenMode)
       
   402 {
       
   403     m_fullScreenMode = fullScreenMode;
       
   404     m_viewportOnDocument = calcViewportOnDocument();
       
   405 }
       
   406 
       
   407 void TnEngineHandler::setVisible(bool visible)
       
   408 {
       
   409     if (visible && !m_visible) {
       
   410         updateNow();
       
   411     }
       
   412     m_visible = visible;
       
   413 }
       
   414 
       
   415 void TnEngineHandler::updateNow()
       
   416 {
       
   417     if (m_updateCbTimer->isActive()) {
       
   418         m_updateCbTimer->stop();
       
   419         m_updateTimer->stop();
       
   420         documentChangedCb();
       
   421     }
       
   422     else {
       
   423         m_updateTimer->stop();
       
   424         updateTimerCb();
       
   425     }
       
   426 }
       
   427 
       
   428 void TnEngineHandler::drawDocumentPart(QPainter& painter, const QRect& documentAreaToDraw)
       
   429 {
       
   430     QWebFrame* frame = m_activePage->mainFrame();
       
   431     QRegion clip(documentAreaToDraw);
       
   432     painter.save();
       
   433     painter.translate(-documentAreaToDraw.x(), -documentAreaToDraw.y());
       
   434     frame->render(&painter, clip);
       
   435     painter.restore();
       
   436 }
       
   437 
       
   438 QRect TnEngineHandler::documentViewport() const
       
   439 {
       
   440     QSize size = m_activePage->webWidget()->size().toSize();
       
   441     QSize offset = QSize(m_scrollX, m_scrollY);
       
   442     return QRect(offset.width(), offset.height(), size.width(), size.height());
       
   443 }
       
   444 
       
   445 void TnEngineHandler::scaledPageChanged(const QRect& area, bool /*fullScreen*/, bool /*scroll*/)
       
   446 {
       
   447     if (m_TnEngineView)
       
   448         m_TnEngineView->update(area);
       
   449 }
       
   450 
       
   451 QSize TnEngineHandler::documentSize() const
       
   452 {
       
   453     return m_activePage->mainFrame()->contentsSize();
       
   454 }
       
   455 
       
   456 QWidget* TnEngineHandler::widget()
       
   457 { 
       
   458     return m_TnEngineView;
       
   459 }
       
   460 
       
   461 
       
   462 void TnEngineHandler::activate()
       
   463 {
       
   464     if (!m_TnEngineView) {
       
   465         createGenerator();
       
   466         createView();
       
   467     }
       
   468 }
       
   469 
       
   470 void TnEngineHandler::deactivate()
       
   471 {
       
   472     if (m_TnEngineView) {
       
   473         destroyView();
       
   474         destroyGenerator();
       
   475     }
       
   476 }
       
   477 
       
   478 void TnEngineHandler::createGenerator()
       
   479 {
       
   480     Q_ASSERT(m_pageMgr);
       
   481     m_activePage = m_pageMgr->currentPage();
       
   482     Q_ASSERT(m_activePage);
       
   483     Q_ASSERT(!m_generator);
       
   484     m_dragging = false;
       
   485     QPoint pos(0,0);
       
   486     pos = m_activePage->mainFrame()->scrollPosition();
       
   487     m_scrollX = pos.x();
       
   488     m_scrollY = pos.y();
       
   489     if (!m_generator) {
       
   490         m_generator = TnEngineGenerator::initWithTnEngine(*this);
       
   491         m_updateCbTimer = new QTimer();
       
   492         m_updateTimer = new QTimer();
       
   493     }
       
   494 }
       
   495 
       
   496 void TnEngineHandler::destroyGenerator()
       
   497 {
       
   498     Q_ASSERT(m_generator);
       
   499     if (m_generator) {
       
   500         delete m_generator;
       
   501         m_generator = NULL;
       
   502     }
       
   503     if (m_updateCbTimer) {
       
   504         m_updateCbTimer->stop();
       
   505         delete m_updateCbTimer;
       
   506         m_updateCbTimer = NULL;
       
   507     }
       
   508     if (m_updateTimer) {
       
   509         m_updateTimer->stop();
       
   510         delete m_updateTimer;
       
   511         m_updateTimer = NULL;
       
   512     }
       
   513 }
       
   514 
       
   515 void TnEngineHandler::createView()
       
   516 {
       
   517     Q_ASSERT(m_activePage);
       
   518     connect(m_updateCbTimer, SIGNAL(timeout()), this, SLOT(updateCbTimerCb()));
       
   519     connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(updateTimerCb()));
       
   520     //    connect(WebController::webController(), SIGNAL(activePageChanged()), this, SLOT(cancelTnEngineView()));
       
   521     connect(m_activePage, SIGNAL(loadStarted()), this, SLOT(documentStarted()));
       
   522     connect(m_activePage, SIGNAL(repaintRequested(const QRect&)), this, SLOT(documentChanged()));
       
   523     connect(m_activePage, SIGNAL(loadFinished(bool)), this, SLOT(documentCompleted(bool)));
       
   524     //    connect(m_activePage, SIGNAL(scrollRequested(int, int, const QRect &)), this, SLOT(documentViewportMoved()));
       
   525     Q_ASSERT(!m_TnEngineView);
       
   526 
       
   527 
       
   528 
       
   529 
       
   530     //m_TnEngineView = TnEngineView::initiWithParentAndTnEngineHandler(m_activePage->webWidget(), this);
       
   531     m_TnEngineView = TnEngineView::initiWithParentAndTnEngineHandler(m_parentWidget, this);
       
   532     m_TnEngineView->show();
       
   533     m_savedPointPageView = documentViewport().topLeft();
       
   534     //    connect(m_activePage, SIGNAL(scrollRequested(int, int, const QRect &)), m_TnEngineView, SLOT(update()));
       
   535     connect(m_TnEngineView, SIGNAL(scrollBy(int, int)), this, SLOT(scrollBy(int, int)));
       
   536     connect(m_TnEngineView, SIGNAL(scrollStarted()), this, SLOT(draggingStarted()));
       
   537     connect(m_TnEngineView, SIGNAL(scrollEnded()), this, SLOT(draggingEnded()));
       
   538     connect(m_TnEngineView, SIGNAL(ok()), this, SLOT(okInvoked()));
       
   539     // get initial thumbnail
       
   540     documentStarted();
       
   541     documentChanged();
       
   542     documentCompleted(true);
       
   543 }
       
   544 
       
   545 void TnEngineHandler::destroyView()
       
   546 {
       
   547     Q_ASSERT(m_activePage);
       
   548     disconnect(m_updateCbTimer, SIGNAL(timeout()), this, SLOT(updateCbTimerCb()));
       
   549     disconnect(m_updateTimer, SIGNAL(timeout()), this, SLOT(updateTimerCb()));
       
   550     //    disconnect(WebController::webController(), SIGNAL(activePageChanged()), this, SLOT(cancelTnEngineView()));
       
   551     disconnect(m_activePage, SIGNAL(loadStarted()), this, SLOT(documentStarted()));
       
   552     disconnect(m_activePage, SIGNAL(repaintRequested(const QRect&)), this, SLOT(documentChanged()));
       
   553     disconnect(m_activePage, SIGNAL(loadFinished(bool)), this, SLOT(documentCompleted(bool)));
       
   554     //    disconnect(m_activePage, SIGNAL(scrollRequested(int, int, const QRect &)), this, SLOT(documentViewportMoved()));
       
   555     Q_ASSERT(m_TnEngineView);
       
   556     //    disconnect(m_activePage, SIGNAL(scrollRequested(int, int, const QRect &)), m_TnEngineView, SLOT(update()));
       
   557     disconnect(m_TnEngineView, SIGNAL(scrollBy(int, int)), this, SLOT(scrollBy(int, int)));
       
   558     disconnect(m_TnEngineView, SIGNAL(scrollStarted()), this, SLOT(draggingStarted()));
       
   559     disconnect(m_TnEngineView, SIGNAL(scrollEnded()), this, SLOT(draggingEnded()));
       
   560     disconnect(m_TnEngineView, SIGNAL(ok()), this, SLOT(okInvoked()));
       
   561     m_TnEngineView->hide();
       
   562     m_TnEngineView->deleteLater();
       
   563     m_TnEngineView = NULL;
       
   564     m_visible = false;
       
   565 }
       
   566 
       
   567 void TnEngineHandler::scrollBy(int x, int y)
       
   568 {
       
   569     WebContentWidget* canvas = static_cast<WebContentWidget*>(m_activePage->webWidget());
       
   570     qreal w = documentSize().width() - canvas->size().width();
       
   571     qreal h = documentSize().height() - canvas->size().height();
       
   572 
       
   573     qreal newX = m_scrollX + x;
       
   574     qreal newY = m_scrollY + y;
       
   575     newX = newX > 0 ? newX : 0;
       
   576     newX = newX < w ? newX : w;
       
   577     newY = newY > 0 ? newY : 0;
       
   578     newY = newY < h ? newY : h;
       
   579     m_scrollX = newX;
       
   580     m_scrollY = newY;
       
   581     if (m_generator)
       
   582         documentViewportMoved();
       
   583     if (m_TnEngineView)
       
   584         m_TnEngineView->update();
       
   585 }
       
   586 
       
   587 void TnEngineHandler::draggingStarted()
       
   588 {
       
   589     m_dragging = true;
       
   590 }
       
   591 
       
   592 void TnEngineHandler::draggingEnded()
       
   593 {
       
   594     m_dragging = false;
       
   595 }
       
   596 
       
   597 void TnEngineHandler::okInvoked()
       
   598 {
       
   599     QPoint pos(0,0);
       
   600     pos = m_activePage->mainFrame()->scrollPosition();
       
   601     
       
   602     emit ok(m_scrollX - pos.x(), m_scrollY - pos.y());
       
   603 }
       
   604 
       
   605 
       
   606 }
       
   607 //  End of File