Changeset 59152 in webkit


Ignore:
Timestamp:
May 11, 2010 8:45:27 AM (14 years ago)
Author:
eric@webkit.org
Message:

2010-05-11 Jesus Sanchez-Palencia <jesus@webkit.org>

Reviewed by Kenneth Rohde Christiansen.

Add PageClientQGraphicsWidget specific implementation.
QGraphicsWebViewPrivate doesn't inherit QWebPageClient anymore
and the needed functions were moved to this new PageClient class,
including Tiling and Accelerated Composite specific ones.

[Qt] PageClientQt specific implementation for QGraphicsWidget
https://bugs.webkit.org/show_bug.cgi?id=37866

  • Api/qgraphicswebview.cpp: (QGraphicsWebViewPrivate::QGraphicsWebViewPrivate): (QGraphicsWebViewPrivate::~QGraphicsWebViewPrivate): (QGraphicsWebViewPrivate::syncLayers): (QGraphicsWebViewPrivate::_q_scaleChanged): (QGraphicsWebView::event): (QGraphicsWebView::setPage): (QGraphicsWebView::updateGeometry): (QGraphicsWebView::setGeometry): (QGraphicsWebView::setResizesToContents):
  • WebCoreSupport/PageClientQt.cpp: (WebCore::PageClientQGraphicsWidget::~PageClientQGraphicsWidget): (WebCore::PageClientQGraphicsWidget::scroll): (WebCore::PageClientQGraphicsWidget::update): (WebCore::PageClientQGraphicsWidget::createOrDeleteOverlay): (WebCore::PageClientQGraphicsWidget::syncLayers): (WebCore::PageClientQGraphicsWidget::setRootGraphicsLayer): (WebCore::PageClientQGraphicsWidget::markForSync): (WebCore::PageClientQGraphicsWidget::updateCompositingScrollPosition): (WebCore::PageClientQGraphicsWidget::updateTiledBackingStoreScale): (WebCore::PageClientQGraphicsWidget::setInputMethodEnabled): (WebCore::PageClientQGraphicsWidget::inputMethodEnabled): (WebCore::PageClientQGraphicsWidget::setInputMethodHint): (WebCore::PageClientQGraphicsWidget::cursor): (WebCore::PageClientQGraphicsWidget::updateCursor): (WebCore::PageClientQGraphicsWidget::palette): (WebCore::PageClientQGraphicsWidget::screenNumber): (WebCore::PageClientQGraphicsWidget::ownerWidget): (WebCore::PageClientQGraphicsWidget::geometryRelativeToOwnerWidget): (WebCore::PageClientQGraphicsWidget::pluginParent): (WebCore::PageClientQGraphicsWidget::style):
  • WebCoreSupport/PageClientQt.h: (WebCore::QGraphicsItemOverlay::page): (WebCore::QGraphicsItemOverlay::boundingRect): (WebCore::QGraphicsItemOverlay::paint): (WebCore::QGraphicsItemOverlay::prepareGraphicsItemGeometryChange): (WebCore::PageClientQGraphicsWidget::PageClientQGraphicsWidget): (WebCore::PageClientQGraphicsWidget::isQWidgetClient): (WebCore::PageClientQGraphicsWidget::allowsAcceleratedCompositing): (WebCore::PageClientQGraphicsWidget::):
Location:
trunk/WebKit/qt
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit/qt/Api/qgraphicswebview.cpp

    r59057 r59152  
    2626#include "qwebpage.h"
    2727#include "qwebpage_p.h"
    28 #include "QWebPageClient.h"
     28#include "PageClientQt.h"
    2929#include "FrameView.h"
    3030#include "GraphicsContext.h"
     
    4747#include <Settings.h>
    4848
    49 // the overlay is here for one reason only: to have the scroll-bars and other
    50 // extra UI elements appear on top of any QGraphicsItems created by CSS compositing layers
    51 class QGraphicsWebViewOverlay : public QGraphicsItem {
    52     public:
    53     QGraphicsWebViewOverlay(QGraphicsWebView* view)
    54             :QGraphicsItem(view)
    55             , q(view)
    56     {
    57         setPos(0, 0);
    58 #if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
    59         setFlag(QGraphicsItem::ItemUsesExtendedStyleOption, true);
    60 #endif
    61         setCacheMode(QGraphicsItem::DeviceCoordinateCache);
    62     }
    63 
    64     QRectF boundingRect() const
    65     {
    66         return q->boundingRect();
    67     }
    68 
    69     void paint(QPainter* painter, const QStyleOptionGraphicsItem* options, QWidget*)
    70     {
    71         q->page()->mainFrame()->render(painter, static_cast<QWebFrame::RenderLayer>(QWebFrame::AllLayers&(~QWebFrame::ContentsLayer)), options->exposedRect.toRect());
    72     }
    73 
    74     friend class QGraphicsWebView;
    75     QGraphicsWebView* q;
    76 };
    77 
    78 class QGraphicsWebViewPrivate : public QWebPageClient {
     49using namespace WebCore;
     50
     51class QGraphicsWebViewPrivate {
    7952public:
    8053    QGraphicsWebViewPrivate(QGraphicsWebView* parent)
    8154        : q(parent)
    8255        , page(0)
    83         , resizesToContents(false)
     56        , resizesToContents(false) {}
     57
     58    virtual ~QGraphicsWebViewPrivate() {};
     59
    8460#if USE(ACCELERATED_COMPOSITING)
    85         , shouldSync(false)
    86 #endif
    87     {
    88 #if USE(ACCELERATED_COMPOSITING)
    89         // the overlay and stays alive for the lifetime of
    90         // this QGraphicsWebView as the scrollbars are needed when there's no compositing
    91         q->setFlag(QGraphicsItem::ItemUsesExtendedStyleOption);
    92         syncMetaMethod = q->metaObject()->method(q->metaObject()->indexOfMethod("syncLayers()"));
    93 #endif
    94     }
    95 
    96     virtual ~QGraphicsWebViewPrivate();
    97 
    98     virtual void scroll(int dx, int dy, const QRect&);
    99     virtual void update(const QRect& dirtyRect);
    100     virtual void setInputMethodEnabled(bool enable);
    101     virtual bool inputMethodEnabled() const;
    102 #if QT_VERSION >= 0x040600
    103     virtual void setInputMethodHint(Qt::InputMethodHint hint, bool enable);
    104 #endif
    105 
    106 #ifndef QT_NO_CURSOR
    107     virtual QCursor cursor() const;
    108     virtual void updateCursor(const QCursor& cursor);
    109 #endif
    110 
    111     virtual QPalette palette() const;
    112     virtual int screenNumber() const;
    113     virtual QWidget* ownerWidget() const;
    114     virtual QRect geometryRelativeToOwnerWidget() const;
    115 
    116     virtual QObject* pluginParent() const;
    117 
    118     virtual QStyle* style() const;
    119 
    120 #if USE(ACCELERATED_COMPOSITING)
    121     virtual void setRootGraphicsLayer(QGraphicsItem* layer);
    122     virtual void markForSync(bool scheduleSync);
    123     void updateCompositingScrollPosition();
    124 
    125     // QGraphicsWebView can render composited layers
    126     virtual bool allowsAcceleratedCompositing() const { return true; }
     61    void syncLayers();
    12762#endif
    12863
    12964    void updateResizesToContentsForPage();
    13065    QRectF graphicsItemVisibleRect() const;
    131 #if ENABLE(TILED_BACKING_STORE)
    132     void updateTiledBackingStoreScale();
    133 #endif
    134 
    135     void createOrDeleteOverlay();
    136 
    137     void syncLayers();
    13866
    13967    void unsetPageIfExists();
     
    14876    QGraphicsWebView* q;
    14977    QWebPage* page;
    150 
    15178    bool resizesToContents;
    15279
    153     // the overlay gets instantiated when the root layer is attached, and get deleted when it's detached
    154     QSharedPointer<QGraphicsWebViewOverlay> overlay;
    155 
    156     // we need to put the root graphics layer behind the overlay (which contains the scrollbar)
    157     enum { RootGraphicsLayerZValue, OverlayZValue };
     80    // Just a convenience to avoid using page->client->overlay always
     81    QSharedPointer<QGraphicsItemOverlay> overlay;
     82};
    15883
    15984#if USE(ACCELERATED_COMPOSITING)
    160     QWeakPointer<QGraphicsObject> rootGraphicsLayer;
    161     // we need to sync the layers if we get a special call from the WebCore
    162     // compositor telling us to do so. We'll get that call from ChromeClientQt
    163     bool shouldSync;
    164 
    165     // we have to flush quite often, so we use a meta-method instead of QTimer::singleShot for putting the event in the queue
    166     QMetaMethod syncMetaMethod;
    167 #endif
    168 };
    169 
    170 QGraphicsWebViewPrivate::~QGraphicsWebViewPrivate()
    171 {
    172 #if USE(ACCELERATED_COMPOSITING)
    173     if (!rootGraphicsLayer)
    174         return;
    175     // we don't need to delete the root graphics layer. The lifecycle is managed in GraphicsLayerQt.cpp.
    176     rootGraphicsLayer.data()->setParentItem(0);
    177     q->scene()->removeItem(rootGraphicsLayer.data());
    178 #endif
    179 }
    180 
    181 void QGraphicsWebViewPrivate::createOrDeleteOverlay()
    182 {
    183     bool useOverlay = false;
    184     if (!resizesToContents) {
    185 #if USE(ACCELERATED_COMPOSITING)
    186         useOverlay = useOverlay || rootGraphicsLayer;
    187 #endif
    188 #if ENABLE(TILED_BACKING_STORE)
    189         useOverlay = useOverlay || QWebFramePrivate::core(q->page()->mainFrame())->tiledBackingStore();
    190 #endif
    191     }
    192     if (useOverlay == !!overlay)
    193         return;
    194     if (useOverlay) {
    195         overlay = QSharedPointer<QGraphicsWebViewOverlay>(new QGraphicsWebViewOverlay(q));
    196         overlay->setZValue(OverlayZValue);
    197     } else
    198         overlay.clear();
    199 }
    200 
    201 #if USE(ACCELERATED_COMPOSITING)
    202 void QGraphicsWebViewPrivate::setRootGraphicsLayer(QGraphicsItem* layer)
    203 {
    204     if (rootGraphicsLayer) {
    205         rootGraphicsLayer.data()->setParentItem(0);
    206         q->scene()->removeItem(rootGraphicsLayer.data());
    207         QWebFramePrivate::core(q->page()->mainFrame())->view()->syncCompositingStateRecursive();
    208     }
    209 
    210     rootGraphicsLayer = layer ? layer->toGraphicsObject() : 0;
    211 
    212     if (layer) {
    213         layer->setFlag(QGraphicsItem::ItemClipsChildrenToShape, true);
    214         layer->setParentItem(q);
    215         layer->setZValue(RootGraphicsLayerZValue);
    216         updateCompositingScrollPosition();
    217     }
    218     createOrDeleteOverlay();
    219 }
    220 
    221 void QGraphicsWebViewPrivate::markForSync(bool scheduleSync)
    222 {
    223     shouldSync = true;
    224     if (scheduleSync)
    225         syncMetaMethod.invoke(q, Qt::QueuedConnection);
    226 }
    227 
    228 void QGraphicsWebViewPrivate::updateCompositingScrollPosition()
    229 {
    230     if (rootGraphicsLayer && q->page() && q->page()->mainFrame()) {
    231         const QPoint scrollPosition = q->page()->mainFrame()->scrollPosition();
    232         rootGraphicsLayer.data()->setPos(-scrollPosition);
    233     }
    234 }
    235 #endif
    236 
    23785void QGraphicsWebViewPrivate::syncLayers()
    23886{
    239 #if USE(ACCELERATED_COMPOSITING)
    240     if (shouldSync) {
    241         QWebFramePrivate::core(q->page()->mainFrame())->view()->syncCompositingStateRecursive();
    242         shouldSync = false;
    243     }
    244 #endif
    245 }
     87    static_cast<PageClientQGraphicsWidget*>(page->d->client)->syncLayers();
     88}
     89#endif
    24690
    24791void QGraphicsWebViewPrivate::_q_doLoadFinished(bool success)
     
    274118}
    275119
    276 void QGraphicsWebViewPrivate::scroll(int dx, int dy, const QRect& rectToScroll)
    277 {
    278     q->scroll(qreal(dx), qreal(dy), QRectF(rectToScroll));
    279 
    280 #if USE(ACCELERATED_COMPOSITING)
    281     updateCompositingScrollPosition();
    282 #endif
    283 }
    284 
    285 void QGraphicsWebViewPrivate::update(const QRect & dirtyRect)
    286 {
    287     q->update(QRectF(dirtyRect));
    288 
    289     createOrDeleteOverlay();
    290     if (overlay)
    291         overlay->update(QRectF(dirtyRect));
    292 #if USE(ACCELERATED_COMPOSITING)
    293     updateCompositingScrollPosition();
    294     syncLayers();
    295 #endif
    296 }
    297 
    298 
    299 void QGraphicsWebViewPrivate::setInputMethodEnabled(bool enable)
    300 {
    301 #if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
    302     q->setFlag(QGraphicsItem::ItemAcceptsInputMethod, enable);
    303 #endif
    304 }
    305 
    306 bool QGraphicsWebViewPrivate::inputMethodEnabled() const
    307 {
    308 #if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
    309     return q->flags() & QGraphicsItem::ItemAcceptsInputMethod;
    310 #else
    311     return false;
    312 #endif
    313 }
    314 
    315 #if QT_VERSION >= 0x040600
    316 void QGraphicsWebViewPrivate::setInputMethodHint(Qt::InputMethodHint hint, bool enable)
    317 {
    318     if (enable)
    319         q->setInputMethodHints(q->inputMethodHints() | hint);
    320     else
    321         q->setInputMethodHints(q->inputMethodHints() & ~hint);
    322 }
    323 #endif
    324 #ifndef QT_NO_CURSOR
    325 QCursor QGraphicsWebViewPrivate::cursor() const
    326 {
    327     return q->cursor();
    328 }
    329 
    330 void QGraphicsWebViewPrivate::updateCursor(const QCursor& cursor)
    331 {
    332     q->setCursor(cursor);
    333 }
    334 #endif
    335 
    336 QPalette QGraphicsWebViewPrivate::palette() const
    337 {
    338     return q->palette();
    339 }
    340 
    341 int QGraphicsWebViewPrivate::screenNumber() const
    342 {
    343 #if defined(Q_WS_X11)
    344     if (QGraphicsScene* scene = q->scene()) {
    345         const QList<QGraphicsView*> views = scene->views();
    346 
    347         if (!views.isEmpty())
    348             return views.at(0)->x11Info().screen();
    349     }
    350 #endif
    351 
    352     return 0;
    353 }
    354 
    355 QWidget* QGraphicsWebViewPrivate::ownerWidget() const
    356 {
    357     if (QGraphicsScene* scene = q->scene()) {
    358         const QList<QGraphicsView*> views = scene->views();
    359         return views.value(0);
    360     }
    361     return 0;
    362 }
    363 
    364 QRect QGraphicsWebViewPrivate::geometryRelativeToOwnerWidget() const
    365 {
    366     if (!q->scene())
    367         return QRect();
    368 
    369     QList<QGraphicsView*> views = q->scene()->views();
    370     if (views.isEmpty())
    371         return QRect();
    372 
    373     QGraphicsView* view = views.at(0);
    374     return view->mapFromScene(q->boundingRect()).boundingRect();
    375 }
    376 
    377 QObject* QGraphicsWebViewPrivate::pluginParent() const
    378 {
    379     return q;
    380 }
    381 
    382 QStyle* QGraphicsWebViewPrivate::style() const
    383 {
    384     return q->style();
    385 }
    386 
    387120void QGraphicsWebViewPrivate::updateResizesToContentsForPage()
    388121{
     
    417150{
    418151#if ENABLE(TILED_BACKING_STORE)
    419     updateTiledBackingStoreScale();
     152    static_cast<PageClientQGraphicsWidget*>(page->d->client)->updateTiledBackingStoreScale();
    420153#endif
    421154}
     
    439172    return q->mapRectFromScene(QRectF(QPoint(xPosition, yPosition), views[0]->viewport()->size()));
    440173}
    441 
    442 #if ENABLE(TILED_BACKING_STORE)
    443 void QGraphicsWebViewPrivate::updateTiledBackingStoreScale()
    444 {
    445     WebCore::TiledBackingStore* backingStore = QWebFramePrivate::core(page->mainFrame())->tiledBackingStore();
    446     if (!backingStore)
    447         return;
    448     backingStore->setContentsScale(q->scale());
    449 }
    450 #endif
    451174
    452175/*!
     
    712435                // FIXME: Add a QEvent::CursorUnset or similar to Qt.
    713436                if (cursor().shape() == Qt::ArrowCursor)
    714                     d->resetCursor();
     437                    d->page->d->client->resetCursor();
    715438            }
    716439#endif
     
    763486        return;
    764487
    765     d->page->d->client = d; // set the page client
     488    d->page->d->client = new PageClientQGraphicsWidget(this, page); // set the page client
     489    d->overlay = static_cast<PageClientQGraphicsWidget*>(d->page->d->client)->overlay;
    766490
    767491    if (d->overlay)
    768         d->overlay->prepareGeometryChange();
     492        d->overlay->prepareGraphicsItemGeometryChange();
    769493
    770494    QSize size = geometry().size().toSize();
     
    877601{
    878602    if (d->overlay)
    879         d->overlay->prepareGeometryChange();
     603        d->overlay->prepareGraphicsItemGeometryChange();
    880604
    881605    QGraphicsWidget::updateGeometry();
     
    895619
    896620    if (d->overlay)
    897         d->overlay->prepareGeometryChange();
     621        d->overlay->prepareGraphicsItemGeometryChange();
    898622
    899623    if (!d->page)
     
    1129853        return;
    1130854    d->resizesToContents = enabled;
    1131     if (d->page)
     855    if (d->page) {
     856        static_cast<PageClientQGraphicsWidget*>(d->page->d->client)->viewResizesToContents = enabled;
    1132857        d->updateResizesToContentsForPage();
     858    }
    1133859}
    1134860
  • trunk/WebKit/qt/ChangeLog

    r59057 r59152  
     12010-05-11  Jesus Sanchez-Palencia  <jesus@webkit.org>
     2
     3        Reviewed by Kenneth Rohde Christiansen.
     4
     5        Add PageClientQGraphicsWidget specific implementation.
     6        QGraphicsWebViewPrivate doesn't inherit QWebPageClient anymore
     7        and the needed functions were moved to this new PageClient class,
     8        including Tiling and Accelerated Composite specific ones.
     9
     10        [Qt] PageClientQt specific implementation for QGraphicsWidget
     11        https://bugs.webkit.org/show_bug.cgi?id=37866
     12
     13        * Api/qgraphicswebview.cpp:
     14        (QGraphicsWebViewPrivate::QGraphicsWebViewPrivate):
     15        (QGraphicsWebViewPrivate::~QGraphicsWebViewPrivate):
     16        (QGraphicsWebViewPrivate::syncLayers):
     17        (QGraphicsWebViewPrivate::_q_scaleChanged):
     18        (QGraphicsWebView::event):
     19        (QGraphicsWebView::setPage):
     20        (QGraphicsWebView::updateGeometry):
     21        (QGraphicsWebView::setGeometry):
     22        (QGraphicsWebView::setResizesToContents):
     23        * WebCoreSupport/PageClientQt.cpp:
     24        (WebCore::PageClientQGraphicsWidget::~PageClientQGraphicsWidget):
     25        (WebCore::PageClientQGraphicsWidget::scroll):
     26        (WebCore::PageClientQGraphicsWidget::update):
     27        (WebCore::PageClientQGraphicsWidget::createOrDeleteOverlay):
     28        (WebCore::PageClientQGraphicsWidget::syncLayers):
     29        (WebCore::PageClientQGraphicsWidget::setRootGraphicsLayer):
     30        (WebCore::PageClientQGraphicsWidget::markForSync):
     31        (WebCore::PageClientQGraphicsWidget::updateCompositingScrollPosition):
     32        (WebCore::PageClientQGraphicsWidget::updateTiledBackingStoreScale):
     33        (WebCore::PageClientQGraphicsWidget::setInputMethodEnabled):
     34        (WebCore::PageClientQGraphicsWidget::inputMethodEnabled):
     35        (WebCore::PageClientQGraphicsWidget::setInputMethodHint):
     36        (WebCore::PageClientQGraphicsWidget::cursor):
     37        (WebCore::PageClientQGraphicsWidget::updateCursor):
     38        (WebCore::PageClientQGraphicsWidget::palette):
     39        (WebCore::PageClientQGraphicsWidget::screenNumber):
     40        (WebCore::PageClientQGraphicsWidget::ownerWidget):
     41        (WebCore::PageClientQGraphicsWidget::geometryRelativeToOwnerWidget):
     42        (WebCore::PageClientQGraphicsWidget::pluginParent):
     43        (WebCore::PageClientQGraphicsWidget::style):
     44        * WebCoreSupport/PageClientQt.h:
     45        (WebCore::QGraphicsItemOverlay::page):
     46        (WebCore::QGraphicsItemOverlay::boundingRect):
     47        (WebCore::QGraphicsItemOverlay::paint):
     48        (WebCore::QGraphicsItemOverlay::prepareGraphicsItemGeometryChange):
     49        (WebCore::PageClientQGraphicsWidget::PageClientQGraphicsWidget):
     50        (WebCore::PageClientQGraphicsWidget::isQWidgetClient):
     51        (WebCore::PageClientQGraphicsWidget::allowsAcceleratedCompositing):
     52        (WebCore::PageClientQGraphicsWidget::):
     53
    1542010-05-09  Noam Rosenthal  <noam.rosenthal@nokia.com>
    255
  • trunk/WebKit/qt/WebCoreSupport/PageClientQt.cpp

    r58038 r59152  
    104104}
    105105
    106 }
     106PageClientQGraphicsWidget::~PageClientQGraphicsWidget()
     107{
     108#if USE(ACCELERATED_COMPOSITING)
     109    if (!rootGraphicsLayer)
     110        return;
     111    // we don't need to delete the root graphics layer. The lifecycle is managed in GraphicsLayerQt.cpp.
     112    rootGraphicsLayer.data()->setParentItem(0);
     113    view->scene()->removeItem(rootGraphicsLayer.data());
     114#endif
     115}
     116
     117void PageClientQGraphicsWidget::scroll(int dx, int dy, const QRect& rectToScroll)
     118{
     119#if USE(ACCELERATED_COMPOSITING)
     120    updateCompositingScrollPosition();
     121#endif
     122}
     123
     124void PageClientQGraphicsWidget::update(const QRect & dirtyRect)
     125{
     126    createOrDeleteOverlay();
     127    if (overlay)
     128        overlay->update(QRectF(dirtyRect));
     129#if USE(ACCELERATED_COMPOSITING)
     130    syncLayers();
     131#endif
     132}
     133
     134void PageClientQGraphicsWidget::createOrDeleteOverlay()
     135{
     136    bool useOverlay = false;
     137    if (!viewResizesToContents) {
     138#if USE(ACCELERATED_COMPOSITING)
     139        useOverlay = useOverlay || rootGraphicsLayer;
     140#endif
     141#if ENABLE(TILED_BACKING_STORE)
     142        useOverlay = useOverlay || QWebFramePrivate::core(page->mainFrame())->tiledBackingStore();
     143#endif
     144    }
     145    if (useOverlay == !!overlay)
     146        return;
     147    if (useOverlay) {
     148        overlay = QSharedPointer<QGraphicsItemOverlay>(new QGraphicsItemOverlay(view, page));
     149        overlay->setZValue(OverlayZValue);
     150    } else
     151        overlay.clear();
     152}
     153
     154#if USE(ACCELERATED_COMPOSITING)
     155void PageClientQGraphicsWidget::syncLayers()
     156{
     157    if (shouldSync) {
     158        QWebFramePrivate::core(page->mainFrame())->view()->syncCompositingStateRecursive();
     159        shouldSync = false;
     160    }
     161}
     162
     163void PageClientQGraphicsWidget::setRootGraphicsLayer(QGraphicsItem* layer)
     164{
     165    if (rootGraphicsLayer) {
     166        rootGraphicsLayer.data()->setParentItem(0);
     167        view->scene()->removeItem(rootGraphicsLayer.data());
     168        QWebFramePrivate::core(page->mainFrame())->view()->syncCompositingStateRecursive();
     169    }
     170
     171    rootGraphicsLayer = layer ? layer->toGraphicsObject() : 0;
     172
     173    if (layer) {
     174        layer->setFlag(QGraphicsItem::ItemClipsChildrenToShape, true);
     175        layer->setParentItem(view);
     176        layer->setZValue(RootGraphicsLayerZValue);
     177        updateCompositingScrollPosition();
     178    }
     179    createOrDeleteOverlay();
     180}
     181
     182void PageClientQGraphicsWidget::markForSync(bool scheduleSync)
     183{
     184    shouldSync = true;
     185    if (scheduleSync)
     186        syncMetaMethod.invoke(view, Qt::QueuedConnection);
     187}
     188
     189void PageClientQGraphicsWidget::updateCompositingScrollPosition()
     190{
     191    if (rootGraphicsLayer && page && page->mainFrame()) {
     192        const QPoint scrollPosition = page->mainFrame()->scrollPosition();
     193        rootGraphicsLayer.data()->setPos(-scrollPosition);
     194    }
     195}
     196#endif
     197
     198#if ENABLE(TILED_BACKING_STORE)
     199void PageClientQGraphicsWidget::updateTiledBackingStoreScale()
     200{
     201    WebCore::TiledBackingStore* backingStore = QWebFramePrivate::core(page->mainFrame())->tiledBackingStore();
     202    if (!backingStore)
     203        return;
     204    backingStore->setContentsScale(view->scale());
     205}
     206#endif
     207
     208void PageClientQGraphicsWidget::setInputMethodEnabled(bool enable)
     209{
     210#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
     211    view->setFlag(QGraphicsItem::ItemAcceptsInputMethod, enable);
     212#endif
     213}
     214
     215bool PageClientQGraphicsWidget::inputMethodEnabled() const
     216{
     217#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
     218    return view->flags() & QGraphicsItem::ItemAcceptsInputMethod;
     219#else
     220    return false;
     221#endif
     222}
     223
     224#if QT_VERSION >= 0x040600
     225void PageClientQGraphicsWidget::setInputMethodHint(Qt::InputMethodHint hint, bool enable)
     226{
     227    if (enable)
     228        view->setInputMethodHints(view->inputMethodHints() | hint);
     229    else
     230        view->setInputMethodHints(view->inputMethodHints() & ~hint);
     231}
     232#endif
     233
     234#ifndef QT_NO_CURSOR
     235QCursor PageClientQGraphicsWidget::cursor() const
     236{
     237    return view->cursor();
     238}
     239
     240void PageClientQGraphicsWidget::updateCursor(const QCursor& cursor)
     241{
     242    view->setCursor(cursor);
     243}
     244#endif
     245
     246QPalette PageClientQGraphicsWidget::palette() const
     247{
     248    return view->palette();
     249}
     250
     251int PageClientQGraphicsWidget::screenNumber() const
     252{
     253#if defined(Q_WS_X11)
     254    if (QGraphicsScene* scene = view->scene()) {
     255        const QList<QGraphicsView*> views = scene->views();
     256
     257        if (!views.isEmpty())
     258            return views.at(0)->x11Info().screen();
     259    }
     260#endif
     261
     262    return 0;
     263}
     264
     265QWidget* PageClientQGraphicsWidget::ownerWidget() const
     266{
     267    if (QGraphicsScene* scene = view->scene()) {
     268        const QList<QGraphicsView*> views = scene->views();
     269        return views.value(0);
     270    }
     271    return 0;
     272}
     273
     274QRect PageClientQGraphicsWidget::geometryRelativeToOwnerWidget() const
     275{
     276    if (!view->scene())
     277        return QRect();
     278
     279    QList<QGraphicsView*> views = view->scene()->views();
     280    if (views.isEmpty())
     281        return QRect();
     282
     283    QGraphicsView* graphicsView = views.at(0);
     284    return graphicsView->mapFromScene(view->boundingRect()).boundingRect();
     285}
     286
     287QObject* PageClientQGraphicsWidget::pluginParent() const
     288{
     289    return view;
     290}
     291
     292QStyle* PageClientQGraphicsWidget::style() const
     293{
     294    return view->style();
     295}
     296
     297
     298
     299}
  • trunk/WebKit/qt/WebCoreSupport/PageClientQt.h

    r58038 r59152  
    2222#define PageClientQt_h
    2323
     24#include "FrameView.h"
     25#include "GraphicsContext.h"
     26#include "IntRect.h"
     27#include "qwebframe.h"
     28#include "qwebframe_p.h"
     29#include "qwebpage.h"
     30#include "qwebpage_p.h"
    2431#include "QWebPageClient.h"
    25 
     32#include "TiledBackingStore.h"
     33
     34#include <QtCore/qmetaobject.h>
     35#include <QtCore/qsharedpointer.h>
     36#include <QtGui/qgraphicsscene.h>
     37#include <QtGui/qgraphicsview.h>
     38#include <QtGui/qgraphicswidget.h>
     39#include <QtGui/qscrollbar.h>
     40#include <QtGui/qstyleoption.h>
    2641#include <QtGui/qwidget.h>
     42
     43#include <Settings.h>
    2744
    2845
     
    6481};
    6582
     83// the overlay is here for one reason only: to have the scroll-bars and other
     84// extra UI elements appear on top of any QGraphicsItems created by CSS compositing layers
     85class QGraphicsItemOverlay : public QGraphicsItem {
     86    public:
     87    QGraphicsItemOverlay(QGraphicsWidget* view, QWebPage* p)
     88            :QGraphicsItem(view)
     89            , q(view)
     90            , page(p)
     91    {
     92        setPos(0, 0);
     93#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
     94        setFlag(QGraphicsItem::ItemUsesExtendedStyleOption, true);
     95#endif
     96        setCacheMode(QGraphicsItem::DeviceCoordinateCache);
     97    }
     98
     99    QRectF boundingRect() const
     100    {
     101        return q->boundingRect();
     102    }
     103
     104    void paint(QPainter* painter, const QStyleOptionGraphicsItem* options, QWidget*)
     105    {
     106        page->mainFrame()->render(painter, static_cast<QWebFrame::RenderLayer>(QWebFrame::AllLayers&(~QWebFrame::ContentsLayer)), options->exposedRect.toRect());
     107    }
     108
     109    void prepareGraphicsItemGeometryChange()
     110    {
     111        prepareGeometryChange();
     112    }
     113
     114    friend class QGraphicsWidget;
     115    QGraphicsWidget* q;
     116    QWebPage* page;
     117};
     118
     119
     120class PageClientQGraphicsWidget : public QWebPageClient {
     121public:
     122    PageClientQGraphicsWidget(QGraphicsWidget* v, QWebPage* p)
     123        : view(v)
     124        , page(p)
     125        , viewResizesToContents(false)
     126#if USE(ACCELERATED_COMPOSITING)
     127        , shouldSync(false)
     128#endif
     129    {
     130       Q_ASSERT(view);
     131#if USE(ACCELERATED_COMPOSITING)
     132        // the overlay and stays alive for the lifetime of
     133        // this QGraphicsWebView as the scrollbars are needed when there's no compositing
     134        view->setFlag(QGraphicsItem::ItemUsesExtendedStyleOption);
     135        syncMetaMethod = view->metaObject()->method(view->metaObject()->indexOfMethod("syncLayers()"));
     136#endif
     137    }
     138
     139    virtual ~PageClientQGraphicsWidget();
     140
     141    virtual bool isQWidgetClient() const { return false; }
     142
     143    virtual void scroll(int dx, int dy, const QRect&);
     144    virtual void update(const QRect& dirtyRect);
     145    virtual void setInputMethodEnabled(bool enable);
     146    virtual bool inputMethodEnabled() const;
     147#if QT_VERSION >= 0x040600
     148    virtual void setInputMethodHint(Qt::InputMethodHint hint, bool enable);
     149#endif
     150
     151#ifndef QT_NO_CURSOR
     152    virtual QCursor cursor() const;
     153    virtual void updateCursor(const QCursor& cursor);
     154#endif
     155
     156    virtual QPalette palette() const;
     157    virtual int screenNumber() const;
     158    virtual QWidget* ownerWidget() const;
     159    virtual QRect geometryRelativeToOwnerWidget() const;
     160
     161    virtual QObject* pluginParent() const;
     162
     163    virtual QStyle* style() const;
     164
     165    void createOrDeleteOverlay();
     166
     167#if ENABLE(TILED_BACKING_STORE)
     168    void updateTiledBackingStoreScale();
     169#endif
     170
     171#if USE(ACCELERATED_COMPOSITING)
     172    virtual void setRootGraphicsLayer(QGraphicsItem* layer);
     173    virtual void markForSync(bool scheduleSync);
     174    void updateCompositingScrollPosition();
     175    void syncLayers();
     176
     177    // QGraphicsWebView can render composited layers
     178    virtual bool allowsAcceleratedCompositing() const { return true; }
     179#endif
     180
     181    QGraphicsWidget* view;
     182    QWebPage* page;
     183    bool viewResizesToContents;
     184
     185#if USE(ACCELERATED_COMPOSITING)
     186    QWeakPointer<QGraphicsObject> rootGraphicsLayer;
     187
     188    // we have to flush quite often, so we use a meta-method instead of QTimer::singleShot for putting the event in the queue
     189    QMetaMethod syncMetaMethod;
     190
     191    // we need to sync the layers if we get a special call from the WebCore
     192    // compositor telling us to do so. We'll get that call from ChromeClientQt
     193    bool shouldSync;
     194#endif
     195    // the overlay gets instantiated when the root layer is attached, and get deleted when it's detached
     196    QSharedPointer<QGraphicsItemOverlay> overlay;
     197
     198    // we need to put the root graphics layer behind the overlay (which contains the scrollbar)
     199    enum { RootGraphicsLayerZValue, OverlayZValue };
     200};
     201
    66202}
    67203#endif // PageClientQt
Note: See TracChangeset for help on using the changeset viewer.